fuse_node.h revision 241519
1/*
2 * Copyright (c) 2007-2009 Google Inc. and Amit Singh
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 *   notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 *   copyright notice, this list of conditions and the following disclaimer
13 *   in the documentation and/or other materials provided with the
14 *   distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 *   contributors may be used to endorse or promote products derived from
17 *   this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Copyright (C) 2005 Csaba Henk.
32 * All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 *    notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 *    notice, this list of conditions and the following disclaimer in the
41 *    documentation and/or other materials provided with the distribution.
42 *
43 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * $FreeBSD: head/sys/fs/fuse/fuse_node.h 241519 2012-10-13 23:54:26Z attilio $
56 */
57
58#ifndef _FUSE_NODE_H_
59#define _FUSE_NODE_H_
60
61#include <sys/types.h>
62#include <sys/mutex.h>
63
64#include "fuse_file.h"
65
66#define FN_REVOKED           0x00000020
67#define FN_FLUSHINPROG       0x00000040
68#define FN_FLUSHWANT         0x00000080
69#define FN_SIZECHANGE        0x00000100
70
71struct fuse_vnode_data {
72    /** self **/
73    uint64_t   nid;
74
75    /** parent **/
76    /* XXXIP very likely to be stale, it's not updated in rename() */
77    uint64_t   parent_nid;
78
79    /** I/O **/
80    struct     fuse_filehandle fufh[FUFH_MAXTYPE];
81
82    /** flags **/
83    uint32_t   flag;
84
85    /** meta **/
86    struct timespec   cached_attrs_valid;
87    struct vattr      cached_attrs;
88    off_t             filesize;
89    uint64_t          nlookup;
90    enum vtype        vtype;
91};
92
93#define VTOFUD(vp) \
94    ((struct fuse_vnode_data *)((vp)->v_data))
95#define VTOI(vp)    (VTOFUD(vp)->nid)
96#define VTOVA(vp)   (&(VTOFUD(vp)->cached_attrs))
97#define VTOILLU(vp) ((uint64_t)(VTOFUD(vp) ? VTOI(vp) : 0))
98
99#define FUSE_NULL_ID 0
100
101extern struct vop_vector fuse_vnops;
102
103static __inline__
104void
105fuse_invalidate_attr(struct vnode *vp)
106{
107    if (VTOFUD(vp)) {
108        bzero(&VTOFUD(vp)->cached_attrs_valid, sizeof(struct timespec));
109    }
110}
111
112static __inline void
113fuse_vnode_setparent(struct vnode *vp, struct vnode *dvp)
114{
115    if (dvp != NULL && vp->v_type == VDIR) {
116        MPASS(dvp->v_type == VDIR);
117        VTOFUD(vp)->parent_nid = VTOI(dvp);
118    }
119}
120
121int fuse_isvalid_attr(struct vnode *vp);
122
123void fuse_vnode_destroy(struct vnode *vp);
124
125int fuse_vnode_get(struct mount         *mp,
126                   uint64_t              nodeid,
127                   struct vnode         *dvp,
128                   struct vnode        **vpp,
129                   struct componentname *cnp,
130                   enum vtype            vtyp);
131
132void fuse_vnode_open(struct vnode *vp,
133                     int32_t fuse_open_flags,
134                     struct thread *td);
135
136void fuse_vnode_refreshsize(struct vnode *vp, struct ucred *cred);
137
138int fuse_vnode_savesize(struct vnode *vp, struct ucred *cred);
139
140int fuse_vnode_setsize(struct vnode *vp, struct ucred *cred, off_t newsize);
141
142#endif /* _FUSE_NODE_H_ */
143