~james-w/+junk/fuse-ubuntu-upstream

« back to all changes in this revision

Viewing changes to include/fuse.h

  • Committer: James Westby
  • Date: 2008-05-16 12:59:17 UTC
  • Revision ID: jw+debian@jameswestby.net-20080516125917-tp1sifyaxglg2kjk
Tags: upstream-debian-2.7.2, upstream-ubuntu-2.7.2
Import upstream from fuse_2.7.2.orig.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
    FUSE: Filesystem in Userspace
3
 
    Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
 
2
  FUSE: Filesystem in Userspace
 
3
  Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
4
4
 
5
 
    This program can be distributed under the terms of the GNU LGPLv2.
6
 
    See the file COPYING.LIB.
 
5
  This program can be distributed under the terms of the GNU LGPLv2.
 
6
  See the file COPYING.LIB.
7
7
*/
8
8
 
9
9
#ifndef _FUSE_H_
37
37
#endif
38
38
 
39
39
/* ----------------------------------------------------------- *
40
 
 * Basic FUSE API                                              *
 
40
 * Basic FUSE API                                              *
41
41
 * ----------------------------------------------------------- */
42
42
 
43
43
/** Handle for a FUSE filesystem */
55
55
 * @return 1 if buffer is full, zero otherwise
56
56
 */
57
57
typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
58
 
                                const struct stat *stbuf, off_t off);
 
58
                                const struct stat *stbuf, off_t off);
59
59
 
60
60
/* Used by deprecated getdir() method */
61
61
typedef struct fuse_dirhandle *fuse_dirh_t;
62
62
typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type,
63
 
                              ino_t ino);
 
63
                              ino_t ino);
64
64
 
65
65
/**
66
66
 * The file system operations:
77
77
 * featured filesystem can still be implemented.
78
78
 */
79
79
struct fuse_operations {
80
 
    /** Get file attributes.
81
 
     *
82
 
     * Similar to stat().  The 'st_dev' and 'st_blksize' fields are
83
 
     * ignored.  The 'st_ino' field is ignored except if the 'use_ino'
84
 
     * mount option is given.
85
 
     */
86
 
    int (*getattr) (const char *, struct stat *);
87
 
 
88
 
    /** Read the target of a symbolic link
89
 
     *
90
 
     * The buffer should be filled with a null terminated string.  The
91
 
     * buffer size argument includes the space for the terminating
92
 
     * null character.  If the linkname is too long to fit in the
93
 
     * buffer, it should be truncated.  The return value should be 0
94
 
     * for success.
95
 
     */
96
 
    int (*readlink) (const char *, char *, size_t);
97
 
 
98
 
    /* Deprecated, use readdir() instead */
99
 
    int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
100
 
 
101
 
    /** Create a file node
102
 
     *
103
 
     * This is called for creation of all non-directory, non-symlink
104
 
     * nodes.  If the filesystem defines a create() method, then for
105
 
     * regular files that will be called instead.
106
 
     */
107
 
    int (*mknod) (const char *, mode_t, dev_t);
108
 
 
109
 
    /** Create a directory */
110
 
    int (*mkdir) (const char *, mode_t);
111
 
 
112
 
    /** Remove a file */
113
 
    int (*unlink) (const char *);
114
 
 
115
 
    /** Remove a directory */
116
 
    int (*rmdir) (const char *);
117
 
 
118
 
    /** Create a symbolic link */
119
 
    int (*symlink) (const char *, const char *);
120
 
 
121
 
    /** Rename a file */
122
 
    int (*rename) (const char *, const char *);
123
 
 
124
 
    /** Create a hard link to a file */
125
 
    int (*link) (const char *, const char *);
126
 
 
127
 
    /** Change the permission bits of a file */
128
 
    int (*chmod) (const char *, mode_t);
129
 
 
130
 
    /** Change the owner and group of a file */
131
 
    int (*chown) (const char *, uid_t, gid_t);
132
 
 
133
 
    /** Change the size of a file */
134
 
    int (*truncate) (const char *, off_t);
135
 
 
136
 
    /** Change the access and/or modification times of a file
137
 
     *
138
 
     * Deprecated, use utimens() instead.
139
 
     */
140
 
    int (*utime) (const char *, struct utimbuf *);
141
 
 
142
 
    /** File open operation
143
 
     *
144
 
     * No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC)
145
 
     * will be passed to open().  Open should check if the operation
146
 
     * is permitted for the given flags.  Optionally open may also
147
 
     * return an arbitrary filehandle in the fuse_file_info structure,
148
 
     * which will be passed to all file operations.
149
 
     *
150
 
     * Changed in version 2.2
151
 
     */
152
 
    int (*open) (const char *, struct fuse_file_info *);
153
 
 
154
 
    /** Read data from an open file
155
 
     *
156
 
     * Read should return exactly the number of bytes requested except
157
 
     * on EOF or error, otherwise the rest of the data will be
158
 
     * substituted with zeroes.  An exception to this is when the
159
 
     * 'direct_io' mount option is specified, in which case the return
160
 
     * value of the read system call will reflect the return value of
161
 
     * this operation.
162
 
     *
163
 
     * Changed in version 2.2
164
 
     */
165
 
    int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *);
166
 
 
167
 
    /** Write data to an open file
168
 
     *
169
 
     * Write should return exactly the number of bytes requested
170
 
     * except on error.  An exception to this is when the 'direct_io'
171
 
     * mount option is specified (see read operation).
172
 
     *
173
 
     * Changed in version 2.2
174
 
     */
175
 
    int (*write) (const char *, const char *, size_t, off_t,
176
 
                  struct fuse_file_info *);
177
 
 
178
 
    /** Get file system statistics
179
 
     *
180
 
     * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
181
 
     *
182
 
     * Replaced 'struct statfs' parameter with 'struct statvfs' in
183
 
     * version 2.5
184
 
     */
185
 
    int (*statfs) (const char *, struct statvfs *);
186
 
 
187
 
    /** Possibly flush cached data
188
 
     *
189
 
     * BIG NOTE: This is not equivalent to fsync().  It's not a
190
 
     * request to sync dirty data.
191
 
     *
192
 
     * Flush is called on each close() of a file descriptor.  So if a
193
 
     * filesystem wants to return write errors in close() and the file
194
 
     * has cached dirty data, this is a good place to write back data
195
 
     * and return any errors.  Since many applications ignore close()
196
 
     * errors this is not always useful.
197
 
     *
198
 
     * NOTE: The flush() method may be called more than once for each
199
 
     * open().  This happens if more than one file descriptor refers
200
 
     * to an opened file due to dup(), dup2() or fork() calls.  It is
201
 
     * not possible to determine if a flush is final, so each flush
202
 
     * should be treated equally.  Multiple write-flush sequences are
203
 
     * relatively rare, so this shouldn't be a problem.
204
 
     *
205
 
     * Filesystems shouldn't assume that flush will always be called
206
 
     * after some writes, or that if will be called at all.
207
 
     *
208
 
     * Changed in version 2.2
209
 
     */
210
 
    int (*flush) (const char *, struct fuse_file_info *);
211
 
 
212
 
    /** Release an open file
213
 
     *
214
 
     * Release is called when there are no more references to an open
215
 
     * file: all file descriptors are closed and all memory mappings
216
 
     * are unmapped.
217
 
     *
218
 
     * For every open() call there will be exactly one release() call
219
 
     * with the same flags and file descriptor.  It is possible to
220
 
     * have a file opened more than once, in which case only the last
221
 
     * release will mean, that no more reads/writes will happen on the
222
 
     * file.  The return value of release is ignored.
223
 
     *
224
 
     * Changed in version 2.2
225
 
     */
226
 
    int (*release) (const char *, struct fuse_file_info *);
227
 
 
228
 
    /** Synchronize file contents
229
 
     *
230
 
     * If the datasync parameter is non-zero, then only the user data
231
 
     * should be flushed, not the meta data.
232
 
     *
233
 
     * Changed in version 2.2
234
 
     */
235
 
    int (*fsync) (const char *, int, struct fuse_file_info *);
236
 
 
237
 
    /** Set extended attributes */
238
 
    int (*setxattr) (const char *, const char *, const char *, size_t, int);
239
 
 
240
 
    /** Get extended attributes */
241
 
    int (*getxattr) (const char *, const char *, char *, size_t);
242
 
 
243
 
    /** List extended attributes */
244
 
    int (*listxattr) (const char *, char *, size_t);
245
 
 
246
 
    /** Remove extended attributes */
247
 
    int (*removexattr) (const char *, const char *);
248
 
 
249
 
    /** Open directory
250
 
     *
251
 
     * This method should check if the open operation is permitted for
252
 
     * this  directory
253
 
     *
254
 
     * Introduced in version 2.3
255
 
     */
256
 
    int (*opendir) (const char *, struct fuse_file_info *);
257
 
 
258
 
    /** Read directory
259
 
     *
260
 
     * This supersedes the old getdir() interface.  New applications
261
 
     * should use this.
262
 
     *
263
 
     * The filesystem may choose between two modes of operation:
264
 
     *
265
 
     * 1) The readdir implementation ignores the offset parameter, and
266
 
     * passes zero to the filler function's offset.  The filler
267
 
     * function will not return '1' (unless an error happens), so the
268
 
     * whole directory is read in a single readdir operation.  This
269
 
     * works just like the old getdir() method.
270
 
     *
271
 
     * 2) The readdir implementation keeps track of the offsets of the
272
 
     * directory entries.  It uses the offset parameter and always
273
 
     * passes non-zero offset to the filler function.  When the buffer
274
 
     * is full (or an error happens) the filler function will return
275
 
     * '1'.
276
 
     *
277
 
     * Introduced in version 2.3
278
 
     */
279
 
    int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
280
 
                    struct fuse_file_info *);
281
 
 
282
 
    /** Release directory
283
 
     *
284
 
     * Introduced in version 2.3
285
 
     */
286
 
    int (*releasedir) (const char *, struct fuse_file_info *);
287
 
 
288
 
    /** Synchronize directory contents
289
 
     *
290
 
     * If the datasync parameter is non-zero, then only the user data
291
 
     * should be flushed, not the meta data
292
 
     *
293
 
     * Introduced in version 2.3
294
 
     */
295
 
    int (*fsyncdir) (const char *, int, struct fuse_file_info *);
296
 
 
297
 
    /**
298
 
     * Initialize filesystem
299
 
     *
300
 
     * The return value will passed in the private_data field of
301
 
     * fuse_context to all file operations and as a parameter to the
302
 
     * destroy() method.
303
 
     *
304
 
     * Introduced in version 2.3
305
 
     * Changed in version 2.6
306
 
     */
307
 
    void *(*init) (struct fuse_conn_info *conn);
308
 
 
309
 
    /**
310
 
     * Clean up filesystem
311
 
     *
312
 
     * Called on filesystem exit.
313
 
     *
314
 
     * Introduced in version 2.3
315
 
     */
316
 
    void (*destroy) (void *);
317
 
 
318
 
    /**
319
 
     * Check file access permissions
320
 
     *
321
 
     * This will be called for the access() system call.  If the
322
 
     * 'default_permissions' mount option is given, this method is not
323
 
     * called.
324
 
     *
325
 
     * This method is not called under Linux kernel versions 2.4.x
326
 
     *
327
 
     * Introduced in version 2.5
328
 
     */
329
 
    int (*access) (const char *, int);
330
 
 
331
 
    /**
332
 
     * Create and open a file
333
 
     *
334
 
     * If the file does not exist, first create it with the specified
335
 
     * mode, and then open it.
336
 
     *
337
 
     * If this method is not implemented or under Linux kernel
338
 
     * versions earlier than 2.6.15, the mknod() and open() methods
339
 
     * will be called instead.
340
 
     *
341
 
     * Introduced in version 2.5
342
 
     */
343
 
    int (*create) (const char *, mode_t, struct fuse_file_info *);
344
 
 
345
 
    /**
346
 
     * Change the size of an open file
347
 
     *
348
 
     * This method is called instead of the truncate() method if the
349
 
     * truncation was invoked from an ftruncate() system call.
350
 
     *
351
 
     * If this method is not implemented or under Linux kernel
352
 
     * versions earlier than 2.6.15, the truncate() method will be
353
 
     * called instead.
354
 
     *
355
 
     * Introduced in version 2.5
356
 
     */
357
 
    int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
358
 
 
359
 
    /**
360
 
     * Get attributes from an open file
361
 
     *
362
 
     * This method is called instead of the getattr() method if the
363
 
     * file information is available.
364
 
     *
365
 
     * Currently this is only called after the create() method if that
366
 
     * is implemented (see above).  Later it may be called for
367
 
     * invocations of fstat() too.
368
 
     *
369
 
     * Introduced in version 2.5
370
 
     */
371
 
    int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
372
 
 
373
 
    /**
374
 
     * Perform POSIX file locking operation
375
 
     *
376
 
     * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
377
 
     *
378
 
     * For the meaning of fields in 'struct flock' see the man page
379
 
     * for fcntl(2).  The l_whence field will always be set to
380
 
     * SEEK_SET.
381
 
     *
382
 
     * For checking lock ownership, the 'fuse_file_info->owner'
383
 
     * argument must be used.
384
 
     *
385
 
     * For F_GETLK operation, the library will first check currently
386
 
     * held locks, and if a conflicting lock is found it will return
387
 
     * information without calling this method.  This ensures, that
388
 
     * for local locks the l_pid field is correctly filled in.  The
389
 
     * results may not be accurate in case of race conditions and in
390
 
     * the presence of hard links, but it's unlikly that an
391
 
     * application would rely on accurate GETLK results in these
392
 
     * cases.  If a conflicting lock is not found, this method will be
393
 
     * called, and the filesystem may fill out l_pid by a meaningful
394
 
     * value, or it may leave this field zero.
395
 
     *
396
 
     * For F_SETLK and F_SETLKW the l_pid field will be set to the pid
397
 
     * of the process performing the locking operation.
398
 
     *
399
 
     * Note: if this method is not implemented, the kernel will still
400
 
     * allow file locking to work locally.  Hence it is only
401
 
     * interesting for network filesystems and similar.
402
 
     *
403
 
     * Introduced in version 2.6
404
 
     */
405
 
    int (*lock) (const char *, struct fuse_file_info *, int cmd,
406
 
                 struct flock *);
407
 
 
408
 
    /**
409
 
     * Change the access and modification times of a file with
410
 
     * nanosecond resolution
411
 
     *
412
 
     * Introduced in version 2.6
413
 
     */
414
 
    int (*utimens) (const char *, const struct timespec tv[2]);
415
 
 
416
 
    /**
417
 
     * Map block index within file to block index within device
418
 
     *
419
 
     * Note: This makes sense only for block device backed filesystems
420
 
     * mounted with the 'blkdev' option
421
 
     *
422
 
     * Introduced in version 2.6
423
 
     */
424
 
    int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
 
80
        /** Get file attributes.
 
81
         *
 
82
         * Similar to stat().  The 'st_dev' and 'st_blksize' fields are
 
83
         * ignored.      The 'st_ino' field is ignored except if the 'use_ino'
 
84
         * mount option is given.
 
85
         */
 
86
        int (*getattr) (const char *, struct stat *);
 
87
 
 
88
        /** Read the target of a symbolic link
 
89
         *
 
90
         * The buffer should be filled with a null terminated string.  The
 
91
         * buffer size argument includes the space for the terminating
 
92
         * null character.      If the linkname is too long to fit in the
 
93
         * buffer, it should be truncated.      The return value should be 0
 
94
         * for success.
 
95
         */
 
96
        int (*readlink) (const char *, char *, size_t);
 
97
 
 
98
        /* Deprecated, use readdir() instead */
 
99
        int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
 
100
 
 
101
        /** Create a file node
 
102
         *
 
103
         * This is called for creation of all non-directory, non-symlink
 
104
         * nodes.  If the filesystem defines a create() method, then for
 
105
         * regular files that will be called instead.
 
106
         */
 
107
        int (*mknod) (const char *, mode_t, dev_t);
 
108
 
 
109
        /** Create a directory */
 
110
        int (*mkdir) (const char *, mode_t);
 
111
 
 
112
        /** Remove a file */
 
113
        int (*unlink) (const char *);
 
114
 
 
115
        /** Remove a directory */
 
116
        int (*rmdir) (const char *);
 
117
 
 
118
        /** Create a symbolic link */
 
119
        int (*symlink) (const char *, const char *);
 
120
 
 
121
        /** Rename a file */
 
122
        int (*rename) (const char *, const char *);
 
123
 
 
124
        /** Create a hard link to a file */
 
125
        int (*link) (const char *, const char *);
 
126
 
 
127
        /** Change the permission bits of a file */
 
128
        int (*chmod) (const char *, mode_t);
 
129
 
 
130
        /** Change the owner and group of a file */
 
131
        int (*chown) (const char *, uid_t, gid_t);
 
132
 
 
133
        /** Change the size of a file */
 
134
        int (*truncate) (const char *, off_t);
 
135
 
 
136
        /** Change the access and/or modification times of a file
 
137
         *
 
138
         * Deprecated, use utimens() instead.
 
139
         */
 
140
        int (*utime) (const char *, struct utimbuf *);
 
141
 
 
142
        /** File open operation
 
143
         *
 
144
         * No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC)
 
145
         * will be passed to open().  Open should check if the operation
 
146
         * is permitted for the given flags.  Optionally open may also
 
147
         * return an arbitrary filehandle in the fuse_file_info structure,
 
148
         * which will be passed to all file operations.
 
149
         *
 
150
         * Changed in version 2.2
 
151
         */
 
152
        int (*open) (const char *, struct fuse_file_info *);
 
153
 
 
154
        /** Read data from an open file
 
155
         *
 
156
         * Read should return exactly the number of bytes requested except
 
157
         * on EOF or error, otherwise the rest of the data will be
 
158
         * substituted with zeroes.      An exception to this is when the
 
159
         * 'direct_io' mount option is specified, in which case the return
 
160
         * value of the read system call will reflect the return value of
 
161
         * this operation.
 
162
         *
 
163
         * Changed in version 2.2
 
164
         */
 
165
        int (*read) (const char *, char *, size_t, off_t,
 
166
                     struct fuse_file_info *);
 
167
 
 
168
        /** Write data to an open file
 
169
         *
 
170
         * Write should return exactly the number of bytes requested
 
171
         * except on error.      An exception to this is when the 'direct_io'
 
172
         * mount option is specified (see read operation).
 
173
         *
 
174
         * Changed in version 2.2
 
175
         */
 
176
        int (*write) (const char *, const char *, size_t, off_t,
 
177
                      struct fuse_file_info *);
 
178
 
 
179
        /** Get file system statistics
 
180
         *
 
181
         * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
 
182
         *
 
183
         * Replaced 'struct statfs' parameter with 'struct statvfs' in
 
184
         * version 2.5
 
185
         */
 
186
        int (*statfs) (const char *, struct statvfs *);
 
187
 
 
188
        /** Possibly flush cached data
 
189
         *
 
190
         * BIG NOTE: This is not equivalent to fsync().  It's not a
 
191
         * request to sync dirty data.
 
192
         *
 
193
         * Flush is called on each close() of a file descriptor.  So if a
 
194
         * filesystem wants to return write errors in close() and the file
 
195
         * has cached dirty data, this is a good place to write back data
 
196
         * and return any errors.  Since many applications ignore close()
 
197
         * errors this is not always useful.
 
198
         *
 
199
         * NOTE: The flush() method may be called more than once for each
 
200
         * open().      This happens if more than one file descriptor refers
 
201
         * to an opened file due to dup(), dup2() or fork() calls.      It is
 
202
         * not possible to determine if a flush is final, so each flush
 
203
         * should be treated equally.  Multiple write-flush sequences are
 
204
         * relatively rare, so this shouldn't be a problem.
 
205
         *
 
206
         * Filesystems shouldn't assume that flush will always be called
 
207
         * after some writes, or that if will be called at all.
 
208
         *
 
209
         * Changed in version 2.2
 
210
         */
 
211
        int (*flush) (const char *, struct fuse_file_info *);
 
212
 
 
213
        /** Release an open file
 
214
         *
 
215
         * Release is called when there are no more references to an open
 
216
         * file: all file descriptors are closed and all memory mappings
 
217
         * are unmapped.
 
218
         *
 
219
         * For every open() call there will be exactly one release() call
 
220
         * with the same flags and file descriptor.      It is possible to
 
221
         * have a file opened more than once, in which case only the last
 
222
         * release will mean, that no more reads/writes will happen on the
 
223
         * file.  The return value of release is ignored.
 
224
         *
 
225
         * Changed in version 2.2
 
226
         */
 
227
        int (*release) (const char *, struct fuse_file_info *);
 
228
 
 
229
        /** Synchronize file contents
 
230
         *
 
231
         * If the datasync parameter is non-zero, then only the user data
 
232
         * should be flushed, not the meta data.
 
233
         *
 
234
         * Changed in version 2.2
 
235
         */
 
236
        int (*fsync) (const char *, int, struct fuse_file_info *);
 
237
 
 
238
        /** Set extended attributes */
 
239
        int (*setxattr) (const char *, const char *, const char *, size_t, int);
 
240
 
 
241
        /** Get extended attributes */
 
242
        int (*getxattr) (const char *, const char *, char *, size_t);
 
243
 
 
244
        /** List extended attributes */
 
245
        int (*listxattr) (const char *, char *, size_t);
 
246
 
 
247
        /** Remove extended attributes */
 
248
        int (*removexattr) (const char *, const char *);
 
249
 
 
250
        /** Open directory
 
251
         *
 
252
         * This method should check if the open operation is permitted for
 
253
         * this  directory
 
254
         *
 
255
         * Introduced in version 2.3
 
256
         */
 
257
        int (*opendir) (const char *, struct fuse_file_info *);
 
258
 
 
259
        /** Read directory
 
260
         *
 
261
         * This supersedes the old getdir() interface.  New applications
 
262
         * should use this.
 
263
         *
 
264
         * The filesystem may choose between two modes of operation:
 
265
         *
 
266
         * 1) The readdir implementation ignores the offset parameter, and
 
267
         * passes zero to the filler function's offset.  The filler
 
268
         * function will not return '1' (unless an error happens), so the
 
269
         * whole directory is read in a single readdir operation.  This
 
270
         * works just like the old getdir() method.
 
271
         *
 
272
         * 2) The readdir implementation keeps track of the offsets of the
 
273
         * directory entries.  It uses the offset parameter and always
 
274
         * passes non-zero offset to the filler function.  When the buffer
 
275
         * is full (or an error happens) the filler function will return
 
276
         * '1'.
 
277
         *
 
278
         * Introduced in version 2.3
 
279
         */
 
280
        int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
 
281
                        struct fuse_file_info *);
 
282
 
 
283
        /** Release directory
 
284
         *
 
285
         * Introduced in version 2.3
 
286
         */
 
287
        int (*releasedir) (const char *, struct fuse_file_info *);
 
288
 
 
289
        /** Synchronize directory contents
 
290
         *
 
291
         * If the datasync parameter is non-zero, then only the user data
 
292
         * should be flushed, not the meta data
 
293
         *
 
294
         * Introduced in version 2.3
 
295
         */
 
296
        int (*fsyncdir) (const char *, int, struct fuse_file_info *);
 
297
 
 
298
        /**
 
299
         * Initialize filesystem
 
300
         *
 
301
         * The return value will passed in the private_data field of
 
302
         * fuse_context to all file operations and as a parameter to the
 
303
         * destroy() method.
 
304
         *
 
305
         * Introduced in version 2.3
 
306
         * Changed in version 2.6
 
307
         */
 
308
        void *(*init) (struct fuse_conn_info *conn);
 
309
 
 
310
        /**
 
311
         * Clean up filesystem
 
312
         *
 
313
         * Called on filesystem exit.
 
314
         *
 
315
         * Introduced in version 2.3
 
316
         */
 
317
        void (*destroy) (void *);
 
318
 
 
319
        /**
 
320
         * Check file access permissions
 
321
         *
 
322
         * This will be called for the access() system call.  If the
 
323
         * 'default_permissions' mount option is given, this method is not
 
324
         * called.
 
325
         *
 
326
         * This method is not called under Linux kernel versions 2.4.x
 
327
         *
 
328
         * Introduced in version 2.5
 
329
         */
 
330
        int (*access) (const char *, int);
 
331
 
 
332
        /**
 
333
         * Create and open a file
 
334
         *
 
335
         * If the file does not exist, first create it with the specified
 
336
         * mode, and then open it.
 
337
         *
 
338
         * If this method is not implemented or under Linux kernel
 
339
         * versions earlier than 2.6.15, the mknod() and open() methods
 
340
         * will be called instead.
 
341
         *
 
342
         * Introduced in version 2.5
 
343
         */
 
344
        int (*create) (const char *, mode_t, struct fuse_file_info *);
 
345
 
 
346
        /**
 
347
         * Change the size of an open file
 
348
         *
 
349
         * This method is called instead of the truncate() method if the
 
350
         * truncation was invoked from an ftruncate() system call.
 
351
         *
 
352
         * If this method is not implemented or under Linux kernel
 
353
         * versions earlier than 2.6.15, the truncate() method will be
 
354
         * called instead.
 
355
         *
 
356
         * Introduced in version 2.5
 
357
         */
 
358
        int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
 
359
 
 
360
        /**
 
361
         * Get attributes from an open file
 
362
         *
 
363
         * This method is called instead of the getattr() method if the
 
364
         * file information is available.
 
365
         *
 
366
         * Currently this is only called after the create() method if that
 
367
         * is implemented (see above).  Later it may be called for
 
368
         * invocations of fstat() too.
 
369
         *
 
370
         * Introduced in version 2.5
 
371
         */
 
372
        int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
 
373
 
 
374
        /**
 
375
         * Perform POSIX file locking operation
 
376
         *
 
377
         * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
 
378
         *
 
379
         * For the meaning of fields in 'struct flock' see the man page
 
380
         * for fcntl(2).  The l_whence field will always be set to
 
381
         * SEEK_SET.
 
382
         *
 
383
         * For checking lock ownership, the 'fuse_file_info->owner'
 
384
         * argument must be used.
 
385
         *
 
386
         * For F_GETLK operation, the library will first check currently
 
387
         * held locks, and if a conflicting lock is found it will return
 
388
         * information without calling this method.      This ensures, that
 
389
         * for local locks the l_pid field is correctly filled in.      The
 
390
         * results may not be accurate in case of race conditions and in
 
391
         * the presence of hard links, but it's unlikly that an
 
392
         * application would rely on accurate GETLK results in these
 
393
         * cases.  If a conflicting lock is not found, this method will be
 
394
         * called, and the filesystem may fill out l_pid by a meaningful
 
395
         * value, or it may leave this field zero.
 
396
         *
 
397
         * For F_SETLK and F_SETLKW the l_pid field will be set to the pid
 
398
         * of the process performing the locking operation.
 
399
         *
 
400
         * Note: if this method is not implemented, the kernel will still
 
401
         * allow file locking to work locally.  Hence it is only
 
402
         * interesting for network filesystems and similar.
 
403
         *
 
404
         * Introduced in version 2.6
 
405
         */
 
406
        int (*lock) (const char *, struct fuse_file_info *, int cmd,
 
407
                     struct flock *);
 
408
 
 
409
        /**
 
410
         * Change the access and modification times of a file with
 
411
         * nanosecond resolution
 
412
         *
 
413
         * Introduced in version 2.6
 
414
         */
 
415
        int (*utimens) (const char *, const struct timespec tv[2]);
 
416
 
 
417
        /**
 
418
         * Map block index within file to block index within device
 
419
         *
 
420
         * Note: This makes sense only for block device backed filesystems
 
421
         * mounted with the 'blkdev' option
 
422
         *
 
423
         * Introduced in version 2.6
 
424
         */
 
425
        int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
425
426
};
426
427
 
427
428
/** Extra context that may be needed by some filesystems
430
431
 * operation.
431
432
 */
432
433
struct fuse_context {
433
 
    /** Pointer to the fuse object */
434
 
    struct fuse *fuse;
435
 
 
436
 
    /** User ID of the calling process */
437
 
    uid_t uid;
438
 
 
439
 
    /** Group ID of the calling process */
440
 
    gid_t gid;
441
 
 
442
 
    /** Thread ID of the calling process */
443
 
    pid_t pid;
444
 
 
445
 
    /** Private filesystem data */
446
 
    void *private_data;
 
434
        /** Pointer to the fuse object */
 
435
        struct fuse *fuse;
 
436
 
 
437
        /** User ID of the calling process */
 
438
        uid_t uid;
 
439
 
 
440
        /** Group ID of the calling process */
 
441
        gid_t gid;
 
442
 
 
443
        /** Thread ID of the calling process */
 
444
        pid_t pid;
 
445
 
 
446
        /** Private filesystem data */
 
447
        void *private_data;
447
448
};
448
449
 
449
450
/**
470
471
 * @return 0 on success, nonzero on failure
471
472
 */
472
473
/*
473
 
int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
474
 
              void *user_data);
 
474
  int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
 
475
  void *user_data);
475
476
*/
476
 
#define fuse_main(argc, argv, op, user_data) \
477
 
            fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
 
477
#define fuse_main(argc, argv, op, user_data)                            \
 
478
        fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
478
479
 
479
480
/* ----------------------------------------------------------- *
480
 
 * More detailed API                                           *
 
481
 * More detailed API                                           *
481
482
 * ----------------------------------------------------------- */
482
483
 
483
484
/**
491
492
 * @return the created FUSE handle
492
493
 */
493
494
struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
494
 
                      const struct fuse_operations *op, size_t op_size,
495
 
                      void *user_data);
 
495
                      const struct fuse_operations *op, size_t op_size,
 
496
                      void *user_data);
496
497
 
497
498
/**
498
499
 * Destroy the FUSE handle.
499
500
 *
500
501
 * The communication channel attached to the handle is also destroyed.
501
502
 *
502
 
 * NOTE: This function does not unmount the filesystem.  If this is
 
503
 * NOTE: This function does not unmount the filesystem.  If this is
503
504
 * needed, call fuse_unmount() before calling this function.
504
505
 *
505
506
 * @param f the FUSE handle
573
574
 * Do not call this directly, use fuse_main()
574
575
 */
575
576
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
576
 
                   size_t op_size, void *user_data);
 
577
                   size_t op_size, void *user_data);
577
578
 
578
579
/*
579
580
 * Stacking API
597
598
 
598
599
int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf);
599
600
int fuse_fs_fgetattr(struct fuse_fs *fs, const char *path, struct stat *buf,
600
 
                     struct fuse_file_info *fi);
 
601
                     struct fuse_file_info *fi);
601
602
int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
602
 
                   const char *newpath);
 
603
                   const char *newpath);
603
604
int fuse_fs_unlink(struct fuse_fs *fs, const char *path);
604
605
int fuse_fs_rmdir(struct fuse_fs *fs, const char *path);
605
606
int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname,
606
 
                    const char *path);
 
607
                    const char *path);
607
608
int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath);
608
 
int fuse_fs_release(struct fuse_fs *fs,  const char *path,
609
 
                     struct fuse_file_info *fi);
 
609
int fuse_fs_release(struct fuse_fs *fs,  const char *path,
 
610
                    struct fuse_file_info *fi);
610
611
int fuse_fs_open(struct fuse_fs *fs, const char *path,
611
 
                 struct fuse_file_info *fi);
 
612
                 struct fuse_file_info *fi);
612
613
int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size,
613
 
                 off_t off, struct fuse_file_info *fi);
 
614
                 off_t off, struct fuse_file_info *fi);
614
615
int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf,
615
 
                  size_t size, off_t off, struct fuse_file_info *fi);
 
616
                  size_t size, off_t off, struct fuse_file_info *fi);
616
617
int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync,
617
 
                  struct fuse_file_info *fi);
 
618
                  struct fuse_file_info *fi);
618
619
int fuse_fs_flush(struct fuse_fs *fs, const char *path,
619
 
                  struct fuse_file_info *fi);
 
620
                  struct fuse_file_info *fi);
620
621
int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf);
621
622
int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
622
 
                    struct fuse_file_info *fi);
 
623
                    struct fuse_file_info *fi);
623
624
int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf,
624
 
                    fuse_fill_dir_t filler, off_t off,
625
 
                    struct fuse_file_info *fi);
 
625
                    fuse_fill_dir_t filler, off_t off,
 
626
                    struct fuse_file_info *fi);
626
627
int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync,
627
 
                     struct fuse_file_info *fi);
 
628
                     struct fuse_file_info *fi);
628
629
int fuse_fs_releasedir(struct fuse_fs *fs, const char *path,
629
 
                        struct fuse_file_info *fi);
 
630
                       struct fuse_file_info *fi);
630
631
int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode,
631
 
                   struct fuse_file_info *fi);
 
632
                   struct fuse_file_info *fi);
632
633
int fuse_fs_lock(struct fuse_fs *fs, const char *path,
633
 
                 struct fuse_file_info *fi, int cmd, struct flock *lock);
 
634
                 struct fuse_file_info *fi, int cmd, struct flock *lock);
634
635
int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode);
635
636
int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid);
636
637
int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size);
637
638
int fuse_fs_ftruncate(struct fuse_fs *fs, const char *path, off_t size,
638
 
                      struct fuse_file_info *fi);
 
639
                      struct fuse_file_info *fi);
639
640
int fuse_fs_utimens(struct fuse_fs *fs, const char *path,
640
 
                    const struct timespec tv[2]);
 
641
                    const struct timespec tv[2]);
641
642
int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask);
642
643
int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf,
643
 
                     size_t len);
 
644
                     size_t len);
644
645
int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
645
 
                  dev_t rdev);
 
646
                  dev_t rdev);
646
647
int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode);
647
648
int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name,
648
 
                     const char *value, size_t size, int flags);
 
649
                     const char *value, size_t size, int flags);
649
650
int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name,
650
 
                     char *value, size_t size);
 
651
                     char *value, size_t size);
651
652
int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list,
652
 
                      size_t size);
 
653
                      size_t size);
653
654
int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
654
 
                        const char *name);
 
655
                        const char *name);
655
656
int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
656
 
                 uint64_t *idx);
 
657
                 uint64_t *idx);
657
658
void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn);
658
659
void fuse_fs_destroy(struct fuse_fs *fs);
659
660
 
669
670
 * @return a new filesystem object
670
671
 */
671
672
struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
672
 
                            void *user_data);
 
673
                            void *user_data);
673
674
 
674
675
/**
675
676
 * Filesystem module
682
683
 * function.
683
684
 */
684
685
struct fuse_module {
685
 
    /**
686
 
     * Name of filesystem
687
 
     */
688
 
    const char *name;
689
 
 
690
 
    /**
691
 
     * Factory for creating filesystem objects
692
 
     *
693
 
     * The function may use and remove options from 'args' that belong
694
 
     * to this module.
695
 
     *
696
 
     * For now the 'fs' vector always contains exactly one filesystem.
697
 
     * This is the filesystem which will be below the newly created
698
 
     * filesystem in the stack.
699
 
     *
700
 
     * @param args the command line arguments
701
 
     * @param fs NULL terminated filesystem object vector
702
 
     * @return the new filesystem object
703
 
     */
704
 
    struct fuse_fs *(*factory)(struct fuse_args *args, struct fuse_fs *fs[]);
705
 
 
706
 
    struct fuse_module *next;
707
 
    struct fusemod_so *so;
708
 
    int ctr;
 
686
        /**
 
687
         * Name of filesystem
 
688
         */
 
689
        const char *name;
 
690
 
 
691
        /**
 
692
         * Factory for creating filesystem objects
 
693
         *
 
694
         * The function may use and remove options from 'args' that belong
 
695
         * to this module.
 
696
         *
 
697
         * For now the 'fs' vector always contains exactly one filesystem.
 
698
         * This is the filesystem which will be below the newly created
 
699
         * filesystem in the stack.
 
700
         *
 
701
         * @param args the command line arguments
 
702
         * @param fs NULL terminated filesystem object vector
 
703
         * @return the new filesystem object
 
704
         */
 
705
        struct fuse_fs *(*factory)(struct fuse_args *args,
 
706
                                   struct fuse_fs *fs[]);
 
707
 
 
708
        struct fuse_module *next;
 
709
        struct fusemod_so *so;
 
710
        int ctr;
709
711
};
710
712
 
711
713
/**
722
724
 * For the parameters, see description of the fields in 'struct
723
725
 * fuse_module'
724
726
 */
725
 
#define FUSE_REGISTER_MODULE(name_, factory_) \
726
 
static __attribute__((constructor)) void name_ ## _register(void) \
727
 
{ \
728
 
    static struct fuse_module mod = { #name_, factory_, NULL, NULL, 0 }; \
729
 
    fuse_register_module(&mod); \
730
 
}
 
727
#define FUSE_REGISTER_MODULE(name_, factory_)                             \
 
728
        static __attribute__((constructor)) void name_ ## _register(void) \
 
729
        {                                                                 \
 
730
                static struct fuse_module mod =                           \
 
731
                        { #name_, factory_, NULL, NULL, 0 };              \
 
732
                fuse_register_module(&mod);                               \
 
733
        }
731
734
 
732
735
 
733
736
/* ----------------------------------------------------------- *
742
745
 
743
746
/** This is the part of fuse_main() before the event loop */
744
747
struct fuse *fuse_setup(int argc, char *argv[],
745
 
                        const struct fuse_operations *op, size_t op_size,
746
 
                        char **mountpoint, int *multithreaded,
747
 
                        void *user_data);
 
748
                        const struct fuse_operations *op, size_t op_size,
 
749
                        char **mountpoint, int *multithreaded,
 
750
                        void *user_data);
748
751
 
749
752
/** This is the part of fuse_main() after the event loop */
750
753
void fuse_teardown(struct fuse *fuse, char *mountpoint);
770
773
struct fuse_session *fuse_get_session(struct fuse *f);
771
774
 
772
775
/* ----------------------------------------------------------- *
773
 
 * Compatibility stuff                                         *
 
776
 * Compatibility stuff                                         *
774
777
 * ----------------------------------------------------------- */
775
778
 
776
779
#if FUSE_USE_VERSION < 26
777
780
#  include "fuse_compat.h"
778
781
#  undef fuse_main
779
782
#  if FUSE_USE_VERSION == 25
780
 
#    define fuse_main(argc, argv, op) \
781
 
            fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
 
783
#    define fuse_main(argc, argv, op)                           \
 
784
        fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
782
785
#    define fuse_new fuse_new_compat25
783
786
#    define fuse_setup fuse_setup_compat25
784
787
#    define fuse_teardown fuse_teardown_compat22
785
788
#    define fuse_operations fuse_operations_compat25
786
789
#  elif FUSE_USE_VERSION == 22
787
 
#    define fuse_main(argc, argv, op) \
788
 
            fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
 
790
#    define fuse_main(argc, argv, op)                           \
 
791
        fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
789
792
#    define fuse_new fuse_new_compat22
790
793
#    define fuse_setup fuse_setup_compat22
791
794
#    define fuse_teardown fuse_teardown_compat22