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.

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