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.

1001 lines
32 KiB

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