PageRenderTime 21ms CodeModel.GetById 8ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/core/10.4/fusefs/fuse_node.h

http://macfuse.googlecode.com/
C++ Header | 205 lines | 147 code | 36 blank | 22 comment | 1 complexity | 88103e64e99ef8fb79cb538beb55c235 MD5 | raw file
  1/*
  2 * Copyright (C) 2006-2008 Google. All Rights Reserved.
  3 * Amit Singh <singh@>
  4 */
  5
  6#ifndef _FUSE_NODE_H_
  7#define _FUSE_NODE_H_
  8
  9#include "fuse_file.h"
 10#include "fuse_knote.h"
 11#include "fuse_nodehash.h"
 12#include <fuse_param.h>
 13
 14extern errno_t (**fuse_vnode_operations)(void *);
 15
 16#if M_MACFUSE_ENABLE_FIFOFS
 17extern errno_t (**fuse_fifo_operations)(void *);
 18#endif /* M_MACFUSE_ENABLE_FIFOFS */
 19
 20#if M_MACFUSE_ENABLE_SPECFS
 21extern errno_t (**fuse_spec_operations)(void *);
 22#endif /* M_MACFUSE_ENABLE_SPECFS */
 23
 24enum {
 25    kFSNodeMagic    = 'FUSE',
 26    kFSNodeBadMagic = 'FU**',
 27    kHNodeMagic     = 'HNOD',
 28};
 29
 30#define FN_ACCESS_NOOP       0x00000001
 31#define FN_CREATING          0x00000002
 32#define FN_DIRECT_IO         0x00000004
 33#define FN_HAS_ACL           0x00000008
 34#define FN_IS_ROOT           0x00000010
 35#define FN_REVOKED           0x00000020
 36
 37#define C_NEED_RVNODE_PUT    0x000000001
 38#define C_NEED_DVNODE_PUT    0x000000002
 39#define C_ZFWANTSYNC         0x000000004
 40#define C_FROMSYNC           0x000000008
 41#define C_MODIFIED           0x000000010
 42#define C_NOEXISTS           0x000000020
 43#define C_DELETED            0x000000040
 44#define C_HARDLINK           0x000000080
 45#define C_FORCEUPDATE        0x000000100
 46#define C_HASXATTRS          0x000000200
 47#define C_NEED_DATA_SETSIZE  0x000001000
 48#define C_NEED_RSRC_SETSIZE  0x000002000
 49#define C_CREATING           0x000004000
 50#define C_ACCESS_NOOP        0x000008000
 51#define C_TOUCH_ACCTIME      0x000010000
 52#define C_TOUCH_CHGTIME      0x000020000
 53#define C_TOUCH_MODTIME      0x000040000
 54#define C_XTIMES_VALID       0x000080000
 55
 56struct fuse_vnode_data {
 57
 58    /** check **/
 59    uint32_t   fMagic;
 60    boolean_t  fInitialised;
 61
 62    /** self **/
 63    vnode_t    vp;
 64    uint64_t   nodeid;
 65    uint64_t   generation;
 66
 67    /** parent **/
 68    vnode_t    parentvp;
 69    uint64_t   parent_nodeid;
 70
 71    /** I/O **/
 72    struct     fuse_filehandle fufh[FUFH_MAXTYPE];
 73
 74    /** flags **/
 75    uint32_t   flag;
 76    uint32_t   c_flag;
 77
 78    /** meta **/
 79    struct timespec   modify_time;
 80    struct timespec   entry_valid;
 81    struct timespec   attr_valid;
 82    struct vnode_attr cached_attr;
 83    off_t             filesize; 
 84    uint64_t          nlookup;
 85    enum vtype        vtype;
 86
 87    /** locking **/
 88
 89    lck_mtx_t *createlock;
 90    void      *creator;
 91
 92#if M_MACFUSE_ENABLE_TSLOCKING
 93    /*
 94     * The nodelock must be held when data in the FUSE node is accessed or
 95     * modified. Typically, we would take this lock at the beginning of a
 96     * vnop and drop it at the end of the vnop.
 97     */
 98    lck_rw_t  *nodelock;
 99    void      *nodelockowner;
100
101    /*
102     * The truncatelock guards against the EOF changing on us (that is, a
103     * file resize) unexpectedly.
104     */
105    lck_rw_t  *truncatelock;
106#endif
107
108    /** miscellaneous **/
109
110#if M_MACFUSE_ENABLE_KQUEUE
111    struct klist c_knotes;
112#endif /* M_MACFUSE_ENABLE_KQUEUE */
113};
114typedef struct fuse_vnode_data * fusenode_t;
115
116#define VTOFUD(vp) \
117    ((struct fuse_vnode_data *)FSNodeGenericFromHNode(vnode_fsnode(vp)))
118#define VTOI(vp)    (VTOFUD(vp)->nodeid)
119#define VTOVA(vp)   (&(VTOFUD(vp)->cached_attr))
120#define VTOILLU(vp) ((uint64_t)(VTOFUD(vp) ? VTOI(vp) : 0))
121
122#define FUSE_NULL_ID 0
123
124static __inline__
125void
126fuse_invalidate_attr(vnode_t vp)
127{
128    if (VTOFUD(vp)) {
129        bzero(&VTOFUD(vp)->attr_valid, sizeof(struct timespec));
130        VTOFUD(vp)->c_flag &= ~C_XTIMES_VALID;
131    }
132}
133
134void fuse_vnode_init(vnode_t vp, struct fuse_vnode_data *fvdat,
135                     uint64_t nodeid, enum vtype vtyp, uint64_t parentid);
136void fuse_vnode_ditch(vnode_t vp, vfs_context_t context);
137void fuse_vnode_teardown(vnode_t vp, vfs_context_t context, enum vtype vtyp);
138
139struct get_filehandle_param {
140
141    enum fuse_opcode opcode;
142    uint8_t          do_gc:1;
143    uint8_t          do_new:1;
144
145    int   explicitidentity;
146    pid_t pid;
147    uid_t uid;
148    gid_t gid;
149};
150
151errno_t
152FSNodeGetOrCreateFileVNodeByID(vnode_t               *vpp,
153                               uint32_t               flags,
154                               struct fuse_entry_out *feo,
155                               mount_t                mp,
156                               vnode_t                dvp,
157                               vfs_context_t          context,
158                               uint32_t              *oflags);
159
160void FSNodeScrub(struct fuse_vnode_data *fvdat);
161
162int
163fuse_vget_i(vnode_t               *vpp,
164            uint32_t               flags,
165            struct fuse_entry_out *feo,
166            struct componentname  *cnp,
167            vnode_t                dvp,
168            mount_t                mp,
169            vfs_context_t          context);
170
171/* Name cache wrappers */
172
173static __inline__
174void
175fuse_vncache_enter(vnode_t dvp, vnode_t vp, struct componentname *cnp)
176{
177#if FUSE_TRACE_VNCACHE
178    IOLog("MacFUSE: cache enter dvp=%p, vp=%p, %s\n", dvp, vp, cnp->cn_nameptr);
179#endif
180    return cache_enter(dvp, vp, cnp);
181}
182
183static __inline__
184void
185fuse_vncache_purge(vnode_t vp)
186{
187#if FUSE_TRACE_VNCACHE
188    IOLog("MacFUSE: cache purge vp=%p\n", vp);
189#endif
190    return cache_purge(vp);
191}
192
193static __inline__
194int
195fuse_vncache_lookup(vnode_t dvp, vnode_t *vpp, struct componentname *cnp)
196{
197    int ret = cache_lookup(dvp, vpp, cnp);
198#if FUSE_TRACE_VNCACHE
199    IOLog("MacFUSE: cache lookup ret=%d, dvp=%p, *vpp=%p, %s\n",
200          ret, dvp, *vpp, cnp->cn_nameptr);
201#endif
202    return ret;
203}
204
205#endif /* _FUSE_NODE_H_ */