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
82 uint64_t generation;
83
91 struct stat attr;
92
97 double attr_timeout;
98
103 double entry_timeout;
104 };
105
114 struct fuse_ctx {
116 uid_t uid;
117
119 gid_t gid;
120
122 pid_t pid;
123
125 mode_t umask;
126 };
127
128 struct fuse_forget_data {
129 fuse_ino_t ino;
130 uint64_t nlookup;
131 };
132
133 /* 'to_set' flags in setattr */
134 #define FUSE_SET_ATTR_MODE (1 << 0)
135 #define FUSE_SET_ATTR_UID (1 << 1)
136 #define FUSE_SET_ATTR_GID (1 << 2)
137 #define FUSE_SET_ATTR_SIZE (1 << 3)
138 #define FUSE_SET_ATTR_ATIME (1 << 4)
139 #define FUSE_SET_ATTR_MTIME (1 << 5)
140 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
141 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
142 #define FUSE_SET_ATTR_CTIME (1 << 10)
143
144 /* ----------------------------------------------------------- *
145 * Request methods and replies *
146 * ----------------------------------------------------------- */
147
175 struct fuse_lowlevel_ops {
192 void (*init) (void *userdata, struct fuse_conn_info *conn);
193
205 void (*destroy) (void *userdata);
206
218 void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
219
256 void (*forget) (fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
257
277 void (*getattr) (fuse_req_t req, fuse_ino_t ino,
278 struct fuse_file_info *fi);
279
308 void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
309 int to_set, struct fuse_file_info *fi);
310
321 void (*readlink) (fuse_req_t req, fuse_ino_t ino);
322
339 void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
340 mode_t mode, dev_t rdev);
341
354 void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
355 mode_t mode);
356
372 void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
373
389 void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
390
403 void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
404 const char *name);
405
435 void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
436 fuse_ino_t newparent, const char *newname,
437 unsigned int flags);
438
451 void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
452 const char *newname);
453
510 void (*open) (fuse_req_t req, fuse_ino_t ino,
511 struct fuse_file_info *fi);
512
538 void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
539 struct fuse_file_info *fi);
540
567 void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
568 size_t size, off_t off, struct fuse_file_info *fi);
569
604 void (*flush) (fuse_req_t req, fuse_ino_t ino,
605 struct fuse_file_info *fi);
606
631 void (*release) (fuse_req_t req, fuse_ino_t ino,
632 struct fuse_file_info *fi);
633
653 void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
654 struct fuse_file_info *fi);
655
677 void (*opendir) (fuse_req_t req, fuse_ino_t ino,
678 struct fuse_file_info *fi);
679
707 void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
708 struct fuse_file_info *fi);
709
726 void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
727 struct fuse_file_info *fi);
728
751 void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
752 struct fuse_file_info *fi);
753
764 void (*statfs) (fuse_req_t req, fuse_ino_t ino);
765
777 void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
778 const char *value, size_t size, int flags);
779
808 void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
809 size_t size);
810
839 void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
840
856 void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
857
878 void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
879
907 void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
908 mode_t mode, struct fuse_file_info *fi);
909
922 void (*getlk) (fuse_req_t req, fuse_ino_t ino,
923 struct fuse_file_info *fi, struct flock *lock);
924
947 void (*setlk) (fuse_req_t req, fuse_ino_t ino,
948 struct fuse_file_info *fi,
949 struct flock *lock, int sleep);
950
971 void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
972 uint64_t idx);
973
999 void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg,
1000 struct fuse_file_info *fi, unsigned flags,
1001 const void *in_buf, size_t in_bufsz, size_t out_bufsz);
1002
1032 void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1033 struct fuse_pollhandle *ph);
1034
1062 void (*write_buf) (fuse_req_t req, fuse_ino_t ino,
1063 struct fuse_bufvec *bufv, off_t off,
1064 struct fuse_file_info *fi);
1065
1078 void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino,
1079 off_t offset, struct fuse_bufvec *bufv);
1080
1092 void (*forget_multi) (fuse_req_t req, size_t count,
1093 struct fuse_forget_data *forgets);
1094
1110 void (*flock) (fuse_req_t req, fuse_ino_t ino,
1111 struct fuse_file_info *fi, int op);
1112
1133 void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode,
1134 off_t offset, off_t length, struct fuse_file_info *fi);
1135
1161 void (*readdirplus) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1162 struct fuse_file_info *fi);
1163 };
1164
1186 int fuse_reply_err(fuse_req_t req, int err);
1187
1198 void fuse_reply_none(fuse_req_t req);
1199
1213 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1214
1232 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1233 const struct fuse_file_info *fi);
1234
1246 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1247 double attr_timeout);
1248
1259 int fuse_reply_readlink(fuse_req_t req, const char *link);
1260
1274 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1275
1286 int fuse_reply_write(fuse_req_t req, size_t count);
1287
1299 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1300
1344 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
1345 enum fuse_buf_copy_flags flags);
1346
1358 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1359
1370 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1371
1382 int fuse_reply_xattr(fuse_req_t req, size_t count);
1383
1394 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1395
1406 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1407
1408 /* ----------------------------------------------------------- *
1409 * Filling a buffer in readdir *
1410 * ----------------------------------------------------------- */
1411
1439 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1440 const char *name, const struct stat *stbuf,
1441 off_t off);
1442
1456 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1457 const char *name,
1458 const struct fuse_entry_param *e, off_t off);
1459
1475 int fuse_reply_ioctl_retry(fuse_req_t req,
1476 const struct iovec *in_iov, size_t in_count,
1477 const struct iovec *out_iov, size_t out_count);
1478
1490 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1491
1503 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1504 int count);
1505
1512 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1513
1514 /* ----------------------------------------------------------- *
1515 * Notification *
1516 * ----------------------------------------------------------- */
1517
1525 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1526
1541 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1542 off_t off, off_t len);
1543
1562 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1563 const char *name, size_t namelen);
1564
1589 int fuse_lowlevel_notify_delete(struct fuse_session *se,
1590 fuse_ino_t parent, fuse_ino_t child,
1591 const char *name, size_t namelen);
1592
1618 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1619 off_t offset, struct fuse_bufvec *bufv,
1620 enum fuse_buf_copy_flags flags);
1650 int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
1651 size_t size, off_t offset, void *cookie);
1652
1653
1654 /* ----------------------------------------------------------- *
1655 * Utility functions *
1656 * ----------------------------------------------------------- */
1657
1664 void *fuse_req_userdata(fuse_req_t req);
1665
1675 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1676
1696 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
1697
1704 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1705
1717 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1718 void *data);
1719
1726 int fuse_req_interrupted(fuse_req_t req);
1727
1728
1729 /* ----------------------------------------------------------- *
1730 * Inquiry functions *
1731 * ----------------------------------------------------------- */
1732
1736 void fuse_lowlevel_version(void);
1737
1743 void fuse_lowlevel_help(void);
1744
1748 void fuse_cmdline_help(void);
1749
1750 /* ----------------------------------------------------------- *
1751 * Filesystem setup & teardown *
1752 * ----------------------------------------------------------- */
1753
1754 struct fuse_cmdline_opts {
1755 int singlethread;
1756 int foreground;
1757 int debug;
1758 int nodefault_subtype;
1759 char *mountpoint;
1760 int show_version;
1761 int show_help;
1762 int clone_fd;
1763 unsigned int max_idle_threads;
1764 };
1765
1784 int fuse_parse_cmdline(struct fuse_args *args,
1785 struct fuse_cmdline_opts *opts);
1786
1815 struct fuse_session *fuse_session_new(struct fuse_args *args,
1816 const struct fuse_lowlevel_ops *op,
1817 size_t op_size, void *userdata);
1818
1827 int fuse_session_mount(struct fuse_session *se, const char *mountpoint);
1828
1851 int fuse_session_loop(struct fuse_session *se);
1852
1864 #if FUSE_USE_VERSION < 32
1865 int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd);
1866 #define fuse_session_loop_mt(se, clone_fd) fuse_session_loop_mt_31(se, clone_fd)
1867 #else
1868 int fuse_session_loop_mt(struct fuse_session *se, struct fuse_loop_config *config);
1869 #endif
1870
1880 void fuse_session_exit(struct fuse_session *se);
1881
1887 void fuse_session_reset(struct fuse_session *se);
1888
1895 int fuse_session_exited(struct fuse_session *se);
1896
1921 void fuse_session_unmount(struct fuse_session *se);
1922
1928 void fuse_session_destroy(struct fuse_session *se);
1929
1930 /* ----------------------------------------------------------- *
1931 * Custom event loop support *
1932 * ----------------------------------------------------------- */
1933
1948 int fuse_session_fd(struct fuse_session *se);
1949
1958 void fuse_session_process_buf(struct fuse_session *se,
1959 const struct fuse_buf *buf);
1960
1972 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
1973
1974 #ifdef __cplusplus
1975 }
1976 #endif
1977
1978 #endif /* FUSE_LOWLEVEL_H_ */
fuse_bufvec::off
size_t off
Definition: fuse_common.h:668
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:2118
fuse_conn_info
Definition: fuse_common.h:332
fuse_session_unmount
void fuse_session_unmount(struct fuse_session *se)
Definition: fuse_lowlevel.c:2916
fuse_session_loop_mt_31
int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd)
Definition: fuse_loop_mt.c:353
fuse_reply_open
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
Definition: fuse_lowlevel.c:450
fuse_req_interrupt_func
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void *data)
Definition: fuse_lowlevel.c:2325
fuse_reply_iov
int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
Definition: fuse_lowlevel.c:245
fuse_reply_statfs
int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf)
Definition: fuse_lowlevel.c:841
fuse_req_ctx
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
Definition: fuse_lowlevel.c:2320
fuse_reply_write
int fuse_reply_write(fuse_req_t req, size_t count)
Definition: fuse_lowlevel.c:459
fuse_reply_poll
int fuse_reply_poll(fuse_req_t req, unsigned revents)
Definition: fuse_lowlevel.c:1023
fuse_entry_param::attr
struct stat attr
Definition: fuse_lowlevel.h:91
fuse_reply_buf
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
Definition: fuse_lowlevel.c:469
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:908
fuse_entry_param
Definition: fuse_lowlevel.h:59
fuse_entry_param::ino
fuse_ino_t ino
Definition: fuse_lowlevel.h:67
fuse_reply_entry
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
Definition: fuse_lowlevel.c:398
fuse_session_loop
int fuse_session_loop(struct fuse_session *se)
Definition: fuse_loop.c:19
fuse_reply_lock
int fuse_reply_lock(fuse_req_t req, const struct flock *lock)
Definition: fuse_lowlevel.c:863
fuse_session_reset
void fuse_session_reset(struct fuse_session *se)
Definition: fuse_lowlevel.c:2998
fuse_file_info
Definition: fuse_common.h:37
fuse_lowlevel_help
void fuse_lowlevel_help(void)
Definition: fuse_lowlevel.c:2587
fuse_interrupt_func_t
void(* fuse_interrupt_func_t)(fuse_req_t req, void *data)
Definition: fuse_lowlevel.h:1704
fuse_file_info::flags
int flags
Definition: fuse_common.h:39
fuse_bufvec
Definition: fuse_common.h:654
fuse_loop_config
Definition: fuse_common.h:86
fuse_reply_readlink
int fuse_reply_readlink(fuse_req_t req, const char *link)
Definition: fuse_lowlevel.c:445
fuse_lowlevel_version
void fuse_lowlevel_version(void)
Definition: fuse_lowlevel.c:2580
fuse_lowlevel_notify_poll
int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
Definition: fuse_lowlevel.c:2101
fuse_ctx
Definition: fuse_lowlevel.h:114
fuse_reply_err
int fuse_reply_err(fuse_req_t req, int err)
Definition: fuse_lowlevel.c:311
fuse_bufvec::count
size_t count
Definition: fuse_common.h:658
fuse_session_receive_buf
int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf)
Definition: fuse_lowlevel.c:2624
fuse_req_userdata
void * fuse_req_userdata(fuse_req_t req)
Definition: fuse_lowlevel.c:2315
fuse_session_fd
int fuse_session_fd(struct fuse_session *se)
Definition: fuse_lowlevel.c:2911
fuse_buf_copy_flags
fuse_buf_copy_flags
Definition: fuse_common.h:568
fuse_req_getgroups
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
Definition: fuse_lowlevel.c:2986
fuse_file_info::flush
unsigned int flush
Definition: fuse_common.h:56
fuse_req_t
struct fuse_req * fuse_req_t
Definition: fuse_lowlevel.h:49
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:2190
fuse_reply_attr
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
Definition: fuse_lowlevel.c:430
fuse_common.h
fuse_parse_cmdline
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
Definition: helper.c:197
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:2785
fuse_session_process_buf
void fuse_session_process_buf(struct fuse_session *se, const struct fuse_buf *buf)
Definition: fuse_lowlevel.c:2424
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:2270
fuse_entry_param::generation
uint64_t generation
Definition: fuse_lowlevel.h:82
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:2164
fuse_ino_t
uint64_t fuse_ino_t
Definition: fuse_lowlevel.h:46
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:266
fuse_reply_bmap
int fuse_reply_bmap(fuse_req_t req, uint64_t idx)
Definition: fuse_lowlevel.c:880
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:2140
fuse_session_destroy
void fuse_session_destroy(struct fuse_session *se)
Definition: fuse_lowlevel.c:2597
fuse_lowlevel_ops
Definition: fuse_lowlevel.h:175
fuse_session_mount
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
Definition: fuse_lowlevel.c:2879
fuse_reply_ioctl
int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
Definition: fuse_lowlevel.c:978
fuse_args
Definition: fuse_opt.h:109
fuse_session_exit
void fuse_session_exit(struct fuse_session *se)
Definition: fuse_lowlevel.c:2993
fuse_req_interrupted
int fuse_req_interrupted(fuse_req_t req)
Definition: fuse_lowlevel.c:2338
fuse_entry_param::entry_timeout
double entry_timeout
Definition: fuse_lowlevel.h:103
fuse_reply_none
void fuse_reply_none(fuse_req_t req)
Definition: fuse_lowlevel.c:316
fuse_entry_param::attr_timeout
double attr_timeout
Definition: fuse_lowlevel.h:97
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:819
fuse_cmdline_help
void fuse_cmdline_help(void)
Definition: helper.c:128
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:356
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:414
fuse_buf
Definition: fuse_common.h:613
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:999
fuse_session_exited
int fuse_session_exited(struct fuse_session *se)
Definition: fuse_lowlevel.c:3004
fuse_reply_xattr
int fuse_reply_xattr(fuse_req_t req, size_t count)
Definition: fuse_lowlevel.c:853