fuse.h 11 KB

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