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 
67  fuse_ino_t ino;
68 
82  uint64_t generation;
83 
91  struct stat attr;
92 
97  double attr_timeout;
98 
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 
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 
608  void (*flush) (fuse_req_t req, fuse_ino_t ino,
609  struct fuse_file_info *fi);
610 
636  void (*release) (fuse_req_t req, fuse_ino_t ino,
637  struct fuse_file_info *fi);
638 
658  void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
659  struct fuse_file_info *fi);
660 
683  void (*opendir) (fuse_req_t req, fuse_ino_t ino,
684  struct fuse_file_info *fi);
685 
729  void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
730  struct fuse_file_info *fi);
731 
748  void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
749  struct fuse_file_info *fi);
750 
773  void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
774  struct fuse_file_info *fi);
775 
786  void (*statfs) (fuse_req_t req, fuse_ino_t ino);
787 
799  void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
800  const char *value, size_t size, int flags);
801 
830  void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
831  size_t size);
832 
861  void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
862 
878  void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
879 
900  void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
901 
929  void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
930  mode_t mode, struct fuse_file_info *fi);
931 
944  void (*getlk) (fuse_req_t req, fuse_ino_t ino,
945  struct fuse_file_info *fi, struct flock *lock);
946 
969  void (*setlk) (fuse_req_t req, fuse_ino_t ino,
970  struct fuse_file_info *fi,
971  struct flock *lock, int sleep);
972 
993  void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
994  uint64_t idx);
995 
1024  void (*ioctl) (fuse_req_t req, fuse_ino_t ino, unsigned int cmd,
1025  void *arg, struct fuse_file_info *fi, unsigned flags,
1026  const void *in_buf, size_t in_bufsz, size_t out_bufsz);
1027 
1057  void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1058  struct fuse_pollhandle *ph);
1059 
1087  void (*write_buf) (fuse_req_t req, fuse_ino_t ino,
1088  struct fuse_bufvec *bufv, off_t off,
1089  struct fuse_file_info *fi);
1090 
1103  void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino,
1104  off_t offset, struct fuse_bufvec *bufv);
1105 
1117  void (*forget_multi) (fuse_req_t req, size_t count,
1118  struct fuse_forget_data *forgets);
1119 
1135  void (*flock) (fuse_req_t req, fuse_ino_t ino,
1136  struct fuse_file_info *fi, int op);
1137 
1158  void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode,
1159  off_t offset, off_t length, struct fuse_file_info *fi);
1160 
1186  void (*readdirplus) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1187  struct fuse_file_info *fi);
1188 
1219  void (*copy_file_range) (fuse_req_t req, fuse_ino_t ino_in,
1220  off_t off_in, struct fuse_file_info *fi_in,
1221  fuse_ino_t ino_out, off_t off_out,
1222  struct fuse_file_info *fi_out, size_t len,
1223  int flags);
1224 };
1225 
1247 int fuse_reply_err(fuse_req_t req, int err);
1248 
1259 void fuse_reply_none(fuse_req_t req);
1260 
1274 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1275 
1293 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1294  const struct fuse_file_info *fi);
1295 
1307 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1308  double attr_timeout);
1309 
1320 int fuse_reply_readlink(fuse_req_t req, const char *link);
1321 
1335 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1336 
1347 int fuse_reply_write(fuse_req_t req, size_t count);
1348 
1360 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1361 
1405 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
1406  enum fuse_buf_copy_flags flags);
1407 
1419 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1420 
1431 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1432 
1443 int fuse_reply_xattr(fuse_req_t req, size_t count);
1444 
1455 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1456 
1467 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1468 
1469 /* ----------------------------------------------------------- *
1470  * Filling a buffer in readdir *
1471  * ----------------------------------------------------------- */
1472 
1500 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1501  const char *name, const struct stat *stbuf,
1502  off_t off);
1503 
1517 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1518  const char *name,
1519  const struct fuse_entry_param *e, off_t off);
1520 
1536 int fuse_reply_ioctl_retry(fuse_req_t req,
1537  const struct iovec *in_iov, size_t in_count,
1538  const struct iovec *out_iov, size_t out_count);
1539 
1551 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1552 
1564 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1565  int count);
1566 
1573 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1574 
1575 /* ----------------------------------------------------------- *
1576  * Notification *
1577  * ----------------------------------------------------------- */
1578 
1586 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1587 
1611 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1612  off_t off, off_t len);
1613 
1639 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1640  const char *name, size_t namelen);
1641 
1670 int fuse_lowlevel_notify_delete(struct fuse_session *se,
1671  fuse_ino_t parent, fuse_ino_t child,
1672  const char *name, size_t namelen);
1673 
1699 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1700  off_t offset, struct fuse_bufvec *bufv,
1701  enum fuse_buf_copy_flags flags);
1731 int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
1732  size_t size, off_t offset, void *cookie);
1733 
1734 
1735 /* ----------------------------------------------------------- *
1736  * Utility functions *
1737  * ----------------------------------------------------------- */
1738 
1745 void *fuse_req_userdata(fuse_req_t req);
1746 
1756 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1757 
1777 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
1778 
1785 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1786 
1798 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1799  void *data);
1800 
1807 int fuse_req_interrupted(fuse_req_t req);
1808 
1809 
1810 /* ----------------------------------------------------------- *
1811  * Inquiry functions *
1812  * ----------------------------------------------------------- */
1813 
1817 void fuse_lowlevel_version(void);
1818 
1824 void fuse_lowlevel_help(void);
1825 
1829 void fuse_cmdline_help(void);
1830 
1831 /* ----------------------------------------------------------- *
1832  * Filesystem setup & teardown *
1833  * ----------------------------------------------------------- */
1834 
1835 struct fuse_cmdline_opts {
1836  int singlethread;
1837  int foreground;
1838  int debug;
1839  int nodefault_subtype;
1840  char *mountpoint;
1841  int show_version;
1842  int show_help;
1843  int clone_fd;
1844  unsigned int max_idle_threads;
1845 };
1846 
1865 int fuse_parse_cmdline(struct fuse_args *args,
1866  struct fuse_cmdline_opts *opts);
1867 
1896 struct fuse_session *fuse_session_new(struct fuse_args *args,
1897  const struct fuse_lowlevel_ops *op,
1898  size_t op_size, void *userdata);
1899 
1908 int fuse_session_mount(struct fuse_session *se, const char *mountpoint);
1909 
1932 int fuse_session_loop(struct fuse_session *se);
1933 
1945 #if FUSE_USE_VERSION < 32
1946 int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd);
1947 #define fuse_session_loop_mt(se, clone_fd) fuse_session_loop_mt_31(se, clone_fd)
1948 #else
1949 int fuse_session_loop_mt(struct fuse_session *se, struct fuse_loop_config *config);
1950 #endif
1951 
1961 void fuse_session_exit(struct fuse_session *se);
1962 
1968 void fuse_session_reset(struct fuse_session *se);
1969 
1976 int fuse_session_exited(struct fuse_session *se);
1977 
2002 void fuse_session_unmount(struct fuse_session *se);
2003 
2009 void fuse_session_destroy(struct fuse_session *se);
2010 
2011 /* ----------------------------------------------------------- *
2012  * Custom event loop support *
2013  * ----------------------------------------------------------- */
2014 
2029 int fuse_session_fd(struct fuse_session *se);
2030 
2039 void fuse_session_process_buf(struct fuse_session *se,
2040  const struct fuse_buf *buf);
2041 
2053 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
2054 
2055 #ifdef __cplusplus
2056 }
2057 #endif
2058 
2059 #endif /* FUSE_LOWLEVEL_H_ */
void fuse_session_destroy(struct fuse_session *se)
int fuse_reply_err(fuse_req_t req, int err)
size_t off
Definition: fuse_common.h:710
int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf)
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
void fuse_session_exit(struct fuse_session *se)
int fuse_session_loop(struct fuse_session *se)
Definition: fuse_loop.c:19
int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino, size_t size, off_t offset, void *cookie)
int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent, fuse_ino_t child, const char *name, size_t namelen)
int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size)
void fuse_lowlevel_help(void)
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)
int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv, enum fuse_buf_copy_flags flags)
int fuse_session_fd(struct fuse_session *se)
const struct fuse_ctx * fuse_req_ctx(fuse_req_t req)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
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)
mode_t umask
void(* fuse_interrupt_func_t)(fuse_req_t req, void *data)
int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph)
struct fuse_req * fuse_req_t
Definition: fuse_lowlevel.h:49
struct stat attr
Definition: fuse_lowlevel.h:91
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
void * fuse_req_userdata(fuse_req_t req)
int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino, off_t off, off_t len)
int fuse_reply_bmap(fuse_req_t req, uint64_t idx)
int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd)
Definition: fuse_loop_mt.c:356
Definition: fuse_lowlevel.h:59
fuse_ino_t ino
Definition: fuse_lowlevel.h:67
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
Definition: helper.c:202
int fuse_reply_xattr(fuse_req_t req, size_t count)
void fuse_cmdline_help(void)
Definition: helper.c:129
int fuse_session_exited(struct fuse_session *se)
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
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)
int fuse_reply_lock(fuse_req_t req, const struct flock *lock)
int fuse_req_interrupted(fuse_req_t req)
void fuse_session_reset(struct fuse_session *se)
void fuse_lowlevel_version(void)
int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, int count)
void fuse_reply_none(fuse_req_t req)
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
size_t count
Definition: fuse_common.h:700
int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
void fuse_session_unmount(struct fuse_session *se)
int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf)
unsigned int flush
Definition: fuse_common.h:68
uint64_t fuse_ino_t
Definition: fuse_lowlevel.h:46
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void *data)
uint64_t generation
Definition: fuse_lowlevel.h:82
int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, const struct fuse_file_info *fi)
int fuse_reply_write(fuse_req_t req, size_t count)
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
double entry_timeout
fuse_buf_copy_flags
Definition: fuse_common.h:610
double attr_timeout
Definition: fuse_lowlevel.h:97
int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count)
int fuse_reply_readlink(fuse_req_t req, const char *link)
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
int fuse_reply_poll(fuse_req_t req, unsigned revents)
void fuse_session_process_buf(struct fuse_session *se, const struct fuse_buf *buf)