fuse.h 12 KB

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