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