libfuse

fuse_lowlevel.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_LOWLEVEL_H_
10 #define FUSE_LOWLEVEL_H_
11
21 #ifndef FUSE_USE_VERSION
22 #error FUSE_USE_VERSION not defined
23 #endif
24
25 #include "fuse_common.h"
26
27 #include <utime.h>
28 #include <fcntl.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <sys/statvfs.h>
32 #include <sys/uio.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /* ----------------------------------------------------------- *
39 * Miscellaneous definitions *
40 * ----------------------------------------------------------- */
41
43 #define FUSE_ROOT_ID 1
44
46 typedef uint64_t fuse_ino_t;
47
49 typedef struct fuse_req *fuse_req_t;
50
56 struct fuse_session;
57
59 struct fuse_entry_param {
67 fuse_ino_t ino;
68
79 uint64_t generation;
80
88 struct stat attr;
89
94 double attr_timeout;
95
100 double entry_timeout;
101 };
102
111 struct fuse_ctx {
113 uid_t uid;
114
116 gid_t gid;
117
119 pid_t pid;
120
122 mode_t umask;
123 };
124
125 struct fuse_forget_data {
126 fuse_ino_t ino;
127 uint64_t nlookup;
128 };
129
130 /* 'to_set' flags in setattr */
131 #define FUSE_SET_ATTR_MODE (1 << 0)
132 #define FUSE_SET_ATTR_UID (1 << 1)
133 #define FUSE_SET_ATTR_GID (1 << 2)
134 #define FUSE_SET_ATTR_SIZE (1 << 3)
135 #define FUSE_SET_ATTR_ATIME (1 << 4)
136 #define FUSE_SET_ATTR_MTIME (1 << 5)
137 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
138 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
139 #define FUSE_SET_ATTR_CTIME (1 << 10)
140
141 /* ----------------------------------------------------------- *
142 * Request methods and replies *
143 * ----------------------------------------------------------- */
144
172 struct fuse_lowlevel_ops {
189 void (*init) (void *userdata, struct fuse_conn_info *conn);
190
202 void (*destroy) (void *userdata);
203
215 void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
216
253 void (*forget) (fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
254
274 void (*getattr) (fuse_req_t req, fuse_ino_t ino,
275 struct fuse_file_info *fi);
276
305 void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
306 int to_set, struct fuse_file_info *fi);
307
318 void (*readlink) (fuse_req_t req, fuse_ino_t ino);
319
336 void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
337 mode_t mode, dev_t rdev);
338
351 void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
352 mode_t mode);
353
369 void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
370
386 void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
387
400 void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
401 const char *name);
402
432 void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
433 fuse_ino_t newparent, const char *newname,
434 unsigned int flags);
435
448 void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
449 const char *newname);
450
507 void (*open) (fuse_req_t req, fuse_ino_t ino,
508 struct fuse_file_info *fi);
509
535 void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
536 struct fuse_file_info *fi);
537
564 void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
565 size_t size, off_t off, struct fuse_file_info *fi);
566
605 void (*flush) (fuse_req_t req, fuse_ino_t ino,
606 struct fuse_file_info *fi);
607
633 void (*release) (fuse_req_t req, fuse_ino_t ino,
634 struct fuse_file_info *fi);
635
655 void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
656 struct fuse_file_info *fi);
657
680 void (*opendir) (fuse_req_t req, fuse_ino_t ino,
681 struct fuse_file_info *fi);
682
726 void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
727 struct fuse_file_info *fi);
728
745 void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
746 struct fuse_file_info *fi);
747
770 void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
771 struct fuse_file_info *fi);
772
783 void (*statfs) (fuse_req_t req, fuse_ino_t ino);
784
796 void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
797 const char *value, size_t size, int flags);
798
827 void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
828 size_t size);
829
858 void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
859
875 void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
876
897 void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
898
926 void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
927 mode_t mode, struct fuse_file_info *fi);
928
941 void (*getlk) (fuse_req_t req, fuse_ino_t ino,
942 struct fuse_file_info *fi, struct flock *lock);
943
966 void (*setlk) (fuse_req_t req, fuse_ino_t ino,
967 struct fuse_file_info *fi,
968 struct flock *lock, int sleep);
969
990 void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
991 uint64_t idx);
992
1021 #if FUSE_USE_VERSION < 35
1022 void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd,
1023 void *arg, struct fuse_file_info *fi, unsigned flags,
1024 const void *in_buf, size_t in_bufsz, size_t out_bufsz);
1025 #else
1026 void (*ioctl) (fuse_req_t req, fuse_ino_t ino, unsigned int cmd,
1027 void *arg, struct fuse_file_info *fi, unsigned flags,
1028 const void *in_buf, size_t in_bufsz, size_t out_bufsz);
1029 #endif
1030
1060 void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1061 struct fuse_pollhandle *ph);
1062
1090 void (*write_buf) (fuse_req_t req, fuse_ino_t ino,
1091 struct fuse_bufvec *bufv, off_t off,
1092 struct fuse_file_info *fi);
1093
1106 void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino,
1107 off_t offset, struct fuse_bufvec *bufv);
1108
1120 void (*forget_multi) (fuse_req_t req, size_t count,
1121 struct fuse_forget_data *forgets);
1122
1138 void (*flock) (fuse_req_t req, fuse_ino_t ino,
1139 struct fuse_file_info *fi, int op);
1140
1161 void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode,
1162 off_t offset, off_t length, struct fuse_file_info *fi);
1163
1189 void (*readdirplus) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1190 struct fuse_file_info *fi);
1191
1222 void (*copy_file_range) (fuse_req_t req, fuse_ino_t ino_in,
1223 off_t off_in, struct fuse_file_info *fi_in,
1224 fuse_ino_t ino_out, off_t off_out,
1225 struct fuse_file_info *fi_out, size_t len,
1226 int flags);
1227
1246 void (*lseek) (fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
1247 struct fuse_file_info *fi);
1248 };
1249
1271 int fuse_reply_err(fuse_req_t req, int err);
1272
1283 void fuse_reply_none(fuse_req_t req);
1284
1298 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1299
1317 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1318 const struct fuse_file_info *fi);
1319
1331 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1332 double attr_timeout);
1333
1344 int fuse_reply_readlink(fuse_req_t req, const char *link);
1345
1359 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1360
1371 int fuse_reply_write(fuse_req_t req, size_t count);
1372
1384 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1385
1429 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
1430 enum fuse_buf_copy_flags flags);
1431
1443 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1444
1455 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1456
1467 int fuse_reply_xattr(fuse_req_t req, size_t count);
1468
1479 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1480
1491 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1492
1493 /* ----------------------------------------------------------- *
1494 * Filling a buffer in readdir *
1495 * ----------------------------------------------------------- */
1496
1524 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1525 const char *name, const struct stat *stbuf,
1526 off_t off);
1527
1541 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1542 const char *name,
1543 const struct fuse_entry_param *e, off_t off);
1544
1560 int fuse_reply_ioctl_retry(fuse_req_t req,
1561 const struct iovec *in_iov, size_t in_count,
1562 const struct iovec *out_iov, size_t out_count);
1563
1575 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1576
1588 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1589 int count);
1590
1597 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1598
1609 int fuse_reply_lseek(fuse_req_t req, off_t off);
1610
1611 /* ----------------------------------------------------------- *
1612 * Notification *
1613 * ----------------------------------------------------------- */
1614
1622 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1623
1647 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1648 off_t off, off_t len);
1649
1675 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1676 const char *name, size_t namelen);
1677
1706 int fuse_lowlevel_notify_delete(struct fuse_session *se,
1707 fuse_ino_t parent, fuse_ino_t child,
1708 const char *name, size_t namelen);
1709
1735 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1736 off_t offset, struct fuse_bufvec *bufv,
1737 enum fuse_buf_copy_flags flags);
1767 int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
1768 size_t size, off_t offset, void *cookie);
1769
1770
1771 /* ----------------------------------------------------------- *
1772 * Utility functions *
1773 * ----------------------------------------------------------- */
1774
1781 void *fuse_req_userdata(fuse_req_t req);
1782
1792 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1793
1813 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
1814
1821 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1822
1834 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1835 void *data);
1836
1843 int fuse_req_interrupted(fuse_req_t req);
1844
1845
1846 /* ----------------------------------------------------------- *
1847 * Inquiry functions *
1848 * ----------------------------------------------------------- */
1849
1853 void fuse_lowlevel_version(void);
1854
1860 void fuse_lowlevel_help(void);
1861
1865 void fuse_cmdline_help(void);
1866
1867 /* ----------------------------------------------------------- *
1868 * Filesystem setup & teardown *
1869 * ----------------------------------------------------------- */
1870
1871 struct fuse_cmdline_opts {
1872 int singlethread;
1873 int foreground;
1874 int debug;
1875 int nodefault_subtype;
1876 char *mountpoint;
1877 int show_version;
1878 int show_help;
1879 int clone_fd;
1880 unsigned int max_idle_threads;
1881 };
1882
1901 int fuse_parse_cmdline(struct fuse_args *args,
1902 struct fuse_cmdline_opts *opts);
1903
1932 struct fuse_session *fuse_session_new(struct fuse_args *args,
1933 const struct fuse_lowlevel_ops *op,
1934 size_t op_size, void *userdata);
1935
1944 int fuse_session_mount(struct fuse_session *se, const char *mountpoint);
1945
1968 int fuse_session_loop(struct fuse_session *se);
1969
1981 #if FUSE_USE_VERSION < 32
1982 int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd);
1983 #define fuse_session_loop_mt(se, clone_fd) fuse_session_loop_mt_31(se, clone_fd)
1984 #else
1985 int fuse_session_loop_mt(struct fuse_session *se, struct fuse_loop_config *config);
1986 #endif
1987
1997 void fuse_session_exit(struct fuse_session *se);
1998
2004 void fuse_session_reset(struct fuse_session *se);
2005
2012 int fuse_session_exited(struct fuse_session *se);
2013
2038 void fuse_session_unmount(struct fuse_session *se);
2039
2045 void fuse_session_destroy(struct fuse_session *se);
2046
2047 /* ----------------------------------------------------------- *
2048 * Custom event loop support *
2049 * ----------------------------------------------------------- */
2050
2065 int fuse_session_fd(struct fuse_session *se);
2066
2075 void fuse_session_process_buf(struct fuse_session *se,
2076 const struct fuse_buf *buf);
2077
2089 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
2090
2091 #ifdef __cplusplus
2092 }
2093 #endif
2094
2095 #endif /* FUSE_LOWLEVEL_H_ */
fuse_req_interrupt_func
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void *data)
Definition: fuse_lowlevel.c:2426
fuse_cmdline_help
void fuse_cmdline_help(void)
Definition: helper.c:129
fuse_bufvec::off
size_t off
Definition: fuse_common.h:721
fuse_session_mount
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
Definition: fuse_lowlevel.c:2981
fuse_lowlevel_notify_inval_entry
int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
Definition: fuse_lowlevel.c:2241
fuse_req_t
struct fuse_req * fuse_req_t
Definition: fuse_lowlevel.h:49
fuse_conn_info
Definition: fuse_common.h:385
fuse_reply_ioctl_iov
int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, int count)
Definition: fuse_lowlevel.c:1034
fuse_session_exited
int fuse_session_exited(struct fuse_session *se)
Definition: fuse_lowlevel.c:3126
fuse_reply_none
void fuse_reply_none(fuse_req_t req)
Definition: fuse_lowlevel.c:317
fuse_session_receive_buf
int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf)
Definition: fuse_lowlevel.c:2727
fuse_session_process_buf
void fuse_session_process_buf(struct fuse_session *se, const struct fuse_buf *buf)
Definition: fuse_lowlevel.c:2527
fuse_reply_attr
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
Definition: fuse_lowlevel.c:433
fuse_entry_param::attr
struct stat attr
Definition: fuse_lowlevel.h:88
fuse_reply_lock
int fuse_reply_lock(fuse_req_t req, const struct flock *lock)
Definition: fuse_lowlevel.c:898
fuse_reply_buf
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
Definition: fuse_lowlevel.c:472
fuse_reply_create
int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, const struct fuse_file_info *fi)
Definition: fuse_lowlevel.c:417
fuse_reply_xattr
int fuse_reply_xattr(fuse_req_t req, size_t count)
Definition: fuse_lowlevel.c:888
fuse_entry_param
Definition: fuse_lowlevel.h:59
fuse_entry_param::ino
fuse_ino_t ino
Definition: fuse_lowlevel.h:67
fuse_lowlevel_notify_inval_inode
int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino, off_t off, off_t len)
Definition: fuse_lowlevel.c:2219
fuse_lowlevel_version
void fuse_lowlevel_version(void)
Definition: fuse_lowlevel.c:2683
fuse_lowlevel_notify_store
int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino, off_t offset, struct fuse_bufvec *bufv, enum fuse_buf_copy_flags flags)
Definition: fuse_lowlevel.c:2291
fuse_reply_write
int fuse_reply_write(fuse_req_t req, size_t count)
Definition: fuse_lowlevel.c:462
fuse_file_info
Definition: fuse_common.h:44
fuse_reply_lseek
int fuse_reply_lseek(fuse_req_t req, off_t off)
Definition: fuse_lowlevel.c:1068
fuse_buf_copy_flags
fuse_buf_copy_flags
Definition: fuse_common.h:621
fuse_lowlevel_notify_poll
int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
Definition: fuse_lowlevel.c:2202
fuse_reply_ioctl_retry
int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov, size_t in_count, const struct iovec *out_iov, size_t out_count)
Definition: fuse_lowlevel.c:943
fuse_session_loop
int fuse_session_loop(struct fuse_session *se)
Definition: fuse_loop.c:19
fuse_common.h
fuse_session_loop_mt_31
int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd)
Definition: fuse_loop_mt.c:356
fuse_file_info::flags
int flags
Definition: fuse_common.h:46
fuse_bufvec
Definition: fuse_common.h:707
fuse_loop_config
Definition: fuse_common.h:107
fuse_ctx
Definition: fuse_lowlevel.h:111
fuse_parse_cmdline
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
Definition: helper.c:202
fuse_session_new
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
Definition: fuse_lowlevel.c:2886
fuse_bufvec::count
size_t count
Definition: fuse_common.h:711
fuse_lowlevel_notify_retrieve
int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino, size_t size, off_t offset, void *cookie)
Definition: fuse_lowlevel.c:2371
fuse_session_fd
int fuse_session_fd(struct fuse_session *se)
Definition: fuse_lowlevel.c:3031
fuse_session_unmount
void fuse_session_unmount(struct fuse_session *se)
Definition: fuse_lowlevel.c:3036
fuse_file_info::flush
unsigned int flush
Definition: fuse_common.h:69
fuse_reply_err
int fuse_reply_err(fuse_req_t req, int err)
Definition: fuse_lowlevel.c:312
fuse_session_reset
void fuse_session_reset(struct fuse_session *se)
Definition: fuse_lowlevel.c:3120
fuse_reply_iov
int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
Definition: fuse_lowlevel.c:246
fuse_add_direntry
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
Definition: fuse_lowlevel.c:267
fuse_req_userdata
void * fuse_req_userdata(fuse_req_t req)
Definition: fuse_lowlevel.c:2416
fuse_req_getgroups
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
Definition: fuse_lowlevel.c:3108
fuse_reply_entry
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
Definition: fuse_lowlevel.c:401
fuse_reply_statfs
int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf)
Definition: fuse_lowlevel.c:876
fuse_req_ctx
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
Definition: fuse_lowlevel.c:2421
fuse_entry_param::generation
uint64_t generation
Definition: fuse_lowlevel.h:79
fuse_session_destroy
void fuse_session_destroy(struct fuse_session *se)
Definition: fuse_lowlevel.c:2700
fuse_lowlevel_ops
Definition: fuse_lowlevel.h:172
fuse_reply_ioctl
int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
Definition: fuse_lowlevel.c:1013
fuse_reply_data
int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv, enum fuse_buf_copy_flags flags)
Definition: fuse_lowlevel.c:854
fuse_args
Definition: fuse_opt.h:109
fuse_ino_t
uint64_t fuse_ino_t
Definition: fuse_lowlevel.h:46
fuse_lowlevel_notify_delete
int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent, fuse_ino_t child, const char *name, size_t namelen)
Definition: fuse_lowlevel.c:2265
fuse_entry_param::entry_timeout
double entry_timeout
Definition: fuse_lowlevel.h:100
fuse_lowlevel_help
void fuse_lowlevel_help(void)
Definition: fuse_lowlevel.c:2690
fuse_entry_param::attr_timeout
double attr_timeout
Definition: fuse_lowlevel.h:94
fuse_buf
Definition: fuse_common.h:666
fuse_req_interrupted
int fuse_req_interrupted(fuse_req_t req)
Definition: fuse_lowlevel.c:2439
fuse_reply_open
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
Definition: fuse_lowlevel.c:453
fuse_session_exit
void fuse_session_exit(struct fuse_session *se)
Definition: fuse_lowlevel.c:3115
fuse_reply_bmap
int fuse_reply_bmap(fuse_req_t req, uint64_t idx)
Definition: fuse_lowlevel.c:915
fuse_add_direntry_plus
size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct fuse_entry_param *e, off_t off)
Definition: fuse_lowlevel.c:357
fuse_reply_readlink
int fuse_reply_readlink(fuse_req_t req, const char *link)
Definition: fuse_lowlevel.c:448
fuse_reply_poll
int fuse_reply_poll(fuse_req_t req, unsigned revents)
Definition: fuse_lowlevel.c:1058
fuse_interrupt_func_t
void(* fuse_interrupt_func_t)(fuse_req_t req, void *data)
Definition: fuse_lowlevel.h:1815