blob: f1cfeb954e19935ce24930030adc755802d54a55 [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB.
7*/
8
9#ifndef _FUSE_LOWLEVEL_H_
10#define _FUSE_LOWLEVEL_H_
11
12/** @file
13 *
14 * Low level API
15 *
16 * IMPORTANT: you should define FUSE_USE_VERSION before including this
17 * header. To use the newest API define it to 26 (recommended for any
18 * new application), to use the old API define it to 24 (default) or
19 * 25
20 */
21
22#ifndef FUSE_USE_VERSION
23#define FUSE_USE_VERSION 24
24#endif
25
26#include "fuse_common.h"
27
28#include <utime.h>
29#include <fcntl.h>
30#include <sys/types.h>
31#include <sys/stat.h>
32#include <sys/statvfs.h>
33#include <sys/uio.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* ----------------------------------------------------------- *
40 * Miscellaneous definitions *
41 * ----------------------------------------------------------- */
42
43/** The node ID of the root inode */
44#define FUSE_ROOT_ID 1
45
46/** Inode number type */
47typedef unsigned long fuse_ino_t;
48
49/** Request pointer type */
50typedef struct fuse_req *fuse_req_t;
51
52/**
53 * Session
54 *
55 * This provides hooks for processing requests, and exiting
56 */
57struct fuse_session;
58
59/**
60 * Channel
61 *
62 * A communication channel, providing hooks for sending and receiving
63 * messages
64 */
65struct fuse_chan;
66
67/** Directory entry parameters supplied to fuse_reply_entry() */
68struct fuse_entry_param {
69 /** Unique inode number
70 *
71 * In lookup, zero means negative entry (from version 2.5)
72 * Returning ENOENT also means negative entry, but by setting zero
73 * ino the kernel may cache negative entries for entry_timeout
74 * seconds.
75 */
76 fuse_ino_t ino;
77
78 /** Generation number for this entry.
79 *
80 * The ino/generation pair should be unique for the filesystem's
81 * lifetime. It must be non-zero, otherwise FUSE will treat it as an
82 * error.
83 */
84 unsigned long generation;
85
86 /** Inode attributes.
87 *
88 * Even if attr_timeout == 0, attr must be correct. For example,
89 * for open(), FUSE uses attr.st_size from lookup() to determine
90 * how many bytes to request. If this value is not correct,
91 * incorrect data will be returned.
92 */
93 struct stat attr;
94
95 /** Validity timeout (in seconds) for the attributes */
96 double attr_timeout;
97
98 /** Validity timeout (in seconds) for the name */
99 double entry_timeout;
100};
101
102/** Additional context associated with requests */
103struct fuse_ctx {
104 /** User ID of the calling process */
105 uid_t uid;
106
107 /** Group ID of the calling process */
108 gid_t gid;
109
110 /** Thread ID of the calling process */
111 pid_t pid;
112
113 /** Umask of the calling process (introduced in version 2.8) */
114 mode_t umask;
115};
116
117/* 'to_set' flags in setattr */
118#define FUSE_SET_ATTR_MODE (1 << 0)
119#define FUSE_SET_ATTR_UID (1 << 1)
120#define FUSE_SET_ATTR_GID (1 << 2)
121#define FUSE_SET_ATTR_SIZE (1 << 3)
122#define FUSE_SET_ATTR_ATIME (1 << 4)
123#define FUSE_SET_ATTR_MTIME (1 << 5)
124#define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
125#define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
126
127/* ----------------------------------------------------------- *
128 * Request methods and replies *
129 * ----------------------------------------------------------- */
130
131/**
132 * Low level filesystem operations
133 *
134 * Most of the methods (with the exception of init and destroy)
135 * receive a request handle (fuse_req_t) as their first argument.
136 * This handle must be passed to one of the specified reply functions.
137 *
138 * This may be done inside the method invocation, or after the call
139 * has returned. The request handle is valid until one of the reply
140 * functions is called.
141 *
142 * Other pointer arguments (name, fuse_file_info, etc) are not valid
143 * after the call has returned, so if they are needed later, their
144 * contents have to be copied.
145 *
146 * The filesystem sometimes needs to handle a return value of -ENOENT
147 * from the reply function, which means, that the request was
148 * interrupted, and the reply discarded. For example if
149 * fuse_reply_open() return -ENOENT means, that the release method for
150 * this file will not be called.
151 */
152struct fuse_lowlevel_ops {
153 /**
154 * Initialize filesystem
155 *
156 * Called before any other filesystem method
157 *
158 * There's no reply to this function
159 *
160 * @param userdata the user data passed to fuse_lowlevel_new()
161 */
162 void (*init) (void *userdata, struct fuse_conn_info *conn);
163
164 /**
165 * Clean up filesystem
166 *
167 * Called on filesystem exit
168 *
169 * There's no reply to this function
170 *
171 * @param userdata the user data passed to fuse_lowlevel_new()
172 */
173 void (*destroy) (void *userdata);
174
175 /**
176 * Look up a directory entry by name and get its attributes.
177 *
178 * Valid replies:
179 * fuse_reply_entry
180 * fuse_reply_err
181 *
182 * @param req request handle
183 * @param parent inode number of the parent directory
184 * @param name the name to look up
185 */
186 void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
187
188 /**
189 * Forget about an inode
190 *
191 * The nlookup parameter indicates the number of lookups
192 * previously performed on this inode.
193 *
194 * If the filesystem implements inode lifetimes, it is recommended
195 * that inodes acquire a single reference on each lookup, and lose
196 * nlookup references on each forget.
197 *
198 * The filesystem may ignore forget calls, if the inodes don't
199 * need to have a limited lifetime.
200 *
201 * On unmount it is not guaranteed, that all referenced inodes
202 * will receive a forget message.
203 *
204 * Valid replies:
205 * fuse_reply_none
206 *
207 * @param req request handle
208 * @param ino the inode number
209 * @param nlookup the number of lookups to forget
210 */
211 void (*forget) (fuse_req_t req, fuse_ino_t ino, unsigned long nlookup);
212
213 /**
214 * Get file attributes
215 *
216 * Valid replies:
217 * fuse_reply_attr
218 * fuse_reply_err
219 *
220 * @param req request handle
221 * @param ino the inode number
222 * @param fi for future use, currently always NULL
223 */
224 void (*getattr) (fuse_req_t req, fuse_ino_t ino,
225 struct fuse_file_info *fi);
226
227 /**
228 * Set file attributes
229 *
230 * In the 'attr' argument only members indicated by the 'to_set'
231 * bitmask contain valid values. Other members contain undefined
232 * values.
233 *
234 * If the setattr was invoked from the ftruncate() system call
235 * under Linux kernel versions 2.6.15 or later, the fi->fh will
236 * contain the value set by the open method or will be undefined
237 * if the open method didn't set any value. Otherwise (not
238 * ftruncate call, or kernel version earlier than 2.6.15) the fi
239 * parameter will be NULL.
240 *
241 * Valid replies:
242 * fuse_reply_attr
243 * fuse_reply_err
244 *
245 * @param req request handle
246 * @param ino the inode number
247 * @param attr the attributes
248 * @param to_set bit mask of attributes which should be set
249 * @param fi file information, or NULL
250 *
251 * Changed in version 2.5:
252 * file information filled in for ftruncate
253 */
254 void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
255 int to_set, struct fuse_file_info *fi);
256
257 /**
258 * Read symbolic link
259 *
260 * Valid replies:
261 * fuse_reply_readlink
262 * fuse_reply_err
263 *
264 * @param req request handle
265 * @param ino the inode number
266 */
267 void (*readlink) (fuse_req_t req, fuse_ino_t ino);
268
269 /**
270 * Create file node
271 *
272 * Create a regular file, character device, block device, fifo or
273 * socket node.
274 *
275 * Valid replies:
276 * fuse_reply_entry
277 * fuse_reply_err
278 *
279 * @param req request handle
280 * @param parent inode number of the parent directory
281 * @param name to create
282 * @param mode file type and mode with which to create the new file
283 * @param rdev the device number (only valid if created file is a device)
284 */
285 void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
286 mode_t mode, dev_t rdev);
287
288 /**
289 * Create a directory
290 *
291 * Valid replies:
292 * fuse_reply_entry
293 * fuse_reply_err
294 *
295 * @param req request handle
296 * @param parent inode number of the parent directory
297 * @param name to create
298 * @param mode with which to create the new file
299 */
300 void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
301 mode_t mode);
302
303 /**
304 * Remove a file
305 *
306 * Valid replies:
307 * fuse_reply_err
308 *
309 * @param req request handle
310 * @param parent inode number of the parent directory
311 * @param name to remove
312 */
313 void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
314
315 /**
316 * Remove a directory
317 *
318 * Valid replies:
319 * fuse_reply_err
320 *
321 * @param req request handle
322 * @param parent inode number of the parent directory
323 * @param name to remove
324 */
325 void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
326
327 /**
328 * Create a symbolic link
329 *
330 * Valid replies:
331 * fuse_reply_entry
332 * fuse_reply_err
333 *
334 * @param req request handle
335 * @param link the contents of the symbolic link
336 * @param parent inode number of the parent directory
337 * @param name to create
338 */
339 void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
340 const char *name);
341
342 /** Rename a file
343 *
344 * Valid replies:
345 * fuse_reply_err
346 *
347 * @param req request handle
348 * @param parent inode number of the old parent directory
349 * @param name old name
350 * @param newparent inode number of the new parent directory
351 * @param newname new name
352 */
353 void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
354 fuse_ino_t newparent, const char *newname);
355
356 /**
357 * Create a hard link
358 *
359 * Valid replies:
360 * fuse_reply_entry
361 * fuse_reply_err
362 *
363 * @param req request handle
364 * @param ino the old inode number
365 * @param newparent inode number of the new parent directory
366 * @param newname new name to create
367 */
368 void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
369 const char *newname);
370
371 /**
372 * Open a file
373 *
374 * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and
375 * O_TRUNC) are available in fi->flags.
376 *
377 * Filesystem may store an arbitrary file handle (pointer, index,
378 * etc) in fi->fh, and use this in other all other file operations
379 * (read, write, flush, release, fsync).
380 *
381 * Filesystem may also implement stateless file I/O and not store
382 * anything in fi->fh.
383 *
384 * There are also some flags (direct_io, keep_cache) which the
385 * filesystem may set in fi, to change the way the file is opened.
386 * See fuse_file_info structure in <fuse_common.h> for more details.
387 *
388 * Valid replies:
389 * fuse_reply_open
390 * fuse_reply_err
391 *
392 * @param req request handle
393 * @param ino the inode number
394 * @param fi file information
395 */
396 void (*open) (fuse_req_t req, fuse_ino_t ino,
397 struct fuse_file_info *fi);
398
399 /**
400 * Read data
401 *
402 * Read should send exactly the number of bytes requested except
403 * on EOF or error, otherwise the rest of the data will be
404 * substituted with zeroes. An exception to this is when the file
405 * has been opened in 'direct_io' mode, in which case the return
406 * value of the read system call will reflect the return value of
407 * this operation.
408 *
409 * fi->fh will contain the value set by the open method, or will
410 * be undefined if the open method didn't set any value.
411 *
412 * Valid replies:
413 * fuse_reply_buf
414 * fuse_reply_iov
415 * fuse_reply_err
416 *
417 * @param req request handle
418 * @param ino the inode number
419 * @param size number of bytes to read
420 * @param off offset to read from
421 * @param fi file information
422 */
423 void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off64_t off,
424 struct fuse_file_info *fi);
425
426 /**
427 * Write data
428 *
429 * Write should return exactly the number of bytes requested
430 * except on error. An exception to this is when the file has
431 * been opened in 'direct_io' mode, in which case the return value
432 * of the write system call will reflect the return value of this
433 * operation.
434 *
435 * fi->fh will contain the value set by the open method, or will
436 * be undefined if the open method didn't set any value.
437 *
438 * Valid replies:
439 * fuse_reply_write
440 * fuse_reply_err
441 *
442 * @param req request handle
443 * @param ino the inode number
444 * @param buf data to write
445 * @param size number of bytes to write
446 * @param off offset to write to
447 * @param fi file information
448 */
449 void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
450 size_t size, off64_t off, struct fuse_file_info *fi);
451
452 /**
453 * Flush method
454 *
455 * This is called on each close() of the opened file.
456 *
457 * Since file descriptors can be duplicated (dup, dup2, fork), for
458 * one open call there may be many flush calls.
459 *
460 * Filesystems shouldn't assume that flush will always be called
461 * after some writes, or that if will be called at all.
462 *
463 * fi->fh will contain the value set by the open method, or will
464 * be undefined if the open method didn't set any value.
465 *
466 * NOTE: the name of the method is misleading, since (unlike
467 * fsync) the filesystem is not forced to flush pending writes.
468 * One reason to flush data, is if the filesystem wants to return
469 * write errors.
470 *
471 * If the filesystem supports file locking operations (setlk,
472 * getlk) it should remove all locks belonging to 'fi->owner'.
473 *
474 * Valid replies:
475 * fuse_reply_err
476 *
477 * @param req request handle
478 * @param ino the inode number
479 * @param fi file information
480 */
481 void (*flush) (fuse_req_t req, fuse_ino_t ino,
482 struct fuse_file_info *fi);
483
484 /**
485 * Release an open file
486 *
487 * Release is called when there are no more references to an open
488 * file: all file descriptors are closed and all memory mappings
489 * are unmapped.
490 *
491 * For every open call there will be exactly one release call.
492 *
493 * The filesystem may reply with an error, but error values are
494 * not returned to close() or munmap() which triggered the
495 * release.
496 *
497 * fi->fh will contain the value set by the open method, or will
498 * be undefined if the open method didn't set any value.
499 * fi->flags will contain the same flags as for open.
500 *
501 * Valid replies:
502 * fuse_reply_err
503 *
504 * @param req request handle
505 * @param ino the inode number
506 * @param fi file information
507 */
508 void (*release) (fuse_req_t req, fuse_ino_t ino,
509 struct fuse_file_info *fi);
510
511 /**
512 * Synchronize file contents
513 *
514 * If the datasync parameter is non-zero, then only the user data
515 * should be flushed, not the meta data.
516 *
517 * Valid replies:
518 * fuse_reply_err
519 *
520 * @param req request handle
521 * @param ino the inode number
522 * @param datasync flag indicating if only data should be flushed
523 * @param fi file information
524 */
525 void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
526 struct fuse_file_info *fi);
527
528 /**
529 * Open a directory
530 *
531 * Filesystem may store an arbitrary file handle (pointer, index,
532 * etc) in fi->fh, and use this in other all other directory
533 * stream operations (readdir, releasedir, fsyncdir).
534 *
535 * Filesystem may also implement stateless directory I/O and not
536 * store anything in fi->fh, though that makes it impossible to
537 * implement standard conforming directory stream operations in
538 * case the contents of the directory can change between opendir
539 * and releasedir.
540 *
541 * Valid replies:
542 * fuse_reply_open
543 * fuse_reply_err
544 *
545 * @param req request handle
546 * @param ino the inode number
547 * @param fi file information
548 */
549 void (*opendir) (fuse_req_t req, fuse_ino_t ino,
550 struct fuse_file_info *fi);
551
552 /**
553 * Read directory
554 *
555 * Send a buffer filled using fuse_add_direntry(), with size not
556 * exceeding the requested size. Send an empty buffer on end of
557 * stream.
558 *
559 * fi->fh will contain the value set by the opendir method, or
560 * will be undefined if the opendir method didn't set any value.
561 *
562 * Valid replies:
563 * fuse_reply_buf
564 * fuse_reply_err
565 *
566 * @param req request handle
567 * @param ino the inode number
568 * @param size maximum number of bytes to send
569 * @param off offset to continue reading the directory stream
570 * @param fi file information
571 */
572 void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off64_t off,
573 struct fuse_file_info *fi);
574
575 /**
576 * Release an open directory
577 *
578 * For every opendir call there will be exactly one releasedir
579 * call.
580 *
581 * fi->fh will contain the value set by the opendir method, or
582 * will be undefined if the opendir method didn't set any value.
583 *
584 * Valid replies:
585 * fuse_reply_err
586 *
587 * @param req request handle
588 * @param ino the inode number
589 * @param fi file information
590 */
591 void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
592 struct fuse_file_info *fi);
593
594 /**
595 * Synchronize directory contents
596 *
597 * If the datasync parameter is non-zero, then only the directory
598 * contents should be flushed, not the meta data.
599 *
600 * fi->fh will contain the value set by the opendir method, or
601 * will be undefined if the opendir method didn't set any value.
602 *
603 * Valid replies:
604 * fuse_reply_err
605 *
606 * @param req request handle
607 * @param ino the inode number
608 * @param datasync flag indicating if only data should be flushed
609 * @param fi file information
610 */
611 void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
612 struct fuse_file_info *fi);
613
614 /**
615 * Get file system statistics
616 *
617 * Valid replies:
618 * fuse_reply_statfs
619 * fuse_reply_err
620 *
621 * @param req request handle
622 * @param ino the inode number, zero means "undefined"
623 */
624 void (*statfs) (fuse_req_t req, fuse_ino_t ino);
625
626 /**
627 * Set an extended attribute
628 *
629 * Valid replies:
630 * fuse_reply_err
631 */
632 void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
633 const char *value, size_t size, int flags);
634
635 /**
636 * Get an extended attribute
637 *
638 * If size is zero, the size of the value should be sent with
639 * fuse_reply_xattr.
640 *
641 * If the size is non-zero, and the value fits in the buffer, the
642 * value should be sent with fuse_reply_buf.
643 *
644 * If the size is too small for the value, the ERANGE error should
645 * be sent.
646 *
647 * Valid replies:
648 * fuse_reply_buf
649 * fuse_reply_xattr
650 * fuse_reply_err
651 *
652 * @param req request handle
653 * @param ino the inode number
654 * @param name of the extended attribute
655 * @param size maximum size of the value to send
656 */
657 void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
658 size_t size);
659
660 /**
661 * List extended attribute names
662 *
663 * If size is zero, the total size of the attribute list should be
664 * sent with fuse_reply_xattr.
665 *
666 * If the size is non-zero, and the null character separated
667 * attribute list fits in the buffer, the list should be sent with
668 * fuse_reply_buf.
669 *
670 * If the size is too small for the list, the ERANGE error should
671 * be sent.
672 *
673 * Valid replies:
674 * fuse_reply_buf
675 * fuse_reply_xattr
676 * fuse_reply_err
677 *
678 * @param req request handle
679 * @param ino the inode number
680 * @param size maximum size of the list to send
681 */
682 void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
683
684 /**
685 * Remove an extended attribute
686 *
687 * Valid replies:
688 * fuse_reply_err
689 *
690 * @param req request handle
691 * @param ino the inode number
692 * @param name of the extended attribute
693 */
694 void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
695
696 /**
697 * Check file access permissions
698 *
699 * This will be called for the access() system call. If the
700 * 'default_permissions' mount option is given, this method is not
701 * called.
702 *
703 * This method is not called under Linux kernel versions 2.4.x
704 *
705 * Introduced in version 2.5
706 *
707 * Valid replies:
708 * fuse_reply_err
709 *
710 * @param req request handle
711 * @param ino the inode number
712 * @param mask requested access mode
713 */
714 void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
715
716 /**
717 * Create and open a file
718 *
719 * If the file does not exist, first create it with the specified
720 * mode, and then open it.
721 *
722 * Open flags (with the exception of O_NOCTTY) are available in
723 * fi->flags.
724 *
725 * Filesystem may store an arbitrary file handle (pointer, index,
726 * etc) in fi->fh, and use this in other all other file operations
727 * (read, write, flush, release, fsync).
728 *
729 * There are also some flags (direct_io, keep_cache) which the
730 * filesystem may set in fi, to change the way the file is opened.
731 * See fuse_file_info structure in <fuse_common.h> for more details.
732 *
733 * If this method is not implemented or under Linux kernel
734 * versions earlier than 2.6.15, the mknod() and open() methods
735 * will be called instead.
736 *
737 * Introduced in version 2.5
738 *
739 * Valid replies:
740 * fuse_reply_create
741 * fuse_reply_err
742 *
743 * @param req request handle
744 * @param parent inode number of the parent directory
745 * @param name to create
746 * @param mode file type and mode with which to create the new file
747 * @param fi file information
748 */
749 void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
750 mode_t mode, struct fuse_file_info *fi);
751
752 /**
753 * Test for a POSIX file lock
754 *
755 * Introduced in version 2.6
756 *
757 * Valid replies:
758 * fuse_reply_lock
759 * fuse_reply_err
760 *
761 * @param req request handle
762 * @param ino the inode number
763 * @param fi file information
764 * @param lock the region/type to test
765 */
766 void (*getlk) (fuse_req_t req, fuse_ino_t ino,
767 struct fuse_file_info *fi, struct flock *lock);
768
769 /**
770 * Acquire, modify or release a POSIX file lock
771 *
772 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
773 * owner, but otherwise this is not always the case. For checking
774 * lock ownership, 'fi->owner' must be used. The l_pid field in
775 * 'struct flock' should only be used to fill in this field in
776 * getlk().
777 *
778 * Note: if the locking methods are not implemented, the kernel
779 * will still allow file locking to work locally. Hence these are
780 * only interesting for network filesystems and similar.
781 *
782 * Introduced in version 2.6
783 *
784 * Valid replies:
785 * fuse_reply_err
786 *
787 * @param req request handle
788 * @param ino the inode number
789 * @param fi file information
790 * @param lock the region/type to test
791 * @param sleep locking operation may sleep
792 */
793 void (*setlk) (fuse_req_t req, fuse_ino_t ino,
794 struct fuse_file_info *fi,
795 struct flock *lock, int sleep);
796
797 /**
798 * Map block index within file to block index within device
799 *
800 * Note: This makes sense only for block device backed filesystems
801 * mounted with the 'blkdev' option
802 *
803 * Introduced in version 2.6
804 *
805 * Valid replies:
806 * fuse_reply_bmap
807 * fuse_reply_err
808 *
809 * @param req request handle
810 * @param ino the inode number
811 * @param blocksize unit of block index
812 * @param idx block index within file
813 */
814 void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
815 uint64_t idx);
816
817 /**
818 * Ioctl
819 *
820 * Note: For unrestricted ioctls (not allowed for FUSE
821 * servers), data in and out areas can be discovered by giving
822 * iovs and setting FUSE_IOCTL_RETRY in @flags. For
823 * restricted ioctls, kernel prepares in/out data area
824 * according to the information encoded in cmd.
825 *
826 * Introduced in version 2.8
827 *
828 * Valid replies:
829 * fuse_reply_ioctl_retry
830 * fuse_reply_ioctl
831 * fuse_reply_ioctl_iov
832 * fuse_reply_err
833 *
834 * @param req request handle
835 * @param ino the inode number
836 * @param cmd ioctl command
837 * @param arg ioctl argument
838 * @param fi file information
839 * @param flags for FUSE_IOCTL_* flags
840 * @param in_buf data fetched from the caller
841 * @param in_bufsz number of fetched bytes
842 * @param out_bufsz maximum size of output data
843 */
844 void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg,
845 struct fuse_file_info *fi, unsigned flags,
846 const void *in_buf, size_t in_bufsz, size_t out_bufsz);
847
848 /**
849 * Poll for IO readiness
850 *
851 * Introduced in version 2.8
852 *
853 * Note: If ph is non-NULL, the client should notify
854 * when IO readiness events occur by calling
855 * fuse_lowelevel_notify_poll() with the specified ph.
856 *
857 * Regardless of the number of times poll with a non-NULL ph
858 * is received, single notification is enough to clear all.
859 * Notifying more times incurs overhead but doesn't harm
860 * correctness.
861 *
862 * The callee is responsible for destroying ph with
863 * fuse_pollhandle_destroy() when no longer in use.
864 *
865 * Valid replies:
866 * fuse_reply_poll
867 * fuse_reply_err
868 *
869 * @param req request handle
870 * @param ino the inode number
871 * @param fi file information
872 * @param ph poll handle to be used for notification
873 */
874 void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
875 struct fuse_pollhandle *ph);
876};
877
878/**
879 * Reply with an error code or success
880 *
881 * Possible requests:
882 * all except forget
883 *
884 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
885 * removexattr and setlk may send a zero code
886 *
887 * @param req request handle
888 * @param err the positive error value, or zero for success
889 * @return zero for success, -errno for failure to send reply
890 */
891int fuse_reply_err(fuse_req_t req, int err);
892
893/**
894 * Don't send reply
895 *
896 * Possible requests:
897 * forget
898 *
899 * @param req request handle
900 */
901void fuse_reply_none(fuse_req_t req);
902
903/**
904 * Reply with a directory entry
905 *
906 * Possible requests:
907 * lookup, mknod, mkdir, symlink, link
908 *
909 * @param req request handle
910 * @param e the entry parameters
911 * @return zero for success, -errno for failure to send reply
912 */
913int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
914
915/**
916 * Reply with a directory entry and open parameters
917 *
918 * currently the following members of 'fi' are used:
919 * fh, direct_io, keep_cache
920 *
921 * Possible requests:
922 * create
923 *
924 * @param req request handle
925 * @param e the entry parameters
926 * @param fi file information
927 * @return zero for success, -errno for failure to send reply
928 */
929int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
930 const struct fuse_file_info *fi);
931
932/**
933 * Reply with attributes
934 *
935 * Possible requests:
936 * getattr, setattr
937 *
938 * @param req request handle
939 * @param attr the attributes
940 * @param attr_timeout validity timeout (in seconds) for the attributes
941 * @return zero for success, -errno for failure to send reply
942 */
943int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
944 double attr_timeout);
945
946/**
947 * Reply with the contents of a symbolic link
948 *
949 * Possible requests:
950 * readlink
951 *
952 * @param req request handle
953 * @param link symbolic link contents
954 * @return zero for success, -errno for failure to send reply
955 */
956int fuse_reply_readlink(fuse_req_t req, const char *link);
957
958/**
959 * Reply with open parameters
960 *
961 * currently the following members of 'fi' are used:
962 * fh, direct_io, keep_cache
963 *
964 * Possible requests:
965 * open, opendir
966 *
967 * @param req request handle
968 * @param fi file information
969 * @return zero for success, -errno for failure to send reply
970 */
971int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
972
973/**
974 * Reply with number of bytes written
975 *
976 * Possible requests:
977 * write
978 *
979 * @param req request handle
980 * @param count the number of bytes written
981 * @return zero for success, -errno for failure to send reply
982 */
983int fuse_reply_write(fuse_req_t req, size_t count);
984
985/**
986 * Reply with data
987 *
988 * Possible requests:
989 * read, readdir, getxattr, listxattr
990 *
991 * @param req request handle
992 * @param buf buffer containing data
993 * @param size the size of data in bytes
994 * @return zero for success, -errno for failure to send reply
995 */
996int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
997
998/**
999 * Reply with data vector
1000 *
1001 * Possible requests:
1002 * read, readdir, getxattr, listxattr
1003 *
1004 * @param req request handle
1005 * @param iov the vector containing the data
1006 * @param count the size of vector
1007 * @return zero for success, -errno for failure to send reply
1008 */
1009int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1010
1011/**
1012 * Reply with filesystem statistics
1013 *
1014 * Possible requests:
1015 * statfs
1016 *
1017 * @param req request handle
1018 * @param stbuf filesystem statistics
1019 * @return zero for success, -errno for failure to send reply
1020 */
1021int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1022
1023/**
1024 * Reply with needed buffer size
1025 *
1026 * Possible requests:
1027 * getxattr, listxattr
1028 *
1029 * @param req request handle
1030 * @param count the buffer size needed in bytes
1031 * @return zero for success, -errno for failure to send reply
1032 */
1033int fuse_reply_xattr(fuse_req_t req, size_t count);
1034
1035/**
1036 * Reply with file lock information
1037 *
1038 * Possible requests:
1039 * getlk
1040 *
1041 * @param req request handle
1042 * @param lock the lock information
1043 * @return zero for success, -errno for failure to send reply
1044 */
1045int fuse_reply_lock(fuse_req_t req, struct flock *lock);
1046
1047/**
1048 * Reply with block index
1049 *
1050 * Possible requests:
1051 * bmap
1052 *
1053 * @param req request handle
1054 * @param idx block index within device
1055 * @return zero for success, -errno for failure to send reply
1056 */
1057int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1058
1059/* ----------------------------------------------------------- *
1060 * Filling a buffer in readdir *
1061 * ----------------------------------------------------------- */
1062
1063/**
1064 * Add a directory entry to the buffer
1065 *
1066 * Buffer needs to be large enough to hold the entry. If it's not,
1067 * then the entry is not filled in but the size of the entry is still
1068 * returned. The caller can check this by comparing the bufsize
1069 * parameter with the returned entry size. If the entry size is
1070 * larger than the buffer size, the operation failed.
1071 *
1072 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1073 * st_mode field are used. The other fields are ignored.
1074 *
1075 * Note: offsets do not necessarily represent physical offsets, and
1076 * could be any marker, that enables the implementation to find a
1077 * specific point in the directory stream.
1078 *
1079 * @param req request handle
1080 * @param buf the point where the new entry will be added to the buffer
1081 * @param bufsize remaining size of the buffer
1082 * @param name the name of the entry
1083 * @param stbuf the file attributes
1084 * @param off the offset of the next entry
1085 * @return the space needed for the entry
1086 */
1087size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1088 const char *name, const struct stat *stbuf,
1089 off64_t off);
1090
1091/**
1092 * Reply to ask for data fetch and output buffer preparation. ioctl
1093 * will be retried with the specified input data fetched and output
1094 * buffer prepared.
1095 *
1096 * Possible requests:
1097 * ioctl
1098 *
1099 * @param req request handle
1100 * @param in_iov iovec specifying data to fetch from the caller
1101 * @param in_count number of entries in in_iov
1102 * @param out_iov iovec specifying addresses to write output to
1103 * @param out_count number of entries in out_iov
1104 * @return zero for success, -errno for failure to send reply
1105 */
1106int fuse_reply_ioctl_retry(fuse_req_t req,
1107 const struct iovec *in_iov, size_t in_count,
1108 const struct iovec *out_iov, size_t out_count);
1109
1110/**
1111 * Reply to finish ioctl
1112 *
1113 * Possible requests:
1114 * ioctl
1115 *
1116 * @param req request handle
1117 * @param result result to be passed to the caller
1118 * @param buf buffer containing output data
1119 * @param size length of output data
1120 */
1121int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1122
1123/**
1124 * Reply to finish ioctl with iov buffer
1125 *
1126 * Possible requests:
1127 * ioctl
1128 *
1129 * @param req request handle
1130 * @param result result to be passed to the caller
1131 * @param iov the vector containing the data
1132 * @param count the size of vector
1133 */
1134int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1135 int count);
1136
1137/**
1138 * Reply with poll result event mask
1139 *
1140 * @param req request handle
1141 * @param revents poll result event mask
1142 */
1143int fuse_reply_poll(fuse_req_t req, unsigned revents);
1144
1145/* ----------------------------------------------------------- *
1146 * Notification *
1147 * ----------------------------------------------------------- */
1148
1149/**
1150 * Notify IO readiness event
1151 *
1152 * For more information, please read comment for poll operation.
1153 *
1154 * @param ph poll handle to notify IO readiness event for
1155 */
1156int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1157
1158/**
1159 * Notify to invalidate cache for an inode
1160 *
1161 * @param ch the channel through which to send the invalidation
1162 * @param ino the inode number
1163 * @param off the offset in the inode where to start invalidating
1164 * or negative to invalidate attributes only
1165 * @param len the amount of cache to invalidate or 0 for all
1166 * @return zero for success, -errno for failure
1167 */
1168int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino,
1169 off64_t off, off64_t len);
1170
1171/**
1172 * Notify to invalidate parent attributes and the dentry matching
1173 * parent/name
1174 *
1175 * @param ch the channel through which to send the invalidation
1176 * @param parent inode number
1177 * @param name file name
1178 * @param namelen strlen() of file name
1179 * @return zero for success, -errno for failure
1180 */
1181int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent,
1182 const char *name, size_t namelen);
1183
1184/* ----------------------------------------------------------- *
1185 * Utility functions *
1186 * ----------------------------------------------------------- */
1187
1188/**
1189 * Get the userdata from the request
1190 *
1191 * @param req request handle
1192 * @return the user data passed to fuse_lowlevel_new()
1193 */
1194void *fuse_req_userdata(fuse_req_t req);
1195
1196/**
1197 * Get the context from the request
1198 *
1199 * The pointer returned by this function will only be valid for the
1200 * request's lifetime
1201 *
1202 * @param req request handle
1203 * @return the context structure
1204 */
1205const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1206
1207/**
1208 * Get the current supplementary group IDs for the specified request
1209 *
1210 * Similar to the getgroups(2) system call, except the return value is
1211 * always the total number of group IDs, even if it is larger than the
1212 * specified size.
1213 *
1214 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
1215 * the group list to userspace, hence this function needs to parse
1216 * "/proc/$TID/task/$TID/status" to get the group IDs.
1217 *
1218 * This feature may not be supported on all operating systems. In
1219 * such a case this function will return -ENOSYS.
1220 *
1221 * @param req request handle
1222 * @param size size of given array
1223 * @param list array of group IDs to be filled in
1224 * @return the total number of supplementary group IDs or -errno on failure
1225 */
1226int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
1227
1228/**
1229 * Callback function for an interrupt
1230 *
1231 * @param req interrupted request
1232 * @param data user data
1233 */
1234typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1235
1236/**
1237 * Register/unregister callback for an interrupt
1238 *
1239 * If an interrupt has already happened, then the callback function is
1240 * called from within this function, hence it's not possible for
1241 * interrupts to be lost.
1242 *
1243 * @param req request handle
1244 * @param func the callback function or NULL for unregister
1245 * @param data user data passed to the callback function
1246 */
1247void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1248 void *data);
1249
1250/**
1251 * Check if a request has already been interrupted
1252 *
1253 * @param req request handle
1254 * @return 1 if the request has been interrupted, 0 otherwise
1255 */
1256int fuse_req_interrupted(fuse_req_t req);
1257
1258/* ----------------------------------------------------------- *
1259 * Filesystem setup *
1260 * ----------------------------------------------------------- */
1261
1262/* Deprecated, don't use */
1263int fuse_lowlevel_is_lib_option(const char *opt);
1264
1265/**
1266 * Create a low level session
1267 *
1268 * @param args argument vector
1269 * @param op the low level filesystem operations
1270 * @param op_size sizeof(struct fuse_lowlevel_ops)
1271 * @param userdata user data
1272 * @return the created session object, or NULL on failure
1273 */
1274struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
1275 const struct fuse_lowlevel_ops *op,
1276 size_t op_size, void *userdata);
1277
1278/* ----------------------------------------------------------- *
1279 * Session interface *
1280 * ----------------------------------------------------------- */
1281
1282/**
1283 * Session operations
1284 *
1285 * This is used in session creation
1286 */
1287struct fuse_session_ops {
1288 /**
1289 * Hook to process a request (mandatory)
1290 *
1291 * @param data user data passed to fuse_session_new()
1292 * @param buf buffer containing the raw request
1293 * @param len request length
1294 * @param ch channel on which the request was received
1295 */
1296 void (*process) (void *data, const char *buf, size_t len,
1297 struct fuse_chan *ch);
1298
1299 /**
1300 * Hook for session exit and reset (optional)
1301 *
1302 * @param data user data passed to fuse_session_new()
1303 * @param val exited status (1 - exited, 0 - not exited)
1304 */
1305 void (*exit) (void *data, int val);
1306
1307 /**
1308 * Hook for querying the current exited status (optional)
1309 *
1310 * @param data user data passed to fuse_session_new()
1311 * @return 1 if exited, 0 if not exited
1312 */
1313 int (*exited) (void *data);
1314
1315 /**
1316 * Hook for cleaning up the channel on destroy (optional)
1317 *
1318 * @param data user data passed to fuse_session_new()
1319 */
1320 void (*destroy) (void *data);
1321};
1322
1323/**
1324 * Create a new session
1325 *
1326 * @param op session operations
1327 * @param data user data
1328 * @return new session object, or NULL on failure
1329 */
1330struct fuse_session *fuse_session_new(struct fuse_session_ops *op, void *data);
1331
1332/**
1333 * Assign a channel to a session
1334 *
1335 * Note: currently only a single channel may be assigned. This may
1336 * change in the future
1337 *
1338 * If a session is destroyed, the assigned channel is also destroyed
1339 *
1340 * @param se the session
1341 * @param ch the channel
1342 */
1343void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch);
1344
1345/**
1346 * Remove a channel from a session
1347 *
1348 * If the channel is not assigned to a session, then this is a no-op
1349 *
1350 * @param ch the channel to remove
1351 */
1352void fuse_session_remove_chan(struct fuse_chan *ch);
1353
1354/**
1355 * Iterate over the channels assigned to a session
1356 *
1357 * The iterating function needs to start with a NULL channel, and
1358 * after that needs to pass the previously returned channel to the
1359 * function.
1360 *
1361 * @param se the session
1362 * @param ch the previous channel, or NULL
1363 * @return the next channel, or NULL if no more channels exist
1364 */
1365struct fuse_chan *fuse_session_next_chan(struct fuse_session *se,
1366 struct fuse_chan *ch);
1367
1368/**
1369 * Process a raw request
1370 *
1371 * @param se the session
1372 * @param buf buffer containing the raw request
1373 * @param len request length
1374 * @param ch channel on which the request was received
1375 */
1376void fuse_session_process(struct fuse_session *se, const char *buf, size_t len,
1377 struct fuse_chan *ch);
1378
1379/**
1380 * Destroy a session
1381 *
1382 * @param se the session
1383 */
1384void fuse_session_destroy(struct fuse_session *se);
1385
1386/**
1387 * Exit a session
1388 *
1389 * @param se the session
1390 */
1391void fuse_session_exit(struct fuse_session *se);
1392
1393/**
1394 * Reset the exited status of a session
1395 *
1396 * @param se the session
1397 */
1398void fuse_session_reset(struct fuse_session *se);
1399
1400/**
1401 * Query the exited status of a session
1402 *
1403 * @param se the session
1404 * @return 1 if exited, 0 if not exited
1405 */
1406int fuse_session_exited(struct fuse_session *se);
1407
1408/**
1409 * Get the user data provided to the session
1410 *
1411 * @param se the session
1412 * @return the user data
1413 */
1414void *fuse_session_data(struct fuse_session *se);
1415
1416/**
1417 * Enter a single threaded event loop
1418 *
1419 * @param se the session
1420 * @return 0 on success, -1 on error
1421 */
1422int fuse_session_loop(struct fuse_session *se);
1423
1424/**
1425 * Enter a multi-threaded event loop
1426 *
1427 * @param se the session
1428 * @return 0 on success, -1 on error
1429 */
1430int fuse_session_loop_mt(struct fuse_session *se);
1431
1432/* ----------------------------------------------------------- *
1433 * Channel interface *
1434 * ----------------------------------------------------------- */
1435
1436/**
1437 * Channel operations
1438 *
1439 * This is used in channel creation
1440 */
1441struct fuse_chan_ops {
1442 /**
1443 * Hook for receiving a raw request
1444 *
1445 * @param ch pointer to the channel
1446 * @param buf the buffer to store the request in
1447 * @param size the size of the buffer
1448 * @return the actual size of the raw request, or -1 on error
1449 */
1450 int (*receive)(struct fuse_chan **chp, char *buf, size_t size);
1451
1452 /**
1453 * Hook for sending a raw reply
1454 *
1455 * A return value of -ENOENT means, that the request was
1456 * interrupted, and the reply was discarded
1457 *
1458 * @param ch the channel
1459 * @param iov vector of blocks
1460 * @param count the number of blocks in vector
1461 * @return zero on success, -errno on failure
1462 */
1463 int (*send)(struct fuse_chan *ch, const struct iovec iov[],
1464 size_t count);
1465
1466 /**
1467 * Destroy the channel
1468 *
1469 * @param ch the channel
1470 */
1471 void (*destroy)(struct fuse_chan *ch);
1472};
1473
1474/**
1475 * Create a new channel
1476 *
1477 * @param op channel operations
1478 * @param fd file descriptor of the channel
1479 * @param bufsize the minimal receive buffer size
1480 * @param data user data
1481 * @return the new channel object, or NULL on failure
1482 */
1483struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd,
1484 size_t bufsize, void *data);
1485
1486/**
1487 * Query the file descriptor of the channel
1488 *
1489 * @param ch the channel
1490 * @return the file descriptor passed to fuse_chan_new()
1491 */
1492int fuse_chan_fd(struct fuse_chan *ch);
1493
1494/**
1495 * Query the minimal receive buffer size
1496 *
1497 * @param ch the channel
1498 * @return the buffer size passed to fuse_chan_new()
1499 */
1500size_t fuse_chan_bufsize(struct fuse_chan *ch);
1501
1502/**
1503 * Query the user data
1504 *
1505 * @param ch the channel
1506 * @return the user data passed to fuse_chan_new()
1507 */
1508void *fuse_chan_data(struct fuse_chan *ch);
1509
1510/**
1511 * Query the session to which this channel is assigned
1512 *
1513 * @param ch the channel
1514 * @return the session, or NULL if the channel is not assigned
1515 */
1516struct fuse_session *fuse_chan_session(struct fuse_chan *ch);
1517
1518/**
1519 * Receive a raw request
1520 *
1521 * A return value of -ENODEV means, that the filesystem was unmounted
1522 *
1523 * @param ch pointer to the channel
1524 * @param buf the buffer to store the request in
1525 * @param size the size of the buffer
1526 * @return the actual size of the raw request, or -errno on error
1527 */
1528int fuse_chan_recv(struct fuse_chan **ch, char *buf, size_t size);
1529
1530/**
1531 * Send a raw reply
1532 *
1533 * A return value of -ENOENT means, that the request was
1534 * interrupted, and the reply was discarded
1535 *
1536 * @param ch the channel
1537 * @param iov vector of blocks
1538 * @param count the number of blocks in vector
1539 * @return zero on success, -errno on failure
1540 */
1541int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[],
1542 size_t count);
1543
1544/**
1545 * Destroy a channel
1546 *
1547 * @param ch the channel
1548 */
1549void fuse_chan_destroy(struct fuse_chan *ch);
1550
1551/* ----------------------------------------------------------- *
1552 * Compatibility stuff *
1553 * ----------------------------------------------------------- */
1554
1555#if FUSE_USE_VERSION < 26
1556# include "fuse_lowlevel_compat.h"
1557# define fuse_chan_ops fuse_chan_ops_compat24
1558# define fuse_chan_new fuse_chan_new_compat24
1559# if FUSE_USE_VERSION == 25
1560# define fuse_lowlevel_ops fuse_lowlevel_ops_compat25
1561# define fuse_lowlevel_new fuse_lowlevel_new_compat25
1562# elif FUSE_USE_VERSION == 24
1563# define fuse_lowlevel_ops fuse_lowlevel_ops_compat
1564# define fuse_lowlevel_new fuse_lowlevel_new_compat
1565# define fuse_file_info fuse_file_info_compat
1566# define fuse_reply_statfs fuse_reply_statfs_compat
1567# define fuse_reply_open fuse_reply_open_compat
1568# else
1569# error Compatibility with low-level API version < 24 not supported
1570# endif
1571#endif
1572
1573#ifdef __cplusplus
1574}
1575#endif
1576
1577#endif /* _FUSE_LOWLEVEL_H_ */