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.

1124 lines
37 KiB

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