fuse.h 13 KB

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