libfuse
fuse.h
Go to the documentation of this file.
1 /*
2  FUSE: Filesystem in Userspace
3  Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
4 
5  This program can be distributed under the terms of the GNU LGPLv2.
6  See the file COPYING.LIB.
7 */
8 
9 #ifndef FUSE_H_
10 #define FUSE_H_
11 
19 #include "fuse_common.h"
20 
21 #include <fcntl.h>
22 #include <time.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <sys/statvfs.h>
26 #include <sys/uio.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /* ----------------------------------------------------------- *
33  * Basic FUSE API *
34  * ----------------------------------------------------------- */
35 
37 struct fuse;
38 
51  FUSE_READDIR_PLUS = (1 << 0)
52 };
53 
67  FUSE_FILL_DIR_PLUS = (1 << 1)
68 };
69 
85 typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
86  const struct stat *stbuf, off_t off,
87  enum fuse_fill_dir_flags flags);
96 struct fuse_config {
101  int set_gid;
102  unsigned int gid;
103 
108  int set_uid;
109  unsigned int uid;
110 
115  int set_mode;
116  unsigned int umask;
117 
122  double entry_timeout;
123 
132  double negative_timeout;
133 
138  double attr_timeout;
139 
143  int intr;
144 
150  int intr_signal;
151 
162  int remember;
163 
180  int hard_remove;
181 
193  int use_ino;
194 
202  int readdir_ino;
203 
221  int direct_io;
222 
240  int kernel_cache;
241 
248  int auto_cache;
249 
257 
264  double ac_attr_timeout;
265 
276  int nullpath_ok;
277 
282  int show_help;
283  char *modules;
284  int debug;
285 };
286 
287 
310 struct fuse_operations {
322  int (*getattr) (const char *, struct stat *, struct fuse_file_info *fi);
323 
332  int (*readlink) (const char *, char *, size_t);
333 
340  int (*mknod) (const char *, mode_t, dev_t);
341 
348  int (*mkdir) (const char *, mode_t);
349 
351  int (*unlink) (const char *);
352 
354  int (*rmdir) (const char *);
355 
357  int (*symlink) (const char *, const char *);
358 
368  int (*rename) (const char *, const char *, unsigned int flags);
369 
371  int (*link) (const char *, const char *);
372 
378  int (*chmod) (const char *, mode_t, struct fuse_file_info *fi);
379 
388  int (*chown) (const char *, uid_t, gid_t, struct fuse_file_info *fi);
389 
398  int (*truncate) (const char *, off_t, struct fuse_file_info *fi);
399 
447  int (*open) (const char *, struct fuse_file_info *);
448 
458  int (*read) (const char *, char *, size_t, off_t,
459  struct fuse_file_info *);
460 
470  int (*write) (const char *, const char *, size_t, off_t,
471  struct fuse_file_info *);
472 
477  int (*statfs) (const char *, struct statvfs *);
478 
507  int (*flush) (const char *, struct fuse_file_info *);
508 
521  int (*release) (const char *, struct fuse_file_info *);
522 
528  int (*fsync) (const char *, int, struct fuse_file_info *);
529 
531  int (*setxattr) (const char *, const char *, const char *, size_t, int);
532 
534  int (*getxattr) (const char *, const char *, char *, size_t);
535 
537  int (*listxattr) (const char *, char *, size_t);
538 
540  int (*removexattr) (const char *, const char *);
541 
550  int (*opendir) (const char *, struct fuse_file_info *);
551 
574  int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
575  struct fuse_file_info *, enum fuse_readdir_flags);
576 
582  int (*releasedir) (const char *, struct fuse_file_info *);
583 
592  int (*fsyncdir) (const char *, int, struct fuse_file_info *);
593 
602  void *(*init) (struct fuse_conn_info *conn,
603  struct fuse_config *cfg);
604 
610  void (*destroy) (void *private_data);
611 
621  int (*access) (const char *, int);
622 
633  int (*create) (const char *, mode_t, struct fuse_file_info *);
634 
665  int (*lock) (const char *, struct fuse_file_info *, int cmd,
666  struct flock *);
667 
680  int (*utimens) (const char *, const struct timespec tv[2],
681  struct fuse_file_info *fi);
682 
689  int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
690 
691 #if FUSE_USE_VERSION < 35
692  int (*ioctl) (const char *, int cmd, void *arg,
693  struct fuse_file_info *, unsigned int flags, void *data);
694 #else
711  int (*ioctl) (const char *, unsigned int cmd, void *arg,
712  struct fuse_file_info *, unsigned int flags, void *data);
713 #endif
714 
730  int (*poll) (const char *, struct fuse_file_info *,
731  struct fuse_pollhandle *ph, unsigned *reventsp);
732 
742  int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off,
743  struct fuse_file_info *);
744 
759  int (*read_buf) (const char *, struct fuse_bufvec **bufp,
760  size_t size, off_t off, struct fuse_file_info *);
779  int (*flock) (const char *, struct fuse_file_info *, int op);
780 
789  int (*fallocate) (const char *, int, off_t, off_t,
790  struct fuse_file_info *);
791 
804  ssize_t (*copy_file_range) (const char *path_in,
805  struct fuse_file_info *fi_in,
806  off_t offset_in, const char *path_out,
807  struct fuse_file_info *fi_out,
808  off_t offset_out, size_t size, int flags);
809 
813  off_t (*lseek) (const char *, off_t off, int whence, struct fuse_file_info *);
814 };
815 
821 struct fuse_context {
823  struct fuse *fuse;
824 
826  uid_t uid;
827 
829  gid_t gid;
830 
832  pid_t pid;
833 
835  void *private_data;
836 
838  mode_t umask;
839 };
840 
895 /*
896  int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
897  void *private_data);
898 */
899 #define fuse_main(argc, argv, op, private_data) \
900  fuse_main_real(argc, argv, op, sizeof(*(op)), private_data)
901 
902 /* ----------------------------------------------------------- *
903  * More detailed API *
904  * ----------------------------------------------------------- */
905 
917 void fuse_lib_help(struct fuse_args *args);
918 
946 #if FUSE_USE_VERSION == 30
947 struct fuse *fuse_new_30(struct fuse_args *args, const struct fuse_operations *op,
948  size_t op_size, void *private_data);
949 #define fuse_new(args, op, size, data) fuse_new_30(args, op, size, data)
950 #else
951 struct fuse *fuse_new(struct fuse_args *args, const struct fuse_operations *op,
952  size_t op_size, void *private_data);
953 #endif
954 
963 int fuse_mount(struct fuse *f, const char *mountpoint);
964 
972 void fuse_unmount(struct fuse *f);
973 
982 void fuse_destroy(struct fuse *f);
983 
999 int fuse_loop(struct fuse *f);
1000 
1009 void fuse_exit(struct fuse *f);
1010 
1011 #if FUSE_USE_VERSION < 32
1012 int fuse_loop_mt_31(struct fuse *f, int clone_fd);
1013 #define fuse_loop_mt(f, clone_fd) fuse_loop_mt_31(f, clone_fd)
1014 #else
1046 int fuse_loop_mt(struct fuse *f, struct fuse_loop_config *config);
1047 #endif
1048 
1057 struct fuse_context *fuse_get_context(void);
1058 
1077 int fuse_getgroups(int size, gid_t list[]);
1078 
1084 int fuse_interrupted(void);
1085 
1097 int fuse_invalidate_path(struct fuse *f, const char *path);
1098 
1104 int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
1105  size_t op_size, void *private_data);
1106 
1114 int fuse_start_cleanup_thread(struct fuse *fuse);
1115 
1122 void fuse_stop_cleanup_thread(struct fuse *fuse);
1123 
1133 int fuse_clean_cache(struct fuse *fuse);
1134 
1135 /*
1136  * Stacking API
1137  */
1138 
1144 struct fuse_fs;
1145 
1146 /*
1147  * These functions call the relevant filesystem operation, and return
1148  * the result.
1149  *
1150  * If the operation is not defined, they return -ENOSYS, with the
1151  * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
1152  * fuse_fs_releasedir and fuse_fs_statfs, which return 0.
1153  */
1154 
1155 int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf,
1156  struct fuse_file_info *fi);
1157 int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
1158  const char *newpath, unsigned int flags);
1159 int fuse_fs_unlink(struct fuse_fs *fs, const char *path);
1160 int fuse_fs_rmdir(struct fuse_fs *fs, const char *path);
1161 int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname,
1162  const char *path);
1163 int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath);
1164 int fuse_fs_release(struct fuse_fs *fs, const char *path,
1165  struct fuse_file_info *fi);
1166 int fuse_fs_open(struct fuse_fs *fs, const char *path,
1167  struct fuse_file_info *fi);
1168 int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size,
1169  off_t off, struct fuse_file_info *fi);
1170 int fuse_fs_read_buf(struct fuse_fs *fs, const char *path,
1171  struct fuse_bufvec **bufp, size_t size, off_t off,
1172  struct fuse_file_info *fi);
1173 int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf,
1174  size_t size, off_t off, struct fuse_file_info *fi);
1175 int fuse_fs_write_buf(struct fuse_fs *fs, const char *path,
1176  struct fuse_bufvec *buf, off_t off,
1177  struct fuse_file_info *fi);
1178 int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync,
1179  struct fuse_file_info *fi);
1180 int fuse_fs_flush(struct fuse_fs *fs, const char *path,
1181  struct fuse_file_info *fi);
1182 int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf);
1183 int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
1184  struct fuse_file_info *fi);
1185 int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf,
1186  fuse_fill_dir_t filler, off_t off,
1187  struct fuse_file_info *fi, enum fuse_readdir_flags flags);
1188 int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync,
1189  struct fuse_file_info *fi);
1190 int fuse_fs_releasedir(struct fuse_fs *fs, const char *path,
1191  struct fuse_file_info *fi);
1192 int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode,
1193  struct fuse_file_info *fi);
1194 int fuse_fs_lock(struct fuse_fs *fs, const char *path,
1195  struct fuse_file_info *fi, int cmd, struct flock *lock);
1196 int fuse_fs_flock(struct fuse_fs *fs, const char *path,
1197  struct fuse_file_info *fi, int op);
1198 int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode,
1199  struct fuse_file_info *fi);
1200 int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid,
1201  struct fuse_file_info *fi);
1202 int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size,
1203  struct fuse_file_info *fi);
1204 int fuse_fs_utimens(struct fuse_fs *fs, const char *path,
1205  const struct timespec tv[2], struct fuse_file_info *fi);
1206 int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask);
1207 int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf,
1208  size_t len);
1209 int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
1210  dev_t rdev);
1211 int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode);
1212 int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name,
1213  const char *value, size_t size, int flags);
1214 int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name,
1215  char *value, size_t size);
1216 int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list,
1217  size_t size);
1218 int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
1219  const char *name);
1220 int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
1221  uint64_t *idx);
1222 #if FUSE_USE_VERSION < 35
1223 int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd,
1224  void *arg, struct fuse_file_info *fi, unsigned int flags,
1225  void *data);
1226 #else
1227 int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, unsigned int cmd,
1228  void *arg, struct fuse_file_info *fi, unsigned int flags,
1229  void *data);
1230 #endif
1231 int fuse_fs_poll(struct fuse_fs *fs, const char *path,
1232  struct fuse_file_info *fi, struct fuse_pollhandle *ph,
1233  unsigned *reventsp);
1234 int fuse_fs_fallocate(struct fuse_fs *fs, const char *path, int mode,
1235  off_t offset, off_t length, struct fuse_file_info *fi);
1236 ssize_t fuse_fs_copy_file_range(struct fuse_fs *fs, const char *path_in,
1237  struct fuse_file_info *fi_in, off_t off_in,
1238  const char *path_out,
1239  struct fuse_file_info *fi_out, off_t off_out,
1240  size_t len, int flags);
1241 off_t fuse_fs_lseek(struct fuse_fs *fs, const char *path, off_t off, int whence,
1242  struct fuse_file_info *fi);
1243 void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn,
1244  struct fuse_config *cfg);
1245 void fuse_fs_destroy(struct fuse_fs *fs);
1246 
1247 int fuse_notify_poll(struct fuse_pollhandle *ph);
1248 
1262 struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
1263  void *private_data);
1264 
1279 typedef struct fuse_fs *(*fuse_module_factory_t)(struct fuse_args *args,
1280  struct fuse_fs *fs[]);
1291 #define FUSE_REGISTER_MODULE(name_, factory_) \
1292  fuse_module_factory_t fuse_module_ ## name_ ## _factory = factory_
1293 
1295 struct fuse_session *fuse_get_session(struct fuse *f);
1296 
1305 int fuse_open_channel(const char *mountpoint, const char *options);
1306 
1307 #ifdef __cplusplus
1308 }
1309 #endif
1310 
1311 #endif /* FUSE_H_ */
struct fuse_session * fuse_get_session(struct fuse *f)
Definition: fuse.c:4509
int fuse_getgroups(int size, gid_t list[])
Definition: fuse.c:4617
int fuse_mount(struct fuse *f, const char *mountpoint)
Definition: fuse.c:5108
int fuse_interrupted(void)
Definition: fuse.c:4626
void fuse_destroy(struct fuse *f)
Definition: fuse.c:5058
int fuse_start_cleanup_thread(struct fuse *fuse)
Definition: fuse.c:4859
int fuse_invalidate_path(struct fuse *f, const char *path)
Definition: fuse.c:4636
int fuse_loop(struct fuse *f)
Definition: fuse.c:4566
struct fuse_fs * fuse_fs_new(const struct fuse_operations *op, size_t op_size, void *private_data)
Definition: fuse.c:4811
int(* fuse_fill_dir_t)(void *buf, const char *name, const struct stat *stbuf, off_t off, enum fuse_fill_dir_flags flags)
Definition: fuse.h:85
void fuse_exit(struct fuse *f)
Definition: fuse.c:4602
int fuse_clean_cache(struct fuse *fuse)
Definition: fuse.c:4422
struct fuse_context * fuse_get_context(void)
Definition: fuse.c:4607
void fuse_lib_help(struct fuse_args *args)
Definition: fuse.c:4701
int fuse_open_channel(const char *mountpoint, const char *options)
Definition: helper.c:424
void fuse_unmount(struct fuse *f)
Definition: fuse.c:5113
int fuse_loop_mt(struct fuse *f, struct fuse_loop_config *config)
void fuse_stop_cleanup_thread(struct fuse *fuse)
Definition: fuse.c:4867
struct fuse * fuse_new(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *private_data)
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *private_data)
Definition: helper.c:279
fuse_fill_dir_flags
Definition: fuse.h:57
@ FUSE_FILL_DIR_PLUS
Definition: fuse.h:67
fuse_readdir_flags
Definition: fuse.h:42
@ FUSE_READDIR_PLUS
Definition: fuse.h:51
size_t off
Definition: fuse_common.h:757
struct fuse_buf buf[1]
Definition: fuse_common.h:762
int remember
Definition: fuse.h:162
int set_uid
Definition: fuse.h:108
int set_gid
Definition: fuse.h:101
int ac_attr_timeout_set
Definition: fuse.h:255
double entry_timeout
Definition: fuse.h:122
int intr_signal
Definition: fuse.h:150
int intr
Definition: fuse.h:143
int auto_cache
Definition: fuse.h:248
double negative_timeout
Definition: fuse.h:132
int kernel_cache
Definition: fuse.h:240
int set_mode
Definition: fuse.h:115
int readdir_ino
Definition: fuse.h:202
int nullpath_ok
Definition: fuse.h:268
int use_ino
Definition: fuse.h:193
int no_rofd_flush
Definition: fuse.h:256
int direct_io
Definition: fuse.h:221
double attr_timeout
Definition: fuse.h:138
int hard_remove
Definition: fuse.h:180
int show_help
Definition: fuse.h:274
void * private_data
Definition: fuse.h:814
uid_t uid
Definition: fuse.h:805
pid_t pid
Definition: fuse.h:811
struct fuse * fuse
Definition: fuse.h:802
gid_t gid
Definition: fuse.h:808
mode_t umask
Definition: fuse.h:817
int(* mkdir)(const char *, mode_t)
Definition: fuse.h:340
int(* truncate)(const char *, off_t, struct fuse_file_info *fi)
Definition: fuse.h:390
int(* mknod)(const char *, mode_t, dev_t)
Definition: fuse.h:332
int(* utimens)(const char *, const struct timespec tv[2], struct fuse_file_info *fi)
Definition: fuse.h:659
int(* open)(const char *, struct fuse_file_info *)
Definition: fuse.h:439
int(* opendir)(const char *, struct fuse_file_info *)
Definition: fuse.h:542
int(* link)(const char *, const char *)
Definition: fuse.h:363
int(* lock)(const char *, struct fuse_file_info *, int cmd, struct flock *)
Definition: fuse.h:644
int(* read_buf)(const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *)
Definition: fuse.h:738
int(* access)(const char *, int)
Definition: fuse.h:600
int(* read)(const char *, char *, size_t, off_t, struct fuse_file_info *)
Definition: fuse.h:450
int(* poll)(const char *, struct fuse_file_info *, struct fuse_pollhandle *ph, unsigned *reventsp)
Definition: fuse.h:709
void(* destroy)(void *private_data)
Definition: fuse.h:589
int(* statfs)(const char *, struct statvfs *)
Definition: fuse.h:469
int(* fallocate)(const char *, int, off_t, off_t, struct fuse_file_info *)
Definition: fuse.h:768
int(* removexattr)(const char *, const char *)
Definition: fuse.h:532
int(* getattr)(const char *, struct stat *, struct fuse_file_info *fi)
Definition: fuse.h:314
int(* releasedir)(const char *, struct fuse_file_info *)
Definition: fuse.h:564
int(* rename)(const char *, const char *, unsigned int flags)
Definition: fuse.h:360
off_t(* lseek)(const char *, off_t off, int whence, struct fuse_file_info *)
Definition: fuse.h:792
int(* write)(const char *, const char *, size_t, off_t, struct fuse_file_info *)
Definition: fuse.h:462
int(* write_buf)(const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *)
Definition: fuse.h:721
int(* unlink)(const char *)
Definition: fuse.h:343
ssize_t(* copy_file_range)(const char *path_in, struct fuse_file_info *fi_in, off_t offset_in, const char *path_out, struct fuse_file_info *fi_out, off_t offset_out, size_t size, int flags)
Definition: fuse.h:783
int(* fsync)(const char *, int, struct fuse_file_info *)
Definition: fuse.h:520
int(* create)(const char *, mode_t, struct fuse_file_info *)
Definition: fuse.h:612
int(* setxattr)(const char *, const char *, const char *, size_t, int)
Definition: fuse.h:523
int(* listxattr)(const char *, char *, size_t)
Definition: fuse.h:529
int(* readlink)(const char *, char *, size_t)
Definition: fuse.h:324
int(* symlink)(const char *, const char *)
Definition: fuse.h:349
int(* fsyncdir)(const char *, int, struct fuse_file_info *)
Definition: fuse.h:571
int(* release)(const char *, struct fuse_file_info *)
Definition: fuse.h:513
int(* chown)(const char *, uid_t, gid_t, struct fuse_file_info *fi)
Definition: fuse.h:380
int(* chmod)(const char *, mode_t, struct fuse_file_info *fi)
Definition: fuse.h:370
int(* rmdir)(const char *)
Definition: fuse.h:346
int(* flush)(const char *, struct fuse_file_info *)
Definition: fuse.h:499
int(* flock)(const char *, struct fuse_file_info *, int op)
Definition: fuse.h:758
int(* ioctl)(const char *, unsigned int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void *data)
Definition: fuse.h:690
int(* readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *, enum fuse_readdir_flags)
Definition: fuse.h:559
int(* getxattr)(const char *, const char *, char *, size_t)
Definition: fuse.h:526
int(* bmap)(const char *, size_t blocksize, uint64_t *idx)
Definition: fuse.h:668