fuse.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU GPL.
  5. See the file COPYING.
  6. */
  7. /*
  8. * This file defines the kernel interface of FUSE
  9. *
  10. * Protocol changelog:
  11. *
  12. * 7.9:
  13. * - new fuse_getattr_in input argument of GETATTR
  14. * - add lk_flags in fuse_lk_in
  15. * - add lock_owner field to fuse_setattr_in, fuse_read_in and fuse_write_in
  16. * - add blksize field to fuse_attr
  17. * - add file flags field to fuse_read_in and fuse_write_in
  18. *
  19. * 7.10
  20. * - add nonseekable open flag
  21. *
  22. * 7.11
  23. * - add IOCTL message
  24. * - add unsolicited notification support
  25. * - add POLL message and NOTIFY_POLL notification
  26. *
  27. * 7.12
  28. * - add umask flag to input argument of open, mknod and mkdir
  29. * - add notification messages for invalidation of inodes and
  30. * directory entries
  31. *
  32. * 7.13
  33. * - make max number of background requests and congestion threshold
  34. * tunables
  35. */
  36. #ifndef _LINUX_FUSE_H
  37. #define _LINUX_FUSE_H
  38. #include <linux/types.h>
  39. /*
  40. * Version negotiation:
  41. *
  42. * Both the kernel and userspace send the version they support in the
  43. * INIT request and reply respectively.
  44. *
  45. * If the major versions match then both shall use the smallest
  46. * of the two minor versions for communication.
  47. *
  48. * If the kernel supports a larger major version, then userspace shall
  49. * reply with the major version it supports, ignore the rest of the
  50. * INIT message and expect a new INIT message from the kernel with a
  51. * matching major version.
  52. *
  53. * If the library supports a larger major version, then it shall fall
  54. * back to the major protocol version sent by the kernel for
  55. * communication and reply with that major version (and an arbitrary
  56. * supported minor version).
  57. */
  58. /** Version number of this interface */
  59. #define FUSE_KERNEL_VERSION 7
  60. /** Minor version number of this interface */
  61. #define FUSE_KERNEL_MINOR_VERSION 13
  62. /** The node ID of the root inode */
  63. #define FUSE_ROOT_ID 1
  64. /* Make sure all structures are padded to 64bit boundary, so 32bit
  65. userspace works under 64bit kernels */
  66. struct fuse_attr {
  67. __u64 ino;
  68. __u64 size;
  69. __u64 blocks;
  70. __u64 atime;
  71. __u64 mtime;
  72. __u64 ctime;
  73. __u32 atimensec;
  74. __u32 mtimensec;
  75. __u32 ctimensec;
  76. __u32 mode;
  77. __u32 nlink;
  78. __u32 uid;
  79. __u32 gid;
  80. __u32 rdev;
  81. __u32 blksize;
  82. __u32 padding;
  83. };
  84. struct fuse_kstatfs {
  85. __u64 blocks;
  86. __u64 bfree;
  87. __u64 bavail;
  88. __u64 files;
  89. __u64 ffree;
  90. __u32 bsize;
  91. __u32 namelen;
  92. __u32 frsize;
  93. __u32 padding;
  94. __u32 spare[6];
  95. };
  96. struct fuse_file_lock {
  97. __u64 start;
  98. __u64 end;
  99. __u32 type;
  100. __u32 pid; /* tgid */
  101. };
  102. /**
  103. * Bitmasks for fuse_setattr_in.valid
  104. */
  105. #define FATTR_MODE (1 << 0)
  106. #define FATTR_UID (1 << 1)
  107. #define FATTR_GID (1 << 2)
  108. #define FATTR_SIZE (1 << 3)
  109. #define FATTR_ATIME (1 << 4)
  110. #define FATTR_MTIME (1 << 5)
  111. #define FATTR_FH (1 << 6)
  112. #define FATTR_ATIME_NOW (1 << 7)
  113. #define FATTR_MTIME_NOW (1 << 8)
  114. #define FATTR_LOCKOWNER (1 << 9)
  115. /**
  116. * Flags returned by the OPEN request
  117. *
  118. * FOPEN_DIRECT_IO: bypass page cache for this open file
  119. * FOPEN_KEEP_CACHE: don't invalidate the data cache on open
  120. * FOPEN_NONSEEKABLE: the file is not seekable
  121. */
  122. #define FOPEN_DIRECT_IO (1 << 0)
  123. #define FOPEN_KEEP_CACHE (1 << 1)
  124. #define FOPEN_NONSEEKABLE (1 << 2)
  125. /**
  126. * INIT request/reply flags
  127. *
  128. * FUSE_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
  129. * FUSE_DONT_MASK: don't apply umask to file mode on create operations
  130. * FUSE_AUTO_INVAL_DATA: automatically invalidate cached pages
  131. */
  132. #define FUSE_ASYNC_READ (1 << 0)
  133. #define FUSE_POSIX_LOCKS (1 << 1)
  134. #define FUSE_FILE_OPS (1 << 2)
  135. #define FUSE_ATOMIC_O_TRUNC (1 << 3)
  136. #define FUSE_EXPORT_SUPPORT (1 << 4)
  137. #define FUSE_BIG_WRITES (1 << 5)
  138. #define FUSE_DONT_MASK (1 << 6)
  139. #define FUSE_AUTO_INVAL_DATA (1 << 12)
  140. #define FUSE_DO_READDIRPLUS (1 << 13)
  141. /**
  142. * CUSE INIT request/reply flags
  143. *
  144. * CUSE_UNRESTRICTED_IOCTL: use unrestricted ioctl
  145. */
  146. #define CUSE_UNRESTRICTED_IOCTL (1 << 0)
  147. /**
  148. * Release flags
  149. */
  150. #define FUSE_RELEASE_FLUSH (1 << 0)
  151. /**
  152. * Getattr flags
  153. */
  154. #define FUSE_GETATTR_FH (1 << 0)
  155. /**
  156. * Lock flags
  157. */
  158. #define FUSE_LK_FLOCK (1 << 0)
  159. /**
  160. * WRITE flags
  161. *
  162. * FUSE_WRITE_CACHE: delayed write from page cache, file handle is guessed
  163. * FUSE_WRITE_LOCKOWNER: lock_owner field is valid
  164. */
  165. #define FUSE_WRITE_CACHE (1 << 0)
  166. #define FUSE_WRITE_LOCKOWNER (1 << 1)
  167. /**
  168. * Read flags
  169. */
  170. #define FUSE_READ_LOCKOWNER (1 << 1)
  171. /**
  172. * Ioctl flags
  173. *
  174. * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
  175. * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
  176. * FUSE_IOCTL_RETRY: retry with new iovecs
  177. *
  178. * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
  179. */
  180. #define FUSE_IOCTL_COMPAT (1 << 0)
  181. #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
  182. #define FUSE_IOCTL_RETRY (1 << 2)
  183. #define FUSE_IOCTL_MAX_IOV 256
  184. /**
  185. * Poll flags
  186. *
  187. * FUSE_POLL_SCHEDULE_NOTIFY: request poll notify
  188. */
  189. #define FUSE_POLL_SCHEDULE_NOTIFY (1 << 0)
  190. enum fuse_opcode {
  191. FUSE_LOOKUP = 1,
  192. FUSE_FORGET = 2, /* no reply */
  193. FUSE_GETATTR = 3,
  194. FUSE_SETATTR = 4,
  195. FUSE_READLINK = 5,
  196. FUSE_SYMLINK = 6,
  197. FUSE_MKNOD = 8,
  198. FUSE_MKDIR = 9,
  199. FUSE_UNLINK = 10,
  200. FUSE_RMDIR = 11,
  201. FUSE_RENAME = 12,
  202. FUSE_LINK = 13,
  203. FUSE_OPEN = 14,
  204. FUSE_READ = 15,
  205. FUSE_WRITE = 16,
  206. FUSE_STATFS = 17,
  207. FUSE_RELEASE = 18,
  208. FUSE_FSYNC = 20,
  209. FUSE_SETXATTR = 21,
  210. FUSE_GETXATTR = 22,
  211. FUSE_LISTXATTR = 23,
  212. FUSE_REMOVEXATTR = 24,
  213. FUSE_FLUSH = 25,
  214. FUSE_INIT = 26,
  215. FUSE_OPENDIR = 27,
  216. FUSE_READDIR = 28,
  217. FUSE_RELEASEDIR = 29,
  218. FUSE_FSYNCDIR = 30,
  219. FUSE_GETLK = 31,
  220. FUSE_SETLK = 32,
  221. FUSE_SETLKW = 33,
  222. FUSE_ACCESS = 34,
  223. FUSE_CREATE = 35,
  224. FUSE_INTERRUPT = 36,
  225. FUSE_BMAP = 37,
  226. FUSE_DESTROY = 38,
  227. FUSE_IOCTL = 39,
  228. FUSE_POLL = 40,
  229. FUSE_READDIRPLUS = 44,
  230. /* CUSE specific operations */
  231. CUSE_INIT = 4096,
  232. };
  233. enum fuse_notify_code {
  234. FUSE_NOTIFY_POLL = 1,
  235. FUSE_NOTIFY_INVAL_INODE = 2,
  236. FUSE_NOTIFY_INVAL_ENTRY = 3,
  237. FUSE_NOTIFY_CODE_MAX,
  238. };
  239. /* The read buffer is required to be at least 8k, but may be much larger */
  240. #define FUSE_MIN_READ_BUFFER 8192
  241. #define FUSE_COMPAT_ENTRY_OUT_SIZE 120
  242. struct fuse_entry_out {
  243. __u64 nodeid; /* Inode ID */
  244. __u64 generation; /* Inode generation: nodeid:gen must
  245. be unique for the fs's lifetime */
  246. __u64 entry_valid; /* Cache timeout for the name */
  247. __u64 attr_valid; /* Cache timeout for the attributes */
  248. __u32 entry_valid_nsec;
  249. __u32 attr_valid_nsec;
  250. struct fuse_attr attr;
  251. };
  252. struct fuse_forget_in {
  253. __u64 nlookup;
  254. };
  255. struct fuse_getattr_in {
  256. __u32 getattr_flags;
  257. __u32 dummy;
  258. __u64 fh;
  259. };
  260. #define FUSE_COMPAT_ATTR_OUT_SIZE 96
  261. struct fuse_attr_out {
  262. __u64 attr_valid; /* Cache timeout for the attributes */
  263. __u32 attr_valid_nsec;
  264. __u32 dummy;
  265. struct fuse_attr attr;
  266. };
  267. #define FUSE_COMPAT_MKNOD_IN_SIZE 8
  268. struct fuse_mknod_in {
  269. __u32 mode;
  270. __u32 rdev;
  271. __u32 umask;
  272. __u32 padding;
  273. };
  274. struct fuse_mkdir_in {
  275. __u32 mode;
  276. __u32 umask;
  277. };
  278. struct fuse_rename_in {
  279. __u64 newdir;
  280. };
  281. struct fuse_link_in {
  282. __u64 oldnodeid;
  283. };
  284. struct fuse_setattr_in {
  285. __u32 valid;
  286. __u32 padding;
  287. __u64 fh;
  288. __u64 size;
  289. __u64 lock_owner;
  290. __u64 atime;
  291. __u64 mtime;
  292. __u64 unused2;
  293. __u32 atimensec;
  294. __u32 mtimensec;
  295. __u32 unused3;
  296. __u32 mode;
  297. __u32 unused4;
  298. __u32 uid;
  299. __u32 gid;
  300. __u32 unused5;
  301. };
  302. struct fuse_open_in {
  303. __u32 flags;
  304. __u32 unused;
  305. };
  306. struct fuse_create_in {
  307. __u32 flags;
  308. __u32 mode;
  309. __u32 umask;
  310. __u32 padding;
  311. };
  312. struct fuse_open_out {
  313. __u64 fh;
  314. __u32 open_flags;
  315. __u32 padding;
  316. };
  317. struct fuse_release_in {
  318. __u64 fh;
  319. __u32 flags;
  320. __u32 release_flags;
  321. __u64 lock_owner;
  322. };
  323. struct fuse_flush_in {
  324. __u64 fh;
  325. __u32 unused;
  326. __u32 padding;
  327. __u64 lock_owner;
  328. };
  329. struct fuse_read_in {
  330. __u64 fh;
  331. __u64 offset;
  332. __u32 size;
  333. __u32 read_flags;
  334. __u64 lock_owner;
  335. __u32 flags;
  336. __u32 padding;
  337. };
  338. #define FUSE_COMPAT_WRITE_IN_SIZE 24
  339. struct fuse_write_in {
  340. __u64 fh;
  341. __u64 offset;
  342. __u32 size;
  343. __u32 write_flags;
  344. __u64 lock_owner;
  345. __u32 flags;
  346. __u32 padding;
  347. };
  348. struct fuse_write_out {
  349. __u32 size;
  350. __u32 padding;
  351. };
  352. #define FUSE_COMPAT_STATFS_SIZE 48
  353. struct fuse_statfs_out {
  354. struct fuse_kstatfs st;
  355. };
  356. struct fuse_fsync_in {
  357. __u64 fh;
  358. __u32 fsync_flags;
  359. __u32 padding;
  360. };
  361. struct fuse_setxattr_in {
  362. __u32 size;
  363. __u32 flags;
  364. };
  365. struct fuse_getxattr_in {
  366. __u32 size;
  367. __u32 padding;
  368. };
  369. struct fuse_getxattr_out {
  370. __u32 size;
  371. __u32 padding;
  372. };
  373. struct fuse_lk_in {
  374. __u64 fh;
  375. __u64 owner;
  376. struct fuse_file_lock lk;
  377. __u32 lk_flags;
  378. __u32 padding;
  379. };
  380. struct fuse_lk_out {
  381. struct fuse_file_lock lk;
  382. };
  383. struct fuse_access_in {
  384. __u32 mask;
  385. __u32 padding;
  386. };
  387. struct fuse_init_in {
  388. __u32 major;
  389. __u32 minor;
  390. __u32 max_readahead;
  391. __u32 flags;
  392. };
  393. struct fuse_init_out {
  394. __u32 major;
  395. __u32 minor;
  396. __u32 max_readahead;
  397. __u32 flags;
  398. __u16 max_background;
  399. __u16 congestion_threshold;
  400. __u32 max_write;
  401. };
  402. #define CUSE_INIT_INFO_MAX 4096
  403. struct cuse_init_in {
  404. __u32 major;
  405. __u32 minor;
  406. __u32 unused;
  407. __u32 flags;
  408. };
  409. struct cuse_init_out {
  410. __u32 major;
  411. __u32 minor;
  412. __u32 unused;
  413. __u32 flags;
  414. __u32 max_read;
  415. __u32 max_write;
  416. __u32 dev_major; /* chardev major */
  417. __u32 dev_minor; /* chardev minor */
  418. __u32 spare[10];
  419. };
  420. struct fuse_interrupt_in {
  421. __u64 unique;
  422. };
  423. struct fuse_bmap_in {
  424. __u64 block;
  425. __u32 blocksize;
  426. __u32 padding;
  427. };
  428. struct fuse_bmap_out {
  429. __u64 block;
  430. };
  431. struct fuse_ioctl_in {
  432. __u64 fh;
  433. __u32 flags;
  434. __u32 cmd;
  435. __u64 arg;
  436. __u32 in_size;
  437. __u32 out_size;
  438. };
  439. struct fuse_ioctl_out {
  440. __s32 result;
  441. __u32 flags;
  442. __u32 in_iovs;
  443. __u32 out_iovs;
  444. };
  445. struct fuse_poll_in {
  446. __u64 fh;
  447. __u64 kh;
  448. __u32 flags;
  449. __u32 padding;
  450. };
  451. struct fuse_poll_out {
  452. __u32 revents;
  453. __u32 padding;
  454. };
  455. struct fuse_notify_poll_wakeup_out {
  456. __u64 kh;
  457. };
  458. struct fuse_in_header {
  459. __u32 len;
  460. __u32 opcode;
  461. __u64 unique;
  462. __u64 nodeid;
  463. __u32 uid;
  464. __u32 gid;
  465. __u32 pid;
  466. __u32 padding;
  467. };
  468. struct fuse_out_header {
  469. __u32 len;
  470. __s32 error;
  471. __u64 unique;
  472. };
  473. struct fuse_dirent {
  474. __u64 ino;
  475. __u64 off;
  476. __u32 namelen;
  477. __u32 type;
  478. char name[0];
  479. };
  480. #define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
  481. #define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(__u64) - 1) & ~(sizeof(__u64) - 1))
  482. #define FUSE_DIRENT_SIZE(d) \
  483. FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
  484. struct fuse_direntplus {
  485. struct fuse_entry_out entry_out;
  486. struct fuse_dirent dirent;
  487. };
  488. #define FUSE_NAME_OFFSET_DIRENTPLUS \
  489. offsetof(struct fuse_direntplus, dirent.name)
  490. #define FUSE_DIRENTPLUS_SIZE(d) \
  491. FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET_DIRENTPLUS + (d)->dirent.namelen)
  492. struct fuse_notify_inval_inode_out {
  493. __u64 ino;
  494. __s64 off;
  495. __s64 len;
  496. };
  497. struct fuse_notify_inval_entry_out {
  498. __u64 parent;
  499. __u32 namelen;
  500. __u32 padding;
  501. };
  502. #endif /* _LINUX_FUSE_H */