fuse.h 12 KB

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