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 
123 
133 
138  double attr_timeout;
139 
143  int intr;
144 
151 
162  int remember;
163 
181 
193  int use_ino;
194 
203 
222 
241 
249 
256  double ac_attr_timeout;
257 
269 
275  char *modules;
276  int debug;
277 };
278 
279 
314  int (*getattr) (const char *, struct stat *, struct fuse_file_info *fi);
315 
324  int (*readlink) (const char *, char *, size_t);
325 
332  int (*mknod) (const char *, mode_t, dev_t);
333 
340  int (*mkdir) (const char *, mode_t);
341 
343  int (*unlink) (const char *);
344 
346  int (*rmdir) (const char *);
347 
349  int (*symlink) (const char *, const char *);
350 
360  int (*rename) (const char *, const char *, unsigned int flags);
361 
363  int (*link) (const char *, const char *);
364 
370  int (*chmod) (const char *, mode_t, struct fuse_file_info *fi);
371 
380  int (*chown) (const char *, uid_t, gid_t, struct fuse_file_info *fi);
381 
390  int (*truncate) (const char *, off_t, struct fuse_file_info *fi);
391 
439  int (*open) (const char *, struct fuse_file_info *);
440 
450  int (*read) (const char *, char *, size_t, off_t,
451  struct fuse_file_info *);
452 
462  int (*write) (const char *, const char *, size_t, off_t,
463  struct fuse_file_info *);
464 
469  int (*statfs) (const char *, struct statvfs *);
470 
499  int (*flush) (const char *, struct fuse_file_info *);
500 
513  int (*release) (const char *, struct fuse_file_info *);
514 
520  int (*fsync) (const char *, int, struct fuse_file_info *);
521 
523  int (*setxattr) (const char *, const char *, const char *, size_t, int);
524 
526  int (*getxattr) (const char *, const char *, char *, size_t);
527 
529  int (*listxattr) (const char *, char *, size_t);
530 
532  int (*removexattr) (const char *, const char *);
533 
542  int (*opendir) (const char *, struct fuse_file_info *);
543 
559  int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
560  struct fuse_file_info *, enum fuse_readdir_flags);
561 
564  int (*releasedir) (const char *, struct fuse_file_info *);
565 
571  int (*fsyncdir) (const char *, int, struct fuse_file_info *);
572 
581  void *(*init) (struct fuse_conn_info *conn,
582  struct fuse_config *cfg);
583 
589  void (*destroy) (void *private_data);
590 
600  int (*access) (const char *, int);
601 
612  int (*create) (const char *, mode_t, struct fuse_file_info *);
613 
644  int (*lock) (const char *, struct fuse_file_info *, int cmd,
645  struct flock *);
646 
659  int (*utimens) (const char *, const struct timespec tv[2],
660  struct fuse_file_info *fi);
661 
668  int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
669 
670 #if FUSE_USE_VERSION < 35
671  int (*ioctl) (const char *, int cmd, void *arg,
672  struct fuse_file_info *, unsigned int flags, void *data);
673 #else
690  int (*ioctl) (const char *, unsigned int cmd, void *arg,
691  struct fuse_file_info *, unsigned int flags, void *data);
692 #endif
693 
709  int (*poll) (const char *, struct fuse_file_info *,
710  struct fuse_pollhandle *ph, unsigned *reventsp);
711 
721  int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off,
722  struct fuse_file_info *);
723 
738  int (*read_buf) (const char *, struct fuse_bufvec **bufp,
739  size_t size, off_t off, struct fuse_file_info *);
758  int (*flock) (const char *, struct fuse_file_info *, int op);
759 
768  int (*fallocate) (const char *, int, off_t, off_t,
769  struct fuse_file_info *);
770 
783  ssize_t (*copy_file_range) (const char *path_in,
784  struct fuse_file_info *fi_in,
785  off_t offset_in, const char *path_out,
786  struct fuse_file_info *fi_out,
787  off_t offset_out, size_t size, int flags);
788 
792  off_t (*lseek) (const char *, off_t off, int whence, struct fuse_file_info *);
793 };
794 
800 struct fuse_context {
802  struct fuse *fuse;
803 
805  uid_t uid;
806 
808  gid_t gid;
809 
811  pid_t pid;
812 
815 
817  mode_t umask;
818 };
819 
874 /*
875  int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
876  void *private_data);
877 */
878 #define fuse_main(argc, argv, op, private_data) \
879  fuse_main_real(argc, argv, op, sizeof(*(op)), private_data)
880 
881 /* ----------------------------------------------------------- *
882  * More detailed API *
883  * ----------------------------------------------------------- */
884 
896 void fuse_lib_help(struct fuse_args *args);
897 
925 #if FUSE_USE_VERSION == 30
926 struct fuse *fuse_new_30(struct fuse_args *args, const struct fuse_operations *op,
927  size_t op_size, void *private_data);
928 #define fuse_new(args, op, size, data) fuse_new_30(args, op, size, data)
929 #else
930 struct fuse *fuse_new(struct fuse_args *args, const struct fuse_operations *op,
931  size_t op_size, void *private_data);
932 #endif
933 
942 int fuse_mount(struct fuse *f, const char *mountpoint);
943 
951 void fuse_unmount(struct fuse *f);
952 
961 void fuse_destroy(struct fuse *f);
962 
978 int fuse_loop(struct fuse *f);
979 
988 void fuse_exit(struct fuse *f);
989 
990 #if FUSE_USE_VERSION < 32
991 int fuse_loop_mt_31(struct fuse *f, int clone_fd);
992 #define fuse_loop_mt(f, clone_fd) fuse_loop_mt_31(f, clone_fd)
993 #else
1025 int fuse_loop_mt(struct fuse *f, struct fuse_loop_config *config);
1026 #endif
1027 
1036 struct fuse_context *fuse_get_context(void);
1037 
1056 int fuse_getgroups(int size, gid_t list[]);
1057 
1063 int fuse_interrupted(void);
1064 
1076 int fuse_invalidate_path(struct fuse *f, const char *path);
1077 
1083 int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
1084  size_t op_size, void *private_data);
1085 
1093 int fuse_start_cleanup_thread(struct fuse *fuse);
1094 
1101 void fuse_stop_cleanup_thread(struct fuse *fuse);
1102 
1112 int fuse_clean_cache(struct fuse *fuse);
1113 
1114 /*
1115  * Stacking API
1116  */
1117 
1123 struct fuse_fs;
1124 
1125 /*
1126  * These functions call the relevant filesystem operation, and return
1127  * the result.
1128  *
1129  * If the operation is not defined, they return -ENOSYS, with the
1130  * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
1131  * fuse_fs_releasedir and fuse_fs_statfs, which return 0.
1132  */
1133 
1134 int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf,
1135  struct fuse_file_info *fi);
1136 int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
1137  const char *newpath, unsigned int flags);
1138 int fuse_fs_unlink(struct fuse_fs *fs, const char *path);
1139 int fuse_fs_rmdir(struct fuse_fs *fs, const char *path);
1140 int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname,
1141  const char *path);
1142 int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath);
1143 int fuse_fs_release(struct fuse_fs *fs, const char *path,
1144  struct fuse_file_info *fi);
1145 int fuse_fs_open(struct fuse_fs *fs, const char *path,
1146  struct fuse_file_info *fi);
1147 int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size,
1148  off_t off, struct fuse_file_info *fi);
1149 int fuse_fs_read_buf(struct fuse_fs *fs, const char *path,
1150  struct fuse_bufvec **bufp, size_t size, off_t off,
1151  struct fuse_file_info *fi);
1152 int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf,
1153  size_t size, off_t off, struct fuse_file_info *fi);
1154 int fuse_fs_write_buf(struct fuse_fs *fs, const char *path,
1155  struct fuse_bufvec *buf, off_t off,
1156  struct fuse_file_info *fi);
1157 int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync,
1158  struct fuse_file_info *fi);
1159 int fuse_fs_flush(struct fuse_fs *fs, const char *path,
1160  struct fuse_file_info *fi);
1161 int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf);
1162 int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
1163  struct fuse_file_info *fi);
1164 int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf,
1165  fuse_fill_dir_t filler, off_t off,
1166  struct fuse_file_info *fi, enum fuse_readdir_flags flags);
1167 int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync,
1168  struct fuse_file_info *fi);
1169 int fuse_fs_releasedir(struct fuse_fs *fs, const char *path,
1170  struct fuse_file_info *fi);
1171 int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode,
1172  struct fuse_file_info *fi);
1173 int fuse_fs_lock(struct fuse_fs *fs, const char *path,
1174  struct fuse_file_info *fi, int cmd, struct flock *lock);
1175 int fuse_fs_flock(struct fuse_fs *fs, const char *path,
1176  struct fuse_file_info *fi, int op);
1177 int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode,
1178  struct fuse_file_info *fi);
1179 int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid,
1180  struct fuse_file_info *fi);
1181 int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size,
1182  struct fuse_file_info *fi);
1183 int fuse_fs_utimens(struct fuse_fs *fs, const char *path,
1184  const struct timespec tv[2], struct fuse_file_info *fi);
1185 int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask);
1186 int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf,
1187  size_t len);
1188 int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
1189  dev_t rdev);
1190 int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode);
1191 int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name,
1192  const char *value, size_t size, int flags);
1193 int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name,
1194  char *value, size_t size);
1195 int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list,
1196  size_t size);
1197 int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
1198  const char *name);
1199 int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
1200  uint64_t *idx);
1201 #if FUSE_USE_VERSION < 35
1202 int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd,
1203  void *arg, struct fuse_file_info *fi, unsigned int flags,
1204  void *data);
1205 #else
1206 int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, unsigned int cmd,
1207  void *arg, struct fuse_file_info *fi, unsigned int flags,
1208  void *data);
1209 #endif
1210 int fuse_fs_poll(struct fuse_fs *fs, const char *path,
1211  struct fuse_file_info *fi, struct fuse_pollhandle *ph,
1212  unsigned *reventsp);
1213 int fuse_fs_fallocate(struct fuse_fs *fs, const char *path, int mode,
1214  off_t offset, off_t length, struct fuse_file_info *fi);
1215 ssize_t fuse_fs_copy_file_range(struct fuse_fs *fs, const char *path_in,
1216  struct fuse_file_info *fi_in, off_t off_in,
1217  const char *path_out,
1218  struct fuse_file_info *fi_out, off_t off_out,
1219  size_t len, int flags);
1220 off_t fuse_fs_lseek(struct fuse_fs *fs, const char *path, off_t off, int whence,
1221  struct fuse_file_info *fi);
1222 void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn,
1223  struct fuse_config *cfg);
1224 void fuse_fs_destroy(struct fuse_fs *fs);
1225 
1226 int fuse_notify_poll(struct fuse_pollhandle *ph);
1227 
1241 struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
1242  void *private_data);
1243 
1258 typedef struct fuse_fs *(*fuse_module_factory_t)(struct fuse_args *args,
1259  struct fuse_fs *fs[]);
1270 #define FUSE_REGISTER_MODULE(name_, factory_) \
1271  fuse_module_factory_t fuse_module_ ## name_ ## _factory = factory_
1272 
1274 struct fuse_session *fuse_get_session(struct fuse *f);
1275 
1284 int fuse_open_channel(const char *mountpoint, const char *options);
1285 
1286 #ifdef __cplusplus
1287 }
1288 #endif
1289 
1290 #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 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