fuse.h 11 KB

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