You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

687 lines
13 KiB

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