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.

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