fuse.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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_ASYNC_READ: asynchronous read requests
  155. * FUSE_POSIX_LOCKS: remote locking for POSIX file locks
  156. * FUSE_FILE_OPS: kernel sends file handle for fstat, etc... (not yet supported)
  157. * FUSE_ATOMIC_O_TRUNC: handles the O_TRUNC open flag in the filesystem
  158. * FUSE_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
  159. * FUSE_BIG_WRITES: filesystem can handle write size larger than 4kB
  160. * FUSE_DONT_MASK: don't apply umask to file mode on create operations
  161. * FUSE_SPLICE_WRITE: kernel supports splice write on the device
  162. * FUSE_SPLICE_MOVE: kernel supports splice move on the device
  163. * FUSE_SPLICE_READ: kernel supports splice read on the device
  164. * FUSE_FLOCK_LOCKS: remote locking for BSD style file locks
  165. * FUSE_HAS_IOCTL_DIR: kernel supports ioctl on directories
  166. * FUSE_AUTO_INVAL_DATA: automatically invalidate cached pages
  167. */
  168. #define FUSE_ASYNC_READ (1 << 0)
  169. #define FUSE_POSIX_LOCKS (1 << 1)
  170. #define FUSE_FILE_OPS (1 << 2)
  171. #define FUSE_ATOMIC_O_TRUNC (1 << 3)
  172. #define FUSE_EXPORT_SUPPORT (1 << 4)
  173. #define FUSE_BIG_WRITES (1 << 5)
  174. #define FUSE_DONT_MASK (1 << 6)
  175. #define FUSE_SPLICE_WRITE (1 << 7)
  176. #define FUSE_SPLICE_MOVE (1 << 8)
  177. #define FUSE_SPLICE_READ (1 << 9)
  178. #define FUSE_FLOCK_LOCKS (1 << 10)
  179. #define FUSE_HAS_IOCTL_DIR (1 << 11)
  180. #define FUSE_AUTO_INVAL_DATA (1 << 12)
  181. #define FUSE_DO_READDIRPLUS (1 << 13)
  182. /**
  183. * CUSE INIT request/reply flags
  184. *
  185. * CUSE_UNRESTRICTED_IOCTL: use unrestricted ioctl
  186. */
  187. #define CUSE_UNRESTRICTED_IOCTL (1 << 0)
  188. /**
  189. * Release flags
  190. */
  191. #define FUSE_RELEASE_FLUSH (1 << 0)
  192. #define FUSE_RELEASE_FLOCK_UNLOCK (1 << 1)
  193. /**
  194. * Getattr flags
  195. */
  196. #define FUSE_GETATTR_FH (1 << 0)
  197. /**
  198. * Lock flags
  199. */
  200. #define FUSE_LK_FLOCK (1 << 0)
  201. /**
  202. * WRITE flags
  203. *
  204. * FUSE_WRITE_CACHE: delayed write from page cache, file handle is guessed
  205. * FUSE_WRITE_LOCKOWNER: lock_owner field is valid
  206. */
  207. #define FUSE_WRITE_CACHE (1 << 0)
  208. #define FUSE_WRITE_LOCKOWNER (1 << 1)
  209. /**
  210. * Read flags
  211. */
  212. #define FUSE_READ_LOCKOWNER (1 << 1)
  213. /**
  214. * Ioctl flags
  215. *
  216. * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
  217. * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
  218. * FUSE_IOCTL_RETRY: retry with new iovecs
  219. * FUSE_IOCTL_32BIT: 32bit ioctl
  220. * FUSE_IOCTL_DIR: is a directory
  221. *
  222. * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
  223. */
  224. #define FUSE_IOCTL_COMPAT (1 << 0)
  225. #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
  226. #define FUSE_IOCTL_RETRY (1 << 2)
  227. #define FUSE_IOCTL_32BIT (1 << 3)
  228. #define FUSE_IOCTL_DIR (1 << 4)
  229. #define FUSE_IOCTL_MAX_IOV 256
  230. /**
  231. * Poll flags
  232. *
  233. * FUSE_POLL_SCHEDULE_NOTIFY: request poll notify
  234. */
  235. #define FUSE_POLL_SCHEDULE_NOTIFY (1 << 0)
  236. enum fuse_opcode {
  237. FUSE_LOOKUP = 1,
  238. FUSE_FORGET = 2, /* no reply */
  239. FUSE_GETATTR = 3,
  240. FUSE_SETATTR = 4,
  241. FUSE_READLINK = 5,
  242. FUSE_SYMLINK = 6,
  243. FUSE_MKNOD = 8,
  244. FUSE_MKDIR = 9,
  245. FUSE_UNLINK = 10,
  246. FUSE_RMDIR = 11,
  247. FUSE_RENAME = 12,
  248. FUSE_LINK = 13,
  249. FUSE_OPEN = 14,
  250. FUSE_READ = 15,
  251. FUSE_WRITE = 16,
  252. FUSE_STATFS = 17,
  253. FUSE_RELEASE = 18,
  254. FUSE_FSYNC = 20,
  255. FUSE_SETXATTR = 21,
  256. FUSE_GETXATTR = 22,
  257. FUSE_LISTXATTR = 23,
  258. FUSE_REMOVEXATTR = 24,
  259. FUSE_FLUSH = 25,
  260. FUSE_INIT = 26,
  261. FUSE_OPENDIR = 27,
  262. FUSE_READDIR = 28,
  263. FUSE_RELEASEDIR = 29,
  264. FUSE_FSYNCDIR = 30,
  265. FUSE_GETLK = 31,
  266. FUSE_SETLK = 32,
  267. FUSE_SETLKW = 33,
  268. FUSE_ACCESS = 34,
  269. FUSE_CREATE = 35,
  270. FUSE_INTERRUPT = 36,
  271. FUSE_BMAP = 37,
  272. FUSE_DESTROY = 38,
  273. FUSE_IOCTL = 39,
  274. FUSE_POLL = 40,
  275. FUSE_NOTIFY_REPLY = 41,
  276. FUSE_BATCH_FORGET = 42,
  277. FUSE_FALLOCATE = 43,
  278. FUSE_READDIRPLUS = 44,
  279. /* CUSE specific operations */
  280. CUSE_INIT = 4096,
  281. };
  282. enum fuse_notify_code {
  283. FUSE_NOTIFY_POLL = 1,
  284. FUSE_NOTIFY_INVAL_INODE = 2,
  285. FUSE_NOTIFY_INVAL_ENTRY = 3,
  286. FUSE_NOTIFY_STORE = 4,
  287. FUSE_NOTIFY_RETRIEVE = 5,
  288. FUSE_NOTIFY_DELETE = 6,
  289. FUSE_NOTIFY_CODE_MAX,
  290. };
  291. /* The read buffer is required to be at least 8k, but may be much larger */
  292. #define FUSE_MIN_READ_BUFFER 8192
  293. #define FUSE_COMPAT_ENTRY_OUT_SIZE 120
  294. struct fuse_entry_out {
  295. __u64 nodeid; /* Inode ID */
  296. __u64 generation; /* Inode generation: nodeid:gen must
  297. be unique for the fs's lifetime */
  298. __u64 entry_valid; /* Cache timeout for the name */
  299. __u64 attr_valid; /* Cache timeout for the attributes */
  300. __u32 entry_valid_nsec;
  301. __u32 attr_valid_nsec;
  302. struct fuse_attr attr;
  303. };
  304. struct fuse_forget_in {
  305. __u64 nlookup;
  306. };
  307. struct fuse_forget_one {
  308. __u64 nodeid;
  309. __u64 nlookup;
  310. };
  311. struct fuse_batch_forget_in {
  312. __u32 count;
  313. __u32 dummy;
  314. };
  315. struct fuse_getattr_in {
  316. __u32 getattr_flags;
  317. __u32 dummy;
  318. __u64 fh;
  319. };
  320. #define FUSE_COMPAT_ATTR_OUT_SIZE 96
  321. struct fuse_attr_out {
  322. __u64 attr_valid; /* Cache timeout for the attributes */
  323. __u32 attr_valid_nsec;
  324. __u32 dummy;
  325. struct fuse_attr attr;
  326. };
  327. #define FUSE_COMPAT_MKNOD_IN_SIZE 8
  328. struct fuse_mknod_in {
  329. __u32 mode;
  330. __u32 rdev;
  331. __u32 umask;
  332. __u32 padding;
  333. };
  334. struct fuse_mkdir_in {
  335. __u32 mode;
  336. __u32 umask;
  337. };
  338. struct fuse_rename_in {
  339. __u64 newdir;
  340. };
  341. struct fuse_link_in {
  342. __u64 oldnodeid;
  343. };
  344. struct fuse_setattr_in {
  345. __u32 valid;
  346. __u32 padding;
  347. __u64 fh;
  348. __u64 size;
  349. __u64 lock_owner;
  350. __u64 atime;
  351. __u64 mtime;
  352. __u64 unused2;
  353. __u32 atimensec;
  354. __u32 mtimensec;
  355. __u32 unused3;
  356. __u32 mode;
  357. __u32 unused4;
  358. __u32 uid;
  359. __u32 gid;
  360. __u32 unused5;
  361. };
  362. struct fuse_open_in {
  363. __u32 flags;
  364. __u32 unused;
  365. };
  366. struct fuse_create_in {
  367. __u32 flags;
  368. __u32 mode;
  369. __u32 umask;
  370. __u32 padding;
  371. };
  372. struct fuse_open_out {
  373. __u64 fh;
  374. __u32 open_flags;
  375. __u32 padding;
  376. };
  377. struct fuse_release_in {
  378. __u64 fh;
  379. __u32 flags;
  380. __u32 release_flags;
  381. __u64 lock_owner;
  382. };
  383. struct fuse_flush_in {
  384. __u64 fh;
  385. __u32 unused;
  386. __u32 padding;
  387. __u64 lock_owner;
  388. };
  389. struct fuse_read_in {
  390. __u64 fh;
  391. __u64 offset;
  392. __u32 size;
  393. __u32 read_flags;
  394. __u64 lock_owner;
  395. __u32 flags;
  396. __u32 padding;
  397. };
  398. #define FUSE_COMPAT_WRITE_IN_SIZE 24
  399. struct fuse_write_in {
  400. __u64 fh;
  401. __u64 offset;
  402. __u32 size;
  403. __u32 write_flags;
  404. __u64 lock_owner;
  405. __u32 flags;
  406. __u32 padding;
  407. };
  408. struct fuse_write_out {
  409. __u32 size;
  410. __u32 padding;
  411. };
  412. #define FUSE_COMPAT_STATFS_SIZE 48
  413. struct fuse_statfs_out {
  414. struct fuse_kstatfs st;
  415. };
  416. struct fuse_fsync_in {
  417. __u64 fh;
  418. __u32 fsync_flags;
  419. __u32 padding;
  420. };
  421. struct fuse_setxattr_in {
  422. __u32 size;
  423. __u32 flags;
  424. };
  425. struct fuse_getxattr_in {
  426. __u32 size;
  427. __u32 padding;
  428. };
  429. struct fuse_getxattr_out {
  430. __u32 size;
  431. __u32 padding;
  432. };
  433. struct fuse_lk_in {
  434. __u64 fh;
  435. __u64 owner;
  436. struct fuse_file_lock lk;
  437. __u32 lk_flags;
  438. __u32 padding;
  439. };
  440. struct fuse_lk_out {
  441. struct fuse_file_lock lk;
  442. };
  443. struct fuse_access_in {
  444. __u32 mask;
  445. __u32 padding;
  446. };
  447. struct fuse_init_in {
  448. __u32 major;
  449. __u32 minor;
  450. __u32 max_readahead;
  451. __u32 flags;
  452. };
  453. struct fuse_init_out {
  454. __u32 major;
  455. __u32 minor;
  456. __u32 max_readahead;
  457. __u32 flags;
  458. __u16 max_background;
  459. __u16 congestion_threshold;
  460. __u32 max_write;
  461. };
  462. #define CUSE_INIT_INFO_MAX 4096
  463. struct cuse_init_in {
  464. __u32 major;
  465. __u32 minor;
  466. __u32 unused;
  467. __u32 flags;
  468. };
  469. struct cuse_init_out {
  470. __u32 major;
  471. __u32 minor;
  472. __u32 unused;
  473. __u32 flags;
  474. __u32 max_read;
  475. __u32 max_write;
  476. __u32 dev_major; /* chardev major */
  477. __u32 dev_minor; /* chardev minor */
  478. __u32 spare[10];
  479. };
  480. struct fuse_interrupt_in {
  481. __u64 unique;
  482. };
  483. struct fuse_bmap_in {
  484. __u64 block;
  485. __u32 blocksize;
  486. __u32 padding;
  487. };
  488. struct fuse_bmap_out {
  489. __u64 block;
  490. };
  491. struct fuse_ioctl_in {
  492. __u64 fh;
  493. __u32 flags;
  494. __u32 cmd;
  495. __u64 arg;
  496. __u32 in_size;
  497. __u32 out_size;
  498. };
  499. struct fuse_ioctl_iovec {
  500. __u64 base;
  501. __u64 len;
  502. };
  503. struct fuse_ioctl_out {
  504. __s32 result;
  505. __u32 flags;
  506. __u32 in_iovs;
  507. __u32 out_iovs;
  508. };
  509. struct fuse_poll_in {
  510. __u64 fh;
  511. __u64 kh;
  512. __u32 flags;
  513. __u32 padding;
  514. };
  515. struct fuse_poll_out {
  516. __u32 revents;
  517. __u32 padding;
  518. };
  519. struct fuse_notify_poll_wakeup_out {
  520. __u64 kh;
  521. };
  522. struct fuse_fallocate_in {
  523. __u64 fh;
  524. __u64 offset;
  525. __u64 length;
  526. __u32 mode;
  527. __u32 padding;
  528. };
  529. struct fuse_in_header {
  530. __u32 len;
  531. __u32 opcode;
  532. __u64 unique;
  533. __u64 nodeid;
  534. __u32 uid;
  535. __u32 gid;
  536. __u32 pid;
  537. __u32 padding;
  538. };
  539. struct fuse_out_header {
  540. __u32 len;
  541. __s32 error;
  542. __u64 unique;
  543. };
  544. struct fuse_dirent {
  545. __u64 ino;
  546. __u64 off;
  547. __u32 namelen;
  548. __u32 type;
  549. char name[];
  550. };
  551. #define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
  552. #define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(__u64) - 1) & ~(sizeof(__u64) - 1))
  553. #define FUSE_DIRENT_SIZE(d) \
  554. FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
  555. struct fuse_direntplus {
  556. struct fuse_entry_out entry_out;
  557. struct fuse_dirent dirent;
  558. };
  559. #define FUSE_NAME_OFFSET_DIRENTPLUS \
  560. offsetof(struct fuse_direntplus, dirent.name)
  561. #define FUSE_DIRENTPLUS_SIZE(d) \
  562. FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET_DIRENTPLUS + (d)->dirent.namelen)
  563. struct fuse_notify_inval_inode_out {
  564. __u64 ino;
  565. __s64 off;
  566. __s64 len;
  567. };
  568. struct fuse_notify_inval_entry_out {
  569. __u64 parent;
  570. __u32 namelen;
  571. __u32 padding;
  572. };
  573. struct fuse_notify_delete_out {
  574. __u64 parent;
  575. __u64 child;
  576. __u32 namelen;
  577. __u32 padding;
  578. };
  579. struct fuse_notify_store_out {
  580. __u64 nodeid;
  581. __u64 offset;
  582. __u32 size;
  583. __u32 padding;
  584. };
  585. struct fuse_notify_retrieve_out {
  586. __u64 notify_unique;
  587. __u64 nodeid;
  588. __u64 offset;
  589. __u32 size;
  590. __u32 padding;
  591. };
  592. /* Matches the size of fuse_write_in */
  593. struct fuse_notify_retrieve_in {
  594. __u64 dummy1;
  595. __u64 offset;
  596. __u32 size;
  597. __u32 dummy2;
  598. __u64 dummy3;
  599. __u64 dummy4;
  600. };
  601. #endif /* _LINUX_FUSE_H */