exportfs: add new methods
[safe/jmp/linux-2.6] / include / linux / exportfs.h
1 #ifndef LINUX_EXPORTFS_H
2 #define LINUX_EXPORTFS_H 1
3
4 #include <linux/types.h>
5
6 struct dentry;
7 struct inode;
8 struct super_block;
9 struct vfsmount;
10
11 /*
12  * The fileid_type identifies how the file within the filesystem is encoded.
13  * In theory this is freely set and parsed by the filesystem, but we try to
14  * stick to conventions so we can share some generic code and don't confuse
15  * sniffers like ethereal/wireshark.
16  *
17  * The filesystem must not use the value '0' or '0xff'.
18  */
19 enum fid_type {
20         /*
21          * The root, or export point, of the filesystem.
22          * (Never actually passed down to the filesystem.
23          */
24         FILEID_ROOT = 0,
25
26         /*
27          * 32bit inode number, 32 bit generation number.
28          */
29         FILEID_INO32_GEN = 1,
30
31         /*
32          * 32bit inode number, 32 bit generation number,
33          * 32 bit parent directory inode number.
34          */
35         FILEID_INO32_GEN_PARENT = 2,
36 };
37
38 struct fid {
39         union {
40                 struct {
41                         u32 ino;
42                         u32 gen;
43                         u32 parent_ino;
44                         u32 parent_gen;
45                 } i32;
46                 __u32 raw[6];
47         };
48 };
49
50 /**
51  * struct export_operations - for nfsd to communicate with file systems
52  * @decode_fh:      decode a file handle fragment and return a &struct dentry
53  * @encode_fh:      encode a file handle fragment from a dentry
54  * @get_name:       find the name for a given inode in a given directory
55  * @get_parent:     find the parent of a given directory
56  * @get_dentry:     find a dentry for the inode given a file handle sub-fragment
57  * @find_exported_dentry:
58  *      set by the exporting module to a standard helper function.
59  *
60  * Description:
61  *    The export_operations structure provides a means for nfsd to communicate
62  *    with a particular exported file system  - particularly enabling nfsd and
63  *    the filesystem to co-operate when dealing with file handles.
64  *
65  *    export_operations contains two basic operation for dealing with file
66  *    handles, decode_fh() and encode_fh(), and allows for some other
67  *    operations to be defined which standard helper routines use to get
68  *    specific information from the filesystem.
69  *
70  *    nfsd encodes information use to determine which filesystem a filehandle
71  *    applies to in the initial part of the file handle.  The remainder, termed
72  *    a file handle fragment, is controlled completely by the filesystem.  The
73  *    standard helper routines assume that this fragment will contain one or
74  *    two sub-fragments, one which identifies the file, and one which may be
75  *    used to identify the (a) directory containing the file.
76  *
77  *    In some situations, nfsd needs to get a dentry which is connected into a
78  *    specific part of the file tree.  To allow for this, it passes the
79  *    function acceptable() together with a @context which can be used to see
80  *    if the dentry is acceptable.  As there can be multiple dentrys for a
81  *    given file, the filesystem should check each one for acceptability before
82  *    looking for the next.  As soon as an acceptable one is found, it should
83  *    be returned.
84  *
85  * decode_fh:
86  *    @decode_fh is given a &struct super_block (@sb), a file handle fragment
87  *    (@fh, @fh_len) and an acceptability testing function (@acceptable,
88  *    @context).  It should return a &struct dentry which refers to the same
89  *    file that the file handle fragment refers to,  and which passes the
90  *    acceptability test.  If it cannot, it should return a %NULL pointer if
91  *    the file was found but no acceptable &dentries were available, or a
92  *    %ERR_PTR error code indicating why it couldn't be found (e.g. %ENOENT or
93  *    %ENOMEM).
94  *
95  * encode_fh:
96  *    @encode_fh should store in the file handle fragment @fh (using at most
97  *    @max_len bytes) information that can be used by @decode_fh to recover the
98  *    file refered to by the &struct dentry @de.  If the @connectable flag is
99  *    set, the encode_fh() should store sufficient information so that a good
100  *    attempt can be made to find not only the file but also it's place in the
101  *    filesystem.   This typically means storing a reference to de->d_parent in
102  *    the filehandle fragment.  encode_fh() should return the number of bytes
103  *    stored or a negative error code such as %-ENOSPC
104  *
105  * fh_to_dentry:
106  *    @fh_to_dentry is given a &struct super_block (@sb) and a file handle
107  *    fragment (@fh, @fh_len). It should return a &struct dentry which refers
108  *    to the same file that the file handle fragment refers to.  If it cannot,
109  *    it should return a %NULL pointer if the file was found but no acceptable
110  *    &dentries were available, or an %ERR_PTR error code indicating why it
111  *    couldn't be found (e.g. %ENOENT or %ENOMEM).  Any suitable dentry can be
112  *    returned including, if necessary, a new dentry created with d_alloc_root.
113  *    The caller can then find any other extant dentries by following the
114  *    d_alias links.
115  *
116  * fh_to_parent:
117  *    Same as @fh_to_dentry, except that it returns a pointer to the parent
118  *    dentry if it was encoded into the filehandle fragment by @encode_fh.
119  *
120  * get_name:
121  *    @get_name should find a name for the given @child in the given @parent
122  *    directory.  The name should be stored in the @name (with the
123  *    understanding that it is already pointing to a a %NAME_MAX+1 sized
124  *    buffer.   get_name() should return %0 on success, a negative error code
125  *    or error.  @get_name will be called without @parent->i_mutex held.
126  *
127  * get_parent:
128  *    @get_parent should find the parent directory for the given @child which
129  *    is also a directory.  In the event that it cannot be found, or storage
130  *    space cannot be allocated, a %ERR_PTR should be returned.
131  *
132  * get_dentry:
133  *    Given a &super_block (@sb) and a pointer to a file-system specific inode
134  *    identifier, possibly an inode number, (@inump) get_dentry() should find
135  *    the identified inode and return a dentry for that inode.  Any suitable
136  *    dentry can be returned including, if necessary, a new dentry created with
137  *    d_alloc_root.  The caller can then find any other extant dentrys by
138  *    following the d_alias links.  If a new dentry was created using
139  *    d_alloc_root, DCACHE_NFSD_DISCONNECTED should be set, and the dentry
140  *    should be d_rehash()ed.
141  *
142  *    If the inode cannot be found, either a %NULL pointer or an %ERR_PTR code
143  *    can be returned.  The @inump will be whatever was passed to
144  *    nfsd_find_fh_dentry() in either the @obj or @parent parameters.
145  *
146  * Locking rules:
147  *    get_parent is called with child->d_inode->i_mutex down
148  *    get_name is not (which is possibly inconsistent)
149  */
150
151 struct export_operations {
152         struct dentry *(*decode_fh)(struct super_block *sb, __u32 *fh,
153                         int fh_len, int fh_type,
154                         int (*acceptable)(void *context, struct dentry *de),
155                         void *context);
156         int (*encode_fh)(struct dentry *de, __u32 *fh, int *max_len,
157                         int connectable);
158         struct dentry * (*fh_to_dentry)(struct super_block *sb, struct fid *fid,
159                         int fh_len, int fh_type);
160         struct dentry * (*fh_to_parent)(struct super_block *sb, struct fid *fid,
161                         int fh_len, int fh_type);
162         int (*get_name)(struct dentry *parent, char *name,
163                         struct dentry *child);
164         struct dentry * (*get_parent)(struct dentry *child);
165         struct dentry * (*get_dentry)(struct super_block *sb, void *inump);
166
167         /* This is set by the exporting module to a standard helper */
168         struct dentry * (*find_exported_dentry)(
169                         struct super_block *sb, void *obj, void *parent,
170                         int (*acceptable)(void *context, struct dentry *de),
171                         void *context);
172 };
173
174 extern struct dentry *find_exported_dentry(struct super_block *sb, void *obj,
175         void *parent, int (*acceptable)(void *context, struct dentry *de),
176         void *context);
177
178 extern int exportfs_encode_fh(struct dentry *dentry, struct fid *fid,
179         int *max_len, int connectable);
180 extern struct dentry *exportfs_decode_fh(struct vfsmount *mnt, struct fid *fid,
181         int fh_len, int fileid_type, int (*acceptable)(void *, struct dentry *),
182         void *context);
183
184 /*
185  * Generic helpers for filesystems.
186  */
187 extern struct dentry *generic_fh_to_dentry(struct super_block *sb,
188         struct fid *fid, int fh_len, int fh_type,
189         struct inode *(*get_inode) (struct super_block *sb, u64 ino, u32 gen));
190 extern struct dentry *generic_fh_to_parent(struct super_block *sb,
191         struct fid *fid, int fh_len, int fh_type,
192         struct inode *(*get_inode) (struct super_block *sb, u64 ino, u32 gen));
193
194 #endif /* LINUX_EXPORTFS_H */