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 
64  FUSE_FILL_DIR_PLUS = (1 << 1)
65 };
66 
82 typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
83  const struct stat *stbuf, off_t off,
84  enum fuse_fill_dir_flags flags);
93 struct fuse_config {
98  int set_gid;
99  unsigned int gid;
100 
105  int set_uid;
106  unsigned int uid;
107 
112  int set_mode;
113  unsigned int umask;
114 
119  double entry_timeout;
120 
129  double negative_timeout;
130 
135  double attr_timeout;
136 
140  int intr;
141 
147  int intr_signal;
148 
159  int remember;
160 
177  int hard_remove;
178 
190  int use_ino;
191 
199  int readdir_ino;
200 
218  int direct_io;
219 
237  int kernel_cache;
238 
245  int auto_cache;
246 
253  double ac_attr_timeout;
254 
265  int nullpath_ok;
266 
271  int show_help;
272  char *modules;
273  int debug;
274 };
275 
276 
299 struct fuse_operations {
311  int (*getattr) (const char *, struct stat *, struct fuse_file_info *fi);
312 
321  int (*readlink) (const char *, char *, size_t);
322 
329  int (*mknod) (const char *, mode_t, dev_t);
330 
337  int (*mkdir) (const char *, mode_t);
338 
340  int (*unlink) (const char *);
341 
343  int (*rmdir) (const char *);
344 
346  int (*symlink) (const char *, const char *);
347 
357  int (*rename) (const char *, const char *, unsigned int flags);
358 
360  int (*link) (const char *, const char *);
361 
367  int (*chmod) (const char *, mode_t, struct fuse_file_info *fi);
368 
377  int (*chown) (const char *, uid_t, gid_t, struct fuse_file_info *fi);
378 
387  int (*truncate) (const char *, off_t, struct fuse_file_info *fi);
388 
436  int (*open) (const char *, struct fuse_file_info *);
437 
447  int (*read) (const char *, char *, size_t, off_t,
448  struct fuse_file_info *);
449 
459  int (*write) (const char *, const char *, size_t, off_t,
460  struct fuse_file_info *);
461 
466  int (*statfs) (const char *, struct statvfs *);
467 
496  int (*flush) (const char *, struct fuse_file_info *);
497 
510  int (*release) (const char *, struct fuse_file_info *);
511 
517  int (*fsync) (const char *, int, struct fuse_file_info *);
518 
520  int (*setxattr) (const char *, const char *, const char *, size_t, int);
521 
523  int (*getxattr) (const char *, const char *, char *, size_t);
524 
526  int (*listxattr) (const char *, char *, size_t);
527 
529  int (*removexattr) (const char *, const char *);
530 
539  int (*opendir) (const char *, struct fuse_file_info *);
540 
556  int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
557  struct fuse_file_info *, enum fuse_readdir_flags);
558 
561  int (*releasedir) (const char *, struct fuse_file_info *);
562 
568  int (*fsyncdir) (const char *, int, struct fuse_file_info *);
569 
578  void *(*init) (struct fuse_conn_info *conn,
579  struct fuse_config *cfg);
580 
586  void (*destroy) (void *private_data);
587 
597  int (*access) (const char *, int);
598 
609  int (*create) (const char *, mode_t, struct fuse_file_info *);
610 
641  int (*lock) (const char *, struct fuse_file_info *, int cmd,
642  struct flock *);
643 
656  int (*utimens) (const char *, const struct timespec tv[2],
657  struct fuse_file_info *fi);
658 
665  int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
666 
683 #if FUSE_USE_VERSION < 35
684  int (*ioctl) (const char *, int cmd, void *arg,
685  struct fuse_file_info *, unsigned int flags, void *data);
686 #else
687  int (*ioctl) (const char *, unsigned int cmd, void *arg,
688  struct fuse_file_info *, unsigned int flags, void *data);
689 #endif
690 
706  int (*poll) (const char *, struct fuse_file_info *,
707  struct fuse_pollhandle *ph, unsigned *reventsp);
708 
718  int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off,
719  struct fuse_file_info *);
720 
735  int (*read_buf) (const char *, struct fuse_bufvec **bufp,
736  size_t size, off_t off, struct fuse_file_info *);
755  int (*flock) (const char *, struct fuse_file_info *, int op);
756 
765  int (*fallocate) (const char *, int, off_t, off_t,
766  struct fuse_file_info *);
767 
780  ssize_t (*copy_file_range) (const char *path_in,
781  struct fuse_file_info *fi_in,
782  off_t offset_in, const char *path_out,
783  struct fuse_file_info *fi_out,
784  off_t offset_out, size_t size, int flags);
785 
789  off_t (*lseek) (const char *, off_t off, int whence, struct fuse_file_info *);
790 };
791 
797 struct fuse_context {
799  struct fuse *fuse;
800 
802  uid_t uid;
803 
805  gid_t gid;
806 
808  pid_t pid;
809 
811  void *private_data;
812 
814  mode_t umask;
815 };
816 
871 /*
872  int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
873  void *private_data);
874 */
875 #define fuse_main(argc, argv, op, private_data) \
876  fuse_main_real(argc, argv, op, sizeof(*(op)), private_data)
877 
878 /* ----------------------------------------------------------- *
879  * More detailed API *
880  * ----------------------------------------------------------- */
881 
893 void fuse_lib_help(struct fuse_args *args);
894 
922 #if FUSE_USE_VERSION == 30
923 struct fuse *fuse_new_30(struct fuse_args *args, const struct fuse_operations *op,
924  size_t op_size, void *private_data);
925 #define fuse_new(args, op, size, data) fuse_new_30(args, op, size, data)
926 #else
927 struct fuse *fuse_new(struct fuse_args *args, const struct fuse_operations *op,
928  size_t op_size, void *private_data);
929 #endif
930 
939 int fuse_mount(struct fuse *f, const char *mountpoint);
940 
948 void fuse_unmount(struct fuse *f);
949 
958 void fuse_destroy(struct fuse *f);
959 
975 int fuse_loop(struct fuse *f);
976 
985 void fuse_exit(struct fuse *f);
986 
1018 #if FUSE_USE_VERSION < 32
1019 int fuse_loop_mt_31(struct fuse *f, int clone_fd);
1020 #define fuse_loop_mt(f, clone_fd) fuse_loop_mt_31(f, clone_fd)
1021 #else
1022 int fuse_loop_mt(struct fuse *f, struct fuse_loop_config *config);
1023 #endif
1024 
1033 struct fuse_context *fuse_get_context(void);
1034 
1053 int fuse_getgroups(int size, gid_t list[]);
1054 
1060 int fuse_interrupted(void);
1061 
1073 int fuse_invalidate_path(struct fuse *f, const char *path);
1074 
1080 int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
1081  size_t op_size, void *private_data);
1082 
1090 int fuse_start_cleanup_thread(struct fuse *fuse);
1091 
1098 void fuse_stop_cleanup_thread(struct fuse *fuse);
1099 
1109 int fuse_clean_cache(struct fuse *fuse);
1110 
1111 /*
1112  * Stacking API
1113  */
1114 
1120 struct fuse_fs;
1121 
1122 /*
1123  * These functions call the relevant filesystem operation, and return
1124  * the result.
1125  *
1126  * If the operation is not defined, they return -ENOSYS, with the
1127  * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
1128  * fuse_fs_releasedir and fuse_fs_statfs, which return 0.
1129  */
1130 
1131 int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf,
1132  struct fuse_file_info *fi);
1133 int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
1134  const char *newpath, unsigned int flags);
1135 int fuse_fs_unlink(struct fuse_fs *fs, const char *path);
1136 int fuse_fs_rmdir(struct fuse_fs *fs, const char *path);
1137 int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname,
1138  const char *path);
1139 int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath);
1140 int fuse_fs_release(struct fuse_fs *fs, const char *path,
1141  struct fuse_file_info *fi);
1142 int fuse_fs_open(struct fuse_fs *fs, const char *path,
1143  struct fuse_file_info *fi);
1144 int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size,
1145  off_t off, struct fuse_file_info *fi);
1146 int fuse_fs_read_buf(struct fuse_fs *fs, const char *path,
1147  struct fuse_bufvec **bufp, size_t size, off_t off,
1148  struct fuse_file_info *fi);
1149 int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf,
1150  size_t size, off_t off, struct fuse_file_info *fi);
1151 int fuse_fs_write_buf(struct fuse_fs *fs, const char *path,
1152  struct fuse_bufvec *buf, off_t off,
1153  struct fuse_file_info *fi);
1154 int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync,
1155  struct fuse_file_info *fi);
1156 int fuse_fs_flush(struct fuse_fs *fs, const char *path,
1157  struct fuse_file_info *fi);
1158 int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf);
1159 int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
1160  struct fuse_file_info *fi);
1161 int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf,
1162  fuse_fill_dir_t filler, off_t off,
1163  struct fuse_file_info *fi, enum fuse_readdir_flags flags);
1164 int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync,
1165  struct fuse_file_info *fi);
1166 int fuse_fs_releasedir(struct fuse_fs *fs, const char *path,
1167  struct fuse_file_info *fi);
1168 int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode,
1169  struct fuse_file_info *fi);
1170 int fuse_fs_lock(struct fuse_fs *fs, const char *path,
1171  struct fuse_file_info *fi, int cmd, struct flock *lock);
1172 int fuse_fs_flock(struct fuse_fs *fs, const char *path,
1173  struct fuse_file_info *fi, int op);
1174 int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode,
1175  struct fuse_file_info *fi);
1176 int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid,
1177  struct fuse_file_info *fi);
1178 int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size,
1179  struct fuse_file_info *fi);
1180 int fuse_fs_utimens(struct fuse_fs *fs, const char *path,
1181  const struct timespec tv[2], struct fuse_file_info *fi);
1182 int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask);
1183 int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf,
1184  size_t len);
1185 int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
1186  dev_t rdev);
1187 int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode);
1188 int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name,
1189  const char *value, size_t size, int flags);
1190 int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name,
1191  char *value, size_t size);
1192 int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list,
1193  size_t size);
1194 int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
1195  const char *name);
1196 int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
1197  uint64_t *idx);
1198 #if FUSE_USE_VERSION < 35
1199 int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd,
1200  void *arg, struct fuse_file_info *fi, unsigned int flags,
1201  void *data);
1202 #else
1203 int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, unsigned int cmd,
1204  void *arg, struct fuse_file_info *fi, unsigned int flags,
1205  void *data);
1206 #endif
1207 int fuse_fs_poll(struct fuse_fs *fs, const char *path,
1208  struct fuse_file_info *fi, struct fuse_pollhandle *ph,
1209  unsigned *reventsp);
1210 int fuse_fs_fallocate(struct fuse_fs *fs, const char *path, int mode,
1211  off_t offset, off_t length, struct fuse_file_info *fi);
1212 ssize_t fuse_fs_copy_file_range(struct fuse_fs *fs, const char *path_in,
1213  struct fuse_file_info *fi_in, off_t off_in,
1214  const char *path_out,
1215  struct fuse_file_info *fi_out, off_t off_out,
1216  size_t len, int flags);
1217 off_t fuse_fs_lseek(struct fuse_fs *fs, const char *path, off_t off, int whence,
1218  struct fuse_file_info *fi);
1219 void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn,
1220  struct fuse_config *cfg);
1221 void fuse_fs_destroy(struct fuse_fs *fs);
1222 
1223 int fuse_notify_poll(struct fuse_pollhandle *ph);
1224 
1238 struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
1239  void *private_data);
1240 
1255 typedef struct fuse_fs *(*fuse_module_factory_t)(struct fuse_args *args,
1256  struct fuse_fs *fs[]);
1267 #define FUSE_REGISTER_MODULE(name_, factory_) \
1268  fuse_module_factory_t fuse_module_ ## name_ ## _factory = factory_
1269 
1271 struct fuse_session *fuse_get_session(struct fuse *f);
1272 
1281 int fuse_open_channel(const char *mountpoint, const char *options);
1282 
1283 #ifdef __cplusplus
1284 }
1285 #endif
1286 
1287 #endif /* FUSE_H_ */
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *private_data)
Definition: helper.c:279
size_t off
Definition: fuse_common.h:721
int fuse_invalidate_path(struct fuse *f, const char *path)
Definition: fuse.c:4631
struct fuse_session * fuse_get_session(struct fuse *f)
Definition: fuse.c:4504
int auto_cache
Definition: fuse.h:245
fuse_fill_dir_flags
Definition: fuse.h:54
int set_gid
Definition: fuse.h:98
int fuse_open_channel(const char *mountpoint, const char *options)
Definition: helper.c:424
struct fuse_fs * fuse_fs_new(const struct fuse_operations *op, size_t op_size, void *private_data)
Definition: fuse.c:4806
int readdir_ino
Definition: fuse.h:199
int fuse_clean_cache(struct fuse *fuse)
Definition: fuse.c:4417
int intr
Definition: fuse.h:140
int set_mode
Definition: fuse.h:112
struct fuse_context * fuse_get_context(void)
Definition: fuse.c:4602
void fuse_lib_help(struct fuse_args *args)
Definition: fuse.c:4696
int fuse_loop(struct fuse *f)
Definition: fuse.c:4561
int fuse_interrupted(void)
Definition: fuse.c:4621
struct fuse * fuse
Definition: fuse.h:793
int nullpath_ok
Definition: fuse.h:265
double negative_timeout
Definition: fuse.h:129
struct fuse * fuse_new(struct fuse_args *args, const struct fuse_operations *op, size_t op_size, void *private_data)
void fuse_exit(struct fuse *f)
Definition: fuse.c:4597
void fuse_stop_cleanup_thread(struct fuse *fuse)
Definition: fuse.c:4862
int set_uid
Definition: fuse.h:105
int remember
Definition: fuse.h:159
int use_ino
Definition: fuse.h:190
void fuse_unmount(struct fuse *f)
Definition: fuse.c:5108
int fuse_getgroups(int size, gid_t list[])
Definition: fuse.c:4612
int fuse_mount(struct fuse *f, const char *mountpoint)
Definition: fuse.c:5103
double attr_timeout
Definition: fuse.h:135
int direct_io
Definition: fuse.h:218
int show_help
Definition: fuse.h:271
fuse_readdir_flags
Definition: fuse.h:42
void fuse_destroy(struct fuse *f)
Definition: fuse.c:5053
int ac_attr_timeout_set
Definition: fuse.h:252
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:82
struct fuse_buf buf[1]
Definition: fuse_common.h:726
double entry_timeout
Definition: fuse.h:119
void * private_data
Definition: fuse.h:805
int kernel_cache
Definition: fuse.h:237
int intr_signal
Definition: fuse.h:147
int hard_remove
Definition: fuse.h:177
int fuse_start_cleanup_thread(struct fuse *fuse)
Definition: fuse.c:4854
int fuse_loop_mt_31(struct fuse *f, int clone_fd)
Definition: fuse.c:4589