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.

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