fuse.h 12 KB

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