PageRenderTime 27ms CodeModel.GetById 20ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/core/10.4/fusefs/fuse_knote.c

http://macfuse.googlecode.com/
C | 132 lines | 92 code | 24 blank | 16 comment | 30 complexity | d8b6a003714d6fb39a0cdc4995af9552 MD5 | raw file
  1/*
  2 * Copyright (C) 2007 Google. All Rights Reserved.
  3 * Amit Singh <singh@>
  4 */
  5
  6#include <fuse_param.h>
  7
  8#if M_MACFUSE_ENABLE_KQUEUE
  9
 10#include "fuse.h"
 11#include "fuse_knote.h"
 12#include "fuse_node.h"
 13
 14struct filterops fuseread_filtops =
 15    { 1, NULL, filt_fusedetach, filt_fuseread };
 16struct filterops fusewrite_filtops =
 17    { 1, NULL, filt_fusedetach, filt_fusewrite };
 18struct filterops fusevnode_filtops =
 19    { 1, NULL, filt_fusedetach, filt_fusevnode };
 20
 21/* Like HFS+ ... */
 22
 23void
 24filt_fusedetach(struct knote *kn)
 25{
 26    struct vnode *vp;
 27        
 28    vp = (struct vnode *)kn->kn_hook;
 29    if (vnode_getwithvid(vp, kn->kn_hookid)) {
 30        return;
 31    }
 32
 33    if (1) {  /* !KNDETACH_VNLOCKED */
 34        if (/* take exclusive lock */ 1) {
 35            (void)KNOTE_DETACH(&VTOFUD(vp)->c_knotes, kn);
 36            /* release lock */
 37        }
 38    }
 39
 40    vnode_put(vp);
 41}
 42
 43int
 44filt_fuseread(struct knote *kn, long hint)
 45{
 46    vnode_t vp = (vnode_t)kn->kn_hook;
 47    int dropvp = 0;
 48    int result = 0;
 49
 50    if (hint == 0)  {
 51        if ((vnode_getwithvid(vp, kn->kn_hookid) != 0)) {
 52            hint = NOTE_REVOKE;
 53        } else  {
 54            dropvp = 1;
 55        }
 56    }
 57
 58    if (hint == NOTE_REVOKE) {
 59        /*
 60         * filesystem is gone, so set the EOF flag and schedule 
 61         * the knote for deletion.
 62         */
 63        kn->kn_flags |= (EV_EOF | EV_ONESHOT);
 64        return 1;
 65    }
 66
 67    /* poll(2) semantics dictate always saying there is data */
 68    if (kn->kn_flags & EV_POLL) {
 69        kn->kn_data = 1;
 70        result = 1;
 71    } else {
 72        /* I'm not going to look inside kn_fp now... to hell with it. */
 73        kn->kn_data = 1;
 74        result = 1;
 75    }
 76
 77    if (dropvp) {
 78        vnode_put(vp);
 79    }
 80
 81    return (kn->kn_data != 0);
 82}
 83
 84int
 85filt_fusewrite(struct knote *kn, long hint)
 86{
 87    if (hint == 0)  {
 88        if ((vnode_getwithvid((vnode_t)kn->kn_hook, kn->kn_hookid) != 0)) {
 89            hint = NOTE_REVOKE;
 90        } else 
 91            vnode_put((vnode_t)kn->kn_hook);
 92    }
 93
 94    if (hint == NOTE_REVOKE) {
 95        /*
 96         * filesystem is gone, so set the EOF flag and schedule 
 97         * the knote for deletion.
 98         */
 99        kn->kn_data = 0;
100        kn->kn_flags |= (EV_EOF | EV_ONESHOT);
101        return 1;
102    }
103
104    kn->kn_data = 0;
105
106    return 1;
107}
108
109int
110filt_fusevnode(struct knote *kn, long hint)
111{
112    if (hint == 0)  {
113        if ((vnode_getwithvid((vnode_t)kn->kn_hook, kn->kn_hookid) != 0)) {
114            hint = NOTE_REVOKE;
115        } else {
116            vnode_put((vnode_t)kn->kn_hook);
117        }
118    }
119
120    if (kn->kn_sfflags & hint) {
121        kn->kn_fflags |= (int)hint;
122    }
123
124    if ((hint == NOTE_REVOKE)) {
125        kn->kn_flags |= (EV_EOF | EV_ONESHOT);
126        return 1;
127    }
128        
129    return (kn->kn_fflags != 0);
130}
131
132#endif /* M_MACFUSE_ENABLE_KQUEUE */