diff --git a/libfuse/include/fuse.h b/libfuse/include/fuse.h index ec17a71d..909227b0 100644 --- a/libfuse/include/fuse.h +++ b/libfuse/include/fuse.h @@ -12,6 +12,7 @@ #include "extern_c.h" #include "fuse_common.h" #include "fuse_kernel.h" +#include "fuse_req_ctx.h" #include #include @@ -28,12 +29,6 @@ EXTERN_C_BEGIN * Basic FUSE API * * ----------------------------------------------------------- */ -/** Handle for a FUSE filesystem */ -struct fuse; - -/** Structure containing a raw command */ -struct fuse_cmd; - struct fuse_dirents_t; typedef struct fuse_dirents_t fuse_dirents_t; @@ -61,516 +56,192 @@ typedef struct fuse_dirents_t fuse_dirents_t; */ struct fuse_operations { - /** Get file attributes. - * - * Similar to stat(). The 'st_dev' and 'st_blksize' fields are - * ignored. The 'st_ino' field is ignored except if the 'use_ino' - * mount option is given. - */ - int (*getattr) (const char *, struct stat *, fuse_timeouts_t *); - - /** Read the target of a symbolic link - * - * The buffer should be filled with a null terminated string. The - * buffer size argument includes the space for the terminating - * null character. If the linkname is too long to fit in the - * buffer, it should be truncated. The return value should be 0 - * for success. - */ - int (*readlink) (const char *, char *, size_t); - - /** Create a file node - * - * This is called for creation of all non-directory, non-symlink - * nodes. If the filesystem defines a create() method, then for - * regular files that will be called instead. - */ - int (*mknod) (const char *, mode_t, dev_t); - - /** Create a directory - * - * Note that the mode argument may not have the type specification - * bits set, i.e. S_ISDIR(mode) can be false. To obtain the - * correct directory type bits use mode|S_IFDIR - * */ - int (*mkdir) (const char *, mode_t); - - /** Remove a file */ - int (*unlink) (const char *); - - /** Remove a directory */ - int (*rmdir) (const char *); - - /** Create a symbolic link */ - int (*symlink) (const char *, const char *, struct stat *, fuse_timeouts_t *); - - /** Rename a file */ - int (*rename) (const char *, const char *); - - /** Create a hard link to a file */ - int (*link) (const char *, const char *, struct stat *, fuse_timeouts_t *); - - /** Change the permission bits of a file */ - int (*chmod) (const char *, mode_t); - int (*fchmod)(const uint64_t, const mode_t); - - /** Change the owner and group of a file */ - int (*chown) (const char *, uid_t, gid_t); - int (*fchown)(const uint64_t, const uid_t, const gid_t); - - /** Change the size of a file */ - int (*truncate) (const char *, off_t); - - /** File open operation - * - * No creation (O_CREAT, O_EXCL) and by default also no - * truncation (O_TRUNC) flags will be passed to open(). If an - * application specifies O_TRUNC, fuse first calls truncate() - * and then open(). Only if 'atomic_o_trunc' has been - * specified and kernel version is 2.6.24 or later, O_TRUNC is - * passed on to open. - * - * Unless the 'default_permissions' mount option is given, - * open should check if the operation is permitted for the - * given flags. Optionally open may also return an arbitrary - * filehandle in the fuse_file_info structure, which will be - * passed to all file operations. - * - * Changed in version 2.2 - */ - int (*open) (const char *, fuse_file_info_t *); - - /** Get file system statistics - * - * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored - * - * Replaced 'struct statfs' parameter with 'struct statvfs' in - * version 2.5 - */ - int (*statfs) (const char *, struct statvfs *); - - /** Possibly flush cached data - * - * BIG NOTE: This is not equivalent to fsync(). It's not a - * request to sync dirty data. - * - * Flush is called on each close() of a file descriptor. So if a - * filesystem wants to return write errors in close() and the file - * has cached dirty data, this is a good place to write back data - * and return any errors. Since many applications ignore close() - * errors this is not always useful. - * - * NOTE: The flush() method may be called more than once for each - * open(). This happens if more than one file descriptor refers - * to an opened file due to dup(), dup2() or fork() calls. It is - * not possible to determine if a flush is final, so each flush - * should be treated equally. Multiple write-flush sequences are - * relatively rare, so this shouldn't be a problem. - * - * Filesystems shouldn't assume that flush will always be called - * after some writes, or that if will be called at all. - * - * Changed in version 2.2 - */ - int (*flush) (const fuse_file_info_t *); - - /** Release an open file - * - * Release is called when there are no more references to an open - * file: all file descriptors are closed and all memory mappings - * are unmapped. - * - * For every open() call there will be exactly one release() call - * with the same flags and file descriptor. It is possible to - * have a file opened more than once, in which case only the last - * release will mean, that no more reads/writes will happen on the - * file. The return value of release is ignored. - * - * Changed in version 2.2 - */ - int (*release) (const fuse_file_info_t *); - - /** Synchronize file contents - * - * If the datasync parameter is non-zero, then only the user data - * should be flushed, not the meta data. - * - * Changed in version 2.2 - */ - int (*fsync) (const uint64_t, int); - - /** Set extended attributes */ - int (*setxattr) (const char *, const char *, const char *, size_t, int); - - /** Get extended attributes */ - int (*getxattr) (const char *, const char *, char *, size_t); - - /** List extended attributes */ - int (*listxattr) (const char *, char *, size_t); - - /** Remove extended attributes */ - int (*removexattr) (const char *, const char *); - - /** Open directory - * - * Unless the 'default_permissions' mount option is given, - * this method should check if opendir is permitted for this - * directory. Optionally opendir may also return an arbitrary - * filehandle in the fuse_file_info structure, which will be - * passed to readdir, closedir and fsyncdir. - * - * Introduced in version 2.3 - */ - int (*opendir) (const char *, - fuse_file_info_t *); - - /** Read directory - * - * This supersedes the old getdir() interface. New applications - * should use this. - * - * The filesystem may choose between two modes of operation: - * - * 1) The readdir implementation ignores the offset parameter, and - * passes zero to the filler function's offset. The filler - * function will not return '1' (unless an error happens), so the - * whole directory is read in a single readdir operation. This - * works just like the old getdir() method. - * - * 2) The readdir implementation keeps track of the offsets of the - * directory entries. It uses the offset parameter and always - * passes non-zero offset to the filler function. When the buffer - * is full (or an error happens) the filler function will return - * '1'. - * - * Introduced in version 2.3 - */ - int (*readdir)(const fuse_file_info_t *, + int (*getattr)(const fuse_req_ctx_t *, + const char *, + struct stat *, + fuse_timeouts_t *); + int (*readlink)(const fuse_req_ctx_t *, + const char *, + char *, + size_t); + int (*mknod)(const fuse_req_ctx_t *, + const char *, + mode_t, + dev_t); + int (*mkdir)(const fuse_req_ctx_t *, + const char *, + mode_t); + int (*unlink)(const fuse_req_ctx_t *, + const char *); + int (*rmdir)(const fuse_req_ctx_t *, + const char *); + int (*symlink)(const fuse_req_ctx_t *, + const char *, + const char *, + struct stat *, + fuse_timeouts_t *); + int (*rename)(const fuse_req_ctx_t *, + const char *, + const char *); + int (*link)(const fuse_req_ctx_t *, + const char *, + const char *, + struct stat *, + fuse_timeouts_t *); + int (*chmod)(const fuse_req_ctx_t *, + const char *, + mode_t); + int (*fchmod)(const fuse_req_ctx_t *, + const uint64_t, + const mode_t); + int (*chown)(const fuse_req_ctx_t *, + const char *, + uid_t, + gid_t); + int (*fchown)(const fuse_req_ctx_t *, + const uint64_t, + const uid_t, + const gid_t); + int (*truncate)(const fuse_req_ctx_t *, + const char *, + off_t); + int (*open)(const fuse_req_ctx_t *, + const char *, + fuse_file_info_t *); + int (*statfs)(const fuse_req_ctx_t *, + const char *, + struct statvfs *); + int (*flush)(const fuse_req_ctx_t *, + const fuse_file_info_t *); + int (*release)(const fuse_req_ctx_t *, + const fuse_file_info_t *); + int (*fsync)(const fuse_req_ctx_t *, + const uint64_t, + int); + int (*setxattr)(const fuse_req_ctx_t *, + const char *, + const char *, + const char *, + size_t, + int); + int (*getxattr)(const fuse_req_ctx_t *, + const char *, + const char *, + char *, + size_t); + int (*listxattr)(const fuse_req_ctx_t *, + const char *, + char *, + size_t); + int (*removexattr)(const fuse_req_ctx_t *, + const char *, + const char *); + int (*opendir)(const fuse_req_ctx_t *, + const char *, + fuse_file_info_t *); + int (*readdir)(const fuse_req_ctx_t *, + const fuse_file_info_t *, fuse_dirents_t *); - - int (*readdir_plus)(const fuse_file_info_t *, + int (*readdir_plus)(const fuse_req_ctx_t *, + const fuse_file_info_t *, fuse_dirents_t *); - - - /** Release directory - * - * Introduced in version 2.3 - */ - int (*releasedir) (const fuse_file_info_t *); - - /** Synchronize directory contents - * - * If the datasync parameter is non-zero, then only the user data - * should be flushed, not the meta data - * - * Introduced in version 2.3 - */ - int (*fsyncdir) (const fuse_file_info_t *, int); - - /** - * Initialize filesystem - * - * The return value will passed in the private_data field of - * fuse_context to all file operations and as a parameter to the - * destroy() method. - * - * Introduced in version 2.3 - * Changed in version 2.6 - */ - void *(*init) (struct fuse_conn_info *conn); - - /** - * Clean up filesystem - * - * Called on filesystem exit. - * - * Introduced in version 2.3 - */ - void (*destroy) (void); - - /** - * Check file access permissions - * - * This will be called for the access() system call. If the - * 'default_permissions' mount option is given, this method is not - * called. - * - * This method is not called under Linux kernel versions 2.4.x - * - * Introduced in version 2.5 - */ - int (*access) (const char *, int); - - /** - * Create and open a file - * - * If the file does not exist, first create it with the specified - * mode, and then open it. - * - * If this method is not implemented or under Linux kernel - * versions earlier than 2.6.15, the mknod() and open() methods - * will be called instead. - * - * Introduced in version 2.5 - */ - int (*create) (const char *, mode_t, fuse_file_info_t *); - - /** - * Change the size of an open file - * - * This method is called instead of the truncate() method if the - * truncation was invoked from an ftruncate() system call. - * - * If this method is not implemented or under Linux kernel - * versions earlier than 2.6.15, the truncate() method will be - * called instead. - * - * Introduced in version 2.5 - */ - int (*ftruncate) (const uint64_t, off_t); - - /** - * Get attributes from an open file - * - * This method is called instead of the getattr() method if the - * file information is available. - * - * Currently this is only called after the create() method if that - * is implemented (see above). Later it may be called for - * invocations of fstat() too. - * - * Introduced in version 2.5 - */ - int (*fgetattr) (const uint64_t, struct stat *, fuse_timeouts_t *); - - /** - * Perform POSIX file locking operation - * - * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW. - * - * For the meaning of fields in 'struct flock' see the man page - * for fcntl(2). The l_whence field will always be set to - * SEEK_SET. - * - * For checking lock ownership, the 'fuse_file_info->owner' - * argument must be used. - * - * For F_GETLK operation, the library will first check currently - * held locks, and if a conflicting lock is found it will return - * information without calling this method. This ensures, that - * for local locks the l_pid field is correctly filled in. The - * results may not be accurate in case of race conditions and in - * the presence of hard links, but it's unlikely that an - * application would rely on accurate GETLK results in these - * cases. If a conflicting lock is not found, this method will be - * called, and the filesystem may fill out l_pid by a meaningful - * value, or it may leave this field zero. - * - * For F_SETLK and F_SETLKW the l_pid field will be set to the pid - * of the process performing the locking operation. - * - * Note: if this method is not implemented, the kernel will still - * allow file locking to work locally. Hence it is only - * interesting for network filesystems and similar. - * - * Introduced in version 2.6 - */ - int (*lock) (const fuse_file_info_t *, - int cmd, - struct flock *); - - /** - * Change the access and modification times of a file with - * nanosecond resolution - * - * This supersedes the old utime() interface. New applications - * should use this. - * - * See the utimensat(2) man page for details. - * - * Introduced in version 2.6 - */ - int (*utimens)(const char *, const struct timespec tv[2]); - int (*futimens)(const uint64_t fh, const struct timespec tv[2]); - - /** - * Map block index within file to block index within device - * - * Note: This makes sense only for block device backed filesystems - * mounted with the 'blkdev' option - * - * Introduced in version 2.6 - */ - int (*bmap) (const char *, size_t blocksize, uint64_t *idx); - - /** - * Ioctl - * - * flags will have FUSE_IOCTL_COMPAT set for 32bit ioctls in - * 64bit environment. The size and direction of data is - * determined by _IOC_*() decoding of cmd. For _IOC_NONE, - * data will be NULL, for _IOC_WRITE data is out area, for - * _IOC_READ in area and if both are set in/out area. In all - * non-NULL cases, the area is of _IOC_SIZE(cmd) bytes. - * - * If flags has FUSE_IOCTL_DIR then the fuse_file_info refers to a - * directory file handle. - * - * Introduced in version 2.8 - */ - int (*ioctl) (const fuse_file_info_t *ffi, - unsigned long cmd, - void *arg, - unsigned int flags, - void *data, - uint32_t *out_bufsz); - - /** - * Poll for IO readiness events - * - * Note: If ph is non-NULL, the client should notify - * when IO readiness events occur by calling - * fuse_notify_poll() with the specified ph. - * - * Regardless of the number of times poll with a non-NULL ph - * is received, single notification is enough to clear all. - * Notifying more times incurs overhead but doesn't harm - * correctness. - * - * The callee is responsible for destroying ph with - * fuse_pollhandle_destroy() when no longer in use. - * - * Introduced in version 2.8 - */ - int (*poll) (const fuse_file_info_t *ffi, - fuse_pollhandle_t *ph, - unsigned *reventsp); - - /** Write contents of buffer to an open file - * - * Similar to the write() method, but data is supplied in a - * generic buffer. Use fuse_buf_copy() to transfer data to - * the destination. - * - * Introduced in version 2.9 - */ - int (*write) (const fuse_file_info_t *ffi, - const char *data, - size_t size, - off_t off); - - /** Store data from an open file in a buffer - * - * Similar to the read() method, but data is stored and - * returned in a generic buffer. - * - * No actual copying of data has to take place, the source - * file descriptor may simply be stored in the buffer for - * later data transfer. - * - * The buffer must be allocated dynamically and stored at the - * location pointed to by bufp. If the buffer contains memory - * regions, they too must be allocated using malloc(). The - * allocated memory will be freed by the caller. - * - * Introduced in version 2.9 - */ - int (*read)(const fuse_file_info_t *ffi, + int (*releasedir)(const fuse_req_ctx_t *, + const fuse_file_info_t *); + int (*fsyncdir)(const fuse_req_ctx_t *, + const fuse_file_info_t *, + int); + void *(*init)(struct fuse_conn_info *conn); + void (*destroy)(void); + int (*access)(const fuse_req_ctx_t *, + const char *, + int); + int (*create)(const fuse_req_ctx_t *, + const char *, + mode_t, + fuse_file_info_t *); + int (*ftruncate)(const fuse_req_ctx_t *, + const uint64_t, + off_t); + int (*fgetattr)(const fuse_req_ctx_t *, + const uint64_t, + struct stat *, + fuse_timeouts_t *); + int (*lock)(const fuse_req_ctx_t *, + const fuse_file_info_t *, + int cmd, + struct flock *); + int (*utimens)(const fuse_req_ctx_t *, + const char *, + const struct timespec tv[2]); + int (*futimens)(const fuse_req_ctx_t *, + const uint64_t fh, + const struct timespec tv[2]); + int (*bmap)(const fuse_req_ctx_t *, + const char *, + size_t blocksize, + uint64_t *idx); + int (*ioctl)(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, + unsigned long cmd, + void *arg, + unsigned int flags, + void *data, + uint32_t *out_bufsz); + int (*poll)(const fuse_req_ctx_t *, + const fuse_file_info_t *ffi, + fuse_pollhandle_t *ph, + unsigned *reventsp); + int (*write)(const fuse_req_ctx_t *, + const fuse_file_info_t *ffi, + const char *data, + size_t size, + off_t off); + int (*read)(const fuse_req_ctx_t *, + const fuse_file_info_t *ffi, char *buf, size_t size, off_t off); - /** - * Perform BSD file locking operation - * - * The op argument will be either LOCK_SH, LOCK_EX or LOCK_UN - * - * Nonblocking requests will be indicated by ORing LOCK_NB to - * the above operations - * - * For more information see the flock(2) manual page. - * - * Additionally fi->owner will be set to a value unique to - * this open file. This same value will be supplied to - * ->release() when the file is released. - * - * Note: if this method is not implemented, the kernel will still - * allow file locking to work locally. Hence it is only - * interesting for network filesystems and similar. - * - * Introduced in version 2.9 - */ - int (*flock) (const fuse_file_info_t *, int op); - - /** - * Allocates space for an open file - * - * This function ensures that required space is allocated for specified - * file. If this function returns success then any subsequent write - * request to specified range is guaranteed not to fail because of lack - * of space on the file system media. - * - * Introduced in version 2.9.1 - */ - int (*fallocate) (const uint64_t, int, off_t, off_t); - - /** - * Copy a range of data from one file to another - * - * Performs an optimized copy between two file descriptors without - * the additional cost of transferring data through the FUSE kernel - * module to user space (glibc) and then back into the FUSE filesystem - * again. - * - * In case this method is not implemented, glibc falls back to - * reading data from the source and writing to the - * destination. Effectively doing an inefficient copy of the - * data. - */ - ssize_t (*copy_file_range)(const fuse_file_info_t *src_fi, + int (*flock)(const fuse_req_ctx_t *, + const fuse_file_info_t *, + int op); + int (*fallocate)(const fuse_req_ctx_t *, + const uint64_t, + int, + off_t, + off_t); + ssize_t (*copy_file_range)(const fuse_req_ctx_t *, + const fuse_file_info_t *src_fi, off_t src_off, const fuse_file_info_t *dst_fi, off_t dst_off, const size_t size, const unsigned int flags); - - ssize_t (*setupmapping)(uint64_t *fh_, + ssize_t (*setupmapping)(const fuse_req_ctx_t *, + uint64_t *fh_, uint64_t foffset_, uint64_t len_, uint64_t flags_, uint64_t moffset_); - - int (*removemapping)(); - int (*syncfs)(); - int (*tmpfile)(const char *, mode_t, fuse_file_info_t *); - int (*statx)(const char *fusepath, + int (*removemapping)(const fuse_req_ctx_t *); + int (*syncfs)(const fuse_req_ctx_t *); + int (*tmpfile)(const fuse_req_ctx_t *, + const char *, + mode_t, + fuse_file_info_t *); + int (*statx)(const fuse_req_ctx_t *, + const char *fusepath, const uint32_t flags, const uint32_t mask, struct fuse_statx *st, fuse_timeouts_t *timeout); - int (*statx_fh)(const uint64_t fh, + int (*statx_fh)(const fuse_req_ctx_t *, + const uint64_t fh, const uint32_t flags, const uint32_t mask, struct fuse_statx *st, fuse_timeouts_t *timeout); }; -/** Extra context that may be needed by some filesystems - * - * The uid, gid and pid fields are not filled in case of a writepage - * operation. - */ -struct fuse_context -{ - uint64_t unique; - uint64_t nodeid; - uint32_t opcode; - uid_t uid; - gid_t gid; - pid_t pid; - mode_t umask; - struct fuse *fuse; -}; - /** * Main function of FUSE. * @@ -593,11 +264,6 @@ struct fuse_context * @param op the file system operation * @return 0 on success, nonzero on failure */ -/* - int fuse_main(int argc, char *argv[], const struct fuse_operations *op); -*/ -#define fuse_main(argc, argv, op) \ - fuse_main_real(argc, argv, op, sizeof(*(op))) /* ----------------------------------------------------------- * * More detailed API * @@ -612,8 +278,9 @@ struct fuse_context * @param op_size the size of the fuse_operations structure * @return the created FUSE handle */ -struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args, - const struct fuse_operations *op, size_t op_size); +struct fuse *fuse_new(struct fuse_chan *ch, + struct fuse_args *args, + const struct fuse_operations *op); /** * Destroy the FUSE handle. @@ -625,7 +292,7 @@ struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args, * * @param f the FUSE handle */ -void fuse_destroy(struct fuse *f); +void fuse_destroy(); /** * Exit from event loop @@ -686,7 +353,9 @@ int fuse_is_lib_option(const char *opt); * * Do not call this directly, use fuse_main() */ -int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, size_t op_size); +int fuse_main(int argc, + char *argv[], + const struct fuse_operations *op); void fuse_populate_maintenance_thread(struct fuse *fuse); @@ -709,13 +378,6 @@ int fuse_clean_cache(struct fuse *fuse); * Stacking API */ -/** - * Fuse filesystem object - * - * This is opaque object represents a filesystem layer - */ -struct fuse_fs; - /* * These functions call the relevant filesystem operation, and return * the result. @@ -727,18 +389,6 @@ struct fuse_fs; int fuse_notify_poll(fuse_pollhandle_t *ph); -/** - * Create a new fuse filesystem object - * - * This is usually called from the factory of a fuse module to create - * a new instance of a filesystem. - * - * @param op the filesystem operations - * @param op_size the size of the fuse_operations structure - * @return a new filesystem object - */ -struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size); - /* ----------------------------------------------------------- * * Advanced API for event handling, don't worry about this... * * ----------------------------------------------------------- */ @@ -746,40 +396,31 @@ struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size); /* NOTE: the following functions are deprecated, and will be removed from the 3.0 API. Use the lowlevel session functions instead */ -/** Function type used to process commands */ -typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *); - /** This is the part of fuse_main() before the event loop */ -struct fuse *fuse_setup(int argc, char *argv[], - const struct fuse_operations *op, size_t op_size, +struct fuse *fuse_setup(int argc, + char *argv[], + const struct fuse_operations *op, char **mountpoint); /** This is the part of fuse_main() after the event loop */ -void fuse_teardown(struct fuse *fuse, char *mountpoint); - -/** Multi threaded event loop, which calls the custom command - processor function */ -int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data); +void fuse_teardown(char *mountpoint); /** Return the exited flag, which indicates if fuse_exit() has been called */ -int fuse_exited(struct fuse *f); +int fuse_exited(); /** This function is obsolete and implemented as a no-op */ void fuse_set_getcontext_func(struct fuse_context *(*func)(void)); /** Get session from fuse object */ -struct fuse_session *fuse_get_session(struct fuse *f); +struct fuse_session *fuse_get_session(); void fuse_gc1(); void fuse_gc(); void fuse_invalidate_all_nodes(); -int fuse_get_dev_fuse_fd(const struct fuse_context *fc); -int fuse_passthrough_open(const struct fuse_context *fc, - const int fd); -int fuse_passthrough_close(const struct fuse_context *fc, - const int backing_id); +int fuse_passthrough_open(const int fd); +int fuse_passthrough_close(const int backing_id); EXTERN_C_END diff --git a/libfuse/include/fuse_common.h b/libfuse/include/fuse_common.h index e631c056..1cef8f9d 100644 --- a/libfuse/include/fuse_common.h +++ b/libfuse/include/fuse_common.h @@ -1,19 +1,4 @@ -/* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi - - This program can be distributed under the terms of the GNU LGPLv2. - See the file COPYING.LIB. -*/ - -/** @file */ - -#if !defined(_FUSE_H_) && !defined(_FUSE_LOWLEVEL_H_) -#error "Never include directly; use or instead." -#endif - -#ifndef _FUSE_COMMON_H_ -#define _FUSE_COMMON_H_ +#pragma once #include "extern_c.h" #include "fuse_opt.h" @@ -22,15 +7,6 @@ #include #include -/** Major version of FUSE library interface */ -#define FUSE_MAJOR_VERSION 2 - -/** Minor version of FUSE library interface */ -#define FUSE_MINOR_VERSION 9 - -#define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min)) -#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION) - /* This interface uses 64 bit off_t */ #if _FILE_OFFSET_BITS != 64 #error Please add -D_FILE_OFFSET_BITS=64 to your compile flags! @@ -449,5 +425,3 @@ int fuse_set_signal_handlers(struct fuse_session *se); void fuse_remove_signal_handlers(struct fuse_session *se); EXTERN_C_END - -#endif /* _FUSE_COMMON_H_ */ diff --git a/libfuse/include/fuse_lowlevel.h b/libfuse/include/fuse_lowlevel.h index 74731edd..40250096 100644 --- a/libfuse/include/fuse_lowlevel.h +++ b/libfuse/include/fuse_lowlevel.h @@ -1,17 +1,9 @@ -/* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi - - This program can be distributed under the terms of the GNU LGPLv2. - See the file COPYING.LIB. -*/ - -#ifndef _FUSE_LOWLEVEL_H_ -#define _FUSE_LOWLEVEL_H_ +#pragma once #include "extern_c.h" #include "fuse_common.h" #include "fuse_kernel.h" +#include "fuse_req.h" #include #include @@ -30,9 +22,6 @@ EXTERN_C_BEGIN /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 -/** Request pointer type */ -typedef struct fuse_req *fuse_req_t; - /** * Session * @@ -88,18 +77,6 @@ struct fuse_entry_param fuse_timeouts_t timeout; }; -/** Additional context associated with requests */ -struct fuse_ctx -{ - uint64_t unique; - uint64_t nodeid; - uint32_t opcode; - uid_t uid; - gid_t gid; - pid_t pid; - mode_t umask; -}; - /* ----------------------------------------------------------- * * Request methods and replies * * ----------------------------------------------------------- */ @@ -127,55 +104,55 @@ struct fuse_ctx */ struct fuse_lowlevel_ops { - void (*access)(fuse_req_t req, struct fuse_in_header *hdr); - void (*bmap)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*copy_file_range)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*create)(fuse_req_t req, struct fuse_in_header *hdr); + void (*access)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*bmap)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*copy_file_range)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*create)(fuse_req_t *req, struct fuse_in_header *hdr); void (*destroy)(void *userdata); - void (*fallocate)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*flock)(fuse_req_t req, uint64_t ino, fuse_file_info_t *fi, int op); - void (*flush)(fuse_req_t req, struct fuse_in_header *hdr); - void (*forget)(fuse_req_t req, struct fuse_in_header *hdr); - void (*forget_multi)(fuse_req_t req, struct fuse_in_header *hdr); - void (*fsync)(fuse_req_t req, struct fuse_in_header *hdr); - void (*fsyncdir)(fuse_req_t req, struct fuse_in_header *hdr); - void (*getattr)(fuse_req_t req, struct fuse_in_header *hdr); - void (*getlk)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*getxattr)(fuse_req_t req, struct fuse_in_header *hdr); + void (*fallocate)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*flock)(fuse_req_t *req, uint64_t ino, fuse_file_info_t *fi, int op); + void (*flush)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*forget)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*forget_multi)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*fsync)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*fsyncdir)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*getattr)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*getlk)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*getxattr)(fuse_req_t *req, struct fuse_in_header *hdr); void (*init)(void *userdata, struct fuse_conn_info *conn); - void (*ioctl)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*link)(fuse_req_t req, struct fuse_in_header *hdr); - void (*listxattr)(fuse_req_t req, struct fuse_in_header *hdr); - void (*lookup)(fuse_req_t req, struct fuse_in_header *hdr); - void (*lseek)(fuse_req_t req, struct fuse_in_header *hdr); - void (*mkdir)(fuse_req_t req, struct fuse_in_header *hdr); - void (*mknod)(fuse_req_t req, struct fuse_in_header *hdr); - void (*open)(fuse_req_t req, struct fuse_in_header *hdr); - void (*opendir)(fuse_req_t req, struct fuse_in_header *hdr); - void (*poll)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*read)(fuse_req_t req, struct fuse_in_header *hdr); - void (*readdir)(fuse_req_t req, struct fuse_in_header *hdr); - void (*readdir_plus)(fuse_req_t req, struct fuse_in_header *hdr); - void (*readlink)(fuse_req_t req, struct fuse_in_header *hdr); - void (*release)(fuse_req_t req, struct fuse_in_header *hdr); - void (*releasedir)(fuse_req_t req, struct fuse_in_header *hdr); - void (*removemapping)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*removexattr)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*rename)(fuse_req_t req, struct fuse_in_header *hdr); - void (*rename2)(fuse_req_t req, struct fuse_in_header *hdr); - void (*retrieve_reply)(fuse_req_t req, void *cookie, uint64_t ino, off_t offset); - void (*rmdir)(fuse_req_t req, struct fuse_in_header *hdr); - void (*setattr)(fuse_req_t req, struct fuse_in_header *hdr); - void (*setlk)(fuse_req_t req, uint64_t ino, fuse_file_info_t *fi, struct flock *lock, int sleep); - void (*setupmapping)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*setxattr)(fuse_req_t req, struct fuse_in_header *hdr); - void (*statfs)(fuse_req_t req, struct fuse_in_header *hdr); - void (*statx)(fuse_req_t req, struct fuse_in_header *hdr); - void (*symlink)(fuse_req_t req, struct fuse_in_header *hdr); - void (*syncfs)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*tmpfile)(fuse_req_t req, const struct fuse_in_header *hdr); - void (*unlink)(fuse_req_t req, struct fuse_in_header *hdr); - void (*write)(fuse_req_t req, struct fuse_in_header *hdr); + void (*ioctl)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*link)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*listxattr)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*lookup)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*lseek)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*mkdir)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*mknod)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*open)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*opendir)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*poll)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*read)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*readdir)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*readdir_plus)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*readlink)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*release)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*releasedir)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*removemapping)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*removexattr)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*rename)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*rename2)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*retrieve_reply)(fuse_req_t *req, void *cookie, uint64_t ino, off_t offset); + void (*rmdir)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*setattr)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*setlk)(fuse_req_t *req, uint64_t ino, fuse_file_info_t *fi, struct flock *lock, int sleep); + void (*setupmapping)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*setxattr)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*statfs)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*statx)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*symlink)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*syncfs)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*tmpfile)(fuse_req_t *req, const struct fuse_in_header *hdr); + void (*unlink)(fuse_req_t *req, struct fuse_in_header *hdr); + void (*write)(fuse_req_t *req, struct fuse_in_header *hdr); }; /** @@ -191,7 +168,7 @@ struct fuse_lowlevel_ops * @param err the positive error value, or zero for success * @return zero for success, -errno for failure to send reply */ -int fuse_reply_err(fuse_req_t req, int err); +int fuse_reply_err(fuse_req_t *req, int err); /** * Don't send reply @@ -201,7 +178,7 @@ int fuse_reply_err(fuse_req_t req, int err); * * @param req request handle */ -void fuse_reply_none(fuse_req_t req); +void fuse_reply_none(fuse_req_t *req); /** * Reply with a directory entry @@ -216,7 +193,7 @@ void fuse_reply_none(fuse_req_t req); * @param e the entry parameters * @return zero for success, -errno for failure to send reply */ -int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e); +int fuse_reply_entry(fuse_req_t *req, const struct fuse_entry_param *e); /** * Reply with a directory entry and open parameters @@ -235,7 +212,8 @@ int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e); * @param fi file information * @return zero for success, -errno for failure to send reply */ -int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, +int fuse_reply_create(fuse_req_t *req, + const struct fuse_entry_param *e, const fuse_file_info_t *fi); /** @@ -249,12 +227,12 @@ int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, * @param attr_timeout validity timeout (in seconds) for the attributes * @return zero for success, -errno for failure to send reply */ -int fuse_reply_attr(fuse_req_t req, +int fuse_reply_attr(fuse_req_t *req, const struct stat *attr, const uint64_t timeout); -int fuse_reply_statx(fuse_req_t req, +int fuse_reply_statx(fuse_req_t *req, int flags, struct fuse_statx *st, const uint64_t timeout); @@ -269,7 +247,7 @@ int fuse_reply_statx(fuse_req_t req, * @param link symbolic link contents * @return zero for success, -errno for failure to send reply */ -int fuse_reply_readlink(fuse_req_t req, const char *link); +int fuse_reply_readlink(fuse_req_t *req, const char *link); /** * Reply with open parameters @@ -284,7 +262,7 @@ int fuse_reply_readlink(fuse_req_t req, const char *link); * @param fi file information * @return zero for success, -errno for failure to send reply */ -int fuse_reply_open(fuse_req_t req, +int fuse_reply_open(fuse_req_t *req, const fuse_file_info_t *fi); /** @@ -297,7 +275,7 @@ int fuse_reply_open(fuse_req_t req, * @param count the number of bytes written * @return zero for success, -errno for failure to send reply */ -int fuse_reply_write(fuse_req_t req, size_t count); +int fuse_reply_write(fuse_req_t *req, size_t count); /** * Reply with data @@ -310,9 +288,9 @@ int fuse_reply_write(fuse_req_t req, size_t count); * @param size the size of data in bytes * @return zero for success, -errno for failure to send reply */ -int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size); +int fuse_reply_buf(fuse_req_t *req, const char *buf, size_t size); -int fuse_reply_data(fuse_req_t req, +int fuse_reply_data(fuse_req_t *req, char *buf, size_t bufsize); @@ -327,7 +305,7 @@ int fuse_reply_data(fuse_req_t req, * @param count the size of vector * @return zero for success, -errno for failure to send reply */ -int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count); +int fuse_reply_iov(fuse_req_t *req, const struct iovec *iov, int count); /** * Reply with filesystem statistics @@ -339,7 +317,7 @@ int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count); * @param stbuf filesystem statistics * @return zero for success, -errno for failure to send reply */ -int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf); +int fuse_reply_statfs(fuse_req_t *req, const struct statvfs *stbuf); /** * Reply with needed buffer size @@ -351,7 +329,7 @@ int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf); * @param count the buffer size needed in bytes * @return zero for success, -errno for failure to send reply */ -int fuse_reply_xattr(fuse_req_t req, size_t count); +int fuse_reply_xattr(fuse_req_t *req, size_t count); /** * Reply with file lock information @@ -363,7 +341,7 @@ int fuse_reply_xattr(fuse_req_t req, size_t count); * @param lock the lock information * @return zero for success, -errno for failure to send reply */ -int fuse_reply_lock(fuse_req_t req, const struct flock *lock); +int fuse_reply_lock(fuse_req_t *req, const struct flock *lock); /** * Reply with block index @@ -375,7 +353,7 @@ int fuse_reply_lock(fuse_req_t req, const struct flock *lock); * @param idx block index within device * @return zero for success, -errno for failure to send reply */ -int fuse_reply_bmap(fuse_req_t req, uint64_t idx); +int fuse_reply_bmap(fuse_req_t *req, uint64_t idx); /** * Reply to ask for data fetch and output buffer preparation. ioctl @@ -392,7 +370,7 @@ int fuse_reply_bmap(fuse_req_t req, uint64_t idx); * @param out_count number of entries in out_iov * @return zero for success, -errno for failure to send reply */ -int fuse_reply_ioctl_retry(fuse_req_t req, +int fuse_reply_ioctl_retry(fuse_req_t *req, const struct iovec *in_iov, size_t in_count, const struct iovec *out_iov, size_t out_count); @@ -407,7 +385,7 @@ int fuse_reply_ioctl_retry(fuse_req_t req, * @param buf buffer containing output data * @param size length of output data */ -int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, uint32_t size); +int fuse_reply_ioctl(fuse_req_t *req, int result, const void *buf, uint32_t size); /** * Reply to finish ioctl with iov buffer @@ -420,7 +398,7 @@ int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, uint32_t size) * @param iov the vector containing the data * @param count the size of vector */ -int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, +int fuse_reply_ioctl_iov(fuse_req_t *req, int result, const struct iovec *iov, int count); /** @@ -429,7 +407,7 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, * @param req request handle * @param revents poll result event mask */ -int fuse_reply_poll(fuse_req_t req, unsigned revents); +int fuse_reply_poll(fuse_req_t *req, unsigned revents); /* ----------------------------------------------------------- * * Notification * @@ -551,25 +529,6 @@ int fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, uint64_t ino, * Utility functions * * ----------------------------------------------------------- */ -/** - * Get the userdata from the request - * - * @param req request handle - * @return the user data passed to fuse_lowlevel_new() - */ -void *fuse_req_userdata(fuse_req_t req); - -/** - * Get the context from the request - * - * The pointer returned by this function will only be valid for the - * request's lifetime - * - * @param req request handle - * @return the context structure - */ -const struct fuse_ctx *fuse_req_ctx(fuse_req_t req); - /** * Get the current supplementary group IDs for the specified request * @@ -589,7 +548,7 @@ const struct fuse_ctx *fuse_req_ctx(fuse_req_t req); * @param list array of group IDs to be filled in * @return the total number of supplementary group IDs or -errno on failure */ -int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]); +int fuse_req_getgroups(fuse_req_t *req, int size, gid_t list[]); /* ----------------------------------------------------------- * * Filesystem setup * @@ -679,5 +638,3 @@ struct fuse_session *fuse_chan_session(struct fuse_chan *ch); void fuse_chan_destroy(struct fuse_chan *ch); EXTERN_C_END - -#endif /* _FUSE_LOWLEVEL_H_ */ diff --git a/libfuse/include/fuse_req.h b/libfuse/include/fuse_req.h new file mode 100644 index 00000000..1be68b0a --- /dev/null +++ b/libfuse/include/fuse_req.h @@ -0,0 +1,15 @@ +#pragma once + +#include "fuse_req_ctx.h" + +struct fuse_ll; +struct fuse_chan; + +typedef struct fuse_req_t fuse_req_t; +struct fuse_req_t +{ + fuse_req_ctx_t ctx; + struct fuse_ll *f; + struct fuse_chan *ch; + unsigned int ioctl_64bit : 1; +}; diff --git a/libfuse/include/fuse_req_ctx.h b/libfuse/include/fuse_req_ctx.h new file mode 100644 index 00000000..b2bdfe28 --- /dev/null +++ b/libfuse/include/fuse_req_ctx.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +typedef struct fuse_req_ctx_t fuse_req_ctx_t; +struct fuse_req_ctx_t +{ + uint32_t len; + uint32_t opcode; + uint64_t unique; + uint64_t nodeid; + uint32_t uid; + uint32_t gid; + uint32_t pid; + uint32_t umask; +}; diff --git a/libfuse/lib/fuse.cpp b/libfuse/lib/fuse.cpp index ad7aee60..21dac2a8 100644 --- a/libfuse/lib/fuse.cpp +++ b/libfuse/lib/fuse.cpp @@ -19,6 +19,7 @@ #include "mutex.hpp" #include "node.hpp" +#include "fuse_req.h" #include "fuse_dirents.hpp" #include "fuse_i.h" #include "fuse_kernel.h" @@ -81,11 +82,6 @@ struct fuse_config int help; }; -struct fuse_fs -{ - struct fuse_operations op; -}; - struct lock_queue_element { struct lock_queue_element *next; @@ -139,7 +135,7 @@ struct fuse unsigned int hidectr; pthread_mutex_t lock; struct fuse_config conf; - struct fuse_fs *fs; + fuse_operations ops; struct lock_queue_element *lockq; kvec_t(remembered_node_t) remembered_nodes; @@ -165,15 +161,7 @@ struct fuse_dh fuse_dirents_t d; }; -struct fuse_context_i -{ - struct fuse_context ctx; - fuse_req_t req; -}; - -static pthread_key_t fuse_context_key; -static pthread_mutex_t fuse_context_lock = PTHREAD_MUTEX_INITIALIZER; -static int fuse_context_ref; +static struct fuse f = {0}; /* Why was the nodeid:generation logic simplified? @@ -181,7 +169,7 @@ static int fuse_context_ref; nodeid is uint64_t: max value of 18446744073709551616 If nodes were created at a rate of 1048576 per second it would take over 500 thousand years to roll over. I'm fine with risking that. - */ +*/ static uint64_t generate_nodeid(nodeid_gen_t *ng_) @@ -191,22 +179,6 @@ generate_nodeid(nodeid_gen_t *ng_) return ng_->nodeid; } -static -char* -filename_strdup(struct fuse *f_, - const char *fn_) -{ - return strdup(fn_); -} - -static -void -filename_free(struct fuse *f_, - char *fn_) -{ - free(fn_); -} - static void* fuse_hdr_arg(const struct fuse_in_header *hdr_) @@ -258,13 +230,12 @@ list_del(struct list_head *entry) static size_t -id_hash(struct fuse *f, - uint64_t ino) +id_hash(uint64_t ino) { - uint64_t hash = ((uint32_t)ino * 2654435761U) % f->id_table.size; - uint64_t oldhash = hash % (f->id_table.size / 2); + uint64_t hash = ((uint32_t)ino * 2654435761U) % f.id_table.size; + uint64_t oldhash = hash % (f.id_table.size / 2); - if(oldhash >= f->id_table.split) + if(oldhash >= f.id_table.split) return oldhash; else return hash; @@ -272,13 +243,12 @@ id_hash(struct fuse *f, static node_t* -get_node_nocheck(struct fuse *f, - uint64_t nodeid) +get_node_nocheck(uint64_t nodeid) { - size_t hash = id_hash(f,nodeid); + size_t hash = id_hash(nodeid); node_t *node; - for(node = f->id_table.array[hash]; node != NULL; node = node->id_next) + for(node = f.id_table.array[hash]; node != NULL; node = node->id_next) if(node->nodeid == nodeid) return node; @@ -287,10 +257,9 @@ get_node_nocheck(struct fuse *f, static node_t* -get_node(struct fuse *f, - const uint64_t nodeid) +get_node(const uint64_t nodeid) { - node_t *node = get_node_nocheck(f,nodeid); + node_t *node = get_node_nocheck(nodeid); if(!node) { @@ -304,15 +273,14 @@ get_node(struct fuse *f, static void -remove_remembered_node(struct fuse *f_, - node_t *node_) +remove_remembered_node(node_t *node_) { - for(size_t i = 0; i < kv_size(f_->remembered_nodes); i++) + for(size_t i = 0; i < kv_size(f.remembered_nodes); i++) { - if(kv_A(f_->remembered_nodes,i).node != node_) + if(kv_A(f.remembered_nodes,i).node != node_) continue; - kv_delete(f_->remembered_nodes,i); + kv_delete(f.remembered_nodes,i); break; } } @@ -359,10 +327,9 @@ current_time() static void -free_node(struct fuse *f_, - node_t *node_) +free_node(node_t *node_) { - filename_free(f_,node_->name); + free(node_->name); node_free(node_); } @@ -387,9 +354,9 @@ node_table_reduce(struct node_table *t) static void -remerge_id(struct fuse *f) +remerge_id() { - struct node_table *t = &f->id_table; + struct node_table *t = &f.id_table; int iter; if(t->split == 0) @@ -417,19 +384,18 @@ remerge_id(struct fuse *f) static void -unhash_id(struct fuse *f, - node_t *node) +unhash_id(node_t *node) { - node_t **nodep = &f->id_table.array[id_hash(f,node->nodeid)]; + node_t **nodep = &f.id_table.array[id_hash(node->nodeid)]; for(; *nodep != NULL; nodep = &(*nodep)->id_next) if(*nodep == node) { *nodep = node->id_next; - f->id_table.use--; + f.id_table.use--; - if(f->id_table.use < f->id_table.size / 4) - remerge_id(f); + if(f.id_table.use < (f.id_table.size / 4)) + remerge_id(); return; } } @@ -455,9 +421,9 @@ node_table_resize(struct node_table *t) static void -rehash_id(struct fuse *f) +rehash_id() { - struct node_table *t = &f->id_table; + struct node_table *t = &f.id_table; node_t **nodep; node_t **next; size_t hash; @@ -470,7 +436,7 @@ rehash_id(struct fuse *f) for(nodep = &t->array[hash]; *nodep != NULL; nodep = next) { node_t *node = *nodep; - size_t newhash = id_hash(f,node->nodeid); + size_t newhash = id_hash(node->nodeid); if(newhash != hash) { @@ -491,25 +457,23 @@ rehash_id(struct fuse *f) static void -hash_id(struct fuse *f, - node_t *node) +hash_id(node_t *node) { size_t hash; - hash = id_hash(f,node->nodeid); - node->id_next = f->id_table.array[hash]; - f->id_table.array[hash] = node; - f->id_table.use++; + hash = id_hash(node->nodeid); + node->id_next = f.id_table.array[hash]; + f.id_table.array[hash] = node; + f.id_table.use++; - if(f->id_table.use >= f->id_table.size / 2) - rehash_id(f); + if(f.id_table.use >= (f.id_table.size / 2)) + rehash_id(); } static size_t -name_hash(struct fuse *f, - uint64_t parent, - const char *name) +name_hash(uint64_t parent, + const char *name) { uint64_t hash = parent; uint64_t oldhash; @@ -517,9 +481,9 @@ name_hash(struct fuse *f, for(; *name; name++) hash = hash * 31 + (unsigned char)*name; - hash %= f->name_table.size; - oldhash = hash % (f->name_table.size / 2); - if(oldhash >= f->name_table.split) + hash %= f.name_table.size; + oldhash = hash % (f.name_table.size / 2); + if(oldhash >= f.name_table.split) return oldhash; else return hash; @@ -527,15 +491,14 @@ name_hash(struct fuse *f, static void -unref_node(struct fuse *f, - node_t *node); +unref_node(node_t *node); static void -remerge_name(struct fuse *f) +remerge_name() { int iter; - struct node_table *t = &f->name_table; + struct node_table *t = &f.name_table; if(t->split == 0) node_table_reduce(t); @@ -561,27 +524,26 @@ remerge_name(struct fuse *f) static void -unhash_name(struct fuse *f, - node_t *node) +unhash_name(node_t *node) { if(node->name) { - size_t hash = name_hash(f,node->parent->nodeid,node->name); - node_t **nodep = &f->name_table.array[hash]; + size_t hash = name_hash(node->parent->nodeid,node->name); + node_t **nodep = &f.name_table.array[hash]; for(; *nodep != NULL; nodep = &(*nodep)->name_next) if(*nodep == node) { *nodep = node->name_next; node->name_next = NULL; - unref_node(f,node->parent); - filename_free(f,node->name); + unref_node(node->parent); + free(node->name); node->name = NULL; node->parent = NULL; - f->name_table.use--; + f.name_table.use--; - if(f->name_table.use < f->name_table.size / 4) - remerge_name(f); + if(f.name_table.use < f.name_table.size / 4) + remerge_name(); return; } @@ -595,9 +557,9 @@ unhash_name(struct fuse *f, static void -rehash_name(struct fuse *f) +rehash_name() { - struct node_table *t = &f->name_table; + struct node_table *t = &f.name_table; node_t **nodep; node_t **next; size_t hash; @@ -610,7 +572,7 @@ rehash_name(struct fuse *f) for(nodep = &t->array[hash]; *nodep != NULL; nodep = next) { node_t *node = *nodep; - size_t newhash = name_hash(f,node->parent->nodeid,node->name); + size_t newhash = name_hash(node->parent->nodeid,node->name); if(newhash != hash) { @@ -631,25 +593,24 @@ rehash_name(struct fuse *f) static int -hash_name(struct fuse *f, - node_t *node, - uint64_t parentid, - const char *name) -{ - size_t hash = name_hash(f,parentid,name); - node_t *parent = get_node(f,parentid); - node->name = filename_strdup(f,name); +hash_name(node_t *node, + uint64_t parentid, + const char *name) +{ + size_t hash = name_hash(parentid,name); + node_t *parent = get_node(parentid); + node->name = strdup(name); if(node->name == NULL) return -1; parent->refctr++; node->parent = parent; - node->name_next = f->name_table.array[hash]; - f->name_table.array[hash] = node; - f->name_table.use++; + node->name_next = f.name_table.array[hash]; + f.name_table.array[hash] = node; + f.name_table.use++; - if(f->name_table.use >= f->name_table.size / 2) - rehash_name(f); + if(f.name_table.use >= f.name_table.size / 2) + rehash_name(); return 0; } @@ -657,33 +618,31 @@ hash_name(struct fuse *f, static inline int -remember_nodes(struct fuse *f_) +remember_nodes() { - return (f_->conf.remember > 0); + return (f.conf.remember > 0); } static void -delete_node(struct fuse *f, - node_t *node) +delete_node(node_t *node) { assert(node->treelock == 0); - unhash_name(f,node); - if(remember_nodes(f)) - remove_remembered_node(f,node); - unhash_id(f,node); + unhash_name(node); + if(remember_nodes()) + remove_remembered_node(node); + unhash_id(node); node_free(node); } static void -unref_node(struct fuse *f, - node_t *node) +unref_node(node_t *node) { assert(node->refctr > 0); node->refctr--; if(!node->refctr) - delete_node(f,node); + delete_node(node); } static @@ -701,15 +660,14 @@ rand64(void) static node_t* -lookup_node(struct fuse *f, - uint64_t parent, - const char *name) +lookup_node(uint64_t parent, + const char *name) { size_t hash; node_t *node; - hash = name_hash(f,parent,name); - for(node = f->name_table.array[hash]; node != NULL; node = node->name_next) + hash = name_hash(parent,name); + for(node = f.name_table.array[hash]; node != NULL; node = node->name_next) if(node->parent->nodeid == parent && strcmp(node->name,name) == 0) return node; @@ -727,17 +685,16 @@ inc_nlookup(node_t *node) static node_t* -find_node(struct fuse *f, - uint64_t parent, - const char *name) +find_node(uint64_t parent, + const char *name) { node_t *node; - mutex_lock(&f->lock); + mutex_lock(&f.lock); if(!name) - node = get_node(f,parent); + node = get_node(parent); else - node = lookup_node(f,parent,name); + node = lookup_node(parent,name); if(node == NULL) { @@ -745,25 +702,25 @@ find_node(struct fuse *f, if(node == NULL) goto out_err; - node->nodeid = generate_nodeid(&f->nodeid_gen); - if(f->conf.remember) + node->nodeid = generate_nodeid(&f.nodeid_gen); + if(f.conf.remember) inc_nlookup(node); - if(hash_name(f,node,parent,name) == -1) + if(hash_name(node,parent,name) == -1) { - free_node(f,node); + free_node(node); node = NULL; goto out_err; } - hash_id(f,node); + hash_id(node); } - else if((node->nlookup == 1) && remember_nodes(f)) + else if((node->nlookup == 1) && remember_nodes()) { - remove_remembered_node(f,node); + remove_remembered_node(node); } inc_nlookup(node); out_err: - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); return node; } @@ -809,10 +766,9 @@ add_name(char **buf, static void -unlock_path(struct fuse *f, - uint64_t nodeid, - node_t *wnode, - node_t *end) +unlock_path(uint64_t nodeid, + node_t *wnode, + node_t *end) { node_t *node; @@ -822,7 +778,9 @@ unlock_path(struct fuse *f, wnode->treelock = 0; } - for(node = get_node(f,nodeid); node != end && node->nodeid != FUSE_ROOT_ID; node = node->parent) + for(node = get_node(nodeid); + node != end && node->nodeid != FUSE_ROOT_ID; + node = node->parent) { assert(node->treelock != 0); assert(node->treelock != TREELOCK_WAIT_OFFSET); @@ -839,12 +797,11 @@ unlock_path(struct fuse *f, '/' for each path but we need a relative path for usage with `openat()` functions and would rather do that here than in the called function. - */ +*/ static int -try_get_path(struct fuse *f, - uint64_t nodeid, +try_get_path(uint64_t nodeid, const char *name, char **path, node_t **wnodep, @@ -878,7 +835,7 @@ try_get_path(struct fuse *f, if(wnodep) { assert(need_lock); - wnode = lookup_node(f,nodeid,name); + wnode = lookup_node(nodeid,name); if(wnode) { if(wnode->treelock != 0) @@ -892,7 +849,7 @@ try_get_path(struct fuse *f, } } - for(node = get_node(f,nodeid); node->nodeid != FUSE_ROOT_ID; node = node->parent) + for(node = get_node(nodeid); node->nodeid != FUSE_ROOT_ID; node = node->parent) { err = -ESTALE; if(node->name == NULL || node->parent == NULL) @@ -926,7 +883,7 @@ try_get_path(struct fuse *f, out_unlock: if(need_lock) - unlock_path(f,nodeid,wnode,node); + unlock_path(nodeid,wnode,node); out_free: free(buf); @@ -936,27 +893,26 @@ try_get_path(struct fuse *f, static int -try_get_path2(struct fuse *f, - uint64_t nodeid1, - const char *name1, - uint64_t nodeid2, - const char *name2, - char **path1, - char **path2, - node_t **wnode1, - node_t **wnode2) +try_get_path2(uint64_t nodeid1, + const char *name1, + uint64_t nodeid2, + const char *name2, + char **path1, + char **path2, + node_t **wnode1, + node_t **wnode2) { int err; - err = try_get_path(f,nodeid1,name1,path1,wnode1,true); + err = try_get_path(nodeid1,name1,path1,wnode1,true); if(!err) { - err = try_get_path(f,nodeid2,name2,path2,wnode2,true); + err = try_get_path(nodeid2,name2,path2,wnode2,true); if(err) { node_t *wn1 = wnode1 ? *wnode1 : NULL; - unlock_path(f,nodeid1,wn1,NULL); + unlock_path(nodeid1,wn1,NULL); free(*path1); } } @@ -966,15 +922,14 @@ try_get_path2(struct fuse *f, static void -queue_element_wakeup(struct fuse *f, - struct lock_queue_element *qe) +queue_element_wakeup(struct lock_queue_element *qe) { int err; if(!qe->path1) { /* Just waiting for it to be unlocked */ - if(get_node(f,qe->nodeid1)->treelock == 0) + if(get_node(qe->nodeid1)->treelock == 0) pthread_cond_signal(&qe->cond); return; @@ -985,8 +940,7 @@ queue_element_wakeup(struct fuse *f, if(!qe->path2) { - err = try_get_path(f, - qe->nodeid1, + err = try_get_path(qe->nodeid1, qe->name1, qe->path1, qe->wnode1, @@ -994,8 +948,7 @@ queue_element_wakeup(struct fuse *f, } else { - err = try_get_path2(f, - qe->nodeid1, + err = try_get_path2(qe->nodeid1, qe->name1, qe->nodeid2, qe->name2, @@ -1015,69 +968,65 @@ queue_element_wakeup(struct fuse *f, static void -wake_up_queued(struct fuse *f) +wake_up_queued() { struct lock_queue_element *qe; - for(qe = f->lockq; qe != NULL; qe = qe->next) - queue_element_wakeup(f,qe); + for(qe = f.lockq; qe != NULL; qe = qe->next) + queue_element_wakeup(qe); } static void -queue_path(struct fuse *f, - struct lock_queue_element *qe) +queue_path(struct lock_queue_element *qe) { struct lock_queue_element **qp; qe->done = false; pthread_cond_init(&qe->cond,NULL); qe->next = NULL; - for(qp = &f->lockq; *qp != NULL; qp = &(*qp)->next); + for(qp = &f.lockq; *qp != NULL; qp = &(*qp)->next); *qp = qe; } static void -dequeue_path(struct fuse *f, - struct lock_queue_element *qe) +dequeue_path(struct lock_queue_element *qe) { struct lock_queue_element **qp; pthread_cond_destroy(&qe->cond); - for(qp = &f->lockq; *qp != qe; qp = &(*qp)->next); + for(qp = &f.lockq; *qp != qe; qp = &(*qp)->next); *qp = qe->next; } static int -wait_path(struct fuse *f, - struct lock_queue_element *qe) +wait_path(struct lock_queue_element *qe) { - queue_path(f,qe); + queue_path(qe); do { - pthread_cond_wait(&qe->cond,&f->lock); + pthread_cond_wait(&qe->cond,&f.lock); } while(!qe->done); - dequeue_path(f,qe); + dequeue_path(qe); return qe->err; } static int -get_path_common(struct fuse *f, - uint64_t nodeid, - const char *name, - char **path, - node_t **wnode) +get_path_common(uint64_t nodeid, + const char *name, + char **path, + node_t **wnode) { int err; - mutex_lock(&f->lock); - err = try_get_path(f,nodeid,name,path,wnode,true); + mutex_lock(&f.lock); + err = try_get_path(nodeid,name,path,wnode,true); if(err == -EAGAIN) { struct lock_queue_element qe = {0}; @@ -1087,59 +1036,55 @@ get_path_common(struct fuse *f, qe.path1 = path; qe.wnode1 = wnode; - err = wait_path(f,&qe); + err = wait_path(&qe); } - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); return err; } static int -get_path(struct fuse *f, - uint64_t nodeid, - char **path) +get_path(uint64_t nodeid, + char **path) { - return get_path_common(f,nodeid,NULL,path,NULL); + return get_path_common(nodeid,NULL,path,NULL); } static int -get_path_name(struct fuse *f, - uint64_t nodeid, - const char *name, - char **path) +get_path_name(uint64_t nodeid, + const char *name, + char **path) { - return get_path_common(f,nodeid,name,path,NULL); + return get_path_common(nodeid,name,path,NULL); } static int -get_path_wrlock(struct fuse *f, - uint64_t nodeid, - const char *name, - char **path, - node_t **wnode) +get_path_wrlock(uint64_t nodeid, + const char *name, + char **path, + node_t **wnode) { - return get_path_common(f,nodeid,name,path,wnode); + return get_path_common(nodeid,name,path,wnode); } static int -get_path2(struct fuse *f, - uint64_t nodeid1, - const char *name1, - uint64_t nodeid2, - const char *name2, - char **path1, - char **path2, - node_t **wnode1, - node_t **wnode2) +get_path2(uint64_t nodeid1, + const char *name1, + uint64_t nodeid2, + const char *name2, + char **path1, + char **path2, + node_t **wnode1, + node_t **wnode2) { int err; - mutex_lock(&f->lock); - err = try_get_path2(f,nodeid1,name1,nodeid2,name2, + mutex_lock(&f.lock); + err = try_get_path2(nodeid1,name1,nodeid2,name2, path1,path2,wnode1,wnode2); if(err == -EAGAIN) { @@ -1154,70 +1099,66 @@ get_path2(struct fuse *f, qe.path2 = path2; qe.wnode2 = wnode2; - err = wait_path(f,&qe); + err = wait_path(&qe); } - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); return err; } static void -free_path_wrlock(struct fuse *f, - uint64_t nodeid, - node_t *wnode, - char *path) -{ - mutex_lock(&f->lock); - unlock_path(f,nodeid,wnode,NULL); - if(f->lockq) - wake_up_queued(f); - mutex_unlock(&f->lock); +free_path_wrlock(uint64_t nodeid, + node_t *wnode, + char *path) +{ + mutex_lock(&f.lock); + unlock_path(nodeid,wnode,NULL); + if(f.lockq) + wake_up_queued(); + mutex_unlock(&f.lock); free(path); } static void -free_path(struct fuse *f, - uint64_t nodeid, - char *path) +free_path(uint64_t nodeid, + char *path) { if(path) - free_path_wrlock(f,nodeid,NULL,path); + free_path_wrlock(nodeid,NULL,path); } static void -free_path2(struct fuse *f, - uint64_t nodeid1, - uint64_t nodeid2, - node_t *wnode1, - node_t *wnode2, - char *path1, - char *path2) -{ - mutex_lock(&f->lock); - unlock_path(f,nodeid1,wnode1,NULL); - unlock_path(f,nodeid2,wnode2,NULL); - wake_up_queued(f); - mutex_unlock(&f->lock); +free_path2(uint64_t nodeid1, + uint64_t nodeid2, + node_t *wnode1, + node_t *wnode2, + char *path1, + char *path2) +{ + mutex_lock(&f.lock); + unlock_path(nodeid1,wnode1,NULL); + unlock_path(nodeid2,wnode2,NULL); + wake_up_queued(); + mutex_unlock(&f.lock); free(path1); free(path2); } static void -forget_node(struct fuse *f, - const uint64_t nodeid, - const uint64_t nlookup) +forget_node(const uint64_t nodeid, + const uint64_t nlookup) { node_t *node; if(nodeid == FUSE_ROOT_ID) return; - mutex_lock(&f->lock); - node = get_node(f,nodeid); + mutex_lock(&f.lock); + node = get_node(nodeid); /* * Node may still be locked due to interrupt idiocy in open, @@ -1229,15 +1170,15 @@ forget_node(struct fuse *f, qe.nodeid1 = nodeid; - queue_path(f,&qe); + queue_path(&qe); do { - pthread_cond_wait(&qe.cond,&f->lock); + pthread_cond_wait(&qe.cond,&f.lock); } while((node->nlookup == nlookup) && node->treelock); - dequeue_path(f,&qe); + dequeue_path(&qe); } assert(node->nlookup >= nlookup); @@ -1245,101 +1186,90 @@ forget_node(struct fuse *f, if(node->nlookup == 0) { - unref_node(f,node); + unref_node(node); } - else if((node->nlookup == 1) && remember_nodes(f)) + else if((node->nlookup == 1) && remember_nodes()) { remembered_node_t fn; fn.node = node; fn.time = current_time(); - kv_push(remembered_node_t,f->remembered_nodes,fn); + kv_push(remembered_node_t,f.remembered_nodes,fn); } - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); } static void -unlink_node(struct fuse *f, - node_t *node) +unlink_node(node_t *node) { - if(remember_nodes(f)) + if(remember_nodes()) { assert(node->nlookup > 1); node->nlookup--; } - unhash_name(f,node); + unhash_name(node); } static void -remove_node(struct fuse *f, - uint64_t dir, - const char *name) +remove_node(uint64_t dir, + const char *name) { node_t *node; - mutex_lock(&f->lock); - node = lookup_node(f,dir,name); + mutex_lock(&f.lock); + node = lookup_node(dir,name); if(node != NULL) - unlink_node(f,node); - mutex_unlock(&f->lock); + unlink_node(node); + mutex_unlock(&f.lock); } static int -rename_node(struct fuse *f, - uint64_t olddir, - const char *oldname, - uint64_t newdir, - const char *newname) +rename_node(uint64_t olddir, + const char *oldname, + uint64_t newdir, + const char *newname) { + int err = 0; node_t *node; node_t *newnode; - int err = 0; - mutex_lock(&f->lock); - node = lookup_node(f,olddir,oldname); - newnode = lookup_node(f,newdir,newname); + mutex_lock(&f.lock); + node = lookup_node(olddir,oldname); + newnode = lookup_node(newdir,newname); if(node == NULL) goto out; if(newnode != NULL) - unlink_node(f,newnode); + unlink_node(newnode); - unhash_name(f,node); - if(hash_name(f,node,newdir,newname) == -1) + unhash_name(node); + if(hash_name(node,newdir,newname) == -1) { err = -ENOMEM; goto out; } out: - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); return err; } static void -set_stat(struct fuse *f, - uint64_t nodeid, +set_stat(uint64_t nodeid, struct stat *stbuf) { - if(f->conf.set_mode) - stbuf->st_mode = (stbuf->st_mode & S_IFMT) | (0777 & ~f->conf.umask); - if(f->conf.set_uid) - stbuf->st_uid = f->conf.uid; - if(f->conf.set_gid) - stbuf->st_gid = f->conf.gid; -} - -static -struct fuse* -req_fuse(fuse_req_t req) -{ - return (struct fuse*)fuse_req_userdata(req); + if(f.conf.set_mode) + stbuf->st_mode = (stbuf->st_mode & S_IFMT) | (0777 & ~f.conf.umask); + if(f.conf.set_uid) + stbuf->st_uid = f.conf.uid; + if(f.conf.set_gid) + stbuf->st_gid = f.conf.gid; } static @@ -1366,25 +1296,24 @@ update_stat(node_t *node_, static int -set_path_info(struct fuse *f, - uint64_t nodeid, +set_path_info(uint64_t nodeid, const char *name, struct fuse_entry_param *e) { node_t *node; - node = find_node(f,nodeid,name); + node = find_node(nodeid,name); if(node == NULL) return -ENOMEM; e->ino = node->nodeid; - e->generation = ((e->ino == FUSE_ROOT_ID) ? 0 : f->nodeid_gen.generation); + e->generation = ((e->ino == FUSE_ROOT_ID) ? 0 : f.nodeid_gen.generation); - mutex_lock(&f->lock); + mutex_lock(&f.lock); update_stat(node,&e->attr); - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); - set_stat(f,e->ino,&e->attr); + set_stat(e->ino,&e->attr); return 0; } @@ -1397,10 +1326,10 @@ set_path_info(struct fuse *f, excluslively. Root node always has a nodeid of 1 and generation of 0. To ensure this set_path_info() explicitly ensures the root id has a generation of 0. - */ +*/ static int -lookup_path(struct fuse *f, +lookup_path(fuse_req_t *req_, uint64_t nodeid, const char *name, const char *fusepath, @@ -1409,124 +1338,38 @@ lookup_path(struct fuse *f, { int rv; + assert(req_ != NULL); + memset(e,0,sizeof(struct fuse_entry_param)); rv = ((fi == NULL) ? - f->fs->op.getattr(&fusepath[1],&e->attr,&e->timeout) : - f->fs->op.fgetattr(fi->fh,&e->attr,&e->timeout)); + f.ops.getattr(&req_->ctx,&fusepath[1],&e->attr,&e->timeout) : + f.ops.fgetattr(&req_->ctx,fi->fh,&e->attr,&e->timeout)); if(rv) return rv; - return set_path_info(f,nodeid,name,e); -} - -static -struct fuse_context_i* -fuse_get_context_internal(void) -{ - struct fuse_context_i *c; - - c = (struct fuse_context_i *)pthread_getspecific(fuse_context_key); - if(c == NULL) - { - c = (struct fuse_context_i*)calloc(1,sizeof(struct fuse_context_i)); - if(c == NULL) - { - /* This is hard to deal with properly,so just - abort. If memory is so low that the - context cannot be allocated,there's not - much hope for the filesystem anyway */ - fprintf(stderr,"fuse: failed to allocate thread specific data\n"); - abort(); - } - pthread_setspecific(fuse_context_key,c); - } - return c; + return set_path_info(nodeid,name,e); } static void -fuse_freecontext(void *data) -{ - free(data); -} - -static -int -fuse_create_context_key(void) -{ - int err = 0; - mutex_lock(&fuse_context_lock); - if(!fuse_context_ref) - { - err = pthread_key_create(&fuse_context_key,fuse_freecontext); - if(err) - { - fprintf(stderr,"fuse: failed to create thread specific key: %s\n", - strerror(err)); - mutex_unlock(&fuse_context_lock); - return -1; - } - } - fuse_context_ref++; - mutex_unlock(&fuse_context_lock); - return 0; -} - -static -void -fuse_delete_context_key(void) -{ - mutex_lock(&fuse_context_lock); - fuse_context_ref--; - if(!fuse_context_ref) - { - free(pthread_getspecific(fuse_context_key)); - pthread_key_delete(fuse_context_key); - } - mutex_unlock(&fuse_context_lock); -} - -static -struct fuse* -req_fuse_prepare(fuse_req_t req) -{ - struct fuse_context_i *c = fuse_get_context_internal(); - const struct fuse_ctx *ctx = fuse_req_ctx(req); - - c->req = req; - c->ctx.fuse = req_fuse(req); - c->ctx.opcode = ctx->opcode; - c->ctx.unique = ctx->unique; - c->ctx.nodeid = ctx->nodeid; - c->ctx.uid = ctx->uid; - c->ctx.gid = ctx->gid; - c->ctx.pid = ctx->pid; - c->ctx.umask = ctx->umask; - - return c->ctx.fuse; -} - -static -void -reply_entry(fuse_req_t req, +reply_entry(fuse_req_t *req_, const struct fuse_entry_param *e, int err) { if(!err) { - struct fuse *f = req_fuse(req); - if(fuse_reply_entry(req,e) == -ENOENT) + if(fuse_reply_entry(req_,e) == -ENOENT) { /* Skip forget for negative result */ if(e->ino != 0) - forget_node(f,e->ino,1); + forget_node(e->ino,1); } } else { - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } } @@ -1535,101 +1378,87 @@ void fuse_lib_init(void *data, struct fuse_conn_info *conn) { - struct fuse *f = (struct fuse *)data; - struct fuse_context_i *c = fuse_get_context_internal(); - - memset(c,0,sizeof(*c)); - c->ctx.fuse = f; - f->fs->op.init(conn); + f.ops.init(conn); } static void fuse_lib_destroy(void *data) { - struct fuse *f = (struct fuse *)data; - struct fuse_context_i *c = fuse_get_context_internal(); - - memset(c,0,sizeof(*c)); - c->ctx.fuse = f; - f->fs->op.destroy(); - free(f->fs); - f->fs = NULL; + f.ops.destroy(); } static void -fuse_lib_lookup(fuse_req_t req, +fuse_lib_lookup(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; uint64_t nodeid; char *fusepath; const char *name; - struct fuse *f; node_t *dot = NULL; struct fuse_entry_param e = {0}; name = (const char*)fuse_hdr_arg(hdr_); nodeid = hdr_->nodeid; - f = req_fuse_prepare(req); if(name[0] == '.') { if(name[1] == '\0') { name = NULL; - mutex_lock(&f->lock); - dot = get_node_nocheck(f,nodeid); + mutex_lock(&f.lock); + dot = get_node_nocheck(nodeid); if(dot == NULL) { - mutex_unlock(&f->lock); - reply_entry(req,&e,-ESTALE); + mutex_unlock(&f.lock); + reply_entry(req_,&e,-ESTALE); return; } dot->refctr++; - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); } else if((name[1] == '.') && (name[2] == '\0')) { if(nodeid == 1) { - reply_entry(req,&e,-ENOENT); + reply_entry(req_,&e,-ENOENT); return; } name = NULL; - mutex_lock(&f->lock); - nodeid = get_node(f,nodeid)->parent->nodeid; - mutex_unlock(&f->lock); + mutex_lock(&f.lock); + nodeid = get_node(nodeid)->parent->nodeid; + mutex_unlock(&f.lock); } } - err = get_path_name(f,nodeid,name,&fusepath); + err = get_path_name(nodeid,name,&fusepath); if(!err) { - err = lookup_path(f,nodeid,name,fusepath,&e,NULL); + err = lookup_path(req_,nodeid,name,fusepath,&e,NULL); if(err == -ENOENT) { e.ino = 0; err = 0; } - free_path(f,nodeid,fusepath); + free_path(nodeid,fusepath); } if(dot) { - mutex_lock(&f->lock); - unref_node(f,dot); - mutex_unlock(&f->lock); + mutex_lock(&f.lock); + unref_node(dot); + mutex_unlock(&f.lock); } - reply_entry(req,&e,err); + reply_entry(req_,&e,err); } static void -fuse_lib_lseek(fuse_req_t req_, +fuse_lib_lseek(fuse_req_t *req_, struct fuse_in_header *hdr_) { fuse_reply_err(req_,ENOSYS); @@ -1637,60 +1466,53 @@ fuse_lib_lseek(fuse_req_t req_, static void -fuse_lib_forget(fuse_req_t req, +fuse_lib_forget(fuse_req_t *req_, struct fuse_in_header *hdr_) { - struct fuse *f; struct fuse_forget_in *arg; - f = req_fuse(req); arg = (fuse_forget_in*)fuse_hdr_arg(hdr_); - forget_node(f,hdr_->nodeid,arg->nlookup); + forget_node(hdr_->nodeid,arg->nlookup); - fuse_reply_none(req); + fuse_reply_none(req_); } static void -fuse_lib_forget_multi(fuse_req_t req, +fuse_lib_forget_multi(fuse_req_t *req_, struct fuse_in_header *hdr_) { - struct fuse *f; struct fuse_batch_forget_in *arg; struct fuse_forget_one *entry; - f = req_fuse(req); arg = (fuse_batch_forget_in*)fuse_hdr_arg(hdr_); entry = (fuse_forget_one*)PARAM(arg); for(uint32_t i = 0; i < arg->count; i++) { - forget_node(f, - entry[i].nodeid, - entry[i].nlookup); + forget_node(entry[i].nodeid, + entry[i].nlookup); } - fuse_reply_none(req); + fuse_reply_none(req_); } static void -fuse_lib_getattr(fuse_req_t req, +fuse_lib_getattr(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; uint64_t fh; - struct fuse *f; struct stat buf; node_t *node; fuse_timeouts_t timeout; const struct fuse_getattr_in *arg; arg = (fuse_getattr_in*)fuse_hdr_arg(hdr_); - f = req_fuse_prepare(req); fh = 0; if(arg->getattr_flags & FUSE_GETATTR_FH) @@ -1702,7 +1524,7 @@ fuse_lib_getattr(fuse_req_t req, fusepath = NULL; if(fh == 0) { - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(err == -ESTALE) // unlinked but open err = 0; } @@ -1710,32 +1532,31 @@ fuse_lib_getattr(fuse_req_t req, if(!err) { err = ((fusepath != NULL) ? - f->fs->op.getattr(&fusepath[1],&buf,&timeout) : - f->fs->op.fgetattr(fh,&buf,&timeout)); + f.ops.getattr(&req_->ctx,&fusepath[1],&buf,&timeout) : + f.ops.fgetattr(&req_->ctx,fh,&buf,&timeout)); - free_path(f,hdr_->nodeid,fusepath); + free_path(hdr_->nodeid,fusepath); } if(!err) { - mutex_lock(&f->lock); - node = get_node(f,hdr_->nodeid); + mutex_lock(&f.lock); + node = get_node(hdr_->nodeid); update_stat(node,&buf); - mutex_unlock(&f->lock); - set_stat(f,hdr_->nodeid,&buf); - fuse_reply_attr(req,&buf,timeout.attr); + mutex_unlock(&f.lock); + set_stat(hdr_->nodeid,&buf); + fuse_reply_attr(req_,&buf,timeout.attr); } else { - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } } static void -fuse_lib_statx_path(fuse_req_t req_, +fuse_lib_statx_path(fuse_req_t *req_, struct fuse_in_header *hdr_, - struct fuse *f_, fuse_statx_in *inarg_) { int err; @@ -1744,20 +1565,21 @@ fuse_lib_statx_path(fuse_req_t req_, fuse_timeouts_t timeouts{}; // TODO: if node unlinked... but FUSE may not send it - err = get_path(f_,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(err) { fuse_reply_err(req_,err); return; } - err = f_->fs->op.statx(&fusepath[1], - inarg_->sx_flags, - inarg_->sx_mask, - &st, - &timeouts); + err = f.ops.statx(&req_->ctx, + &fusepath[1], + inarg_->sx_flags, + inarg_->sx_mask, + &st, + &timeouts); - free_path(f_,hdr_->nodeid,fusepath); + free_path(hdr_->nodeid,fusepath); if(err) fuse_reply_err(req_,err); @@ -1767,20 +1589,20 @@ fuse_lib_statx_path(fuse_req_t req_, static void -fuse_lib_statx_fh(fuse_req_t req_, +fuse_lib_statx_fh(fuse_req_t *req_, struct fuse_in_header *hdr_, - struct fuse *f_, - fuse_statx_in *inarg_) + fuse_statx_in *inarg_) { int err; struct fuse_statx st{}; fuse_timeouts_t timeouts{}; - err = f_->fs->op.statx_fh(inarg_->fh, - inarg_->sx_flags, - inarg_->sx_mask, - &st, - &timeouts); + err = f.ops.statx_fh(&req_->ctx, + inarg_->fh, + inarg_->sx_flags, + inarg_->sx_mask, + &st, + &timeouts); if(err) fuse_reply_err(req_,err); @@ -1790,27 +1612,25 @@ fuse_lib_statx_fh(fuse_req_t req_, static void -fuse_lib_statx(fuse_req_t req_, +fuse_lib_statx(fuse_req_t *req_, struct fuse_in_header *hdr_) { - struct fuse *f = req_fuse_prepare(req_); fuse_statx_in *inarg; inarg = (fuse_statx_in*)fuse_hdr_arg(hdr_); if(inarg->getattr_flags & FUSE_GETATTR_FH) - fuse_lib_statx_fh(req_,hdr_,f,inarg); + fuse_lib_statx_fh(req_,hdr_,inarg); else - fuse_lib_statx_path(req_,hdr_,f,inarg); + fuse_lib_statx_path(req_,hdr_,inarg); } static void -fuse_lib_setattr(fuse_req_t req, +fuse_lib_setattr(fuse_req_t *req_, struct fuse_in_header *hdr_) { uint64_t fh; - struct fuse *f = req_fuse_prepare(req); struct stat stbuf = {0}; char *fusepath; int err; @@ -1827,7 +1647,7 @@ fuse_lib_setattr(fuse_req_t req, fusepath = NULL; if(fh == 0) { - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(err == -ESTALE) err = 0; } @@ -1837,8 +1657,8 @@ fuse_lib_setattr(fuse_req_t req, err = 0; if(!err && (arg->valid & FATTR_MODE)) err = ((fusepath != NULL) ? - f->fs->op.chmod(&fusepath[1],arg->mode) : - f->fs->op.fchmod(fh,arg->mode)); + f.ops.chmod(&req_->ctx,&fusepath[1],arg->mode) : + f.ops.fchmod(&req_->ctx,fh,arg->mode)); if(!err && (arg->valid & (FATTR_UID | FATTR_GID))) { @@ -1846,14 +1666,14 @@ fuse_lib_setattr(fuse_req_t req, gid_t gid = ((arg->valid & FATTR_GID) ? arg->gid : (gid_t)-1); err = ((fusepath != NULL) ? - f->fs->op.chown(&fusepath[1],uid,gid) : - f->fs->op.fchown(fh,uid,gid)); + f.ops.chown(&req_->ctx,&fusepath[1],uid,gid) : + f.ops.fchown(&req_->ctx,fh,uid,gid)); } if(!err && (arg->valid & FATTR_SIZE)) err = ((fusepath != NULL) ? - f->fs->op.truncate(&fusepath[1],arg->size) : - f->fs->op.ftruncate(fh,arg->size)); + f.ops.truncate(&req_->ctx,&fusepath[1],arg->size) : + f.ops.ftruncate(&req_->ctx,fh,arg->size)); if(!err && (arg->valid & (FATTR_ATIME | FATTR_MTIME))) { @@ -1875,119 +1695,116 @@ fuse_lib_setattr(fuse_req_t req, tv[1] = (struct timespec){ static_cast(arg->mtime), arg->mtimensec }; err = ((fusepath != NULL) ? - f->fs->op.utimens(&fusepath[1],tv) : - f->fs->op.futimens(fh,tv)); + f.ops.utimens(&req_->ctx,&fusepath[1],tv) : + f.ops.futimens(&req_->ctx,fh,tv)); } else if(!err && ((arg->valid & (FATTR_ATIME|FATTR_MTIME)) == (FATTR_ATIME|FATTR_MTIME))) - { - struct timespec tv[2]; - tv[0].tv_sec = arg->atime; - tv[0].tv_nsec = arg->atimensec; - tv[1].tv_sec = arg->mtime; - tv[1].tv_nsec = arg->mtimensec; - err = ((fusepath != NULL) ? - f->fs->op.utimens(&fusepath[1],tv) : - f->fs->op.futimens(fh,tv)); - } + { + struct timespec tv[2]; + tv[0].tv_sec = arg->atime; + tv[0].tv_nsec = arg->atimensec; + tv[1].tv_sec = arg->mtime; + tv[1].tv_nsec = arg->mtimensec; + err = ((fusepath != NULL) ? + f.ops.utimens(&req_->ctx,&fusepath[1],tv) : + f.ops.futimens(&req_->ctx,fh,tv)); + } if(!err) err = ((fusepath != NULL) ? - f->fs->op.getattr(&fusepath[1],&stbuf,&timeout) : - f->fs->op.fgetattr(fh,&stbuf,&timeout)); + f.ops.getattr(&req_->ctx,&fusepath[1],&stbuf,&timeout) : + f.ops.fgetattr(&req_->ctx,fh,&stbuf,&timeout)); - free_path(f,hdr_->nodeid,fusepath); + free_path(hdr_->nodeid,fusepath); } if(!err) { - mutex_lock(&f->lock); - update_stat(get_node(f,hdr_->nodeid),&stbuf); - mutex_unlock(&f->lock); - set_stat(f,hdr_->nodeid,&stbuf); - fuse_reply_attr(req,&stbuf,timeout.attr); + mutex_lock(&f.lock); + update_stat(get_node(hdr_->nodeid),&stbuf); + mutex_unlock(&f.lock); + set_stat(hdr_->nodeid,&stbuf); + fuse_reply_attr(req_,&stbuf,timeout.attr); } else { - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } } static void -fuse_lib_access(fuse_req_t req, +fuse_lib_access(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; struct fuse_access_in *arg; arg = (fuse_access_in*)fuse_hdr_arg(hdr_); - f = req_fuse_prepare(req); - - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.access(&fusepath[1],arg->mask); - free_path(f,hdr_->nodeid,fusepath); + err = f.ops.access(&req_->ctx, + &fusepath[1], + arg->mask); + free_path(hdr_->nodeid,fusepath); } - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_readlink(fuse_req_t req, +fuse_lib_readlink(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; char linkname[PATH_MAX + 1]; - f = req_fuse_prepare(req); - - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.readlink(&fusepath[1],linkname,sizeof(linkname)); - free_path(f,hdr_->nodeid,fusepath); + err = f.ops.readlink(&req_->ctx, + &fusepath[1], + linkname, + sizeof(linkname)); + free_path(hdr_->nodeid,fusepath); } if(!err) { linkname[PATH_MAX] = '\0'; - fuse_reply_readlink(req,linkname); + fuse_reply_readlink(req_,linkname); } else { - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } } static void -fuse_lib_mknod(fuse_req_t req, +fuse_lib_mknod(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; const char* name; struct fuse_entry_param e; struct fuse_mknod_in *arg; arg = (fuse_mknod_in*)fuse_hdr_arg(hdr_); name = (const char*)PARAM(arg); - if(req->f->conn.proto_minor >= 12) - req->ctx.umask = arg->umask; + + if(req_->f->conn.proto_minor >= 12) + req_->ctx.umask = arg->umask; else name = (char*)arg + FUSE_COMPAT_MKNOD_IN_SIZE; - f = req_fuse_prepare(req); - - err = get_path_name(f,hdr_->nodeid,name,&fusepath); + err = get_path_name(hdr_->nodeid,name,&fusepath); if(!err) { err = -ENOSYS; @@ -1997,124 +1814,126 @@ fuse_lib_mknod(fuse_req_t req, memset(&fi,0,sizeof(fi)); fi.flags = O_CREAT | O_EXCL | O_WRONLY; - err = f->fs->op.create(&fusepath[1],arg->mode,&fi); + err = f.ops.create(&req_->ctx, + &fusepath[1], + arg->mode, + &fi); if(!err) { - err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,&fi); - f->fs->op.release(&fi); + err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,&fi); + f.ops.release(&req_->ctx, + &fi); } } if(err == -ENOSYS) { - err = f->fs->op.mknod(&fusepath[1],arg->mode,arg->rdev); + err = f.ops.mknod(&req_->ctx, + &fusepath[1], + arg->mode, + arg->rdev); if(!err) - err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,NULL); + err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,NULL); } - free_path(f,hdr_->nodeid,fusepath); + free_path(hdr_->nodeid,fusepath); } - reply_entry(req,&e,err); + reply_entry(req_,&e,err); } static void -fuse_lib_mkdir(fuse_req_t req, +fuse_lib_mkdir(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; const char *name; struct fuse_entry_param e; struct fuse_mkdir_in *arg; arg = (fuse_mkdir_in*)fuse_hdr_arg(hdr_); name = (const char*)PARAM(arg); - if(req->f->conn.proto_minor >= 12) - req->ctx.umask = arg->umask; - - f = req_fuse_prepare(req); + if(req_->f->conn.proto_minor >= 12) + req_->ctx.umask = arg->umask; - err = get_path_name(f,hdr_->nodeid,name,&fusepath); + err = get_path_name(hdr_->nodeid,name,&fusepath); if(!err) { - err = f->fs->op.mkdir(&fusepath[1],arg->mode); + err = f.ops.mkdir(&req_->ctx, + &fusepath[1], + arg->mode); if(!err) - err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,NULL); - free_path(f,hdr_->nodeid,fusepath); + err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,NULL); + free_path(hdr_->nodeid,fusepath); } - reply_entry(req,&e,err); + reply_entry(req_,&e,err); } static void -fuse_lib_unlink(fuse_req_t req, +fuse_lib_unlink(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; const char *name; node_t *wnode; name = (const char*)PARAM(hdr_); - f = req_fuse_prepare(req); - err = get_path_wrlock(f,hdr_->nodeid,name,&fusepath,&wnode); + err = get_path_wrlock(hdr_->nodeid,name,&fusepath,&wnode); if(!err) { if(node_open(wnode)) - fuse_get_context()->nodeid = wnode->nodeid; + req_->ctx.nodeid = wnode->nodeid; - err = f->fs->op.unlink(&fusepath[1]); + err = f.ops.unlink(&req_->ctx, + &fusepath[1]); if(!err) - remove_node(f,hdr_->nodeid,name); + remove_node(hdr_->nodeid,name); - free_path_wrlock(f,hdr_->nodeid,wnode,fusepath); + free_path_wrlock(hdr_->nodeid,wnode,fusepath); } - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_rmdir(fuse_req_t req, +fuse_lib_rmdir(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; const char *name; node_t *wnode; name = (const char*)PARAM(hdr_); - f = req_fuse_prepare(req); - - err = get_path_wrlock(f,hdr_->nodeid,name,&fusepath,&wnode); + err = get_path_wrlock(hdr_->nodeid,name,&fusepath,&wnode); if(!err) { - err = f->fs->op.rmdir(&fusepath[1]); + err = f.ops.rmdir(&req_->ctx, + &fusepath[1]); if(!err) - remove_node(f,hdr_->nodeid,name); - free_path_wrlock(f,hdr_->nodeid,wnode,fusepath); + remove_node(hdr_->nodeid,name); + free_path_wrlock(hdr_->nodeid,wnode,fusepath); } - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_symlink(fuse_req_t req_, +fuse_lib_symlink(fuse_req_t *req_, struct fuse_in_header *hdr_) { int rv; char *fusepath; - struct fuse *f; const char *name; const char *linkname; struct fuse_entry_param e = {0}; @@ -2122,15 +1941,17 @@ fuse_lib_symlink(fuse_req_t req_, name = (const char*)fuse_hdr_arg(hdr_); linkname = (name + strlen(name) + 1); - f = req_fuse_prepare(req_); - - rv = get_path_name(f,hdr_->nodeid,name,&fusepath); + rv = get_path_name(hdr_->nodeid,name,&fusepath); if(rv == 0) { - rv = f->fs->op.symlink(linkname,&fusepath[1],&e.attr,&e.timeout); + rv = f.ops.symlink(&req_->ctx, + linkname, + &fusepath[1], + &e.attr, + &e.timeout); if(rv == 0) - rv = set_path_info(f,hdr_->nodeid,name,&e); - free_path(f,hdr_->nodeid,fusepath); + rv = set_path_info(hdr_->nodeid,name,&e); + free_path(hdr_->nodeid,fusepath); } reply_entry(req_,&e,rv); @@ -2138,11 +1959,10 @@ fuse_lib_symlink(fuse_req_t req_, static void -fuse_lib_rename(fuse_req_t req, +fuse_lib_rename(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; - struct fuse *f; char *oldpath; char *newpath; const char *oldname; @@ -2155,9 +1975,7 @@ fuse_lib_rename(fuse_req_t req, oldname = (const char*)PARAM(arg); newname = (oldname + strlen(oldname) + 1); - f = req_fuse_prepare(req); - err = get_path2(f, - hdr_->nodeid, + err = get_path2(hdr_->nodeid, oldname, arg->newdir, newname, @@ -2168,19 +1986,21 @@ fuse_lib_rename(fuse_req_t req, if(!err) { - err = f->fs->op.rename(&oldpath[1],&newpath[1]); + err = f.ops.rename(&req_->ctx, + &oldpath[1], + &newpath[1]); if(!err) - err = rename_node(f,hdr_->nodeid,oldname,arg->newdir,newname); + err = rename_node(hdr_->nodeid,oldname,arg->newdir,newname); - free_path2(f,hdr_->nodeid,arg->newdir,wnode1,wnode2,oldpath,newpath); + free_path2(hdr_->nodeid,arg->newdir,wnode1,wnode2,oldpath,newpath); } - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_rename2(fuse_req_t req_, +fuse_lib_rename2(fuse_req_t *req_, struct fuse_in_header *hdr_) { fuse_reply_err(req_,ENOSYS); @@ -2188,7 +2008,7 @@ fuse_lib_rename2(fuse_req_t req_, static void -fuse_lib_retrieve_reply(fuse_req_t req_, +fuse_lib_retrieve_reply(fuse_req_t *req_, void *cookie_, uint64_t ino_, off_t offset_) @@ -2198,24 +2018,20 @@ fuse_lib_retrieve_reply(fuse_req_t req_, static void -fuse_lib_link(fuse_req_t req, +fuse_lib_link(fuse_req_t *req_, struct fuse_in_header *hdr_) { int rv; char *oldpath; char *newpath; - struct fuse *f; const char *newname; struct fuse_link_in *arg; struct fuse_entry_param e = {0}; - arg = (fuse_link_in*)fuse_hdr_arg(hdr_); + arg = (fuse_link_in*)fuse_hdr_arg(hdr_); newname = (const char*)PARAM(arg); - f = req_fuse_prepare(req); - - rv = get_path2(f, - arg->oldnodeid, + rv = get_path2(arg->oldnodeid, NULL, hdr_->nodeid, newname, @@ -2225,114 +2041,119 @@ fuse_lib_link(fuse_req_t req, NULL); if(!rv) { - rv = f->fs->op.link(&oldpath[1],&newpath[1],&e.attr,&e.timeout); + rv = f.ops.link(&req_->ctx, + &oldpath[1], + &newpath[1], + &e.attr, + &e.timeout); if(rv == 0) - rv = set_path_info(f,hdr_->nodeid,newname,&e); - free_path2(f,arg->oldnodeid,hdr_->nodeid,NULL,NULL,oldpath,newpath); + rv = set_path_info(hdr_->nodeid,newname,&e); + free_path2(arg->oldnodeid,hdr_->nodeid,NULL,NULL,oldpath,newpath); } - reply_entry(req,&e,rv); + reply_entry(req_,&e,rv); } static void -fuse_do_release(struct fuse *f, - uint64_t ino, - fuse_file_info_t *fi) +fuse_do_release(fuse_req_ctx_t *req_ctx_, + uint64_t ino_, + fuse_file_info_t *ffi_) { - node_t *node; - - f->fs->op.release(fi); + f.ops.release(req_ctx_, + ffi_); - mutex_lock(&f->lock); + mutex_lock(&f.lock); { - node = get_node(f,ino); + node_t *node; + + node = get_node(ino_); assert(node->open_count > 0); node->open_count--; } - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); } static void -fuse_lib_create(fuse_req_t req, +fuse_lib_create(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; const char *name; uint64_t new_nodeid; fuse_file_info_t ffi = {0}; struct fuse_entry_param e; struct fuse_create_in *arg; - arg = (fuse_create_in*)fuse_hdr_arg(hdr_); - name = (const char*)PARAM(arg); + arg = (fuse_create_in*)fuse_hdr_arg(hdr_); + name = (const char*)PARAM(arg); ffi.flags = arg->flags; - if(req->f->conn.proto_minor >= 12) - req->ctx.umask = arg->umask; + if(req_->f->conn.proto_minor >= 12) + req_->ctx.umask = arg->umask; else - name = (char*)arg + sizeof(struct fuse_open_in); - - f = req_fuse_prepare(req); + name = ((char*)arg + sizeof(struct fuse_open_in)); // opportunistically allocate a node so we have a new nodeid for // later in the actual create. Added for use with passthrough. { - node_t *node = find_node(f,hdr_->nodeid,name); + node_t *node = find_node(hdr_->nodeid,name); new_nodeid = node->nodeid; - fuse_get_context()->nodeid = new_nodeid; + req_->ctx.nodeid = new_nodeid; } - err = get_path_name(f,hdr_->nodeid,name,&fusepath); + err = get_path_name(hdr_->nodeid,name,&fusepath); if(!err) { - err = f->fs->op.create(&fusepath[1],arg->mode,&ffi); + err = f.ops.create(&req_->ctx, + &fusepath[1], + arg->mode, + &ffi); if(!err) { - err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,&ffi); + err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,&ffi); if(err) { - f->fs->op.release(&ffi); + f.ops.release(&req_->ctx,&ffi); } else if(!S_ISREG(e.attr.st_mode)) { err = -EIO; - f->fs->op.release(&ffi); - forget_node(f,e.ino,1); + f.ops.release(&req_->ctx,&ffi); + forget_node(e.ino,1); } } } if(!err) { - mutex_lock(&f->lock); - get_node(f,e.ino)->open_count++; - mutex_unlock(&f->lock); + mutex_lock(&f.lock); + get_node(e.ino)->open_count++; + mutex_unlock(&f.lock); - if(fuse_reply_create(req,&e,&ffi) == -ENOENT) + if(fuse_reply_create(req_,&e,&ffi) == -ENOENT) { /* The open syscall was interrupted,so it must be cancelled */ - fuse_do_release(f,e.ino,&ffi); - forget_node(f,e.ino,1); + fuse_do_release(&req_->ctx,e.ino,&ffi); + forget_node(e.ino,1); } } else { - forget_node(f,new_nodeid,1); - fuse_reply_err(req,err); + forget_node(new_nodeid,1); + fuse_reply_err(req_,err); } - free_path(f,hdr_->nodeid,fusepath); + free_path(hdr_->nodeid,fusepath); } static void -open_auto_cache(struct fuse *f, +open_auto_cache(fuse_req_ctx_t *req_ctx_, uint64_t ino, const char *path, fuse_file_info_t *fi) @@ -2340,17 +2161,20 @@ open_auto_cache(struct fuse *f, node_t *node; fuse_timeouts_t timeout; - mutex_lock(&f->lock); + mutex_lock(&f.lock); - node = get_node(f,ino); + node = get_node(ino); if(node->is_stat_cache_valid) { int err; struct stat stbuf; - mutex_unlock(&f->lock); - err = f->fs->op.fgetattr(fi->fh,&stbuf,&timeout); - mutex_lock(&f->lock); + mutex_unlock(&f.lock); + err = f.ops.fgetattr(req_ctx_, + fi->fh, + &stbuf, + &timeout); + mutex_lock(&f.lock); if(!err) update_stat(node,&stbuf); @@ -2363,102 +2187,101 @@ open_auto_cache(struct fuse *f, node->is_stat_cache_valid = 1; - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); } static void -fuse_lib_open(fuse_req_t req, +fuse_lib_open(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; fuse_file_info_t ffi = {0}; struct fuse_open_in *arg; - arg = (fuse_open_in*)fuse_hdr_arg(hdr_); + arg = (fuse_open_in*)fuse_hdr_arg(hdr_); ffi.flags = arg->flags; - f = req_fuse_prepare(req); - - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.open(&fusepath[1],&ffi); + err = f.ops.open(&req_->ctx, + &fusepath[1], + &ffi); if(!err) { if(ffi.auto_cache && (ffi.passthrough == false)) - open_auto_cache(f,hdr_->nodeid,fusepath,&ffi); + open_auto_cache(&req_->ctx,hdr_->nodeid,fusepath,&ffi); } } if(!err) { - mutex_lock(&f->lock); - get_node(f,hdr_->nodeid)->open_count++; - mutex_unlock(&f->lock); + mutex_lock(&f.lock); + get_node(hdr_->nodeid)->open_count++; + mutex_unlock(&f.lock); /* The open syscall was interrupted,so it must be cancelled */ - if(fuse_reply_open(req,&ffi) == -ENOENT) - fuse_do_release(f,hdr_->nodeid,&ffi); + if(fuse_reply_open(req_,&ffi) == -ENOENT) + fuse_do_release(&req_->ctx,hdr_->nodeid,&ffi); } else { - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } - free_path(f,hdr_->nodeid,fusepath); + free_path(hdr_->nodeid,fusepath); } static void -fuse_lib_read(fuse_req_t req, +fuse_lib_read(fuse_req_t *req_, struct fuse_in_header *hdr_) { int res; - struct fuse *f; fuse_file_info_t ffi = {0}; struct fuse_read_in *arg; fuse_msgbuf_t *msgbuf; arg = (fuse_read_in*)fuse_hdr_arg(hdr_); ffi.fh = arg->fh; - if(req->f->conn.proto_minor >= 9) + if(req_->f->conn.proto_minor >= 9) { ffi.flags = arg->flags; ffi.lock_owner = arg->lock_owner; } - f = req_fuse_prepare(req); - msgbuf = msgbuf_alloc_page_aligned(); - res = f->fs->op.read(&ffi,msgbuf->mem,arg->size,arg->offset); + res = f.ops.read(&req_->ctx, + &ffi, + msgbuf->mem, + arg->size, + arg->offset); if(res >= 0) - fuse_reply_data(req,msgbuf->mem,res); + fuse_reply_data(req_,msgbuf->mem,res); else - fuse_reply_err(req,res); + fuse_reply_err(req_,res); msgbuf_free(msgbuf); } static void -fuse_lib_write(fuse_req_t req, +fuse_lib_write(fuse_req_t *req_, struct fuse_in_header *hdr_) { int res; char *data; - struct fuse *f; fuse_file_info_t ffi = {0}; struct fuse_write_in *arg; - arg = (fuse_write_in*)fuse_hdr_arg(hdr_); - ffi.fh = arg->fh; + arg = (fuse_write_in*)fuse_hdr_arg(hdr_); + ffi.fh = arg->fh; ffi.writepage = !!(arg->write_flags & 1); - if(req->f->conn.proto_minor < 9) + if(req_->f->conn.proto_minor < 9) { data = ((char*)arg) + FUSE_COMPAT_WRITE_IN_SIZE; } @@ -2469,34 +2292,37 @@ fuse_lib_write(fuse_req_t req, data = (char*)PARAM(arg); } - f = req_fuse_prepare(req); - - res = f->fs->op.write(&ffi,data,arg->size,arg->offset); - free_path(f,hdr_->nodeid,NULL); + res = f.ops.write(&req_->ctx, + &ffi, + data, + arg->size, + arg->offset); + free_path(hdr_->nodeid,NULL); if(res >= 0) - fuse_reply_write(req,res); + fuse_reply_write(req_,res); else - fuse_reply_err(req,res); + fuse_reply_err(req_,res); } static void -fuse_lib_fsync(fuse_req_t req, +fuse_lib_fsync(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; - struct fuse *f; + int is_datasync; struct fuse_fsync_in *arg; arg = (fuse_fsync_in*)fuse_hdr_arg(hdr_); - f = req_fuse_prepare(req); + is_datasync = !!(arg->fsync_flags & FUSE_FSYNC_FDATASYNC); - err = f->fs->op.fsync(arg->fh, - !!(arg->fsync_flags & 1)); + err = f.ops.fsync(&req_->ctx, + arg->fh, + is_datasync); - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static @@ -2512,7 +2338,7 @@ get_dirhandle(const fuse_file_info_t *llfi, static void -fuse_lib_opendir(fuse_req_t req, +fuse_lib_opendir(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; @@ -2520,18 +2346,15 @@ fuse_lib_opendir(fuse_req_t req, struct fuse_dh *dh; fuse_file_info_t llffi = {0}; fuse_file_info_t ffi = {0}; - struct fuse *f; struct fuse_open_in *arg; arg = (fuse_open_in*)fuse_hdr_arg(hdr_); llffi.flags = arg->flags; - f = req_fuse_prepare(req); - dh = (struct fuse_dh *)calloc(1,sizeof(struct fuse_dh)); if(dh == NULL) { - fuse_reply_err(req,ENOMEM); + fuse_reply_err(req_,ENOMEM); return; } @@ -2541,10 +2364,12 @@ fuse_lib_opendir(fuse_req_t req, llffi.fh = (uintptr_t)dh; ffi.flags = llffi.flags; - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.opendir(&fusepath[1],&ffi); + err = f.ops.opendir(&req_->ctx, + &fusepath[1], + &ffi); dh->fh = ffi.fh; llffi.keep_cache = ffi.keep_cache; llffi.cache_readdir = ffi.cache_readdir; @@ -2552,23 +2377,24 @@ fuse_lib_opendir(fuse_req_t req, if(!err) { - if(fuse_reply_open(req,&llffi) == -ENOENT) + if(fuse_reply_open(req_,&llffi) == -ENOENT) { /* The opendir syscall was interrupted,so it must be cancelled */ - f->fs->op.releasedir(&ffi); + f.ops.releasedir(&req_->ctx, + &ffi); mutex_destroy(&dh->lock); free(dh); } } else { - fuse_reply_err(req,err); + fuse_reply_err(req_,err); mutex_destroy(&dh->lock); free(dh); } - free_path(f,hdr_->nodeid,fusepath); + free_path(hdr_->nodeid,fusepath); } static @@ -2598,23 +2424,21 @@ readdir_buf(fuse_dirents_t *d_, static void -fuse_lib_readdir(fuse_req_t req_, +fuse_lib_readdir(fuse_req_t *req_, struct fuse_in_header *hdr_) { int rv; size_t size; - struct fuse *f; fuse_dirents_t *d; struct fuse_dh *dh; fuse_file_info_t ffi = {0}; fuse_file_info_t llffi = {0}; struct fuse_read_in *arg; - arg = (fuse_read_in*)fuse_hdr_arg(hdr_); - size = arg->size; + arg = (fuse_read_in*)fuse_hdr_arg(hdr_); + size = arg->size; llffi.fh = arg->fh; - f = req_fuse_prepare(req_); dh = get_dirhandle(&llffi,&ffi); d = &dh->d; @@ -2622,7 +2446,9 @@ fuse_lib_readdir(fuse_req_t req_, rv = 0; if((arg->offset == 0) || (kv_size(d->data) == 0)) - rv = f->fs->op.readdir(&ffi,d); + rv = f.ops.readdir(&req_->ctx, + &ffi, + d); if(rv) { @@ -2642,23 +2468,21 @@ fuse_lib_readdir(fuse_req_t req_, static void -fuse_lib_readdir_plus(fuse_req_t req_, +fuse_lib_readdir_plus(fuse_req_t *req_, struct fuse_in_header *hdr_) { int rv; size_t size; - struct fuse *f; fuse_dirents_t *d; struct fuse_dh *dh; fuse_file_info_t ffi = {0}; fuse_file_info_t llffi = {0}; struct fuse_read_in *arg; - arg = (fuse_read_in*)fuse_hdr_arg(hdr_); - size = arg->size; + arg = (fuse_read_in*)fuse_hdr_arg(hdr_); + size = arg->size; llffi.fh = arg->fh; - f = req_fuse_prepare(req_); dh = get_dirhandle(&llffi,&ffi); d = &dh->d; @@ -2666,7 +2490,9 @@ fuse_lib_readdir_plus(fuse_req_t req_, rv = 0; if((arg->offset == 0) || (kv_size(d->data) == 0)) - rv = f->fs->op.readdir_plus(&ffi,d); + rv = f.ops.readdir_plus(&req_->ctx, + &ffi, + d); if(rv) { @@ -2686,10 +2512,9 @@ fuse_lib_readdir_plus(fuse_req_t req_, static void -fuse_lib_releasedir(fuse_req_t req_, +fuse_lib_releasedir(fuse_req_t *req_, struct fuse_in_header *hdr_) { - struct fuse *f; struct fuse_dh *dh; fuse_file_info_t ffi; fuse_file_info_t llffi = {0}; @@ -2699,10 +2524,10 @@ fuse_lib_releasedir(fuse_req_t req_, llffi.fh = arg->fh; llffi.flags = arg->flags; - f = req_fuse_prepare(req_); dh = get_dirhandle(&llffi,&ffi); - f->fs->op.releasedir(&ffi); + f.ops.releasedir(&req_->ctx, + &ffi); /* Done to keep race condition between last readdir reply and the unlock */ mutex_lock(&dh->lock); @@ -2715,106 +2540,111 @@ fuse_lib_releasedir(fuse_req_t req_, static void -fuse_lib_fsyncdir(fuse_req_t req, +fuse_lib_fsyncdir(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; - struct fuse *f; + int is_datasync; fuse_file_info_t ffi; fuse_file_info_t llffi = {0}; struct fuse_fsync_in *arg; - arg = (fuse_fsync_in*)fuse_hdr_arg(hdr_); - llffi.fh = arg->fh; - - f = req_fuse_prepare(req); + arg = (fuse_fsync_in*)fuse_hdr_arg(hdr_); + is_datasync = !!(arg->fsync_flags & FUSE_FSYNC_FDATASYNC); + llffi.fh = arg->fh; get_dirhandle(&llffi,&ffi); - err = f->fs->op.fsyncdir(&ffi, - !!(arg->fsync_flags & FUSE_FSYNC_FDATASYNC)); + err = f.ops.fsyncdir(&req_->ctx, + &ffi, + is_datasync); - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_statfs(fuse_req_t req, +fuse_lib_statfs(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err = 0; char *fusepath; - struct fuse *f; struct statvfs buf = {0}; - f = req_fuse_prepare(req); - fusepath = NULL; if(hdr_->nodeid) - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.statfs(fusepath ? &fusepath[1] : "",&buf); - free_path(f,hdr_->nodeid,fusepath); + err = f.ops.statfs(&req_->ctx, + fusepath ? &fusepath[1] : "", + &buf); + free_path(hdr_->nodeid,fusepath); } if(!err) - fuse_reply_statfs(req,&buf); + fuse_reply_statfs(req_,&buf); else - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_setxattr(fuse_req_t req, +fuse_lib_setxattr(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; char *fusepath; const char *name; const char *value; - struct fuse *f; struct fuse_setxattr_in *arg; - arg = (fuse_setxattr_in*)fuse_hdr_arg(hdr_); - if((req->f->conn.capable & FUSE_SETXATTR_EXT) && (req->f->conn.want & FUSE_SETXATTR_EXT)) + arg = (fuse_setxattr_in*)fuse_hdr_arg(hdr_); + if((req_->f->conn.capable & FUSE_SETXATTR_EXT) && + (req_->f->conn.want & FUSE_SETXATTR_EXT)) name = (const char*)PARAM(arg); else name = (((char*)arg) + FUSE_COMPAT_SETXATTR_IN_SIZE); value = (name + strlen(name) + 1); - f = req_fuse_prepare(req); - - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.setxattr(&fusepath[1],name,value,arg->size,arg->flags); - free_path(f,hdr_->nodeid,fusepath); + err = f.ops.setxattr(&req_->ctx, + &fusepath[1], + name, + value, + arg->size, + arg->flags); + free_path(hdr_->nodeid,fusepath); } - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static int -common_getxattr(struct fuse *f, - fuse_req_t req, - uint64_t ino, - const char *name, - char *value, - size_t size) +common_getxattr(fuse_req_t *req_, + uint64_t ino, + const char *name, + char *value, + size_t size) { int err; char *fusepath; - err = get_path(f,ino,&fusepath); + err = get_path(ino,&fusepath); if(!err) { - err = f->fs->op.getxattr(&fusepath[1],name,value,size); + err = f.ops.getxattr(&req_->ctx, + &fusepath[1], + name, + value, + size); - free_path(f,ino,fusepath); + free_path(ino,fusepath); } return err; @@ -2822,61 +2652,60 @@ common_getxattr(struct fuse *f, static void -fuse_lib_getxattr(fuse_req_t req, +fuse_lib_getxattr(fuse_req_t *req_, struct fuse_in_header *hdr_) { int res; - struct fuse *f; const char* name; struct fuse_getxattr_in *arg; arg = (fuse_getxattr_in*)fuse_hdr_arg(hdr_); name = (const char*)PARAM(arg); - f = req_fuse_prepare(req); - if(arg->size) { char *value = (char*)malloc(arg->size); if(value == NULL) { - fuse_reply_err(req,ENOMEM); + fuse_reply_err(req_,ENOMEM); return; } - res = common_getxattr(f,req,hdr_->nodeid,name,value,arg->size); + res = common_getxattr(req_,hdr_->nodeid,name,value,arg->size); if(res > 0) - fuse_reply_buf(req,value,res); + fuse_reply_buf(req_,value,res); else - fuse_reply_err(req,res); + fuse_reply_err(req_,res); free(value); } else { - res = common_getxattr(f,req,hdr_->nodeid,name,NULL,0); + res = common_getxattr(req_,hdr_->nodeid,name,NULL,0); if(res >= 0) - fuse_reply_xattr(req,res); + fuse_reply_xattr(req_,res); else - fuse_reply_err(req,res); + fuse_reply_err(req_,res); } } static int -common_listxattr(struct fuse *f, - fuse_req_t req, - uint64_t ino, - char *list, - size_t size) +common_listxattr(fuse_req_t *req_, + uint64_t ino, + char *list, + size_t size) { int err; char *fusepath; - err = get_path(f,ino,&fusepath); + err = get_path(ino,&fusepath); if(!err) { - err = f->fs->op.listxattr(&fusepath[1],list,size); - free_path(f,ino,fusepath); + err = f.ops.listxattr(&req_->ctx, + &fusepath[1], + list, + size); + free_path(ino,fusepath); } return err; @@ -2884,74 +2713,69 @@ common_listxattr(struct fuse *f, static void -fuse_lib_listxattr(fuse_req_t req, +fuse_lib_listxattr(fuse_req_t *req_, struct fuse_in_header *hdr_) { int res; - struct fuse *f; struct fuse_getxattr_in *arg; arg = (fuse_getxattr_in*)fuse_hdr_arg(hdr_); - f = req_fuse_prepare(req); - if(arg->size) { char *list = (char*)malloc(arg->size); if(list == NULL) { - fuse_reply_err(req,ENOMEM); + fuse_reply_err(req_,ENOMEM); return; } - res = common_listxattr(f,req,hdr_->nodeid,list,arg->size); + res = common_listxattr(req_,hdr_->nodeid,list,arg->size); if(res > 0) - fuse_reply_buf(req,list,res); + fuse_reply_buf(req_,list,res); else - fuse_reply_err(req,res); + fuse_reply_err(req_,res); free(list); } else { - res = common_listxattr(f,req,hdr_->nodeid,NULL,0); + res = common_listxattr(req_,hdr_->nodeid,NULL,0); if(res >= 0) - fuse_reply_xattr(req,res); + fuse_reply_xattr(req_,res); else - fuse_reply_err(req,res); + fuse_reply_err(req_,res); } } static void -fuse_lib_removexattr(fuse_req_t req, +fuse_lib_removexattr(fuse_req_t *req_, const struct fuse_in_header *hdr_) { int err; char *fusepath; const char *name; - struct fuse *f; name = (const char*)fuse_hdr_arg(hdr_); - f = req_fuse_prepare(req); - - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.removexattr(&fusepath[1],name); - free_path(f,hdr_->nodeid,fusepath); + err = f.ops.removexattr(&req_->ctx, + &fusepath[1], + name); + free_path(hdr_->nodeid,fusepath); } - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_copy_file_range(fuse_req_t req_, +fuse_lib_copy_file_range(fuse_req_t *req_, const struct fuse_in_header *hdr_) { ssize_t rv; - struct fuse *f; fuse_file_info_t ffi_in = {0}; fuse_file_info_t ffi_out = {0}; const struct fuse_copy_file_range_in *arg; @@ -2960,14 +2784,13 @@ fuse_lib_copy_file_range(fuse_req_t req_, ffi_in.fh = arg->fh_in; ffi_out.fh = arg->fh_out; - f = req_fuse_prepare(req_); - - rv = f->fs->op.copy_file_range(&ffi_in, - arg->off_in, - &ffi_out, - arg->off_out, - arg->len, - arg->flags); + rv = f.ops.copy_file_range(&req_->ctx, + &ffi_in, + arg->off_in, + &ffi_out, + arg->off_out, + arg->len, + arg->flags); if(rv >= 0) fuse_reply_write(req_,rv); @@ -2977,7 +2800,7 @@ fuse_lib_copy_file_range(fuse_req_t req_, static void -fuse_lib_setupmapping(fuse_req_t req_, +fuse_lib_setupmapping(fuse_req_t *req_, const struct fuse_in_header *hdr_) { fuse_reply_err(req_,ENOSYS); @@ -2985,7 +2808,7 @@ fuse_lib_setupmapping(fuse_req_t req_, static void -fuse_lib_removemapping(fuse_req_t req_, +fuse_lib_removemapping(fuse_req_t *req_, const struct fuse_in_header *hdr_) { fuse_reply_err(req_,ENOSYS); @@ -2993,7 +2816,7 @@ fuse_lib_removemapping(fuse_req_t req_, static void -fuse_lib_syncfs(fuse_req_t req_, +fuse_lib_syncfs(fuse_req_t *req_, const struct fuse_in_header *hdr_) { fuse_reply_err(req_,ENOSYS); @@ -3005,12 +2828,11 @@ fuse_lib_syncfs(fuse_req_t req_, // nodeid is the base directory static void -fuse_lib_tmpfile(fuse_req_t req_, +fuse_lib_tmpfile(fuse_req_t *req_, const struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; const char *name; fuse_file_info_t ffi = {0}; struct fuse_entry_param e; @@ -3026,40 +2848,43 @@ fuse_lib_tmpfile(fuse_req_t req_, else name = (char*)arg + sizeof(struct fuse_open_in); - f = req_fuse_prepare(req_); - - err = get_path_name(f,hdr_->nodeid,name,&fusepath); + err = get_path_name(hdr_->nodeid,name,&fusepath); if(!err) { - err = f->fs->op.tmpfile(&fusepath[1],arg->mode,&ffi); + err = f.ops.tmpfile(&req_->ctx, + &fusepath[1], + arg->mode, + &ffi); if(!err) { - err = lookup_path(f,hdr_->nodeid,name,fusepath,&e,&ffi); + err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,&ffi); if(err) { - f->fs->op.release(&ffi); + f.ops.release(&req_->ctx, + &ffi); } else if(!S_ISREG(e.attr.st_mode)) { err = -EIO; - f->fs->op.release(&ffi); - forget_node(f,e.ino,1); + f.ops.release(&req_->ctx, + &ffi); + forget_node(e.ino,1); } } } if(!err) { - mutex_lock(&f->lock); - get_node(f,e.ino)->open_count++; - mutex_unlock(&f->lock); + mutex_lock(&f.lock); + get_node(e.ino)->open_count++; + mutex_unlock(&f.lock); if(fuse_reply_create(req_,&e,&ffi) == -ENOENT) { /* The open syscall was interrupted,so it must be cancelled */ - fuse_do_release(f,e.ino,&ffi); - forget_node(f,e.ino,1); + fuse_do_release(&req_->ctx,e.ino,&ffi); + forget_node(e.ino,1); } } else @@ -3067,7 +2892,7 @@ fuse_lib_tmpfile(fuse_req_t req_, fuse_reply_err(req_,err); } - free_path(f,hdr_->nodeid,fusepath); + free_path(hdr_->nodeid,fusepath); } static @@ -3214,10 +3039,9 @@ lock_to_flock(lock_t *lock, static int -fuse_flush_common(struct fuse *f, - fuse_req_t req, - uint64_t ino, - fuse_file_info_t *fi) +fuse_flush_common(fuse_req_t *req_, + uint64_t ino_, + fuse_file_info_t *ffi_) { struct flock lock; lock_t l; @@ -3227,16 +3051,20 @@ fuse_flush_common(struct fuse *f, memset(&lock,0,sizeof(lock)); lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; - err = f->fs->op.flush(fi); - errlock = f->fs->op.lock(fi,F_SETLK,&lock); + err = f.ops.flush(&req_->ctx, + ffi_); + errlock = f.ops.lock(&req_->ctx, + ffi_, + F_SETLK, + &lock); if(errlock != -ENOSYS) { flock_to_lock(&lock,&l); - l.owner = fi->lock_owner; - mutex_lock(&f->lock); - locks_insert(get_node(f,ino),&l); - mutex_unlock(&f->lock); + l.owner = ffi_->lock_owner; + mutex_lock(&f.lock); + locks_insert(get_node(ino_),&l); + mutex_unlock(&f.lock); /* if op.lock() is defined FLUSH is needed regardless of op.flush() */ @@ -3249,18 +3077,17 @@ fuse_flush_common(struct fuse *f, static void -fuse_lib_release(fuse_req_t req, +fuse_lib_release(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err = 0; - struct fuse *f; fuse_file_info_t ffi = {0}; struct fuse_release_in *arg; arg = (fuse_release_in*)fuse_hdr_arg(hdr_); ffi.fh = arg->fh; ffi.flags = arg->flags; - if(req->f->conn.proto_minor >= 8) + if(req_->f->conn.proto_minor >= 8) { ffi.flush = !!(arg->release_flags & FUSE_RELEASE_FLUSH); ffi.lock_owner = arg->lock_owner; @@ -3271,27 +3098,26 @@ fuse_lib_release(fuse_req_t req, ffi.lock_owner = arg->lock_owner; } - f = req_fuse_prepare(req); - if(ffi.flush) { - err = fuse_flush_common(f,req,hdr_->nodeid,&ffi); + err = fuse_flush_common(req_,hdr_->nodeid,&ffi); if(err == -ENOSYS) err = 0; } - fuse_do_release(f,hdr_->nodeid,&ffi); + fuse_do_release(&req_->ctx, + hdr_->nodeid, + &ffi); - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_flush(fuse_req_t req, +fuse_lib_flush(fuse_req_t *req_, struct fuse_in_header *hdr_) { int err; - struct fuse *f; fuse_file_info_t ffi = {0}; struct fuse_flush_in *arg; @@ -3299,28 +3125,28 @@ fuse_lib_flush(fuse_req_t req, ffi.fh = arg->fh; ffi.flush = 1; - if(req->f->conn.proto_minor >= 7) + if(req_->f->conn.proto_minor >= 7) ffi.lock_owner = arg->lock_owner; - f = req_fuse_prepare(req); - - err = fuse_flush_common(f,req,hdr_->nodeid,&ffi); + err = fuse_flush_common(req_,hdr_->nodeid,&ffi); - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static int -fuse_lock_common(fuse_req_t req, - uint64_t ino, - fuse_file_info_t *fi, - struct flock *lock, - int cmd) +fuse_lock_common(fuse_req_t *req_, + uint64_t ino_, + fuse_file_info_t *ffi_, + struct flock *lock_, + int cmd_) { int err; - struct fuse *f = req_fuse_prepare(req); - err = f->fs->op.lock(fi,cmd,lock); + err = f.ops.lock(&req_->ctx, + ffi_, + cmd_, + lock_); return err; } @@ -3343,11 +3169,10 @@ convert_fuse_file_lock(const struct fuse_file_lock *fl, static void -fuse_lib_getlk(fuse_req_t req, +fuse_lib_getlk(fuse_req_t *req_, const struct fuse_in_header *hdr_) { int err; - struct fuse *f; lock_t lk; struct flock flk; lock_t *conflict; @@ -3360,102 +3185,99 @@ fuse_lib_getlk(fuse_req_t req, convert_fuse_file_lock(&arg->lk,&flk); - f = req_fuse(req); - flock_to_lock(&flk,&lk); lk.owner = ffi.lock_owner; - mutex_lock(&f->lock); - conflict = locks_conflict(get_node(f,hdr_->nodeid),&lk); + mutex_lock(&f.lock); + conflict = locks_conflict(get_node(hdr_->nodeid),&lk); if(conflict) lock_to_flock(conflict,&flk); - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); if(!conflict) - err = fuse_lock_common(req,hdr_->nodeid,&ffi,&flk,F_GETLK); + err = fuse_lock_common(req_,hdr_->nodeid,&ffi,&flk,F_GETLK); else err = 0; if(!err) - fuse_reply_lock(req,&flk); + fuse_reply_lock(req_,&flk); else - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_setlk(fuse_req_t req, +fuse_lib_setlk(fuse_req_t *req_, uint64_t ino, fuse_file_info_t *fi, struct flock *lock, int sleep) { - int err = fuse_lock_common(req,ino,fi,lock, + int err = fuse_lock_common(req_,ino,fi,lock, sleep ? F_SETLKW : F_SETLK); if(!err) { - struct fuse *f = req_fuse(req); lock_t l; flock_to_lock(lock,&l); l.owner = fi->lock_owner; - mutex_lock(&f->lock); - locks_insert(get_node(f,ino),&l); - mutex_unlock(&f->lock); + mutex_lock(&f.lock); + locks_insert(get_node(ino),&l); + mutex_unlock(&f.lock); } - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_flock(fuse_req_t req, - uint64_t ino, - fuse_file_info_t *fi, - int op) +fuse_lib_flock(fuse_req_t *req_, + uint64_t ino_, + fuse_file_info_t *ffi_, + int op_) { int err; - struct fuse *f = req_fuse_prepare(req); - err = f->fs->op.flock(fi,op); + err = f.ops.flock(&req_->ctx, + ffi_, + op_); - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_bmap(fuse_req_t req, +fuse_lib_bmap(fuse_req_t *req_, const struct fuse_in_header *hdr_) { int err; char *fusepath; - struct fuse *f; uint64_t block; const struct fuse_bmap_in *arg; arg = (fuse_bmap_in*)fuse_hdr_arg(hdr_); block = arg->block; - f = req_fuse_prepare(req); - - err = get_path(f,hdr_->nodeid,&fusepath); + err = get_path(hdr_->nodeid,&fusepath); if(!err) { - err = f->fs->op.bmap(&fusepath[1],arg->blocksize,&block); - free_path(f,hdr_->nodeid,fusepath); + err = f.ops.bmap(&req_->ctx, + &fusepath[1], + arg->blocksize, + &block); + free_path(hdr_->nodeid,fusepath); } if(!err) - fuse_reply_bmap(req,block); + fuse_reply_bmap(req_,block); else - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_ioctl(fuse_req_t req, +fuse_lib_ioctl(fuse_req_t *req_, const struct fuse_in_header *hdr_) { int err; char *out_buf = NULL; - struct fuse *f = req_fuse_prepare(req); fuse_file_info_t ffi; fuse_file_info_t llffi = {0}; const void *in_buf; @@ -3463,17 +3285,17 @@ fuse_lib_ioctl(fuse_req_t req, const struct fuse_ioctl_in *arg; arg = (fuse_ioctl_in*)fuse_hdr_arg(hdr_); - if((arg->flags & FUSE_IOCTL_DIR) && !(req->f->conn.want & FUSE_CAP_IOCTL_DIR)) + if((arg->flags & FUSE_IOCTL_DIR) && !(req_->f->conn.want & FUSE_CAP_IOCTL_DIR)) { - fuse_reply_err(req,ENOTTY); + fuse_reply_err(req_,ENOTTY); return; } - if((sizeof(void*) == 4) && - (req->f->conn.proto_minor >= 16) && + if((sizeof(void*) == 4) && + (req_->f->conn.proto_minor >= 16) && !(arg->flags & FUSE_IOCTL_32BIT)) { - req->ioctl_64bit = 1; + req_->ioctl_64bit = 1; } llffi.fh = arg->fh; @@ -3501,30 +3323,30 @@ fuse_lib_ioctl(fuse_req_t req, if(out_buf) memcpy(out_buf,in_buf,arg->in_size); - err = f->fs->op.ioctl(&ffi, - arg->cmd, - (void*)(uintptr_t)arg->arg, - arg->flags, - out_buf ?: (void *)in_buf, - &out_size); + err = f.ops.ioctl(&req_->ctx, + &ffi, + arg->cmd, + (void*)(uintptr_t)arg->arg, + arg->flags, + out_buf ?: (void *)in_buf, + &out_size); if(err < 0) goto err; - fuse_reply_ioctl(req,err,out_buf,out_size); + fuse_reply_ioctl(req_,err,out_buf,out_size); goto out; err: - fuse_reply_err(req,err); + fuse_reply_err(req_,err); out: free(out_buf); } static void -fuse_lib_poll(fuse_req_t req, +fuse_lib_poll(fuse_req_t *req_, const struct fuse_in_header *hdr_) { int err; - struct fuse *f = req_fuse_prepare(req); unsigned revents = 0; fuse_file_info_t ffi = {0}; fuse_pollhandle_t *ph = NULL; @@ -3538,42 +3360,43 @@ fuse_lib_poll(fuse_req_t req, ph = (fuse_pollhandle_t*)malloc(sizeof(fuse_pollhandle_t)); if(ph == NULL) { - fuse_reply_err(req,ENOMEM); + fuse_reply_err(req_,ENOMEM); return; } ph->kh = arg->kh; - ph->ch = req->ch; - ph->f = req->f; + ph->ch = req_->ch; + ph->f = req_->f; } - err = f->fs->op.poll(&ffi,ph,&revents); + err = f.ops.poll(&req_->ctx, + &ffi, + ph, + &revents); if(!err) - fuse_reply_poll(req,revents); + fuse_reply_poll(req_,revents); else - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static void -fuse_lib_fallocate(fuse_req_t req, +fuse_lib_fallocate(fuse_req_t *req_, const struct fuse_in_header *hdr_) { int err; - struct fuse *f; const struct fuse_fallocate_in *arg; arg = (fuse_fallocate_in*)fuse_hdr_arg(hdr_); - f = req_fuse_prepare(req); + err = f.ops.fallocate(&req_->ctx, + arg->fh, + arg->mode, + arg->offset, + arg->length); - err = f->fs->op.fallocate(arg->fh, - arg->mode, - arg->offset, - arg->length); - - fuse_reply_err(req,err); + fuse_reply_err(req_,err); } static @@ -3589,36 +3412,35 @@ remembered_node_cmp(const void *a_, static void -remembered_nodes_sort(struct fuse *f_) +remembered_nodes_sort() { - mutex_lock(&f_->lock); - qsort(&kv_first(f_->remembered_nodes), - kv_size(f_->remembered_nodes), + mutex_lock(&f.lock); + qsort(&kv_first(f.remembered_nodes), + kv_size(f.remembered_nodes), sizeof(remembered_node_t), remembered_node_cmp); - mutex_unlock(&f_->lock); + mutex_unlock(&f.lock); } #define MAX_PRUNE 100 #define MAX_CHECK 1000 int -fuse_prune_some_remembered_nodes(struct fuse *f_, - int *offset_) +fuse_prune_some_remembered_nodes(int *offset_) { time_t now; int pruned; int checked; - mutex_lock(&f_->lock); + mutex_lock(&f.lock); pruned = 0; checked = 0; now = current_time(); - while(*offset_ < kv_size(f_->remembered_nodes)) + while(*offset_ < kv_size(f.remembered_nodes)) { time_t age; - remembered_node_t *fn = &kv_A(f_->remembered_nodes,*offset_); + remembered_node_t *fn = &kv_A(f.remembered_nodes,*offset_); if(pruned >= MAX_PRUNE) break; @@ -3627,7 +3449,7 @@ fuse_prune_some_remembered_nodes(struct fuse *f_, checked++; age = (now - fn->time); - if(f_->conf.remember > age) + if(f.conf.remember > age) break; assert(fn->node->nlookup == 1); @@ -3640,12 +3462,12 @@ fuse_prune_some_remembered_nodes(struct fuse *f_, } fn->node->nlookup = 0; - unref_node(f_,fn->node); - kv_delete(f_->remembered_nodes,*offset_); + unref_node(fn->node); + kv_delete(f.remembered_nodes,*offset_); pruned++; } - mutex_unlock(&f_->lock); + mutex_unlock(&f.lock); if((pruned < MAX_PRUNE) && (checked < MAX_CHECK)) *offset_ = -1; @@ -3666,7 +3488,7 @@ sleep_100ms(void) } void -fuse_prune_remembered_nodes(struct fuse *f_) +fuse_prune_remembered_nodes() { int offset; int pruned; @@ -3675,7 +3497,7 @@ fuse_prune_remembered_nodes(struct fuse *f_) pruned = 0; for(;;) { - pruned += fuse_prune_some_remembered_nodes(f_,&offset); + pruned += fuse_prune_some_remembered_nodes(&offset); if(offset >= 0) { sleep_100ms(); @@ -3686,7 +3508,7 @@ fuse_prune_remembered_nodes(struct fuse *f_) } if(pruned > 0) - remembered_nodes_sort(f_); + remembered_nodes_sort(); } static struct fuse_lowlevel_ops fuse_path_ops = @@ -3749,53 +3571,48 @@ fuse_notify_poll(fuse_pollhandle_t *ph) } int -fuse_exited(struct fuse *f) +fuse_exited() { - return fuse_session_exited(f->se); + return fuse_session_exited(f.se); } struct fuse_session* -fuse_get_session(struct fuse *f) +fuse_get_session() { - return f->se; + return f.se; } void -fuse_exit(struct fuse *f) +fuse_exit() { - f->se->exited = 1; + f.se->exited = 1; } -struct fuse_context* -fuse_get_context(void) -{ - return &fuse_get_context_internal()->ctx; -} - -enum { - KEY_HELP, -}; +enum + { + KEY_HELP, + }; #define FUSE_LIB_OPT(t,p,v) { t,offsetof(struct fuse_config,p),v } static const struct fuse_opt fuse_lib_opts[] = { - FUSE_OPT_KEY("-h", KEY_HELP), - FUSE_OPT_KEY("--help", KEY_HELP), - FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP), - FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP), - FUSE_LIB_OPT("debug", debug,1), - FUSE_LIB_OPT("-d", debug,1), - FUSE_LIB_OPT("nogc", nogc,1), - FUSE_LIB_OPT("umask=", set_mode,1), - FUSE_LIB_OPT("umask=%o", umask,0), - FUSE_LIB_OPT("uid=", set_uid,1), - FUSE_LIB_OPT("uid=%d", uid,0), - FUSE_LIB_OPT("gid=", set_gid,1), - FUSE_LIB_OPT("gid=%d", gid,0), - FUSE_LIB_OPT("noforget", remember,-1), - FUSE_LIB_OPT("remember=%u", remember,0), - FUSE_OPT_END + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP), + FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP), + FUSE_LIB_OPT("debug", debug,1), + FUSE_LIB_OPT("-d", debug,1), + FUSE_LIB_OPT("nogc", nogc,1), + FUSE_LIB_OPT("umask=", set_mode,1), + FUSE_LIB_OPT("umask=%o", umask,0), + FUSE_LIB_OPT("uid=", set_uid,1), + FUSE_LIB_OPT("uid=%d", uid,0), + FUSE_LIB_OPT("gid=", set_gid,1), + FUSE_LIB_OPT("gid=%d", gid,0), + FUSE_LIB_OPT("noforget", remember,-1), + FUSE_LIB_OPT("remember=%u", remember,0), + FUSE_OPT_END }; static void fuse_lib_help(void) @@ -3837,31 +3654,6 @@ fuse_is_lib_option(const char *opt) return fuse_lowlevel_is_lib_option(opt) || fuse_opt_match(fuse_lib_opts,opt); } -struct fuse_fs* -fuse_fs_new(const struct fuse_operations *op, - size_t op_size) -{ - struct fuse_fs *fs; - - if(sizeof(struct fuse_operations) < op_size) - { - fprintf(stderr,"fuse: warning: library too old,some operations may not not work\n"); - op_size = sizeof(struct fuse_operations); - } - - fs = (struct fuse_fs *)calloc(1,sizeof(struct fuse_fs)); - if(!fs) - { - fprintf(stderr,"fuse: failed to allocate fuse_fs object\n"); - return NULL; - } - - if(op) - memcpy(&fs->op,op,op_size); - - return fs; -} - static int node_table_init(struct node_table *t) @@ -3879,19 +3671,9 @@ node_table_init(struct node_table *t) return 0; } -static -struct fuse* -fuse_get_fuse_obj() -{ - static struct fuse f = {0}; - - return &f; -} - static void -metrics_log_nodes_info(struct fuse *f_, - FILE *file_) +metrics_log_nodes_info(FILE *file_) { char buf[1024]; char time_str[64]; @@ -3939,12 +3721,12 @@ metrics_log_nodes_info(struct fuse *f_, , time_str, sizeof_node, - (uint64_t)f_->id_table.size, - (uint64_t)f_->id_table.use, - (uint64_t)(f_->id_table.size * sizeof(node_t*)), - (uint64_t)f_->name_table.size, - (uint64_t)f_->name_table.use, - (uint64_t)(f_->name_table.size * sizeof(node_t*)), + (uint64_t)f.id_table.size, + (uint64_t)f.id_table.use, + (uint64_t)(f.id_table.size * sizeof(node_t*)), + (uint64_t)f.name_table.size, + (uint64_t)f.name_table.use, + (uint64_t)(f.name_table.size * sizeof(node_t*)), node_slab_count, node_usage_ratio, node_avail_objs, @@ -3979,7 +3761,7 @@ metrics_log_nodes_info_to_tmp_dir(struct fuse *f_) if(file == NULL) return; - metrics_log_nodes_info(f_,file); + metrics_log_nodes_info(file); fclose(file); } @@ -3996,15 +3778,14 @@ fuse_malloc_trim(void) void fuse_invalidate_all_nodes() { - struct fuse *f = fuse_get_fuse_obj(); std::vector names; - mutex_lock(&f->lock); - for(size_t i = 0; i < f->id_table.size; i++) + mutex_lock(&f.lock); + for(size_t i = 0; i < f.id_table.size; i++) { node_t *node; - for(node = f->id_table.array[i]; node != NULL; node = node->id_next) + for(node = f.id_table.array[i]; node != NULL; node = node->id_next) { if(node->nodeid == FUSE_ROOT_ID) continue; @@ -4018,13 +3799,13 @@ fuse_invalidate_all_nodes() names.emplace_back(node->name); } } - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); SysLog::info("invalidating {} file entries", names.size()); for(auto &name : names) { - fuse_lowlevel_notify_inval_entry(f->se->ch, + fuse_lowlevel_notify_inval_entry(f.se->ch, FUSE_ROOT_ID, name.c_str(), name.size()); @@ -4054,8 +3835,8 @@ fuse_populate_maintenance_thread(struct fuse *f_) { MaintenanceThread::push_job([=](int count_) { - if(remember_nodes(f_)) - fuse_prune_remembered_nodes(f_); + if(remember_nodes()) + fuse_prune_remembered_nodes(); }); MaintenanceThread::push_job([](int count_) @@ -4072,63 +3853,46 @@ fuse_populate_maintenance_thread(struct fuse *f_) } struct fuse* -fuse_new_common(struct fuse_chan *ch, - struct fuse_args *args, - const struct fuse_operations *op, - size_t op_size) +fuse_new(struct fuse_chan *ch, + struct fuse_args *args, + const struct fuse_operations *ops_) { - struct fuse *f; node_t *root; - struct fuse_fs *fs; struct fuse_lowlevel_ops llop = fuse_path_ops; - if(fuse_create_context_key() == -1) - goto out; - - f = fuse_get_fuse_obj(); - if(f == NULL) - { - fprintf(stderr,"fuse: failed to allocate fuse object\n"); - goto out_delete_context_key; - } - - fs = fuse_fs_new(op,op_size); - if(!fs) - goto out_free; - - f->fs = fs; + f.ops = *ops_; /* Oh f**k,this is ugly! */ - if(!fs->op.lock) + if(!f.ops.lock) { llop.getlk = NULL; llop.setlk = NULL; } - if(fuse_opt_parse(args,&f->conf,fuse_lib_opts,fuse_lib_opt_proc) == -1) + if(fuse_opt_parse(args,&f.conf,fuse_lib_opts,fuse_lib_opt_proc) == -1) goto out_free_fs; - g_LOG_METRICS = f->conf.debug; + g_LOG_METRICS = f.conf.debug; - f->se = fuse_lowlevel_new_common(args,&llop,sizeof(llop),f); - if(f->se == NULL) + f.se = fuse_lowlevel_new_common(args,&llop,sizeof(llop),&f); + if(f.se == NULL) goto out_free_fs; - fuse_session_add_chan(f->se,ch); + fuse_session_add_chan(f.se,ch); /* Trace topmost layer by default */ srand(time(NULL)); - f->nodeid_gen.nodeid = FUSE_ROOT_ID; - f->nodeid_gen.generation = rand64(); - if(node_table_init(&f->name_table) == -1) + f.nodeid_gen.nodeid = FUSE_ROOT_ID; + f.nodeid_gen.generation = rand64(); + if(node_table_init(&f.name_table) == -1) goto out_free_session; - if(node_table_init(&f->id_table) == -1) + if(node_table_init(&f.id_table) == -1) goto out_free_name_table; - mutex_init(&f->lock); + mutex_init(&f.lock); - kv_init(f->remembered_nodes); + kv_init(f.remembered_nodes); root = node_alloc(); if(root == NULL) @@ -4137,75 +3901,52 @@ fuse_new_common(struct fuse_chan *ch, goto out_free_id_table; } - root->name = filename_strdup(f,"/"); + root->name = strdup("/"); root->parent = NULL; root->nodeid = FUSE_ROOT_ID; inc_nlookup(root); - hash_id(f,root); + hash_id(root); - return f; + return &f; out_free_id_table: - free(f->id_table.array); + free(f.id_table.array); out_free_name_table: - free(f->name_table.array); + free(f.name_table.array); out_free_session: - fuse_session_destroy(f->se); + fuse_session_destroy(f.se); out_free_fs: /* Horrible compatibility hack to stop the destructor from being called on the filesystem without init being called first */ - fs->op.destroy = NULL; - free(f->fs); - out_free: - // free(f); - out_delete_context_key: - fuse_delete_context_key(); - out: - return NULL; -} + f.ops.destroy = NULL; -struct fuse* -fuse_new(struct fuse_chan *ch, - struct fuse_args *args, - const struct fuse_operations *op, - size_t op_size) -{ - return fuse_new_common(ch,args,op,op_size); + return NULL; } void -fuse_destroy(struct fuse *f) +fuse_destroy(struct fuse *) { size_t i; - if(f->fs) - { - struct fuse_context_i *c = fuse_get_context_internal(); - - memset(c,0,sizeof(*c)); - c->ctx.fuse = f; - } - - for(i = 0; i < f->id_table.size; i++) + for(i = 0; i < f.id_table.size; i++) { node_t *node; node_t *next; - for(node = f->id_table.array[i]; node != NULL; node = next) + for(node = f.id_table.array[i]; node != NULL; node = next) { next = node->id_next; - free_node(f,node); - f->id_table.use--; + free_node(node); + f.id_table.use--; } } - free(f->id_table.array); - free(f->name_table.array); - mutex_destroy(&f->lock); - fuse_session_destroy(f->se); - kv_destroy(f->remembered_nodes); - fuse_delete_context_key(); + free(f.id_table.array); + free(f.name_table.array); + mutex_destroy(&f.lock); + fuse_session_destroy(f.se); + kv_destroy(f.remembered_nodes); } void @@ -4221,20 +3962,13 @@ fuse_log_metrics_get(void) } int -fuse_get_dev_fuse_fd(const struct fuse_context *fc_) -{ - return fuse_chan_fd(fc_->fuse->se->ch); -} - -int -fuse_passthrough_open(const struct fuse_context *fc_, - const int fd_) +fuse_passthrough_open(const int fd_) { int rv; int dev_fuse_fd; struct fuse_backing_map bm = {0}; - dev_fuse_fd = fuse_get_dev_fuse_fd(fc_); + dev_fuse_fd = fuse_chan_fd(f.se->ch); bm.fd = fd_; rv = ::ioctl(dev_fuse_fd,FUSE_DEV_IOC_BACKING_OPEN,&bm); @@ -4243,12 +3977,11 @@ fuse_passthrough_open(const struct fuse_context *fc_, } int -fuse_passthrough_close(const struct fuse_context *fc_, - const int backing_id_) +fuse_passthrough_close(const int backing_id_) { int dev_fuse_fd; - dev_fuse_fd = fuse_get_dev_fuse_fd(fc_); + dev_fuse_fd = fuse_chan_fd(f.se->ch); return ::ioctl(dev_fuse_fd,FUSE_DEV_IOC_BACKING_CLOSE,&backing_id_); } diff --git a/libfuse/lib/fuse_i.h b/libfuse/lib/fuse_i.h index 93ca59d2..f1b4fa01 100644 --- a/libfuse/lib/fuse_i.h +++ b/libfuse/lib/fuse_i.h @@ -32,20 +32,11 @@ struct fuse_session struct fuse_chan *ch; }; -struct fuse_req -{ - struct fuse_ll *f; - uint64_t unique; - struct fuse_ctx ctx; - struct fuse_chan *ch; - unsigned int ioctl_64bit : 1; -}; - struct fuse_notify_req { uint64_t unique; void (*reply)(struct fuse_notify_req *, - fuse_req_t, + fuse_req_t*, uint64_t, const void *); struct fuse_notify_req *next; @@ -81,9 +72,9 @@ struct fuse_cmd EXTERN_C_BEGIN -struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args, - const struct fuse_operations *op, - size_t op_size); +struct fuse *fuse_new_common(struct fuse_chan *ch, + struct fuse_args *args, + const struct fuse_operations *op); struct fuse_chan *fuse_kern_chan_new(int fd); @@ -101,10 +92,10 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov, void fuse_free_req(fuse_req_t req); -struct fuse *fuse_setup_common(int argc, char *argv[], +struct fuse *fuse_setup_common(int argc, + char *argv[], const struct fuse_operations *op, - size_t op_size, - char **mountpoint, + char **mountpoint, int *fd); int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg); diff --git a/libfuse/lib/fuse_loop.cpp b/libfuse/lib/fuse_loop.cpp index 0c685c75..5bfe85c9 100644 --- a/libfuse/lib/fuse_loop.cpp +++ b/libfuse/lib/fuse_loop.cpp @@ -335,7 +335,7 @@ fuse_loop_mt(struct fuse *f_) MaintenanceThread::setup(); fuse_populate_maintenance_thread(f_); - res = fuse_session_loop_mt(fuse_get_session(f_), + res = fuse_session_loop_mt(fuse_get_session(), fuse_config_get_read_thread_count(), fuse_config_get_process_thread_count(), fuse_config_get_process_thread_queue_depth(), diff --git a/libfuse/lib/fuse_lowlevel.cpp b/libfuse/lib/fuse_lowlevel.cpp index 81472423..2efb1554 100644 --- a/libfuse/lib/fuse_lowlevel.cpp +++ b/libfuse/lib/fuse_lowlevel.cpp @@ -55,7 +55,7 @@ void fuse_ll_constructor(void) { pagesize = sysconf(_SC_PAGESIZE); - lfmp_init(&g_FMP_fuse_req,sizeof(struct fuse_req),1); + lfmp_init(&g_FMP_fuse_req,sizeof(struct fuse_req_t),1); } static @@ -104,18 +104,18 @@ iov_length(const struct iovec *iov, static void -destroy_req(fuse_req_t req) +destroy_req(fuse_req_t *req) { lfmp_free(&g_FMP_fuse_req,req); } static -struct fuse_req* +fuse_req_t* fuse_ll_alloc_req(struct fuse_ll *f) { - struct fuse_req *req; + fuse_req_t *req; - req = (struct fuse_req*)lfmp_calloc(&g_FMP_fuse_req); + req = (fuse_req_t*)lfmp_calloc(&g_FMP_fuse_req); if(req == NULL) { fprintf(stderr, "fuse: failed to allocate request\n"); @@ -151,7 +151,7 @@ fuse_send_msg(struct fuse_ll *f, #define MAX_ERRNO 4095 int -fuse_send_reply_iov_nofree(fuse_req_t req, +fuse_send_reply_iov_nofree(fuse_req_t *req, int error, struct iovec *iov, int count) @@ -167,7 +167,7 @@ fuse_send_reply_iov_nofree(fuse_req_t req, error = -ERANGE; } - out.unique = req->unique; + out.unique = req->ctx.unique; out.error = error; iov[0].iov_base = &out; @@ -178,7 +178,7 @@ fuse_send_reply_iov_nofree(fuse_req_t req, static int -send_reply_iov(fuse_req_t req, +send_reply_iov(fuse_req_t *req, int error, struct iovec *iov, int count) @@ -193,7 +193,7 @@ send_reply_iov(fuse_req_t req, static int -send_reply(fuse_req_t req, +send_reply(fuse_req_t *req, int error, const void *arg, size_t argsize) @@ -227,7 +227,7 @@ convert_statfs(const struct statvfs *stbuf, static int -send_reply_ok(fuse_req_t req, +send_reply_ok(fuse_req_t *req, const void *arg, size_t argsize) { @@ -235,14 +235,14 @@ send_reply_ok(fuse_req_t req, } int -fuse_reply_err(fuse_req_t req_, - int err_) +fuse_reply_err(fuse_req_t *req_, + int err_) { return send_reply(req_,err_,NULL,0); } void -fuse_reply_none(fuse_req_t req) +fuse_reply_none(fuse_req_t *req) { destroy_req(req); } @@ -287,7 +287,7 @@ fill_open(struct fuse_open_out *arg_, } int -fuse_reply_entry(fuse_req_t req, +fuse_reply_entry(fuse_req_t *req, const struct fuse_entry_param *e) { struct fuse_entry_out arg = {0}; @@ -316,7 +316,7 @@ struct fuse_create_out }; int -fuse_reply_create(fuse_req_t req, +fuse_reply_create(fuse_req_t *req, const struct fuse_entry_param *e, const fuse_file_info_t *f) { @@ -333,7 +333,7 @@ fuse_reply_create(fuse_req_t req, } int -fuse_reply_attr(fuse_req_t req, +fuse_reply_attr(fuse_req_t *req, const struct stat *attr, const uint64_t timeout) { @@ -349,7 +349,7 @@ fuse_reply_attr(fuse_req_t req, } int -fuse_reply_statx(fuse_req_t req_, +fuse_reply_statx(fuse_req_t *req_, int flags_, struct fuse_statx *st_, uint64_t timeout_) @@ -365,14 +365,14 @@ fuse_reply_statx(fuse_req_t req_, } int -fuse_reply_readlink(fuse_req_t req, +fuse_reply_readlink(fuse_req_t *req, const char *linkname) { return send_reply_ok(req, linkname, strlen(linkname)); } int -fuse_reply_open(fuse_req_t req, +fuse_reply_open(fuse_req_t *req, const fuse_file_info_t *f) { struct fuse_open_out arg = {0}; @@ -383,8 +383,8 @@ fuse_reply_open(fuse_req_t req, } int -fuse_reply_write(fuse_req_t req, - size_t count) +fuse_reply_write(fuse_req_t *req, + size_t count) { struct fuse_write_out arg = {0}; @@ -394,7 +394,7 @@ fuse_reply_write(fuse_req_t req, } int -fuse_reply_buf(fuse_req_t req, +fuse_reply_buf(fuse_req_t *req, const char *buf, size_t size) { @@ -482,7 +482,7 @@ fuse_send_data_iov(struct fuse_ll *f, } int -fuse_reply_data(fuse_req_t req, +fuse_reply_data(fuse_req_t *req, char *buf_, const size_t bufsize_) { @@ -495,7 +495,7 @@ fuse_reply_data(fuse_req_t req, iov[1].iov_base = buf_; iov[1].iov_len = bufsize_; - out.unique = req->unique; + out.unique = req->ctx.unique; out.error = 0; res = fuse_send_msg(req->f,req->ch,iov,2); @@ -511,7 +511,7 @@ fuse_reply_data(fuse_req_t req, } int -fuse_reply_statfs(fuse_req_t req, +fuse_reply_statfs(fuse_req_t *req, const struct statvfs *stbuf) { struct fuse_statfs_out arg = {0}; @@ -524,8 +524,8 @@ fuse_reply_statfs(fuse_req_t req, } int -fuse_reply_xattr(fuse_req_t req, - size_t count) +fuse_reply_xattr(fuse_req_t *req, + size_t count) { struct fuse_getxattr_out arg = {0}; @@ -535,7 +535,7 @@ fuse_reply_xattr(fuse_req_t req, } int -fuse_reply_lock(fuse_req_t req, +fuse_reply_lock(fuse_req_t *req, const struct flock *lock) { struct fuse_lk_out arg = {0}; @@ -555,8 +555,8 @@ fuse_reply_lock(fuse_req_t req, } int -fuse_reply_bmap(fuse_req_t req, - uint64_t idx) +fuse_reply_bmap(fuse_req_t *req, + uint64_t idx) { struct fuse_bmap_out arg = {0}; @@ -587,7 +587,7 @@ fuse_ioctl_iovec_copy(const struct iovec *iov, } int -fuse_reply_ioctl_retry(fuse_req_t req, +fuse_reply_ioctl_retry(fuse_req_t *req, const struct iovec *in_iov, size_t in_count, const struct iovec *out_iov, @@ -667,7 +667,7 @@ fuse_reply_ioctl_retry(fuse_req_t req, } int -fuse_reply_ioctl(fuse_req_t req, +fuse_reply_ioctl(fuse_req_t *req, int result, const void *buf, uint32_t size) @@ -697,7 +697,7 @@ fuse_reply_ioctl(fuse_req_t req, } int -fuse_reply_ioctl_iov(fuse_req_t req, +fuse_reply_ioctl_iov(fuse_req_t *req, int result, const struct iovec *iov, int count) @@ -723,8 +723,8 @@ fuse_reply_ioctl_iov(fuse_req_t req, } int -fuse_reply_poll(fuse_req_t req, - unsigned revents) +fuse_reply_poll(fuse_req_t *req, + unsigned revents) { struct fuse_poll_out arg = {0}; @@ -735,7 +735,7 @@ fuse_reply_poll(fuse_req_t req, static void -do_lookup(fuse_req_t req, +do_lookup(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.lookup(req,hdr_); @@ -743,7 +743,7 @@ do_lookup(fuse_req_t req, static void -do_forget(fuse_req_t req, +do_forget(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.forget(req,hdr_); @@ -751,7 +751,7 @@ do_forget(fuse_req_t req, static void -do_batch_forget(fuse_req_t req, +do_batch_forget(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.forget_multi(req,hdr_); @@ -759,7 +759,7 @@ do_batch_forget(fuse_req_t req, static void -do_getattr(fuse_req_t req, +do_getattr(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.getattr(req, hdr_); @@ -767,7 +767,7 @@ do_getattr(fuse_req_t req, static void -do_setattr(fuse_req_t req_, +do_setattr(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.setattr(req_,hdr_); @@ -775,7 +775,7 @@ do_setattr(fuse_req_t req_, static void -do_access(fuse_req_t req, +do_access(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.access(req,hdr_); @@ -783,7 +783,7 @@ do_access(fuse_req_t req, static void -do_readlink(fuse_req_t req, +do_readlink(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.readlink(req,hdr_); @@ -791,7 +791,7 @@ do_readlink(fuse_req_t req, static void -do_mknod(fuse_req_t req, +do_mknod(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.mknod(req,hdr_); @@ -799,7 +799,7 @@ do_mknod(fuse_req_t req, static void -do_mkdir(fuse_req_t req, +do_mkdir(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.mkdir(req,hdr_); @@ -807,7 +807,7 @@ do_mkdir(fuse_req_t req, static void -do_unlink(fuse_req_t req, +do_unlink(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.unlink(req,hdr_); @@ -815,7 +815,7 @@ do_unlink(fuse_req_t req, static void -do_rmdir(fuse_req_t req, +do_rmdir(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.rmdir(req,hdr_); @@ -823,7 +823,7 @@ do_rmdir(fuse_req_t req, static void -do_symlink(fuse_req_t req, +do_symlink(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.symlink(req,hdr_); @@ -831,7 +831,7 @@ do_symlink(fuse_req_t req, static void -do_rename(fuse_req_t req, +do_rename(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.rename(req,hdr_); @@ -839,7 +839,7 @@ do_rename(fuse_req_t req, static void -do_link(fuse_req_t req, +do_link(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.link(req,hdr_); @@ -847,7 +847,7 @@ do_link(fuse_req_t req, static void -do_create(fuse_req_t req, +do_create(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.create(req,hdr_); @@ -855,7 +855,7 @@ do_create(fuse_req_t req, static void -do_open(fuse_req_t req, +do_open(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.open(req,hdr_); @@ -863,7 +863,7 @@ do_open(fuse_req_t req, static void -do_read(fuse_req_t req, +do_read(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.read(req,hdr_); @@ -871,7 +871,7 @@ do_read(fuse_req_t req, static void -do_write(fuse_req_t req, +do_write(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.write(req,hdr_); @@ -879,7 +879,7 @@ do_write(fuse_req_t req, static void -do_flush(fuse_req_t req, +do_flush(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.flush(req,hdr_); @@ -887,7 +887,7 @@ do_flush(fuse_req_t req, static void -do_release(fuse_req_t req, +do_release(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.release(req,hdr_); @@ -895,7 +895,7 @@ do_release(fuse_req_t req, static void -do_fsync(fuse_req_t req, +do_fsync(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.fsync(req,hdr_); @@ -903,7 +903,7 @@ do_fsync(fuse_req_t req, static void -do_opendir(fuse_req_t req, +do_opendir(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.opendir(req,hdr_); @@ -911,7 +911,7 @@ do_opendir(fuse_req_t req, static void -do_readdir(fuse_req_t req, +do_readdir(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.readdir(req,hdr_); @@ -919,7 +919,7 @@ do_readdir(fuse_req_t req, static void -do_readdirplus(fuse_req_t req_, +do_readdirplus(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.readdir_plus(req_,hdr_); @@ -927,7 +927,7 @@ do_readdirplus(fuse_req_t req_, static void -do_releasedir(fuse_req_t req, +do_releasedir(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.releasedir(req,hdr_); @@ -935,7 +935,7 @@ do_releasedir(fuse_req_t req, static void -do_fsyncdir(fuse_req_t req, +do_fsyncdir(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.fsyncdir(req,hdr_); @@ -943,7 +943,7 @@ do_fsyncdir(fuse_req_t req, static void -do_statfs(fuse_req_t req, +do_statfs(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.statfs(req,hdr_); @@ -951,7 +951,7 @@ do_statfs(fuse_req_t req, static void -do_setxattr(fuse_req_t req, +do_setxattr(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.setxattr(req,hdr_); @@ -959,7 +959,7 @@ do_setxattr(fuse_req_t req, static void -do_getxattr(fuse_req_t req, +do_getxattr(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.getxattr(req,hdr_); @@ -967,7 +967,7 @@ do_getxattr(fuse_req_t req, static void -do_listxattr(fuse_req_t req, +do_listxattr(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.listxattr(req,hdr_); @@ -975,7 +975,7 @@ do_listxattr(fuse_req_t req, static void -do_removexattr(fuse_req_t req, +do_removexattr(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.removexattr(req,hdr_); @@ -999,7 +999,7 @@ convert_fuse_file_lock(struct fuse_file_lock *fl, static void -do_getlk(fuse_req_t req, +do_getlk(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.getlk(req,hdr_); @@ -1007,7 +1007,7 @@ do_getlk(fuse_req_t req, static void -do_setlk_common(fuse_req_t req, +do_setlk_common(fuse_req_t *req, uint64_t nodeid, const void *inarg, int sleep) @@ -1051,7 +1051,7 @@ do_setlk_common(fuse_req_t req, static void -do_setlk(fuse_req_t req, +do_setlk(fuse_req_t *req, struct fuse_in_header *hdr_) { do_setlk_common(req, hdr_->nodeid, &hdr_[1], 0); @@ -1059,7 +1059,7 @@ do_setlk(fuse_req_t req, static void -do_setlkw(fuse_req_t req, +do_setlkw(fuse_req_t *req, struct fuse_in_header *hdr_) { do_setlk_common(req, hdr_->nodeid, &hdr_[1], 1); @@ -1067,7 +1067,7 @@ do_setlkw(fuse_req_t req, static void -do_interrupt(fuse_req_t req, +do_interrupt(fuse_req_t *req, struct fuse_in_header *hdr_) { destroy_req(req); @@ -1075,7 +1075,7 @@ do_interrupt(fuse_req_t req, static void -do_bmap(fuse_req_t req, +do_bmap(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.bmap(req,hdr_); @@ -1083,7 +1083,7 @@ do_bmap(fuse_req_t req, static void -do_ioctl(fuse_req_t req, +do_ioctl(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.ioctl(req, hdr_); @@ -1097,7 +1097,7 @@ fuse_pollhandle_destroy(fuse_pollhandle_t *ph) static void -do_poll(fuse_req_t req, +do_poll(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.poll(req,hdr_); @@ -1105,7 +1105,7 @@ do_poll(fuse_req_t req, static void -do_fallocate(fuse_req_t req, +do_fallocate(fuse_req_t *req, struct fuse_in_header *hdr_) { req->f->op.fallocate(req,hdr_); @@ -1113,7 +1113,7 @@ do_fallocate(fuse_req_t req, static void -do_init(fuse_req_t req, +do_init(fuse_req_t *req, struct fuse_in_header *hdr_) { struct fuse_init_out outarg = {0}; @@ -1334,7 +1334,7 @@ do_init(fuse_req_t req, static void -do_destroy(fuse_req_t req, +do_destroy(fuse_req_t *req, struct fuse_in_header *hdr_) { struct fuse_ll *f = req->f; @@ -1377,7 +1377,7 @@ list_init_nreq(struct fuse_notify_req *nreq) static void -do_notify_reply(fuse_req_t req, +do_notify_reply(fuse_req_t *req, struct fuse_in_header *hdr_) { struct fuse_ll *f = req->f; @@ -1388,7 +1388,7 @@ do_notify_reply(fuse_req_t req, head = &f->notify_list; for(nreq = head->next; nreq != head; nreq = nreq->next) { - if(nreq->unique == req->unique) + if(nreq->unique == req->ctx.unique) { list_del_nreq(nreq); break; @@ -1402,7 +1402,7 @@ do_notify_reply(fuse_req_t req, static void -do_copy_file_range(fuse_req_t req_, +do_copy_file_range(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.copy_file_range(req_,hdr_); @@ -1410,15 +1410,15 @@ do_copy_file_range(fuse_req_t req_, static void -do_setupmapping(fuse_req_t req_, - struct fuse_in_header *hdr_) +do_setupmapping(fuse_req_t *req_, + struct fuse_in_header *hdr_) { req_->f->op.setupmapping(req_,hdr_); } static void -do_removemapping(fuse_req_t req_, +do_removemapping(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.removemapping(req_,hdr_); @@ -1426,7 +1426,7 @@ do_removemapping(fuse_req_t req_, static void -do_syncfs(fuse_req_t req_, +do_syncfs(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.syncfs(req_,hdr_); @@ -1434,7 +1434,7 @@ do_syncfs(fuse_req_t req_, static void -do_tmpfile(fuse_req_t req_, +do_tmpfile(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.tmpfile(req_,hdr_); @@ -1442,7 +1442,7 @@ do_tmpfile(fuse_req_t req_, static void -do_statx(fuse_req_t req_, +do_statx(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.statx(req_,hdr_); @@ -1450,7 +1450,7 @@ do_statx(fuse_req_t req_, static void -do_rename2(fuse_req_t req_, +do_rename2(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.rename2(req_,hdr_); @@ -1458,7 +1458,7 @@ do_rename2(fuse_req_t req_, static void -do_lseek(fuse_req_t req_, +do_lseek(fuse_req_t *req_, struct fuse_in_header *hdr_) { req_->f->op.lseek(req_,hdr_); @@ -1650,7 +1650,7 @@ struct fuse_retrieve_req static void fuse_ll_retrieve_reply(struct fuse_notify_req *nreq, - fuse_req_t req, + fuse_req_t *req, uint64_t ino, const void *inarg) { @@ -1716,22 +1716,9 @@ fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, return err; } -void * -fuse_req_userdata(fuse_req_t req) -{ - return req->f->userdata; -} - -const -struct fuse_ctx * -fuse_req_ctx(fuse_req_t req) -{ - return &req->ctx; -} - #define FUSE_OPCODE_LEN (FUSE_STATX + 1) -typedef void (*fuse_ll_func)(fuse_req_t, struct fuse_in_header *); +typedef void (*fuse_ll_func)(fuse_req_t*, struct fuse_in_header *); const fuse_ll_func fuse_ll_funcs[FUSE_OPCODE_LEN] = @@ -1966,7 +1953,7 @@ fuse_ll_buf_process_read(struct fuse_session *se_, const fuse_msgbuf_t *msgbuf_) { int err; - struct fuse_req *req; + struct fuse_req_t *req; struct fuse_in_header *in; in = (struct fuse_in_header*)msgbuf_->mem; @@ -1978,13 +1965,14 @@ fuse_ll_buf_process_read(struct fuse_session *se_, if(req == NULL) return fuse_send_enomem(se_->f,se_->ch,in->unique); - req->unique = in->unique; + req->ctx.len = in->len; req->ctx.opcode = in->opcode; req->ctx.unique = in->unique; req->ctx.nodeid = in->nodeid; req->ctx.uid = in->uid; req->ctx.gid = in->gid; req->ctx.pid = in->pid; + req->ctx.umask = 0; req->ch = se_->ch; err = ENOSYS; @@ -2008,7 +1996,7 @@ fuse_ll_buf_process_read_init(struct fuse_session *se_, const fuse_msgbuf_t *msgbuf_) { int err; - struct fuse_req *req; + fuse_req_t *req; struct fuse_in_header *in; in = (struct fuse_in_header*)msgbuf_->mem; @@ -2017,13 +2005,14 @@ fuse_ll_buf_process_read_init(struct fuse_session *se_, if(req == NULL) return fuse_send_enomem(se_->f,se_->ch,in->unique); - req->unique = in->unique; + req->ctx.len = in->len; req->ctx.opcode = in->opcode; req->ctx.unique = in->unique; req->ctx.nodeid = in->nodeid; req->ctx.uid = in->uid; req->ctx.gid = in->gid; req->ctx.pid = in->pid; + req->ctx.umask = 0; req->ch = se_->ch; err = EIO; diff --git a/libfuse/lib/helper.c b/libfuse/lib/helper.c index 23ba83b9..185311fa 100644 --- a/libfuse/lib/helper.c +++ b/libfuse/lib/helper.c @@ -281,11 +281,10 @@ void fuse_unmount(const char *mountpoint, struct fuse_chan *ch) fuse_unmount_common(mountpoint, ch); } -struct fuse * +struct fuse* fuse_setup_common(int argc, char *argv[], const struct fuse_operations *op, - size_t op_size, char **mountpoint, int *fd) { @@ -305,7 +304,7 @@ fuse_setup_common(int argc, goto err_free; } - fuse = fuse_new_common(ch, &args, op, op_size); + fuse = fuse_new(ch, &args, op); fuse_opt_free_args(&args); if (fuse == NULL) goto err_unmount; @@ -325,75 +324,59 @@ fuse_setup_common(int argc, err_unmount: fuse_unmount_common(*mountpoint, ch); - if (fuse) - fuse_destroy(fuse); err_free: free(*mountpoint); return NULL; } -struct fuse *fuse_setup(int argc, char *argv[], - const struct fuse_operations *op, size_t op_size, +struct fuse *fuse_setup(int argc, + char *argv[], + const struct fuse_operations *op, char **mountpoint) { - return fuse_setup_common(argc, argv, op, op_size, mountpoint, + return fuse_setup_common(argc, + argv, + op, + mountpoint, NULL); } -static void fuse_teardown_common(struct fuse *fuse, char *mountpoint) +static void fuse_teardown_common(char *mountpoint) { - struct fuse_session *se = fuse_get_session(fuse); + struct fuse_session *se = fuse_get_session(); struct fuse_chan *ch = se->ch; fuse_remove_signal_handlers(se); fuse_unmount_common(mountpoint, ch); - fuse_destroy(fuse); free(mountpoint); } -void fuse_teardown(struct fuse *fuse, char *mountpoint) +void fuse_teardown(char *mountpoint) { - fuse_teardown_common(fuse, mountpoint); + fuse_teardown_common(mountpoint); } -static int fuse_main_common(int argc, char *argv[], - const struct fuse_operations *op, size_t op_size) +int +fuse_main(int argc, + char *argv[], + const struct fuse_operations *op) { struct fuse *fuse; char *mountpoint; int res; - fuse = fuse_setup_common(argc, argv, op, op_size, + fuse = fuse_setup_common(argc, + argv, + op, &mountpoint, NULL); - if (fuse == NULL) + if(fuse == NULL) return 1; res = fuse_loop_mt(fuse); - fuse_teardown_common(fuse, mountpoint); - if (res == -1) + fuse_teardown_common(mountpoint); + if(res == -1) return 1; return 0; } - -int fuse_main_real(int argc, - char *argv[], - const struct fuse_operations *op, - size_t op_size) -{ - return fuse_main_common(argc, argv, op, op_size); -} - -#undef fuse_main -int fuse_main(void); -int fuse_main(void) -{ - fprintf(stderr, "fuse_main(): This function does not exist\n"); - return -1; -} - -int fuse_version(void) -{ - return FUSE_VERSION; -} diff --git a/src/fuse_access.cpp b/src/fuse_access.cpp index 8a94ef9e..ae3419c8 100644 --- a/src/fuse_access.cpp +++ b/src/fuse_access.cpp @@ -50,12 +50,12 @@ _access(const Policy::Search &searchFunc_, } int -FUSE::access(const char *fusepath_, - int mask_) +FUSE::access(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + int mask_) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_->uid,ctx_->gid); return ::_access(cfg.func.access.policy, cfg.branches, diff --git a/src/fuse_access.hpp b/src/fuse_access.hpp index 72386aae..2195f7b2 100644 --- a/src/fuse_access.hpp +++ b/src/fuse_access.hpp @@ -16,10 +16,12 @@ #pragma once +#include "fuse_req_ctx.h" namespace FUSE { int - access(const char *fusepath, - int mask); + access(const fuse_req_ctx_t *ctx, + const char *fusepath, + int mask); } diff --git a/src/fuse_bmap.cpp b/src/fuse_bmap.cpp index 5b950813..9b61428c 100644 --- a/src/fuse_bmap.cpp +++ b/src/fuse_bmap.cpp @@ -20,16 +20,14 @@ #include "errno.hpp" -#include - -#include - int -FUSE::bmap(const char *fusepath_, - size_t blocksize_, - uint64_t *idx_) +FUSE::bmap(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + size_t blocksize_, + uint64_t *idx_) { + (void)ctx_; (void)fusepath_; (void)blocksize_; (void)idx_; diff --git a/src/fuse_bmap.hpp b/src/fuse_bmap.hpp index 35152674..84026162 100644 --- a/src/fuse_bmap.hpp +++ b/src/fuse_bmap.hpp @@ -18,12 +18,17 @@ #pragma once -#include "fuse.h" +#include "fuse_req_ctx.h" + +#include +#include + namespace FUSE { int - bmap(const char *fusepath, - size_t blocksize, - uint64_t *idx); + bmap(const fuse_req_ctx_t *ctx, + const char *fusepath, + size_t blocksize, + uint64_t *idx); } diff --git a/src/fuse_chmod.cpp b/src/fuse_chmod.cpp index dd58e590..aa3e1d59 100644 --- a/src/fuse_chmod.cpp +++ b/src/fuse_chmod.cpp @@ -94,8 +94,6 @@ int _chmod(const fs::path &fusepath_, const mode_t mode_) { - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); return ::_chmod(cfg.func.chmod.policy, cfg.func.getattr.policy, @@ -105,10 +103,12 @@ _chmod(const fs::path &fusepath_, } int -FUSE::chmod(const char *fusepath_, - mode_t mode_) +FUSE::chmod(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + mode_t mode_) { const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_->uid,ctx_->gid); return ::_chmod(fusepath,mode_); } diff --git a/src/fuse_chmod.hpp b/src/fuse_chmod.hpp index 5da49e17..c2a93af7 100644 --- a/src/fuse_chmod.hpp +++ b/src/fuse_chmod.hpp @@ -16,12 +16,15 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - chmod(const char *fusepath, - mode_t mode); + chmod(const fuse_req_ctx_t *ctx, + const char *fusepath, + mode_t mode); } diff --git a/src/fuse_chown.cpp b/src/fuse_chown.cpp index bda4464a..2653a44e 100644 --- a/src/fuse_chown.cpp +++ b/src/fuse_chown.cpp @@ -94,13 +94,13 @@ _chown(const Policy::Action &actionFunc_, } int -FUSE::chown(const char *fusepath_, - uid_t uid_, - gid_t gid_) +FUSE::chown(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + uid_t uid_, + gid_t gid_) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_->uid,ctx_->gid); return ::_chown(cfg.func.chown.policy, cfg.func.getattr.policy, diff --git a/src/fuse_chown.hpp b/src/fuse_chown.hpp index 77233cb0..0c654044 100644 --- a/src/fuse_chown.hpp +++ b/src/fuse_chown.hpp @@ -16,13 +16,16 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - chown(const char *fusepath, - uid_t uid, - gid_t gid); + chown(const fuse_req_ctx_t *ctx, + const char *fusepath, + uid_t uid, + gid_t gid); } diff --git a/src/fuse_copy_file_range.cpp b/src/fuse_copy_file_range.cpp index cd9277d3..c8b5dce6 100644 --- a/src/fuse_copy_file_range.cpp +++ b/src/fuse_copy_file_range.cpp @@ -47,14 +47,15 @@ _copy_file_range(const int src_fd_, } ssize_t -FUSE::copy_file_range(const fuse_file_info_t *src_ffi_, +FUSE::copy_file_range(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *src_ffi_, off_t src_off_, const fuse_file_info_t *dst_ffi_, off_t dst_off_, const size_t size_, const unsigned int flags_) { - FileInfo *src_fi = FileInfo::from_fh(src_ffi_->fh); + FileInfo *src_fi = FileInfo::from_fh(src_ffi_->fh); FileInfo *dst_fi = FileInfo::from_fh(dst_ffi_->fh); return ::_copy_file_range(src_fi->fd, diff --git a/src/fuse_copy_file_range.hpp b/src/fuse_copy_file_range.hpp index 4b7f7804..6b9df495 100644 --- a/src/fuse_copy_file_range.hpp +++ b/src/fuse_copy_file_range.hpp @@ -32,7 +32,8 @@ namespace FUSE { ssize_t - copy_file_range(const fuse_file_info_t *ffi_in, + copy_file_range(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_in, off_t offset_in, const fuse_file_info_t *ffi_out, off_t offset_out, diff --git a/src/fuse_create.cpp b/src/fuse_create.cpp index c8a6e328..f1be33ee 100644 --- a/src/fuse_create.cpp +++ b/src/fuse_create.cpp @@ -223,17 +223,17 @@ _(const PassthroughEnum e_, static int -_create_for_insert_lambda(const fuse_context *fc_, - const fs::path &fusepath_, - const mode_t mode_, - fuse_file_info_t *ffi_, - State::OpenFile *of_) +_create_for_insert_lambda(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + const mode_t mode_, + fuse_file_info_t *ffi_, + State::OpenFile *of_) { int rv; FileInfo *fi; - const ugid::Set ugid(fc_->uid,fc_->gid); + const ugid::Set ugid(ctx_->uid,ctx_->gid); - ::_config_to_ffi_flags(cfg,fc_->pid,ffi_); + ::_config_to_ffi_flags(cfg,ctx_->pid,ffi_); if(cfg.writeback_cache) ::_tweak_flags_writeback_cache(&ffi_->flags); ffi_->noflush = !::_calculate_flush(cfg.flushonclose, @@ -245,7 +245,7 @@ _create_for_insert_lambda(const fuse_context *fc_, fusepath_, ffi_, mode_, - fc_->umask); + ctx_->umask); if(rv == -EROFS) { cfg.branches.find_and_set_mode_ro(); @@ -255,7 +255,7 @@ _create_for_insert_lambda(const fuse_context *fc_, fusepath_, ffi_, mode_, - fc_->umask); + ctx_->umask); } if(rv < 0) @@ -278,7 +278,7 @@ _create_for_insert_lambda(const fuse_context *fc_, return 0; } - of_->backing_id = FUSE::passthrough_open(fc_,fi->fd); + of_->backing_id = FUSE::passthrough_open(fi->fd); if(of_->backing_id < 0) return 0; @@ -292,16 +292,16 @@ _create_for_insert_lambda(const fuse_context *fc_, static inline auto -_create_insert_lambda(const fuse_context *fc_, - const fs::path &fusepath_, - const mode_t mode_, - fuse_file_info_t *ffi_, - int *_rv_) +_create_insert_lambda(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + const mode_t mode_, + fuse_file_info_t *ffi_, + int *_rv_) { return [=](auto &val_) { - *_rv_ = ::_create_for_insert_lambda(fc_, + *_rv_ = ::_create_for_insert_lambda(ctx_, fusepath_, mode_, ffi_, @@ -326,24 +326,24 @@ _create_update_lambda() static int -_create(const fuse_context *fc_, - const fs::path &fusepath_, - mode_t mode_, - fuse_file_info_t *ffi_) +_create(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + mode_t mode_, + fuse_file_info_t *ffi_) { int rv; auto &of = state.open_files; rv = -EINVAL; - of.try_emplace_and_visit(fc_->nodeid, - ::_create_insert_lambda(fc_,fusepath_,mode_,ffi_,&rv), + of.try_emplace_and_visit(ctx_->nodeid, + ::_create_insert_lambda(ctx_,fusepath_,mode_,ffi_,&rv), ::_create_update_lambda()); // Can't abort an emplace_and_visit and can't assume another thread // hasn't created an entry since this failure so erase only if // ref_count is default (0). if(rv < 0) - of.erase_if(fc_->nodeid, + of.erase_if(ctx_->nodeid, [](const auto &val_) { return (val_.second.ref_count <= 0); @@ -353,12 +353,12 @@ _create(const fuse_context *fc_, } int -FUSE::create(const char *fusepath_, - mode_t mode_, - fuse_file_info_t *ffi_) +FUSE::create(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + mode_t mode_, + fuse_file_info_t *ffi_) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); + const fs::path fusepath{fusepath_}; - return ::_create(fc,fusepath,mode_,ffi_); + return ::_create(ctx_,fusepath,mode_,ffi_); } diff --git a/src/fuse_create.hpp b/src/fuse_create.hpp index 36a74d17..d14faeb6 100644 --- a/src/fuse_create.hpp +++ b/src/fuse_create.hpp @@ -24,7 +24,8 @@ namespace FUSE { int - create(const char *fusepath, - mode_t mode, - fuse_file_info_t *ffi); + create(const fuse_req_ctx_t *ctx, + const char *fusepath, + mode_t mode, + fuse_file_info_t *ffi); } diff --git a/src/fuse_fallocate.cpp b/src/fuse_fallocate.cpp index 8a774759..950d9133 100644 --- a/src/fuse_fallocate.cpp +++ b/src/fuse_fallocate.cpp @@ -40,18 +40,18 @@ _fallocate(const int fd_, } int -FUSE::fallocate(const uint64_t fh_, - int mode_, - off_t offset_, - off_t len_) +FUSE::fallocate(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + int mode_, + off_t offset_, + off_t len_) { uint64_t fh; - const fuse_context *fc = fuse_get_context(); fh = fh_; if(fh == 0) { - state.open_files.cvisit(fc->nodeid, + state.open_files.cvisit(ctx_->nodeid, [&](auto &val_) { fh = val_.second.fi->to_fh(); diff --git a/src/fuse_fallocate.hpp b/src/fuse_fallocate.hpp index cdc3ff24..3e2c759c 100644 --- a/src/fuse_fallocate.hpp +++ b/src/fuse_fallocate.hpp @@ -22,8 +22,9 @@ namespace FUSE { int - fallocate(const uint64_t fh, - int mode, - off_t offset, - off_t len); + fallocate(const fuse_req_ctx_t *ctx, + const uint64_t fh, + int mode, + off_t offset, + off_t len); } diff --git a/src/fuse_fchmod.cpp b/src/fuse_fchmod.cpp index 52e3ff05..7923a2ac 100644 --- a/src/fuse_fchmod.cpp +++ b/src/fuse_fchmod.cpp @@ -37,16 +37,16 @@ _fchmod(const int fd_, } int -FUSE::fchmod(const uint64_t fh_, - const mode_t mode_) +FUSE::fchmod(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + const mode_t mode_) { uint64_t fh; - const fuse_context *fc = fuse_get_context(); fh = fh_; if(fh == 0) { - state.open_files.cvisit(fc->nodeid, + state.open_files.cvisit(ctx_->nodeid, [&](auto &val_) { fh = val_.second.fi->to_fh(); diff --git a/src/fuse_fchmod.hpp b/src/fuse_fchmod.hpp index 99723f35..490780e2 100644 --- a/src/fuse_fchmod.hpp +++ b/src/fuse_fchmod.hpp @@ -18,12 +18,15 @@ #include "fuse.h" +#include "fuse_req_ctx.h" + #include namespace FUSE { int - fchmod(const uint64_t fh, - const mode_t mode); + fchmod(const fuse_req_ctx_t *ctx, + const uint64_t fh, + const mode_t mode); } diff --git a/src/fuse_fchown.cpp b/src/fuse_fchown.cpp index f85eea0b..143c4965 100644 --- a/src/fuse_fchown.cpp +++ b/src/fuse_fchown.cpp @@ -40,17 +40,17 @@ _fchown(const int fd_, } int -FUSE::fchown(const uint64_t fh_, - const uid_t uid_, - const gid_t gid_) +FUSE::fchown(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + const uid_t uid_, + const gid_t gid_) { uint64_t fh; - const fuse_context *fc = fuse_get_context(); fh = fh_; if(fh == 0) { - state.open_files.cvisit(fc->nodeid, + state.open_files.cvisit(ctx_->nodeid, [&](auto &val_) { fh = val_.second.fi->to_fh(); diff --git a/src/fuse_fchown.hpp b/src/fuse_fchown.hpp index f743a910..682cb972 100644 --- a/src/fuse_fchown.hpp +++ b/src/fuse_fchown.hpp @@ -22,7 +22,8 @@ namespace FUSE { int - fchown(const uint64_t fh, - uid_t uid, - gid_t gid); + fchown(const fuse_req_ctx_t *ctx, + const uint64_t fh, + uid_t uid, + gid_t gid); } diff --git a/src/fuse_fgetattr.cpp b/src/fuse_fgetattr.cpp index e4f36719..524a5da2 100644 --- a/src/fuse_fgetattr.cpp +++ b/src/fuse_fgetattr.cpp @@ -46,18 +46,18 @@ _fgetattr(const FileInfo *fi_, int -FUSE::fgetattr(const uint64_t fh_, - struct stat *st_, - fuse_timeouts_t *timeout_) +FUSE::fgetattr(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + struct stat *st_, + fuse_timeouts_t *timeout_) { int rv; uint64_t fh; - const fuse_context *fc = fuse_get_context(); fh = fh_; if(fh == 0) { - state.open_files.cvisit(fc->nodeid, + state.open_files.cvisit(ctx_->nodeid, [&](const auto &val_) { fh = val_.second.fi->to_fh(); diff --git a/src/fuse_fgetattr.hpp b/src/fuse_fgetattr.hpp index 9a9def7c..7323837d 100644 --- a/src/fuse_fgetattr.hpp +++ b/src/fuse_fgetattr.hpp @@ -26,7 +26,8 @@ namespace FUSE { int - fgetattr(const uint64_t fh, - struct stat *st, - fuse_timeouts_t *timeout); + fgetattr(const fuse_req_ctx_t *ctx, + const uint64_t fh, + struct stat *st, + fuse_timeouts_t *timeout); } diff --git a/src/fuse_flock.cpp b/src/fuse_flock.cpp index 10aa96ac..c511eaae 100644 --- a/src/fuse_flock.cpp +++ b/src/fuse_flock.cpp @@ -37,16 +37,16 @@ _flock(const int fd_, } int -FUSE::flock(const fuse_file_info_t *ffi_, +FUSE::flock(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, int op_) { uint64_t fh; - const fuse_context *fc = fuse_get_context(); fh = ffi_->fh; if(fh == 0) { - state.open_files.cvisit(fc->nodeid, + state.open_files.cvisit(ctx_->nodeid, [&](const auto &val_) { fh = val_.second.fi->to_fh(); diff --git a/src/fuse_flock.hpp b/src/fuse_flock.hpp index 194da4de..2d2d0b46 100644 --- a/src/fuse_flock.hpp +++ b/src/fuse_flock.hpp @@ -22,6 +22,7 @@ namespace FUSE { int - flock(const fuse_file_info_t *ffi, + flock(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, int op); } diff --git a/src/fuse_flush.cpp b/src/fuse_flush.cpp index 7e92461a..5bc3989c 100644 --- a/src/fuse_flush.cpp +++ b/src/fuse_flush.cpp @@ -38,7 +38,8 @@ _flush(const int fd_) } int -FUSE::flush(const fuse_file_info_t *ffi_) +FUSE::flush(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_) { FileInfo *fi = FileInfo::from_fh(ffi_->fh); diff --git a/src/fuse_flush.hpp b/src/fuse_flush.hpp index b8d447c3..e00bf4b9 100644 --- a/src/fuse_flush.hpp +++ b/src/fuse_flush.hpp @@ -22,5 +22,6 @@ namespace FUSE { int - flush(const fuse_file_info_t *ffi); + flush(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi); } diff --git a/src/fuse_fsync.cpp b/src/fuse_fsync.cpp index 3a25fcb8..6024a2f4 100644 --- a/src/fuse_fsync.cpp +++ b/src/fuse_fsync.cpp @@ -43,8 +43,9 @@ _fsync(const int fd_, } int -FUSE::fsync(const uint64_t fh_, - int isdatasync_) +FUSE::fsync(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + int isdatasync_) { FileInfo *fi = FileInfo::from_fh(fh_); diff --git a/src/fuse_fsync.hpp b/src/fuse_fsync.hpp index d62574e1..56720268 100644 --- a/src/fuse_fsync.hpp +++ b/src/fuse_fsync.hpp @@ -22,7 +22,8 @@ namespace FUSE { int - fsync(const uint64_t fh, - int isdatasync); + fsync(const fuse_req_ctx_t *ctx, + const uint64_t fh, + int isdatasync); } diff --git a/src/fuse_fsyncdir.cpp b/src/fuse_fsyncdir.cpp index 1b56deca..add63fc3 100644 --- a/src/fuse_fsyncdir.cpp +++ b/src/fuse_fsyncdir.cpp @@ -35,7 +35,8 @@ _fsyncdir(const DirInfo *di_, } int -FUSE::fsyncdir(const fuse_file_info_t *ffi_, +FUSE::fsyncdir(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, int isdatasync_) { DirInfo *di = DirInfo::from_fh(ffi_->fh); diff --git a/src/fuse_fsyncdir.hpp b/src/fuse_fsyncdir.hpp index e1eba800..aa12c7cf 100644 --- a/src/fuse_fsyncdir.hpp +++ b/src/fuse_fsyncdir.hpp @@ -22,6 +22,7 @@ namespace FUSE { int - fsyncdir(const fuse_file_info_t *ffi, + fsyncdir(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, int isdatasync); } diff --git a/src/fuse_ftruncate.cpp b/src/fuse_ftruncate.cpp index 61c24c40..0db78535 100644 --- a/src/fuse_ftruncate.cpp +++ b/src/fuse_ftruncate.cpp @@ -37,16 +37,16 @@ _ftruncate(const int fd_, } int -FUSE::ftruncate(const uint64_t fh_, - off_t size_) +FUSE::ftruncate(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + off_t size_) { uint64_t fh; - const fuse_context *fc = fuse_get_context(); fh = fh_; if(fh == 0) { - state.open_files.cvisit(fc->nodeid, + state.open_files.cvisit(ctx_->nodeid, [&](auto &val_) { fh = val_.second.fi->to_fh(); diff --git a/src/fuse_ftruncate.hpp b/src/fuse_ftruncate.hpp index 0b7751d2..1b0fafb3 100644 --- a/src/fuse_ftruncate.hpp +++ b/src/fuse_ftruncate.hpp @@ -25,6 +25,7 @@ namespace FUSE { int - ftruncate(const uint64_t fh, - off_t size); + ftruncate(const fuse_req_ctx_t *ctx, + const uint64_t fh, + off_t size); } diff --git a/src/fuse_futimens.cpp b/src/fuse_futimens.cpp index 605027c0..1f44635a 100644 --- a/src/fuse_futimens.cpp +++ b/src/fuse_futimens.cpp @@ -39,16 +39,16 @@ _futimens(const int fd_, } int -FUSE::futimens(const uint64_t fh_, - const struct timespec ts_[2]) +FUSE::futimens(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + const struct timespec ts_[2]) { uint64_t fh; - const fuse_context *fc = fuse_get_context(); fh = fh_; if(fh == 0) { - state.open_files.cvisit(fc->nodeid, + state.open_files.cvisit(ctx_->nodeid, [&](const auto &val_) { fh = val_.second.fi->to_fh(); diff --git a/src/fuse_futimens.hpp b/src/fuse_futimens.hpp index 37f69233..a0b84cea 100644 --- a/src/fuse_futimens.hpp +++ b/src/fuse_futimens.hpp @@ -24,6 +24,7 @@ namespace FUSE { int - futimens(const uint64_t fh, - const timespec ts[2]); + futimens(const fuse_req_ctx_t *ctx, + const uint64_t fh, + const timespec ts[2]); } diff --git a/src/fuse_getattr.cpp b/src/fuse_getattr.cpp index ff937400..2dfe0096 100644 --- a/src/fuse_getattr.cpp +++ b/src/fuse_getattr.cpp @@ -177,8 +177,6 @@ _getattr(const fs::path &fusepath_, fuse_timeouts_t *timeout_) { int rv; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); rv = ::_getattr(cfg.func.getattr.policy, cfg.branches, @@ -199,13 +197,25 @@ _getattr(const fs::path &fusepath_, } int -FUSE::getattr(const char *fusepath_, - struct stat *st_, - fuse_timeouts_t *timeout_) +FUSE::getattr(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + struct stat *st_, + fuse_timeouts_t *timeout_) { const fs::path fusepath{fusepath_}; - return FUSE::getattr(fusepath,st_,timeout_); + return FUSE::getattr(ctx_,fusepath,st_,timeout_); +} + +int +FUSE::getattr(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + struct stat *st_, + fuse_timeouts_t *timeout_) +{ + const ugid::Set ugid(ctx_); + + return FUSE::getattr(fusepath_,st_,timeout_); } int diff --git a/src/fuse_getattr.hpp b/src/fuse_getattr.hpp index 8cc0c7f8..8017d418 100644 --- a/src/fuse_getattr.hpp +++ b/src/fuse_getattr.hpp @@ -28,9 +28,16 @@ namespace FUSE { int - getattr(const char *fusepath, - struct stat *buf, - fuse_timeouts_t *timeout); + getattr(const fuse_req_ctx_t *ctx, + const char *fusepath, + struct stat *buf, + fuse_timeouts_t *timeout); + + int + getattr(const fuse_req_ctx_t *ctx, + const fs::path &fusepath, + struct stat *buf, + fuse_timeouts_t *timeout); int getattr(const fs::path &fusepath, diff --git a/src/fuse_getxattr.cpp b/src/fuse_getxattr.cpp index 0cc4e4f9..5da8b12f 100644 --- a/src/fuse_getxattr.cpp +++ b/src/fuse_getxattr.cpp @@ -172,10 +172,11 @@ _getxattr(const Policy::Search &searchFunc_, } int -FUSE::getxattr(const char *fusepath_, - const char *attrname_, - char *attrvalue_, - size_t attrvalue_size_) +FUSE::getxattr(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + const char *attrname_, + char *attrvalue_, + size_t attrvalue_size_) { const fs::path fusepath{fusepath_}; @@ -192,8 +193,7 @@ FUSE::getxattr(const char *fusepath_, if(cfg.xattr.to_int()) return -cfg.xattr.to_int(); - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const ugid::Set ugid(ctx_->uid,ctx_->gid); return ::_getxattr(cfg.func.getxattr.policy, cfg.branches, diff --git a/src/fuse_getxattr.hpp b/src/fuse_getxattr.hpp index a9f550e1..341541f7 100644 --- a/src/fuse_getxattr.hpp +++ b/src/fuse_getxattr.hpp @@ -16,14 +16,17 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - getxattr(const char *fusepath, - const char *attrname, - char *attrvalue, - size_t attrvalue_size); + getxattr(const fuse_req_ctx_t *ctx, + const char *fusepath, + const char *attrname, + char *attrvalue, + size_t attrvalue_size); } diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index 9c837613..28e5a086 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -107,14 +107,14 @@ _ioctl(const int fd_, static int -_ioctl_file(const fuse_file_info_t *ffi_, +_ioctl_file(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, const uint32_t cmd_, void *data_, uint32_t *out_bufsz_) { - FileInfo *fi = FileInfo::from_fh(ffi_->fh); - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + FileInfo *fi = FileInfo::from_fh(ffi_->fh); + const ugid::Set ugid(ctx_); return ::_ioctl(fi->fd,cmd_,data_,out_bufsz_); } @@ -156,14 +156,14 @@ _ioctl_dir_base(const Policy::Search &searchFunc_, static int -_ioctl_dir(const fuse_file_info_t *ffi_, +_ioctl_dir(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, const uint32_t cmd_, void *data_, uint32_t *out_bufsz_) { - DirInfo *di = DirInfo::from_fh(ffi_->fh); - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + DirInfo *di = DirInfo::from_fh(ffi_->fh); + const ugid::Set ugid(ctx_); return ::_ioctl_dir_base(cfg.func.open.policy, cfg.branches, @@ -181,7 +181,8 @@ _is_btrfs_ioctl_cmd(const unsigned long cmd_) } int -FUSE::ioctl(const fuse_file_info_t *ffi_, +FUSE::ioctl(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, unsigned long cmd_, void *arg_, unsigned int flags_, @@ -192,7 +193,7 @@ FUSE::ioctl(const fuse_file_info_t *ffi_, return -ENOTTY; if(flags_ & FUSE_IOCTL_DIR) - return ::_ioctl_dir(ffi_,cmd_,data_,out_bufsz_); + return ::_ioctl_dir(ctx_,ffi_,cmd_,data_,out_bufsz_); - return ::_ioctl_file(ffi_,cmd_,data_,out_bufsz_); + return ::_ioctl_file(ctx_,ffi_,cmd_,data_,out_bufsz_); } diff --git a/src/fuse_ioctl.hpp b/src/fuse_ioctl.hpp index 11ea6233..e1d95459 100644 --- a/src/fuse_ioctl.hpp +++ b/src/fuse_ioctl.hpp @@ -24,7 +24,8 @@ namespace FUSE { int - ioctl(const fuse_file_info_t *ffi, + ioctl(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, unsigned long cmd, void *arg, unsigned int flags, diff --git a/src/fuse_link.cpp b/src/fuse_link.cpp index be39ed24..9bbc4f7f 100644 --- a/src/fuse_link.cpp +++ b/src/fuse_link.cpp @@ -165,36 +165,35 @@ _link_preserve_path(const Policy::Action &actionFunc_, static int -_link(Config &cfg_, - const fs::path &oldpath_, +_link(const fs::path &oldpath_, const fs::path &newpath_, struct stat *st_) { - if(cfg_.func.create.policy.path_preserving() && !cfg_.ignorepponrename) - return ::_link_preserve_path(cfg_.func.link.policy, - cfg_.branches, + if(cfg.func.create.policy.path_preserving() && !cfg.ignorepponrename) + return ::_link_preserve_path(cfg.func.link.policy, + cfg.branches, oldpath_, newpath_, st_); - return ::_link_create_path(cfg_.func.getattr.policy, - cfg_.func.link.policy, - cfg_.branches, + return ::_link_create_path(cfg.func.getattr.policy, + cfg.func.link.policy, + cfg.branches, oldpath_, newpath_); } static int -_link(Config &cfg_, - const fs::path &oldpath_, - const fs::path &newpath_, - struct stat *st_, - fuse_timeouts_t *timeouts_) +_link(const fuse_req_ctx_t *ctx_, + const fs::path &oldpath_, + const fs::path &newpath_, + struct stat *st_, + fuse_timeouts_t *timeouts_) { int rv; - rv = ::_link(cfg_,oldpath_,newpath_,st_); + rv = ::_link(oldpath_,newpath_,st_); if(rv < 0) return rv; @@ -203,10 +202,11 @@ _link(Config &cfg_, static int -_link_exdev_rel_symlink(const fs::path &oldpath_, - const fs::path &newpath_, - struct stat *st_, - fuse_timeouts_t *timeouts_) +_link_exdev_rel_symlink(const fuse_req_ctx_t *ctx_, + const fs::path &oldpath_, + const fs::path &newpath_, + struct stat *st_, + fuse_timeouts_t *timeouts_) { int rv; fs::path target(oldpath_); @@ -214,9 +214,9 @@ _link_exdev_rel_symlink(const fs::path &oldpath_, target = target.lexically_relative(linkpath.parent_path()); - rv = FUSE::symlink(target.c_str(),linkpath); + rv = FUSE::symlink(ctx_,target.c_str(),linkpath); if(rv == 0) - rv = FUSE::getattr(oldpath_,st_,timeouts_); + rv = FUSE::getattr(ctx_,oldpath_,st_,timeouts_); // Disable caching since we created a symlink but should be a regular. timeouts_->attr = 0; @@ -227,7 +227,8 @@ _link_exdev_rel_symlink(const fs::path &oldpath_, static int -_link_exdev_abs_base_symlink(const Policy::Search &openPolicy_, +_link_exdev_abs_base_symlink(const fuse_req_ctx_t *ctx_, + const Policy::Search &openPolicy_, const Branches::Ptr &ibranches_, const fs::path &oldpath_, const fs::path &newpath_, @@ -244,9 +245,9 @@ _link_exdev_abs_base_symlink(const Policy::Search &openPolicy_, target = obranches[0]->path / oldpath_; - rv = FUSE::symlink(target.c_str(),newpath_); + rv = FUSE::symlink(ctx_,target.c_str(),newpath_); if(rv == 0) - rv = FUSE::getattr(oldpath_,st_,timeouts_); + rv = FUSE::getattr(ctx_,oldpath_,st_,timeouts_); // Disable caching since we created a symlink but should be a regular. timeouts_->attr = 0; @@ -257,11 +258,12 @@ _link_exdev_abs_base_symlink(const Policy::Search &openPolicy_, static int -_link_exdev_abs_pool_symlink(const fs::path &mount_, - const fs::path &oldpath_, - const fs::path &newpath_, - struct stat *st_, - fuse_timeouts_t *timeouts_) +_link_exdev_abs_pool_symlink(const fuse_req_ctx_t *ctx_, + const fs::path &mount_, + const fs::path &oldpath_, + const fs::path &newpath_, + struct stat *st_, + fuse_timeouts_t *timeouts_) { int rv; StrVec basepaths; @@ -269,9 +271,9 @@ _link_exdev_abs_pool_symlink(const fs::path &mount_, target = mount_ / oldpath_; - rv = FUSE::symlink(target.c_str(),newpath_); + rv = FUSE::symlink(ctx_,target.c_str(),newpath_); if(rv == 0) - rv = FUSE::getattr(oldpath_,st_,timeouts_); + rv = FUSE::getattr(ctx_,oldpath_,st_,timeouts_); // Disable caching since we created a symlink but should be a regular. timeouts_->attr = 0; @@ -282,30 +284,33 @@ _link_exdev_abs_pool_symlink(const fs::path &mount_, static int -_link_exdev(Config &cfg_, - const fs::path &oldpath_, - const fs::path &newpath_, - struct stat *st_, - fuse_timeouts_t *timeouts_) +_link_exdev(const fuse_req_ctx_t *ctx_, + const fs::path &oldpath_, + const fs::path &newpath_, + struct stat *st_, + fuse_timeouts_t *timeouts_) { - switch(cfg_.link_exdev) + switch(cfg.link_exdev) { case LinkEXDEV::ENUM::PASSTHROUGH: return -EXDEV; case LinkEXDEV::ENUM::REL_SYMLINK: - return ::_link_exdev_rel_symlink(oldpath_, + return ::_link_exdev_rel_symlink(ctx_, + oldpath_, newpath_, st_, timeouts_); case LinkEXDEV::ENUM::ABS_BASE_SYMLINK: - return ::_link_exdev_abs_base_symlink(cfg_.func.open.policy, - cfg_.branches, + return ::_link_exdev_abs_base_symlink(ctx_, + cfg.func.open.policy, + cfg.branches, oldpath_, newpath_, st_, timeouts_); case LinkEXDEV::ENUM::ABS_POOL_SYMLINK: - return ::_link_exdev_abs_pool_symlink(cfg_.mountpoint, + return ::_link_exdev_abs_pool_symlink(ctx_, + cfg.mountpoint, oldpath_, newpath_, st_, @@ -316,20 +321,20 @@ _link_exdev(Config &cfg_, } int -FUSE::link(const char *oldpath_, - const char *newpath_, - struct stat *st_, - fuse_timeouts_t *timeouts_) +FUSE::link(const fuse_req_ctx_t *ctx_, + const char *oldpath_, + const char *newpath_, + struct stat *st_, + fuse_timeouts_t *timeouts_) { int rv; - const fs::path oldpath{oldpath_}; - const fs::path newpath{newpath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path oldpath{oldpath_}; + const fs::path newpath{newpath_}; + const ugid::Set ugid(ctx_); - rv = ::_link(cfg,oldpath,newpath,st_,timeouts_); + rv = ::_link(ctx_,oldpath,newpath,st_,timeouts_); if(rv == -EXDEV) - rv = ::_link_exdev(cfg,oldpath,newpath,st_,timeouts_); + rv = ::_link_exdev(ctx_,oldpath,newpath,st_,timeouts_); return rv; } diff --git a/src/fuse_link.hpp b/src/fuse_link.hpp index 2711b931..f3475eb0 100644 --- a/src/fuse_link.hpp +++ b/src/fuse_link.hpp @@ -22,8 +22,9 @@ namespace FUSE { int - link(const char *oldpath, - const char *newpath, - struct stat *st, - fuse_timeouts_t *timeouts); + link(const fuse_req_ctx_t *ctx, + const char *oldpath, + const char *newpath, + struct stat *st, + fuse_timeouts_t *timeouts); } diff --git a/src/fuse_listxattr.cpp b/src/fuse_listxattr.cpp index 8ea9c654..e7cadca8 100644 --- a/src/fuse_listxattr.cpp +++ b/src/fuse_listxattr.cpp @@ -123,9 +123,10 @@ _listxattr(const Policy::Search &searchFunc_, } int -FUSE::listxattr(const char *fusepath_, - char *list_, - size_t size_) +FUSE::listxattr(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + char *list_, + size_t size_) { const fs::path fusepath{fusepath_}; @@ -142,8 +143,7 @@ FUSE::listxattr(const char *fusepath_, return -ENOSYS; } - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const ugid::Set ugid(ctx_); return ::_listxattr(cfg.func.listxattr.policy, cfg.branches, diff --git a/src/fuse_listxattr.hpp b/src/fuse_listxattr.hpp index 45906614..34d1ca8b 100644 --- a/src/fuse_listxattr.hpp +++ b/src/fuse_listxattr.hpp @@ -16,12 +16,15 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - listxattr(const char *fusepath, - char *buf, - size_t count); + listxattr(const fuse_req_ctx_t *ctx, + const char *fusepath, + char *buf, + size_t count); } diff --git a/src/fuse_lock.cpp b/src/fuse_lock.cpp index 813405f2..f5b33067 100644 --- a/src/fuse_lock.cpp +++ b/src/fuse_lock.cpp @@ -24,7 +24,8 @@ int -FUSE::lock(const fuse_file_info_t *ffi, +FUSE::lock(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, int cmd, struct flock *flock) { diff --git a/src/fuse_lock.hpp b/src/fuse_lock.hpp index f6c08c63..10cf826c 100644 --- a/src/fuse_lock.hpp +++ b/src/fuse_lock.hpp @@ -23,7 +23,8 @@ namespace FUSE { int - lock(const fuse_file_info_t *ffi, + lock(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, int cmd, struct flock *flock); } diff --git a/src/fuse_mkdir.cpp b/src/fuse_mkdir.cpp index 3193062a..883f4ac2 100644 --- a/src/fuse_mkdir.cpp +++ b/src/fuse_mkdir.cpp @@ -125,20 +125,20 @@ _mkdir(const Policy::Search &getattrPolicy_, } int -FUSE::mkdir(const char *fusepath_, - mode_t mode_) +FUSE::mkdir(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + mode_t mode_) { int rv; - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_); rv = ::_mkdir(cfg.func.getattr.policy, cfg.func.mkdir.policy, cfg.branches, fusepath, mode_, - fc->umask); + ctx_->umask); if(rv == -EROFS) { cfg.branches.find_and_set_mode_ro(); @@ -147,7 +147,7 @@ FUSE::mkdir(const char *fusepath_, cfg.branches, fusepath, mode_, - fc->umask); + ctx_->umask); } return rv; diff --git a/src/fuse_mkdir.hpp b/src/fuse_mkdir.hpp index e410a600..5ae8574a 100644 --- a/src/fuse_mkdir.hpp +++ b/src/fuse_mkdir.hpp @@ -16,12 +16,15 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - mkdir(const char *fusepath, - mode_t mode); + mkdir(const fuse_req_ctx_t *ctx, + const char *fusepath, + mode_t mode); } diff --git a/src/fuse_mknod.cpp b/src/fuse_mknod.cpp index 2b45c776..80d4f853 100644 --- a/src/fuse_mknod.cpp +++ b/src/fuse_mknod.cpp @@ -132,21 +132,21 @@ _mknod(const Policy::Search &searchFunc_, } int -FUSE::mknod(const char *fusepath_, - mode_t mode_, - dev_t rdev_) +FUSE::mknod(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + mode_t mode_, + dev_t rdev_) { int rv; - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_); rv = ::_mknod(cfg.func.getattr.policy, cfg.func.mknod.policy, cfg.branches, fusepath, mode_, - fc->umask, + ctx_->umask, rdev_); if(rv == -EROFS) { @@ -156,7 +156,7 @@ FUSE::mknod(const char *fusepath_, cfg.branches, fusepath, mode_, - fc->umask, + ctx_->umask, rdev_); } diff --git a/src/fuse_mknod.hpp b/src/fuse_mknod.hpp index 138a0893..4fad72f0 100644 --- a/src/fuse_mknod.hpp +++ b/src/fuse_mknod.hpp @@ -17,13 +17,16 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - mknod(const char *fusepath, - mode_t mode, - dev_t rdev); + mknod(const fuse_req_ctx_t *ctx, + const char *fusepath, + mode_t mode, + dev_t rdev); } diff --git a/src/fuse_open.cpp b/src/fuse_open.cpp index dfec7e37..a19f41d7 100644 --- a/src/fuse_open.cpp +++ b/src/fuse_open.cpp @@ -280,16 +280,16 @@ _(const PassthroughEnum e_, static int -_open_for_insert_lambda(const fuse_context *fc_, - const fs::path &fusepath_, - fuse_file_info_t *ffi_, - State::OpenFile *of_) +_open_for_insert_lambda(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + fuse_file_info_t *ffi_, + State::OpenFile *of_) { int rv; FileInfo *fi; - const ugid::Set ugid(fc_->uid,fc_->gid); + const ugid::Set ugid(ctx_); - ::_config_to_ffi_flags(cfg,fc_->pid,ffi_); + ::_config_to_ffi_flags(cfg,ctx_->pid,ffi_); if(cfg.writeback_cache) ::_tweak_flags_writeback_cache(&ffi_->flags); @@ -324,7 +324,7 @@ _open_for_insert_lambda(const fuse_context *fc_, return 0; } - of_->backing_id = FUSE::passthrough_open(fc_,fi->fd); + of_->backing_id = FUSE::passthrough_open(fi->fd); if(of_->backing_id <= 0) return 0; @@ -337,15 +337,15 @@ _open_for_insert_lambda(const fuse_context *fc_, static int -_open_for_update_lambda(const fuse_context *fc_, - const fs::path &fusepath_, - fuse_file_info_t *ffi_, - State::OpenFile *of_) +_open_for_update_lambda(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + fuse_file_info_t *ffi_, + State::OpenFile *of_) { int rv; - const ugid::Set ugid(fc_->uid,fc_->gid); + const ugid::Set ugid(ctx_); - ::_config_to_ffi_flags(cfg,fc_->pid,ffi_); + ::_config_to_ffi_flags(cfg,ctx_->pid,ffi_); if(cfg.writeback_cache) ::_tweak_flags_writeback_cache(&ffi_->flags); @@ -375,15 +375,15 @@ _open_for_update_lambda(const fuse_context *fc_, static inline auto -_open_insert_lambda(const fuse_context *fc_, - const fs::path &fusepath_, - fuse_file_info_t *ffi_, - int *rv_) +_open_insert_lambda(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + fuse_file_info_t *ffi_, + int *rv_) { return [=](auto &val_) { - *rv_ = ::_open_for_insert_lambda(fc_, + *rv_ = ::_open_for_insert_lambda(ctx_, fusepath_, ffi_, &val_.second); @@ -393,10 +393,10 @@ _open_insert_lambda(const fuse_context *fc_, static inline auto -_open_update_lambda(const fuse_context *fc_, - const fs::path &fusepath_, - fuse_file_info_t *ffi_, - int *rv_) +_open_update_lambda(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + fuse_file_info_t *ffi_, + int *rv_) { return [=](auto &val_) @@ -406,14 +406,14 @@ _open_update_lambda(const fuse_context *fc_, // to abort an insert. if(val_.second.ref_count <= 0) { - *rv_ = ::_open_for_insert_lambda(fc_, + *rv_ = ::_open_for_insert_lambda(ctx_, fusepath_, ffi_, &val_.second); return; } - *rv_ = ::_open_for_update_lambda(fc_, + *rv_ = ::_open_for_update_lambda(ctx_, fusepath_, ffi_, &val_.second); @@ -422,23 +422,23 @@ _open_update_lambda(const fuse_context *fc_, static int -_open(const fuse_context *fc_, - const fs::path &fusepath_, - fuse_file_info_t *ffi_) +_open(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + fuse_file_info_t *ffi_) { int rv; auto &of = state.open_files; rv = -EINVAL; - of.try_emplace_and_visit(fc_->nodeid, - ::_open_insert_lambda(fc_,fusepath_,ffi_,&rv), - ::_open_update_lambda(fc_,fusepath_,ffi_,&rv)); + of.try_emplace_and_visit(ctx_->nodeid, + ::_open_insert_lambda(ctx_,fusepath_,ffi_,&rv), + ::_open_update_lambda(ctx_,fusepath_,ffi_,&rv)); // Can't abort an emplace_and_visit and can't assume another thread // hasn't created an entry since this failure so erase only if // ref_count is default (0). if(rv < 0) - of.erase_if(fc_->nodeid, + of.erase_if(ctx_->nodeid, [](auto &val_) { return (val_.second.ref_count <= 0); @@ -449,11 +449,11 @@ _open(const fuse_context *fc_, int -FUSE::open(const char *fusepath_, - fuse_file_info_t *ffi_) +FUSE::open(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + fuse_file_info_t *ffi_) { const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - return ::_open(fc,fusepath,ffi_); + return ::_open(ctx_,fusepath,ffi_); } diff --git a/src/fuse_open.hpp b/src/fuse_open.hpp index 34c758bc..84a5260e 100644 --- a/src/fuse_open.hpp +++ b/src/fuse_open.hpp @@ -22,6 +22,7 @@ namespace FUSE { int - open(const char *fusepath, - fuse_file_info_t *ffi); + open(const fuse_req_ctx_t *ctx, + const char *fusepath, + fuse_file_info_t *ffi); } diff --git a/src/fuse_opendir.cpp b/src/fuse_opendir.cpp index c2e09eac..76109d14 100644 --- a/src/fuse_opendir.cpp +++ b/src/fuse_opendir.cpp @@ -23,8 +23,9 @@ int -FUSE::opendir(const char *fusepath_, - fuse_file_info_t *ffi_) +FUSE::opendir(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + fuse_file_info_t *ffi_) { DirInfo *di; diff --git a/src/fuse_opendir.hpp b/src/fuse_opendir.hpp index 1a2dca84..7b5ae5ed 100644 --- a/src/fuse_opendir.hpp +++ b/src/fuse_opendir.hpp @@ -22,6 +22,7 @@ namespace FUSE { int - opendir(const char *fusepath, - fuse_file_info_t *ffi); + opendir(const fuse_req_ctx_t *ctx, + const char *fusepath, + fuse_file_info_t *ffi); } diff --git a/src/fuse_passthrough.hpp b/src/fuse_passthrough.hpp index 91338b22..fcccf817 100644 --- a/src/fuse_passthrough.hpp +++ b/src/fuse_passthrough.hpp @@ -4,27 +4,28 @@ #include "fuse.h" +// Becoming root is required due to current security policies within +// the kernel. This may be able to be changed in the future. + namespace FUSE { static inline int - passthrough_open(const fuse_context *fc_, - const int fd_) + passthrough_open(const int fd_) { const ugid::SetRootGuard _; - return fuse_passthrough_open(fc_,fd_); + return fuse_passthrough_open(fd_); } static inline int - passthrough_close(const fuse_context *fc_, - const int backing_id_) + passthrough_close(const int backing_id_) { const ugid::SetRootGuard _; - return fuse_passthrough_close(fc_,backing_id_); + return fuse_passthrough_close(backing_id_); } } diff --git a/src/fuse_poll.cpp b/src/fuse_poll.cpp index e6fe3f3e..616a3a92 100644 --- a/src/fuse_poll.cpp +++ b/src/fuse_poll.cpp @@ -24,10 +24,12 @@ int -FUSE::poll(const fuse_file_info_t *ffi_, +FUSE::poll(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, fuse_pollhandle_t *ph_, unsigned *reventsp_) { + (void)ctx_; (void)ffi_; (void)ph_; (void)reventsp_; diff --git a/src/fuse_poll.hpp b/src/fuse_poll.hpp index 37c1be2d..1df68f92 100644 --- a/src/fuse_poll.hpp +++ b/src/fuse_poll.hpp @@ -24,7 +24,8 @@ namespace FUSE { int - poll(const fuse_file_info_t *ffi, + poll(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, fuse_pollhandle_t *ph, unsigned *reventsp); } diff --git a/src/fuse_read.cpp b/src/fuse_read.cpp index dc2d0979..e4ce2054 100644 --- a/src/fuse_read.cpp +++ b/src/fuse_read.cpp @@ -56,12 +56,13 @@ _read_cached(const int fd_, } int -FUSE::read(const fuse_file_info_t *ffi_, +FUSE::read(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, char *buf_, size_t size_, off_t offset_) { - ioprio::SetFrom iop(fuse_get_context()->pid); + ioprio::SetFrom iop(ctx_->pid); FileInfo *fi = FileInfo::from_fh(ffi_->fh); if(fi->direct_io) @@ -71,7 +72,8 @@ FUSE::read(const fuse_file_info_t *ffi_, } int -FUSE::read_null(const fuse_file_info_t *ffi_, +FUSE::read_null(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, char *buf_, size_t size_, off_t offset_) diff --git a/src/fuse_read.hpp b/src/fuse_read.hpp index 8e641f6d..30b0f651 100644 --- a/src/fuse_read.hpp +++ b/src/fuse_read.hpp @@ -24,13 +24,15 @@ namespace FUSE { int - read(const fuse_file_info_t *ffi, + read(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, char *buf, size_t size, off_t offset); int - read_null(const fuse_file_info_t *ffi, + read_null(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, char *buf, size_t size, off_t offset); diff --git a/src/fuse_readdir.cpp b/src/fuse_readdir.cpp index 3b02f1cd..8c0f8d26 100644 --- a/src/fuse_readdir.cpp +++ b/src/fuse_readdir.cpp @@ -31,10 +31,11 @@ int -FUSE::readdir(const fuse_file_info_t *ffi_, +FUSE::readdir(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, fuse_dirents_t *buf_) { - return cfg.readdir(ffi_,buf_); + return cfg.readdir(ctx_,ffi_,buf_); } FUSE::ReadDir::ReadDir(const std::string_view s_) @@ -99,7 +100,8 @@ _handle_ENOENT(const fuse_file_info_t *ffi_, } int -FUSE::ReadDir::operator()(const fuse_file_info_t *ffi_, +FUSE::ReadDir::operator()(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, fuse_dirents_t *buf_) { int rv; @@ -108,7 +110,7 @@ FUSE::ReadDir::operator()(const fuse_file_info_t *ffi_, readdir = std::atomic_load(&_impl); assert(readdir); - rv = (*readdir)(ffi_,buf_); + rv = (*readdir)(ctx_,ffi_,buf_); if(rv == -ENOENT) return ::_handle_ENOENT(ffi_,buf_); diff --git a/src/fuse_readdir.hpp b/src/fuse_readdir.hpp index abc800aa..ab3e44ec 100644 --- a/src/fuse_readdir.hpp +++ b/src/fuse_readdir.hpp @@ -28,7 +28,8 @@ namespace FUSE { - int readdir(fuse_file_info_t const *ffi, + int readdir(const fuse_req_ctx_t *ctx, + fuse_file_info_t const *ffi, fuse_dirents_t *buf); } @@ -49,7 +50,8 @@ namespace FUSE int from_string(const std::string_view); public: - int operator()(fuse_file_info_t const *ffi, + int operator()(const fuse_req_ctx_t *ctx, + fuse_file_info_t const *ffi, fuse_dirents_t *buf); public: diff --git a/src/fuse_readdir_base.hpp b/src/fuse_readdir_base.hpp index 7043ff37..7e598bdd 100644 --- a/src/fuse_readdir_base.hpp +++ b/src/fuse_readdir_base.hpp @@ -30,7 +30,8 @@ namespace FUSE virtual ~ReadDirBase() {}; public: - virtual int operator()(const fuse_file_info_t *ffi, + virtual int operator()(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, fuse_dirents_t *buf) = 0; }; } diff --git a/src/fuse_readdir_cor.cpp b/src/fuse_readdir_cor.cpp index c0e7141e..f61a0e61 100644 --- a/src/fuse_readdir_cor.cpp +++ b/src/fuse_readdir_cor.cpp @@ -86,16 +86,16 @@ _concurrent_readdir(ThreadPool &tp_, } int -FUSE::ReadDirCOR::operator()(const fuse_file_info_t *ffi_, +FUSE::ReadDirCOR::operator()(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, fuse_dirents_t *dirents_) { - DirInfo *di = DirInfo::from_fh(ffi_->fh); - const fuse_context *fc = fuse_get_context(); + DirInfo *di = DirInfo::from_fh(ffi_->fh); return ::_concurrent_readdir(_tp, cfg.branches, di->fusepath, dirents_, - fc->uid, - fc->gid); + ctx_->uid, + ctx_->gid); } diff --git a/src/fuse_readdir_cor.hpp b/src/fuse_readdir_cor.hpp index 39ec3c6a..711d7691 100644 --- a/src/fuse_readdir_cor.hpp +++ b/src/fuse_readdir_cor.hpp @@ -33,7 +33,8 @@ namespace FUSE unsigned max_queue_depth); ~ReadDirCOR(); - int operator()(const fuse_file_info_t *ffi, + int operator()(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, fuse_dirents_t *buf); private: diff --git a/src/fuse_readdir_cosr.cpp b/src/fuse_readdir_cosr.cpp index ebd905f9..c7e39a1a 100644 --- a/src/fuse_readdir_cosr.cpp +++ b/src/fuse_readdir_cosr.cpp @@ -61,16 +61,16 @@ _readdir(ThreadPool &tp_, } int -FUSE::ReadDirCOSR::operator()(fuse_file_info_t const *ffi_, +FUSE::ReadDirCOSR::operator()(const fuse_req_ctx_t *ctx_, + fuse_file_info_t const *ffi_, fuse_dirents_t *dirents_) { - DirInfo *di = DirInfo::from_fh(ffi_->fh); - const fuse_context *fc = fuse_get_context(); + DirInfo *di = DirInfo::from_fh(ffi_->fh); return ::_readdir(_tp, cfg.branches, di->fusepath, dirents_, - fc->uid, - fc->gid); + ctx_->uid, + ctx_->gid); } diff --git a/src/fuse_readdir_cosr.hpp b/src/fuse_readdir_cosr.hpp index c2596385..5e76929b 100644 --- a/src/fuse_readdir_cosr.hpp +++ b/src/fuse_readdir_cosr.hpp @@ -32,7 +32,8 @@ namespace FUSE unsigned max_queue_depth); ~ReadDirCOSR(); - int operator()(fuse_file_info_t const *ffi, + int operator()(const fuse_req_ctx_t *ctx, + fuse_file_info_t const *ffi, fuse_dirents_t *buf); private: diff --git a/src/fuse_readdir_plus.cpp b/src/fuse_readdir_plus.cpp index 8c49c11b..c2207eba 100644 --- a/src/fuse_readdir_plus.cpp +++ b/src/fuse_readdir_plus.cpp @@ -22,7 +22,8 @@ int -FUSE::readdir_plus(const fuse_file_info_t *ffi_, +FUSE::readdir_plus(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, fuse_dirents_t *buf_) { return -ENOTSUP; diff --git a/src/fuse_readdir_plus.hpp b/src/fuse_readdir_plus.hpp index c60ea677..a2c26f2d 100644 --- a/src/fuse_readdir_plus.hpp +++ b/src/fuse_readdir_plus.hpp @@ -21,6 +21,7 @@ namespace FUSE { - int readdir_plus(fuse_file_info_t const *ffi, + int readdir_plus(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, fuse_dirents_t *buf); } diff --git a/src/fuse_readdir_seq.cpp b/src/fuse_readdir_seq.cpp index 699f1f3c..ee27021c 100644 --- a/src/fuse_readdir_seq.cpp +++ b/src/fuse_readdir_seq.cpp @@ -29,12 +29,12 @@ #endif int -FUSE::ReadDirSeq::operator()(fuse_file_info_t const *ffi_, +FUSE::ReadDirSeq::operator()(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, fuse_dirents_t *dirents_) { - DirInfo *di = DirInfo::from_fh(ffi_->fh); - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + DirInfo *di = DirInfo::from_fh(ffi_->fh); + const ugid::Set ugid(ctx_); return ::_readdir(cfg.branches, di->fusepath, diff --git a/src/fuse_readdir_seq.hpp b/src/fuse_readdir_seq.hpp index f89b8779..647c5f72 100644 --- a/src/fuse_readdir_seq.hpp +++ b/src/fuse_readdir_seq.hpp @@ -29,7 +29,8 @@ namespace FUSE ReadDirSeq() {} ~ReadDirSeq() {} - int operator()(fuse_file_info_t const *ffi, + int operator()(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, fuse_dirents_t *buf); }; } diff --git a/src/fuse_readlink.cpp b/src/fuse_readlink.cpp index c202cd9a..989db75c 100644 --- a/src/fuse_readlink.cpp +++ b/src/fuse_readlink.cpp @@ -115,13 +115,13 @@ _readlink(const Policy::Search &searchFunc_, } int -FUSE::readlink(const char *fusepath_, - char *buf_, - size_t size_) +FUSE::readlink(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + char *buf_, + size_t size_) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_); return ::_readlink(cfg.func.readlink.policy, cfg.branches, diff --git a/src/fuse_readlink.hpp b/src/fuse_readlink.hpp index 60966ee1..8b360b55 100644 --- a/src/fuse_readlink.hpp +++ b/src/fuse_readlink.hpp @@ -16,13 +16,16 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - readlink(const char *fusepath, - char *buf, - size_t size); + readlink(const fuse_req_ctx_t *ctx, + const char *fusepath, + char *buf, + size_t size); } diff --git a/src/fuse_release.cpp b/src/fuse_release.cpp index 188032b9..122d384b 100644 --- a/src/fuse_release.cpp +++ b/src/fuse_release.cpp @@ -29,9 +29,8 @@ static constexpr auto -_erase_if_lambda(const fuse_context *fc_, - FileInfo *fi_, - bool *existed_in_map_) +_erase_if_lambda(FileInfo *fi_, + bool *existed_in_map_) { return [=](auto &val_) @@ -49,7 +48,7 @@ _erase_if_lambda(const fuse_context *fc_, return false; if(val_.second.backing_id > 0) - FUSE::passthrough_close(fc_,val_.second.backing_id); + FUSE::passthrough_close(val_.second.backing_id); fs::close(val_.second.fi->fd); delete val_.second.fi; @@ -59,9 +58,9 @@ _erase_if_lambda(const fuse_context *fc_, static int -_release(const fuse_context *fc_, - FileInfo *fi_, - const bool dropcacheonclose_) +_release(const fuse_req_ctx_t *ctx_, + FileInfo *fi_, + const bool dropcacheonclose_) { bool existed_in_map; @@ -77,8 +76,8 @@ _release(const fuse_context *fc_, // existed. Just how many it erased and in this case I only want to // erase if there are no more open files. existed_in_map = false; - state.open_files.erase_if(fc_->nodeid, - ::_erase_if_lambda(fc_,fi_,&existed_in_map)); + state.open_files.erase_if(ctx_->nodeid, + ::_erase_if_lambda(fi_,&existed_in_map)); if(existed_in_map) return 0; @@ -90,18 +89,17 @@ _release(const fuse_context *fc_, static int -_release(const fuse_context *fc_, +_release(const fuse_req_ctx_t *ctx_, const fuse_file_info_t *ffi_) { FileInfo *fi = FileInfo::from_fh(ffi_->fh); - return ::_release(fc_,fi,cfg.dropcacheonclose); + return ::_release(ctx_,fi,cfg.dropcacheonclose); } int -FUSE::release(const fuse_file_info_t *ffi_) +FUSE::release(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_) { - const fuse_context *fc = fuse_get_context(); - - return ::_release(fc,ffi_); + return ::_release(ctx_,ffi_); } diff --git a/src/fuse_release.hpp b/src/fuse_release.hpp index 94858839..830f8d7b 100644 --- a/src/fuse_release.hpp +++ b/src/fuse_release.hpp @@ -22,5 +22,6 @@ namespace FUSE { int - release(const fuse_file_info_t *ffi); + release(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi); } diff --git a/src/fuse_releasedir.cpp b/src/fuse_releasedir.cpp index 47f36398..93704ac6 100644 --- a/src/fuse_releasedir.cpp +++ b/src/fuse_releasedir.cpp @@ -32,7 +32,8 @@ _releasedir(DirInfo *di_) } int -FUSE::releasedir(const fuse_file_info_t *ffi_) +FUSE::releasedir(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_) { DirInfo *di = DirInfo::from_fh(ffi_->fh); diff --git a/src/fuse_releasedir.hpp b/src/fuse_releasedir.hpp index 28d278e0..0caa8141 100644 --- a/src/fuse_releasedir.hpp +++ b/src/fuse_releasedir.hpp @@ -22,5 +22,6 @@ namespace FUSE { int - releasedir(const fuse_file_info_t *ffi); + releasedir(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi); } diff --git a/src/fuse_removemapping.cpp b/src/fuse_removemapping.cpp index fa55f767..a25f5441 100644 --- a/src/fuse_removemapping.cpp +++ b/src/fuse_removemapping.cpp @@ -22,7 +22,7 @@ int -FUSE::removemapping() +FUSE::removemapping(const fuse_req_ctx_t *ctx) { return -ENOSYS; } diff --git a/src/fuse_removemapping.hpp b/src/fuse_removemapping.hpp index 392c603c..982fe6ff 100644 --- a/src/fuse_removemapping.hpp +++ b/src/fuse_removemapping.hpp @@ -23,5 +23,5 @@ namespace FUSE { - int removemapping(); + int removemapping(const fuse_req_ctx_t *ctx); } diff --git a/src/fuse_removexattr.cpp b/src/fuse_removexattr.cpp index b007af7b..87a2dcaf 100644 --- a/src/fuse_removexattr.cpp +++ b/src/fuse_removexattr.cpp @@ -89,8 +89,9 @@ _removexattr(const Policy::Action &actionFunc_, } int -FUSE::removexattr(const char *fusepath_, - const char *attrname_) +FUSE::removexattr(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + const char *attrname_) { const fs::path fusepath{fusepath_}; @@ -100,8 +101,7 @@ FUSE::removexattr(const char *fusepath_, if(cfg.xattr.to_int()) return -cfg.xattr.to_int(); - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const ugid::Set ugid(ctx_); return ::_removexattr(cfg.func.removexattr.policy, cfg.func.getxattr.policy, diff --git a/src/fuse_removexattr.hpp b/src/fuse_removexattr.hpp index 4c7357f9..0daf7074 100644 --- a/src/fuse_removexattr.hpp +++ b/src/fuse_removexattr.hpp @@ -16,10 +16,13 @@ #pragma once +#include "fuse_req_ctx.h" + namespace FUSE { int - removexattr(const char *fusepath, - const char *attrname); + removexattr(const fuse_req_ctx_t *ctx, + const char *fusepath, + const char *attrname); } diff --git a/src/fuse_rename.cpp b/src/fuse_rename.cpp index fc40c0ab..224da590 100644 --- a/src/fuse_rename.cpp +++ b/src/fuse_rename.cpp @@ -244,7 +244,8 @@ _rename_exdev_rename_target(const Policy::Action &actionPolicy_, static int -_rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, +_rename_exdev_rel_symlink(const fuse_req_ctx_t *ctx_, + const Policy::Action &actionPolicy_, const Branches::Ptr &branches_, const fs::path &oldfusepath_, const fs::path &newfusepath_) @@ -263,7 +264,7 @@ _rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, target /= oldfusepath_; target = target.lexically_relative(linkpath.parent_path()); - rv = FUSE::symlink(target.c_str(),linkpath); + rv = FUSE::symlink(ctx_,target.c_str(),linkpath); if(rv < 0) ::_rename_exdev_rename_back(branches,oldfusepath_); @@ -272,7 +273,8 @@ _rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, static int -_rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, +_rename_exdev_abs_symlink(const fuse_req_ctx_t *ctx_, + const Policy::Action &actionPolicy_, const Branches::Ptr &branches_, const fs::path &mount_, const fs::path &oldfusepath_, @@ -292,7 +294,7 @@ _rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, target /= ".mergerfs_rename_exdev"; target /= oldfusepath_; - rv = FUSE::symlink(target.c_str(),linkpath); + rv = FUSE::symlink(ctx_,target.c_str(),linkpath); if(rv < 0) ::_rename_exdev_rename_back(branches,oldfusepath_); @@ -301,23 +303,25 @@ _rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, static int -_rename_exdev(Config &cfg_, - const fs::path &oldfusepath_, - const fs::path &newfusepath_) +_rename_exdev(const fuse_req_ctx_t *ctx_, + const fs::path &oldfusepath_, + const fs::path &newfusepath_) { - switch(cfg_.rename_exdev) + switch(cfg.rename_exdev) { case RenameEXDEV::ENUM::PASSTHROUGH: return -EXDEV; case RenameEXDEV::ENUM::REL_SYMLINK: - return ::_rename_exdev_rel_symlink(cfg_.func.rename.policy, - cfg_.branches, + return ::_rename_exdev_rel_symlink(ctx_, + cfg.func.rename.policy, + cfg.branches, oldfusepath_, newfusepath_); case RenameEXDEV::ENUM::ABS_SYMLINK: - return ::_rename_exdev_abs_symlink(cfg_.func.rename.policy, - cfg_.branches, - cfg_.mountpoint, + return ::_rename_exdev_abs_symlink(ctx_, + cfg.func.rename.policy, + cfg.branches, + cfg.mountpoint, oldfusepath_, newfusepath_); } @@ -327,36 +331,35 @@ _rename_exdev(Config &cfg_, static int -_rename(Config &cfg_, - const fs::path &oldpath_, +_rename(const fs::path &oldpath_, const fs::path &newpath_) { - if(cfg_.func.create.policy.path_preserving() && !cfg_.ignorepponrename) - return ::_rename_preserve_path(cfg_.func.rename.policy, - cfg_.branches, + if(cfg.func.create.policy.path_preserving() && !cfg.ignorepponrename) + return ::_rename_preserve_path(cfg.func.rename.policy, + cfg.branches, oldpath_, newpath_); - return ::_rename_create_path(cfg_.func.getattr.policy, - cfg_.func.rename.policy, - cfg_.branches, + return ::_rename_create_path(cfg.func.getattr.policy, + cfg.func.rename.policy, + cfg.branches, oldpath_, newpath_); } int -FUSE::rename(const char *oldfusepath_, - const char *newfusepath_) +FUSE::rename(const fuse_req_ctx_t *ctx_, + const char *oldfusepath_, + const char *newfusepath_) { int rv; const fs::path oldfusepath{oldfusepath_}; const fs::path newfusepath{newfusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const ugid::Set ugid(ctx_); - rv = ::_rename(cfg,oldfusepath,newfusepath); + rv = ::_rename(oldfusepath,newfusepath); if(rv == -EXDEV) - return ::_rename_exdev(cfg,oldfusepath,newfusepath); + return ::_rename_exdev(ctx_,oldfusepath,newfusepath); return rv; } diff --git a/src/fuse_rename.hpp b/src/fuse_rename.hpp index abbcf515..60c0b6f1 100644 --- a/src/fuse_rename.hpp +++ b/src/fuse_rename.hpp @@ -16,10 +16,13 @@ #pragma once +#include "fuse_req_ctx.h" + namespace FUSE { int - rename(const char *from, - const char *to); + rename(const fuse_req_ctx_t *ctx, + const char *from, + const char *to); } diff --git a/src/fuse_rmdir.cpp b/src/fuse_rmdir.cpp index 5c7c483e..29b29d6f 100644 --- a/src/fuse_rmdir.cpp +++ b/src/fuse_rmdir.cpp @@ -92,11 +92,11 @@ _rmdir(const Policy::Action &actionFunc_, } int -FUSE::rmdir(const char *fusepath_) +FUSE::rmdir(const fuse_req_ctx_t *ctx_, + const char *fusepath_) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_); return ::_rmdir(cfg.func.rmdir.policy, cfg.branches, diff --git a/src/fuse_rmdir.hpp b/src/fuse_rmdir.hpp index d2782468..fe521a69 100644 --- a/src/fuse_rmdir.hpp +++ b/src/fuse_rmdir.hpp @@ -16,9 +16,12 @@ #pragma once +#include "fuse_req_ctx.h" + namespace FUSE { int - rmdir(const char *fusepath); + rmdir(const fuse_req_ctx_t *ctx, + const char *fusepath); } diff --git a/src/fuse_setupmapping.cpp b/src/fuse_setupmapping.cpp index eb21d9ce..d2835be4 100644 --- a/src/fuse_setupmapping.cpp +++ b/src/fuse_setupmapping.cpp @@ -25,11 +25,12 @@ ssize_t -FUSE::setupmapping(uint64_t *fh_, - uint64_t foffset_, - uint64_t len_, - uint64_t flags_, - uint64_t moffset_) +FUSE::setupmapping(const fuse_req_ctx_t *ctx_, + uint64_t *fh_, + uint64_t foffset_, + uint64_t len_, + uint64_t flags_, + uint64_t moffset_) { return -ENOSYS; } diff --git a/src/fuse_setupmapping.hpp b/src/fuse_setupmapping.hpp index 5b290b6b..b03cb63d 100644 --- a/src/fuse_setupmapping.hpp +++ b/src/fuse_setupmapping.hpp @@ -23,7 +23,8 @@ namespace FUSE { - ssize_t setupmapping(uint64_t *fh_, + ssize_t setupmapping(const fuse_req_ctx_t *ctx, + uint64_t *fh_, uint64_t foffset_, uint64_t len_, uint64_t flags_, diff --git a/src/fuse_setxattr.cpp b/src/fuse_setxattr.cpp index 542f7daf..6bbd0319 100644 --- a/src/fuse_setxattr.cpp +++ b/src/fuse_setxattr.cpp @@ -180,11 +180,12 @@ _setxattr(const Policy::Action &setxattrPolicy_, static int -_setxattr(const fs::path &fusepath_, - const char *attrname_, - const char *attrval_, - size_t attrvalsize_, - int flags_) +_setxattr(const fuse_req_ctx_t *ctx_, + const fs::path &fusepath_, + const char *attrname_, + const char *attrval_, + size_t attrvalsize_, + int flags_) { if((cfg.security_capability == false) && ::_is_attrname_security_capability(attrname_)) @@ -193,8 +194,7 @@ _setxattr(const fs::path &fusepath_, if(cfg.xattr.to_int()) return -cfg.xattr.to_int(); - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const ugid::Set ugid(ctx_); return ::_setxattr(cfg.func.setxattr.policy, cfg.func.getxattr.policy, @@ -208,11 +208,12 @@ _setxattr(const fs::path &fusepath_, int -FUSE::setxattr(const char *fusepath_, - const char *attrname_, - const char *attrval_, - size_t attrvalsize_, - int flags_) +FUSE::setxattr(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + const char *attrname_, + const char *attrval_, + size_t attrvalsize_, + int flags_) { const fs::path fusepath{fusepath_}; @@ -222,5 +223,10 @@ FUSE::setxattr(const char *fusepath_, attrvalsize_, flags_); - return ::_setxattr(fusepath,attrname_,attrval_,attrvalsize_,flags_); + return ::_setxattr(ctx_, + fusepath, + attrname_, + attrval_, + attrvalsize_, + flags_); } diff --git a/src/fuse_setxattr.hpp b/src/fuse_setxattr.hpp index 0f373a62..c73198d5 100644 --- a/src/fuse_setxattr.hpp +++ b/src/fuse_setxattr.hpp @@ -18,13 +18,16 @@ #include +#include "fuse_req_ctx.h" + namespace FUSE { int - setxattr(const char *fusepath, - const char *attrname, - const char *attrval, - size_t attrvalize, - int flags); + setxattr(const fuse_req_ctx_t *ctx, + const char *fusepath, + const char *attrname, + const char *attrval, + size_t attrvalize, + int flags); } diff --git a/src/fuse_statfs.cpp b/src/fuse_statfs.cpp index 6d9184eb..2ddd343a 100644 --- a/src/fuse_statfs.cpp +++ b/src/fuse_statfs.cpp @@ -142,12 +142,12 @@ _statfs(const Branches::Ptr &branches_, } int -FUSE::statfs(const char *fusepath_, - struct statvfs *st_) +FUSE::statfs(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + struct statvfs *st_) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_); return ::_statfs(cfg.branches, fusepath, diff --git a/src/fuse_statfs.hpp b/src/fuse_statfs.hpp index c34ac43a..e8c9901e 100644 --- a/src/fuse_statfs.hpp +++ b/src/fuse_statfs.hpp @@ -16,12 +16,15 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - statfs(const char *fusepath, - struct statvfs *fsstat); + statfs(const fuse_req_ctx_t *ctx, + const char *fusepath, + struct statvfs *fsstat); } diff --git a/src/fuse_statx.hpp b/src/fuse_statx.hpp index 9b0df523..992f5aa3 100644 --- a/src/fuse_statx.hpp +++ b/src/fuse_statx.hpp @@ -25,14 +25,16 @@ namespace FUSE { - int statx(const char *fusepath, - const uint32_t flags, - const uint32_t mask, - struct fuse_statx *st, - fuse_timeouts_t *timeout); - int statx_fh(const uint64_t fh, - const uint32_t flags, - const uint32_t mask, - struct fuse_statx *st, - fuse_timeouts_t *timeout); + int statx(const fuse_req_ctx_t *ctx, + const char *fusepath, + const uint32_t flags, + const uint32_t mask, + struct fuse_statx *st, + fuse_timeouts_t *timeout); + int statx_fh(const fuse_req_ctx_t *ctx, + const uint64_t fh, + const uint32_t flags, + const uint32_t mask, + struct fuse_statx *st, + fuse_timeouts_t *timeout); } diff --git a/src/fuse_statx_supported.icpp b/src/fuse_statx_supported.icpp index 4bf0f9a7..32089583 100644 --- a/src/fuse_statx_supported.icpp +++ b/src/fuse_statx_supported.icpp @@ -179,8 +179,6 @@ _statx(const fs::path &fusepath_, fuse_timeouts_t *timeout_) { int rv; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); rv = ::_statx(cfg.func.getattr.policy, cfg.branches, @@ -203,17 +201,20 @@ _statx(const fs::path &fusepath_, } int -FUSE::statx(const char *fusepath_, - const uint32_t flags_, - const uint32_t mask_, - struct fuse_statx *st_, - fuse_timeouts_t *timeout_) +FUSE::statx(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + const uint32_t flags_, + const uint32_t mask_, + struct fuse_statx *st_, + fuse_timeouts_t *timeout_) { const fs::path fusepath{fusepath_}; if(Config::is_ctrl_file(fusepath)) return ::_statx_controlfile(st_); + const ugid::Set ugid(ctx_); + return ::_statx(fusepath, flags_|AT_STATX_DONT_SYNC, mask_, @@ -222,19 +223,19 @@ FUSE::statx(const char *fusepath_, } int -FUSE::statx_fh(const uint64_t fh_, - const uint32_t flags_, - const uint32_t mask_, - struct fuse_statx *st_, - fuse_timeouts_t *timeout_) +FUSE::statx_fh(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + const uint32_t flags_, + const uint32_t mask_, + struct fuse_statx *st_, + fuse_timeouts_t *timeout_) { uint64_t fh; - const fuse_context *fc = fuse_get_context(); fh = fh_; if(fh == 0) { - state.open_files.cvisit(fc->nodeid, + state.open_files.cvisit(ctx_->nodeid, [&](auto &val_) { fh = val_.second.fi->to_fh(); @@ -246,6 +247,8 @@ FUSE::statx_fh(const uint64_t fh_, FileInfo *fi = FileInfo::from_fh(fh); + const ugid::Set ugid(ctx_); + return ::_statx(fi->fusepath, flags_|AT_STATX_DONT_SYNC, mask_, diff --git a/src/fuse_statx_unsupported.icpp b/src/fuse_statx_unsupported.icpp index 254f6e48..8c6b6e54 100644 --- a/src/fuse_statx_unsupported.icpp +++ b/src/fuse_statx_unsupported.icpp @@ -1,21 +1,23 @@ #include "fuse_statx.hpp" int -FUSE::statx(const char *fusepath_, - const uint32_t flags_, - const uint32_t mask_, - struct fuse_statx *st_, - fuse_timeouts_t *timeout_) +FUSE::statx(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + const uint32_t flags_, + const uint32_t mask_, + struct fuse_statx *st_, + fuse_timeouts_t *timeout_) { return -ENOSYS; } int -FUSE::statx_fh(const uint64_t fh_, - const uint32_t flags_, - const uint32_t mask_, - struct fuse_statx *st_, - fuse_timeouts_t *timeout_) +FUSE::statx_fh(const fuse_req_ctx_t *ctx_, + const uint64_t fh_, + const uint32_t flags_, + const uint32_t mask_, + struct fuse_statx *st_, + fuse_timeouts_t *timeout_) { return -ENOSYS; } diff --git a/src/fuse_symlink.cpp b/src/fuse_symlink.cpp index ed43630e..ae5803ce 100644 --- a/src/fuse_symlink.cpp +++ b/src/fuse_symlink.cpp @@ -120,28 +120,30 @@ _symlink(const Policy::Search &searchFunc_, } int -FUSE::symlink(const char *target_, - const char *linkpath_, - struct stat *st_, - fuse_timeouts_t *timeouts_) +FUSE::symlink(const fuse_req_ctx_t *ctx_, + const char *target_, + const char *linkpath_, + struct stat *st_, + fuse_timeouts_t *timeouts_) { const fs::path linkpath{linkpath_}; - return FUSE::symlink(target_, + return FUSE::symlink(ctx_, + target_, linkpath, st_, timeouts_); } int -FUSE::symlink(const char *target_, - const fs::path &linkpath_, - struct stat *st_, - fuse_timeouts_t *timeouts_) +FUSE::symlink(const fuse_req_ctx_t *ctx_, + const char *target_, + const fs::path &linkpath_, + struct stat *st_, + fuse_timeouts_t *timeouts_) { int rv; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const ugid::Set ugid(ctx_); rv = ::_symlink(cfg.func.getattr.policy, cfg.func.symlink.policy, diff --git a/src/fuse_symlink.hpp b/src/fuse_symlink.hpp index dbfaeb9c..79dd109b 100644 --- a/src/fuse_symlink.hpp +++ b/src/fuse_symlink.hpp @@ -27,15 +27,16 @@ namespace FUSE { int - symlink(const char *target, - const char *linkpath, - struct stat *st = NULL, - fuse_timeouts_t *timeouts = NULL); + symlink(const fuse_req_ctx_t *ctx, + const char *target, + const char *linkpath, + struct stat *st = NULL, + fuse_timeouts_t *timeouts = NULL); int - symlink(const char *target, - const fs::path &linkpath, - struct stat *st = NULL, - fuse_timeouts_t *timeouts = NULL); - + symlink(const fuse_req_ctx_t *ctx, + const char *target, + const fs::path &linkpath, + struct stat *st = NULL, + fuse_timeouts_t *timeouts = NULL); } diff --git a/src/fuse_syncfs.cpp b/src/fuse_syncfs.cpp index 6af031ef..c62fd273 100644 --- a/src/fuse_syncfs.cpp +++ b/src/fuse_syncfs.cpp @@ -22,7 +22,7 @@ int -FUSE::syncfs() +FUSE::syncfs(const fuse_req_ctx_t *ctx_) { return -ENOSYS; } diff --git a/src/fuse_syncfs.hpp b/src/fuse_syncfs.hpp index f1a73b6b..70b10e27 100644 --- a/src/fuse_syncfs.hpp +++ b/src/fuse_syncfs.hpp @@ -23,5 +23,5 @@ namespace FUSE { - int syncfs(); + int syncfs(const fuse_req_ctx_t *ctx); } diff --git a/src/fuse_tmpfile.cpp b/src/fuse_tmpfile.cpp index 76888395..674e7138 100644 --- a/src/fuse_tmpfile.cpp +++ b/src/fuse_tmpfile.cpp @@ -24,9 +24,10 @@ int -FUSE::tmpfile(const char *fusepath_, - mode_t mode_, - fuse_file_info_t *ffi_) +FUSE::tmpfile(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + mode_t mode_, + fuse_file_info_t *ffi_) { return -ENOSYS; } diff --git a/src/fuse_tmpfile.hpp b/src/fuse_tmpfile.hpp index 47a743d2..eb2fd4cb 100644 --- a/src/fuse_tmpfile.hpp +++ b/src/fuse_tmpfile.hpp @@ -26,7 +26,8 @@ namespace FUSE { int - tmpfile(const char *fusepath, - mode_t mode, - fuse_file_info_t *ffi); + tmpfile(const fuse_req_ctx_t *ctx, + const char *fusepath, + mode_t mode, + fuse_file_info_t *ffi); } diff --git a/src/fuse_truncate.cpp b/src/fuse_truncate.cpp index dfecae7e..ff0ad2f3 100644 --- a/src/fuse_truncate.cpp +++ b/src/fuse_truncate.cpp @@ -90,12 +90,12 @@ _truncate(const Policy::Action &actionFunc_, } int -FUSE::truncate(const char *fusepath_, - off_t size_) +FUSE::truncate(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + off_t size_) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_); return ::_truncate(cfg.func.truncate.policy, cfg.func.getattr.policy, diff --git a/src/fuse_truncate.hpp b/src/fuse_truncate.hpp index 61331295..dc70011a 100644 --- a/src/fuse_truncate.hpp +++ b/src/fuse_truncate.hpp @@ -16,12 +16,15 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - truncate(const char *fusepath, - off_t size); + truncate(const fuse_req_ctx_t *ctx, + const char *fusepath, + off_t size); } diff --git a/src/fuse_unlink.cpp b/src/fuse_unlink.cpp index 62fecfb8..144c9264 100644 --- a/src/fuse_unlink.cpp +++ b/src/fuse_unlink.cpp @@ -65,11 +65,11 @@ _unlink(const Policy::Action &unlinkPolicy_, } int -FUSE::unlink(const char *fusepath_) +FUSE::unlink(const fuse_req_ctx_t *ctx_, + const char *fusepath_) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_); return ::_unlink(cfg.func.unlink.policy, cfg.branches, diff --git a/src/fuse_unlink.hpp b/src/fuse_unlink.hpp index 845ac186..22b9f431 100644 --- a/src/fuse_unlink.hpp +++ b/src/fuse_unlink.hpp @@ -16,9 +16,12 @@ #pragma once +#include "fuse_req_ctx.h" + namespace FUSE { int - unlink(const char *fusepath); + unlink(const fuse_req_ctx_t *ctx, + const char *fusepath); } diff --git a/src/fuse_utimens.cpp b/src/fuse_utimens.cpp index 2703cdb3..b383b466 100644 --- a/src/fuse_utimens.cpp +++ b/src/fuse_utimens.cpp @@ -89,12 +89,12 @@ _utimens(const Policy::Action &utimensPolicy_, } int -FUSE::utimens(const char *fusepath_, - const timespec ts_[2]) +FUSE::utimens(const fuse_req_ctx_t *ctx_, + const char *fusepath_, + const timespec ts_[2]) { - const fs::path fusepath{fusepath_}; - const fuse_context *fc = fuse_get_context(); - const ugid::Set ugid(fc->uid,fc->gid); + const fs::path fusepath{fusepath_}; + const ugid::Set ugid(ctx_); return ::_utimens(cfg.func.utimens.policy, cfg.func.getattr.policy, diff --git a/src/fuse_utimens.hpp b/src/fuse_utimens.hpp index 2b24258e..c3d10508 100644 --- a/src/fuse_utimens.hpp +++ b/src/fuse_utimens.hpp @@ -16,12 +16,15 @@ #pragma once +#include "fuse_req_ctx.h" + #include namespace FUSE { int - utimens(const char *fusepath, - const timespec ts[2]); + utimens(const fuse_req_ctx_t *ctx, + const char *fusepath, + const timespec ts[2]); } diff --git a/src/fuse_write.cpp b/src/fuse_write.cpp index c7c0c3a9..3583a833 100644 --- a/src/fuse_write.cpp +++ b/src/fuse_write.cpp @@ -183,18 +183,20 @@ _write(const fuse_file_info_t *ffi_, } int -FUSE::write(const fuse_file_info_t *ffi_, +FUSE::write(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, const char *buf_, size_t count_, off_t offset_) { - ioprio::SetFrom iop(fuse_get_context()->pid); + ioprio::SetFrom iop(ctx_->pid); return ::_write(ffi_,buf_,count_,offset_); } int -FUSE::write_null(const fuse_file_info_t *ffi_, +FUSE::write_null(const fuse_req_ctx_t *ctx_, + const fuse_file_info_t *ffi_, const char *buf_, size_t count_, off_t offset_) diff --git a/src/fuse_write.hpp b/src/fuse_write.hpp index abbfd093..661f0fb2 100644 --- a/src/fuse_write.hpp +++ b/src/fuse_write.hpp @@ -22,13 +22,15 @@ namespace FUSE { int - write(const fuse_file_info_t *ffi, + write(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, const char *buf, size_t count, off_t offset); int - write_null(const fuse_file_info_t *ffi, + write_null(const fuse_req_ctx_t *ctx, + const fuse_file_info_t *ffi, const char *buf, size_t count, off_t offset); diff --git a/src/ugid_linux.hpp b/src/ugid_linux.hpp index 478dc8b5..422904bd 100644 --- a/src/ugid_linux.hpp +++ b/src/ugid_linux.hpp @@ -16,6 +16,8 @@ #pragma once +#include "fuse_req_ctx.h" + #include #include #include @@ -94,6 +96,11 @@ namespace ugid currentuid = newuid_; currentgid = newgid_; } + + Set(const fuse_req_ctx_t *ctx_) + : Set(ctx_->uid,ctx_->gid) + { + } }; struct SetRootGuard diff --git a/src/ugid_rwlock.hpp b/src/ugid_rwlock.hpp index e37dbce7..a223614b 100644 --- a/src/ugid_rwlock.hpp +++ b/src/ugid_rwlock.hpp @@ -70,6 +70,12 @@ namespace ugid ugid_set(newuid_,newgid_); } + Set(const fuse_req_ctx_t *ctx_) + : Set(ctx_->uid,ctx_->gid) + { + + } + ~Set() { pthread_rwlock_unlock(&rwlock);