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.

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