77
77
* featured filesystem can still be implemented.
79
79
struct fuse_operations {
80
/** Get file attributes.
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.
86
int (*getattr) (const char *, struct stat *);
88
/** Read the target of a symbolic link
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
96
int (*readlink) (const char *, char *, size_t);
98
/* Deprecated, use readdir() instead */
99
int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
101
/** Create a file node
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.
107
int (*mknod) (const char *, mode_t, dev_t);
109
/** Create a directory */
110
int (*mkdir) (const char *, mode_t);
113
int (*unlink) (const char *);
115
/** Remove a directory */
116
int (*rmdir) (const char *);
118
/** Create a symbolic link */
119
int (*symlink) (const char *, const char *);
122
int (*rename) (const char *, const char *);
124
/** Create a hard link to a file */
125
int (*link) (const char *, const char *);
127
/** Change the permission bits of a file */
128
int (*chmod) (const char *, mode_t);
130
/** Change the owner and group of a file */
131
int (*chown) (const char *, uid_t, gid_t);
133
/** Change the size of a file */
134
int (*truncate) (const char *, off_t);
136
/** Change the access and/or modification times of a file
138
* Deprecated, use utimens() instead.
140
int (*utime) (const char *, struct utimbuf *);
142
/** File open operation
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.
150
* Changed in version 2.2
152
int (*open) (const char *, struct fuse_file_info *);
154
/** Read data from an open file
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
163
* Changed in version 2.2
165
int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *);
167
/** Write data to an open file
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).
173
* Changed in version 2.2
175
int (*write) (const char *, const char *, size_t, off_t,
176
struct fuse_file_info *);
178
/** Get file system statistics
180
* The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
182
* Replaced 'struct statfs' parameter with 'struct statvfs' in
185
int (*statfs) (const char *, struct statvfs *);
187
/** Possibly flush cached data
189
* BIG NOTE: This is not equivalent to fsync(). It's not a
190
* request to sync dirty data.
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.
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.
205
* Filesystems shouldn't assume that flush will always be called
206
* after some writes, or that if will be called at all.
208
* Changed in version 2.2
210
int (*flush) (const char *, struct fuse_file_info *);
212
/** Release an open file
214
* Release is called when there are no more references to an open
215
* file: all file descriptors are closed and all memory mappings
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.
224
* Changed in version 2.2
226
int (*release) (const char *, struct fuse_file_info *);
228
/** Synchronize file contents
230
* If the datasync parameter is non-zero, then only the user data
231
* should be flushed, not the meta data.
233
* Changed in version 2.2
235
int (*fsync) (const char *, int, struct fuse_file_info *);
237
/** Set extended attributes */
238
int (*setxattr) (const char *, const char *, const char *, size_t, int);
240
/** Get extended attributes */
241
int (*getxattr) (const char *, const char *, char *, size_t);
243
/** List extended attributes */
244
int (*listxattr) (const char *, char *, size_t);
246
/** Remove extended attributes */
247
int (*removexattr) (const char *, const char *);
251
* This method should check if the open operation is permitted for
254
* Introduced in version 2.3
256
int (*opendir) (const char *, struct fuse_file_info *);
260
* This supersedes the old getdir() interface. New applications
263
* The filesystem may choose between two modes of operation:
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.
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
277
* Introduced in version 2.3
279
int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
280
struct fuse_file_info *);
282
/** Release directory
284
* Introduced in version 2.3
286
int (*releasedir) (const char *, struct fuse_file_info *);
288
/** Synchronize directory contents
290
* If the datasync parameter is non-zero, then only the user data
291
* should be flushed, not the meta data
293
* Introduced in version 2.3
295
int (*fsyncdir) (const char *, int, struct fuse_file_info *);
298
* Initialize filesystem
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
304
* Introduced in version 2.3
305
* Changed in version 2.6
307
void *(*init) (struct fuse_conn_info *conn);
310
* Clean up filesystem
312
* Called on filesystem exit.
314
* Introduced in version 2.3
316
void (*destroy) (void *);
319
* Check file access permissions
321
* This will be called for the access() system call. If the
322
* 'default_permissions' mount option is given, this method is not
325
* This method is not called under Linux kernel versions 2.4.x
327
* Introduced in version 2.5
329
int (*access) (const char *, int);
332
* Create and open a file
334
* If the file does not exist, first create it with the specified
335
* mode, and then open it.
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.
341
* Introduced in version 2.5
343
int (*create) (const char *, mode_t, struct fuse_file_info *);
346
* Change the size of an open file
348
* This method is called instead of the truncate() method if the
349
* truncation was invoked from an ftruncate() system call.
351
* If this method is not implemented or under Linux kernel
352
* versions earlier than 2.6.15, the truncate() method will be
355
* Introduced in version 2.5
357
int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
360
* Get attributes from an open file
362
* This method is called instead of the getattr() method if the
363
* file information is available.
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.
369
* Introduced in version 2.5
371
int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
374
* Perform POSIX file locking operation
376
* The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
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
382
* For checking lock ownership, the 'fuse_file_info->owner'
383
* argument must be used.
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.
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.
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.
403
* Introduced in version 2.6
405
int (*lock) (const char *, struct fuse_file_info *, int cmd,
409
* Change the access and modification times of a file with
410
* nanosecond resolution
412
* Introduced in version 2.6
414
int (*utimens) (const char *, const struct timespec tv[2]);
417
* Map block index within file to block index within device
419
* Note: This makes sense only for block device backed filesystems
420
* mounted with the 'blkdev' option
422
* Introduced in version 2.6
424
int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
80
/** Get file attributes.
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.
86
int (*getattr) (const char *, struct stat *);
88
/** Read the target of a symbolic link
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
96
int (*readlink) (const char *, char *, size_t);
98
/* Deprecated, use readdir() instead */
99
int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
101
/** Create a file node
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.
107
int (*mknod) (const char *, mode_t, dev_t);
109
/** Create a directory */
110
int (*mkdir) (const char *, mode_t);
113
int (*unlink) (const char *);
115
/** Remove a directory */
116
int (*rmdir) (const char *);
118
/** Create a symbolic link */
119
int (*symlink) (const char *, const char *);
122
int (*rename) (const char *, const char *);
124
/** Create a hard link to a file */
125
int (*link) (const char *, const char *);
127
/** Change the permission bits of a file */
128
int (*chmod) (const char *, mode_t);
130
/** Change the owner and group of a file */
131
int (*chown) (const char *, uid_t, gid_t);
133
/** Change the size of a file */
134
int (*truncate) (const char *, off_t);
136
/** Change the access and/or modification times of a file
138
* Deprecated, use utimens() instead.
140
int (*utime) (const char *, struct utimbuf *);
142
/** File open operation
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.
150
* Changed in version 2.2
152
int (*open) (const char *, struct fuse_file_info *);
154
/** Read data from an open file
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
163
* Changed in version 2.2
165
int (*read) (const char *, char *, size_t, off_t,
166
struct fuse_file_info *);
168
/** Write data to an open file
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).
174
* Changed in version 2.2
176
int (*write) (const char *, const char *, size_t, off_t,
177
struct fuse_file_info *);
179
/** Get file system statistics
181
* The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
183
* Replaced 'struct statfs' parameter with 'struct statvfs' in
186
int (*statfs) (const char *, struct statvfs *);
188
/** Possibly flush cached data
190
* BIG NOTE: This is not equivalent to fsync(). It's not a
191
* request to sync dirty data.
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.
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.
206
* Filesystems shouldn't assume that flush will always be called
207
* after some writes, or that if will be called at all.
209
* Changed in version 2.2
211
int (*flush) (const char *, struct fuse_file_info *);
213
/** Release an open file
215
* Release is called when there are no more references to an open
216
* file: all file descriptors are closed and all memory mappings
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.
225
* Changed in version 2.2
227
int (*release) (const char *, struct fuse_file_info *);
229
/** Synchronize file contents
231
* If the datasync parameter is non-zero, then only the user data
232
* should be flushed, not the meta data.
234
* Changed in version 2.2
236
int (*fsync) (const char *, int, struct fuse_file_info *);
238
/** Set extended attributes */
239
int (*setxattr) (const char *, const char *, const char *, size_t, int);
241
/** Get extended attributes */
242
int (*getxattr) (const char *, const char *, char *, size_t);
244
/** List extended attributes */
245
int (*listxattr) (const char *, char *, size_t);
247
/** Remove extended attributes */
248
int (*removexattr) (const char *, const char *);
252
* This method should check if the open operation is permitted for
255
* Introduced in version 2.3
257
int (*opendir) (const char *, struct fuse_file_info *);
261
* This supersedes the old getdir() interface. New applications
264
* The filesystem may choose between two modes of operation:
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.
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
278
* Introduced in version 2.3
280
int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
281
struct fuse_file_info *);
283
/** Release directory
285
* Introduced in version 2.3
287
int (*releasedir) (const char *, struct fuse_file_info *);
289
/** Synchronize directory contents
291
* If the datasync parameter is non-zero, then only the user data
292
* should be flushed, not the meta data
294
* Introduced in version 2.3
296
int (*fsyncdir) (const char *, int, struct fuse_file_info *);
299
* Initialize filesystem
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
305
* Introduced in version 2.3
306
* Changed in version 2.6
308
void *(*init) (struct fuse_conn_info *conn);
311
* Clean up filesystem
313
* Called on filesystem exit.
315
* Introduced in version 2.3
317
void (*destroy) (void *);
320
* Check file access permissions
322
* This will be called for the access() system call. If the
323
* 'default_permissions' mount option is given, this method is not
326
* This method is not called under Linux kernel versions 2.4.x
328
* Introduced in version 2.5
330
int (*access) (const char *, int);
333
* Create and open a file
335
* If the file does not exist, first create it with the specified
336
* mode, and then open it.
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.
342
* Introduced in version 2.5
344
int (*create) (const char *, mode_t, struct fuse_file_info *);
347
* Change the size of an open file
349
* This method is called instead of the truncate() method if the
350
* truncation was invoked from an ftruncate() system call.
352
* If this method is not implemented or under Linux kernel
353
* versions earlier than 2.6.15, the truncate() method will be
356
* Introduced in version 2.5
358
int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
361
* Get attributes from an open file
363
* This method is called instead of the getattr() method if the
364
* file information is available.
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.
370
* Introduced in version 2.5
372
int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
375
* Perform POSIX file locking operation
377
* The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
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
383
* For checking lock ownership, the 'fuse_file_info->owner'
384
* argument must be used.
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.
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.
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.
404
* Introduced in version 2.6
406
int (*lock) (const char *, struct fuse_file_info *, int cmd,
410
* Change the access and modification times of a file with
411
* nanosecond resolution
413
* Introduced in version 2.6
415
int (*utimens) (const char *, const struct timespec tv[2]);
418
* Map block index within file to block index within device
420
* Note: This makes sense only for block device backed filesystems
421
* mounted with the 'blkdev' option
423
* Introduced in version 2.6
425
int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
427
428
/** Extra context that may be needed by some filesystems
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,
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,
644
645
int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
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,
653
654
int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
655
656
int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
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);