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.

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