fuse.h 12 KB

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