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.

1061 lines
34 KiB

  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU LGPLv2.
  5. See the file COPYING.LIB.
  6. */
  7. #ifndef _FUSE_H_
  8. #define _FUSE_H_
  9. /** @file
  10. *
  11. * This file defines the library interface of FUSE
  12. *
  13. * IMPORTANT: you should define FUSE_USE_VERSION before including this
  14. * header. To use the newest API define it to 26 (recommended for any
  15. * new application), to use the old API define it to 21 (default) 22
  16. * or 25, to use the even older 1.X API define it to 11.
  17. */
  18. #ifndef FUSE_USE_VERSION
  19. #define FUSE_USE_VERSION 21
  20. #endif
  21. #include "fuse_common.h"
  22. #include <fcntl.h>
  23. #include <time.h>
  24. #include <utime.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <sys/statvfs.h>
  28. #include <sys/uio.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* ----------------------------------------------------------- *
  33. * Basic FUSE API *
  34. * ----------------------------------------------------------- */
  35. /** Handle for a FUSE filesystem */
  36. struct fuse;
  37. /** Structure containing a raw command */
  38. struct fuse_cmd;
  39. /** Function to add an entry in a readdir() operation
  40. *
  41. * @param buf the buffer passed to the readdir() operation
  42. * @param name the file name of the directory entry
  43. * @param stat file attributes, can be NULL
  44. * @param off offset of the next entry or zero
  45. * @return 1 if buffer is full, zero otherwise
  46. */
  47. typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
  48. const struct stat *stbuf, off_t off);
  49. /* Used by deprecated getdir() method */
  50. typedef struct fuse_dirhandle *fuse_dirh_t;
  51. typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type,
  52. ino_t ino);
  53. /**
  54. * The file system operations:
  55. *
  56. * Most of these should work very similarly to the well known UNIX
  57. * file system operations. A major exception is that instead of
  58. * returning an error in 'errno', the operation should return the
  59. * negated error value (-errno) directly.
  60. *
  61. * All methods are optional, but some are essential for a useful
  62. * filesystem (e.g. getattr). Open, flush, release, fsync, opendir,
  63. * releasedir, fsyncdir, access, create, ftruncate, fgetattr, lock,
  64. * init and destroy are special purpose methods, without which a full
  65. * featured filesystem can still be implemented.
  66. *
  67. * Almost all operations take a path which can be of any length.
  68. *
  69. * Changed in fuse 2.8.0 (regardless of API version)
  70. * Previously, paths were limited to a length of PATH_MAX.
  71. *
  72. * See http://fuse.sourceforge.net/wiki/ for more information. There
  73. * is also a snapshot of the relevant wiki pages in the doc/ folder.
  74. */
  75. struct fuse_operations {
  76. /** Get file attributes.
  77. *
  78. * Similar to stat(). The 'st_dev' and 'st_blksize' fields are
  79. * ignored. The 'st_ino' field is ignored except if the 'use_ino'
  80. * mount option is given.
  81. */
  82. int (*getattr) (const char *, struct stat *);
  83. /** Read the target of a symbolic link
  84. *
  85. * The buffer should be filled with a null terminated string. The
  86. * buffer size argument includes the space for the terminating
  87. * null character. If the linkname is too long to fit in the
  88. * buffer, it should be truncated. The return value should be 0
  89. * for success.
  90. */
  91. int (*readlink) (const char *, char *, size_t);
  92. /* Deprecated, use readdir() instead */
  93. int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
  94. /** Create a file node
  95. *
  96. * This is called for creation of all non-directory, non-symlink
  97. * nodes. If the filesystem defines a create() method, then for
  98. * regular files that will be called instead.
  99. */
  100. int (*mknod) (const char *, mode_t, dev_t);
  101. /** Create a directory
  102. *
  103. * Note that the mode argument may not have the type specification
  104. * bits set, i.e. S_ISDIR(mode) can be false. To obtain the
  105. * correct directory type bits use mode|S_IFDIR
  106. * */
  107. int (*mkdir) (const char *, mode_t);
  108. /** Remove a file */
  109. int (*unlink) (const char *);
  110. /** Remove a directory */
  111. int (*rmdir) (const char *);
  112. /** Create a symbolic link */
  113. int (*symlink) (const char *, const char *);
  114. /** Rename a file */
  115. int (*rename) (const char *, const char *);
  116. /** Create a hard link to a file */
  117. int (*link) (const char *, const char *);
  118. /** Change the permission bits of a file */
  119. int (*chmod) (const char *, mode_t);
  120. /** Change the owner and group of a file */
  121. int (*chown) (const char *, uid_t, gid_t);
  122. /** Change the size of a file */
  123. int (*truncate) (const char *, off_t);
  124. /** Change the access and/or modification times of a file
  125. *
  126. * Deprecated, use utimens() instead.
  127. */
  128. int (*utime) (const char *, struct utimbuf *);
  129. /** File open operation
  130. *
  131. * No creation (O_CREAT, O_EXCL) and by default also no
  132. * truncation (O_TRUNC) flags will be passed to open(). If an
  133. * application specifies O_TRUNC, fuse first calls truncate()
  134. * and then open(). Only if 'atomic_o_trunc' has been
  135. * specified and kernel version is 2.6.24 or later, O_TRUNC is
  136. * passed on to open.
  137. *
  138. * Unless the 'default_permissions' mount option is given,
  139. * open should check if the operation is permitted for the
  140. * given flags. Optionally open may also return an arbitrary
  141. * filehandle in the fuse_file_info structure, which will be
  142. * passed to all file operations.
  143. *
  144. * Changed in version 2.2
  145. */
  146. int (*open) (const char *, struct fuse_file_info *);
  147. /** Read data from an open file
  148. *
  149. * Read should return exactly the number of bytes requested except
  150. * on EOF or error, otherwise the rest of the data will be
  151. * substituted with zeroes. An exception to this is when the
  152. * 'direct_io' mount option is specified, in which case the return
  153. * value of the read system call will reflect the return value of
  154. * this operation.
  155. *
  156. * Changed in version 2.2
  157. */
  158. int (*read) (const char *, char *, size_t, off_t,
  159. struct fuse_file_info *);
  160. /** Write data to an open file
  161. *
  162. * Write should return exactly the number of bytes requested
  163. * except on error. An exception to this is when the 'direct_io'
  164. * mount option is specified (see read operation).
  165. *
  166. * Changed in version 2.2
  167. */
  168. int (*write) (const char *, const char *, size_t, off_t,
  169. struct fuse_file_info *);
  170. /** Get file system statistics
  171. *
  172. * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
  173. *
  174. * Replaced 'struct statfs' parameter with 'struct statvfs' in
  175. * version 2.5
  176. */
  177. int (*statfs) (const char *, struct statvfs *);
  178. /** Possibly flush cached data
  179. *
  180. * BIG NOTE: This is not equivalent to fsync(). It's not a
  181. * request to sync dirty data.
  182. *
  183. * Flush is called on each close() of a file descriptor. So if a
  184. * filesystem wants to return write errors in close() and the file
  185. * has cached dirty data, this is a good place to write back data
  186. * and return any errors. Since many applications ignore close()
  187. * errors this is not always useful.
  188. *
  189. * NOTE: The flush() method may be called more than once for each
  190. * open(). This happens if more than one file descriptor refers
  191. * to an opened file due to dup(), dup2() or fork() calls. It is
  192. * not possible to determine if a flush is final, so each flush
  193. * should be treated equally. Multiple write-flush sequences are
  194. * relatively rare, so this shouldn't be a problem.
  195. *
  196. * Filesystems shouldn't assume that flush will always be called
  197. * after some writes, or that if will be called at all.
  198. *
  199. * Changed in version 2.2
  200. */
  201. int (*flush) (const char *, struct fuse_file_info *);
  202. /** Release an open file
  203. *
  204. * Release is called when there are no more references to an open
  205. * file: all file descriptors are closed and all memory mappings
  206. * are unmapped.
  207. *
  208. * For every open() call there will be exactly one release() call
  209. * with the same flags and file descriptor. It is possible to
  210. * have a file opened more than once, in which case only the last
  211. * release will mean, that no more reads/writes will happen on the
  212. * file. The return value of release is ignored.
  213. *
  214. * Changed in version 2.2
  215. */
  216. int (*release) (const char *, struct fuse_file_info *);
  217. /** Synchronize file contents
  218. *
  219. * If the datasync parameter is non-zero, then only the user data
  220. * should be flushed, not the meta data.
  221. *
  222. * Changed in version 2.2
  223. */
  224. int (*fsync) (const char *, int, struct fuse_file_info *);
  225. /** Set extended attributes */
  226. int (*setxattr) (const char *, const char *, const char *, size_t, int);
  227. /** Get extended attributes */
  228. int (*getxattr) (const char *, const char *, char *, size_t);
  229. /** List extended attributes */
  230. int (*listxattr) (const char *, char *, size_t);
  231. /** Remove extended attributes */
  232. int (*removexattr) (const char *, const char *);
  233. /** Open directory
  234. *
  235. * Unless the 'default_permissions' mount option is given,
  236. * this method should check if opendir is permitted for this
  237. * directory. Optionally opendir may also return an arbitrary
  238. * filehandle in the fuse_file_info structure, which will be
  239. * passed to readdir, closedir and fsyncdir.
  240. *
  241. * Introduced in version 2.3
  242. */
  243. int (*opendir) (const char *, struct fuse_file_info *);
  244. /** Read directory
  245. *
  246. * This supersedes the old getdir() interface. New applications
  247. * should use this.
  248. *
  249. * The filesystem may choose between two modes of operation:
  250. *
  251. * 1) The readdir implementation ignores the offset parameter, and
  252. * passes zero to the filler function's offset. The filler
  253. * function will not return '1' (unless an error happens), so the
  254. * whole directory is read in a single readdir operation. This
  255. * works just like the old getdir() method.
  256. *
  257. * 2) The readdir implementation keeps track of the offsets of the
  258. * directory entries. It uses the offset parameter and always
  259. * passes non-zero offset to the filler function. When the buffer
  260. * is full (or an error happens) the filler function will return
  261. * '1'.
  262. *
  263. * Introduced in version 2.3
  264. */
  265. int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
  266. struct fuse_file_info *);
  267. /** Release directory
  268. *
  269. * Introduced in version 2.3
  270. */
  271. int (*releasedir) (const char *, struct fuse_file_info *);
  272. /** Synchronize directory contents
  273. *
  274. * If the datasync parameter is non-zero, then only the user data
  275. * should be flushed, not the meta data
  276. *
  277. * Introduced in version 2.3
  278. */
  279. int (*fsyncdir) (const char *, int, struct fuse_file_info *);
  280. /**
  281. * Initialize filesystem
  282. *
  283. * The return value will passed in the private_data field of
  284. * fuse_context to all file operations and as a parameter to the
  285. * destroy() method.
  286. *
  287. * Introduced in version 2.3
  288. * Changed in version 2.6
  289. */
  290. void *(*init) (struct fuse_conn_info *conn);
  291. /**
  292. * Clean up filesystem
  293. *
  294. * Called on filesystem exit.
  295. *
  296. * Introduced in version 2.3
  297. */
  298. void (*destroy) (void *);
  299. /**
  300. * Check file access permissions
  301. *
  302. * This will be called for the access() system call. If the
  303. * 'default_permissions' mount option is given, this method is not
  304. * called.
  305. *
  306. * This method is not called under Linux kernel versions 2.4.x
  307. *
  308. * Introduced in version 2.5
  309. */
  310. int (*access) (const char *, int);
  311. /**
  312. * Create and open a file
  313. *
  314. * If the file does not exist, first create it with the specified
  315. * mode, and then open it.
  316. *
  317. * If this method is not implemented or under Linux kernel
  318. * versions earlier than 2.6.15, the mknod() and open() methods
  319. * will be called instead.
  320. *
  321. * Introduced in version 2.5
  322. */
  323. int (*create) (const char *, mode_t, struct fuse_file_info *);
  324. /**
  325. * Change the size of an open file
  326. *
  327. * This method is called instead of the truncate() method if the
  328. * truncation was invoked from an ftruncate() system call.
  329. *
  330. * If this method is not implemented or under Linux kernel
  331. * versions earlier than 2.6.15, the truncate() method will be
  332. * called instead.
  333. *
  334. * Introduced in version 2.5
  335. */
  336. int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
  337. /**
  338. * Get attributes from an open file
  339. *
  340. * This method is called instead of the getattr() method if the
  341. * file information is available.
  342. *
  343. * Currently this is only called after the create() method if that
  344. * is implemented (see above). Later it may be called for
  345. * invocations of fstat() too.
  346. *
  347. * Introduced in version 2.5
  348. */
  349. int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
  350. /**
  351. * Perform POSIX file locking operation
  352. *
  353. * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
  354. *
  355. * For the meaning of fields in 'struct flock' see the man page
  356. * for fcntl(2). The l_whence field will always be set to
  357. * SEEK_SET.
  358. *
  359. * For checking lock ownership, the 'fuse_file_info->owner'
  360. * argument must be used.
  361. *
  362. * For F_GETLK operation, the library will first check currently
  363. * held locks, and if a conflicting lock is found it will return
  364. * information without calling this method. This ensures, that
  365. * for local locks the l_pid field is correctly filled in. The
  366. * results may not be accurate in case of race conditions and in
  367. * the presence of hard links, but it's unlikely that an
  368. * application would rely on accurate GETLK results in these
  369. * cases. If a conflicting lock is not found, this method will be
  370. * called, and the filesystem may fill out l_pid by a meaningful
  371. * value, or it may leave this field zero.
  372. *
  373. * For F_SETLK and F_SETLKW the l_pid field will be set to the pid
  374. * of the process performing the locking operation.
  375. *
  376. * Note: if this method is not implemented, the kernel will still
  377. * allow file locking to work locally. Hence it is only
  378. * interesting for network filesystems and similar.
  379. *
  380. * Introduced in version 2.6
  381. */
  382. int (*lock) (const char *, struct fuse_file_info *, int cmd,
  383. struct flock *);
  384. /**
  385. * Change the access and modification times of a file with
  386. * nanosecond resolution
  387. *
  388. * This supersedes the old utime() interface. New applications
  389. * should use this.
  390. *
  391. * See the utimensat(2) man page for details.
  392. *
  393. * Introduced in version 2.6
  394. */
  395. int (*utimens) (const char *, const struct timespec tv[2]);
  396. /**
  397. * Map block index within file to block index within device
  398. *
  399. * Note: This makes sense only for block device backed filesystems
  400. * mounted with the 'blkdev' option
  401. *
  402. * Introduced in version 2.6
  403. */
  404. int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
  405. /**
  406. * Flag indicating that the filesystem can accept a NULL path
  407. * as the first argument for the following operations:
  408. *
  409. * read, write, flush, release, fsync, readdir, releasedir,
  410. * fsyncdir, ftruncate, fgetattr, lock, ioctl and poll
  411. *
  412. * If this flag is set these operations continue to work on
  413. * unlinked files even if "-ohard_remove" option was specified.
  414. */
  415. unsigned int flag_nullpath_ok:1;
  416. /**
  417. * Flag indicating that the path need not be calculated for
  418. * the following operations:
  419. *
  420. * read, write, flush, release, fsync, readdir, releasedir,
  421. * fsyncdir, ftruncate, fgetattr, lock, ioctl and poll
  422. *
  423. * Closely related to flag_nullpath_ok, but if this flag is
  424. * set then the path will not be calculaged even if the file
  425. * wasn't unlinked. However the path can still be non-NULL if
  426. * it needs to be calculated for some other reason.
  427. */
  428. unsigned int flag_nopath:1;
  429. /**
  430. * Flag indicating that the filesystem accepts special
  431. * UTIME_NOW and UTIME_OMIT values in its utimens operation.
  432. */
  433. unsigned int flag_utime_omit_ok:1;
  434. /**
  435. * Reserved flags, don't set
  436. */
  437. unsigned int flag_reserved:29;
  438. /**
  439. * Ioctl
  440. *
  441. * flags will have FUSE_IOCTL_COMPAT set for 32bit ioctls in
  442. * 64bit environment. The size and direction of data is
  443. * determined by _IOC_*() decoding of cmd. For _IOC_NONE,
  444. * data will be NULL, for _IOC_WRITE data is out area, for
  445. * _IOC_READ in area and if both are set in/out area. In all
  446. * non-NULL cases, the area is of _IOC_SIZE(cmd) bytes.
  447. *
  448. * If flags has FUSE_IOCTL_DIR then the fuse_file_info refers to a
  449. * directory file handle.
  450. *
  451. * Introduced in version 2.8
  452. */
  453. int (*ioctl) (const char *, int cmd, void *arg,
  454. struct fuse_file_info *, unsigned int flags, void *data);
  455. /**
  456. * Poll for IO readiness events
  457. *
  458. * Note: If ph is non-NULL, the client should notify
  459. * when IO readiness events occur by calling
  460. * fuse_notify_poll() with the specified ph.
  461. *
  462. * Regardless of the number of times poll with a non-NULL ph
  463. * is received, single notification is enough to clear all.
  464. * Notifying more times incurs overhead but doesn't harm
  465. * correctness.
  466. *
  467. * The callee is responsible for destroying ph with
  468. * fuse_pollhandle_destroy() when no longer in use.
  469. *
  470. * Introduced in version 2.8
  471. */
  472. int (*poll) (const char *, struct fuse_file_info *,
  473. struct fuse_pollhandle *ph, unsigned *reventsp);
  474. /** Write contents of buffer to an open file
  475. *
  476. * Similar to the write() method, but data is supplied in a
  477. * generic buffer. Use fuse_buf_copy() to transfer data to
  478. * the destination.
  479. *
  480. * Introduced in version 2.9
  481. */
  482. int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off,
  483. struct fuse_file_info *);
  484. /** Store data from an open file in a buffer
  485. *
  486. * Similar to the read() method, but data is stored and
  487. * returned in a generic buffer.
  488. *
  489. * No actual copying of data has to take place, the source
  490. * file descriptor may simply be stored in the buffer for
  491. * later data transfer.
  492. *
  493. * The buffer must be allocated dynamically and stored at the
  494. * location pointed to by bufp. If the buffer contains memory
  495. * regions, they too must be allocated using malloc(). The
  496. * allocated memory will be freed by the caller.
  497. *
  498. * Introduced in version 2.9
  499. */
  500. int (*read_buf) (const char *, struct fuse_bufvec **bufp,
  501. size_t size, off_t off, struct fuse_file_info *);
  502. /**
  503. * Perform BSD file locking operation
  504. *
  505. * The op argument will be either LOCK_SH, LOCK_EX or LOCK_UN
  506. *
  507. * Nonblocking requests will be indicated by ORing LOCK_NB to
  508. * the above operations
  509. *
  510. * For more information see the flock(2) manual page.
  511. *
  512. * Additionally fi->owner will be set to a value unique to
  513. * this open file. This same value will be supplied to
  514. * ->release() when the file is released.
  515. *
  516. * Note: if this method is not implemented, the kernel will still
  517. * allow file locking to work locally. Hence it is only
  518. * interesting for network filesystems and similar.
  519. *
  520. * Introduced in version 2.9
  521. */
  522. int (*flock) (const char *, struct fuse_file_info *, int op);
  523. /**
  524. * Allocates space for an open file
  525. *
  526. * This function ensures that required space is allocated for specified
  527. * file. If this function returns success then any subsequent write
  528. * request to specified range is guaranteed not to fail because of lack
  529. * of space on the file system media.
  530. *
  531. * Introduced in version 2.9.1
  532. */
  533. int (*fallocate) (const char *, int, off_t, off_t,
  534. struct fuse_file_info *);
  535. };
  536. /** Extra context that may be needed by some filesystems
  537. *
  538. * The uid, gid and pid fields are not filled in case of a writepage
  539. * operation.
  540. */
  541. struct fuse_context {
  542. /** Pointer to the fuse object */
  543. struct fuse *fuse;
  544. /** User ID of the calling process */
  545. uid_t uid;
  546. /** Group ID of the calling process */
  547. gid_t gid;
  548. /** Thread ID of the calling process */
  549. pid_t pid;
  550. /** Private filesystem data */
  551. void *private_data;
  552. /** Umask of the calling process (introduced in version 2.8) */
  553. mode_t umask;
  554. };
  555. /**
  556. * Main function of FUSE.
  557. *
  558. * This is for the lazy. This is all that has to be called from the
  559. * main() function.
  560. *
  561. * This function does the following:
  562. * - parses command line options (-d -s and -h)
  563. * - passes relevant mount options to the fuse_mount()
  564. * - installs signal handlers for INT, HUP, TERM and PIPE
  565. * - registers an exit handler to unmount the filesystem on program exit
  566. * - creates a fuse handle
  567. * - registers the operations
  568. * - calls either the single-threaded or the multi-threaded event loop
  569. *
  570. * Note: this is currently implemented as a macro.
  571. *
  572. * @param argc the argument counter passed to the main() function
  573. * @param argv the argument vector passed to the main() function
  574. * @param op the file system operation
  575. * @param user_data user data supplied in the context during the init() method
  576. * @return 0 on success, nonzero on failure
  577. */
  578. /*
  579. int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
  580. void *user_data);
  581. */
  582. #define fuse_main(argc, argv, op, user_data) \
  583. fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
  584. /* ----------------------------------------------------------- *
  585. * More detailed API *
  586. * ----------------------------------------------------------- */
  587. /**
  588. * Create a new FUSE filesystem.
  589. *
  590. * @param ch the communication channel
  591. * @param args argument vector
  592. * @param op the filesystem operations
  593. * @param op_size the size of the fuse_operations structure
  594. * @param user_data user data supplied in the context during the init() method
  595. * @return the created FUSE handle
  596. */
  597. struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
  598. const struct fuse_operations *op, size_t op_size,
  599. void *user_data);
  600. /**
  601. * Destroy the FUSE handle.
  602. *
  603. * The communication channel attached to the handle is also destroyed.
  604. *
  605. * NOTE: This function does not unmount the filesystem. If this is
  606. * needed, call fuse_unmount() before calling this function.
  607. *
  608. * @param f the FUSE handle
  609. */
  610. void fuse_destroy(struct fuse *f);
  611. /**
  612. * FUSE event loop.
  613. *
  614. * Requests from the kernel are processed, and the appropriate
  615. * operations are called.
  616. *
  617. * @param f the FUSE handle
  618. * @return 0 if no error occurred, -1 otherwise
  619. */
  620. int fuse_loop(struct fuse *f);
  621. /**
  622. * Exit from event loop
  623. *
  624. * @param f the FUSE handle
  625. */
  626. void fuse_exit(struct fuse *f);
  627. /**
  628. * FUSE event loop with multiple threads
  629. *
  630. * Requests from the kernel are processed, and the appropriate
  631. * operations are called. Request are processed in parallel by
  632. * distributing them between multiple threads.
  633. *
  634. * Calling this function requires the pthreads library to be linked to
  635. * the application.
  636. *
  637. * @param f the FUSE handle
  638. * @return 0 if no error occurred, -1 otherwise
  639. */
  640. int fuse_loop_mt(struct fuse *f);
  641. /**
  642. * Get the current context
  643. *
  644. * The context is only valid for the duration of a filesystem
  645. * operation, and thus must not be stored and used later.
  646. *
  647. * @return the context
  648. */
  649. struct fuse_context *fuse_get_context(void);
  650. /**
  651. * Get the current supplementary group IDs for the current request
  652. *
  653. * Similar to the getgroups(2) system call, except the return value is
  654. * always the total number of group IDs, even if it is larger than the
  655. * specified size.
  656. *
  657. * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
  658. * the group list to userspace, hence this function needs to parse
  659. * "/proc/$TID/task/$TID/status" to get the group IDs.
  660. *
  661. * This feature may not be supported on all operating systems. In
  662. * such a case this function will return -ENOSYS.
  663. *
  664. * @param size size of given array
  665. * @param list array of group IDs to be filled in
  666. * @return the total number of supplementary group IDs or -errno on failure
  667. */
  668. int fuse_getgroups(int size, gid_t list[]);
  669. /**
  670. * Check if the current request has already been interrupted
  671. *
  672. * @return 1 if the request has been interrupted, 0 otherwise
  673. */
  674. int fuse_interrupted(void);
  675. /**
  676. * Obsolete, doesn't do anything
  677. *
  678. * @return -EINVAL
  679. */
  680. int fuse_invalidate(struct fuse *f, const char *path);
  681. /* Deprecated, don't use */
  682. int fuse_is_lib_option(const char *opt);
  683. /**
  684. * The real main function
  685. *
  686. * Do not call this directly, use fuse_main()
  687. */
  688. int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
  689. size_t op_size, void *user_data);
  690. /**
  691. * Start the cleanup thread when using option "remember".
  692. *
  693. * This is done automatically by fuse_loop_mt()
  694. * @param fuse struct fuse pointer for fuse instance
  695. * @return 0 on success and -1 on error
  696. */
  697. int fuse_start_cleanup_thread(struct fuse *fuse);
  698. /**
  699. * Stop the cleanup thread when using option "remember".
  700. *
  701. * This is done automatically by fuse_loop_mt()
  702. * @param fuse struct fuse pointer for fuse instance
  703. */
  704. void fuse_stop_cleanup_thread(struct fuse *fuse);
  705. /**
  706. * Iterate over cache removing stale entries
  707. * use in conjunction with "-oremember"
  708. *
  709. * NOTE: This is already done for the standard sessions
  710. *
  711. * @param fuse struct fuse pointer for fuse instance
  712. * @return the number of seconds until the next cleanup
  713. */
  714. int fuse_clean_cache(struct fuse *fuse);
  715. /*
  716. * Stacking API
  717. */
  718. /**
  719. * Fuse filesystem object
  720. *
  721. * This is opaque object represents a filesystem layer
  722. */
  723. struct fuse_fs;
  724. /*
  725. * These functions call the relevant filesystem operation, and return
  726. * the result.
  727. *
  728. * If the operation is not defined, they return -ENOSYS, with the
  729. * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
  730. * fuse_fs_releasedir and fuse_fs_statfs, which return 0.
  731. */
  732. int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf);
  733. int fuse_fs_fgetattr(struct fuse_fs *fs, const char *path, struct stat *buf,
  734. struct fuse_file_info *fi);
  735. int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
  736. const char *newpath);
  737. int fuse_fs_unlink(struct fuse_fs *fs, const char *path);
  738. int fuse_fs_rmdir(struct fuse_fs *fs, const char *path);
  739. int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname,
  740. const char *path);
  741. int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath);
  742. int fuse_fs_release(struct fuse_fs *fs, const char *path,
  743. struct fuse_file_info *fi);
  744. int fuse_fs_open(struct fuse_fs *fs, const char *path,
  745. struct fuse_file_info *fi);
  746. int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size,
  747. off_t off, struct fuse_file_info *fi);
  748. int fuse_fs_read_buf(struct fuse_fs *fs, const char *path,
  749. struct fuse_bufvec **bufp, size_t size, off_t off,
  750. struct fuse_file_info *fi);
  751. int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf,
  752. size_t size, off_t off, struct fuse_file_info *fi);
  753. int fuse_fs_write_buf(struct fuse_fs *fs, const char *path,
  754. struct fuse_bufvec *buf, off_t off,
  755. struct fuse_file_info *fi);
  756. int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync,
  757. struct fuse_file_info *fi);
  758. int fuse_fs_flush(struct fuse_fs *fs, const char *path,
  759. struct fuse_file_info *fi);
  760. int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf);
  761. int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
  762. struct fuse_file_info *fi);
  763. int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf,
  764. fuse_fill_dir_t filler, off_t off,
  765. struct fuse_file_info *fi);
  766. int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync,
  767. struct fuse_file_info *fi);
  768. int fuse_fs_releasedir(struct fuse_fs *fs, const char *path,
  769. struct fuse_file_info *fi);
  770. int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode,
  771. struct fuse_file_info *fi);
  772. int fuse_fs_lock(struct fuse_fs *fs, const char *path,
  773. struct fuse_file_info *fi, int cmd, struct flock *lock);
  774. int fuse_fs_flock(struct fuse_fs *fs, const char *path,
  775. struct fuse_file_info *fi, int op);
  776. int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode);
  777. int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid);
  778. int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size);
  779. int fuse_fs_ftruncate(struct fuse_fs *fs, const char *path, off_t size,
  780. struct fuse_file_info *fi);
  781. int fuse_fs_utimens(struct fuse_fs *fs, const char *path,
  782. const struct timespec tv[2]);
  783. int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask);
  784. int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf,
  785. size_t len);
  786. int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
  787. dev_t rdev);
  788. int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode);
  789. int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name,
  790. const char *value, size_t size, int flags);
  791. int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name,
  792. char *value, size_t size);
  793. int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list,
  794. size_t size);
  795. int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
  796. const char *name);
  797. int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
  798. uint64_t *idx);
  799. int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd, void *arg,
  800. struct fuse_file_info *fi, unsigned int flags, void *data);
  801. int fuse_fs_poll(struct fuse_fs *fs, const char *path,
  802. struct fuse_file_info *fi, struct fuse_pollhandle *ph,
  803. unsigned *reventsp);
  804. int fuse_fs_fallocate(struct fuse_fs *fs, const char *path, int mode,
  805. off_t offset, off_t length, struct fuse_file_info *fi);
  806. void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn);
  807. void fuse_fs_destroy(struct fuse_fs *fs);
  808. int fuse_notify_poll(struct fuse_pollhandle *ph);
  809. /**
  810. * Create a new fuse filesystem object
  811. *
  812. * This is usually called from the factory of a fuse module to create
  813. * a new instance of a filesystem.
  814. *
  815. * @param op the filesystem operations
  816. * @param op_size the size of the fuse_operations structure
  817. * @param user_data user data supplied in the context during the init() method
  818. * @return a new filesystem object
  819. */
  820. struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
  821. void *user_data);
  822. /**
  823. * Filesystem module
  824. *
  825. * Filesystem modules are registered with the FUSE_REGISTER_MODULE()
  826. * macro.
  827. *
  828. * If the "-omodules=modname:..." option is present, filesystem
  829. * objects are created and pushed onto the stack with the 'factory'
  830. * function.
  831. */
  832. struct fuse_module {
  833. /**
  834. * Name of filesystem
  835. */
  836. const char *name;
  837. /**
  838. * Factory for creating filesystem objects
  839. *
  840. * The function may use and remove options from 'args' that belong
  841. * to this module.
  842. *
  843. * For now the 'fs' vector always contains exactly one filesystem.
  844. * This is the filesystem which will be below the newly created
  845. * filesystem in the stack.
  846. *
  847. * @param args the command line arguments
  848. * @param fs NULL terminated filesystem object vector
  849. * @return the new filesystem object
  850. */
  851. struct fuse_fs *(*factory)(struct fuse_args *args,
  852. struct fuse_fs *fs[]);
  853. struct fuse_module *next;
  854. struct fusemod_so *so;
  855. int ctr;
  856. };
  857. /**
  858. * Register a filesystem module
  859. *
  860. * This function is used by FUSE_REGISTER_MODULE and there's usually
  861. * no need to call it directly
  862. */
  863. void fuse_register_module(struct fuse_module *mod);
  864. /**
  865. * Register filesystem module
  866. *
  867. * For the parameters, see description of the fields in 'struct
  868. * fuse_module'
  869. */
  870. #define FUSE_REGISTER_MODULE(name_, factory_) \
  871. static __attribute__((constructor)) void name_ ## _register(void) \
  872. { \
  873. static struct fuse_module mod = \
  874. { #name_, factory_, NULL, NULL, 0 }; \
  875. fuse_register_module(&mod); \
  876. }
  877. /* ----------------------------------------------------------- *
  878. * Advanced API for event handling, don't worry about this... *
  879. * ----------------------------------------------------------- */
  880. /* NOTE: the following functions are deprecated, and will be removed
  881. from the 3.0 API. Use the lowlevel session functions instead */
  882. /** Function type used to process commands */
  883. typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
  884. /** This is the part of fuse_main() before the event loop */
  885. struct fuse *fuse_setup(int argc, char *argv[],
  886. const struct fuse_operations *op, size_t op_size,
  887. char **mountpoint, int *multithreaded,
  888. void *user_data);
  889. /** This is the part of fuse_main() after the event loop */
  890. void fuse_teardown(struct fuse *fuse, char *mountpoint);
  891. /** Read a single command. If none are read, return NULL */
  892. struct fuse_cmd *fuse_read_cmd(struct fuse *f);
  893. /** Process a single command */
  894. void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
  895. /** Multi threaded event loop, which calls the custom command
  896. processor function */
  897. int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data);
  898. /** Return the exited flag, which indicates if fuse_exit() has been
  899. called */
  900. int fuse_exited(struct fuse *f);
  901. /** This function is obsolete and implemented as a no-op */
  902. void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
  903. /** Get session from fuse object */
  904. struct fuse_session *fuse_get_session(struct fuse *f);
  905. /* ----------------------------------------------------------- *
  906. * Compatibility stuff *
  907. * ----------------------------------------------------------- */
  908. #if FUSE_USE_VERSION < 26
  909. # include "fuse_compat.h"
  910. # undef fuse_main
  911. # if FUSE_USE_VERSION == 25
  912. # define fuse_main(argc, argv, op) \
  913. fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
  914. # define fuse_new fuse_new_compat25
  915. # define fuse_setup fuse_setup_compat25
  916. # define fuse_teardown fuse_teardown_compat22
  917. # define fuse_operations fuse_operations_compat25
  918. # elif FUSE_USE_VERSION == 22
  919. # define fuse_main(argc, argv, op) \
  920. fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
  921. # define fuse_new fuse_new_compat22
  922. # define fuse_setup fuse_setup_compat22
  923. # define fuse_teardown fuse_teardown_compat22
  924. # define fuse_operations fuse_operations_compat22
  925. # define fuse_file_info fuse_file_info_compat
  926. # elif FUSE_USE_VERSION == 24
  927. # error Compatibility with high-level API version 24 not supported
  928. # else
  929. # define fuse_dirfil_t fuse_dirfil_t_compat
  930. # define __fuse_read_cmd fuse_read_cmd
  931. # define __fuse_process_cmd fuse_process_cmd
  932. # define __fuse_loop_mt fuse_loop_mt_proc
  933. # if FUSE_USE_VERSION == 21
  934. # define fuse_operations fuse_operations_compat2
  935. # define fuse_main fuse_main_compat2
  936. # define fuse_new fuse_new_compat2
  937. # define __fuse_setup fuse_setup_compat2
  938. # define __fuse_teardown fuse_teardown_compat22
  939. # define __fuse_exited fuse_exited
  940. # define __fuse_set_getcontext_func fuse_set_getcontext_func
  941. # else
  942. # define fuse_statfs fuse_statfs_compat1
  943. # define fuse_operations fuse_operations_compat1
  944. # define fuse_main fuse_main_compat1
  945. # define fuse_new fuse_new_compat1
  946. # define FUSE_DEBUG FUSE_DEBUG_COMPAT1
  947. # endif
  948. # endif
  949. #endif
  950. #ifdef __cplusplus
  951. }
  952. #endif
  953. #endif /* _FUSE_H_ */