diff --git a/libfuse/include/fuse.h b/libfuse/include/fuse.h index 538216c8..e6db214b 100644 --- a/libfuse/include/fuse.h +++ b/libfuse/include/fuse.h @@ -131,11 +131,11 @@ struct fuse_operations /** Change the permission bits of a file */ int (*chmod) (const char *, mode_t); - int (*fchmod)(const struct fuse_file_info *, const mode_t); + int (*fchmod)(const fuse_file_info_t *, const mode_t); /** Change the owner and group of a file */ int (*chown) (const char *, uid_t, gid_t); - int (*fchown)(const struct fuse_file_info *, const uid_t, const gid_t); + int (*fchown)(const fuse_file_info_t *, const uid_t, const gid_t); /** Change the size of a file */ int (*truncate) (const char *, off_t); @@ -163,7 +163,7 @@ struct fuse_operations * * Changed in version 2.2 */ - int (*open) (const char *, struct fuse_file_info *); + int (*open) (const char *, fuse_file_info_t *); /** Read data from an open file * @@ -176,8 +176,10 @@ struct fuse_operations * * Changed in version 2.2 */ - int (*read) (char *, size_t, off_t, - struct fuse_file_info *); + int (*read) (const fuse_file_info_t *, + char *, + size_t, + off_t); /** Write data to an open file * @@ -187,8 +189,10 @@ struct fuse_operations * * Changed in version 2.2 */ - int (*write) (const char *, size_t, off_t, - struct fuse_file_info *); + int (*write) (const fuse_file_info_t *, + const char *, + size_t, + off_t); /** Get file system statistics * @@ -222,7 +226,7 @@ struct fuse_operations * * Changed in version 2.2 */ - int (*flush) (struct fuse_file_info *); + int (*flush) (const fuse_file_info_t *); /** Release an open file * @@ -238,7 +242,7 @@ struct fuse_operations * * Changed in version 2.2 */ - int (*release) (struct fuse_file_info *); + int (*release) (const fuse_file_info_t *); /** Synchronize file contents * @@ -247,7 +251,7 @@ struct fuse_operations * * Changed in version 2.2 */ - int (*fsync) (int, struct fuse_file_info *); + int (*fsync) (const fuse_file_info_t *, int); /** Set extended attributes */ int (*setxattr) (const char *, const char *, const char *, size_t, int); @@ -271,7 +275,8 @@ struct fuse_operations * * Introduced in version 2.3 */ - int (*opendir) (const char *, struct fuse_file_info *); + int (*opendir) (const char *, + fuse_file_info_t *); /** Read directory * @@ -294,10 +299,10 @@ struct fuse_operations * * Introduced in version 2.3 */ - int (*readdir)(struct fuse_file_info *, + int (*readdir)(const fuse_file_info_t *, fuse_dirents_t *); - int (*readdir_plus)(struct fuse_file_info *, + int (*readdir_plus)(const fuse_file_info_t *, fuse_dirents_t *); @@ -305,7 +310,7 @@ struct fuse_operations * * Introduced in version 2.3 */ - int (*releasedir) (struct fuse_file_info *); + int (*releasedir) (const fuse_file_info_t *); /** Synchronize directory contents * @@ -314,7 +319,7 @@ struct fuse_operations * * Introduced in version 2.3 */ - int (*fsyncdir) (int, struct fuse_file_info *); + int (*fsyncdir) (const fuse_file_info_t *, int); /** * Initialize filesystem @@ -362,7 +367,7 @@ struct fuse_operations * * Introduced in version 2.5 */ - int (*create) (const char *, mode_t, struct fuse_file_info *); + int (*create) (const char *, mode_t, fuse_file_info_t *); /** * Change the size of an open file @@ -376,7 +381,7 @@ struct fuse_operations * * Introduced in version 2.5 */ - int (*ftruncate) (off_t, struct fuse_file_info *); + int (*ftruncate) (const fuse_file_info_t *, off_t); /** * Get attributes from an open file @@ -390,7 +395,7 @@ struct fuse_operations * * Introduced in version 2.5 */ - int (*fgetattr) (struct stat *, struct fuse_file_info *, fuse_timeouts_t *); + int (*fgetattr) (const fuse_file_info_t *, struct stat *, fuse_timeouts_t *); /** * Perform POSIX file locking operation @@ -424,7 +429,8 @@ struct fuse_operations * * Introduced in version 2.6 */ - int (*lock) (struct fuse_file_info *, int cmd, + int (*lock) (const fuse_file_info_t *, + int cmd, struct flock *); /** @@ -439,7 +445,7 @@ struct fuse_operations * Introduced in version 2.6 */ int (*utimens)(const char *, const struct timespec tv[2]); - int (*futimens)(const struct fuse_file_info *ffi_, const struct timespec tv_[2]); + int (*futimens)(const fuse_file_info_t *ffi_, const struct timespec tv_[2]); /** * Map block index within file to block index within device @@ -466,12 +472,12 @@ struct fuse_operations * * Introduced in version 2.8 */ - int (*ioctl) (unsigned long cmd, - void *arg, - struct fuse_file_info *ffi, - unsigned int flags, - void *data, - uint32_t *out_bufsz); + 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 @@ -490,8 +496,9 @@ struct fuse_operations * * Introduced in version 2.8 */ - int (*poll) (struct fuse_file_info *, - struct fuse_pollhandle *ph, unsigned *reventsp); + int (*poll) (const fuse_file_info_t *ffi, + fuse_pollhandle_t *ph, + unsigned *reventsp); /** Write contents of buffer to an open file * @@ -501,8 +508,9 @@ struct fuse_operations * * Introduced in version 2.9 */ - int (*write_buf) (struct fuse_bufvec *buf, off_t off, - struct fuse_file_info *); + int (*write_buf) (const fuse_file_info_t *ffi, + struct fuse_bufvec *buf, + off_t off); /** Store data from an open file in a buffer * @@ -520,8 +528,10 @@ struct fuse_operations * * Introduced in version 2.9 */ - int (*read_buf) (struct fuse_bufvec **bufp, - size_t size, off_t off, struct fuse_file_info *); + int (*read_buf) (const fuse_file_info_t *ffi, + struct fuse_bufvec **bufp, + size_t size, + off_t off); /** * Perform BSD file locking operation * @@ -542,7 +552,7 @@ struct fuse_operations * * Introduced in version 2.9 */ - int (*flock) (struct fuse_file_info *, int op); + int (*flock) (const fuse_file_info_t *, int op); /** * Allocates space for an open file @@ -554,7 +564,7 @@ struct fuse_operations * * Introduced in version 2.9.1 */ - int (*fallocate) (int, off_t, off_t,struct fuse_file_info *); + int (*fallocate) (const fuse_file_info_t *, int, off_t, off_t); /** * Copy a range of data from one file to another @@ -569,12 +579,12 @@ struct fuse_operations * destination. Effectively doing an inefficient copy of the * data. */ - ssize_t (*copy_file_range)(struct fuse_file_info *fi_in, - off_t offset_in, - struct fuse_file_info *fi_out, - off_t offset_out, - size_t size, - int flags); + ssize_t (*copy_file_range)(const fuse_file_info_t *fi_in, + off_t offset_in, + const fuse_file_info_t *fi_out, + off_t offset_out, + size_t size, + int flags); }; /** Extra context that may be needed by some filesystems @@ -775,10 +785,10 @@ int fuse_fs_getattr(struct fuse_fs *fs, struct stat *buf, fuse_timeouts_t *timeout); -int fuse_fs_fgetattr(struct fuse_fs *fs, - struct stat *buf, - struct fuse_file_info *fi, - fuse_timeouts_t *timeout); +int fuse_fs_fgetattr(struct fuse_fs *fs, + struct stat *buf, + fuse_file_info_t *fi, + fuse_timeouts_t *timeout); int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath, const char *newpath); @@ -788,44 +798,44 @@ int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname, const char *path); int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath); int fuse_fs_release(struct fuse_fs *fs, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_open(struct fuse_fs *fs, const char *path, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_read(struct fuse_fs *fs, char *buf, size_t size, - off_t off, struct fuse_file_info *fi); + off_t off, fuse_file_info_t *fi); int fuse_fs_read_buf(struct fuse_fs *fs, struct fuse_bufvec **bufp, size_t size, off_t off, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_write(struct fuse_fs *fs, const char *buf, - size_t size, off_t off, struct fuse_file_info *fi); + size_t size, off_t off, fuse_file_info_t *fi); int fuse_fs_write_buf(struct fuse_fs *fs, struct fuse_bufvec *buf, off_t off, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_fsync(struct fuse_fs *fs, int datasync, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_flush(struct fuse_fs *fs, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf); int fuse_fs_opendir(struct fuse_fs *fs, const char *path, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_readdir(struct fuse_fs *fs, - struct fuse_file_info *fi, + fuse_file_info_t *fi, fuse_dirents_t *buf); int fuse_fs_fsyncdir(struct fuse_fs *fs, int datasync, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_releasedir(struct fuse_fs *fs, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_lock(struct fuse_fs *fs, - struct fuse_file_info *fi, int cmd, struct flock *lock); + fuse_file_info_t *fi, int cmd, struct flock *lock); int fuse_fs_flock(struct fuse_fs *fs, - struct fuse_file_info *fi, int op); + fuse_file_info_t *fi, int op); int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode); int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid); int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size); int fuse_fs_ftruncate(struct fuse_fs *fs, off_t size, - struct fuse_file_info *fi); + fuse_file_info_t *fi); int fuse_fs_utimens(struct fuse_fs *fs, const char *path, const struct timespec tv[2]); int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask); @@ -845,24 +855,24 @@ int fuse_fs_removexattr(struct fuse_fs *fs, const char *path, int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize, uint64_t *idx); int fuse_fs_ioctl(struct fuse_fs *fs, unsigned long cmd, void *arg, - struct fuse_file_info *fi, unsigned int flags, + fuse_file_info_t *fi, unsigned int flags, void *data, uint32_t *out_bufsz); int fuse_fs_poll(struct fuse_fs *fs, - struct fuse_file_info *fi, struct fuse_pollhandle *ph, + fuse_file_info_t *fi, fuse_pollhandle_t *ph, unsigned *reventsp); int fuse_fs_fallocate(struct fuse_fs *fs, int mode, - off_t offset, off_t length, struct fuse_file_info *fi); + off_t offset, off_t length, fuse_file_info_t *fi); void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn); void fuse_fs_destroy(struct fuse_fs *fs); int fuse_fs_prepare_hide(struct fuse_fs *fs, const char *path, uint64_t *fh); int fuse_fs_free_hide(struct fuse_fs *fs, uint64_t fh); ssize_t fuse_fs_copy_file_range(struct fuse_fs *fs, - struct fuse_file_info *fi_in, off_t off_in, - struct fuse_file_info *fi_out, off_t off_out, + fuse_file_info_t *fi_in, off_t off_in, + fuse_file_info_t *fi_out, off_t off_out, size_t len, int flags); -int fuse_notify_poll(struct fuse_pollhandle *ph); +int fuse_notify_poll(fuse_pollhandle_t *ph); /** * Create a new fuse filesystem object diff --git a/libfuse/include/fuse_common.h b/libfuse/include/fuse_common.h index 96c317f9..62089504 100644 --- a/libfuse/include/fuse_common.h +++ b/libfuse/include/fuse_common.h @@ -46,8 +46,8 @@ EXTERN_C_BEGIN * * Changed in version 2.5 */ -struct -fuse_file_info +typedef struct fuse_file_info_t fuse_file_info_t; +struct fuse_file_info_t { /** Open flags. Available in open() and release() */ int flags; @@ -205,7 +205,8 @@ struct fuse_conn_info { struct fuse_session; struct fuse_chan; -struct fuse_pollhandle; +struct fuse_pollhandle_t; +typedef struct fuse_pollhandle_t fuse_pollhandle_t; /** * Create a FUSE mountpoint @@ -271,7 +272,7 @@ int fuse_version(void); * * @param ph the poll handle */ -void fuse_pollhandle_destroy(struct fuse_pollhandle *ph); +void fuse_pollhandle_destroy(fuse_pollhandle_t *ph); /* ----------------------------------------------------------- * * Data buffer * diff --git a/libfuse/include/fuse_lowlevel.h b/libfuse/include/fuse_lowlevel.h index 133ec1c5..ee236713 100644 --- a/libfuse/include/fuse_lowlevel.h +++ b/libfuse/include/fuse_lowlevel.h @@ -67,63 +67,63 @@ struct fuse_chan; /** Directory entry parameters supplied to fuse_reply_entry() */ struct fuse_entry_param { -/** Unique inode number - * - * In lookup, zero means negative entry (from version 2.5) - * Returning ENOENT also means negative entry, but by setting zero - * ino the kernel may cache negative entries for entry_timeout - * seconds. - */ -fuse_ino_t ino; + /** Unique inode number + * + * In lookup, zero means negative entry (from version 2.5) + * Returning ENOENT also means negative entry, but by setting zero + * ino the kernel may cache negative entries for entry_timeout + * seconds. + */ + fuse_ino_t ino; -/** Generation number for this entry. - * - * If the file system will be exported over NFS, the - * ino/generation pairs need to be unique over the file - * system's lifetime (rather than just the mount time). So if - * the file system reuses an inode after it has been deleted, - * it must assign a new, previously unused generation number - * to the inode at the same time. - * - * The generation must be non-zero, otherwise FUSE will treat - * it as an error. - * - */ -uint64_t generation; + /** Generation number for this entry. + * + * If the file system will be exported over NFS, the + * ino/generation pairs need to be unique over the file + * system's lifetime (rather than just the mount time). So if + * the file system reuses an inode after it has been deleted, + * it must assign a new, previously unused generation number + * to the inode at the same time. + * + * The generation must be non-zero, otherwise FUSE will treat + * it as an error. + * + */ + uint64_t generation; -/** Inode attributes. - * - * Even if attr_timeout == 0, attr must be correct. For example, - * for open(), FUSE uses attr.st_size from lookup() to determine - * how many bytes to request. If this value is not correct, - * incorrect data will be returned. - */ -struct stat attr; + /** Inode attributes. + * + * Even if attr_timeout == 0, attr must be correct. For example, + * for open(), FUSE uses attr.st_size from lookup() to determine + * how many bytes to request. If this value is not correct, + * incorrect data will be returned. + */ + struct stat attr; -fuse_timeouts_t timeout; + fuse_timeouts_t timeout; }; /** Additional context associated with requests */ struct fuse_ctx { -/** User ID of the calling process */ -uid_t uid; + /** User ID of the calling process */ + uid_t uid; -/** Group ID of the calling process */ -gid_t gid; + /** Group ID of the calling process */ + gid_t gid; -/** Thread ID of the calling process */ -pid_t pid; + /** Thread ID of the calling process */ + pid_t pid; -/** Umask of the calling process (introduced in version 2.8) */ -mode_t umask; + /** Umask of the calling process (introduced in version 2.8) */ + mode_t umask; }; struct fuse_forget_data { -fuse_ino_t ino; -uint64_t nlookup; + fuse_ino_t ino; + uint64_t nlookup; }; /* ----------------------------------------------------------- * @@ -153,78 +153,78 @@ uint64_t nlookup; */ struct fuse_lowlevel_ops { -/** - * Initialize filesystem - * - * Called before any other filesystem method - * - * There's no reply to this function - * - * @param userdata the user data passed to fuse_lowlevel_new() - */ -void (*init) (void *userdata, struct fuse_conn_info *conn); + /** + * Initialize filesystem + * + * Called before any other filesystem method + * + * There's no reply to this function + * + * @param userdata the user data passed to fuse_lowlevel_new() + */ + void (*init)(void *userdata, struct fuse_conn_info *conn); -/** - * Clean up filesystem - * - * Called on filesystem exit - * - * There's no reply to this function - * - * @param userdata the user data passed to fuse_lowlevel_new() - */ -void (*destroy) (void *userdata); + /** + * Clean up filesystem + * + * Called on filesystem exit + * + * There's no reply to this function + * + * @param userdata the user data passed to fuse_lowlevel_new() + */ + void (*destroy)(void *userdata); -/** - * Look up a directory entry by name and get its attributes. - * - * Valid replies: - * fuse_reply_entry - * fuse_reply_err - * - * @param req request handle - * @param parent inode number of the parent directory - * @param name the name to look up - */ -void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); + /** + * Look up a directory entry by name and get its attributes. + * + * Valid replies: + * fuse_reply_entry + * fuse_reply_err + * + * @param req request handle + * @param parent inode number of the parent directory + * @param name the name to look up + */ + void (*lookup)(fuse_req_t req, fuse_ino_t parent, const char *name); -/** - * Forget about an inode - * - * This function is called when the kernel removes an inode - * from its internal caches. - * - * The inode's lookup count increases by one for every call to - * fuse_reply_entry and fuse_reply_create. The nlookup parameter - * indicates by how much the lookup count should be decreased. - * - * Inodes with a non-zero lookup count may receive request from - * the kernel even after calls to unlink, rmdir or (when - * overwriting an existing file) rename. Filesystems must handle - * such requests properly and it is recommended to defer removal - * of the inode until the lookup count reaches zero. Calls to - * unlink, remdir or rename will be followed closely by forget - * unless the file or directory is open, in which case the - * kernel issues forget only after the release or releasedir - * calls. - * - * Note that if a file system will be exported over NFS the - * inodes lifetime must extend even beyond forget. See the - * generation field in struct fuse_entry_param above. - * - * On unmount the lookup count for all inodes implicitly drops - * to zero. It is not guaranteed that the file system will - * receive corresponding forget messages for the affected - * inodes. - * - * Valid replies: - * fuse_reply_none - * - * @param req request handle - * @param ino the inode number - * @param nlookup the number of lookups to forget - */ - void (*forget) (fuse_req_t req, fuse_ino_t ino, uint64_t nlookup); + /** + * Forget about an inode + * + * This function is called when the kernel removes an inode + * from its internal caches. + * + * The inode's lookup count increases by one for every call to + * fuse_reply_entry and fuse_reply_create. The nlookup parameter + * indicates by how much the lookup count should be decreased. + * + * Inodes with a non-zero lookup count may receive request from + * the kernel even after calls to unlink, rmdir or (when + * overwriting an existing file) rename. Filesystems must handle + * such requests properly and it is recommended to defer removal + * of the inode until the lookup count reaches zero. Calls to + * unlink, remdir or rename will be followed closely by forget + * unless the file or directory is open, in which case the + * kernel issues forget only after the release or releasedir + * calls. + * + * Note that if a file system will be exported over NFS the + * inodes lifetime must extend even beyond forget. See the + * generation field in struct fuse_entry_param above. + * + * On unmount the lookup count for all inodes implicitly drops + * to zero. It is not guaranteed that the file system will + * receive corresponding forget messages for the affected + * inodes. + * + * Valid replies: + * fuse_reply_none + * + * @param req request handle + * @param ino the inode number + * @param nlookup the number of lookups to forget + */ + void (*forget)(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup); /** * Get file attributes @@ -237,8 +237,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param fi for future use, currently always NULL */ - void (*getattr) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi); + void (*getattr)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi); /** * Set file attributes @@ -267,8 +267,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * Changed in version 2.5: * file information filled in for ftruncate */ - void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr, - int to_set, struct fuse_file_info *fi); + void (*setattr)(fuse_req_t req, fuse_ino_t ino, struct stat *attr, + int to_set, fuse_file_info_t *fi); /** * Read symbolic link @@ -280,7 +280,7 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param req request handle * @param ino the inode number */ - void (*readlink) (fuse_req_t req, fuse_ino_t ino); + void (*readlink)(fuse_req_t req, fuse_ino_t ino); /** * Create file node @@ -298,8 +298,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param mode file type and mode with which to create the new file * @param rdev the device number (only valid if created file is a device) */ - void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name, - mode_t mode, dev_t rdev); + void (*mknod)(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, dev_t rdev); /** * Create a directory @@ -313,8 +313,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param name to create * @param mode with which to create the new file */ - void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name, - mode_t mode); + void (*mkdir)(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode); /** * Remove a file @@ -331,7 +331,7 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param parent inode number of the parent directory * @param name to remove */ - void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name); + void (*unlink)(fuse_req_t req, fuse_ino_t parent, const char *name); /** * Remove a directory @@ -348,7 +348,7 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param parent inode number of the parent directory * @param name to remove */ - void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name); + void (*rmdir)(fuse_req_t req, fuse_ino_t parent, const char *name); /** * Create a symbolic link @@ -362,8 +362,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param parent inode number of the parent directory * @param name to create */ - void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent, - const char *name); + void (*symlink)(fuse_req_t req, const char *link, fuse_ino_t parent, + const char *name); /** Rename a file * @@ -382,8 +382,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param newparent inode number of the new parent directory * @param newname new name */ - void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name, - fuse_ino_t newparent, const char *newname); + void (*rename)(fuse_req_t req, fuse_ino_t parent, const char *name, + fuse_ino_t newparent, const char *newname); /** * Create a hard link @@ -397,8 +397,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param newparent inode number of the new parent directory * @param newname new name to create */ - void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, - const char *newname); + void (*link)(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, + const char *newname); /** * Open a file @@ -425,8 +425,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param fi file information */ - void (*open) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi); + void (*open)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi); /** * Read data @@ -453,8 +453,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param off offset to read from * @param fi file information */ - void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, - struct fuse_file_info *fi); + void (*read)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + fuse_file_info_t *fi); /** * Write data @@ -479,8 +479,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param off offset to write to * @param fi file information */ - void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf, - size_t size, off_t off, struct fuse_file_info *fi); + void (*write)(fuse_req_t req, fuse_ino_t ino, const char *buf, + size_t size, off_t off, fuse_file_info_t *fi); /** * Flush method @@ -511,8 +511,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param fi file information */ - void (*flush) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi); + void (*flush)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi); /** * Release an open file @@ -538,8 +538,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param fi file information */ - void (*release) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi); + void (*release)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi); /** * Synchronize file contents @@ -555,8 +555,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param datasync flag indicating if only data should be flushed * @param fi file information */ - void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync, - struct fuse_file_info *fi); + void (*fsync)(fuse_req_t req, fuse_ino_t ino, int datasync, + fuse_file_info_t *fi); /** * Open a directory @@ -579,8 +579,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param fi file information */ - void (*opendir) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi); + void (*opendir)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi); /** * Read directory @@ -603,12 +603,12 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param off offset to continue reading the directory stream * @param fi file information */ - void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, - struct fuse_file_info *llffi); + void (*readdir)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, + fuse_file_info_t *llffi); void (*readdir_plus)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, - struct fuse_file_info *ffi); + fuse_file_info_t *ffi); /** * Release an open directory @@ -626,8 +626,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param fi file information */ - void (*releasedir) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi); + void (*releasedir)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi); /** * Synchronize directory contents @@ -646,8 +646,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param datasync flag indicating if only data should be flushed * @param fi file information */ - void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync, - struct fuse_file_info *fi); + void (*fsyncdir)(fuse_req_t req, fuse_ino_t ino, int datasync, + fuse_file_info_t *fi); /** * Get file system statistics @@ -659,7 +659,7 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param req request handle * @param ino the inode number, zero means "undefined" */ - void (*statfs) (fuse_req_t req, fuse_ino_t ino); + void (*statfs)(fuse_req_t req, fuse_ino_t ino); /** * Set an extended attribute @@ -667,8 +667,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * Valid replies: * fuse_reply_err */ - void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name, - const char *value, size_t size, int flags); + void (*setxattr)(fuse_req_t req, fuse_ino_t ino, const char *name, + const char *value, size_t size, int flags); /** * Get an extended attribute @@ -693,8 +693,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param name of the extended attribute * @param size maximum size of the value to send */ - void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name, - size_t size); + void (*getxattr)(fuse_req_t req, fuse_ino_t ino, const char *name, + size_t size); /** * List extended attribute names @@ -719,7 +719,7 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param size maximum size of the list to send */ - void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size); + void (*listxattr)(fuse_req_t req, fuse_ino_t ino, size_t size); /** * Remove an extended attribute @@ -731,7 +731,7 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param name of the extended attribute */ - void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name); + void (*removexattr)(fuse_req_t req, fuse_ino_t ino, const char *name); /** * Check file access permissions @@ -751,7 +751,7 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param ino the inode number * @param mask requested access mode */ - void (*access) (fuse_req_t req, fuse_ino_t ino, int mask); + void (*access)(fuse_req_t req, fuse_ino_t ino, int mask); /** * Create and open a file @@ -786,8 +786,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param mode file type and mode with which to create the new file * @param fi file information */ - void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name, - mode_t mode, struct fuse_file_info *fi); + void (*create)(fuse_req_t req, fuse_ino_t parent, const char *name, + mode_t mode, fuse_file_info_t *fi); /** * Test for a POSIX file lock @@ -803,8 +803,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param fi file information * @param lock the region/type to test */ - void (*getlk) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi, struct flock *lock); + void (*getlk)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi, struct flock *lock); /** * Acquire, modify or release a POSIX file lock @@ -830,9 +830,9 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param lock the region/type to set * @param sleep locking operation may sleep */ - void (*setlk) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi, - struct flock *lock, int sleep); + void (*setlk)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi, + struct flock *lock, int sleep); /** * Map block index within file to block index within device @@ -851,8 +851,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param blocksize unit of block index * @param idx block index within file */ - void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize, - uint64_t idx); + void (*bmap)(fuse_req_t req, fuse_ino_t ino, size_t blocksize, + uint64_t idx); /** * Ioctl @@ -881,9 +881,9 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param in_bufsz number of fetched bytes * @param out_bufsz maximum size of output data */ - void (*ioctl) (fuse_req_t req, fuse_ino_t ino, unsigned long cmd, void *arg, - struct fuse_file_info *fi, unsigned flags, - const void *in_buf, uint32_t in_bufsz, uint32_t out_bufsz); + void (*ioctl)(fuse_req_t req, fuse_ino_t ino, unsigned long cmd, void *arg, + fuse_file_info_t *fi, unsigned flags, + const void *in_buf, uint32_t in_bufsz, uint32_t out_bufsz); /** * Poll for IO readiness @@ -911,8 +911,10 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param fi file information * @param ph poll handle to be used for notification */ - void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, - struct fuse_pollhandle *ph); + void (*poll)(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi, + fuse_pollhandle_t *ph); /** * Write data made available in a buffer @@ -940,9 +942,9 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param off offset to write to * @param fi file information */ - void (*write_buf) (fuse_req_t req, fuse_ino_t ino, - struct fuse_bufvec *bufv, off_t off, - struct fuse_file_info *fi); + void (*write_buf)(fuse_req_t req, fuse_ino_t ino, + struct fuse_bufvec *bufv, off_t off, + fuse_file_info_t *fi); /** * Callback function for the retrieve request @@ -958,8 +960,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param offset the offset supplied to fuse_lowlevel_notify_retrieve() * @param bufv the buffer containing the returned data */ - void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino, - off_t offset, struct fuse_bufvec *bufv); + void (*retrieve_reply)(fuse_req_t req, void *cookie, fuse_ino_t ino, + off_t offset, struct fuse_bufvec *bufv); /** * Forget about multiple inodes @@ -974,8 +976,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * * @param req request handle */ - void (*forget_multi) (fuse_req_t req, size_t count, - struct fuse_forget_data *forgets); + void (*forget_multi)(fuse_req_t req, size_t count, + struct fuse_forget_data *forgets); /** * Acquire, modify or release a BSD file lock @@ -994,8 +996,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param fi file information * @param op the locking operation, see flock(2) */ - void (*flock) (fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi, int op); + void (*flock)(fuse_req_t req, fuse_ino_t ino, + fuse_file_info_t *fi, int op); /** * Allocate requested space. If this function returns success then @@ -1014,8 +1016,8 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param mode determines the operation to be performed on the given range, * see fallocate(2) */ - void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode, - off_t offset, off_t length, struct fuse_file_info *fi); + void (*fallocate)(fuse_req_t req, fuse_ino_t ino, int mode, + off_t offset, off_t length, fuse_file_info_t *fi); /** * Copy a range of data from one file to another @@ -1053,15 +1055,15 @@ void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); * @param len maximum size of the data to copy * @param flags passed along with the copy_file_range() syscall */ - void (*copy_file_range)(fuse_req_t req, - fuse_ino_t ino_in, - off_t off_in, - struct fuse_file_info *fi_in, - fuse_ino_t ino_out, - off_t off_out, - struct fuse_file_info *fi_out, - size_t len, - int flags); + void (*copy_file_range)(fuse_req_t req, + fuse_ino_t ino_in, + off_t off_in, + fuse_file_info_t *fi_in, + fuse_ino_t ino_out, + off_t off_out, + fuse_file_info_t *fi_out, + size_t len, + int flags); }; /** @@ -1122,7 +1124,7 @@ int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e); * @return zero for success, -errno for failure to send reply */ int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, - const struct fuse_file_info *fi); + const fuse_file_info_t *fi); /** * Reply with attributes @@ -1164,7 +1166,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, const struct fuse_file_info *fi); +int fuse_reply_open(fuse_req_t req, const fuse_file_info_t *fi); /** * Reply with number of bytes written @@ -1331,7 +1333,7 @@ int fuse_reply_poll(fuse_req_t req, unsigned revents); * * @param ph poll handle to notify IO readiness event for */ -int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph); +int fuse_lowlevel_notify_poll(fuse_pollhandle_t *ph); /** * Notify to invalidate cache for an inode @@ -1549,8 +1551,8 @@ struct fuse_session_ops * @param len request length * @param ch channel on which the request was received */ - void (*process) (void *data, const char *buf, size_t len, - struct fuse_chan *ch); + void (*process)(void *data, const char *buf, size_t len, + struct fuse_chan *ch); /** * Hook for session exit and reset (optional) @@ -1558,7 +1560,7 @@ struct fuse_session_ops * @param data user data passed to fuse_session_new() * @param val exited status (1 - exited, 0 - not exited) */ - void (*exit) (void *data, int val); + void (*exit)(void *data, int val); /** * Hook for querying the current exited status (optional) @@ -1566,14 +1568,14 @@ struct fuse_session_ops * @param data user data passed to fuse_session_new() * @return 1 if exited, 0 if not exited */ - int (*exited) (void *data); + int (*exited)(void *data); /** * Hook for cleaning up the channel on destroy (optional) * * @param data user data passed to fuse_session_new() */ - void (*destroy) (void *data); + void (*destroy)(void *data); }; /** diff --git a/libfuse/lib/fuse.c b/libfuse/lib/fuse.c index 8a53495b..6d3f1fa0 100644 --- a/libfuse/lib/fuse.c +++ b/libfuse/lib/fuse.c @@ -6,7 +6,6 @@ See the file COPYING.LIB */ - /* For pthread_rwlock_t */ #define _GNU_SOURCE @@ -45,8 +44,6 @@ #undef FUSE_NODE_SLAB #endif -#define FUSE_DEFAULT_INTR_SIGNAL SIGUSR1 - #define FUSE_UNKNOWN_INO UINT64_MAX #define OFFSET_MAX 0x7fffffffffffffffLL @@ -56,15 +53,13 @@ struct fuse_config { unsigned int uid; unsigned int gid; - unsigned int umask; + unsigned int umask; int remember; int debug; int use_ino; int set_mode; int set_uid; int set_gid; - int intr; - int intr_signal; int help; int threads; }; @@ -102,12 +97,12 @@ struct node_table size_t split; }; -#define container_of(ptr, type, member) ({ \ +#define container_of(ptr,type,member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) -#define list_entry(ptr, type, member) \ - container_of(ptr, type, member) +#define list_entry(ptr,type,member) \ + container_of(ptr,type,member) struct list_head { @@ -167,7 +162,9 @@ struct node uint64_t hidden_fh; char is_hidden; int treelock; - struct stat stat_cache; + ino_t ino; + off_t size; + struct timespec mtim; char stat_cache_valid; char inline_name[32]; }; @@ -232,7 +229,7 @@ void list_add_head(struct list_head *new, struct list_head *head) { - list_add(new, head, head->next); + list_add(new,head,head->next); } static @@ -241,7 +238,7 @@ void list_add_tail(struct list_head *new, struct list_head *head) { - list_add(new, head->prev, head); + list_add(new,head->prev,head); } static @@ -276,7 +273,7 @@ static size_t get_node_size(struct fuse *f) { - if (lru_enabled(f)) + if(lru_enabled(f)) return sizeof(struct node_lru); else return sizeof(struct node); @@ -287,14 +284,15 @@ static struct node_slab* list_to_slab(struct list_head *head) { - return (struct node_slab *) head; + return (struct node_slab *)head; } static struct node_slab* -node_to_slab(struct fuse *f, struct node *node) +node_to_slab(struct fuse *f, + struct node *node) { - return (struct node_slab *) (((uintptr_t) node) & ~((uintptr_t) f->pagesize - 1)); + return (struct node_slab *)(((uintptr_t)node) & ~((uintptr_t)f->pagesize - 1)); } static @@ -308,10 +306,10 @@ alloc_slab(struct fuse *f) size_t i; size_t node_size = get_node_size(f); - mem = mmap(NULL, f->pagesize, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + mem = mmap(NULL,f->pagesize,PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS,-1,0); - if (mem == MAP_FAILED) + if(mem == MAP_FAILED) return -1; slab = mem; @@ -319,14 +317,15 @@ alloc_slab(struct fuse *f) slab->used = 0; num = (f->pagesize - sizeof(struct node_slab)) / node_size; - start = (char *) mem + f->pagesize - num * node_size; - for (i = 0; i < num; i++) { - struct list_head *n; + start = (char *)mem + f->pagesize - num * node_size; + for(i = 0; i < num; i++) + { + struct list_head *n; - n = (struct list_head *) (start + i * node_size); - list_add_tail(n, &slab->freelist); - } - list_add_tail(&slab->list, &f->partial_slabs); + n = (struct list_head *)(start + i * node_size); + list_add_tail(n,&slab->freelist); + } + list_add_tail(&slab->list,&f->partial_slabs); return 0; } @@ -338,22 +337,24 @@ alloc_node(struct fuse *f) struct node_slab *slab; struct list_head *node; - if (list_empty(&f->partial_slabs)) { - int res = alloc_slab(f); - if (res != 0) - return NULL; - } + if(list_empty(&f->partial_slabs)) + { + int res = alloc_slab(f); + if(res != 0) + return NULL; + } slab = list_to_slab(f->partial_slabs.next); slab->used++; node = slab->freelist.next; list_del(node); - if (list_empty(&slab->freelist)) { - list_del(&slab->list); - list_add_tail(&slab->list, &f->full_slabs); - } - memset(node, 0, sizeof(struct node)); + if(list_empty(&slab->freelist)) + { + list_del(&slab->list); + list_add_tail(&slab->list,&f->full_slabs); + } + memset(node,0,sizeof(struct node)); - return (struct node *) node; + return (struct node *)node; } static @@ -364,9 +365,9 @@ free_slab(struct fuse *f, int res; list_del(&slab->list); - res = munmap(slab, f->pagesize); - if (res == -1) - fprintf(stderr, "fuse warning: munmap(%p) failed\n", slab); + res = munmap(slab,f->pagesize); + if(res == -1) + fprintf(stderr,"fuse warning: munmap(%p) failed\n",slab); } static @@ -374,26 +375,30 @@ void free_node_mem(struct fuse *f, struct node *node) { - struct node_slab *slab = node_to_slab(f, node); - struct list_head *n = (struct list_head *) node; + struct node_slab *slab = node_to_slab(f,node); + struct list_head *n = (struct list_head *)node; slab->used--; - if (slab->used) { - if (list_empty(&slab->freelist)) { - list_del(&slab->list); - list_add_tail(&slab->list, &f->partial_slabs); + if(slab->used) + { + if(list_empty(&slab->freelist)) + { + list_del(&slab->list); + list_add_tail(&slab->list,&f->partial_slabs); + } + list_add_head(n,&slab->freelist); + } + else + { + free_slab(f,slab); } - list_add_head(n, &slab->freelist); - } else { - free_slab(f, slab); - } } #else static struct node* alloc_node(struct fuse *f) { - return (struct node *) calloc(1, get_node_size(f)); + return (struct node *)calloc(1,get_node_size(f)); } static @@ -401,7 +406,7 @@ void free_node_mem(struct fuse *f, struct node *node) { - (void) f; + (void)f; free(node); } #endif @@ -411,10 +416,10 @@ size_t id_hash(struct fuse *f, fuse_ino_t ino) { - uint64_t hash = ((uint32_t) ino * 2654435761U) % f->id_table.size; + 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; @@ -425,11 +430,11 @@ struct node* get_node_nocheck(struct fuse *f, fuse_ino_t nodeid) { - size_t hash = id_hash(f, nodeid); + size_t hash = id_hash(f,nodeid); struct node *node; - for (node = f->id_table.array[hash]; node != NULL; node = node->id_next) - if (node->nodeid == nodeid) + for(node = f->id_table.array[hash]; node != NULL; node = node->id_next) + if(node->nodeid == nodeid) return node; return NULL; @@ -440,12 +445,12 @@ struct node* get_node(struct fuse *f, const fuse_ino_t nodeid) { - struct node *node = get_node_nocheck(f, nodeid); + struct node *node = get_node_nocheck(f,nodeid); if(!node) { - fprintf(stderr, "fuse internal error: node %llu not found\n", - (unsigned long long) nodeid); + fprintf(stderr,"fuse internal error: node %llu not found\n", + (unsigned long long)nodeid); abort(); } @@ -473,7 +478,7 @@ set_forget_time(struct fuse *f, struct node_lru *lnode = node_lru(node); list_del(&lnode->lru); - list_add_tail(&lnode->lru, &f->lru_table); + list_add_tail(&lnode->lru,&f->lru_table); curr_time(&lnode->forget_time); } @@ -498,11 +503,11 @@ node_table_reduce(struct node_table *t) size_t newsize = t->size / 2; void *newarray; - if (newsize < NODE_TABLE_MIN_SIZE) + if(newsize < NODE_TABLE_MIN_SIZE) return; - newarray = realloc(t->array, sizeof(struct node *) * newsize); - if (newarray != NULL) + newarray = realloc(t->array,sizeof(struct node *)* newsize); + if(newarray != NULL) t->array = newarray; t->size = newsize; @@ -516,216 +521,264 @@ remerge_id(struct fuse *f) struct node_table *t = &f->id_table; int iter; - if (t->split == 0) + if(t->split == 0) node_table_reduce(t); - for (iter = 8; t->split > 0 && iter; iter--) { - struct node **upper; + for(iter = 8; t->split > 0 && iter; iter--) + { + struct node **upper; - t->split--; - upper = &t->array[t->split + t->size / 2]; - if (*upper) { - struct node **nodep; + t->split--; + upper = &t->array[t->split + t->size / 2]; + if(*upper) + { + struct node **nodep; - for (nodep = &t->array[t->split]; *nodep; - nodep = &(*nodep)->id_next); + for(nodep = &t->array[t->split]; *nodep; + nodep = &(*nodep)->id_next); - *nodep = *upper; - *upper = NULL; - break; + *nodep = *upper; + *upper = NULL; + break; + } } - } } static void -unhash_id(struct fuse *f, struct node *node) +unhash_id(struct fuse *f, + struct node *node) { - struct node **nodep = &f->id_table.array[id_hash(f, node->nodeid)]; + struct node **nodep = &f->id_table.array[id_hash(f,node->nodeid)]; - for (; *nodep != NULL; nodep = &(*nodep)->id_next) - if (*nodep == node) { - *nodep = node->id_next; - f->id_table.use--; + for(; *nodep != NULL; nodep = &(*nodep)->id_next) + if(*nodep == node) + { + *nodep = node->id_next; + f->id_table.use--; - if(f->id_table.use < f->id_table.size / 4) - remerge_id(f); - return; - } + if(f->id_table.use < f->id_table.size / 4) + remerge_id(f); + return; + } } -static int node_table_resize(struct node_table *t) +static +int +node_table_resize(struct node_table *t) { size_t newsize = t->size * 2; void *newarray; - newarray = realloc(t->array, sizeof(struct node *) * newsize); - if (newarray == NULL) + newarray = realloc(t->array,sizeof(struct node *)* newsize); + if(newarray == NULL) return -1; t->array = newarray; - memset(t->array + t->size, 0, t->size * sizeof(struct node *)); + memset(t->array + t->size,0,t->size * sizeof(struct node *)); t->size = newsize; t->split = 0; return 0; } -static void rehash_id(struct fuse *f) +static +void +rehash_id(struct fuse *f) { struct node_table *t = &f->id_table; struct node **nodep; struct node **next; size_t hash; - if (t->split == t->size / 2) + if(t->split == t->size / 2) return; hash = t->split; t->split++; - for (nodep = &t->array[hash]; *nodep != NULL; nodep = next) { - struct node *node = *nodep; - size_t newhash = id_hash(f, node->nodeid); - - if (newhash != hash) { - next = nodep; - *nodep = node->id_next; - node->id_next = t->array[newhash]; - t->array[newhash] = node; - } else { - next = &node->id_next; + for(nodep = &t->array[hash]; *nodep != NULL; nodep = next) + { + struct node *node = *nodep; + size_t newhash = id_hash(f,node->nodeid); + + if(newhash != hash) + { + next = nodep; + *nodep = node->id_next; + node->id_next = t->array[newhash]; + t->array[newhash] = node; + } + else + { + next = &node->id_next; + } } - } - if (t->split == t->size / 2) + + if(t->split == t->size / 2) node_table_resize(t); } -static void hash_id(struct fuse *f, struct node *node) +static +void +hash_id(struct fuse *f, + struct node *node) { - size_t hash = id_hash(f, node->nodeid); + 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++; - if (f->id_table.use >= f->id_table.size / 2) + if(f->id_table.use >= f->id_table.size / 2) rehash_id(f); } -static size_t name_hash(struct fuse *f, fuse_ino_t parent, - const char *name) +static +size_t +name_hash(struct fuse *f, + fuse_ino_t parent, + const char *name) { uint64_t hash = parent; uint64_t oldhash; - for (; *name; name++) - hash = hash * 31 + (unsigned char) *name; + 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) + if(oldhash >= f->name_table.split) return oldhash; else return hash; } -static void unref_node(struct fuse *f, struct node *node); +static +void +unref_node(struct fuse *f, + struct node *node); -static void remerge_name(struct fuse *f) +static +void +remerge_name(struct fuse *f) { - struct node_table *t = &f->name_table; int iter; + struct node_table *t = &f->name_table; - if (t->split == 0) + if(t->split == 0) node_table_reduce(t); - for (iter = 8; t->split > 0 && iter; iter--) { - struct node **upper; + for(iter = 8; t->split > 0 && iter; iter--) + { + struct node **upper; - t->split--; - upper = &t->array[t->split + t->size / 2]; - if (*upper) { - struct node **nodep; + t->split--; + upper = &t->array[t->split + t->size / 2]; + if(*upper) + { + struct node **nodep; - for (nodep = &t->array[t->split]; *nodep; - nodep = &(*nodep)->name_next); + for(nodep = &t->array[t->split]; *nodep; nodep = &(*nodep)->name_next); - *nodep = *upper; - *upper = NULL; - break; + *nodep = *upper; + *upper = NULL; + break; + } } - } } -static void unhash_name(struct fuse *f, struct node *node) +static +void +unhash_name(struct fuse *f, + struct node *node) { - if (node->name) { - size_t hash = name_hash(f, node->parent->nodeid, node->name); - struct node **nodep = &f->name_table.array[hash]; + if(node->name) + { + size_t hash = name_hash(f,node->parent->nodeid,node->name); + struct node **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); + if(node->name != node->inline_name) + free(node->name); + node->name = NULL; + node->parent = NULL; + f->name_table.use--; + + if(f->name_table.use < f->name_table.size / 4) + remerge_name(f); + return; + } - for (; *nodep != NULL; nodep = &(*nodep)->name_next) - if (*nodep == node) { - *nodep = node->name_next; - node->name_next = NULL; - unref_node(f, node->parent); - if (node->name != node->inline_name) - free(node->name); - node->name = NULL; - node->parent = NULL; - f->name_table.use--; + fprintf(stderr, + "fuse internal error: unable to unhash node: %llu\n", + (unsigned long long)node->nodeid); - if (f->name_table.use < f->name_table.size / 4) - remerge_name(f); - return; - } - fprintf(stderr, - "fuse internal error: unable to unhash node: %llu\n", - (unsigned long long) node->nodeid); - abort(); - } + abort(); + } } -static void rehash_name(struct fuse *f) +static +void +rehash_name(struct fuse *f) { struct node_table *t = &f->name_table; struct node **nodep; struct node **next; size_t hash; - if (t->split == t->size / 2) + if(t->split == t->size / 2) return; hash = t->split; t->split++; - for (nodep = &t->array[hash]; *nodep != NULL; nodep = next) { - struct node *node = *nodep; - size_t newhash = name_hash(f, node->parent->nodeid, node->name); - - if (newhash != hash) { - next = nodep; - *nodep = node->name_next; - node->name_next = t->array[newhash]; - t->array[newhash] = node; - } else { - next = &node->name_next; + for(nodep = &t->array[hash]; *nodep != NULL; nodep = next) + { + struct node *node = *nodep; + size_t newhash = name_hash(f,node->parent->nodeid,node->name); + + if(newhash != hash) + { + next = nodep; + *nodep = node->name_next; + node->name_next = t->array[newhash]; + t->array[newhash] = node; + } + else + { + next = &node->name_next; + } } - } - if (t->split == t->size / 2) + + if(t->split == t->size / 2) node_table_resize(t); } -static int hash_name(struct fuse *f, struct node *node, fuse_ino_t parentid, - const char *name) -{ - size_t hash = name_hash(f, parentid, name); - struct node *parent = get_node(f, parentid); - if (strlen(name) < sizeof(node->inline_name)) { - strcpy(node->inline_name, name); - node->name = node->inline_name; - } else { - node->name = strdup(name); - if (node->name == NULL) - return -1; - } +static +int +hash_name(struct fuse *f, + struct node *node, + fuse_ino_t parentid, + const char *name) +{ + size_t hash = name_hash(f,parentid,name); + struct node *parent = get_node(f,parentid); + if(strlen(name) < sizeof(node->inline_name)) + { + strcpy(node->inline_name,name); + node->name = node->inline_name; + } + else + { + node->name = strdup(name); + if(node->name == NULL) + return -1; + } parent->refctr ++; node->parent = parent; @@ -733,32 +786,37 @@ static int hash_name(struct fuse *f, struct node *node, fuse_ino_t parentid, f->name_table.array[hash] = node; f->name_table.use++; - if (f->name_table.use >= f->name_table.size / 2) + if(f->name_table.use >= f->name_table.size / 2) rehash_name(f); return 0; } -static void delete_node(struct fuse *f, struct node *node) +static +void +delete_node(struct fuse *f, + struct node *node) { - if (f->conf.debug) - fprintf(stderr, "DELETE: %llu\n", - (unsigned long long) node->nodeid); + if(f->conf.debug) + fprintf(stderr,"DELETE: %llu\n",(unsigned long long)node->nodeid); assert(node->treelock == 0); - unhash_name(f, node); - if (lru_enabled(f)) + unhash_name(f,node); + if(lru_enabled(f)) remove_node_lru(node); - unhash_id(f, node); - free_node(f, node); + unhash_id(f,node); + free_node(f,node); } -static void unref_node(struct fuse *f, struct node *node) +static +void +unref_node(struct fuse *f, + struct node *node) { assert(node->refctr > 0); - node->refctr --; - if (!node->refctr) - delete_node(f, node); + node->refctr--; + if(!node->refctr) + delete_node(f,node); } static @@ -785,127 +843,158 @@ next_id(struct fuse *f) f->generation++; } while((f->ctr == 0) || (f->ctr == FUSE_UNKNOWN_INO) || - (get_node_nocheck(f, f->ctr) != NULL)); + (get_node_nocheck(f,f->ctr) != NULL)); return f->ctr; } -static struct node *lookup_node(struct fuse *f, fuse_ino_t parent, - const char *name) +static +struct node* +lookup_node(struct fuse *f, + fuse_ino_t parent, + const char *name) { - size_t hash = name_hash(f, parent, name); + size_t hash; struct node *node; - for (node = f->name_table.array[hash]; node != NULL; node = node->name_next) - if (node->parent->nodeid == parent && - strcmp(node->name, name) == 0) + hash = name_hash(f,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; return NULL; } -static void inc_nlookup(struct node *node) +static +void +inc_nlookup(struct node *node) { - if (!node->nlookup) + if(!node->nlookup) node->refctr++; node->nlookup++; } -static struct node *find_node(struct fuse *f, fuse_ino_t parent, - const char *name) +static +struct node* +find_node(struct fuse *f, + fuse_ino_t parent, + const char *name) { struct node *node; pthread_mutex_lock(&f->lock); - if (!name) - node = get_node(f, parent); + if(!name) + node = get_node(f,parent); else - node = lookup_node(f, parent, name); - if (node == NULL) { - node = alloc_node(f); - if (node == NULL) - goto out_err; - - node->nodeid = next_id(f); - node->generation = f->generation; - if (f->conf.remember) - inc_nlookup(node); - - if (hash_name(f, node, parent, name) == -1) { - free_node(f, node); - node = NULL; - goto out_err; + node = lookup_node(f,parent,name); + if(node == NULL) + { + node = alloc_node(f); + if(node == NULL) + goto out_err; + + node->nodeid = next_id(f); + node->generation = f->generation; + if(f->conf.remember) + inc_nlookup(node); + + if(hash_name(f,node,parent,name) == -1) + { + free_node(f,node); + node = NULL; + goto out_err; + } + hash_id(f,node); + if(lru_enabled(f)) + { + struct node_lru *lnode = node_lru(node); + init_list_head(&lnode->lru); + } } - hash_id(f, node); - if (lru_enabled(f)) { - struct node_lru *lnode = node_lru(node); - init_list_head(&lnode->lru); + else if(lru_enabled(f) && node->nlookup == 1) + { + remove_node_lru(node); } - } else if (lru_enabled(f) && node->nlookup == 1) { - remove_node_lru(node); - } inc_nlookup(node); out_err: pthread_mutex_unlock(&f->lock); return node; } -static char *add_name(char **buf, unsigned *bufsize, char *s, const char *name) +static +char* +add_name(char **buf, + unsigned *bufsize, + char *s, + const char *name) { size_t len = strlen(name); - if (s - len <= *buf) { - unsigned pathlen = *bufsize - (s - *buf); - unsigned newbufsize = *bufsize; - char *newbuf; + if(s - len <= *buf) + { + unsigned pathlen = *bufsize - (s - *buf); + unsigned newbufsize = *bufsize; + char *newbuf; - while (newbufsize < pathlen + len + 1) { - if (newbufsize >= 0x80000000) - newbufsize = 0xffffffff; - else - newbufsize *= 2; - } + while(newbufsize < pathlen + len + 1) + { + if(newbufsize >= 0x80000000) + newbufsize = 0xffffffff; + else + newbufsize *= 2; + } - newbuf = realloc(*buf, newbufsize); - if (newbuf == NULL) - return NULL; + newbuf = realloc(*buf,newbufsize); + if(newbuf == NULL) + return NULL; - *buf = newbuf; - s = newbuf + newbufsize - pathlen; - memmove(s, newbuf + *bufsize - pathlen, pathlen); - *bufsize = newbufsize; - } + *buf = newbuf; + s = newbuf + newbufsize - pathlen; + memmove(s,newbuf + *bufsize - pathlen,pathlen); + *bufsize = newbufsize; + } s -= len; - strncpy(s, name, len); + strncpy(s,name,len); s--; *s = '/'; return s; } -static void unlock_path(struct fuse *f, fuse_ino_t nodeid, struct node *wnode, - struct node *end) +static +void +unlock_path(struct fuse *f, + fuse_ino_t nodeid, + struct node *wnode, + struct node *end) { struct node *node; - if (wnode) { - assert(wnode->treelock == TREELOCK_WRITE); - wnode->treelock = 0; - } + if(wnode) + { + assert(wnode->treelock == TREELOCK_WRITE); + wnode->treelock = 0; + } - for (node = get_node(f, nodeid); - node != end && node->nodeid != FUSE_ROOT_ID; node = node->parent) { - assert(node->treelock != 0); - assert(node->treelock != TREELOCK_WAIT_OFFSET); - assert(node->treelock != TREELOCK_WRITE); - node->treelock--; - if (node->treelock == TREELOCK_WAIT_OFFSET) - node->treelock = 0; - } + for(node = get_node(f,nodeid); node != end && node->nodeid != FUSE_ROOT_ID; node = node->parent) + { + assert(node->treelock != 0); + assert(node->treelock != TREELOCK_WAIT_OFFSET); + assert(node->treelock != TREELOCK_WRITE); + node->treelock--; + if(node->treelock == TREELOCK_WAIT_OFFSET) + node->treelock = 0; + } } -static int try_get_path(struct fuse *f, fuse_ino_t nodeid, const char *name, - char **path, struct node **wnodep, bool need_lock) +static +int +try_get_path(struct fuse *f, + fuse_ino_t nodeid, + const char *name, + char **path, + struct node **wnodep, + bool need_lock) { unsigned bufsize = 256; char *buf; @@ -918,67 +1007,72 @@ static int try_get_path(struct fuse *f, fuse_ino_t nodeid, const char *name, err = -ENOMEM; buf = malloc(bufsize); - if (buf == NULL) + if(buf == NULL) goto out_err; s = buf + bufsize - 1; *s = '\0'; - if (name != NULL) { - s = add_name(&buf, &bufsize, s, name); - err = -ENOMEM; - if (s == NULL) - goto out_free; - } - - if (wnodep) { - assert(need_lock); - wnode = lookup_node(f, nodeid, name); - if (wnode) { - if (wnode->treelock != 0) { - if (wnode->treelock > 0) - wnode->treelock += TREELOCK_WAIT_OFFSET; - err = -EAGAIN; + if(name != NULL) + { + s = add_name(&buf,&bufsize,s,name); + err = -ENOMEM; + if(s == NULL) goto out_free; - } - wnode->treelock = TREELOCK_WRITE; } - } - for (node = get_node(f, nodeid); node->nodeid != FUSE_ROOT_ID; - node = node->parent) { - err = -ENOENT; - if (node->name == NULL || node->parent == NULL) - goto out_unlock; + if(wnodep) + { + assert(need_lock); + wnode = lookup_node(f,nodeid,name); + if(wnode) + { + if(wnode->treelock != 0) + { + if(wnode->treelock > 0) + wnode->treelock += TREELOCK_WAIT_OFFSET; + err = -EAGAIN; + goto out_free; + } + wnode->treelock = TREELOCK_WRITE; + } + } - err = -ENOMEM; - s = add_name(&buf, &bufsize, s, node->name); - if (s == NULL) - goto out_unlock; + for(node = get_node(f,nodeid); node->nodeid != FUSE_ROOT_ID; node = node->parent) + { + err = -ENOENT; + if(node->name == NULL || node->parent == NULL) + goto out_unlock; - if (need_lock) { - err = -EAGAIN; - if (node->treelock < 0) + err = -ENOMEM; + s = add_name(&buf,&bufsize,s,node->name); + if(s == NULL) goto out_unlock; - node->treelock++; + if(need_lock) + { + err = -EAGAIN; + if(node->treelock < 0) + goto out_unlock; + + node->treelock++; + } } - } - if (s[0]) - memmove(buf, s, bufsize - (s - buf)); + if(s[0]) + memmove(buf,s,bufsize - (s - buf)); else - strcpy(buf, "/"); + strcpy(buf,"/"); *path = buf; - if (wnodep) + if(wnodep) *wnodep = wnode; return 0; out_unlock: - if (need_lock) - unlock_path(f, nodeid, wnode, node); + if(need_lock) + unlock_path(f,nodeid,wnode,node); out_free: free(buf); @@ -986,56 +1080,69 @@ static int try_get_path(struct fuse *f, fuse_ino_t nodeid, const char *name, return err; } -static void queue_element_unlock(struct fuse *f, struct lock_queue_element *qe) +static +void +queue_element_unlock(struct fuse *f, + struct lock_queue_element *qe) { struct node *wnode; - if (qe->first_locked) { - wnode = qe->wnode1 ? *qe->wnode1 : NULL; - unlock_path(f, qe->nodeid1, wnode, NULL); - qe->first_locked = false; - } - if (qe->second_locked) { - wnode = qe->wnode2 ? *qe->wnode2 : NULL; - unlock_path(f, qe->nodeid2, wnode, NULL); - qe->second_locked = false; - } + if(qe->first_locked) + { + wnode = qe->wnode1 ? *qe->wnode1 : NULL; + unlock_path(f,qe->nodeid1,wnode,NULL); + qe->first_locked = false; + } + + if(qe->second_locked) + { + wnode = qe->wnode2 ? *qe->wnode2 : NULL; + unlock_path(f,qe->nodeid2,wnode,NULL); + qe->second_locked = false; + } } -static void queue_element_wakeup(struct fuse *f, struct lock_queue_element *qe) +static +void +queue_element_wakeup(struct fuse *f, + struct lock_queue_element *qe) { int err; bool first = (qe == f->lockq); - if (!qe->path1) { - /* Just waiting for it to be unlocked */ - if (get_node(f, qe->nodeid1)->treelock == 0) - pthread_cond_signal(&qe->cond); + if(!qe->path1) + { + /* Just waiting for it to be unlocked */ + if(get_node(f,qe->nodeid1)->treelock == 0) + pthread_cond_signal(&qe->cond); - return; - } + return; + } - if (!qe->first_locked) { - err = try_get_path(f, qe->nodeid1, qe->name1, qe->path1, - qe->wnode1, true); - if (!err) - qe->first_locked = true; - else if (err != -EAGAIN) - goto err_unlock; - } - if (!qe->second_locked && qe->path2) { - err = try_get_path(f, qe->nodeid2, qe->name2, qe->path2, - qe->wnode2, true); - if (!err) - qe->second_locked = true; - else if (err != -EAGAIN) - goto err_unlock; - } + if(!qe->first_locked) + { + err = try_get_path(f,qe->nodeid1,qe->name1,qe->path1,qe->wnode1,true); + if(!err) + qe->first_locked = true; + else if(err != -EAGAIN) + goto err_unlock; + } - if (qe->first_locked && (qe->second_locked || !qe->path2)) { - err = 0; - goto done; - } + if(!qe->second_locked && qe->path2) + { + err = try_get_path(f,qe->nodeid2,qe->name2,qe->path2, + qe->wnode2,true); + if(!err) + qe->second_locked = true; + else if(err != -EAGAIN) + goto err_unlock; + } + + if(qe->first_locked && (qe->second_locked || !qe->path2)) + { + err = 0; + goto done; + } /* * Only let the first element be partially locked otherwise there could @@ -1044,197 +1151,267 @@ static void queue_element_wakeup(struct fuse *f, struct lock_queue_element *qe) * But do allow the first element to be partially locked to prevent * starvation. */ - if (!first) - queue_element_unlock(f, qe); + if(!first) + queue_element_unlock(f,qe); /* keep trying */ return; err_unlock: - queue_element_unlock(f, qe); + queue_element_unlock(f,qe); done: qe->err = err; qe->done = true; pthread_cond_signal(&qe->cond); } -static void wake_up_queued(struct fuse *f) +static +void +wake_up_queued(struct fuse *f) { 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(f,qe); } -static void debug_path(struct fuse *f, const char *msg, fuse_ino_t nodeid, - const char *name, bool wr) +static +void +debug_path(struct fuse *f, + const char *msg, + fuse_ino_t nodeid, + const char *name, + bool wr) { - if (f->conf.debug) { - struct node *wnode = NULL; + if(f->conf.debug) + { + struct node *wnode = NULL; - if (wr) - wnode = lookup_node(f, nodeid, name); + if(wr) + wnode = lookup_node(f,nodeid,name); - if (wnode) - fprintf(stderr, "%s %li (w)\n", msg, wnode->nodeid); - else - fprintf(stderr, "%s %li\n", msg, nodeid); - } + if(wnode) + fprintf(stderr,"%s %li (w)\n", msg,wnode->nodeid); + else + fprintf(stderr,"%s %li\n",msg,nodeid); + } } -static void queue_path(struct fuse *f, struct lock_queue_element *qe) +static +void +queue_path(struct fuse *f, + struct lock_queue_element *qe) { struct lock_queue_element **qp; qe->done = false; qe->first_locked = false; qe->second_locked = false; - pthread_cond_init(&qe->cond, NULL); + 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) +static +void +dequeue_path(struct fuse *f, + 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) +static +int +wait_path(struct fuse *f, + struct lock_queue_element *qe) { - queue_path(f, qe); + queue_path(f,qe); - do { - pthread_cond_wait(&qe->cond, &f->lock); - } while (!qe->done); + do + { + pthread_cond_wait(&qe->cond,&f->lock); + } while(!qe->done); - dequeue_path(f, qe); + dequeue_path(f,qe); return qe->err; } -static int get_path_common(struct fuse *f, fuse_ino_t nodeid, const char *name, - char **path, struct node **wnode) +static +int +get_path_common(struct fuse *f, + fuse_ino_t nodeid, + const char *name, + char **path, + struct node **wnode) { int err; pthread_mutex_lock(&f->lock); - err = try_get_path(f, nodeid, name, path, wnode, true); - if (err == -EAGAIN) { - struct lock_queue_element qe = { - .nodeid1 = nodeid, - .name1 = name, - .path1 = path, - .wnode1 = wnode, - }; - debug_path(f, "QUEUE PATH", nodeid, name, !!wnode); - err = wait_path(f, &qe); - debug_path(f, "DEQUEUE PATH", nodeid, name, !!wnode); - } + err = try_get_path(f,nodeid,name,path,wnode,true); + if(err == -EAGAIN) + { + struct lock_queue_element qe; + + qe.nodeid1 = nodeid; + qe.name1 = name; + qe.path1 = path; + qe.wnode1 = wnode; + + debug_path(f,"QUEUE PATH",nodeid,name,!!wnode); + err = wait_path(f,&qe); + debug_path(f,"DEQUEUE PATH",nodeid,name,!!wnode); + } pthread_mutex_unlock(&f->lock); return err; } -static int get_path(struct fuse *f, fuse_ino_t nodeid, char **path) +static +int +get_path(struct fuse *f, + fuse_ino_t nodeid, + char **path) { - return get_path_common(f, nodeid, NULL, path, NULL); + return get_path_common(f,nodeid,NULL,path,NULL); } -static int get_path_name(struct fuse *f, fuse_ino_t nodeid, const char *name, - char **path) +static +int +get_path_name(struct fuse *f, + fuse_ino_t nodeid, + const char *name, + char **path) { - return get_path_common(f, nodeid, name, path, NULL); + return get_path_common(f,nodeid,name,path,NULL); } -static int get_path_wrlock(struct fuse *f, fuse_ino_t nodeid, const char *name, - char **path, struct node **wnode) +static +int +get_path_wrlock(struct fuse *f, + fuse_ino_t nodeid, + const char *name, + char **path, + struct node **wnode) { - return get_path_common(f, nodeid, name, path, wnode); + return get_path_common(f,nodeid,name,path,wnode); } -static int try_get_path2(struct fuse *f, fuse_ino_t nodeid1, const char *name1, - fuse_ino_t nodeid2, const char *name2, - char **path1, char **path2, - struct node **wnode1, struct node **wnode2) +static +int +try_get_path2(struct fuse *f, + fuse_ino_t nodeid1, + const char *name1, + fuse_ino_t nodeid2, + const char *name2, + char **path1, + char **path2, + struct node **wnode1, + struct node **wnode2) { int err; /* FIXME: locking two paths needs deadlock checking */ - err = try_get_path(f, nodeid1, name1, path1, wnode1, true); - if (!err) { - err = try_get_path(f, nodeid2, name2, path2, wnode2, true); - if (err) { - struct node *wn1 = wnode1 ? *wnode1 : NULL; - - unlock_path(f, nodeid1, wn1, NULL); - free(*path1); + err = try_get_path(f,nodeid1,name1,path1,wnode1,true); + if(!err) + { + err = try_get_path(f,nodeid2,name2,path2,wnode2,true); + if(err) + { + struct node *wn1 = wnode1 ? *wnode1 : NULL; + + unlock_path(f,nodeid1,wn1,NULL); + free(*path1); + } } - } + return err; } -static int get_path2(struct fuse *f, fuse_ino_t nodeid1, const char *name1, - fuse_ino_t nodeid2, const char *name2, - char **path1, char **path2, - struct node **wnode1, struct node **wnode2) +static +int +get_path2(struct fuse *f, + fuse_ino_t nodeid1, + const char *name1, + fuse_ino_t nodeid2, + const char *name2, + char **path1, + char **path2, + struct node **wnode1, + struct node **wnode2) { int err; pthread_mutex_lock(&f->lock); - err = try_get_path2(f, nodeid1, name1, nodeid2, name2, - path1, path2, wnode1, wnode2); - if (err == -EAGAIN) { - struct lock_queue_element qe = { - .nodeid1 = nodeid1, - .name1 = name1, - .path1 = path1, - .wnode1 = wnode1, - .nodeid2 = nodeid2, - .name2 = name2, - .path2 = path2, - .wnode2 = wnode2, - }; - - debug_path(f, "QUEUE PATH1", nodeid1, name1, !!wnode1); - debug_path(f, " PATH2", nodeid2, name2, !!wnode2); - err = wait_path(f, &qe); - debug_path(f, "DEQUEUE PATH1", nodeid1, name1, !!wnode1); - debug_path(f, " PATH2", nodeid2, name2, !!wnode2); - } + err = try_get_path2(f,nodeid1,name1,nodeid2,name2, + path1,path2,wnode1,wnode2); + if(err == -EAGAIN) + { + struct lock_queue_element qe; + + qe.nodeid1 = nodeid1; + qe.name1 = name1; + qe.path1 = path1; + qe.wnode1 = wnode1; + qe.nodeid2 = nodeid2; + qe.name2 = name2; + qe.path2 = path2; + qe.wnode2 = wnode2; + + debug_path(f,"QUEUE PATH1",nodeid1,name1,!!wnode1); + debug_path(f," PATH2",nodeid2,name2,!!wnode2); + err = wait_path(f,&qe); + debug_path(f,"DEQUEUE PATH1",nodeid1,name1,!!wnode1); + debug_path(f," PATH2",nodeid2,name2,!!wnode2); + } pthread_mutex_unlock(&f->lock); return err; } -static void free_path_wrlock(struct fuse *f, fuse_ino_t nodeid, - struct node *wnode, char *path) +static +void +free_path_wrlock(struct fuse *f, + fuse_ino_t nodeid, + struct node *wnode, + char *path) { pthread_mutex_lock(&f->lock); - unlock_path(f, nodeid, wnode, NULL); - if (f->lockq) + unlock_path(f,nodeid,wnode,NULL); + if(f->lockq) wake_up_queued(f); pthread_mutex_unlock(&f->lock); free(path); } -static void free_path(struct fuse *f, fuse_ino_t nodeid, char *path) +static +void +free_path(struct fuse *f, + fuse_ino_t nodeid, + char *path) { - if (path) - free_path_wrlock(f, nodeid, NULL, path); + if(path) + free_path_wrlock(f,nodeid,NULL,path); } -static void free_path2(struct fuse *f, fuse_ino_t nodeid1, fuse_ino_t nodeid2, - struct node *wnode1, struct node *wnode2, - char *path1, char *path2) +static +void +free_path2(struct fuse *f, + fuse_ino_t nodeid1, + fuse_ino_t nodeid2, + struct node *wnode1, + struct node *wnode2, + char *path1, + char *path2) { pthread_mutex_lock(&f->lock); - unlock_path(f, nodeid1, wnode1, NULL); - unlock_path(f, nodeid2, wnode2, NULL); + unlock_path(f,nodeid1,wnode1,NULL); + unlock_path(f,nodeid2,wnode2,NULL); wake_up_queued(f); pthread_mutex_unlock(&f->lock); free(path1); @@ -1253,7 +1430,7 @@ forget_node(struct fuse *f, return; pthread_mutex_lock(&f->lock); - node = get_node(f, nodeid); + node = get_node(f,nodeid); /* * Node may still be locked due to interrupt idiocy in open, @@ -1261,164 +1438,115 @@ forget_node(struct fuse *f, */ while(node->nlookup == nlookup && node->treelock) { - struct lock_queue_element qe = { - .nodeid1 = nodeid, - }; + struct lock_queue_element qe; + + qe.nodeid1 = nodeid; - debug_path(f, "QUEUE PATH (forget)", nodeid, NULL, false); - queue_path(f, &qe); + debug_path(f,"QUEUE PATH (forget)",nodeid,NULL,false); + queue_path(f,&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); - debug_path(f, "DEQUEUE_PATH (forget)", nodeid, NULL, false); + dequeue_path(f,&qe); + debug_path(f,"DEQUEUE_PATH (forget)",nodeid,NULL,false); } assert(node->nlookup >= nlookup); node->nlookup -= nlookup; if(!node->nlookup) - unref_node(f, node); + unref_node(f,node); else if(lru_enabled(f) && node->nlookup == 1) - set_forget_time(f, node); + set_forget_time(f,node); pthread_mutex_unlock(&f->lock); } -static void unlink_node(struct fuse *f, struct node *node) +static +void +unlink_node(struct fuse *f, + struct node *node) { - if (f->conf.remember) { - assert(node->nlookup > 1); - node->nlookup--; - } - unhash_name(f, node); + if(f->conf.remember) + { + assert(node->nlookup > 1); + node->nlookup--; + } + unhash_name(f,node); } -static void remove_node(struct fuse *f, fuse_ino_t dir, const char *name) +static +void +remove_node(struct fuse *f, + fuse_ino_t dir, + const char *name) { struct node *node; pthread_mutex_lock(&f->lock); - node = lookup_node(f, dir, name); - if (node != NULL) - unlink_node(f, node); + node = lookup_node(f,dir,name); + if(node != NULL) + unlink_node(f,node); pthread_mutex_unlock(&f->lock); } -static int rename_node(struct fuse *f, fuse_ino_t olddir, const char *oldname, - fuse_ino_t newdir, const char *newname) +static +int +rename_node(struct fuse *f, + fuse_ino_t olddir, + const char *oldname, + fuse_ino_t newdir, + const char *newname) { struct node *node; struct node *newnode; int err = 0; pthread_mutex_lock(&f->lock); - node = lookup_node(f, olddir, oldname); - newnode = lookup_node(f, newdir, newname); - if (node == NULL) + node = lookup_node(f,olddir,oldname); + newnode = lookup_node(f,newdir,newname); + if(node == NULL) goto out; - if (newnode != NULL) - unlink_node(f, newnode); - + if(newnode != NULL) + unlink_node(f,newnode); - unhash_name(f, node); - if (hash_name(f, node, newdir, newname) == -1) { - err = -ENOMEM; - goto out; - } + unhash_name(f,node); + if(hash_name(f,node,newdir,newname) == -1) + { + err = -ENOMEM; + goto out; + } out: pthread_mutex_unlock(&f->lock); return err; } -static void set_stat(struct fuse *f, fuse_ino_t nodeid, struct stat *stbuf) +static +void +set_stat(struct fuse *f, + fuse_ino_t nodeid, + struct stat *stbuf) { - if (!f->conf.use_ino) + if(!f->conf.use_ino) stbuf->st_ino = nodeid; - if (f->conf.set_mode) - stbuf->st_mode = (stbuf->st_mode & S_IFMT) | - (0777 & ~f->conf.umask); - if (f->conf.set_uid) + 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) + if(f->conf.set_gid) stbuf->st_gid = f->conf.gid; } -static struct fuse *req_fuse(fuse_req_t req) +static +struct fuse* +req_fuse(fuse_req_t req) { - return (struct fuse *) fuse_req_userdata(req); -} - -static void fuse_intr_sighandler(int sig) -{ - (void) sig; - /* Nothing to do */ -} - -struct fuse_intr_data { - pthread_t id; - pthread_cond_t cond; - int finished; -}; - -static void fuse_interrupt(fuse_req_t req, void *d_) -{ - struct fuse_intr_data *d = d_; - struct fuse *f = req_fuse(req); - - if (d->id == pthread_self()) - return; - - pthread_mutex_lock(&f->lock); - while (!d->finished) { - struct timeval now; - struct timespec timeout; - - pthread_kill(d->id, f->conf.intr_signal); - gettimeofday(&now, NULL); - timeout.tv_sec = now.tv_sec + 1; - timeout.tv_nsec = now.tv_usec * 1000; - pthread_cond_timedwait(&d->cond, &f->lock, &timeout); - } - pthread_mutex_unlock(&f->lock); -} - -static void fuse_do_finish_interrupt(struct fuse *f, fuse_req_t req, - struct fuse_intr_data *d) -{ - pthread_mutex_lock(&f->lock); - d->finished = 1; - pthread_cond_broadcast(&d->cond); - pthread_mutex_unlock(&f->lock); - fuse_req_interrupt_func(req, NULL, NULL); - pthread_cond_destroy(&d->cond); -} - -static void fuse_do_prepare_interrupt(fuse_req_t req, struct fuse_intr_data *d) -{ - d->id = pthread_self(); - pthread_cond_init(&d->cond, NULL); - d->finished = 0; - fuse_req_interrupt_func(req, fuse_interrupt, d); -} - -static inline void fuse_finish_interrupt(struct fuse *f, fuse_req_t req, - struct fuse_intr_data *d) -{ - if (f->conf.intr) - fuse_do_finish_interrupt(f, req, d); -} - -static inline void fuse_prepare_interrupt(struct fuse *f, fuse_req_t req, - struct fuse_intr_data *d) -{ - if (f->conf.intr) - fuse_do_prepare_interrupt(req, d); + return (struct fuse*)fuse_req_userdata(req); } int @@ -1439,10 +1567,10 @@ fuse_fs_getattr(struct fuse_fs *fs, } int -fuse_fs_fgetattr(struct fuse_fs *fs, - struct stat *buf, - struct fuse_file_info *fi, - fuse_timeouts_t *timeout) +fuse_fs_fgetattr(struct fuse_fs *fs, + struct stat *buf, + fuse_file_info_t *fi, + fuse_timeouts_t *timeout) { if(fs->op.fgetattr == NULL) return -ENOSYS; @@ -1451,7 +1579,7 @@ fuse_fs_fgetattr(struct fuse_fs *fs, if(fs->debug) fprintf(stderr,"fgetattr[%llu]\n",(unsigned long long)fi->fh); - return fs->op.fgetattr(buf,fi,timeout); + return fs->op.fgetattr(fi,buf,timeout); } int @@ -1459,12 +1587,12 @@ fuse_fs_rename(struct fuse_fs *fs, const char *oldpath, const char *newpath) { - fuse_get_context()->private_data = fs->user_data; + if(fs->op.rename == NULL) + return -ENOSYS; - if(fs->op.rename) - return fs->op.rename(oldpath, newpath); + fuse_get_context()->private_data = fs->user_data; - return -ENOSYS; + return fs->op.rename(oldpath,newpath); } int @@ -1472,377 +1600,433 @@ fuse_fs_prepare_hide(struct fuse_fs *fs_, const char *path_, uint64_t *fh_) { - fuse_get_context()->private_data = fs_->user_data; + if(fs_->op.prepare_hide == NULL) + return -ENOSYS; - if(fs_->op.prepare_hide) - return fs_->op.prepare_hide(path_,fh_); + fuse_get_context()->private_data = fs_->user_data; - return -ENOSYS; + return fs_->op.prepare_hide(path_,fh_); } int fuse_fs_free_hide(struct fuse_fs *fs_, uint64_t fh_) { - fuse_get_context()->private_data = fs_->user_data; + if(fs_->op.free_hide == NULL) + return -ENOSYS; - if(fs_->op.free_hide) - return fs_->op.free_hide(fh_); + fuse_get_context()->private_data = fs_->user_data; - return -ENOSYS; + return fs_->op.free_hide(fh_); } -int fuse_fs_unlink(struct fuse_fs *fs, const char *path) +int +fuse_fs_unlink(struct fuse_fs *fs, + const char *path) { + if(fs->op.unlink == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.unlink) { - if (fs->debug) - fprintf(stderr, "unlink %s\n", path); - return fs->op.unlink(path); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"unlink %s\n",path); + + return fs->op.unlink(path); } -int fuse_fs_rmdir(struct fuse_fs *fs, const char *path) +int +fuse_fs_rmdir(struct fuse_fs *fs, + const char *path) { + if(fs->op.rmdir == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.rmdir) { - if (fs->debug) - fprintf(stderr, "rmdir %s\n", path); - return fs->op.rmdir(path); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"rmdir %s\n",path); + + return fs->op.rmdir(path); } -int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname, const char *path) +int +fuse_fs_symlink(struct fuse_fs *fs, + const char *linkname, + const char *path) { + if(fs->op.symlink == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.symlink) { - if (fs->debug) - fprintf(stderr, "symlink %s %s\n", linkname, path); - return fs->op.symlink(linkname, path); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"symlink %s %s\n",linkname,path); + + return fs->op.symlink(linkname,path); } -int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath) +int +fuse_fs_link(struct fuse_fs *fs, + const char *oldpath, + const char *newpath) { + if(fs->op.link == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.link) { - if (fs->debug) - fprintf(stderr, "link %s %s\n", oldpath, newpath); - return fs->op.link(oldpath, newpath); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"link %s %s\n",oldpath,newpath); + + return fs->op.link(oldpath,newpath); } -int fuse_fs_release(struct fuse_fs *fs, - struct fuse_file_info *fi) +int +fuse_fs_release(struct fuse_fs *fs, + fuse_file_info_t *fi) { + if(fs->op.release == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.release) { - if (fs->debug) - fprintf(stderr, "release%s[%llu] flags: 0x%x\n", - fi->flush ? "+flush" : "", - (unsigned long long) fi->fh, fi->flags); - - return fs->op.release(fi); - } else { - return 0; - } + + if(fs->debug) + fprintf(stderr,"release%s[%llu] flags: 0x%x\n", + fi->flush ? "+flush" : "", + (unsigned long long)fi->fh,fi->flags); + + return fs->op.release(fi); } -int fuse_fs_opendir(struct fuse_fs *fs, const char *path, - struct fuse_file_info *fi) +int +fuse_fs_opendir(struct fuse_fs *fs, + const char *path, + fuse_file_info_t *fi) { + int err; + + if(fs->op.opendir == NULL) + return 0; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.opendir) { - int err; - if (fs->debug) - fprintf(stderr, "opendir flags: 0x%x %s\n", fi->flags, - path); + if(fs->debug) + fprintf(stderr,"opendir flags: 0x%x %s\n",fi->flags,path); - err = fs->op.opendir(path,fi); + err = fs->op.opendir(path,fi); - if (fs->debug && !err) - fprintf(stderr, " opendir[%lli] flags: 0x%x %s\n", - (unsigned long long) fi->fh, fi->flags, path); + if(fs->debug && !err) + fprintf(stderr," opendir[%lli] flags: 0x%x %s\n", + (unsigned long long)fi->fh,fi->flags,path); - return err; - } else { - return 0; - } + return err; } -int fuse_fs_open(struct fuse_fs *fs, const char *path, - struct fuse_file_info *fi) +int +fuse_fs_open(struct fuse_fs *fs, + const char *path, + fuse_file_info_t *fi) { + int err; + + if(fs->op.open == NULL) + return 0; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.open) { - int err; - if (fs->debug) - fprintf(stderr, "open flags: 0x%x %s\n", fi->flags, - path); + if(fs->debug) + fprintf(stderr,"open flags: 0x%x %s\n",fi->flags,path); - err = fs->op.open(path,fi); + err = fs->op.open(path,fi); - if (fs->debug && !err) - fprintf(stderr, " open[%lli] flags: 0x%x %s\n", - (unsigned long long) fi->fh, fi->flags, path); + if(fs->debug && !err) + fprintf(stderr," open[%lli] flags: 0x%x %s\n", + (unsigned long long)fi->fh,fi->flags,path); - return err; - } else { - return 0; - } + return err; } -static void fuse_free_buf(struct fuse_bufvec *buf) +static +void +fuse_free_buf(struct fuse_bufvec *buf) { - if (buf != NULL) { - size_t i; + if(buf != NULL) + { + size_t i; - for (i = 0; i < buf->count; i++) - free(buf->buf[i].mem); - free(buf); - } + for(i = 0; i < buf->count; i++) + free(buf->buf[i].mem); + free(buf); + } } -int fuse_fs_read_buf(struct fuse_fs *fs, - struct fuse_bufvec **bufp, size_t size, off_t off, - struct fuse_file_info *fi) +int +fuse_fs_read_buf(struct fuse_fs *fs, + struct fuse_bufvec **bufp, + size_t size, + off_t off, + fuse_file_info_t *fi) { fuse_get_context()->private_data = fs->user_data; - if (fs->op.read || fs->op.read_buf) { - int res; + if(fs->op.read || fs->op.read_buf) + { + int res; - if (fs->debug) - fprintf(stderr, - "read[%llu] %zu bytes from %llu flags: 0x%x\n", - (unsigned long long) fi->fh, - size, (unsigned long long) off, fi->flags); - - if (fs->op.read_buf) { - res = fs->op.read_buf(bufp, size, off, fi); - } else { - struct fuse_bufvec *buf; - void *mem; - - buf = malloc(sizeof(struct fuse_bufvec)); - if (buf == NULL) - return -ENOMEM; - - mem = malloc(size); - if (mem == NULL) { - free(buf); - return -ENOMEM; - } - *buf = FUSE_BUFVEC_INIT(size); - buf->buf[0].mem = mem; - *bufp = buf; + if(fs->debug) + fprintf(stderr, + "read[%llu] %zu bytes from %llu flags: 0x%x\n", + (unsigned long long)fi->fh, + size,(unsigned long long)off,fi->flags); - res = fs->op.read(mem, size, off, fi); - if (res >= 0) - buf->buf[0].size = res; - } + if(fs->op.read_buf) + { + res = fs->op.read_buf(fi,bufp,size,off); + } + else + { + struct fuse_bufvec *buf; + void *mem; - if (fs->debug && res >= 0) - fprintf(stderr, " read[%llu] %zu bytes from %llu\n", - (unsigned long long) fi->fh, - fuse_buf_size(*bufp), - (unsigned long long) off); - if (res >= 0 && fuse_buf_size(*bufp) > (int) size) - fprintf(stderr, "fuse: read too many bytes\n"); + buf = malloc(sizeof(struct fuse_bufvec)); + if(buf == NULL) + return -ENOMEM; - if (res < 0) - return res; + mem = malloc(size); + if(mem == NULL) + { + free(buf); + return -ENOMEM; + } - return 0; - } else { - return -ENOSYS; - } + *buf = FUSE_BUFVEC_INIT(size); + buf->buf[0].mem = mem; + *bufp = buf; + + res = fs->op.read(fi,mem,size,off); + if(res >= 0) + buf->buf[0].size = res; + } + + if(fs->debug && res >= 0) + fprintf(stderr," read[%llu] %zu bytes from %llu\n", + (unsigned long long)fi->fh, + fuse_buf_size(*bufp), + (unsigned long long)off); + if(res >= 0 && fuse_buf_size(*bufp) > (int)size) + fprintf(stderr,"fuse: read too many bytes\n"); + + if(res < 0) + return res; + + return 0; + } + else + { + return -ENOSYS; + } } -int fuse_fs_read(struct fuse_fs *fs, char *mem, size_t size, - off_t off, struct fuse_file_info *fi) +int +fuse_fs_read(struct fuse_fs *fs, + char *mem, + size_t size, + off_t off, + fuse_file_info_t *fi) { int res; struct fuse_bufvec *buf = NULL; - res = fuse_fs_read_buf(fs, &buf, size, off, fi); - if (res == 0) { - struct fuse_bufvec dst = FUSE_BUFVEC_INIT(size); + res = fuse_fs_read_buf(fs,&buf,size,off,fi); + if(res == 0) + { + struct fuse_bufvec dst = FUSE_BUFVEC_INIT(size); - dst.buf[0].mem = mem; - res = fuse_buf_copy(&dst, buf, 0); - } + dst.buf[0].mem = mem; + res = fuse_buf_copy(&dst,buf,0); + } fuse_free_buf(buf); return res; } -int fuse_fs_write_buf(struct fuse_fs *fs, - struct fuse_bufvec *buf, off_t off, - struct fuse_file_info *fi) +int +fuse_fs_write_buf(struct fuse_fs *fs, + struct fuse_bufvec *buf, + off_t off, + fuse_file_info_t *fi) { fuse_get_context()->private_data = fs->user_data; - if (fs->op.write_buf || fs->op.write) { - int res; - size_t size = fuse_buf_size(buf); + if(fs->op.write_buf || fs->op.write) + { + int res; + size_t size = fuse_buf_size(buf); + + assert(buf->idx == 0 && buf->off == 0); + if(fs->debug) + fprintf(stderr, + "write%s[%llu] %zu bytes to %llu flags: 0x%x\n", + fi->writepage ? "page" : "", + (unsigned long long)fi->fh, + size, + (unsigned long long)off, + fi->flags); + + if(fs->op.write_buf) + { + res = fs->op.write_buf(fi,buf,off); + } + else + { + void *mem = NULL; + struct fuse_buf *flatbuf; + struct fuse_bufvec tmp = FUSE_BUFVEC_INIT(size); - assert(buf->idx == 0 && buf->off == 0); - if (fs->debug) - fprintf(stderr, - "write%s[%llu] %zu bytes to %llu flags: 0x%x\n", - fi->writepage ? "page" : "", - (unsigned long long) fi->fh, - size, - (unsigned long long) off, - fi->flags); - - if (fs->op.write_buf) { - res = fs->op.write_buf(buf, off, fi); - } else { - void *mem = NULL; - struct fuse_buf *flatbuf; - struct fuse_bufvec tmp = FUSE_BUFVEC_INIT(size); - - if (buf->count == 1 && - !(buf->buf[0].flags & FUSE_BUF_IS_FD)) { - flatbuf = &buf->buf[0]; - } else { - res = -ENOMEM; - mem = malloc(size); - if (mem == NULL) - goto out; - - tmp.buf[0].mem = mem; - res = fuse_buf_copy(&tmp, buf, 0); - if (res <= 0) - goto out_free; - - tmp.buf[0].size = res; - flatbuf = &tmp.buf[0]; - } + if(buf->count == 1 && !(buf->buf[0].flags & FUSE_BUF_IS_FD)) + { + flatbuf = &buf->buf[0]; + } + else + { + res = -ENOMEM; + mem = malloc(size); + if(mem == NULL) + goto out; + + tmp.buf[0].mem = mem; + res = fuse_buf_copy(&tmp,buf,0); + if(res <= 0) + goto out_free; + + tmp.buf[0].size = res; + flatbuf = &tmp.buf[0]; + } - res = fs->op.write(flatbuf->mem, flatbuf->size, - off, fi); - out_free: - free(mem); + res = fs->op.write(fi,flatbuf->mem,flatbuf->size,off); + out_free: + free(mem); + } + out: + if(fs->debug && res >= 0) + fprintf(stderr," write%s[%llu] %u bytes to %llu\n", + fi->writepage ? "page" : "", + (unsigned long long)fi->fh,res, + (unsigned long long)off); + if(res > (int)size) + fprintf(stderr,"fuse: wrote too many bytes\n"); + + return res; + } + else + { + return -ENOSYS; } - out: - if (fs->debug && res >= 0) - fprintf(stderr, " write%s[%llu] %u bytes to %llu\n", - fi->writepage ? "page" : "", - (unsigned long long) fi->fh, res, - (unsigned long long) off); - if (res > (int) size) - fprintf(stderr, "fuse: wrote too many bytes\n"); - - return res; - } else { - return -ENOSYS; - } } -int fuse_fs_write(struct fuse_fs *fs, const char *mem, - size_t size, off_t off, struct fuse_file_info *fi) +int +fuse_fs_write(struct fuse_fs *fs, + const char *mem, + size_t size, + off_t off, + fuse_file_info_t *fi) { struct fuse_bufvec bufv = FUSE_BUFVEC_INIT(size); - bufv.buf[0].mem = (void *) mem; + bufv.buf[0].mem = (void *)mem; - return fuse_fs_write_buf(fs, &bufv, off, fi); + return fuse_fs_write_buf(fs,&bufv,off,fi); } -int fuse_fs_fsync(struct fuse_fs *fs, int datasync, - struct fuse_file_info *fi) +int +fuse_fs_fsync(struct fuse_fs *fs, + int datasync, + fuse_file_info_t *fi) { + if(fs->op.fsync == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.fsync) { - if (fs->debug) - fprintf(stderr, "fsync[%llu] datasync: %i\n", - (unsigned long long) fi->fh, datasync); - return fs->op.fsync(datasync, fi); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"fsync[%llu] datasync: %i\n", + (unsigned long long)fi->fh,datasync); + + return fs->op.fsync(fi,datasync); } -int fuse_fs_fsyncdir(struct fuse_fs *fs, int datasync, - struct fuse_file_info *fi) +int +fuse_fs_fsyncdir(struct fuse_fs *fs, + int datasync, + fuse_file_info_t *fi) { + if(fs->op.fsyncdir == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.fsyncdir) { - if (fs->debug) - fprintf(stderr, "fsyncdir[%llu] datasync: %i\n", - (unsigned long long) fi->fh, datasync); - return fs->op.fsyncdir(datasync, fi); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"fsyncdir[%llu] datasync: %i\n", + (unsigned long long)fi->fh,datasync); + + return fs->op.fsyncdir(fi,datasync); } -int fuse_fs_flush(struct fuse_fs *fs, - struct fuse_file_info *fi) +int +fuse_fs_flush(struct fuse_fs *fs, + fuse_file_info_t *fi) { + if(fs->op.flush == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.flush) { - if (fs->debug) - fprintf(stderr, "flush[%llu]\n", - (unsigned long long) fi->fh); - return fs->op.flush(fi); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"flush[%llu]\n", + (unsigned long long)fi->fh); + + return fs->op.flush(fi); } -int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf) +int +fuse_fs_statfs(struct fuse_fs *fs, + const char *path, + struct statvfs *buf) { + if(fs->op.statfs == NULL) + { + buf->f_namemax = 255; + buf->f_bsize = 512; + return 0; + } + fuse_get_context()->private_data = fs->user_data; - if (fs->op.statfs) { - if (fs->debug) - fprintf(stderr, "statfs %s\n", path); - - return fs->op.statfs(path,buf); - } else { - buf->f_namemax = 255; - buf->f_bsize = 512; - return 0; - } + + if(fs->debug) + fprintf(stderr,"statfs %s\n",path); + + return fs->op.statfs(path,buf); } -int fuse_fs_releasedir(struct fuse_fs *fs, - struct fuse_file_info *fi) +int +fuse_fs_releasedir(struct fuse_fs *fs, + fuse_file_info_t *fi) { + if(fs->op.releasedir == NULL) + return 0; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.releasedir) { - if (fs->debug) - fprintf(stderr, "releasedir[%llu] flags: 0x%x\n", - (unsigned long long) fi->fh, fi->flags); - return fs->op.releasedir(fi); - } else { - return 0; - } + if(fs->debug) + fprintf(stderr,"releasedir[%llu] flags: 0x%x\n", + (unsigned long long)fi->fh,fi->flags); + + return fs->op.releasedir(fi); } int -fuse_fs_readdir(struct fuse_fs *fs, - struct fuse_file_info *fi, - fuse_dirents_t *buf) +fuse_fs_readdir(struct fuse_fs *fs, + fuse_file_info_t *fi, + fuse_dirents_t *buf) { if(fs->op.readdir == NULL) return -ENOSYS; @@ -1853,9 +2037,9 @@ fuse_fs_readdir(struct fuse_fs *fs, } int -fuse_fs_readdir_plus(struct fuse_fs *fs_, - struct fuse_file_info *ffi_, - fuse_dirents_t *buf_) +fuse_fs_readdir_plus(struct fuse_fs *fs_, + fuse_file_info_t *ffi_, + fuse_dirents_t *buf_) { if(fs_->op.readdir_plus == NULL) return -ENOSYS; @@ -1865,370 +2049,444 @@ fuse_fs_readdir_plus(struct fuse_fs *fs_, return fs_->op.readdir_plus(ffi_,buf_); } -int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode, - struct fuse_file_info *fi) +int +fuse_fs_create(struct fuse_fs *fs, + const char *path, + mode_t mode, + fuse_file_info_t *fi) { + int err; + + if(fs->op.create == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.create) { - int err; - if (fs->debug) - fprintf(stderr, - "create flags: 0x%x %s 0%o umask=0%03o\n", - fi->flags, path, mode, - fuse_get_context()->umask); + if(fs->debug) + fprintf(stderr, + "create flags: 0x%x %s 0%o umask=0%03o\n", + fi->flags,path,mode, + fuse_get_context()->umask); - err = fs->op.create(path, mode, fi); + err = fs->op.create(path,mode,fi); - if (fs->debug && !err) - fprintf(stderr, " create[%llu] flags: 0x%x %s\n", - (unsigned long long) fi->fh, fi->flags, path); + if(fs->debug && !err) + fprintf(stderr," create[%llu] flags: 0x%x %s\n", + (unsigned long long)fi->fh,fi->flags,path); - return err; - } else { - return -ENOSYS; - } + return err; } -int fuse_fs_lock(struct fuse_fs *fs, - struct fuse_file_info *fi, int cmd, struct flock *lock) +int +fuse_fs_lock(struct fuse_fs *fs, + fuse_file_info_t *fi, + int cmd, + struct flock *lock) { - fuse_get_context()->private_data = fs->user_data; - if (fs->op.lock) { - if (fs->debug) - fprintf(stderr, "lock[%llu] %s %s start: %llu len: %llu pid: %llu\n", - (unsigned long long) fi->fh, - (cmd == F_GETLK ? "F_GETLK" : - (cmd == F_SETLK ? "F_SETLK" : - (cmd == F_SETLKW ? "F_SETLKW" : "???"))), - (lock->l_type == F_RDLCK ? "F_RDLCK" : - (lock->l_type == F_WRLCK ? "F_WRLCK" : - (lock->l_type == F_UNLCK ? "F_UNLCK" : - "???"))), - (unsigned long long) lock->l_start, - (unsigned long long) lock->l_len, - (unsigned long long) lock->l_pid); - - return fs->op.lock(fi, cmd, lock); - } else { + if(fs->op.lock == NULL) return -ENOSYS; - } + + fuse_get_context()->private_data = fs->user_data; + + if(fs->debug) + fprintf(stderr,"lock[%llu] %s %s start: %llu len: %llu pid: %llu\n", + (unsigned long long)fi->fh, + (cmd == F_GETLK ? "F_GETLK" : + (cmd == F_SETLK ? "F_SETLK" : + (cmd == F_SETLKW ? "F_SETLKW" : "???"))), + (lock->l_type == F_RDLCK ? "F_RDLCK" : + (lock->l_type == F_WRLCK ? "F_WRLCK" : + (lock->l_type == F_UNLCK ? "F_UNLCK" : + "???"))), + (unsigned long long)lock->l_start, + (unsigned long long)lock->l_len, + (unsigned long long)lock->l_pid); + + return fs->op.lock(fi,cmd,lock); } -int fuse_fs_flock(struct fuse_fs *fs, - struct fuse_file_info *fi, int op) +int +fuse_fs_flock(struct fuse_fs *fs, + fuse_file_info_t *fi, + int op) { + if(fs->op.flock == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.flock) { - if (fs->debug) { + + if(fs->debug) + { int xop = op & ~LOCK_NB; - fprintf(stderr, "lock[%llu] %s%s\n", - (unsigned long long) fi->fh, + fprintf(stderr,"lock[%llu] %s%s\n", + (unsigned long long)fi->fh, xop == LOCK_SH ? "LOCK_SH" : (xop == LOCK_EX ? "LOCK_EX" : (xop == LOCK_UN ? "LOCK_UN" : "???")), (op & LOCK_NB) ? "|LOCK_NB" : ""); } - return fs->op.flock(fi, op); - } else { - return -ENOSYS; - } + + return fs->op.flock(fi,op); } -int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid) +int +fuse_fs_chown(struct fuse_fs *fs, + const char *path, + uid_t uid, + gid_t gid) { + if(fs->op.chown == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.chown) { - if (fs->debug) - fprintf(stderr, "chown %s %lu %lu\n", path, - (unsigned long) uid, (unsigned long) gid); - return fs->op.chown(path, uid, gid); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"chown %s %lu %lu\n",path, + (unsigned long)uid,(unsigned long)gid); + + return fs->op.chown(path,uid,gid); } int -fuse_fs_fchown(struct fuse_fs *fs_, - const struct fuse_file_info *ffi_, - const uid_t uid_, - const gid_t gid_) +fuse_fs_fchown(struct fuse_fs *fs_, + const fuse_file_info_t *ffi_, + const uid_t uid_, + const gid_t gid_) { + if(fs_->op.fchown == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs_->user_data; - if(fs_->op.fchown) - return fs_->op.fchown(ffi_,uid_,gid_); - return -ENOSYS; + return fs_->op.fchown(ffi_,uid_,gid_); } -int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size) +int +fuse_fs_truncate(struct fuse_fs *fs, + const char *path, + off_t size) { + if(fs->op.truncate == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.truncate) { - if (fs->debug) - fprintf(stderr, "truncate %s %llu\n", path, - (unsigned long long) size); - return fs->op.truncate(path, size); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"truncate %s %llu\n",path, + (unsigned long long)size); + + return fs->op.truncate(path,size); } -int fuse_fs_ftruncate(struct fuse_fs *fs, off_t size, - struct fuse_file_info *fi) +int +fuse_fs_ftruncate(struct fuse_fs *fs, + off_t size, + fuse_file_info_t *fi) { + if(fs->op.ftruncate == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->debug) - fprintf(stderr, "ftruncate[%llu] %llu\n", - (unsigned long long) fi->fh, - (unsigned long long) size); - return fs->op.ftruncate(size, fi); + if(fs->debug) + fprintf(stderr,"ftruncate[%llu] %llu\n", + (unsigned long long)fi->fh, + (unsigned long long)size); + + return fs->op.ftruncate(fi,size); } -int fuse_fs_utimens(struct fuse_fs *fs, const char *path, - const struct timespec tv[2]) +int +fuse_fs_utimens(struct fuse_fs *fs, + const char *path, + const struct timespec tv[2]) { fuse_get_context()->private_data = fs->user_data; - if (fs->op.utimens) { - if (fs->debug) - fprintf(stderr, "utimens %s %li.%09lu %li.%09lu\n", - path, tv[0].tv_sec, tv[0].tv_nsec, - tv[1].tv_sec, tv[1].tv_nsec); - - return fs->op.utimens(path, tv); - } else if(fs->op.utime) { - struct utimbuf buf; - - if (fs->debug) - fprintf(stderr, "utime %s %li %li\n", path, - tv[0].tv_sec, tv[1].tv_sec); - - buf.actime = tv[0].tv_sec; - buf.modtime = tv[1].tv_sec; - return fs->op.utime(path, &buf); - } else { - return -ENOSYS; - } + if(fs->op.utimens) + { + if(fs->debug) + fprintf(stderr,"utimens %s %li.%09lu %li.%09lu\n", + path,tv[0].tv_sec,tv[0].tv_nsec, + tv[1].tv_sec,tv[1].tv_nsec); + + return fs->op.utimens(path,tv); + } + else if(fs->op.utime) + { + struct utimbuf buf; + + if(fs->debug) + fprintf(stderr,"utime %s %li %li\n",path, + tv[0].tv_sec,tv[1].tv_sec); + + buf.actime = tv[0].tv_sec; + buf.modtime = tv[1].tv_sec; + return fs->op.utime(path,&buf); + } + else + { + return -ENOSYS; + } } int -fuse_fs_futimens(struct fuse_fs *fs_, - const struct fuse_file_info *ffi_, - const struct timespec tv_[2]) +fuse_fs_futimens(struct fuse_fs *fs_, + const fuse_file_info_t *ffi_, + const struct timespec tv_[2]) { - fuse_get_context()->private_data = fs_->user_data; + if(fs_->op.futimens == NULL) + return -ENOSYS; - if(fs_->op.futimens) - return fs_->op.futimens(ffi_,tv_); + fuse_get_context()->private_data = fs_->user_data; - return -ENOSYS; + return fs_->op.futimens(ffi_,tv_); } -int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask) +int +fuse_fs_access(struct fuse_fs *fs, + const char *path, + int mask) { + if(fs->op.access == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.access) { - if (fs->debug) - fprintf(stderr, "access %s 0%o\n", path, mask); - return fs->op.access(path, mask); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"access %s 0%o\n",path,mask); + + return fs->op.access(path,mask); } -int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf, - size_t len) +int +fuse_fs_readlink(struct fuse_fs *fs, + const char *path, + char *buf, + size_t len) { + if(fs->op.readlink == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.readlink) { - if (fs->debug) - fprintf(stderr, "readlink %s %lu\n", path, - (unsigned long) len); - return fs->op.readlink(path, buf, len); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"readlink %s %lu\n",path, + (unsigned long)len); + + return fs->op.readlink(path,buf,len); } -int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode, - dev_t rdev) +int +fuse_fs_mknod(struct fuse_fs *fs, + const char *path, + mode_t mode, + dev_t rdev) { - fuse_get_context()->private_data = fs->user_data; - if (fs->op.mknod) { - if (fs->debug) - fprintf(stderr, "mknod %s 0%o 0x%llx umask=0%03o\n", - path, mode, (unsigned long long) rdev, - fuse_get_context()->umask); - - return fs->op.mknod(path, mode, rdev); - } else { + if(fs->op.mknod == NULL) return -ENOSYS; - } -} -int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode) -{ fuse_get_context()->private_data = fs->user_data; - if (fs->op.mkdir) { - if (fs->debug) - fprintf(stderr, "mkdir %s 0%o umask=0%03o\n", - path, mode, fuse_get_context()->umask); - return fs->op.mkdir(path, mode); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"mknod %s 0%o 0x%llx umask=0%03o\n", + path,mode,(unsigned long long)rdev, + fuse_get_context()->umask); + + return fs->op.mknod(path,mode,rdev); } -int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name, - const char *value, size_t size, int flags) +int +fuse_fs_mkdir(struct fuse_fs *fs, + const char *path, + mode_t mode) { + if(fs->op.mkdir == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.setxattr) { - if (fs->debug) - fprintf(stderr, "setxattr %s %s %lu 0x%x\n", - path, name, (unsigned long) size, flags); - return fs->op.setxattr(path, name, value, size, flags); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"mkdir %s 0%o umask=0%03o\n", + path,mode,fuse_get_context()->umask); + + return fs->op.mkdir(path,mode); } -int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name, - char *value, size_t size) -{ +int +fuse_fs_setxattr(struct fuse_fs *fs, + const char *path, + const char *name, + const char *value, + size_t size, + int flags) +{ + if(fs->op.setxattr == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.getxattr) { - if (fs->debug) - fprintf(stderr, "getxattr %s %s %lu\n", - path, name, (unsigned long) size); - return fs->op.getxattr(path, name, value, size); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"setxattr %s %s %lu 0x%x\n", + path,name,(unsigned long)size,flags); + + return fs->op.setxattr(path,name,value,size,flags); } -int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list, - size_t size) +int +fuse_fs_getxattr(struct fuse_fs *fs, + const char *path, + const char *name, + char *value, + size_t size) { + if(fs->op.getxattr == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.listxattr) { - if (fs->debug) - fprintf(stderr, "listxattr %s %lu\n", - path, (unsigned long) size); - return fs->op.listxattr(path, list, size); - } else { - return -ENOSYS; - } + if(fs->debug) + fprintf(stderr,"getxattr %s %s %lu\n", + path,name,(unsigned long)size); + + return fs->op.getxattr(path,name,value,size); } -int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize, - uint64_t *idx) +int +fuse_fs_listxattr(struct fuse_fs *fs, + const char *path, + char *list, + size_t size) { - fuse_get_context()->private_data = fs->user_data; - if (fs->op.bmap) { - if (fs->debug) - fprintf(stderr, "bmap %s blocksize: %lu index: %llu\n", - path, (unsigned long) blocksize, - (unsigned long long) *idx); - - return fs->op.bmap(path, blocksize, idx); - } else { + if(fs->op.listxattr == NULL) return -ENOSYS; - } + + fuse_get_context()->private_data = fs->user_data; + + if(fs->debug) + fprintf(stderr,"listxattr %s %lu\n", + path,(unsigned long)size); + + return fs->op.listxattr(path,list,size); } -int fuse_fs_removexattr(struct fuse_fs *fs, const char *path, const char *name) +int +fuse_fs_bmap(struct fuse_fs *fs, + const char *path, + size_t blocksize, + uint64_t *idx) { + if(fs->op.bmap == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.removexattr) { - if (fs->debug) - fprintf(stderr, "removexattr %s %s\n", path, name); + if(fs->debug) + fprintf(stderr,"bmap %s blocksize: %lu index: %llu\n", + path,(unsigned long)blocksize, + (unsigned long long)*idx); - return fs->op.removexattr(path, name); - } else { - return -ENOSYS; - } + return fs->op.bmap(path,blocksize,idx); } -int fuse_fs_ioctl(struct fuse_fs *fs, unsigned long cmd, void *arg, - struct fuse_file_info *fi, unsigned int flags, - void *data, uint32_t *out_size) +int +fuse_fs_removexattr(struct fuse_fs *fs, + const char *path, + const char *name) { + if(fs->op.removexattr == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.ioctl) { - if (fs->debug) - fprintf(stderr, "ioctl[%llu] 0x%lx flags: 0x%x\n", - (unsigned long long) fi->fh, cmd, flags); - return fs->op.ioctl(cmd, arg, fi, flags, data, out_size); - } else + if(fs->debug) + fprintf(stderr,"removexattr %s %s\n",path,name); + + return fs->op.removexattr(path,name); +} + +int +fuse_fs_ioctl(struct fuse_fs *fs, + unsigned long cmd, + void *arg, + fuse_file_info_t *fi, + unsigned int flags, + void *data, + uint32_t *out_size) +{ + if(fs->op.ioctl == NULL) return -ENOSYS; + + fuse_get_context()->private_data = fs->user_data; + + if(fs->debug) + fprintf(stderr,"ioctl[%llu] 0x%lx flags: 0x%x\n", + (unsigned long long)fi->fh,cmd,flags); + + return fs->op.ioctl(fi,cmd,arg,flags,data,out_size); } -int fuse_fs_poll(struct fuse_fs *fs, - struct fuse_file_info *fi, struct fuse_pollhandle *ph, - unsigned *reventsp) +int +fuse_fs_poll(struct fuse_fs *fs, + fuse_file_info_t *fi, + fuse_pollhandle_t *ph, + unsigned *reventsp) { + int res; + + if(fs->op.poll == NULL) + return -ENOSYS; + fuse_get_context()->private_data = fs->user_data; - if (fs->op.poll) { - int res; - if (fs->debug) - fprintf(stderr, "poll[%llu] ph: %p\n", - (unsigned long long) fi->fh, ph); + if(fs->debug) + fprintf(stderr,"poll[%llu] ph: %p\n", + (unsigned long long)fi->fh,ph); - res = fs->op.poll(fi, ph, reventsp); + res = fs->op.poll(fi,ph,reventsp); - if (fs->debug && !res) - fprintf(stderr, " poll[%llu] revents: 0x%x\n", - (unsigned long long) fi->fh, *reventsp); + if(fs->debug && !res) + fprintf(stderr," poll[%llu] revents: 0x%x\n", + (unsigned long long)fi->fh,*reventsp); - return res; - } else - return -ENOSYS; + return res; } -int fuse_fs_fallocate(struct fuse_fs *fs, int mode, - off_t offset, off_t length, struct fuse_file_info *fi) +int +fuse_fs_fallocate(struct fuse_fs *fs, + int mode, + off_t offset, + off_t length, + fuse_file_info_t *fi) { - fuse_get_context()->private_data = fs->user_data; - if (fs->op.fallocate) { - if (fs->debug) - fprintf(stderr, "fallocate mode %x, offset: %llu, length: %llu\n", - mode, - (unsigned long long) offset, - (unsigned long long) length); - - return fs->op.fallocate(mode, offset, length, fi); - } else + if(fs->op.fallocate == NULL) return -ENOSYS; + + fuse_get_context()->private_data = fs->user_data; + + if(fs->debug) + fprintf(stderr,"fallocate mode %x,offset: %llu,length: %llu\n", + mode, + (unsigned long long)offset, + (unsigned long long)length); + + return fs->op.fallocate(fi,mode,offset,length); } ssize_t -fuse_fs_copy_file_range(struct fuse_fs *fs_, - struct fuse_file_info *ffi_in_, - off_t off_in_, - struct fuse_file_info *ffi_out_, - off_t off_out_, - size_t len_, - int flags_) +fuse_fs_copy_file_range(struct fuse_fs *fs_, + fuse_file_info_t *ffi_in_, + off_t off_in_, + fuse_file_info_t *ffi_out_, + off_t off_out_, + size_t len_, + int flags_) { - fuse_get_context()->private_data = fs_->user_data; - if(fs_->op.copy_file_range == NULL) return -ENOSYS; + fuse_get_context()->private_data = fs_->user_data; + return fs_->op.copy_file_range(ffi_in_, off_in_, ffi_out_, @@ -2237,29 +2495,34 @@ fuse_fs_copy_file_range(struct fuse_fs *fs_, flags_); } +static int node_open(const struct node *node_) { - return ((node_ != NULL) && - (node_->open_count > 0)); + return ((node_ != NULL) && (node_->open_count > 0)); } #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC CLOCK_REALTIME #endif -static void curr_time(struct timespec *now) +static +void +curr_time(struct timespec *now) { static clockid_t clockid = CLOCK_MONOTONIC; - int res = clock_gettime(clockid, now); - if (res == -1 && errno == EINVAL) { - clockid = CLOCK_REALTIME; - res = clock_gettime(clockid, now); - } - if (res == -1) { - perror("fuse: clock_gettime"); - abort(); - } + int res = clock_gettime(clockid,now); + if(res == -1 && errno == EINVAL) + { + clockid = CLOCK_REALTIME; + res = clock_gettime(clockid,now); + } + + if(res == -1) + { + perror("fuse: clock_gettime"); + abort(); + } } static @@ -2267,16 +2530,16 @@ void update_stat(struct node *node_, const struct stat *stnew_) { - struct stat *stold; - - stold = &node_->stat_cache; if((node_->stat_cache_valid) && - ((stold->st_mtim.tv_sec != stnew_->st_mtim.tv_sec) || - (stold->st_mtim.tv_nsec != stnew_->st_mtim.tv_nsec) || - (stold->st_size != stnew_->st_size))) + ((node_->mtim.tv_sec != stnew_->st_mtim.tv_sec) || + (node_->mtim.tv_nsec != stnew_->st_mtim.tv_nsec) || + (node_->ino != stnew_->st_ino) || + (node_->size != stnew_->st_size))) node_->stat_cache_valid = 0; - *stold = *stnew_; + node_->ino = stnew_->st_ino; + node_->size = stnew_->st_size; + node_->mtim = stnew_->st_mtim; } static @@ -2286,16 +2549,15 @@ lookup_path(struct fuse *f, const char *name, const char *path, struct fuse_entry_param *e, - struct fuse_file_info *fi) + fuse_file_info_t *fi) { int res; memset(e,0,sizeof(struct fuse_entry_param)); - if(fi) - res = fuse_fs_fgetattr(f->fs,&e->attr,fi,&e->timeout); - else - res = fuse_fs_getattr(f->fs,path,&e->attr,&e->timeout); + res = ((fi == NULL) ? + fuse_fs_getattr(f->fs,path,&e->attr,&e->timeout) : + fuse_fs_fgetattr(f->fs,&e->attr,fi,&e->timeout)); if(res == 0) { @@ -2328,62 +2590,76 @@ lookup_path(struct fuse *f, return res; } -static struct fuse_context_i *fuse_get_context_internal(void) +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(); + 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); } - pthread_setspecific(fuse_context_key, c); - } return c; } -static void fuse_freecontext(void *data) +static +void +fuse_freecontext(void *data) { free(data); } -static int fuse_create_context_key(void) +static +int +fuse_create_context_key(void) { int err = 0; pthread_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)); - pthread_mutex_unlock(&fuse_context_lock); - return -1; + 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)); + pthread_mutex_unlock(&fuse_context_lock); + return -1; + } } - } fuse_context_ref++; pthread_mutex_unlock(&fuse_context_lock); return 0; } -static void fuse_delete_context_key(void) +static +void +fuse_delete_context_key(void) { pthread_mutex_lock(&fuse_context_lock); fuse_context_ref--; - if (!fuse_context_ref) { - free(pthread_getspecific(fuse_context_key)); - pthread_key_delete(fuse_context_key); - } + if(!fuse_context_ref) + { + free(pthread_getspecific(fuse_context_key)); + pthread_key_delete(fuse_context_key); + } pthread_mutex_unlock(&fuse_context_lock); } -static struct fuse *req_fuse_prepare(fuse_req_t req) +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); @@ -2396,64 +2672,84 @@ static struct fuse *req_fuse_prepare(fuse_req_t req) return c->ctx.fuse; } -static inline void reply_err(fuse_req_t req, int err) +static +inline +void +reply_err(fuse_req_t req, + int err) { /* fuse_reply_err() uses non-negated errno values */ - fuse_reply_err(req, -err); + fuse_reply_err(req,-err); } -static void reply_entry(fuse_req_t req, const struct fuse_entry_param *e, - int err) +static +void +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) { - /* Skip forget for negative result */ - if (e->ino != 0) - forget_node(f, e->ino, 1); + if(!err) + { + struct fuse *f = req_fuse(req); + if(fuse_reply_entry(req,e) == -ENOENT) + { + /* Skip forget for negative result */ + if(e->ino != 0) + forget_node(f,e->ino,1); + } + } + else + { + reply_err(req,err); } - } else - reply_err(req, err); } -void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn) +void +fuse_fs_init(struct fuse_fs *fs, + struct fuse_conn_info *conn) { fuse_get_context()->private_data = fs->user_data; - if (!fs->op.write_buf) + if(!fs->op.write_buf) conn->want &= ~FUSE_CAP_SPLICE_READ; - if (!fs->op.lock) + if(!fs->op.lock) conn->want &= ~FUSE_CAP_POSIX_LOCKS; - if (!fs->op.flock) + if(!fs->op.flock) conn->want &= ~FUSE_CAP_FLOCK_LOCKS; - if (fs->op.init) + if(fs->op.init) fs->user_data = fs->op.init(conn); } -static void fuse_lib_init(void *data, struct fuse_conn_info *conn) +static +void +fuse_lib_init(void *data, + struct fuse_conn_info *conn) { - struct fuse *f = (struct fuse *) data; + struct fuse *f = (struct fuse *)data; struct fuse_context_i *c = fuse_get_context_internal(); - memset(c, 0, sizeof(*c)); + memset(c,0,sizeof(*c)); c->ctx.fuse = f; conn->want |= FUSE_CAP_EXPORT_SUPPORT; - fuse_fs_init(f->fs, conn); + fuse_fs_init(f->fs,conn); } -void fuse_fs_destroy(struct fuse_fs *fs) +void +fuse_fs_destroy(struct fuse_fs *fs) { fuse_get_context()->private_data = fs->user_data; - if (fs->op.destroy) + if(fs->op.destroy) fs->op.destroy(fs->user_data); free(fs); } -static void fuse_lib_destroy(void *data) +static +void +fuse_lib_destroy(void *data) { - struct fuse *f = (struct fuse *) data; + struct fuse *f = (struct fuse *)data; struct fuse_context_i *c = fuse_get_context_internal(); - memset(c, 0, sizeof(*c)); + memset(c,0,sizeof(*c)); c->ctx.fuse = f; fuse_fs_destroy(f->fs); f->fs = NULL; @@ -2461,8 +2757,8 @@ static void fuse_lib_destroy(void *data) static void -fuse_lib_lookup(fuse_req_t req, - fuse_ino_t parent, +fuse_lib_lookup(fuse_req_t req, + fuse_ino_t parent, const char *name) { struct fuse *f = req_fuse_prepare(req); @@ -2471,85 +2767,94 @@ fuse_lib_lookup(fuse_req_t req, int err; struct node *dot = NULL; - if (name[0] == '.') { - int len = strlen(name); + if(name[0] == '.') + { + int len = strlen(name); - if (len == 1 || (name[1] == '.' && len == 2)) { - pthread_mutex_lock(&f->lock); - if (len == 1) { - if (f->conf.debug) - fprintf(stderr, "LOOKUP-DOT\n"); - dot = get_node_nocheck(f, parent); - if (dot == NULL) { + if(len == 1 || (name[1] == '.' && len == 2)) + { + pthread_mutex_lock(&f->lock); + if(len == 1) + { + if(f->conf.debug) + fprintf(stderr,"LOOKUP-DOT\n"); + dot = get_node_nocheck(f,parent); + if(dot == NULL) + { + pthread_mutex_unlock(&f->lock); + reply_entry(req,&e,-ESTALE); + return; + } + dot->refctr++; + } + else + { + if(f->conf.debug) + fprintf(stderr,"LOOKUP-DOTDOT\n"); + parent = get_node(f,parent)->parent->nodeid; + } pthread_mutex_unlock(&f->lock); - reply_entry(req, &e, -ESTALE); - return; + name = NULL; } - dot->refctr++; - } else { - if (f->conf.debug) - fprintf(stderr, "LOOKUP-DOTDOT\n"); - parent = get_node(f, parent)->parent->nodeid; - } - pthread_mutex_unlock(&f->lock); - name = NULL; } - } - err = get_path_name(f, parent, name, &path); - if (!err) { - struct fuse_intr_data d; - if (f->conf.debug) - fprintf(stderr, "LOOKUP %s\n", path); - fuse_prepare_interrupt(f, req, &d); - err = lookup_path(f, parent, name, path, &e, NULL); - if (err == -ENOENT) { - e.ino = 0; - err = 0; + err = get_path_name(f,parent,name,&path); + if(!err) + { + if(f->conf.debug) + fprintf(stderr,"LOOKUP %s\n",path); + err = lookup_path(f,parent,name,path,&e,NULL); + if(err == -ENOENT) + { + e.ino = 0; + err = 0; + } + free_path(f,parent,path); } - fuse_finish_interrupt(f, req, &d); - free_path(f, parent, path); - } - if (dot) { - pthread_mutex_lock(&f->lock); - unref_node(f, dot); - pthread_mutex_unlock(&f->lock); - } - reply_entry(req, &e, err); + if(dot) + { + pthread_mutex_lock(&f->lock); + unref_node(f,dot); + pthread_mutex_unlock(&f->lock); + } + reply_entry(req,&e,err); } static void -do_forget(struct fuse *f, - const fuse_ino_t ino, - const uint64_t nlookup) +do_forget(struct fuse *f, + const fuse_ino_t ino, + const uint64_t nlookup) { if(f->conf.debug) fprintf(stderr, "FORGET %llu/%llu\n", (unsigned long long)ino, (unsigned long long)nlookup); - forget_node(f, ino, nlookup); + forget_node(f,ino,nlookup); } static void -fuse_lib_forget(fuse_req_t req, +fuse_lib_forget(fuse_req_t req, const fuse_ino_t ino, - const uint64_t nlookup) + const uint64_t nlookup) { - do_forget(req_fuse(req), ino, nlookup); + do_forget(req_fuse(req),ino,nlookup); fuse_reply_none(req); } -static void fuse_lib_forget_multi(fuse_req_t req, size_t count, - struct fuse_forget_data *forgets) +static +void +fuse_lib_forget_multi(fuse_req_t req, + size_t count, + struct fuse_forget_data *forgets) { struct fuse *f = req_fuse(req); size_t i; - for (i = 0; i < count; i++) - do_forget(f, forgets[i].ino, forgets[i].nlookup); + for(i = 0; i < count; i++) + do_forget(f,forgets[i].ino,forgets[i].nlookup); fuse_reply_none(req); } @@ -2557,9 +2862,9 @@ static void fuse_lib_forget_multi(fuse_req_t req, size_t count, static void -fuse_lib_getattr(fuse_req_t req, - fuse_ino_t ino, - struct fuse_file_info *fi) +fuse_lib_getattr(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi) { int err; @@ -2568,7 +2873,7 @@ fuse_lib_getattr(fuse_req_t req, struct stat buf; struct node *node; fuse_timeouts_t timeout; - struct fuse_file_info ffi = {0}; + fuse_file_info_t ffi = {0}; f = req_fuse_prepare(req); if(fi == NULL) @@ -2583,7 +2888,7 @@ fuse_lib_getattr(fuse_req_t req, pthread_mutex_unlock(&f->lock); } - memset(&buf, 0, sizeof(buf)); + memset(&buf,0,sizeof(buf)); err = 0; path = NULL; @@ -2592,16 +2897,10 @@ fuse_lib_getattr(fuse_req_t req, if(!err) { - struct fuse_intr_data d; - - fuse_prepare_interrupt(f,req,&d); - err = ((fi == NULL) ? fuse_fs_getattr(f->fs,path,&buf,&timeout) : fuse_fs_fgetattr(f->fs,&buf,fi,&timeout)); - fuse_finish_interrupt(f,req,&d); - free_path(f,ino,path); } @@ -2616,39 +2915,43 @@ fuse_lib_getattr(fuse_req_t req, } else { - reply_err(req, err); + reply_err(req,err); } } -int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode) +int +fuse_fs_chmod(struct fuse_fs *fs, + const char *path, + mode_t mode) { - fuse_get_context()->private_data = fs->user_data; - if (fs->op.chmod) - return fs->op.chmod(path, mode); - else + if(fs->op.chmod == NULL) return -ENOSYS; + + fuse_get_context()->private_data = fs->user_data; + + return fs->op.chmod(path,mode); } int -fuse_fs_fchmod(struct fuse_fs *fs_, - const struct fuse_file_info *ffi_, - const mode_t mode_) +fuse_fs_fchmod(struct fuse_fs *fs_, + const fuse_file_info_t *ffi_, + const mode_t mode_) { - fuse_get_context()->private_data = fs_->user_data; + if(fs_->op.fchmod == NULL) + return -ENOSYS; - if(fs_->op.fchmod) - return fs_->op.fchmod(ffi_,mode_); + fuse_get_context()->private_data = fs_->user_data; - return -ENOSYS; + return fs_->op.fchmod(ffi_,mode_); } static void -fuse_lib_setattr(fuse_req_t req, - fuse_ino_t ino, - struct stat *attr, - int valid, - struct fuse_file_info *fi) +fuse_lib_setattr(fuse_req_t req, + fuse_ino_t ino, + struct stat *attr, + int valid, + fuse_file_info_t *fi) { struct fuse *f = req_fuse_prepare(req); struct stat buf; @@ -2656,7 +2959,7 @@ fuse_lib_setattr(fuse_req_t req, int err; struct node *node; fuse_timeouts_t timeout; - struct fuse_file_info ffi = {0}; + fuse_file_info_t ffi = {0}; if(fi == NULL) { @@ -2679,20 +2982,16 @@ fuse_lib_setattr(fuse_req_t req, if(!err) { - struct fuse_intr_data d; - - fuse_prepare_interrupt(f,req,&d); - err = 0; - if (!err && (valid & FATTR_MODE)) + if(!err && (valid & FATTR_MODE)) err = ((fi == NULL) ? fuse_fs_chmod(f->fs,path,attr->st_mode) : fuse_fs_fchmod(f->fs,fi,attr->st_mode)); if(!err && (valid & (FATTR_UID | FATTR_GID))) { - uid_t uid = ((valid & FATTR_UID) ? attr->st_uid : (uid_t) -1); - gid_t gid = ((valid & FATTR_GID) ? attr->st_gid : (gid_t) -1); + uid_t uid = ((valid & FATTR_UID) ? attr->st_uid : (uid_t)-1); + gid_t gid = ((valid & FATTR_GID) ? attr->st_gid : (gid_t)-1); err = ((fi == NULL) ? fuse_fs_chown(f->fs,path,uid,gid) : @@ -2742,12 +3041,11 @@ fuse_lib_setattr(fuse_req_t req, fuse_fs_futimens(f->fs,fi,tv)); } - if (!err) + if(!err) err = ((fi == NULL) ? fuse_fs_getattr(f->fs,path,&buf,&timeout) : fuse_fs_fgetattr(f->fs,&buf,fi,&timeout)); - fuse_finish_interrupt(f,req,&d); free_path(f,ino,path); } @@ -2766,104 +3064,117 @@ fuse_lib_setattr(fuse_req_t req, } } -static void fuse_lib_access(fuse_req_t req, fuse_ino_t ino, int mask) +static +void +fuse_lib_access(fuse_req_t req, + fuse_ino_t ino, + int mask) { struct fuse *f = req_fuse_prepare(req); char *path; int err; - err = get_path(f, ino, &path); - if (!err) { - struct fuse_intr_data d; + err = get_path(f,ino,&path); + if(!err) + { + err = fuse_fs_access(f->fs,path,mask); + free_path(f,ino,path); + } - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_access(f->fs, path, mask); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, path); - } - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_readlink(fuse_req_t req, fuse_ino_t ino) +static +void +fuse_lib_readlink(fuse_req_t req, + fuse_ino_t ino) { struct fuse *f = req_fuse_prepare(req); char linkname[PATH_MAX + 1]; char *path; int err; - err = get_path(f, ino, &path); - if (!err) { - struct fuse_intr_data d; - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_readlink(f->fs, path, linkname, sizeof(linkname)); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, path); - } - if (!err) { - linkname[PATH_MAX] = '\0'; - fuse_reply_readlink(req, linkname); - } else - reply_err(req, err); + err = get_path(f,ino,&path); + if(!err) + { + err = fuse_fs_readlink(f->fs,path,linkname,sizeof(linkname)); + free_path(f,ino,path); + } + + if(!err) + { + linkname[PATH_MAX] = '\0'; + fuse_reply_readlink(req,linkname); + } + else + { + reply_err(req,err); + } } -static void fuse_lib_mknod(fuse_req_t req, fuse_ino_t parent, const char *name, - mode_t mode, dev_t rdev) +static +void +fuse_lib_mknod(fuse_req_t req, + fuse_ino_t parent, + const char *name, + mode_t mode, + dev_t rdev) { struct fuse *f = req_fuse_prepare(req); struct fuse_entry_param e; char *path; int err; - err = get_path_name(f, parent, name, &path); - if (!err) { - struct fuse_intr_data d; - - fuse_prepare_interrupt(f, req, &d); - err = -ENOSYS; - if (S_ISREG(mode)) { - struct fuse_file_info fi; - - memset(&fi, 0, sizeof(fi)); - fi.flags = O_CREAT | O_EXCL | O_WRONLY; - err = fuse_fs_create(f->fs, path, mode, &fi); - if (!err) { - err = lookup_path(f, parent, name, path, &e, - &fi); - fuse_fs_release(f->fs, &fi); - } - } - if (err == -ENOSYS) { - err = fuse_fs_mknod(f->fs, path, mode, rdev); - if (!err) - err = lookup_path(f, parent, name, path, &e, - NULL); + err = get_path_name(f,parent,name,&path); + if(!err) + { + err = -ENOSYS; + if(S_ISREG(mode)) + { + fuse_file_info_t fi; + + memset(&fi,0,sizeof(fi)); + fi.flags = O_CREAT | O_EXCL | O_WRONLY; + err = fuse_fs_create(f->fs,path,mode,&fi); + if(!err) + { + err = lookup_path(f,parent,name,path,&e, + &fi); + fuse_fs_release(f->fs,&fi); + } + } + if(err == -ENOSYS) + { + err = fuse_fs_mknod(f->fs,path,mode,rdev); + if(!err) + err = lookup_path(f,parent,name,path,&e,NULL); + } + free_path(f,parent,path); } - fuse_finish_interrupt(f, req, &d); - free_path(f, parent, path); - } - reply_entry(req, &e, err); + reply_entry(req,&e,err); } -static void fuse_lib_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name, - mode_t mode) +static +void +fuse_lib_mkdir(fuse_req_t req, + fuse_ino_t parent, + const char *name, + mode_t mode) { struct fuse *f = req_fuse_prepare(req); struct fuse_entry_param e; char *path; int err; - err = get_path_name(f, parent, name, &path); - if (!err) { - struct fuse_intr_data d; - - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_mkdir(f->fs, path, mode); - if (!err) - err = lookup_path(f, parent, name, path, &e, NULL); - fuse_finish_interrupt(f, req, &d); - free_path(f, parent, path); - } - reply_entry(req, &e, err); + err = get_path_name(f,parent,name,&path); + if(!err) + { + err = fuse_fs_mkdir(f->fs,path,mode); + if(!err) + err = lookup_path(f,parent,name,path,&e,NULL); + free_path(f,parent,path); + } + reply_entry(req,&e,err); } static @@ -2876,15 +3187,12 @@ fuse_lib_unlink(fuse_req_t req, char *path; struct fuse *f; struct node *wnode; - struct fuse_intr_data d; f = req_fuse_prepare(req); err = get_path_wrlock(f,parent,name,&path,&wnode); if(!err) { - fuse_prepare_interrupt(f,req,&d); - pthread_mutex_lock(&f->lock); if(node_open(wnode)) { @@ -2898,54 +3206,57 @@ fuse_lib_unlink(fuse_req_t req, if(!err) remove_node(f,parent,name); - fuse_finish_interrupt(f,req,&d); free_path_wrlock(f,parent,wnode,path); } reply_err(req,err); } -static void fuse_lib_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) +static +void +fuse_lib_rmdir(fuse_req_t req, + fuse_ino_t parent, + const char *name) { struct fuse *f = req_fuse_prepare(req); struct node *wnode; char *path; int err; - err = get_path_wrlock(f, parent, name, &path, &wnode); - if (!err) { - struct fuse_intr_data d; + err = get_path_wrlock(f,parent,name,&path,&wnode); + if(!err) + { + err = fuse_fs_rmdir(f->fs,path); + if(!err) + remove_node(f,parent,name); + free_path_wrlock(f,parent,wnode,path); + } - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_rmdir(f->fs, path); - fuse_finish_interrupt(f, req, &d); - if (!err) - remove_node(f, parent, name); - free_path_wrlock(f, parent, wnode, path); - } - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_symlink(fuse_req_t req, const char *linkname, - fuse_ino_t parent, const char *name) +static +void +fuse_lib_symlink(fuse_req_t req, + const char *linkname, + fuse_ino_t parent, + const char *name) { struct fuse *f = req_fuse_prepare(req); struct fuse_entry_param e; char *path; int err; - err = get_path_name(f, parent, name, &path); - if (!err) { - struct fuse_intr_data d; + err = get_path_name(f,parent,name,&path); + if(!err) + { + err = fuse_fs_symlink(f->fs,linkname,path); + if(!err) + err = lookup_path(f,parent,name,path,&e,NULL); + free_path(f,parent,path); + } - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_symlink(f->fs, linkname, path); - if (!err) - err = lookup_path(f, parent, name, path, &e, NULL); - fuse_finish_interrupt(f, req, &d); - free_path(f, parent, path); - } - reply_entry(req, &e, err); + reply_entry(req,&e,err); } static @@ -2962,7 +3273,6 @@ fuse_lib_rename(fuse_req_t req, char *newpath; struct node *wnode1; struct node *wnode2; - struct fuse_intr_data d; f = req_fuse_prepare(req); err = get_path2(f,olddir,oldname,newdir,newname, @@ -2970,8 +3280,6 @@ fuse_lib_rename(fuse_req_t req, if(!err) { - fuse_prepare_interrupt(f,req,&d); - pthread_mutex_lock(&f->lock); if(node_open(wnode2)) { @@ -2985,14 +3293,13 @@ fuse_lib_rename(fuse_req_t req, if(!err) err = rename_node(f,olddir,oldname,newdir,newname); - fuse_finish_interrupt(f,req,&d); free_path2(f,olddir,newdir,wnode1,wnode2,oldpath,newpath); } reply_err(req,err); } -static void fuse_lib_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, +static void fuse_lib_link(fuse_req_t req,fuse_ino_t ino,fuse_ino_t newparent, const char *newname) { struct fuse *f = req_fuse_prepare(req); @@ -3001,42 +3308,44 @@ static void fuse_lib_link(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, char *newpath; int err; - err = get_path2(f, ino, NULL, newparent, newname, - &oldpath, &newpath, NULL, NULL); - if (!err) { - struct fuse_intr_data d; - - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_link(f->fs, oldpath, newpath); - if (!err) - err = lookup_path(f, newparent, newname, newpath, - &e, NULL); - fuse_finish_interrupt(f, req, &d); - free_path2(f, ino, newparent, NULL, NULL, oldpath, newpath); - } - reply_entry(req, &e, err); + err = get_path2(f,ino,NULL,newparent,newname, + &oldpath,&newpath,NULL,NULL); + if(!err) + { + err = fuse_fs_link(f->fs,oldpath,newpath); + if(!err) + err = lookup_path(f,newparent,newname,newpath, + &e,NULL); + free_path2(f,ino,newparent,NULL,NULL,oldpath,newpath); + } + + reply_entry(req,&e,err); } -static void fuse_do_release(struct fuse *f, fuse_ino_t ino, - struct fuse_file_info *fi) +static +void +fuse_do_release(struct fuse *f, + fuse_ino_t ino, + fuse_file_info_t *fi) { struct node *node; uint64_t fh; int was_hidden; fh = 0; - fuse_fs_release(f->fs, fi); + fuse_fs_release(f->fs,fi); pthread_mutex_lock(&f->lock); - node = get_node(f, ino); + node = get_node(f,ino); assert(node->open_count > 0); node->open_count--; was_hidden = 0; - if (node->is_hidden && (node->open_count == 0)) { - was_hidden = 1; - node->is_hidden = 0; - fh = node->hidden_fh; - } + if(node->is_hidden && (node->open_count == 0)) + { + was_hidden = 1; + node->is_hidden = 0; + fh = node->hidden_fh; + } pthread_mutex_unlock(&f->lock); if(was_hidden) @@ -3045,39 +3354,36 @@ static void fuse_do_release(struct fuse *f, fuse_ino_t ino, static void -fuse_lib_create(fuse_req_t req, - fuse_ino_t parent, - const char *name, - mode_t mode, - struct fuse_file_info *fi) +fuse_lib_create(fuse_req_t req, + fuse_ino_t parent, + const char *name, + mode_t mode, + fuse_file_info_t *fi) { int err; char *path; struct fuse *f; - struct fuse_intr_data d; struct fuse_entry_param e; f = req_fuse_prepare(req); - err = get_path_name(f, parent, name, &path); + err = get_path_name(f,parent,name,&path); if(!err) { - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_create(f->fs, path, mode, fi); + err = fuse_fs_create(f->fs,path,mode,fi); if(!err) { - err = lookup_path(f, parent, name, path, &e, fi); + err = lookup_path(f,parent,name,path,&e,fi); if(err) { - fuse_fs_release(f->fs, fi); + fuse_fs_release(f->fs,fi); } else if(!S_ISREG(e.attr.st_mode)) { err = -EIO; - fuse_fs_release(f->fs, fi); - forget_node(f, e.ino, 1); + fuse_fs_release(f->fs,fi); + forget_node(f,e.ino,1); } } - fuse_finish_interrupt(f, req, &d); } if(!err) @@ -3086,34 +3392,37 @@ fuse_lib_create(fuse_req_t req, get_node(f,e.ino)->open_count++; pthread_mutex_unlock(&f->lock); - if (fuse_reply_create(req, &e, fi) == -ENOENT) { - /* The open syscall was interrupted, so it - must be cancelled */ - fuse_do_release(f, e.ino, fi); - forget_node(f, e.ino, 1); - } + if(fuse_reply_create(req,&e,fi) == -ENOENT) + { + /* The open syscall was interrupted,so it + must be cancelled */ + fuse_do_release(f,e.ino,fi); + forget_node(f,e.ino,1); + } } else { - reply_err(req, err); + reply_err(req,err); } - free_path(f, parent, path); + free_path(f,parent,path); } -static double diff_timespec(const struct timespec *t1, - const struct timespec *t2) +static +double +diff_timespec(const struct timespec *t1, + const struct timespec *t2) { return (t1->tv_sec - t2->tv_sec) + - ((double) t1->tv_nsec - (double) t2->tv_nsec) / 1000000000.0; + ((double)t1->tv_nsec - (double)t2->tv_nsec) / 1000000000.0; } static void -open_auto_cache(struct fuse *f, - fuse_ino_t ino, - const char *path, - struct fuse_file_info *fi) +open_auto_cache(struct fuse *f, + fuse_ino_t ino, + const char *path, + fuse_file_info_t *fi) { struct node *node; fuse_timeouts_t timeout; @@ -3146,27 +3455,24 @@ open_auto_cache(struct fuse *f, static void -fuse_lib_open(fuse_req_t req, - fuse_ino_t ino, - struct fuse_file_info *fi) +fuse_lib_open(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi) { int err; char *path; struct fuse *f; - struct fuse_intr_data d; f = req_fuse_prepare(req); - err = get_path(f, ino, &path); + err = get_path(f,ino,&path); if(!err) { - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_open(f->fs, path, fi); + err = fuse_fs_open(f->fs,path,fi); if(!err) { - if (fi && fi->auto_cache) - open_auto_cache(f, ino, path, fi); + if(fi && fi->auto_cache) + open_auto_cache(f,ino,path,fi); } - fuse_finish_interrupt(f, req, &d); } if(!err) @@ -3174,160 +3480,166 @@ fuse_lib_open(fuse_req_t req, pthread_mutex_lock(&f->lock); get_node(f,ino)->open_count++; pthread_mutex_unlock(&f->lock); - /* The open syscall was interrupted, so it must be cancelled */ - if(fuse_reply_open(req, fi) == -ENOENT) - fuse_do_release(f, ino, fi); + /* The open syscall was interrupted,so it must be cancelled */ + if(fuse_reply_open(req,fi) == -ENOENT) + fuse_do_release(f,ino,fi); } else { - reply_err(req, err); + reply_err(req,err); } - free_path(f, ino, path); + free_path(f,ino,path); } -static void fuse_lib_read(fuse_req_t req, fuse_ino_t ino, size_t size, - off_t off, struct fuse_file_info *fi) +static +void +fuse_lib_read(fuse_req_t req, + fuse_ino_t ino, + size_t size, + off_t off, + fuse_file_info_t *fi) { struct fuse *f = req_fuse_prepare(req); struct fuse_bufvec *buf = NULL; int res; - struct fuse_intr_data d; - fuse_prepare_interrupt(f, req, &d); - res = fuse_fs_read_buf(f->fs, &buf, size, off, fi); - fuse_finish_interrupt(f, req, &d); + res = fuse_fs_read_buf(f->fs,&buf,size,off,fi); - if (res == 0) - fuse_reply_data(req, buf, FUSE_BUF_SPLICE_MOVE); + if(res == 0) + fuse_reply_data(req,buf,FUSE_BUF_SPLICE_MOVE); else - reply_err(req, res); + reply_err(req,res); fuse_free_buf(buf); } -static void fuse_lib_write_buf(fuse_req_t req, fuse_ino_t ino, - struct fuse_bufvec *buf, off_t off, - struct fuse_file_info *fi) +static +void +fuse_lib_write_buf(fuse_req_t req, + fuse_ino_t ino, + struct fuse_bufvec *buf, + off_t off, + fuse_file_info_t *fi) { - struct fuse *f = req_fuse_prepare(req); int res; - struct fuse_intr_data d; + struct fuse *f = req_fuse_prepare(req); - fuse_prepare_interrupt(f, req, &d); - res = fuse_fs_write_buf(f->fs, buf, off, fi); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, NULL); + res = fuse_fs_write_buf(f->fs,buf,off,fi); + free_path(f,ino,NULL); - if (res >= 0) - fuse_reply_write(req, res); + if(res >= 0) + fuse_reply_write(req,res); else - reply_err(req, res); + reply_err(req,res); } -static void fuse_lib_fsync(fuse_req_t req, fuse_ino_t ino, int datasync, - struct fuse_file_info *fi) +static +void +fuse_lib_fsync(fuse_req_t req, + fuse_ino_t ino, + int datasync, + fuse_file_info_t *fi) { - struct fuse *f = req_fuse_prepare(req); int err; - struct fuse_intr_data d; + struct fuse *f = req_fuse_prepare(req); - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_fsync(f->fs, datasync, fi); - fuse_finish_interrupt(f, req, &d); + err = fuse_fs_fsync(f->fs,datasync,fi); - reply_err(req, err); + reply_err(req,err); } -static struct fuse_dh *get_dirhandle(const struct fuse_file_info *llfi, - struct fuse_file_info *fi) +static +struct fuse_dh* +get_dirhandle(const fuse_file_info_t *llfi, + fuse_file_info_t *fi) { - struct fuse_dh *dh = (struct fuse_dh *) (uintptr_t) llfi->fh; - memset(fi, 0, sizeof(struct fuse_file_info)); + struct fuse_dh *dh = (struct fuse_dh *)(uintptr_t)llfi->fh; + memset(fi,0,sizeof(fuse_file_info_t)); fi->fh = dh->fh; return dh; } -static void fuse_lib_opendir(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *llfi) +static +void +fuse_lib_opendir(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *llfi) { - struct fuse *f = req_fuse_prepare(req); - struct fuse_intr_data d; - struct fuse_dh *dh; - struct fuse_file_info fi; - char *path; int err; + char *path; + struct fuse_dh *dh; + fuse_file_info_t fi; + struct fuse *f = req_fuse_prepare(req); - dh = (struct fuse_dh *) calloc(1,sizeof(struct fuse_dh)); - if (dh == NULL) { - reply_err(req, -ENOMEM); - return; - } + dh = (struct fuse_dh *)calloc(1,sizeof(struct fuse_dh)); + if(dh == NULL) + { + reply_err(req,-ENOMEM); + return; + } fuse_dirents_init(&dh->d); fuse_mutex_init(&dh->lock); - llfi->fh = (uintptr_t) dh; + llfi->fh = (uintptr_t)dh; - memset(&fi, 0, sizeof(fi)); + memset(&fi,0,sizeof(fi)); fi.flags = llfi->flags; - err = get_path(f, ino, &path); - if (!err) { - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_opendir(f->fs, path, &fi); - fuse_finish_interrupt(f, req, &d); - dh->fh = fi.fh; - llfi->keep_cache = fi.keep_cache; - llfi->cache_readdir = fi.cache_readdir; - } + err = get_path(f,ino,&path); + if(!err) + { + err = fuse_fs_opendir(f->fs,path,&fi); + dh->fh = fi.fh; + llfi->keep_cache = fi.keep_cache; + llfi->cache_readdir = fi.cache_readdir; + } - if (!err) { - if (fuse_reply_open(req, llfi) == -ENOENT) { - /* The opendir syscall was interrupted, so it - must be cancelled */ - fuse_fs_releasedir(f->fs, &fi); + if(!err) + { + if(fuse_reply_open(req,llfi) == -ENOENT) + { + /* The opendir syscall was interrupted,so it + must be cancelled */ + fuse_fs_releasedir(f->fs,&fi); + pthread_mutex_destroy(&dh->lock); + free(dh); + } + } + else + { + reply_err(req,err); pthread_mutex_destroy(&dh->lock); free(dh); } - } else { - reply_err(req, err); - pthread_mutex_destroy(&dh->lock); - free(dh); - } - free_path(f, ino, path); + free_path(f,ino,path); } static int -readdir_fill(struct fuse *f_, - fuse_req_t req_, - fuse_dirents_t *d_, - struct fuse_file_info *fi_) +readdir_fill(struct fuse *f_, + fuse_req_t req_, + fuse_dirents_t *d_, + fuse_file_info_t *fi_) { int rv; - struct fuse_intr_data intr_data; - fuse_prepare_interrupt(f_,req_,&intr_data); rv = fuse_fs_readdir(f_->fs,fi_,d_); - fuse_finish_interrupt(f_,req_,&intr_data); return rv; } static int -readdir_plus_fill(struct fuse *f_, - fuse_req_t req_, - fuse_dirents_t *d_, - struct fuse_file_info *fi_) +readdir_plus_fill(struct fuse *f_, + fuse_req_t req_, + fuse_dirents_t *d_, + fuse_file_info_t *fi_) { int rv; - struct fuse_intr_data intr_data; - fuse_prepare_interrupt(f_,req_,&intr_data); rv = fuse_fs_readdir_plus(f_->fs,fi_,d_); - fuse_finish_interrupt(f_,req_,&intr_data); return rv; } @@ -3355,17 +3667,17 @@ readdir_buf(fuse_dirents_t *d_, static void -fuse_lib_readdir(fuse_req_t req_, - fuse_ino_t ino_, - size_t size_, - off_t off_, - struct fuse_file_info *llffi_) +fuse_lib_readdir(fuse_req_t req_, + fuse_ino_t ino_, + size_t size_, + off_t off_, + fuse_file_info_t *llffi_) { int rv; struct fuse *f; fuse_dirents_t *d; struct fuse_dh *dh; - struct fuse_file_info fi; + fuse_file_info_t fi; f = req_fuse_prepare(req_); dh = get_dirhandle(llffi_,&fi); @@ -3395,17 +3707,17 @@ fuse_lib_readdir(fuse_req_t req_, static void -fuse_lib_readdir_plus(fuse_req_t req_, - fuse_ino_t ino_, - size_t size_, - off_t off_, - struct fuse_file_info *llffi_) +fuse_lib_readdir_plus(fuse_req_t req_, + fuse_ino_t ino_, + size_t size_, + off_t off_, + fuse_file_info_t *llffi_) { int rv; struct fuse *f; fuse_dirents_t *d; struct fuse_dh *dh; - struct fuse_file_info fi; + fuse_file_info_t fi; f = req_fuse_prepare(req_); dh = get_dirhandle(llffi_,&fi); @@ -3435,21 +3747,18 @@ fuse_lib_readdir_plus(fuse_req_t req_, static void -fuse_lib_releasedir(fuse_req_t req_, - fuse_ino_t ino_, - struct fuse_file_info *llfi_) +fuse_lib_releasedir(fuse_req_t req_, + fuse_ino_t ino_, + fuse_file_info_t *llfi_) { struct fuse *f; struct fuse_dh *dh; - struct fuse_intr_data d; - struct fuse_file_info fi; + fuse_file_info_t fi; f = req_fuse_prepare(req_); dh = get_dirhandle(llfi_,&fi); - fuse_prepare_interrupt(f,req_,&d); fuse_fs_releasedir(f->fs,&fi); - fuse_finish_interrupt(f,req_,&d); /* Done to keep race condition between last readdir reply and the unlock */ pthread_mutex_lock(&dh->lock); @@ -3460,191 +3769,225 @@ fuse_lib_releasedir(fuse_req_t req_, reply_err(req_,0); } -static void fuse_lib_fsyncdir(fuse_req_t req, fuse_ino_t ino, int datasync, - struct fuse_file_info *llfi) +static +void +fuse_lib_fsyncdir(fuse_req_t req, + fuse_ino_t ino, + int datasync, + fuse_file_info_t *llfi) { - struct fuse *f = req_fuse_prepare(req); - struct fuse_file_info fi; int err; - struct fuse_intr_data d; + fuse_file_info_t fi; + struct fuse *f = req_fuse_prepare(req); - get_dirhandle(llfi, &fi); + get_dirhandle(llfi,&fi); - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_fsyncdir(f->fs, datasync, &fi); - fuse_finish_interrupt(f, req, &d); + err = fuse_fs_fsyncdir(f->fs,datasync,&fi); - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_statfs(fuse_req_t req, fuse_ino_t ino) +static +void +fuse_lib_statfs(fuse_req_t req, + fuse_ino_t ino) { struct fuse *f = req_fuse_prepare(req); struct statvfs buf; char *path = NULL; int err = 0; - memset(&buf, 0, sizeof(buf)); - if (ino) - err = get_path(f, ino, &path); + memset(&buf,0,sizeof(buf)); + if(ino) + err = get_path(f,ino,&path); - if (!err) { - struct fuse_intr_data d; - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_statfs(f->fs, path ? path : "/", &buf); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, path); - } + if(!err) + { + err = fuse_fs_statfs(f->fs,path ? path : "/",&buf); + free_path(f,ino,path); + } - if (!err) - fuse_reply_statfs(req, &buf); + if(!err) + fuse_reply_statfs(req,&buf); else - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, - const char *value, size_t size, int flags) +static +void +fuse_lib_setxattr(fuse_req_t req, + fuse_ino_t ino, + const char *name, + const char *value, + size_t size, + int flags) { struct fuse *f = req_fuse_prepare(req); char *path; int err; - err = get_path(f, ino, &path); - if (!err) { - struct fuse_intr_data d; - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_setxattr(f->fs, path, name, value, size, flags); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, path); - } - reply_err(req, err); + err = get_path(f,ino,&path); + if(!err) + { + err = fuse_fs_setxattr(f->fs,path,name,value,size,flags); + free_path(f,ino,path); + } + + reply_err(req,err); } -static int common_getxattr(struct fuse *f, fuse_req_t req, fuse_ino_t ino, - const char *name, char *value, size_t size) +static +int +common_getxattr(struct fuse *f, + fuse_req_t req, + fuse_ino_t ino, + const char *name, + char *value, + size_t size) { int err; char *path; - err = get_path(f, ino, &path); - if (!err) { - struct fuse_intr_data d; - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_getxattr(f->fs, path, name, value, size); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, path); - } + err = get_path(f,ino,&path); + if(!err) + { + err = fuse_fs_getxattr(f->fs,path,name,value,size); + + free_path(f,ino,path); + } + return err; } -static void fuse_lib_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, - size_t size) +static +void +fuse_lib_getxattr(fuse_req_t req, + fuse_ino_t ino, + const char *name, + size_t size) { struct fuse *f = req_fuse_prepare(req); int res; - if (size) { - char *value = (char *) malloc(size); - if (value == NULL) { - reply_err(req, -ENOMEM); - return; + if(size) + { + char *value = (char *)malloc(size); + if(value == NULL) + { + reply_err(req,-ENOMEM); + return; + } + + res = common_getxattr(f,req,ino,name,value,size); + if(res > 0) + fuse_reply_buf(req,value,res); + else + reply_err(req,res); + free(value); + } + else + { + res = common_getxattr(f,req,ino,name,NULL,0); + if(res >= 0) + fuse_reply_xattr(req,res); + else + reply_err(req,res); } - res = common_getxattr(f, req, ino, name, value, size); - if (res > 0) - fuse_reply_buf(req, value, res); - else - reply_err(req, res); - free(value); - } else { - res = common_getxattr(f, req, ino, name, NULL, 0); - if (res >= 0) - fuse_reply_xattr(req, res); - else - reply_err(req, res); - } } -static int common_listxattr(struct fuse *f, fuse_req_t req, fuse_ino_t ino, - char *list, size_t size) +static +int +common_listxattr(struct fuse *f, + fuse_req_t req, + fuse_ino_t ino, + char *list, + size_t size) { char *path; int err; - err = get_path(f, ino, &path); - if (!err) { - struct fuse_intr_data d; - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_listxattr(f->fs, path, list, size); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, path); - } + err = get_path(f,ino,&path); + if(!err) + { + err = fuse_fs_listxattr(f->fs,path,list,size); + free_path(f,ino,path); + } + return err; } -static void fuse_lib_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) +static +void +fuse_lib_listxattr(fuse_req_t req, + fuse_ino_t ino, + size_t size) { struct fuse *f = req_fuse_prepare(req); int res; - if (size) { - char *list = (char *) malloc(size); - if (list == NULL) { - reply_err(req, -ENOMEM); - return; + if(size) + { + char *list = (char *)malloc(size); + if(list == NULL) + { + reply_err(req,-ENOMEM); + return; + } + + res = common_listxattr(f,req,ino,list,size); + if(res > 0) + fuse_reply_buf(req,list,res); + else + reply_err(req,res); + free(list); + } + else + { + res = common_listxattr(f,req,ino,NULL,0); + if(res >= 0) + fuse_reply_xattr(req,res); + else + reply_err(req,res); } - res = common_listxattr(f, req, ino, list, size); - if (res > 0) - fuse_reply_buf(req, list, res); - else - reply_err(req, res); - free(list); - } else { - res = common_listxattr(f, req, ino, NULL, 0); - if (res >= 0) - fuse_reply_xattr(req, res); - else - reply_err(req, res); - } } -static void fuse_lib_removexattr(fuse_req_t req, fuse_ino_t ino, - const char *name) +static +void +fuse_lib_removexattr(fuse_req_t req, + fuse_ino_t ino, + const char *name) { struct fuse *f = req_fuse_prepare(req); char *path; int err; - err = get_path(f, ino, &path); - if (!err) { - struct fuse_intr_data d; - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_removexattr(f->fs, path, name); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, path); - } - reply_err(req, err); + err = get_path(f,ino,&path); + if(!err) + { + err = fuse_fs_removexattr(f->fs,path,name); + free_path(f,ino,path); + } + + reply_err(req,err); } static void -fuse_lib_copy_file_range(fuse_req_t req_, - fuse_ino_t nodeid_in_, - off_t off_in_, - struct fuse_file_info *ffi_in_, - fuse_ino_t nodeid_out_, - off_t off_out_, - struct fuse_file_info *ffi_out_, - size_t len_, - int flags_) +fuse_lib_copy_file_range(fuse_req_t req_, + fuse_ino_t nodeid_in_, + off_t off_in_, + fuse_file_info_t *ffi_in_, + fuse_ino_t nodeid_out_, + off_t off_out_, + fuse_file_info_t *ffi_out_, + size_t len_, + int flags_) { ssize_t rv; struct fuse *f; - struct fuse_intr_data d; f = req_fuse_prepare(req_); - fuse_prepare_interrupt(f,req_,&d); - rv = fuse_fs_copy_file_range(f->fs, ffi_in_, off_in_, @@ -3653,370 +3996,422 @@ fuse_lib_copy_file_range(fuse_req_t req_, len_, flags_); - fuse_finish_interrupt(f,req_,&d); - if(rv >= 0) fuse_reply_write(req_,rv); else reply_err(req_,rv); } -static struct lock *locks_conflict(struct node *node, const struct lock *lock) +static +struct lock* +locks_conflict(struct node *node, + const struct lock *lock) { struct lock *l; - for (l = node->locks; l; l = l->next) - if (l->owner != lock->owner && - lock->start <= l->end && l->start <= lock->end && - (l->type == F_WRLCK || lock->type == F_WRLCK)) + for(l = node->locks; l; l = l->next) + if(l->owner != lock->owner && + lock->start <= l->end && l->start <= lock->end && + (l->type == F_WRLCK || lock->type == F_WRLCK)) break; return l; } -static void delete_lock(struct lock **lockp) +static +void +delete_lock(struct lock **lockp) { struct lock *l = *lockp; *lockp = l->next; free(l); } -static void insert_lock(struct lock **pos, struct lock *lock) +static +void +insert_lock(struct lock **pos, + struct lock *lock) { lock->next = *pos; - *pos = lock; + *pos = lock; } -static int locks_insert(struct node *node, struct lock *lock) +static +int +locks_insert(struct node *node, + struct lock *lock) { struct lock **lp; - struct lock *newl1 = NULL; - struct lock *newl2 = NULL; - - if (lock->type != F_UNLCK || lock->start != 0 || - lock->end != OFFSET_MAX) { - newl1 = malloc(sizeof(struct lock)); - newl2 = malloc(sizeof(struct lock)); - - if (!newl1 || !newl2) { - free(newl1); - free(newl2); - return -ENOLCK; - } - } + struct lock *newl1 = NULL; + struct lock *newl2 = NULL; - for (lp = &node->locks; *lp;) { - struct lock *l = *lp; - if (l->owner != lock->owner) - goto skip; + if(lock->type != F_UNLCK || lock->start != 0 || lock->end != OFFSET_MAX) + { + newl1 = malloc(sizeof(struct lock)); + newl2 = malloc(sizeof(struct lock)); - if (lock->type == l->type) { - if (l->end < lock->start - 1) - goto skip; - if (lock->end < l->start - 1) - break; - if (l->start <= lock->start && lock->end <= l->end) - goto out; - if (l->start < lock->start) - lock->start = l->start; - if (lock->end < l->end) - lock->end = l->end; - goto delete; - } else { - if (l->end < lock->start) - goto skip; - if (lock->end < l->start) - break; - if (lock->start <= l->start && l->end <= lock->end) - goto delete; - if (l->end <= lock->end) { - l->end = lock->start - 1; - goto skip; - } - if (lock->start <= l->start) { - l->start = lock->end + 1; - break; - } - *newl2 = *l; - newl2->start = lock->end + 1; - l->end = lock->start - 1; - insert_lock(&l->next, newl2); - newl2 = NULL; + if(!newl1 || !newl2) + { + free(newl1); + free(newl2); + return -ENOLCK; + } } - skip: - lp = &l->next; - continue; - delete: - delete_lock(lp); - } - if (lock->type != F_UNLCK) { - *newl1 = *lock; - insert_lock(lp, newl1); - newl1 = NULL; - } + for(lp = &node->locks; *lp;) + { + struct lock *l = *lp; + if(l->owner != lock->owner) + goto skip; + + if(lock->type == l->type) + { + if(l->end < lock->start - 1) + goto skip; + if(lock->end < l->start - 1) + break; + if(l->start <= lock->start && lock->end <= l->end) + goto out; + if(l->start < lock->start) + lock->start = l->start; + if(lock->end < l->end) + lock->end = l->end; + goto delete; + } + else + { + if(l->end < lock->start) + goto skip; + if(lock->end < l->start) + break; + if(lock->start <= l->start && l->end <= lock->end) + goto delete; + if(l->end <= lock->end) + { + l->end = lock->start - 1; + goto skip; + } + if(lock->start <= l->start) + { + l->start = lock->end + 1; + break; + } + *newl2 = *l; + newl2->start = lock->end + 1; + l->end = lock->start - 1; + insert_lock(&l->next,newl2); + newl2 = NULL; + } + skip: + lp = &l->next; + continue; + + delete: + delete_lock(lp); + } + if(lock->type != F_UNLCK) + { + *newl1 = *lock; + insert_lock(lp,newl1); + newl1 = NULL; + } out: free(newl1); free(newl2); return 0; } -static void flock_to_lock(struct flock *flock, struct lock *lock) +static +void +flock_to_lock(struct flock *flock, + struct lock *lock) { - memset(lock, 0, sizeof(struct lock)); + memset(lock,0,sizeof(struct lock)); lock->type = flock->l_type; lock->start = flock->l_start; - lock->end = - flock->l_len ? flock->l_start + flock->l_len - 1 : OFFSET_MAX; + lock->end = flock->l_len ? flock->l_start + flock->l_len - 1 : OFFSET_MAX; lock->pid = flock->l_pid; } -static void lock_to_flock(struct lock *lock, struct flock *flock) +static +void +lock_to_flock(struct lock *lock, + struct flock *flock) { flock->l_type = lock->type; flock->l_start = lock->start; - flock->l_len = - (lock->end == OFFSET_MAX) ? 0 : lock->end - lock->start + 1; + flock->l_len = (lock->end == OFFSET_MAX) ? 0 : lock->end - lock->start + 1; flock->l_pid = lock->pid; } -static int fuse_flush_common(struct fuse *f, fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) +static +int +fuse_flush_common(struct fuse *f, + fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi) { - struct fuse_intr_data d; struct flock lock; struct lock l; int err; int errlock; - fuse_prepare_interrupt(f, req, &d); - memset(&lock, 0, sizeof(lock)); + memset(&lock,0,sizeof(lock)); lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; - err = fuse_fs_flush(f->fs, fi); - errlock = fuse_fs_lock(f->fs, fi, F_SETLK, &lock); - fuse_finish_interrupt(f, req, &d); - - if (errlock != -ENOSYS) { - flock_to_lock(&lock, &l); - l.owner = fi->lock_owner; - pthread_mutex_lock(&f->lock); - locks_insert(get_node(f, ino), &l); - pthread_mutex_unlock(&f->lock); - - /* if op.lock() is defined FLUSH is needed regardless - of op.flush() */ - if (err == -ENOSYS) - err = 0; - } + err = fuse_fs_flush(f->fs,fi); + errlock = fuse_fs_lock(f->fs,fi,F_SETLK,&lock); + + if(errlock != -ENOSYS) + { + flock_to_lock(&lock,&l); + l.owner = fi->lock_owner; + pthread_mutex_lock(&f->lock); + locks_insert(get_node(f,ino),&l); + pthread_mutex_unlock(&f->lock); + + /* if op.lock() is defined FLUSH is needed regardless + of op.flush() */ + if(err == -ENOSYS) + err = 0; + } + return err; } -static void fuse_lib_release(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) +static +void +fuse_lib_release(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi) { - struct fuse *f = req_fuse_prepare(req); - struct fuse_intr_data d; int err = 0; + struct fuse *f = req_fuse_prepare(req); - if (fi->flush) { - err = fuse_flush_common(f, req, ino, fi); - if (err == -ENOSYS) - err = 0; - } + if(fi->flush) + { + err = fuse_flush_common(f,req,ino,fi); + if(err == -ENOSYS) + err = 0; + } - fuse_prepare_interrupt(f, req, &d); - fuse_do_release(f, ino, fi); - fuse_finish_interrupt(f, req, &d); + fuse_do_release(f,ino,fi); - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_flush(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) +static +void +fuse_lib_flush(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi) { - struct fuse *f = req_fuse_prepare(req); int err; + struct fuse *f = req_fuse_prepare(req); - err = fuse_flush_common(f, req, ino, fi); + err = fuse_flush_common(f,req,ino,fi); - reply_err(req, err); + reply_err(req,err); } -static int fuse_lock_common(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi, struct flock *lock, - int cmd) +static +int +fuse_lock_common(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi, + struct flock *lock, + int cmd) { - struct fuse *f = req_fuse_prepare(req); int err; - struct fuse_intr_data d; + struct fuse *f = req_fuse_prepare(req); - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_lock(f->fs, fi, cmd, lock); - fuse_finish_interrupt(f, req, &d); + err = fuse_fs_lock(f->fs,fi,cmd,lock); return err; } -static void fuse_lib_getlk(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi, struct flock *lock) +static +void +fuse_lib_getlk(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi, + struct flock *lock) { int err; struct lock l; struct lock *conflict; struct fuse *f = req_fuse(req); - flock_to_lock(lock, &l); + flock_to_lock(lock,&l); l.owner = fi->lock_owner; pthread_mutex_lock(&f->lock); - conflict = locks_conflict(get_node(f, ino), &l); - if (conflict) - lock_to_flock(conflict, lock); + conflict = locks_conflict(get_node(f,ino),&l); + if(conflict) + lock_to_flock(conflict,lock); pthread_mutex_unlock(&f->lock); - if (!conflict) - err = fuse_lock_common(req, ino, fi, lock, F_GETLK); + if(!conflict) + err = fuse_lock_common(req,ino,fi,lock,F_GETLK); else err = 0; - if (!err) - fuse_reply_lock(req, lock); + if(!err) + fuse_reply_lock(req,lock); else - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_setlk(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi, struct flock *lock, - int sleep) +static +void +fuse_lib_setlk(fuse_req_t req, + fuse_ino_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); - struct lock l; - flock_to_lock(lock, &l); - l.owner = fi->lock_owner; - pthread_mutex_lock(&f->lock); - locks_insert(get_node(f, ino), &l); - pthread_mutex_unlock(&f->lock); - } - reply_err(req, err); + if(!err) + { + struct fuse *f = req_fuse(req); + struct lock l; + flock_to_lock(lock,&l); + l.owner = fi->lock_owner; + pthread_mutex_lock(&f->lock); + locks_insert(get_node(f,ino),&l); + pthread_mutex_unlock(&f->lock); + } + + reply_err(req,err); } -static void fuse_lib_flock(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi, int op) +static +void +fuse_lib_flock(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi, + int op) { - struct fuse *f = req_fuse_prepare(req); int err; - struct fuse_intr_data d; + struct fuse *f = req_fuse_prepare(req); - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_flock(f->fs, fi, op); - fuse_finish_interrupt(f, req, &d); + err = fuse_fs_flock(f->fs,fi,op); - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_bmap(fuse_req_t req, fuse_ino_t ino, size_t blocksize, - uint64_t idx) +static +void +fuse_lib_bmap(fuse_req_t req, + fuse_ino_t ino, + size_t blocksize, + uint64_t idx) { - struct fuse *f = req_fuse_prepare(req); - struct fuse_intr_data d; - char *path; int err; + char *path; + struct fuse *f = req_fuse_prepare(req); - err = get_path(f, ino, &path); - if (!err) { - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_bmap(f->fs, path, blocksize, &idx); - fuse_finish_interrupt(f, req, &d); - free_path(f, ino, path); - } - if (!err) - fuse_reply_bmap(req, idx); + err = get_path(f,ino,&path); + if(!err) + { + err = fuse_fs_bmap(f->fs,path,blocksize,&idx); + free_path(f,ino,path); + } + + if(!err) + fuse_reply_bmap(req,idx); else - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_ioctl(fuse_req_t req, fuse_ino_t ino, unsigned long cmd, void *arg, - struct fuse_file_info *llfi, unsigned int flags, - const void *in_buf, uint32_t in_bufsz, - uint32_t out_bufsz_) +static +void +fuse_lib_ioctl(fuse_req_t req, + fuse_ino_t ino, + unsigned long cmd, + void *arg, + fuse_file_info_t *llfi, + unsigned int flags, + const void *in_buf, + uint32_t in_bufsz, + uint32_t out_bufsz_) { - struct fuse *f = req_fuse_prepare(req); - struct fuse_intr_data d; - struct fuse_file_info fi; - char *out_buf = NULL; int err; + char *out_buf = NULL; + struct fuse *f = req_fuse_prepare(req); + fuse_file_info_t fi; uint32_t out_bufsz = out_bufsz_; err = -EPERM; - if (flags & FUSE_IOCTL_UNRESTRICTED) + if(flags & FUSE_IOCTL_UNRESTRICTED) goto err; - if (flags & FUSE_IOCTL_DIR) - get_dirhandle(llfi, &fi); + if(flags & FUSE_IOCTL_DIR) + get_dirhandle(llfi,&fi); else fi = *llfi; - if (out_bufsz) { - err = -ENOMEM; - out_buf = malloc(out_bufsz); - if (!out_buf) - goto err; - } + if(out_bufsz) + { + err = -ENOMEM; + out_buf = malloc(out_bufsz); + if(!out_buf) + goto err; + } assert(!in_bufsz || !out_bufsz || in_bufsz == out_bufsz); - if (out_buf) - memcpy(out_buf, in_buf, in_bufsz); + if(out_buf) + memcpy(out_buf,in_buf,in_bufsz); - fuse_prepare_interrupt(f, req, &d); + err = fuse_fs_ioctl(f->fs,cmd,arg,&fi,flags, + out_buf ?: (void *)in_buf,&out_bufsz); - err = fuse_fs_ioctl(f->fs, cmd, arg, &fi, flags, - out_buf ?: (void *)in_buf, &out_bufsz); - - fuse_finish_interrupt(f, req, &d); - - fuse_reply_ioctl(req, err, out_buf, out_bufsz); + fuse_reply_ioctl(req,err,out_buf,out_bufsz); goto out; err: - reply_err(req, err); + reply_err(req,err); out: free(out_buf); } -static void fuse_lib_poll(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi, struct fuse_pollhandle *ph) +static +void +fuse_lib_poll(fuse_req_t req, + fuse_ino_t ino, + fuse_file_info_t *fi, + fuse_pollhandle_t *ph) { - struct fuse *f = req_fuse_prepare(req); - struct fuse_intr_data d; int err; + struct fuse *f = req_fuse_prepare(req); unsigned revents = 0; - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_poll(f->fs, fi, ph, &revents); - fuse_finish_interrupt(f, req, &d); + err = fuse_fs_poll(f->fs,fi,ph,&revents); - if (!err) - fuse_reply_poll(req, revents); + if(!err) + fuse_reply_poll(req,revents); else - reply_err(req, err); + reply_err(req,err); } -static void fuse_lib_fallocate(fuse_req_t req, fuse_ino_t ino, int mode, - off_t offset, off_t length, struct fuse_file_info *fi) +static +void +fuse_lib_fallocate(fuse_req_t req, + fuse_ino_t ino, + int mode, + off_t offset, + off_t length, + fuse_file_info_t *fi) { - struct fuse *f = req_fuse_prepare(req); - struct fuse_intr_data d; int err; + struct fuse *f = req_fuse_prepare(req); - fuse_prepare_interrupt(f, req, &d); - err = fuse_fs_fallocate(f->fs, mode, offset, length, fi); - fuse_finish_interrupt(f, req, &d); + err = fuse_fs_fallocate(f->fs,mode,offset,length,fi); - reply_err(req, err); + reply_err(req,err); } -static int clean_delay(struct fuse *f) +static +int +clean_delay(struct fuse *f) { /* * This is calculating the delay between clean runs. To @@ -4027,17 +4422,18 @@ static int clean_delay(struct fuse *f) int max_sleep = 3600; int sleep_time = f->conf.remember / 10; - if (sleep_time > max_sleep) + if(sleep_time > max_sleep) return max_sleep; - if (sleep_time < min_sleep) + if(sleep_time < min_sleep) return min_sleep; return sleep_time; } -int fuse_clean_cache(struct fuse *f) +int +fuse_clean_cache(struct fuse *f) { struct node_lru *lnode; - struct list_head *curr, *next; + struct list_head *curr,*next; struct node *node; struct timespec now; @@ -4045,193 +4441,196 @@ int fuse_clean_cache(struct fuse *f) curr_time(&now); - for (curr = f->lru_table.next; curr != &f->lru_table; curr = next) { + for(curr = f->lru_table.next; curr != &f->lru_table; curr = next) + { double age; next = curr->next; - lnode = list_entry(curr, struct node_lru, lru); + lnode = list_entry(curr,struct node_lru,lru); node = &lnode->node; - age = diff_timespec(&now, &lnode->forget_time); - if (age <= f->conf.remember) + age = diff_timespec(&now,&lnode->forget_time); + if(age <= f->conf.remember) break; assert(node->nlookup == 1); /* Don't forget active directories */ - if (node->refctr > 1) + if(node->refctr > 1) continue; node->nlookup = 0; - unhash_name(f, node); - unref_node(f, node); + unhash_name(f,node); + unref_node(f,node); } pthread_mutex_unlock(&f->lock); return clean_delay(f); } -static struct fuse_lowlevel_ops fuse_path_ops = { - .init = fuse_lib_init, - .destroy = fuse_lib_destroy, - .lookup = fuse_lib_lookup, - .forget = fuse_lib_forget, - .forget_multi = fuse_lib_forget_multi, - .getattr = fuse_lib_getattr, - .setattr = fuse_lib_setattr, - .access = fuse_lib_access, - .readlink = fuse_lib_readlink, - .mknod = fuse_lib_mknod, - .mkdir = fuse_lib_mkdir, - .unlink = fuse_lib_unlink, - .rmdir = fuse_lib_rmdir, - .symlink = fuse_lib_symlink, - .rename = fuse_lib_rename, - .link = fuse_lib_link, - .create = fuse_lib_create, - .open = fuse_lib_open, - .read = fuse_lib_read, - .write_buf = fuse_lib_write_buf, - .flush = fuse_lib_flush, - .release = fuse_lib_release, - .fsync = fuse_lib_fsync, - .opendir = fuse_lib_opendir, - .readdir = fuse_lib_readdir, - .readdir_plus = fuse_lib_readdir_plus, - .releasedir = fuse_lib_releasedir, - .fsyncdir = fuse_lib_fsyncdir, - .statfs = fuse_lib_statfs, - .setxattr = fuse_lib_setxattr, - .getxattr = fuse_lib_getxattr, - .listxattr = fuse_lib_listxattr, - .removexattr = fuse_lib_removexattr, - .getlk = fuse_lib_getlk, - .setlk = fuse_lib_setlk, - .flock = fuse_lib_flock, - .bmap = fuse_lib_bmap, - .ioctl = fuse_lib_ioctl, - .poll = fuse_lib_poll, - .fallocate = fuse_lib_fallocate, - .copy_file_range = fuse_lib_copy_file_range, -}; +static struct fuse_lowlevel_ops fuse_path_ops = + { + .init = fuse_lib_init, + .destroy = fuse_lib_destroy, + .lookup = fuse_lib_lookup, + .forget = fuse_lib_forget, + .forget_multi = fuse_lib_forget_multi, + .getattr = fuse_lib_getattr, + .setattr = fuse_lib_setattr, + .access = fuse_lib_access, + .readlink = fuse_lib_readlink, + .mknod = fuse_lib_mknod, + .mkdir = fuse_lib_mkdir, + .unlink = fuse_lib_unlink, + .rmdir = fuse_lib_rmdir, + .symlink = fuse_lib_symlink, + .rename = fuse_lib_rename, + .link = fuse_lib_link, + .create = fuse_lib_create, + .open = fuse_lib_open, + .read = fuse_lib_read, + .write_buf = fuse_lib_write_buf, + .flush = fuse_lib_flush, + .release = fuse_lib_release, + .fsync = fuse_lib_fsync, + .opendir = fuse_lib_opendir, + .readdir = fuse_lib_readdir, + .readdir_plus = fuse_lib_readdir_plus, + .releasedir = fuse_lib_releasedir, + .fsyncdir = fuse_lib_fsyncdir, + .statfs = fuse_lib_statfs, + .setxattr = fuse_lib_setxattr, + .getxattr = fuse_lib_getxattr, + .listxattr = fuse_lib_listxattr, + .removexattr = fuse_lib_removexattr, + .getlk = fuse_lib_getlk, + .setlk = fuse_lib_setlk, + .flock = fuse_lib_flock, + .bmap = fuse_lib_bmap, + .ioctl = fuse_lib_ioctl, + .poll = fuse_lib_poll, + .fallocate = fuse_lib_fallocate, + .copy_file_range = fuse_lib_copy_file_range, + }; -int fuse_notify_poll(struct fuse_pollhandle *ph) +int +fuse_notify_poll(fuse_pollhandle_t *ph) { return fuse_lowlevel_notify_poll(ph); } -static void free_cmd(struct fuse_cmd *cmd) +static +void +free_cmd(struct fuse_cmd *cmd) { free(cmd->buf); free(cmd); } -void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd) +void +fuse_process_cmd(struct fuse *f, + struct fuse_cmd *cmd) { - fuse_session_process(f->se, cmd->buf, cmd->buflen, cmd->ch); + fuse_session_process(f->se,cmd->buf,cmd->buflen,cmd->ch); free_cmd(cmd); } -int fuse_exited(struct fuse *f) +int +fuse_exited(struct fuse *f) { return fuse_session_exited(f->se); } -struct fuse_session *fuse_get_session(struct fuse *f) +struct fuse_session* +fuse_get_session(struct fuse *f) { return f->se; } -static struct fuse_cmd *fuse_alloc_cmd(size_t bufsize) +static +struct fuse_cmd* +fuse_alloc_cmd(size_t bufsize) { - struct fuse_cmd *cmd = (struct fuse_cmd *) malloc(sizeof(*cmd)); - if (cmd == NULL) { - fprintf(stderr, "fuse: failed to allocate cmd\n"); - return NULL; - } - cmd->buf = (char *) malloc(bufsize); - if (cmd->buf == NULL) { - fprintf(stderr, "fuse: failed to allocate read buffer\n"); - free(cmd); - return NULL; - } + struct fuse_cmd *cmd = (struct fuse_cmd *)malloc(sizeof(*cmd)); + if(cmd == NULL) + { + fprintf(stderr,"fuse: failed to allocate cmd\n"); + return NULL; + } + + cmd->buf = (char *)malloc(bufsize); + if(cmd->buf == NULL) + { + fprintf(stderr,"fuse: failed to allocate read buffer\n"); + free(cmd); + return NULL; + } + return cmd; } -struct fuse_cmd *fuse_read_cmd(struct fuse *f) +struct fuse_cmd* +fuse_read_cmd(struct fuse *f) { - struct fuse_chan *ch = fuse_session_next_chan(f->se, NULL); + struct fuse_chan *ch = fuse_session_next_chan(f->se,NULL); size_t bufsize = fuse_chan_bufsize(ch); struct fuse_cmd *cmd = fuse_alloc_cmd(bufsize); - if (cmd != NULL) { - int res = fuse_chan_recv(&ch, cmd->buf, bufsize); - if (res <= 0) { - free_cmd(cmd); - if (res < 0 && res != -EINTR && res != -EAGAIN) - fuse_exit(f); - return NULL; + + if(cmd != NULL) + { + int res = fuse_chan_recv(&ch,cmd->buf,bufsize); + if(res <= 0) + { + free_cmd(cmd); + if(res < 0 && res != -EINTR && res != -EAGAIN) + fuse_exit(f); + return NULL; + } + cmd->buflen = res; + cmd->ch = ch; } - cmd->buflen = res; - cmd->ch = ch; - } - return cmd; -} -int fuse_invalidate(struct fuse *f, const char *path) -{ - (void) f; - (void) path; - return -EINVAL; + return cmd; } -void fuse_exit(struct fuse *f) +void +fuse_exit(struct fuse *f) { fuse_session_exit(f->se); } -struct fuse_context *fuse_get_context(void) +struct fuse_context* +fuse_get_context(void) { return &fuse_get_context_internal()->ctx; } -int fuse_interrupted(void) -{ - return fuse_req_interrupted(fuse_get_context_internal()->req); -} - -void fuse_set_getcontext_func(struct fuse_context *(*func)(void)) -{ - (void) func; - /* no-op */ -} - 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("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_LIB_OPT("intr", intr, 1), - FUSE_LIB_OPT("intr_signal=%d", intr_signal, 0), - FUSE_LIB_OPT("threads=%d", threads, 0), - FUSE_LIB_OPT("use_ino", use_ino, 1), - FUSE_OPT_END -}; +#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("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_LIB_OPT("threads=%d", threads,0), + FUSE_LIB_OPT("use_ino", use_ino,1), + FUSE_OPT_END + }; static void fuse_lib_help(void) { @@ -4241,223 +4640,202 @@ static void fuse_lib_help(void) " -o gid=N set file group\n" " -o noforget never forget cached inodes\n" " -o remember=T remember cached inodes for T seconds (0s)\n" - " -o intr allow requests to be interrupted\n" - " -o intr_signal=NUM signal to send on interrupt (%i)\n" " -o threads=NUM number of worker threads. 0 = autodetect.\n" " Negative values autodetect then divide by\n" " absolute value. default = 0\n" - "\n", FUSE_DEFAULT_INTR_SIGNAL); + "\n"); } -static int fuse_lib_opt_proc(void *data, const char *arg, int key, - struct fuse_args *outargs) +static +int +fuse_lib_opt_proc(void *data, + const char *arg, + int key, + struct fuse_args *outargs) { - (void) arg; (void) outargs; + (void)arg; (void)outargs; - if (key == KEY_HELP) { - struct fuse_config *conf = (struct fuse_config *) data; - fuse_lib_help(); - conf->help = 1; - } + if(key == KEY_HELP) + { + struct fuse_config *conf = (struct fuse_config *)data; + fuse_lib_help(); + conf->help = 1; + } return 1; } -int fuse_is_lib_option(const char *opt) -{ - return fuse_lowlevel_is_lib_option(opt) || - fuse_opt_match(fuse_lib_opts, opt); -} - -static int fuse_init_intr_signal(int signum, int *installed) -{ - struct sigaction old_sa; - - if (sigaction(signum, NULL, &old_sa) == -1) { - perror("fuse: cannot get old signal handler"); - return -1; - } - - if (old_sa.sa_handler == SIG_DFL) { - struct sigaction sa; - - memset(&sa, 0, sizeof(struct sigaction)); - sa.sa_handler = fuse_intr_sighandler; - sigemptyset(&sa.sa_mask); - - if (sigaction(signum, &sa, NULL) == -1) { - perror("fuse: cannot set interrupt signal handler"); - return -1; - } - *installed = 1; - } - return 0; -} - -static void fuse_restore_intr_signal(int signum) +int +fuse_is_lib_option(const char *opt) { - struct sigaction sa; - - memset(&sa, 0, sizeof(struct sigaction)); - sa.sa_handler = SIG_DFL; - sigaction(signum, &sa, NULL); + 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, - void *user_data) +struct fuse_fs* +fuse_fs_new(const struct fuse_operations *op, + size_t op_size, + void *user_data) { 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); - } + 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; - } + fs = (struct fuse_fs *)calloc(1,sizeof(struct fuse_fs)); + if(!fs) + { + fprintf(stderr,"fuse: failed to allocate fuse_fs object\n"); + return NULL; + } fs->user_data = user_data; - if (op) - memcpy(&fs->op, op, op_size); + if(op) + memcpy(&fs->op,op,op_size); + return fs; } -static int node_table_init(struct node_table *t) +static +int +node_table_init(struct node_table *t) { t->size = NODE_TABLE_MIN_SIZE; - t->array = (struct node **) calloc(1, sizeof(struct node *) * t->size); - if (t->array == NULL) { - fprintf(stderr, "fuse: memory allocation failed\n"); - return -1; - } + t->array = (struct node **)calloc(1,sizeof(struct node *) * t->size); + if(t->array == NULL) + { + fprintf(stderr,"fuse: memory allocation failed\n"); + return -1; + } t->use = 0; t->split = 0; return 0; } -static void *fuse_prune_nodes(void *fuse) +static +void* +fuse_prune_nodes(void *fuse) { struct fuse *f = fuse; int sleep_time; - while(1) { - sleep_time = fuse_clean_cache(f); - sleep(sleep_time); - } + while(1) + { + sleep_time = fuse_clean_cache(f); + sleep(sleep_time); + } return NULL; } -int fuse_start_cleanup_thread(struct fuse *f) +int +fuse_start_cleanup_thread(struct fuse *f) { - if (lru_enabled(f)) - return fuse_start_thread(&f->prune_thread, fuse_prune_nodes, f); + if(lru_enabled(f)) + return fuse_start_thread(&f->prune_thread,fuse_prune_nodes,f); return 0; } -void fuse_stop_cleanup_thread(struct fuse *f) +void +fuse_stop_cleanup_thread(struct fuse *f) { - if (lru_enabled(f)) { - pthread_mutex_lock(&f->lock); - pthread_cancel(f->prune_thread); - pthread_mutex_unlock(&f->lock); - pthread_join(f->prune_thread, NULL); - } + if(lru_enabled(f)) + { + pthread_mutex_lock(&f->lock); + pthread_cancel(f->prune_thread); + pthread_mutex_unlock(&f->lock); + pthread_join(f->prune_thread,NULL); + } } -struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args, - const struct fuse_operations *op, - size_t op_size, void *user_data) +struct fuse* +fuse_new_common(struct fuse_chan *ch, + struct fuse_args *args, + const struct fuse_operations *op, + size_t op_size, + void *user_data) { struct fuse *f; struct node *root; struct fuse_fs *fs; struct fuse_lowlevel_ops llop = fuse_path_ops; - if (fuse_create_context_key() == -1) + if(fuse_create_context_key() == -1) goto out; - f = (struct fuse *) calloc(1, sizeof(struct fuse)); - if (f == NULL) { - fprintf(stderr, "fuse: failed to allocate fuse object\n"); - goto out_delete_context_key; - } + f = (struct fuse *)calloc(1,sizeof(struct fuse)); + if(f == NULL) + { + fprintf(stderr,"fuse: failed to allocate fuse object\n"); + goto out_delete_context_key; + } - fs = fuse_fs_new(op, op_size, user_data); - if (!fs) + fs = fuse_fs_new(op,op_size,user_data); + if(!fs) goto out_free; f->fs = fs; - /* Oh f**k, this is ugly! */ - if (!fs->op.lock) { - llop.getlk = NULL; - llop.setlk = NULL; - } - - f->conf.intr_signal = FUSE_DEFAULT_INTR_SIGNAL; + /* Oh f**k,this is ugly! */ + if(!fs->op.lock) + { + llop.getlk = NULL; + llop.setlk = NULL; + } f->pagesize = getpagesize(); init_list_head(&f->partial_slabs); init_list_head(&f->full_slabs); init_list_head(&f->lru_table); - 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; - 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->fs->debug = f->conf.debug; f->ctr = 0; f->generation = rand64(); - if (node_table_init(&f->name_table) == -1) + 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; fuse_mutex_init(&f->lock); root = alloc_node(f); - if (root == NULL) { - fprintf(stderr, "fuse: memory allocation failed\n"); - goto out_free_id_table; - } - if (lru_enabled(f)) { - struct node_lru *lnode = node_lru(root); - init_list_head(&lnode->lru); - } + if(root == NULL) + { + fprintf(stderr,"fuse: memory allocation failed\n"); + goto out_free_id_table; + } - strcpy(root->inline_name, "/"); - root->name = root->inline_name; + if(lru_enabled(f)) + { + struct node_lru *lnode = node_lru(root); + init_list_head(&lnode->lru); + } - if (f->conf.intr && - fuse_init_intr_signal(f->conf.intr_signal, - &f->intr_installed) == -1) - goto out_free_root; + strcpy(root->inline_name,"/"); + root->name = root->inline_name; root->parent = NULL; root->nodeid = FUSE_ROOT_ID; inc_nlookup(root); - hash_id(f, root); + hash_id(f,root); return f; - out_free_root: - free(root); out_free_id_table: free(f->id_table.array); out_free_name_table: @@ -4477,46 +4855,53 @@ struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args, return NULL; } -struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args, - const struct fuse_operations *op, size_t op_size, - void *user_data) +struct fuse* +fuse_new(struct fuse_chan *ch, + struct fuse_args *args, + const struct fuse_operations *op, + size_t op_size, + void *user_data) { - return fuse_new_common(ch, args, op, op_size, user_data); + return fuse_new_common(ch,args,op,op_size,user_data); } -void fuse_destroy(struct fuse *f) +void +fuse_destroy(struct fuse *f) { size_t i; - if (f->conf.intr && f->intr_installed) - fuse_restore_intr_signal(f->conf.intr_signal); + if(f->fs) + { + struct fuse_context_i *c = fuse_get_context_internal(); + + memset(c,0,sizeof(*c)); + c->ctx.fuse = f; - if (f->fs) { - struct fuse_context_i *c = fuse_get_context_internal(); + for(i = 0; i < f->id_table.size; i++) + { + struct node *node; - memset(c, 0, sizeof(*c)); - c->ctx.fuse = f; + for(node = f->id_table.array[i]; node != NULL; node = node->id_next) + { + if(node->is_hidden) + fuse_fs_free_hide(f->fs,node->hidden_fh); + } + } + } - for (i = 0; i < f->id_table.size; i++) { + for(i = 0; i < f->id_table.size; i++) + { struct node *node; + struct node *next; - for (node = f->id_table.array[i]; node != NULL; node = node->id_next) + for(node = f->id_table.array[i]; node != NULL; node = next) { - if (node->is_hidden) - fuse_fs_free_hide(f->fs,node->hidden_fh); + next = node->id_next; + free_node(f,node); + f->id_table.use--; } } - } - for (i = 0; i < f->id_table.size; i++) { - struct node *node; - struct 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--; - } - } + assert(list_empty(&f->partial_slabs)); assert(list_empty(&f->full_slabs)); diff --git a/libfuse/lib/fuse_loop_mt.c b/libfuse/lib/fuse_loop_mt.c index d9b76565..893ce7ae 100644 --- a/libfuse/lib/fuse_loop_mt.c +++ b/libfuse/lib/fuse_loop_mt.c @@ -6,25 +6,26 @@ See the file COPYING.LIB. */ +#include "fuse_i.h" +#include "fuse_kernel.h" #include "fuse_lowlevel.h" #include "fuse_misc.h" -#include "fuse_kernel.h" -#include "fuse_i.h" +#include +#include +#include #include #include #include -#include -#include -#include -#include #include #include +#include /* Environment var controlling the thread stack size */ #define ENVNAME_THREAD_STACK "FUSE_THREAD_STACK" -struct fuse_worker { +struct fuse_worker +{ struct fuse_worker *prev; struct fuse_worker *next; pthread_t thread_id; @@ -33,7 +34,8 @@ struct fuse_worker { struct fuse_mt *mt; }; -struct fuse_mt { +struct fuse_mt +{ struct fuse_session *se; struct fuse_chan *prevch; struct fuse_worker main; @@ -42,7 +44,10 @@ struct fuse_mt { int error; }; -static void list_add_worker(struct fuse_worker *w, struct fuse_worker *next) +static +void +list_add_worker(struct fuse_worker *w, + struct fuse_worker *next) { struct fuse_worker *prev = next->prev; w->next = next; @@ -61,37 +66,40 @@ static void list_del_worker(struct fuse_worker *w) static int fuse_loop_start_thread(struct fuse_mt *mt); -static void *fuse_do_work(void *data) +static +void* +fuse_do_work(void *data) { struct fuse_worker *w = (struct fuse_worker *) data; struct fuse_mt *mt = w->mt; - while (!fuse_session_exited(mt->se)) { - struct fuse_chan *ch = mt->prevch; - struct fuse_buf fbuf = { - .mem = w->buf, - .size = w->bufsize, - }; - int res; - - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - res = fuse_session_receive_buf(mt->se, &fbuf, &ch); - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - if (res == -EINTR) - continue; - if (res <= 0) { - if (res < 0) { - fuse_session_exit(mt->se); - mt->error = -1; + while(!fuse_session_exited(mt->se)) + { + int res; + struct fuse_buf fbuf; + struct fuse_chan *ch = mt->prevch; + + fbuf.mem = w->buf; + fbuf.size = w->bufsize; + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + res = fuse_session_receive_buf(mt->se, &fbuf, &ch); + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); + if(res == -EINTR) + continue; + if(res <= 0) { + if(res < 0) { + fuse_session_exit(mt->se); + mt->error = -1; + } + break; } - break; - } - if (mt->exit) - return NULL; + if(mt->exit) + return NULL; - fuse_session_process_buf(mt->se, &fbuf, ch); - } + fuse_session_process_buf(mt->se, &fbuf, ch); + } sem_post(&mt->finish); @@ -109,20 +117,16 @@ int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg) /* Override default stack size */ pthread_attr_init(&attr); stack_size = getenv(ENVNAME_THREAD_STACK); - if (stack_size && pthread_attr_setstacksize(&attr, atoi(stack_size))) + if(stack_size && pthread_attr_setstacksize(&attr, atoi(stack_size))) fprintf(stderr, "fuse: invalid stack size: %s\n", stack_size); /* Disallow signal reception in worker threads */ - sigemptyset(&newset); - sigaddset(&newset, SIGTERM); - sigaddset(&newset, SIGINT); - sigaddset(&newset, SIGHUP); - sigaddset(&newset, SIGQUIT); - pthread_sigmask(SIG_BLOCK, &newset, &oldset); + sigfillset(&newset); + pthread_sigmask(SIG_BLOCK,&newset,&oldset); res = pthread_create(thread_id, &attr, func, arg); - pthread_sigmask(SIG_SETMASK, &oldset, NULL); + pthread_sigmask(SIG_SETMASK,&oldset,NULL); pthread_attr_destroy(&attr); - if (res != 0) { + if(res != 0) { fprintf(stderr, "fuse: error creating thread: %s\n", strerror(res)); return -1; @@ -135,7 +139,7 @@ static int fuse_loop_start_thread(struct fuse_mt *mt) { int res; struct fuse_worker *w = malloc(sizeof(struct fuse_worker)); - if (!w) { + if(!w) { fprintf(stderr, "fuse: failed to allocate worker structure\n"); return -1; } @@ -143,14 +147,14 @@ static int fuse_loop_start_thread(struct fuse_mt *mt) w->bufsize = fuse_chan_bufsize(mt->prevch); w->buf = calloc(w->bufsize,1); w->mt = mt; - if (!w->buf) { + if(!w->buf) { fprintf(stderr, "fuse: failed to allocate read buffer\n"); free(w); return -1; } res = fuse_start_thread(&w->thread_id, fuse_do_work, w); - if (res == -1) { + if(res == -1) { free(w->buf); free(w); return -1; @@ -177,8 +181,9 @@ static int number_of_threads(void) return 4; } -int fuse_session_loop_mt(struct fuse_session *se, - const int _threads) +int +fuse_session_loop_mt(struct fuse_session *se_, + const int threads_) { int i; int err; @@ -186,17 +191,17 @@ int fuse_session_loop_mt(struct fuse_session *se, struct fuse_mt mt; struct fuse_worker *w; - memset(&mt, 0, sizeof(struct fuse_mt)); - mt.se = se; - mt.prevch = fuse_session_next_chan(se, NULL); + memset(&mt,0,sizeof(struct fuse_mt)); + mt.se = se_; + mt.prevch = fuse_session_next_chan(se_,NULL); mt.error = 0; mt.main.thread_id = pthread_self(); mt.main.prev = mt.main.next = &mt.main; - sem_init(&mt.finish, 0, 0); + sem_init(&mt.finish,0,0); - threads = ((_threads > 0) ? _threads : number_of_threads()); - if(_threads < 0) - threads /= -_threads; + threads = ((threads_ > 0) ? threads_ : number_of_threads()); + if(threads_ < 0) + threads /= -threads_; if(threads == 0) threads = 1; @@ -204,22 +209,24 @@ int fuse_session_loop_mt(struct fuse_session *se, for(i = 0; (i < threads) && !err; i++) err = fuse_loop_start_thread(&mt); - if (!err) { - /* sem_wait() is interruptible */ - while (!fuse_session_exited(se)) - sem_wait(&mt.finish); + if(!err) + { + /* sem_wait() is interruptible */ + while(!fuse_session_exited(se_)) + sem_wait(&mt.finish); - for (w = mt.main.next; w != &mt.main; w = w->next) - pthread_cancel(w->thread_id); - mt.exit = 1; + for(w = mt.main.next; w != &mt.main; w = w->next) + pthread_cancel(w->thread_id); + mt.exit = 1; - while (mt.main.next != &mt.main) - fuse_join_worker(mt.main.next); + while(mt.main.next != &mt.main) + fuse_join_worker(mt.main.next); - err = mt.error; - } + err = mt.error; + } sem_destroy(&mt.finish); - fuse_session_reset(se); + fuse_session_reset(se_); + return err; } diff --git a/libfuse/lib/fuse_lowlevel.c b/libfuse/lib/fuse_lowlevel.c index 8a922477..576021e3 100644 --- a/libfuse/lib/fuse_lowlevel.c +++ b/libfuse/lib/fuse_lowlevel.c @@ -39,7 +39,8 @@ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) -struct fuse_pollhandle { +struct fuse_pollhandle_t +{ uint64_t kh; struct fuse_chan *ch; struct fuse_ll *f; @@ -91,23 +92,30 @@ convert_attr(const struct fuse_setattr_in *attr_, ST_CTIM_NSEC_SET(stbuf_,attr_->ctimensec); } -static size_t iov_length(const struct iovec *iov, size_t count) +static +size_t +iov_length(const struct iovec *iov, + size_t count) { size_t seg; size_t ret = 0; - for (seg = 0; seg < count; seg++) + for(seg = 0; seg < count; seg++) ret += iov[seg].iov_len; return ret; } -static void list_init_req(struct fuse_req *req) +static +void +list_init_req(struct fuse_req *req) { req->next = req; req->prev = req; } -static void list_del_req(struct fuse_req *req) +static +void +list_del_req(struct fuse_req *req) { struct fuse_req *prev = req->prev; struct fuse_req *next = req->next; @@ -115,7 +123,10 @@ static void list_del_req(struct fuse_req *req) next->prev = prev; } -static void list_add_req(struct fuse_req *req, struct fuse_req *next) +static +void +list_add_req(struct fuse_req *req, + struct fuse_req *next) { struct fuse_req *prev = next->prev; req->next = next; @@ -124,13 +135,16 @@ static void list_add_req(struct fuse_req *req, struct fuse_req *next) next->prev = req; } -static void destroy_req(fuse_req_t req) +static +void +destroy_req(fuse_req_t req) { pthread_mutex_destroy(&req->lock); free(req); } -void fuse_free_req(fuse_req_t req) +void +fuse_free_req(fuse_req_t req) { int ctr; struct fuse_ll *f = req->f; @@ -141,62 +155,81 @@ void fuse_free_req(fuse_req_t req) list_del_req(req); ctr = --req->ctr; pthread_mutex_unlock(&f->lock); - if (!ctr) + if(!ctr) destroy_req(req); } -static struct fuse_req *fuse_ll_alloc_req(struct fuse_ll *f) +static +struct fuse_req* +fuse_ll_alloc_req(struct fuse_ll *f) { struct fuse_req *req; req = (struct fuse_req *) calloc(1, sizeof(struct fuse_req)); - if (req == NULL) { - fprintf(stderr, "fuse: failed to allocate request\n"); - } else { - req->f = f; - req->ctr = 1; - list_init_req(req); - fuse_mutex_init(&req->lock); - } + if (req == NULL) + { + fprintf(stderr, "fuse: failed to allocate request\n"); + } + else + { + req->f = f; + req->ctr = 1; + list_init_req(req); + fuse_mutex_init(&req->lock); + } return req; } -static int fuse_send_msg(struct fuse_ll *f, struct fuse_chan *ch, - struct iovec *iov, int count) +static +int +fuse_send_msg(struct fuse_ll *f, + struct fuse_chan *ch, + struct iovec *iov, + int count) { struct fuse_out_header *out = iov[0].iov_base; out->len = iov_length(iov, count); - if (f->debug) { - if (out->unique == 0) { - fprintf(stderr, "NOTIFY: code=%d length=%u\n", - out->error, out->len); - } else if (out->error) { - fprintf(stderr, - " unique: %llu, error: %i (%s), outsize: %i\n", - (unsigned long long) out->unique, out->error, - strerror(-out->error), out->len); - } else { - fprintf(stderr, - " unique: %llu, success, outsize: %i\n", - (unsigned long long) out->unique, out->len); + if (f->debug) + { + if (out->unique == 0) + { + fprintf(stderr, "NOTIFY: code=%d length=%u\n", + out->error, out->len); + } + else if (out->error) + { + fprintf(stderr, + " unique: %llu, error: %i (%s), outsize: %i\n", + (unsigned long long) out->unique, out->error, + strerror(-out->error), out->len); + } + else + { + fprintf(stderr, + " unique: %llu, success, outsize: %i\n", + (unsigned long long) out->unique, out->len); + } } - } return fuse_chan_send(ch, iov, count); } -int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov, - int count) +int +fuse_send_reply_iov_nofree(fuse_req_t req, + int error, + struct iovec *iov, + int count) { struct fuse_out_header out; - if (error <= -1000 || error > 0) { - fprintf(stderr, "fuse: bad error value: %i\n", error); - error = -ERANGE; - } + if (error <= -1000 || error > 0) + { + fprintf(stderr, "fuse: bad error value: %i\n",error); + error = -ERANGE; + } out.unique = req->unique; out.error = error; @@ -207,30 +240,44 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov, return fuse_send_msg(req->f, req->ch, iov, count); } -static int send_reply_iov(fuse_req_t req, int error, struct iovec *iov, - int count) +static +int +send_reply_iov(fuse_req_t req, + int error, + struct iovec *iov, + int count) { int res; res = fuse_send_reply_iov_nofree(req, error, iov, count); fuse_free_req(req); + return res; } -static int send_reply(fuse_req_t req, int error, const void *arg, - size_t argsize) +static +int +send_reply(fuse_req_t req, + int error, + const void *arg, + size_t argsize) { struct iovec iov[2]; int count = 1; - if (argsize) { - iov[1].iov_base = (void *) arg; - iov[1].iov_len = argsize; - count++; - } + if (argsize) + { + iov[1].iov_base = (void *) arg; + iov[1].iov_len = argsize; + count++; + } + return send_reply_iov(req, error, iov, count); } -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) { int res; struct iovec *padded_iov; @@ -248,13 +295,17 @@ int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count) return res; } -size_t fuse_dirent_size(size_t namelen) +size_t +fuse_dirent_size(size_t namelen) { return FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + namelen); } -char *fuse_add_dirent(char *buf, const char *name, const struct stat *stbuf, - off_t off) +char* +fuse_add_dirent(char *buf, + const char *name, + const struct stat *stbuf, + off_t off) { unsigned namelen = strlen(name); unsigned entlen = FUSE_NAME_OFFSET + namelen; @@ -273,8 +324,13 @@ char *fuse_add_dirent(char *buf, const char *name, const struct stat *stbuf, return buf + entsize; } -size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, - const char *name, const struct stat *stbuf, off_t off) +size_t +fuse_add_direntry(fuse_req_t req, + char *buf, + size_t bufsize, + const char *name, + const struct stat *stbuf, + off_t off) { size_t entsize; @@ -285,20 +341,26 @@ size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, return entsize; } -static void convert_statfs(const struct statvfs *stbuf, - struct fuse_kstatfs *kstatfs) -{ - kstatfs->bsize = stbuf->f_bsize; - kstatfs->frsize = stbuf->f_frsize; - kstatfs->blocks = stbuf->f_blocks; - kstatfs->bfree = stbuf->f_bfree; - kstatfs->bavail = stbuf->f_bavail; - kstatfs->files = stbuf->f_files; - kstatfs->ffree = stbuf->f_ffree; +static +void +convert_statfs(const struct statvfs *stbuf, + struct fuse_kstatfs *kstatfs) +{ + kstatfs->bsize = stbuf->f_bsize; + kstatfs->frsize = stbuf->f_frsize; + kstatfs->blocks = stbuf->f_blocks; + kstatfs->bfree = stbuf->f_bfree; + kstatfs->bavail = stbuf->f_bavail; + kstatfs->files = stbuf->f_files; + kstatfs->ffree = stbuf->f_ffree; kstatfs->namelen = stbuf->f_namemax; } -static int send_reply_ok(fuse_req_t req, const void *arg, size_t argsize) +static +int +send_reply_ok(fuse_req_t req, + const void *arg, + size_t argsize) { return send_reply(req, 0, arg, argsize); } @@ -310,7 +372,8 @@ fuse_reply_err(fuse_req_t req_, return send_reply(req_,-err_,NULL,0); } -void fuse_reply_none(fuse_req_t req) +void +fuse_reply_none(fuse_req_t req) { if (req->ch) fuse_chan_send(req->ch, NULL, 0); @@ -331,8 +394,10 @@ fill_entry(struct fuse_entry_out *arg, convert_stat(&e->attr,&arg->attr); } -static void fill_open(struct fuse_open_out *arg, - const struct fuse_file_info *f) +static +void +fill_open(struct fuse_open_out *arg, + const fuse_file_info_t *f) { arg->fh = f->fh; if (f->direct_io) @@ -345,7 +410,9 @@ static void fill_open(struct fuse_open_out *arg, arg->open_flags |= FOPEN_CACHE_DIR; } -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) { struct fuse_entry_out arg; size_t size = req->f->conn.proto_minor < 9 ? @@ -358,11 +425,14 @@ int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e) memset(&arg, 0, sizeof(arg)); fill_entry(&arg, e); + return send_reply_ok(req, &arg, size); } -int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, - const struct fuse_file_info *f) +int +fuse_reply_create(fuse_req_t req, + const struct fuse_entry_param *e, + const fuse_file_info_t *f) { char buf[sizeof(struct fuse_entry_out) + sizeof(struct fuse_open_out)]; size_t entrysize = req->f->conn.proto_minor < 9 ? @@ -373,8 +443,8 @@ int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, memset(buf, 0, sizeof(buf)); fill_entry(earg, e); fill_open(oarg, f); - return send_reply_ok(req, buf, - entrysize + sizeof(struct fuse_open_out)); + + return send_reply_ok(req, buf, entrysize + sizeof(struct fuse_open_out)); } int @@ -394,21 +464,28 @@ fuse_reply_attr(fuse_req_t req, return send_reply_ok(req,&arg,size); } -int fuse_reply_readlink(fuse_req_t req, const char *linkname) +int +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, const struct fuse_file_info *f) +int +fuse_reply_open(fuse_req_t req, + const fuse_file_info_t *f) { struct fuse_open_out arg; memset(&arg, 0, sizeof(arg)); fill_open(&arg, f); + return send_reply_ok(req, &arg, sizeof(arg)); } -int fuse_reply_write(fuse_req_t req, size_t count) +int +fuse_reply_write(fuse_req_t req, + size_t count) { struct fuse_write_out arg; @@ -418,31 +495,40 @@ int fuse_reply_write(fuse_req_t req, size_t count) return send_reply_ok(req, &arg, sizeof(arg)); } -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) { return send_reply_ok(req, buf, size); } -static int fuse_send_data_iov_fallback(struct fuse_ll *f, struct fuse_chan *ch, - struct iovec *iov, int iov_count, - struct fuse_bufvec *buf, - size_t len) +static +int +fuse_send_data_iov_fallback(struct fuse_ll *f, + struct fuse_chan *ch, + struct iovec *iov, + int iov_count, + struct fuse_bufvec *buf, + size_t len) { - struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len); - void *mbuf; int res; + void *mbuf; + struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len); /* Optimize common case */ if (buf->count == 1 && buf->idx == 0 && buf->off == 0 && - !(buf->buf[0].flags & FUSE_BUF_IS_FD)) { - /* FIXME: also avoid memory copy if there are multiple buffers - but none of them contain an fd */ - - iov[iov_count].iov_base = buf->buf[0].mem; - iov[iov_count].iov_len = len; - iov_count++; - return fuse_send_msg(f, ch, iov, iov_count); - } + !(buf->buf[0].flags & FUSE_BUF_IS_FD)) + { + /* FIXME: also avoid memory copy if there are multiple buffers + but none of them contain an fd */ + + iov[iov_count].iov_base = buf->buf[0].mem; + iov[iov_count].iov_len = len; + iov_count++; + + return fuse_send_msg(f, ch, iov, iov_count); + } res = posix_memalign(&mbuf, pagesize, len); if (res != 0) @@ -450,10 +536,11 @@ static int fuse_send_data_iov_fallback(struct fuse_ll *f, struct fuse_chan *ch, mem_buf.buf[0].mem = mbuf; res = fuse_buf_copy(&mem_buf, buf, 0); - if (res < 0) { - free(mbuf); - return -res; - } + if (res < 0) + { + free(mbuf); + return -res; + } len = res; iov[iov_count].iov_base = mbuf; @@ -465,13 +552,16 @@ static int fuse_send_data_iov_fallback(struct fuse_ll *f, struct fuse_chan *ch, return res; } -struct fuse_ll_pipe { +struct fuse_ll_pipe +{ size_t size; int can_grow; int pipe[2]; }; -static void fuse_ll_pipe_free(struct fuse_ll_pipe *llp) +static +void +fuse_ll_pipe_free(struct fuse_ll_pipe *llp) { close(llp->pipe[0]); close(llp->pipe[1]); @@ -479,72 +569,94 @@ static void fuse_ll_pipe_free(struct fuse_ll_pipe *llp) } #ifdef HAVE_SPLICE -static struct fuse_ll_pipe *fuse_ll_get_pipe(struct fuse_ll *f) +static +struct fuse_ll_pipe* +fuse_ll_get_pipe(struct fuse_ll *f) { struct fuse_ll_pipe *llp = pthread_getspecific(f->pipe_key); - if (llp == NULL) { - int res; - - llp = malloc(sizeof(struct fuse_ll_pipe)); - if (llp == NULL) - return NULL; + if (llp == NULL) + { + int res; + + llp = malloc(sizeof(struct fuse_ll_pipe)); + if (llp == NULL) + return NULL; + + res = pipe(llp->pipe); + if (res == -1) + { + free(llp); + return NULL; + } + + if (fcntl(llp->pipe[0], F_SETFL, O_NONBLOCK) == -1 || + fcntl(llp->pipe[1], F_SETFL, O_NONBLOCK) == -1) + { + close(llp->pipe[0]); + close(llp->pipe[1]); + free(llp); + return NULL; + } - res = pipe(llp->pipe); - if (res == -1) { - free(llp); - return NULL; - } + /* + *the default size is 16 pages on linux + */ + llp->size = pagesize * 16; + llp->can_grow = 1; - if (fcntl(llp->pipe[0], F_SETFL, O_NONBLOCK) == -1 || - fcntl(llp->pipe[1], F_SETFL, O_NONBLOCK) == -1) { - close(llp->pipe[0]); - close(llp->pipe[1]); - free(llp); - return NULL; + pthread_setspecific(f->pipe_key, llp); } - /* - *the default size is 16 pages on linux - */ - llp->size = pagesize * 16; - llp->can_grow = 1; - - pthread_setspecific(f->pipe_key, llp); - } - return llp; } #endif -static void fuse_ll_clear_pipe(struct fuse_ll *f) +static +void +fuse_ll_clear_pipe(struct fuse_ll *f) { struct fuse_ll_pipe *llp = pthread_getspecific(f->pipe_key); - if (llp) { - pthread_setspecific(f->pipe_key, NULL); - fuse_ll_pipe_free(llp); - } + + if (llp) + { + pthread_setspecific(f->pipe_key, NULL); + fuse_ll_pipe_free(llp); + } } #if defined(HAVE_SPLICE) && defined(HAVE_VMSPLICE) -static int read_back(int fd, char *buf, size_t len) +static +int +read_back(int fd, + char *buf, + size_t len) { int res; res = read(fd, buf, len); - if (res == -1) { - fprintf(stderr, "fuse: internal error: failed to read back from pipe: %s\n", strerror(errno)); - return -EIO; - } - if (res != len) { - fprintf(stderr, "fuse: internal error: short read back from pipe: %i from %zi\n", res, len); - return -EIO; - } + if (res == -1) + { + fprintf(stderr, "fuse: internal error: failed to read back from pipe: %s\n", strerror(errno)); + return -EIO; + } + + if (res != len) + { + fprintf(stderr, "fuse: internal error: short read back from pipe: %i from %zi\n", res, len); + return -EIO; + } + return 0; } -static int fuse_send_data_iov(struct fuse_ll *f, struct fuse_chan *ch, - struct iovec *iov, int iov_count, - struct fuse_bufvec *buf, unsigned int flags) +static +int +fuse_send_data_iov(struct fuse_ll *f, + struct fuse_chan *ch, + struct iovec *iov, + int iov_count, + struct fuse_bufvec *buf, + unsigned int flags) { int res; size_t len = fuse_buf_size(buf); @@ -564,25 +676,26 @@ static int fuse_send_data_iov(struct fuse_ll *f, struct fuse_chan *ch, goto fallback; total_fd_size = 0; - for (idx = buf->idx; idx < buf->count; idx++) { - if (buf->buf[idx].flags & FUSE_BUF_IS_FD) { - total_fd_size = buf->buf[idx].size; - if (idx == buf->idx) - total_fd_size -= buf->off; + for (idx = buf->idx; idx < buf->count; idx++) + { + if (buf->buf[idx].flags & FUSE_BUF_IS_FD) + { + total_fd_size = buf->buf[idx].size; + if (idx == buf->idx) + total_fd_size -= buf->off; + } } - } + if (total_fd_size < 2 * pagesize) goto fallback; - if (f->conn.proto_minor < 14 || - !(f->conn.want & FUSE_CAP_SPLICE_WRITE)) + if (f->conn.proto_minor < 14 || !(f->conn.want & FUSE_CAP_SPLICE_WRITE)) goto fallback; llp = fuse_ll_get_pipe(f); if (llp == NULL) goto fallback; - headerlen = iov_length(iov, iov_count); out->len = headerlen + len; @@ -593,142 +706,157 @@ static int fuse_send_data_iov(struct fuse_ll *f, struct fuse_chan *ch, */ pipesize = pagesize * (iov_count + buf->count + 1) + out->len; - if (llp->size < pipesize) { - if (llp->can_grow) { - res = fcntl(llp->pipe[0], F_SETPIPE_SZ, pipesize); - if (res == -1) { - llp->can_grow = 0; + if (llp->size < pipesize) + { + if (llp->can_grow) + { + res = fcntl(llp->pipe[0], F_SETPIPE_SZ, pipesize); + if (res == -1) + { + llp->can_grow = 0; + goto fallback; + } + llp->size = res; + } + + if (llp->size < pipesize) goto fallback; - } - llp->size = res; } - if (llp->size < pipesize) - goto fallback; - } - res = vmsplice(llp->pipe[1], iov, iov_count, SPLICE_F_NONBLOCK); if (res == -1) goto fallback; - if (res != headerlen) { - res = -EIO; - fprintf(stderr, "fuse: short vmsplice to pipe: %u/%zu\n", res, - headerlen); - goto clear_pipe; - } + if (res != headerlen) + { + res = -EIO; + fprintf(stderr, "fuse: short vmsplice to pipe: %u/%zu\n", res, + headerlen); + goto clear_pipe; + } pipe_buf.buf[0].flags = FUSE_BUF_IS_FD; pipe_buf.buf[0].fd = llp->pipe[1]; res = fuse_buf_copy(&pipe_buf, buf, FUSE_BUF_FORCE_SPLICE | FUSE_BUF_SPLICE_NONBLOCK); - if (res < 0) { - if (res == -EAGAIN || res == -EINVAL) { - /* - * Should only get EAGAIN on kernels with - * broken SPLICE_F_NONBLOCK support (<= - * 2.6.35) where this error or a short read is - * returned even if the pipe itself is not - * full - * - * EINVAL might mean that splice can't handle - * this combination of input and output. - */ - if (res == -EAGAIN) - f->broken_splice_nonblock = 1; - - pthread_setspecific(f->pipe_key, NULL); - fuse_ll_pipe_free(llp); - goto fallback; - } - res = -res; - goto clear_pipe; - } - - if (res != 0 && res < len) { - struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len); - void *mbuf; - size_t now_len = res; - /* - * For regular files a short count is either - * 1) due to EOF, or - * 2) because of broken SPLICE_F_NONBLOCK (see above) - * - * For other inputs it's possible that we overflowed - * the pipe because of small buffer fragments. - */ - - res = posix_memalign(&mbuf, pagesize, len); - if (res != 0) + if (res < 0) + { + if (res == -EAGAIN || res == -EINVAL) + { + /* + * Should only get EAGAIN on kernels with + * broken SPLICE_F_NONBLOCK support (<= + * 2.6.35) where this error or a short read is + * returned even if the pipe itself is not + * full + * + * EINVAL might mean that splice can't handle + * this combination of input and output. + */ + if (res == -EAGAIN) + f->broken_splice_nonblock = 1; + + pthread_setspecific(f->pipe_key, NULL); + fuse_ll_pipe_free(llp); + goto fallback; + } + res = -res; goto clear_pipe; + } - mem_buf.buf[0].mem = mbuf; - mem_buf.off = now_len; - res = fuse_buf_copy(&mem_buf, buf, 0); - if (res > 0) { - char *tmpbuf; - size_t extra_len = res; + if (res != 0 && res < len) + { + struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len); + void *mbuf; + size_t now_len = res; /* - * Trickiest case: got more data. Need to get - * back the data from the pipe and then fall - * back to regular write. + * For regular files a short count is either + * 1) due to EOF, or + * 2) because of broken SPLICE_F_NONBLOCK (see above) + * + * For other inputs it's possible that we overflowed + * the pipe because of small buffer fragments. */ - tmpbuf = malloc(headerlen); - if (tmpbuf == NULL) { - free(mbuf); - res = ENOMEM; - goto clear_pipe; - } - res = read_back(llp->pipe[0], tmpbuf, headerlen); - free(tmpbuf); - if (res != 0) { - free(mbuf); - goto clear_pipe; - } - res = read_back(llp->pipe[0], mbuf, now_len); - if (res != 0) { - free(mbuf); + + res = posix_memalign(&mbuf, pagesize, len); + if (res != 0) goto clear_pipe; - } - len = now_len + extra_len; - iov[iov_count].iov_base = mbuf; - iov[iov_count].iov_len = len; - iov_count++; - res = fuse_send_msg(f, ch, iov, iov_count); + + mem_buf.buf[0].mem = mbuf; + mem_buf.off = now_len; + res = fuse_buf_copy(&mem_buf, buf, 0); + if (res > 0) + { + char *tmpbuf; + size_t extra_len = res; + /* + * Trickiest case: got more data. Need to get + * back the data from the pipe and then fall + * back to regular write. + */ + tmpbuf = malloc(headerlen); + if (tmpbuf == NULL) + { + free(mbuf); + res = ENOMEM; + goto clear_pipe; + } + res = read_back(llp->pipe[0], tmpbuf, headerlen); + free(tmpbuf); + if (res != 0) + { + free(mbuf); + goto clear_pipe; + } + res = read_back(llp->pipe[0], mbuf, now_len); + if (res != 0) + { + free(mbuf); + goto clear_pipe; + } + len = now_len + extra_len; + iov[iov_count].iov_base = mbuf; + iov[iov_count].iov_len = len; + iov_count++; + res = fuse_send_msg(f, ch, iov, iov_count); + free(mbuf); + return res; + } free(mbuf); - return res; + res = now_len; } - free(mbuf); - res = now_len; - } len = res; out->len = headerlen + len; - if (f->debug) { - fprintf(stderr, - " unique: %llu, success, outsize: %i (splice)\n", - (unsigned long long) out->unique, out->len); - } + if (f->debug) + { + fprintf(stderr, + " unique: %llu, success, outsize: %i (splice)\n", + (unsigned long long) out->unique, out->len); + } splice_flags = 0; if ((flags & FUSE_BUF_SPLICE_MOVE) && (f->conn.want & FUSE_CAP_SPLICE_MOVE)) splice_flags |= SPLICE_F_MOVE; - res = splice(llp->pipe[0], NULL, - fuse_chan_fd(ch), NULL, out->len, splice_flags); - if (res == -1) { - res = -errno; - perror("fuse: splice from pipe"); - goto clear_pipe; - } - if (res != out->len) { - res = -EIO; - fprintf(stderr, "fuse: short splice from pipe: %u/%u\n", - res, out->len); - goto clear_pipe; - } + res = splice(llp->pipe[0], NULL, fuse_chan_fd(ch), NULL, out->len, splice_flags); + if (res == -1) + { + res = -errno; + perror("fuse: splice from pipe"); + goto clear_pipe; + } + + if (res != out->len) + { + res = -EIO; + fprintf(stderr, "fuse: short splice from pipe: %u/%u\n", + res, out->len); + goto clear_pipe; + } + return 0; clear_pipe: @@ -739,9 +867,14 @@ static int fuse_send_data_iov(struct fuse_ll *f, struct fuse_chan *ch, return fuse_send_data_iov_fallback(f, ch, iov, iov_count, buf, len); } #else -static int fuse_send_data_iov(struct fuse_ll *f, struct fuse_chan *ch, - struct iovec *iov, int iov_count, - struct fuse_bufvec *buf, unsigned int flags) +static +int +fuse_send_data_iov(struct fuse_ll *f, + struct fuse_chan *ch, + struct iovec *iov, + int iov_count, + struct fuse_bufvec *buf, + unsigned int flags) { size_t len = fuse_buf_size(buf); (void) flags; @@ -750,8 +883,10 @@ static int fuse_send_data_iov(struct fuse_ll *f, struct fuse_chan *ch, } #endif -int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv, - enum fuse_buf_copy_flags flags) +int +fuse_reply_data(fuse_req_t req, + struct fuse_bufvec *bufv, + enum fuse_buf_copy_flags flags) { struct iovec iov[2]; struct fuse_out_header out; @@ -764,15 +899,20 @@ int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv, out.error = 0; res = fuse_send_data_iov(req->f, req->ch, iov, 1, bufv, flags); - if (res <= 0) { - fuse_free_req(req); - return res; - } else { - return fuse_reply_err(req, res); - } + if (res <= 0) + { + fuse_free_req(req); + return res; + } + else + { + return fuse_reply_err(req, res); + } } -int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf) +int +fuse_reply_statfs(fuse_req_t req, + const struct statvfs *stbuf) { struct fuse_statfs_out arg; size_t size = req->f->conn.proto_minor < 4 ? @@ -784,7 +924,9 @@ int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf) return send_reply_ok(req, &arg, size); } -int fuse_reply_xattr(fuse_req_t req, size_t count) +int +fuse_reply_xattr(fuse_req_t req, + size_t count) { struct fuse_getxattr_out arg; @@ -794,24 +936,30 @@ int fuse_reply_xattr(fuse_req_t req, size_t count) return send_reply_ok(req, &arg, sizeof(arg)); } -int fuse_reply_lock(fuse_req_t req, const struct flock *lock) +int +fuse_reply_lock(fuse_req_t req, + const struct flock *lock) { struct fuse_lk_out arg; memset(&arg, 0, sizeof(arg)); arg.lk.type = lock->l_type; - if (lock->l_type != F_UNLCK) { - arg.lk.start = lock->l_start; - if (lock->l_len == 0) - arg.lk.end = OFFSET_MAX; - else - arg.lk.end = lock->l_start + lock->l_len - 1; - } + if (lock->l_type != F_UNLCK) + { + arg.lk.start = lock->l_start; + if (lock->l_len == 0) + arg.lk.end = OFFSET_MAX; + else + arg.lk.end = lock->l_start + lock->l_len - 1; + } arg.lk.pid = lock->l_pid; + return send_reply_ok(req, &arg, sizeof(arg)); } -int fuse_reply_bmap(fuse_req_t req, uint64_t idx) +int +fuse_reply_bmap(fuse_req_t req, + uint64_t idx) { struct fuse_bmap_out arg; @@ -821,8 +969,10 @@ int fuse_reply_bmap(fuse_req_t req, uint64_t idx) return send_reply_ok(req, &arg, sizeof(arg)); } -static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(const struct iovec *iov, - size_t count) +static +struct fuse_ioctl_iovec* +fuse_ioctl_iovec_copy(const struct iovec *iov, + size_t count) { struct fuse_ioctl_iovec *fiov; size_t i; @@ -831,17 +981,21 @@ static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(const struct iovec *iov, if (!fiov) return NULL; - for (i = 0; i < count; i++) { - fiov[i].base = (uintptr_t) iov[i].iov_base; - fiov[i].len = iov[i].iov_len; - } + for (i = 0; i < count; i++) + { + fiov[i].base = (uintptr_t) iov[i].iov_base; + fiov[i].len = iov[i].iov_len; + } return fiov; } -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) +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) { struct fuse_ioctl_out arg; struct fuse_ioctl_iovec *in_fiov = NULL; @@ -858,44 +1012,52 @@ int fuse_reply_ioctl_retry(fuse_req_t req, iov[count].iov_len = sizeof(arg); count++; - if (req->f->conn.proto_minor < 16) { - if (in_count) { - iov[count].iov_base = (void *)in_iov; - iov[count].iov_len = sizeof(in_iov[0]) * in_count; - count++; - } - - if (out_count) { - iov[count].iov_base = (void *)out_iov; - iov[count].iov_len = sizeof(out_iov[0]) * out_count; - count++; - } - } else { - /* Can't handle non-compat 64bit ioctls on 32bit */ - if (sizeof(void *) == 4 && req->ioctl_64bit) { - res = fuse_reply_err(req, EINVAL); - goto out; - } - - if (in_count) { - in_fiov = fuse_ioctl_iovec_copy(in_iov, in_count); - if (!in_fiov) - goto enomem; - - iov[count].iov_base = (void *)in_fiov; - iov[count].iov_len = sizeof(in_fiov[0]) * in_count; - count++; + if (req->f->conn.proto_minor < 16) + { + if (in_count) + { + iov[count].iov_base = (void *)in_iov; + iov[count].iov_len = sizeof(in_iov[0]) * in_count; + count++; + } + + if (out_count) + { + iov[count].iov_base = (void *)out_iov; + iov[count].iov_len = sizeof(out_iov[0]) * out_count; + count++; + } } - if (out_count) { - out_fiov = fuse_ioctl_iovec_copy(out_iov, out_count); - if (!out_fiov) - goto enomem; - - iov[count].iov_base = (void *)out_fiov; - iov[count].iov_len = sizeof(out_fiov[0]) * out_count; - count++; + else + { + /* Can't handle non-compat 64bit ioctls on 32bit */ + if (sizeof(void *) == 4 && req->ioctl_64bit) + { + res = fuse_reply_err(req, EINVAL); + goto out; + } + + if (in_count) + { + in_fiov = fuse_ioctl_iovec_copy(in_iov, in_count); + if (!in_fiov) + goto enomem; + + iov[count].iov_base = (void *)in_fiov; + iov[count].iov_len = sizeof(in_fiov[0]) * in_count; + count++; + } + if (out_count) + { + out_fiov = fuse_ioctl_iovec_copy(out_iov, out_count); + if (!out_fiov) + goto enomem; + + iov[count].iov_base = (void *)out_fiov; + iov[count].iov_len = sizeof(out_fiov[0]) * out_count; + count++; + } } - } res = send_reply_iov(req, 0, iov, count); out: @@ -909,7 +1071,11 @@ int fuse_reply_ioctl_retry(fuse_req_t req, goto out; } -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) { int count; struct iovec iov[3]; @@ -935,8 +1101,11 @@ int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, uint32_t size) return send_reply_iov(req, 0, iov, count); } -int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, - int count) +int +fuse_reply_ioctl_iov(fuse_req_t req, + int result, + const struct iovec *iov, + int count) { struct iovec *padded_iov; struct fuse_ioctl_out arg; @@ -959,7 +1128,9 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, return res; } -int fuse_reply_poll(fuse_req_t req, unsigned revents) +int +fuse_reply_poll(fuse_req_t req, + unsigned revents) { struct fuse_poll_out arg; @@ -969,7 +1140,11 @@ int fuse_reply_poll(fuse_req_t req, unsigned revents) return send_reply_ok(req, &arg, sizeof(arg)); } -static void do_lookup(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_lookup(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { char *name = (char *) inarg; @@ -979,7 +1154,11 @@ static void do_lookup(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_forget(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_forget(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_forget_in *arg = (struct fuse_forget_in *) inarg; @@ -989,8 +1168,11 @@ static void do_forget(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_none(req); } -static void do_batch_forget(fuse_req_t req, fuse_ino_t nodeid, - const void *inarg) +static +void +do_batch_forget(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_batch_forget_in *arg = (void *) inarg; struct fuse_forget_one *param = (void *) PARAM(arg); @@ -998,45 +1180,56 @@ static void do_batch_forget(fuse_req_t req, fuse_ino_t nodeid, (void) nodeid; - if (req->f->op.forget_multi) { - req->f->op.forget_multi(req, arg->count, - (struct fuse_forget_data *) param); - } else if (req->f->op.forget) { - for (i = 0; i < arg->count; i++) { - struct fuse_forget_one *forget = ¶m[i]; - struct fuse_req *dummy_req; - - dummy_req = fuse_ll_alloc_req(req->f); - if (dummy_req == NULL) - break; - - dummy_req->unique = req->unique; - dummy_req->ctx = req->ctx; - dummy_req->ch = NULL; - - req->f->op.forget(dummy_req, forget->nodeid, - forget->nlookup); + if (req->f->op.forget_multi) + { + req->f->op.forget_multi(req, arg->count, + (struct fuse_forget_data *) param); + } + else if (req->f->op.forget) + { + for (i = 0; i < arg->count; i++) + { + struct fuse_forget_one *forget = ¶m[i]; + struct fuse_req *dummy_req; + + dummy_req = fuse_ll_alloc_req(req->f); + if (dummy_req == NULL) + break; + + dummy_req->unique = req->unique; + dummy_req->ctx = req->ctx; + dummy_req->ch = NULL; + + req->f->op.forget(dummy_req, forget->nodeid, forget->nlookup); + } + fuse_reply_none(req); + } + else + { + fuse_reply_none(req); } - fuse_reply_none(req); - } else { - fuse_reply_none(req); - } } -static void do_getattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_getattr(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { - struct fuse_file_info *fip = NULL; - struct fuse_file_info fi; + fuse_file_info_t *fip = NULL; + fuse_file_info_t fi; - if (req->f->conn.proto_minor >= 9) { - struct fuse_getattr_in *arg = (struct fuse_getattr_in *) inarg; - - if (arg->getattr_flags & FUSE_GETATTR_FH) { - memset(&fi, 0, sizeof(fi)); - fi.fh = arg->fh; - fip = &fi; + if (req->f->conn.proto_minor >= 9) + { + struct fuse_getattr_in *arg = (struct fuse_getattr_in *) inarg; + + if (arg->getattr_flags & FUSE_GETATTR_FH) + { + memset(&fi, 0, sizeof(fi)); + fi.fh = arg->fh; + fip = &fi; + } } - } if (req->f->op.getattr) req->f->op.getattr(req, nodeid, fip); @@ -1051,8 +1244,8 @@ do_setattr(fuse_req_t req_, const void *inarg_) { struct stat stbuf; - struct fuse_file_info *fi; - struct fuse_file_info fi_store; + fuse_file_info_t *fi; + fuse_file_info_t fi_store; struct fuse_setattr_in *arg; if(req_->f->op.setattr == NULL) @@ -1086,7 +1279,11 @@ do_setattr(fuse_req_t req_, req_->f->op.setattr(req_,nodeid_,&stbuf,arg->valid,fi); } -static void do_access(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_access(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_access_in *arg = (struct fuse_access_in *) inarg; @@ -1096,7 +1293,11 @@ static void do_access(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_readlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_readlink(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { (void) inarg; @@ -1106,7 +1307,11 @@ static void do_readlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_mknod(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_mknod(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_mknod_in *arg = (struct fuse_mknod_in *) inarg; char *name = PARAM(arg); @@ -1122,7 +1327,11 @@ static void do_mknod(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_mkdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_mkdir(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_mkdir_in *arg = (struct fuse_mkdir_in *) inarg; @@ -1135,7 +1344,11 @@ static void do_mkdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_unlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_unlink(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { char *name = (char *) inarg; @@ -1145,7 +1358,11 @@ static void do_unlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_rmdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_rmdir(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { char *name = (char *) inarg; @@ -1155,7 +1372,11 @@ static void do_rmdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_symlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_symlink(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { char *name = (char *) inarg; char *linkname = ((char *) inarg) + strlen((char *) inarg) + 1; @@ -1166,7 +1387,11 @@ static void do_symlink(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_rename(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_rename(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_rename_in *arg = (struct fuse_rename_in *) inarg; char *oldname = PARAM(arg); @@ -1178,7 +1403,11 @@ static void do_rename(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_link(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_link(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_link_in *arg = (struct fuse_link_in *) inarg; @@ -1188,31 +1417,43 @@ static void do_link(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_create(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_create(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_create_in *arg = (struct fuse_create_in *) inarg; - if (req->f->op.create) { - struct fuse_file_info fi; - char *name = PARAM(arg); + if (req->f->op.create) + { + fuse_file_info_t fi; + char *name = PARAM(arg); - memset(&fi, 0, sizeof(fi)); - fi.flags = arg->flags; + memset(&fi, 0, sizeof(fi)); + fi.flags = arg->flags; - if (req->f->conn.proto_minor >= 12) - req->ctx.umask = arg->umask; - else - name = (char *) inarg + sizeof(struct fuse_open_in); + if (req->f->conn.proto_minor >= 12) + req->ctx.umask = arg->umask; + else + name = (char *) inarg + sizeof(struct fuse_open_in); - req->f->op.create(req, nodeid, name, arg->mode, &fi); - } else - fuse_reply_err(req, ENOSYS); + req->f->op.create(req, nodeid, name, arg->mode, &fi); + } + else + { + fuse_reply_err(req, ENOSYS); + } } -static void do_open(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_open(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_open_in *arg = (struct fuse_open_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; @@ -1223,51 +1464,71 @@ static void do_open(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_open(req, &fi); } -static void do_read(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_read(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_read_in *arg = (struct fuse_read_in *) inarg; - if (req->f->op.read) { - struct fuse_file_info fi; + if (req->f->op.read) + { + fuse_file_info_t fi; - memset(&fi, 0, sizeof(fi)); - fi.fh = arg->fh; - if (req->f->conn.proto_minor >= 9) { - fi.lock_owner = arg->lock_owner; - fi.flags = arg->flags; + memset(&fi, 0, sizeof(fi)); + fi.fh = arg->fh; + if (req->f->conn.proto_minor >= 9) + { + fi.lock_owner = arg->lock_owner; + fi.flags = arg->flags; + } + + req->f->op.read(req, nodeid, arg->size, arg->offset, &fi); + } + else + { + fuse_reply_err(req, ENOSYS); } - req->f->op.read(req, nodeid, arg->size, arg->offset, &fi); - } else - fuse_reply_err(req, ENOSYS); } -static void do_write(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_write(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_write_in *arg = (struct fuse_write_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; char *param; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.writepage = arg->write_flags & 1; - if (req->f->conn.proto_minor < 9) { - param = ((char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE; - } else { - fi.lock_owner = arg->lock_owner; - fi.flags = arg->flags; - param = PARAM(arg); - } + if (req->f->conn.proto_minor < 9) + { + param = ((char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE; + } + else + { + fi.lock_owner = arg->lock_owner; + fi.flags = arg->flags; + param = PARAM(arg); + } if (req->f->op.write) - req->f->op.write(req, nodeid, param, arg->size, - arg->offset, &fi); + req->f->op.write(req, nodeid, param, arg->size, arg->offset, &fi); else fuse_reply_err(req, ENOSYS); } -static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg, - const struct fuse_buf *ibuf) +static +void +do_write_buf(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg, + const struct fuse_buf *ibuf) { struct fuse_ll *f = req->f; struct fuse_bufvec bufv = { @@ -1275,31 +1536,36 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg, .count = 1, }; struct fuse_write_in *arg = (struct fuse_write_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.writepage = arg->write_flags & 1; - if (req->f->conn.proto_minor < 9) { - bufv.buf[0].mem = ((char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE; - bufv.buf[0].size -= sizeof(struct fuse_in_header) + - FUSE_COMPAT_WRITE_IN_SIZE; - assert(!(bufv.buf[0].flags & FUSE_BUF_IS_FD)); - } else { - fi.lock_owner = arg->lock_owner; - fi.flags = arg->flags; - if (!(bufv.buf[0].flags & FUSE_BUF_IS_FD)) - bufv.buf[0].mem = PARAM(arg); + if (req->f->conn.proto_minor < 9) + { + bufv.buf[0].mem = ((char *) arg) + FUSE_COMPAT_WRITE_IN_SIZE; + bufv.buf[0].size -= sizeof(struct fuse_in_header) + + FUSE_COMPAT_WRITE_IN_SIZE; + assert(!(bufv.buf[0].flags & FUSE_BUF_IS_FD)); + } + else + { + fi.lock_owner = arg->lock_owner; + fi.flags = arg->flags; + if (!(bufv.buf[0].flags & FUSE_BUF_IS_FD)) + bufv.buf[0].mem = PARAM(arg); - bufv.buf[0].size -= sizeof(struct fuse_in_header) + - sizeof(struct fuse_write_in); - } - if (bufv.buf[0].size < arg->size) { - fprintf(stderr, "fuse: do_write_buf: buffer size too small\n"); - fuse_reply_err(req, EIO); - goto out; - } + bufv.buf[0].size -= sizeof(struct fuse_in_header) + + sizeof(struct fuse_write_in); + } + + if (bufv.buf[0].size < arg->size) + { + fprintf(stderr, "fuse: do_write_buf: buffer size too small\n"); + fuse_reply_err(req, EIO); + goto out; + } bufv.buf[0].size = arg->size; req->f->op.write_buf(req, nodeid, &bufv, arg->offset, &fi); @@ -1310,10 +1576,14 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg, fuse_ll_clear_pipe(f); } -static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_flush(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_flush_in *arg = (struct fuse_flush_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; @@ -1327,22 +1597,29 @@ static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_release(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_release(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_release_in *arg = (struct fuse_release_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; fi.fh = arg->fh; - if (req->f->conn.proto_minor >= 8) { - fi.flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0; - fi.lock_owner = arg->lock_owner; - } - if (arg->release_flags & FUSE_RELEASE_FLOCK_UNLOCK) { - fi.flock_release = 1; - fi.lock_owner = arg->lock_owner; - } + if (req->f->conn.proto_minor >= 8) + { + fi.flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0; + fi.lock_owner = arg->lock_owner; + } + + if (arg->release_flags & FUSE_RELEASE_FLOCK_UNLOCK) + { + fi.flock_release = 1; + fi.lock_owner = arg->lock_owner; + } if (req->f->op.release) req->f->op.release(req, nodeid, &fi); @@ -1350,10 +1627,14 @@ static void do_release(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, 0); } -static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_fsync(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; @@ -1364,10 +1645,14 @@ static void do_fsync(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_opendir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_opendir(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_open_in *arg = (struct fuse_open_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; @@ -1378,10 +1663,14 @@ static void do_opendir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_open(req, &fi); } -static void do_readdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_readdir(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_read_in *arg = (struct fuse_read_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; @@ -1399,7 +1688,7 @@ do_readdir_plus(fuse_req_t req_, const void *inarg_) { const struct fuse_read_in *arg; - struct fuse_file_info ffi = {0}; + fuse_file_info_t ffi = {0}; arg = (struct fuse_read_in*)inarg_; ffi.fh = arg->fh; @@ -1410,10 +1699,14 @@ do_readdir_plus(fuse_req_t req_, fuse_reply_err(req_,ENOSYS); } -static void do_releasedir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_releasedir(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_release_in *arg = (struct fuse_release_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.flags = arg->flags; @@ -1425,10 +1718,14 @@ static void do_releasedir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, 0); } -static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_fsyncdir(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; @@ -1439,38 +1736,53 @@ static void do_fsyncdir(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_statfs(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_statfs(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { (void) nodeid; (void) inarg; if (req->f->op.statfs) - req->f->op.statfs(req, nodeid); - else { - struct statvfs buf = { - .f_namemax = 255, - .f_bsize = 512, - }; - fuse_reply_statfs(req, &buf); - } + { + req->f->op.statfs(req, nodeid); + } + else + { + struct statvfs buf = {0}; + + buf.f_namemax = 255; + buf.f_bsize = 512; + + fuse_reply_statfs(req, &buf); + } } -static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_setxattr(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_setxattr_in *arg = (struct fuse_setxattr_in *) inarg; char *name = PARAM(arg); char *value = name + strlen(name) + 1; if (req->f->op.setxattr) - req->f->op.setxattr(req, nodeid, name, value, arg->size, - arg->flags); + req->f->op.setxattr(req, nodeid, name, value, arg->size, arg->flags); else fuse_reply_err(req, ENOSYS); } -static void do_getxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_getxattr(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { - struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inarg; + struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *)inarg; if (req->f->op.getxattr) req->f->op.getxattr(req, nodeid, PARAM(arg), arg->size); @@ -1478,7 +1790,11 @@ static void do_getxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_listxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_listxattr(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inarg; @@ -1488,7 +1804,11 @@ static void do_listxattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_removexattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_removexattr(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { char *name = (char *) inarg; @@ -1498,8 +1818,10 @@ static void do_removexattr(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void convert_fuse_file_lock(struct fuse_file_lock *fl, - struct flock *flock) +static +void +convert_fuse_file_lock(struct fuse_file_lock *fl, + struct flock *flock) { memset(flock, 0, sizeof(struct flock)); flock->l_type = fl->type; @@ -1512,10 +1834,14 @@ static void convert_fuse_file_lock(struct fuse_file_lock *fl, flock->l_pid = fl->pid; } -static void do_getlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_getlk(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_lk_in *arg = (struct fuse_lk_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; struct flock flock; memset(&fi, 0, sizeof(fi)); @@ -1529,97 +1855,125 @@ static void do_getlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_setlk_common(fuse_req_t req, fuse_ino_t nodeid, - const void *inarg, int sleep) +static +void +do_setlk_common(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg, + int sleep) { struct fuse_lk_in *arg = (struct fuse_lk_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; struct flock flock; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; fi.lock_owner = arg->owner; - if (arg->lk_flags & FUSE_LK_FLOCK) { - int op = 0; - - switch (arg->lk.type) { - case F_RDLCK: - op = LOCK_SH; - break; - case F_WRLCK: - op = LOCK_EX; - break; - case F_UNLCK: - op = LOCK_UN; - break; + if (arg->lk_flags & FUSE_LK_FLOCK) + { + int op = 0; + + switch (arg->lk.type) + { + case F_RDLCK: + op = LOCK_SH; + break; + case F_WRLCK: + op = LOCK_EX; + break; + case F_UNLCK: + op = LOCK_UN; + break; + } + + if (!sleep) + op |= LOCK_NB; + + if (req->f->op.flock) + req->f->op.flock(req, nodeid, &fi, op); + else + fuse_reply_err(req, ENOSYS); + } + else + { + convert_fuse_file_lock(&arg->lk, &flock); + if (req->f->op.setlk) + req->f->op.setlk(req, nodeid, &fi, &flock, sleep); + else + fuse_reply_err(req, ENOSYS); } - if (!sleep) - op |= LOCK_NB; - - if (req->f->op.flock) - req->f->op.flock(req, nodeid, &fi, op); - else - fuse_reply_err(req, ENOSYS); - } else { - convert_fuse_file_lock(&arg->lk, &flock); - if (req->f->op.setlk) - req->f->op.setlk(req, nodeid, &fi, &flock, sleep); - else - fuse_reply_err(req, ENOSYS); - } } -static void do_setlk(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_setlk(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { do_setlk_common(req, nodeid, inarg, 0); } -static void do_setlkw(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_setlkw(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { do_setlk_common(req, nodeid, inarg, 1); } -static int find_interrupted(struct fuse_ll *f, struct fuse_req *req) +static +int +find_interrupted(struct fuse_ll *f, + struct fuse_req *req) { struct fuse_req *curr; - for (curr = f->list.next; curr != &f->list; curr = curr->next) { - if (curr->unique == req->u.i.unique) { - fuse_interrupt_func_t func; - void *data; - - curr->ctr++; - pthread_mutex_unlock(&f->lock); - - /* Ugh, ugly locking */ - pthread_mutex_lock(&curr->lock); - pthread_mutex_lock(&f->lock); - curr->interrupted = 1; - func = curr->u.ni.func; - data = curr->u.ni.data; - pthread_mutex_unlock(&f->lock); - if (func) - func(curr, data); - pthread_mutex_unlock(&curr->lock); - - pthread_mutex_lock(&f->lock); - curr->ctr--; - if (!curr->ctr) - destroy_req(curr); - - return 1; + for (curr = f->list.next; curr != &f->list; curr = curr->next) + { + if (curr->unique == req->u.i.unique) + { + fuse_interrupt_func_t func; + void *data; + + curr->ctr++; + pthread_mutex_unlock(&f->lock); + + /* Ugh, ugly locking */ + pthread_mutex_lock(&curr->lock); + pthread_mutex_lock(&f->lock); + curr->interrupted = 1; + func = curr->u.ni.func; + data = curr->u.ni.data; + pthread_mutex_unlock(&f->lock); + if (func) + func(curr, data); + pthread_mutex_unlock(&curr->lock); + + pthread_mutex_lock(&f->lock); + curr->ctr--; + if (!curr->ctr) + destroy_req(curr); + + return 1; + } } - } + for (curr = f->interrupts.next; curr != &f->interrupts; - curr = curr->next) { - if (curr->u.i.unique == req->u.i.unique) - return 1; - } + curr = curr->next) + { + if (curr->u.i.unique == req->u.i.unique) + return 1; + } return 0; } -static void do_interrupt(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_interrupt(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_interrupt_in *arg = (struct fuse_interrupt_in *) inarg; struct fuse_ll *f = req->f; @@ -1632,36 +1986,51 @@ static void do_interrupt(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) req->u.i.unique = arg->unique; pthread_mutex_lock(&f->lock); - if (find_interrupted(f, req)) + if(find_interrupted(f, req)) destroy_req(req); else list_add_req(req, &f->interrupts); pthread_mutex_unlock(&f->lock); } -static struct fuse_req *check_interrupt(struct fuse_ll *f, struct fuse_req *req) +static +struct +fuse_req* +check_interrupt(struct fuse_ll *f, + struct fuse_req *req) { struct fuse_req *curr; for (curr = f->interrupts.next; curr != &f->interrupts; - curr = curr->next) { - if (curr->u.i.unique == req->unique) { - req->interrupted = 1; + curr = curr->next) + { + if (curr->u.i.unique == req->unique) + { + req->interrupted = 1; + list_del_req(curr); + free(curr); + return NULL; + } + } + + curr = f->interrupts.next; + if (curr != &f->interrupts) + { list_del_req(curr); - free(curr); + list_init_req(curr); + return curr; + } + else + { return NULL; } - } - curr = f->interrupts.next; - if (curr != &f->interrupts) { - list_del_req(curr); - list_init_req(curr); - return curr; - } else - return NULL; } -static void do_bmap(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_bmap(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_bmap_in *arg = (struct fuse_bmap_in *) inarg; @@ -1671,26 +2040,31 @@ static void do_bmap(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_ioctl(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_ioctl(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_ioctl_in *arg = (struct fuse_ioctl_in *) inarg; unsigned int flags = arg->flags; void *in_buf = arg->in_size ? PARAM(arg) : NULL; - struct fuse_file_info fi; + fuse_file_info_t fi; - if (flags & FUSE_IOCTL_DIR && - !(req->f->conn.want & FUSE_CAP_IOCTL_DIR)) { - fuse_reply_err(req, ENOTTY); - return; - } + if (flags & FUSE_IOCTL_DIR && !(req->f->conn.want & FUSE_CAP_IOCTL_DIR)) + { + fuse_reply_err(req, ENOTTY); + return; + } memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; - if (sizeof(void *) == 4 && req->f->conn.proto_minor >= 16 && - !(flags & FUSE_IOCTL_32BIT)) { - req->ioctl_64bit = 1; - } + if(sizeof(void *) == 4 && req->f->conn.proto_minor >= 16 && + !(flags & FUSE_IOCTL_32BIT)) + { + req->ioctl_64bit = 1; + } if (req->f->op.ioctl) req->f->op.ioctl(req, nodeid, (unsigned long)arg->cmd, @@ -1700,43 +2074,56 @@ static void do_ioctl(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -void fuse_pollhandle_destroy(struct fuse_pollhandle *ph) +void +fuse_pollhandle_destroy(fuse_pollhandle_t *ph) { free(ph); } -static void do_poll(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_poll(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_poll_in *arg = (struct fuse_poll_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; - if (req->f->op.poll) { - struct fuse_pollhandle *ph = NULL; - - if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) { - ph = malloc(sizeof(struct fuse_pollhandle)); - if (ph == NULL) { - fuse_reply_err(req, ENOMEM); - return; - } - ph->kh = arg->kh; - ph->ch = req->ch; - ph->f = req->f; + if (req->f->op.poll) + { + fuse_pollhandle_t *ph = NULL; + + if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) + { + ph = malloc(sizeof(fuse_pollhandle_t)); + if (ph == NULL) { + fuse_reply_err(req, ENOMEM); + return; + } + ph->kh = arg->kh; + ph->ch = req->ch; + ph->f = req->f; + } + + req->f->op.poll(req, nodeid, &fi, ph); + } + else + { + fuse_reply_err(req, ENOSYS); } - - req->f->op.poll(req, nodeid, &fi, ph); - } else { - fuse_reply_err(req, ENOSYS); - } } -static void do_fallocate(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_fallocate(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_fallocate_in *arg = (struct fuse_fallocate_in *) inarg; - struct fuse_file_info fi; + fuse_file_info_t fi; memset(&fi, 0, sizeof(fi)); fi.fh = arg->fh; @@ -1747,7 +2134,11 @@ static void do_fallocate(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fuse_reply_err(req, ENOSYS); } -static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_init(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_init_in *arg = (struct fuse_init_in *) inarg; struct fuse_init_out outarg; @@ -1755,14 +2146,17 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) size_t bufsize = fuse_chan_bufsize(req->ch); (void) nodeid; - if (f->debug) { - fprintf(stderr, "INIT: %u.%u\n", arg->major, arg->minor); - if (arg->major == 7 && arg->minor >= 6) { - fprintf(stderr, "flags=0x%08x\n", arg->flags); - fprintf(stderr, "max_readahead=0x%08x\n", - arg->max_readahead); + if (f->debug) + { + fprintf(stderr, "INIT: %u.%u\n", arg->major, arg->minor); + if (arg->major == 7 && arg->minor >= 6) + { + fprintf(stderr, "flags=0x%08x\n", arg->flags); + fprintf(stderr, "max_readahead=0x%08x\n", + arg->max_readahead); + } } - } + f->conn.proto_major = arg->major; f->conn.proto_minor = arg->minor; f->conn.capable = 0; @@ -1774,71 +2168,78 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) outarg.minor = FUSE_KERNEL_MINOR_VERSION; outarg.max_pages = FUSE_DEFAULT_MAX_PAGES_PER_REQ; - if (arg->major < 7) { - fprintf(stderr, "fuse: unsupported protocol version: %u.%u\n", - arg->major, arg->minor); - fuse_reply_err(req, EPROTO); - return; - } + if (arg->major < 7) + { + fprintf(stderr, "fuse: unsupported protocol version: %u.%u\n", + arg->major, arg->minor); + fuse_reply_err(req, EPROTO); + return; + } - if (arg->major > 7) { - /* Wait for a second INIT request with a 7.X version */ - send_reply_ok(req, &outarg, sizeof(outarg)); - return; - } + if (arg->major > 7) + { + /* Wait for a second INIT request with a 7.X version */ + send_reply_ok(req, &outarg, sizeof(outarg)); + return; + } - if (arg->minor >= 6) { - if (arg->max_readahead < f->conn.max_readahead) - f->conn.max_readahead = arg->max_readahead; - if (arg->flags & FUSE_ASYNC_READ) - f->conn.capable |= FUSE_CAP_ASYNC_READ; - if (arg->flags & FUSE_POSIX_LOCKS) - f->conn.capable |= FUSE_CAP_POSIX_LOCKS; - if (arg->flags & FUSE_ATOMIC_O_TRUNC) - f->conn.capable |= FUSE_CAP_ATOMIC_O_TRUNC; - if (arg->flags & FUSE_EXPORT_SUPPORT) - f->conn.capable |= FUSE_CAP_EXPORT_SUPPORT; - if (arg->flags & FUSE_BIG_WRITES) - f->conn.capable |= FUSE_CAP_BIG_WRITES; - if (arg->flags & FUSE_DONT_MASK) - f->conn.capable |= FUSE_CAP_DONT_MASK; - if (arg->flags & FUSE_FLOCK_LOCKS) - f->conn.capable |= FUSE_CAP_FLOCK_LOCKS; - if (arg->flags & FUSE_POSIX_ACL) - f->conn.capable |= FUSE_CAP_POSIX_ACL; - if (arg->flags & FUSE_CACHE_SYMLINKS) - f->conn.capable |= FUSE_CAP_CACHE_SYMLINKS; - if (arg->flags & FUSE_ASYNC_DIO) - f->conn.capable |= FUSE_CAP_ASYNC_DIO; - if (arg->flags & FUSE_PARALLEL_DIROPS) - f->conn.capable |= FUSE_CAP_PARALLEL_DIROPS; - if (arg->flags & FUSE_MAX_PAGES) - f->conn.capable |= FUSE_CAP_MAX_PAGES; - if (arg->flags & FUSE_WRITEBACK_CACHE) - f->conn.capable |= FUSE_CAP_WRITEBACK_CACHE; - if (arg->flags & FUSE_DO_READDIRPLUS) - f->conn.capable |= FUSE_CAP_READDIR_PLUS; - if (arg->flags & FUSE_READDIRPLUS_AUTO) - f->conn.capable |= FUSE_CAP_READDIR_PLUS_AUTO; - } else { - f->conn.want &= ~FUSE_CAP_ASYNC_READ; - f->conn.max_readahead = 0; - } + if (arg->minor >= 6) + { + if (arg->max_readahead < f->conn.max_readahead) + f->conn.max_readahead = arg->max_readahead; + if (arg->flags & FUSE_ASYNC_READ) + f->conn.capable |= FUSE_CAP_ASYNC_READ; + if (arg->flags & FUSE_POSIX_LOCKS) + f->conn.capable |= FUSE_CAP_POSIX_LOCKS; + if (arg->flags & FUSE_ATOMIC_O_TRUNC) + f->conn.capable |= FUSE_CAP_ATOMIC_O_TRUNC; + if (arg->flags & FUSE_EXPORT_SUPPORT) + f->conn.capable |= FUSE_CAP_EXPORT_SUPPORT; + if (arg->flags & FUSE_BIG_WRITES) + f->conn.capable |= FUSE_CAP_BIG_WRITES; + if (arg->flags & FUSE_DONT_MASK) + f->conn.capable |= FUSE_CAP_DONT_MASK; + if (arg->flags & FUSE_FLOCK_LOCKS) + f->conn.capable |= FUSE_CAP_FLOCK_LOCKS; + if (arg->flags & FUSE_POSIX_ACL) + f->conn.capable |= FUSE_CAP_POSIX_ACL; + if (arg->flags & FUSE_CACHE_SYMLINKS) + f->conn.capable |= FUSE_CAP_CACHE_SYMLINKS; + if (arg->flags & FUSE_ASYNC_DIO) + f->conn.capable |= FUSE_CAP_ASYNC_DIO; + if (arg->flags & FUSE_PARALLEL_DIROPS) + f->conn.capable |= FUSE_CAP_PARALLEL_DIROPS; + if (arg->flags & FUSE_MAX_PAGES) + f->conn.capable |= FUSE_CAP_MAX_PAGES; + if (arg->flags & FUSE_WRITEBACK_CACHE) + f->conn.capable |= FUSE_CAP_WRITEBACK_CACHE; + if (arg->flags & FUSE_DO_READDIRPLUS) + f->conn.capable |= FUSE_CAP_READDIR_PLUS; + if (arg->flags & FUSE_READDIRPLUS_AUTO) + f->conn.capable |= FUSE_CAP_READDIR_PLUS_AUTO; + } + else + { + f->conn.want &= ~FUSE_CAP_ASYNC_READ; + f->conn.max_readahead = 0; + } - if (req->f->conn.proto_minor >= 14) { + if (req->f->conn.proto_minor >= 14) + { #ifdef HAVE_SPLICE #ifdef HAVE_VMSPLICE - f->conn.capable |= FUSE_CAP_SPLICE_WRITE | FUSE_CAP_SPLICE_MOVE; - if (f->splice_write) - f->conn.want |= FUSE_CAP_SPLICE_WRITE; - if (f->splice_move) - f->conn.want |= FUSE_CAP_SPLICE_MOVE; + f->conn.capable |= FUSE_CAP_SPLICE_WRITE | FUSE_CAP_SPLICE_MOVE; + if (f->splice_write) + f->conn.want |= FUSE_CAP_SPLICE_WRITE; + if (f->splice_move) + f->conn.want |= FUSE_CAP_SPLICE_MOVE; #endif - f->conn.capable |= FUSE_CAP_SPLICE_READ; - if (f->splice_read) - f->conn.want |= FUSE_CAP_SPLICE_READ; + f->conn.capable |= FUSE_CAP_SPLICE_READ; + if (f->splice_read) + f->conn.want |= FUSE_CAP_SPLICE_READ; #endif - } + } + if (req->f->conn.proto_minor >= 18) f->conn.capable |= FUSE_CAP_IOCTL_DIR; @@ -1847,11 +2248,12 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) if (f->op.flock && !f->no_remote_flock) f->conn.want |= FUSE_CAP_FLOCK_LOCKS; - if (bufsize < FUSE_MIN_READ_BUFFER) { - fprintf(stderr, "fuse: warning: buffer size too small: %zu\n", - bufsize); - bufsize = FUSE_MIN_READ_BUFFER; - } + if (bufsize < FUSE_MIN_READ_BUFFER) + { + fprintf(stderr, "fuse: warning: buffer size too small: %zu\n", + bufsize); + bufsize = FUSE_MIN_READ_BUFFER; + } bufsize -= 4096; if (bufsize < f->conn.max_write) @@ -1905,32 +2307,34 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) outarg.max_readahead = f->conn.max_readahead; outarg.max_write = f->conn.max_write; - if (f->conn.proto_minor >= 13) { - if (f->conn.max_background >= (1 << 16)) - f->conn.max_background = (1 << 16) - 1; - if (f->conn.congestion_threshold > f->conn.max_background) - f->conn.congestion_threshold = f->conn.max_background; - if (!f->conn.congestion_threshold) { - f->conn.congestion_threshold = - f->conn.max_background * 3 / 4; - } - - outarg.max_background = f->conn.max_background; - outarg.congestion_threshold = f->conn.congestion_threshold; - } + if (f->conn.proto_minor >= 13) + { + if (f->conn.max_background >= (1 << 16)) + f->conn.max_background = (1 << 16) - 1; + if (f->conn.congestion_threshold > f->conn.max_background) + f->conn.congestion_threshold = f->conn.max_background; + if (!f->conn.congestion_threshold) + { + f->conn.congestion_threshold = f->conn.max_background * 3 / 4; + } + + outarg.max_background = f->conn.max_background; + outarg.congestion_threshold = f->conn.congestion_threshold; + } - if (f->debug) { - fprintf(stderr, " INIT: %u.%u\n", outarg.major, outarg.minor); - fprintf(stderr, " flags=0x%08x\n", outarg.flags); - fprintf(stderr, " max_readahead=0x%08x\n", - outarg.max_readahead); - fprintf(stderr, " max_write=0x%08x\n", outarg.max_write); - fprintf(stderr, " max_background=%i\n", - outarg.max_background); - fprintf(stderr, " congestion_threshold=%i\n", - outarg.congestion_threshold); - fprintf(stderr, " max_pages=%d\n",outarg.max_pages); - } + if (f->debug) + { + fprintf(stderr, " INIT: %u.%u\n", outarg.major, outarg.minor); + fprintf(stderr, " flags=0x%08x\n", outarg.flags); + fprintf(stderr, " max_readahead=0x%08x\n", + outarg.max_readahead); + fprintf(stderr, " max_write=0x%08x\n", outarg.max_write); + fprintf(stderr, " max_background=%i\n", + outarg.max_background); + fprintf(stderr, " congestion_threshold=%i\n", + outarg.congestion_threshold); + fprintf(stderr, " max_pages=%d\n",outarg.max_pages); + } size_t outargsize; if(arg->minor < 5) @@ -1943,7 +2347,11 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) send_reply_ok(req, &outarg, outargsize); } -static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) +static +void +do_destroy(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg) { struct fuse_ll *f = req->f; @@ -1957,7 +2365,9 @@ static void do_destroy(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) send_reply_ok(req, NULL, 0); } -static void list_del_nreq(struct fuse_notify_req *nreq) +static +void +list_del_nreq(struct fuse_notify_req *nreq) { struct fuse_notify_req *prev = nreq->prev; struct fuse_notify_req *next = nreq->next; @@ -1965,8 +2375,10 @@ static void list_del_nreq(struct fuse_notify_req *nreq) next->prev = prev; } -static void list_add_nreq(struct fuse_notify_req *nreq, - struct fuse_notify_req *next) +static +void +list_add_nreq(struct fuse_notify_req *nreq, + struct fuse_notify_req *next) { struct fuse_notify_req *prev = next->prev; nreq->next = next; @@ -1975,14 +2387,20 @@ static void list_add_nreq(struct fuse_notify_req *nreq, next->prev = nreq; } -static void list_init_nreq(struct fuse_notify_req *nreq) +static +void +list_init_nreq(struct fuse_notify_req *nreq) { nreq->next = nreq; nreq->prev = nreq; } -static void do_notify_reply(fuse_req_t req, fuse_ino_t nodeid, - const void *inarg, const struct fuse_buf *buf) +static +void +do_notify_reply(fuse_req_t req, + fuse_ino_t nodeid, + const void *inarg, + const struct fuse_buf *buf) { struct fuse_ll *f = req->f; struct fuse_notify_req *nreq; @@ -1990,12 +2408,14 @@ static void do_notify_reply(fuse_req_t req, fuse_ino_t nodeid, pthread_mutex_lock(&f->lock); head = &f->notify_list; - for (nreq = head->next; nreq != head; nreq = nreq->next) { - if (nreq->unique == req->unique) { - list_del_nreq(nreq); - break; + for (nreq = head->next; nreq != head; nreq = nreq->next) + { + if (nreq->unique == req->unique) + { + list_del_nreq(nreq); + break; + } } - } pthread_mutex_unlock(&f->lock); if (nreq != head) @@ -2009,8 +2429,8 @@ do_copy_file_range(fuse_req_t req_, const void *arg_) { - struct fuse_file_info ffi_in = {0}; - struct fuse_file_info ffi_out = {0}; + fuse_file_info_t ffi_in = {0}; + fuse_file_info_t ffi_out = {0}; struct fuse_copy_file_range_in *arg = (struct fuse_copy_file_range_in*)arg_; ffi_in.fh = arg->fh_in; @@ -2030,8 +2450,13 @@ do_copy_file_range(fuse_req_t req_, arg->flags); } -static int send_notify_iov(struct fuse_ll *f, struct fuse_chan *ch, - int notify_code, struct iovec *iov, int count) +static +int +send_notify_iov(struct fuse_ll *f, + struct fuse_chan *ch, + int notify_code, + struct iovec *iov, + int count) { struct fuse_out_header out; @@ -2046,25 +2471,32 @@ static int send_notify_iov(struct fuse_ll *f, struct fuse_chan *ch, return fuse_send_msg(f, ch, iov, count); } -int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph) +int +fuse_lowlevel_notify_poll(fuse_pollhandle_t *ph) { - if (ph != NULL) { - struct fuse_notify_poll_wakeup_out outarg; - struct iovec iov[2]; + if (ph != NULL) + { + struct fuse_notify_poll_wakeup_out outarg; + struct iovec iov[2]; - outarg.kh = ph->kh; + outarg.kh = ph->kh; - iov[1].iov_base = &outarg; - iov[1].iov_len = sizeof(outarg); + iov[1].iov_base = &outarg; + iov[1].iov_len = sizeof(outarg); - return send_notify_iov(ph->f, ph->ch, FUSE_NOTIFY_POLL, iov, 2); - } else { - return 0; - } + return send_notify_iov(ph->f, ph->ch, FUSE_NOTIFY_POLL, iov, 2); + } + else + { + return 0; + } } -int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino, - off_t off, off_t len) +int +fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, + fuse_ino_t ino, + off_t off, + off_t len) { struct fuse_notify_inval_inode_out outarg; struct fuse_ll *f; @@ -2087,8 +2519,11 @@ int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino, return send_notify_iov(f, ch, FUSE_NOTIFY_INVAL_INODE, iov, 2); } -int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent, - const char *name, size_t namelen) +int +fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, + fuse_ino_t parent, + const char *name, + size_t namelen) { struct fuse_notify_inval_entry_out outarg; struct fuse_ll *f; @@ -2113,9 +2548,12 @@ int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent, return send_notify_iov(f, ch, FUSE_NOTIFY_INVAL_ENTRY, iov, 3); } -int fuse_lowlevel_notify_delete(struct fuse_chan *ch, - fuse_ino_t parent, fuse_ino_t child, - const char *name, size_t namelen) +int +fuse_lowlevel_notify_delete(struct fuse_chan *ch, + fuse_ino_t parent, + fuse_ino_t child, + const char *name, + size_t namelen) { struct fuse_notify_delete_out outarg; struct fuse_ll *f; @@ -2144,9 +2582,12 @@ int fuse_lowlevel_notify_delete(struct fuse_chan *ch, return send_notify_iov(f, ch, FUSE_NOTIFY_DELETE, iov, 3); } -int fuse_lowlevel_notify_store(struct fuse_chan *ch, fuse_ino_t ino, - off_t offset, struct fuse_bufvec *bufv, - enum fuse_buf_copy_flags flags) +int +fuse_lowlevel_notify_store(struct fuse_chan *ch, + fuse_ino_t ino, + off_t offset, + struct fuse_bufvec *bufv, + enum fuse_buf_copy_flags flags) { struct fuse_out_header out; struct fuse_notify_store_out outarg; @@ -2185,15 +2626,19 @@ int fuse_lowlevel_notify_store(struct fuse_chan *ch, fuse_ino_t ino, return res; } -struct fuse_retrieve_req { +struct fuse_retrieve_req +{ struct fuse_notify_req nreq; void *cookie; }; -static void fuse_ll_retrieve_reply(struct fuse_notify_req *nreq, - fuse_req_t req, fuse_ino_t ino, - const void *inarg, - const struct fuse_buf *ibuf) +static +void +fuse_ll_retrieve_reply(struct fuse_notify_req *nreq, + fuse_req_t req, + fuse_ino_t ino, + const void *inarg, + const struct fuse_buf *ibuf) { struct fuse_ll *f = req->f; struct fuse_retrieve_req *rreq = @@ -2210,27 +2655,36 @@ static void fuse_ll_retrieve_reply(struct fuse_notify_req *nreq, bufv.buf[0].size -= sizeof(struct fuse_in_header) + sizeof(struct fuse_notify_retrieve_in); - if (bufv.buf[0].size < arg->size) { - fprintf(stderr, "fuse: retrieve reply: buffer size too small\n"); - fuse_reply_none(req); - goto out; - } + if (bufv.buf[0].size < arg->size) + { + fprintf(stderr, "fuse: retrieve reply: buffer size too small\n"); + fuse_reply_none(req); + goto out; + } bufv.buf[0].size = arg->size; - if (req->f->op.retrieve_reply) { - req->f->op.retrieve_reply(req, rreq->cookie, ino, - arg->offset, &bufv); - } else { - fuse_reply_none(req); - } + if (req->f->op.retrieve_reply) + { + req->f->op.retrieve_reply(req, rreq->cookie, ino, + arg->offset, &bufv); + } + else + { + fuse_reply_none(req); + } + out: free(rreq); if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count) fuse_ll_clear_pipe(f); } -int fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, fuse_ino_t ino, - size_t size, off_t offset, void *cookie) +int +fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, + fuse_ino_t ino, + size_t size, + off_t offset, + void *cookie) { struct fuse_notify_retrieve_out outarg; struct fuse_ll *f; @@ -2268,28 +2722,34 @@ int fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, fuse_ino_t ino, iov[1].iov_len = sizeof(outarg); err = send_notify_iov(f, ch, FUSE_NOTIFY_RETRIEVE, iov, 2); - if (err) { - pthread_mutex_lock(&f->lock); - list_del_nreq(&rreq->nreq); - pthread_mutex_unlock(&f->lock); - free(rreq); - } + if (err) + { + pthread_mutex_lock(&f->lock); + list_del_nreq(&rreq->nreq); + pthread_mutex_unlock(&f->lock); + free(rreq); + } return err; } -void *fuse_req_userdata(fuse_req_t req) +void * +fuse_req_userdata(fuse_req_t req) { return req->f->userdata; } -const struct fuse_ctx *fuse_req_ctx(fuse_req_t req) +const +struct fuse_ctx * +fuse_req_ctx(fuse_req_t req) { return &req->ctx; } -void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, - void *data) +void +fuse_req_interrupt_func(fuse_req_t req, + fuse_interrupt_func_t func, + void *data) { pthread_mutex_lock(&req->lock); pthread_mutex_lock(&req->f->lock); @@ -2301,7 +2761,8 @@ void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, pthread_mutex_unlock(&req->lock); } -int fuse_req_interrupted(fuse_req_t req) +int +fuse_req_interrupted(fuse_req_t req) { int interrupted; @@ -2364,7 +2825,9 @@ static struct { #define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0])) -static const char *opname(enum fuse_opcode opcode) +static +const char * +opname(enum fuse_opcode opcode) { if (opcode >= FUSE_MAXOP || !fuse_ll_ops[opcode].name) return "???"; @@ -2372,23 +2835,32 @@ static const char *opname(enum fuse_opcode opcode) return fuse_ll_ops[opcode].name; } -static int fuse_ll_copy_from_pipe(struct fuse_bufvec *dst, - struct fuse_bufvec *src) +static +int +fuse_ll_copy_from_pipe(struct fuse_bufvec *dst, + struct fuse_bufvec *src) { int res = fuse_buf_copy(dst, src, 0); - if (res < 0) { - fprintf(stderr, "fuse: copy from pipe: %s\n", strerror(-res)); - return res; - } - if (res < fuse_buf_size(dst)) { - fprintf(stderr, "fuse: copy from pipe: short read\n"); - return -1; - } + if (res < 0) + { + fprintf(stderr, "fuse: copy from pipe: %s\n", strerror(-res)); + return res; + } + + if (res < fuse_buf_size(dst)) + { + fprintf(stderr, "fuse: copy from pipe: short read\n"); + return -1; + } + return 0; } -static void fuse_ll_process_buf(void *data, const struct fuse_buf *buf, - struct fuse_chan *ch) +static +void +fuse_ll_process_buf(void *data, + const struct fuse_buf *buf, + struct fuse_chan *ch) { struct fuse_ll *f = (struct fuse_ll *) data; const size_t write_header_size = sizeof(struct fuse_in_header) + @@ -2402,48 +2874,54 @@ static void fuse_ll_process_buf(void *data, const struct fuse_buf *buf, int err; int res; - if (buf->flags & FUSE_BUF_IS_FD) { - if (buf->size < tmpbuf.buf[0].size) - tmpbuf.buf[0].size = buf->size; + if (buf->flags & FUSE_BUF_IS_FD) + { + if (buf->size < tmpbuf.buf[0].size) + tmpbuf.buf[0].size = buf->size; + + mbuf = malloc(tmpbuf.buf[0].size); + if (mbuf == NULL) + { + fprintf(stderr, "fuse: failed to allocate header\n"); + goto clear_pipe; + } + tmpbuf.buf[0].mem = mbuf; + + res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv); + if (res < 0) + goto clear_pipe; - mbuf = malloc(tmpbuf.buf[0].size); - if (mbuf == NULL) { - fprintf(stderr, "fuse: failed to allocate header\n"); - goto clear_pipe; + in = mbuf; + } + else + { + in = buf->mem; } - tmpbuf.buf[0].mem = mbuf; - - res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv); - if (res < 0) - goto clear_pipe; - - in = mbuf; - } else { - in = buf->mem; - } - if (f->debug) { - fprintf(stderr, - "unique: %llu, opcode: %s (%i), nodeid: %lu, insize: %zu, pid: %u\n", - (unsigned long long) in->unique, - opname((enum fuse_opcode) in->opcode), in->opcode, - (unsigned long) in->nodeid, buf->size, in->pid); - } + if (f->debug) + { + fprintf(stderr, + "unique: %llu, opcode: %s (%i), nodeid: %lu, insize: %zu, pid: %u\n", + (unsigned long long) in->unique, + opname((enum fuse_opcode) in->opcode), in->opcode, + (unsigned long) in->nodeid, buf->size, in->pid); + } req = fuse_ll_alloc_req(f); - if (req == NULL) { - struct fuse_out_header out = { - .unique = in->unique, - .error = -ENOMEM, - }; - struct iovec iov = { - .iov_base = &out, - .iov_len = sizeof(struct fuse_out_header), - }; - - fuse_send_msg(f, ch, &iov, 1); - goto clear_pipe; - } + if (req == NULL) + { + struct fuse_out_header out = { + .unique = in->unique, + .error = -ENOMEM, + }; + struct iovec iov = { + .iov_base = &out, + .iov_len = sizeof(struct fuse_out_header), + }; + + fuse_send_msg(f, ch, &iov, 1); + goto clear_pipe; + } req->unique = in->unique; req->ctx.uid = in->uid; @@ -2461,7 +2939,9 @@ static void fuse_ll_process_buf(void *data, const struct fuse_buf *buf, goto reply_err; } else if(in->opcode == FUSE_INIT) - goto reply_err; + { + goto reply_err; + } err = EACCES; if (f->allow_root && @@ -2494,25 +2974,26 @@ static void fuse_ll_process_buf(void *data, const struct fuse_buf *buf, if ((buf->flags & FUSE_BUF_IS_FD) && write_header_size < buf->size && (in->opcode != FUSE_WRITE || !f->op.write_buf) && - in->opcode != FUSE_NOTIFY_REPLY) { - void *newmbuf; + in->opcode != FUSE_NOTIFY_REPLY) + { + void *newmbuf; - err = ENOMEM; - newmbuf = realloc(mbuf, buf->size); - if (newmbuf == NULL) - goto reply_err; - mbuf = newmbuf; + err = ENOMEM; + newmbuf = realloc(mbuf, buf->size); + if (newmbuf == NULL) + goto reply_err; + mbuf = newmbuf; - tmpbuf = FUSE_BUFVEC_INIT(buf->size - write_header_size); - tmpbuf.buf[0].mem = mbuf + write_header_size; + tmpbuf = FUSE_BUFVEC_INIT(buf->size - write_header_size); + tmpbuf.buf[0].mem = mbuf + write_header_size; - res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv); - err = -res; - if (res < 0) - goto reply_err; + res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv); + err = -res; + if (res < 0) + goto reply_err; - in = mbuf; - } + in = mbuf; + } inarg = (void *) &in[1]; if (in->opcode == FUSE_WRITE && f->op.write_buf) @@ -2534,8 +3015,12 @@ static void fuse_ll_process_buf(void *data, const struct fuse_buf *buf, goto out_free; } -static void fuse_ll_process(void *data, const char *buf, size_t len, - struct fuse_chan *ch) +static +void +fuse_ll_process(void *data, + const char *buf, + size_t len, + struct fuse_chan *ch) { struct fuse_buf fbuf = { .mem = (void *) buf, @@ -2550,39 +3035,44 @@ enum { KEY_VERSION, }; -static const struct fuse_opt fuse_ll_opts[] = { - { "debug", offsetof(struct fuse_ll, debug), 1 }, - { "-d", offsetof(struct fuse_ll, debug), 1 }, - { "allow_root", offsetof(struct fuse_ll, allow_root), 1 }, - { "max_readahead=%u", offsetof(struct fuse_ll, conn.max_readahead), 0 }, - { "max_background=%u", offsetof(struct fuse_ll, conn.max_background), 0 }, - { "congestion_threshold=%u", - offsetof(struct fuse_ll, conn.congestion_threshold), 0 }, - { "no_remote_lock", offsetof(struct fuse_ll, no_remote_posix_lock), 1}, - { "no_remote_lock", offsetof(struct fuse_ll, no_remote_flock), 1}, - { "no_remote_flock", offsetof(struct fuse_ll, no_remote_flock), 1}, - { "no_remote_posix_lock", offsetof(struct fuse_ll, no_remote_posix_lock), 1}, - { "splice_write", offsetof(struct fuse_ll, splice_write), 1}, - { "no_splice_write", offsetof(struct fuse_ll, no_splice_write), 1}, - { "splice_move", offsetof(struct fuse_ll, splice_move), 1}, - { "no_splice_move", offsetof(struct fuse_ll, no_splice_move), 1}, - { "splice_read", offsetof(struct fuse_ll, splice_read), 1}, - { "no_splice_read", offsetof(struct fuse_ll, no_splice_read), 1}, - FUSE_OPT_KEY("max_read=", FUSE_OPT_KEY_DISCARD), - FUSE_OPT_KEY("-h", KEY_HELP), - FUSE_OPT_KEY("--help", KEY_HELP), - FUSE_OPT_KEY("-V", KEY_VERSION), - FUSE_OPT_KEY("--version", KEY_VERSION), - FUSE_OPT_END -}; +static const struct fuse_opt fuse_ll_opts[] = + { + { "debug", offsetof(struct fuse_ll, debug), 1 }, + { "-d", offsetof(struct fuse_ll, debug), 1 }, + { "allow_root", offsetof(struct fuse_ll, allow_root), 1 }, + { "max_readahead=%u", offsetof(struct fuse_ll, conn.max_readahead), 0 }, + { "max_background=%u", offsetof(struct fuse_ll, conn.max_background), 0 }, + { "congestion_threshold=%u", + offsetof(struct fuse_ll, conn.congestion_threshold), 0 }, + { "no_remote_lock", offsetof(struct fuse_ll, no_remote_posix_lock), 1}, + { "no_remote_lock", offsetof(struct fuse_ll, no_remote_flock), 1}, + { "no_remote_flock", offsetof(struct fuse_ll, no_remote_flock), 1}, + { "no_remote_posix_lock", offsetof(struct fuse_ll, no_remote_posix_lock), 1}, + { "splice_write", offsetof(struct fuse_ll, splice_write), 1}, + { "no_splice_write", offsetof(struct fuse_ll, no_splice_write), 1}, + { "splice_move", offsetof(struct fuse_ll, splice_move), 1}, + { "no_splice_move", offsetof(struct fuse_ll, no_splice_move), 1}, + { "splice_read", offsetof(struct fuse_ll, splice_read), 1}, + { "no_splice_read", offsetof(struct fuse_ll, no_splice_read), 1}, + FUSE_OPT_KEY("max_read=", FUSE_OPT_KEY_DISCARD), + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("-V", KEY_VERSION), + FUSE_OPT_KEY("--version", KEY_VERSION), + FUSE_OPT_END + }; -static void fuse_ll_version(void) +static +void +fuse_ll_version(void) { fprintf(stderr, "using FUSE kernel interface version %i.%i\n", FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); } -static void fuse_ll_help(void) +static +void +fuse_ll_help(void) { fprintf(stderr, " -o max_readahead=N set maximum readahead\n" @@ -2597,41 +3087,51 @@ static void fuse_ll_help(void) ); } -static int fuse_ll_opt_proc(void *data, const char *arg, int key, - struct fuse_args *outargs) +static +int +fuse_ll_opt_proc(void *data, + const char *arg, + int key, + struct fuse_args *outargs) { (void) data; (void) outargs; - switch (key) { - case KEY_HELP: - fuse_ll_help(); - break; + switch (key) + { + case KEY_HELP: + fuse_ll_help(); + break; - case KEY_VERSION: - fuse_ll_version(); - break; + case KEY_VERSION: + fuse_ll_version(); + break; - default: - fprintf(stderr, "fuse: unknown option `%s'\n", arg); - } + default: + fprintf(stderr, "fuse: unknown option `%s'\n", arg); + } return -1; } -int fuse_lowlevel_is_lib_option(const char *opt) +int +fuse_lowlevel_is_lib_option(const char *opt) { return fuse_opt_match(fuse_ll_opts, opt); } -static void fuse_ll_destroy(void *data) +static +void +fuse_ll_destroy(void *data) { struct fuse_ll *f = (struct fuse_ll *) data; struct fuse_ll_pipe *llp; - if (f->got_init && !f->got_destroy) { - if (f->op.destroy) - f->op.destroy(f->userdata); - } + if (f->got_init && !f->got_destroy) + { + if (f->op.destroy) + f->op.destroy(f->userdata); + } + llp = pthread_getspecific(f->pipe_key); if (llp != NULL) fuse_ll_pipe_free(llp); @@ -2640,15 +3140,20 @@ static void fuse_ll_destroy(void *data) free(f); } -static void fuse_ll_pipe_destructor(void *data) +static +void +fuse_ll_pipe_destructor(void *data) { struct fuse_ll_pipe *llp = data; fuse_ll_pipe_free(llp); } #ifdef HAVE_SPLICE -static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf, - struct fuse_chan **chp) +static +int +fuse_ll_receive_buf(struct fuse_session *se, + struct fuse_buf *buf, + struct fuse_chan **chp) { struct fuse_chan *ch = *chp; struct fuse_ll *f = fuse_session_data(se); @@ -2665,39 +3170,47 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf, if (llp == NULL) goto fallback; - if (llp->size < bufsize) { - if (llp->can_grow) { - res = fcntl(llp->pipe[0], F_SETPIPE_SZ, bufsize); - if (res == -1) { - llp->can_grow = 0; + if (llp->size < bufsize) + { + if (llp->can_grow) + { + res = fcntl(llp->pipe[0], F_SETPIPE_SZ, bufsize); + if (res == -1) + { + llp->can_grow = 0; + goto fallback; + } + llp->size = res; + } + if (llp->size < bufsize) goto fallback; - } - llp->size = res; } - if (llp->size < bufsize) - goto fallback; - } res = splice(fuse_chan_fd(ch), NULL, llp->pipe[1], NULL, bufsize, 0); err = errno; - if (fuse_session_exited(se)) + if(fuse_session_exited(se)) return 0; - if (res == -1) { - if (err == ENODEV) { - fuse_session_exit(se); - return 0; + if (res == -1) + { + if (err == ENODEV) + { + fuse_session_exit(se); + return 0; + } + + if (err != EINTR && err != EAGAIN) + perror("fuse: splice from device"); + + return -err; } - if (err != EINTR && err != EAGAIN) - perror("fuse: splice from device"); - return -err; - } - if (res < sizeof(struct fuse_in_header)) { - fprintf(stderr, "short splice from fuse device\n"); - return -EIO; - } + if (res < sizeof(struct fuse_in_header)) + { + fprintf(stderr, "short splice from fuse device\n"); + return -EIO; + } tmpbuf = (struct fuse_buf) { .size = res, @@ -2711,25 +3224,30 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf, * just an optimization. */ if (res < sizeof(struct fuse_in_header) + - sizeof(struct fuse_write_in) + pagesize) { - struct fuse_bufvec src = { .buf[0] = tmpbuf, .count = 1 }; - struct fuse_bufvec dst = { .buf[0] = *buf, .count = 1 }; - - res = fuse_buf_copy(&dst, &src, 0); - if (res < 0) { - fprintf(stderr, "fuse: copy from pipe: %s\n", - strerror(-res)); - fuse_ll_clear_pipe(f); - return res; - } - if (res < tmpbuf.size) { - fprintf(stderr, "fuse: copy from pipe: short read\n"); - fuse_ll_clear_pipe(f); - return -EIO; + sizeof(struct fuse_write_in) + pagesize) + { + struct fuse_bufvec src = { .buf[0] = tmpbuf, .count = 1 }; + struct fuse_bufvec dst = { .buf[0] = *buf, .count = 1 }; + + res = fuse_buf_copy(&dst, &src, 0); + if (res < 0) { + fprintf(stderr, "fuse: copy from pipe: %s\n", + strerror(-res)); + fuse_ll_clear_pipe(f); + return res; + } + + if (res < tmpbuf.size) + { + fprintf(stderr, "fuse: copy from pipe: short read\n"); + fuse_ll_clear_pipe(f); + return -EIO; + } + + buf->size = tmpbuf.size; + + return buf->size; } - buf->size = tmpbuf.size; - return buf->size; - } *buf = tmpbuf; @@ -2745,8 +3263,11 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf, return res; } #else -static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf, - struct fuse_chan **chp) +static +int +fuse_ll_receive_buf(struct fuse_session *se, + struct fuse_buf *buf, + struct fuse_chan **chp) { (void) se; @@ -2760,15 +3281,16 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf, } #endif - /* * always call fuse_lowlevel_new_common() internally, to work around a * misfeature in the FreeBSD runtime linker, which links the old * version of a symbol to internal references. */ -struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args, - const struct fuse_lowlevel_ops *op, - size_t op_size, void *userdata) +struct fuse_session * +fuse_lowlevel_new_common(struct fuse_args *args, + const struct fuse_lowlevel_ops *op, + size_t op_size, + void *userdata) { int err; struct fuse_ll *f; @@ -2778,16 +3300,18 @@ struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args, .destroy = fuse_ll_destroy, }; - if (sizeof(struct fuse_lowlevel_ops) < op_size) { - fprintf(stderr, "fuse: warning: library too old, some operations may not work\n"); - op_size = sizeof(struct fuse_lowlevel_ops); - } + if (sizeof(struct fuse_lowlevel_ops) < op_size) + { + fprintf(stderr, "fuse: warning: library too old, some operations may not work\n"); + op_size = sizeof(struct fuse_lowlevel_ops); + } f = (struct fuse_ll *) calloc(1, sizeof(struct fuse_ll)); - if (f == NULL) { - fprintf(stderr, "fuse: failed to allocate fuse object\n"); - goto out; - } + if (f == NULL) + { + fprintf(stderr, "fuse: failed to allocate fuse object\n"); + goto out; + } f->conn.max_write = UINT_MAX; f->conn.max_readahead = UINT_MAX; @@ -2798,11 +3322,12 @@ struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args, fuse_mutex_init(&f->lock); err = pthread_key_create(&f->pipe_key, fuse_ll_pipe_destructor); - if (err) { - fprintf(stderr, "fuse: failed to create thread specific key: %s\n", - strerror(err)); - goto out_free; - } + if (err) + { + fprintf(stderr, "fuse: failed to create thread specific key: %s\n", + strerror(err)); + goto out_free; + } if (fuse_opt_parse(args, f, fuse_ll_opts, fuse_ll_opt_proc) == -1) goto out_key_destroy; @@ -2833,10 +3358,10 @@ struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args, } struct fuse_session* -fuse_lowlevel_new(struct fuse_args *args, +fuse_lowlevel_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, - size_t op_size, - void *userdata) + size_t op_size, + void *userdata) { return fuse_lowlevel_new_common(args, op, op_size, userdata); } diff --git a/src/fuse_copy_file_range.cpp b/src/fuse_copy_file_range.cpp index 5ab8c6c7..2c88733e 100644 --- a/src/fuse_copy_file_range.cpp +++ b/src/fuse_copy_file_range.cpp @@ -49,12 +49,12 @@ namespace l namespace FUSE { ssize_t - copy_file_range(struct fuse_file_info *ffi_in_, - off_t offset_in_, - struct fuse_file_info *ffi_out_, - off_t offset_out_, - size_t size_, - int flags_) + copy_file_range(const fuse_file_info_t *ffi_in_, + off_t offset_in_, + const fuse_file_info_t *ffi_out_, + off_t offset_out_, + size_t size_, + int flags_) { FileInfo *fi_in = reinterpret_cast(ffi_in_->fh); FileInfo *fi_out = reinterpret_cast(ffi_out_->fh); diff --git a/src/fuse_copy_file_range.hpp b/src/fuse_copy_file_range.hpp index 32ed0a57..30185ad3 100644 --- a/src/fuse_copy_file_range.hpp +++ b/src/fuse_copy_file_range.hpp @@ -19,10 +19,10 @@ namespace FUSE { ssize_t - copy_file_range(struct fuse_file_info *ffi_in, - off_t offset_in, - struct fuse_file_info *ffi_out, - off_t offset_out, - size_t size, - int flags); + copy_file_range(const fuse_file_info_t *ffi_in, + off_t offset_in, + const fuse_file_info_t *ffi_out, + off_t offset_out, + size_t size, + int flags); } diff --git a/src/fuse_create.cpp b/src/fuse_create.cpp index e57d0f29..4a854d1a 100644 --- a/src/fuse_create.cpp +++ b/src/fuse_create.cpp @@ -54,8 +54,8 @@ namespace l static void - config_to_ffi_flags(const Config &config_, - fuse_file_info *ffi_) + config_to_ffi_flags(const Config &config_, + fuse_file_info_t *ffi_) { switch(config_.cache_files) { @@ -166,9 +166,9 @@ namespace l namespace FUSE { int - create(const char *fusepath_, - mode_t mode_, - fuse_file_info *ffi_) + create(const char *fusepath_, + mode_t mode_, + fuse_file_info_t *ffi_) { const fuse_context *fc = fuse_get_context(); const Config &config = Config::ro(); diff --git a/src/fuse_create.hpp b/src/fuse_create.hpp index b5420118..0fa08a80 100644 --- a/src/fuse_create.hpp +++ b/src/fuse_create.hpp @@ -23,7 +23,7 @@ namespace FUSE { int - create(const char *fusepath, - mode_t mode, - fuse_file_info *ffi); + create(const char *fusepath, + mode_t mode, + fuse_file_info_t *ffi); } diff --git a/src/fuse_fallocate.cpp b/src/fuse_fallocate.cpp index 4a8e3e9e..8235ce43 100644 --- a/src/fuse_fallocate.cpp +++ b/src/fuse_fallocate.cpp @@ -40,10 +40,10 @@ namespace l namespace FUSE { int - fallocate(int mode_, - off_t offset_, - off_t len_, - fuse_file_info *ffi_) + fallocate(const fuse_file_info_t *ffi_, + int mode_, + off_t offset_, + off_t len_) { FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_fallocate.hpp b/src/fuse_fallocate.hpp index 94bc14e5..f29e4a7f 100644 --- a/src/fuse_fallocate.hpp +++ b/src/fuse_fallocate.hpp @@ -21,8 +21,8 @@ namespace FUSE { int - fallocate(int mode, - off_t offset, - off_t len, - fuse_file_info *ffi); + fallocate(const fuse_file_info_t *ffi, + int mode, + off_t offset, + off_t len); } diff --git a/src/fuse_fchmod.cpp b/src/fuse_fchmod.cpp index 482869a3..3b8cdf8c 100644 --- a/src/fuse_fchmod.cpp +++ b/src/fuse_fchmod.cpp @@ -40,8 +40,8 @@ namespace l namespace FUSE { int - fchmod(const struct fuse_file_info *ffi_, - const mode_t mode_) + fchmod(const fuse_file_info_t *ffi_, + const mode_t mode_) { FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_fchmod.hpp b/src/fuse_fchmod.hpp index 17535416..96d4be7e 100644 --- a/src/fuse_fchmod.hpp +++ b/src/fuse_fchmod.hpp @@ -23,6 +23,6 @@ namespace FUSE { int - fchmod(const fuse_file_info *ffi, - const mode_t mode); + fchmod(const fuse_file_info_t *ffi, + const mode_t mode); } diff --git a/src/fuse_fchown.cpp b/src/fuse_fchown.cpp index ca447db9..5bf873ab 100644 --- a/src/fuse_fchown.cpp +++ b/src/fuse_fchown.cpp @@ -43,9 +43,9 @@ namespace l namespace FUSE { int - fchown(const struct fuse_file_info *ffi_, - const uid_t uid_, - const gid_t gid_) + fchown(const fuse_file_info_t *ffi_, + const uid_t uid_, + const gid_t gid_) { FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_fchown.hpp b/src/fuse_fchown.hpp index 5a7bb401..6b043282 100644 --- a/src/fuse_fchown.hpp +++ b/src/fuse_fchown.hpp @@ -21,7 +21,7 @@ namespace FUSE { int - fchown(const fuse_file_info *ffi, - uid_t uid, - gid_t gid); + fchown(const fuse_file_info_t *ffi, + uid_t uid, + gid_t gid); } diff --git a/src/fuse_fgetattr.cpp b/src/fuse_fgetattr.cpp index 7cb0ca44..eb5242ec 100644 --- a/src/fuse_fgetattr.cpp +++ b/src/fuse_fgetattr.cpp @@ -45,9 +45,9 @@ namespace l namespace FUSE { int - fgetattr(struct stat *st_, - fuse_file_info *ffi_, - fuse_timeouts_t *timeout_) + fgetattr(const fuse_file_info_t *ffi_, + struct stat *st_, + fuse_timeouts_t *timeout_) { int rv; const Config &config = Config::ro(); diff --git a/src/fuse_fgetattr.hpp b/src/fuse_fgetattr.hpp index d8a913ad..ce032ac5 100644 --- a/src/fuse_fgetattr.hpp +++ b/src/fuse_fgetattr.hpp @@ -25,7 +25,7 @@ namespace FUSE { int - fgetattr(struct stat *st, - fuse_file_info *ffi, - fuse_timeouts_t *timeout); + fgetattr(const fuse_file_info_t *ffi, + struct stat *st, + fuse_timeouts_t *timeout); } diff --git a/src/fuse_flock.cpp b/src/fuse_flock.cpp index 78065207..f1df49fa 100644 --- a/src/fuse_flock.cpp +++ b/src/fuse_flock.cpp @@ -38,9 +38,8 @@ namespace l namespace FUSE { int - flock(const char *fusepath_, - fuse_file_info *ffi_, - int op_) + flock(const fuse_file_info_t *ffi_, + int op_) { FileInfo* fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_flock.hpp b/src/fuse_flock.hpp index a1124677..cab3c845 100644 --- a/src/fuse_flock.hpp +++ b/src/fuse_flock.hpp @@ -21,7 +21,6 @@ namespace FUSE { int - flock(const char *fusepath, - fuse_file_info *ffi, - int op); + flock(const fuse_file_info_t *ffi, + int op); } diff --git a/src/fuse_flush.cpp b/src/fuse_flush.cpp index 277a3218..33935530 100644 --- a/src/fuse_flush.cpp +++ b/src/fuse_flush.cpp @@ -42,7 +42,7 @@ namespace l namespace FUSE { int - flush(fuse_file_info *ffi_) + flush(const fuse_file_info_t *ffi_) { FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_flush.hpp b/src/fuse_flush.hpp index b13d21f7..27ca708b 100644 --- a/src/fuse_flush.hpp +++ b/src/fuse_flush.hpp @@ -21,5 +21,5 @@ namespace FUSE { int - flush(fuse_file_info *ffi); + flush(const fuse_file_info_t *ffi); } diff --git a/src/fuse_fsync.cpp b/src/fuse_fsync.cpp index a8d7c793..96dbc083 100644 --- a/src/fuse_fsync.cpp +++ b/src/fuse_fsync.cpp @@ -44,8 +44,8 @@ namespace l namespace FUSE { int - fsync(int isdatasync_, - fuse_file_info *ffi_) + fsync(const fuse_file_info_t *ffi_, + int isdatasync_) { FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_fsync.hpp b/src/fuse_fsync.hpp index 9f05ff48..c97e569f 100644 --- a/src/fuse_fsync.hpp +++ b/src/fuse_fsync.hpp @@ -21,6 +21,7 @@ namespace FUSE { int - fsync(int isdatasync, - fuse_file_info *ffi); + fsync(const fuse_file_info_t *ffi, + int isdatasync); + } diff --git a/src/fuse_fsyncdir.cpp b/src/fuse_fsyncdir.cpp index 12b9f727..21ae8efd 100644 --- a/src/fuse_fsyncdir.cpp +++ b/src/fuse_fsyncdir.cpp @@ -42,8 +42,8 @@ namespace l namespace FUSE { int - fsyncdir(int isdatasync_, - fuse_file_info *ffi_) + fsyncdir(const fuse_file_info_t *ffi_, + int isdatasync_) { DirInfo *di = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_fsyncdir.hpp b/src/fuse_fsyncdir.hpp index 677dea7c..7db828cd 100644 --- a/src/fuse_fsyncdir.hpp +++ b/src/fuse_fsyncdir.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - fsyncdir(int isdatasync, - fuse_file_info *ffi); + fsyncdir(const fuse_file_info_t *ffi, + int isdatasync); } diff --git a/src/fuse_ftruncate.cpp b/src/fuse_ftruncate.cpp index d7879e7d..c68a312f 100644 --- a/src/fuse_ftruncate.cpp +++ b/src/fuse_ftruncate.cpp @@ -38,8 +38,8 @@ namespace l namespace FUSE { int - ftruncate(off_t size_, - fuse_file_info *ffi_) + ftruncate(const fuse_file_info_t *ffi_, + off_t size_) { FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_ftruncate.hpp b/src/fuse_ftruncate.hpp index 312764c9..78c8fb9e 100644 --- a/src/fuse_ftruncate.hpp +++ b/src/fuse_ftruncate.hpp @@ -24,6 +24,6 @@ namespace FUSE { int - ftruncate(off_t size, - fuse_file_info *ffi); + ftruncate(const fuse_file_info_t *ffi, + off_t size); } diff --git a/src/fuse_futimens.cpp b/src/fuse_futimens.cpp index fac6768a..2f21b319 100644 --- a/src/fuse_futimens.cpp +++ b/src/fuse_futimens.cpp @@ -42,8 +42,8 @@ namespace l namespace FUSE { int - futimens(const struct fuse_file_info *ffi_, - const struct timespec ts_[2]) + futimens(const fuse_file_info_t *ffi_, + const struct timespec ts_[2]) { FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_futimens.hpp b/src/fuse_futimens.hpp index 100c8bca..6d149ed7 100644 --- a/src/fuse_futimens.hpp +++ b/src/fuse_futimens.hpp @@ -23,6 +23,6 @@ namespace FUSE { int - futimens(const fuse_file_info *ffi, - const timespec ts[2]); + futimens(const fuse_file_info_t *ffi, + const timespec ts[2]); } diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index de7cb971..88d49610 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -116,10 +116,10 @@ namespace l static int - ioctl_file(fuse_file_info *ffi_, - const uint32_t cmd_, - void *data_, - uint32_t *out_bufsz_) + ioctl_file(const fuse_file_info_t *ffi_, + const uint32_t cmd_, + void *data_, + uint32_t *out_bufsz_) { FileInfo *fi = reinterpret_cast(ffi_->fh); const fuse_context *fc = fuse_get_context(); @@ -165,10 +165,10 @@ namespace l static int - ioctl_dir(fuse_file_info *ffi_, - const uint32_t cmd_, - void *data_, - uint32_t *out_bufsz_) + ioctl_dir(const fuse_file_info_t *ffi_, + const uint32_t cmd_, + void *data_, + uint32_t *out_bufsz_) { DirInfo *di = reinterpret_cast(ffi_->fh); const fuse_context *fc = fuse_get_context(); @@ -270,8 +270,8 @@ namespace l static int - file_basepath(fuse_file_info *ffi_, - void *data_) + file_basepath(const fuse_file_info_t *ffi_, + void *data_) { const Config &config = Config::ro(); std::string &fusepath = reinterpret_cast(ffi_->fh)->fusepath; @@ -284,8 +284,8 @@ namespace l static int - file_relpath(fuse_file_info *ffi_, - void *data_) + file_relpath(const fuse_file_info_t *ffi_, + void *data_) { std::string &fusepath = reinterpret_cast(ffi_->fh)->fusepath; @@ -314,8 +314,8 @@ namespace l static int - file_fullpath(fuse_file_info *ffi_, - void *data_) + file_fullpath(const fuse_file_info_t *ffi_, + void *data_) { const Config &config = Config::ro(); std::string &fusepath = reinterpret_cast(ffi_->fh)->fusepath; @@ -328,8 +328,8 @@ namespace l static int - file_allpaths(fuse_file_info *ffi_, - void *data_) + file_allpaths(const fuse_file_info_t *ffi_, + void *data_) { string concated; vector paths; @@ -348,8 +348,8 @@ namespace l static int - file_info(fuse_file_info *ffi_, - void *data_) + file_info(const fuse_file_info_t *ffi_, + void *data_) { char *key = (char*)data_; @@ -369,12 +369,12 @@ namespace l namespace FUSE { int - ioctl(unsigned long cmd_, - void *arg_, - fuse_file_info *ffi_, - unsigned int flags_, - void *data_, - uint32_t *out_bufsz_) + ioctl(const fuse_file_info_t *ffi_, + unsigned long cmd_, + void *arg_, + unsigned int flags_, + void *data_, + uint32_t *out_bufsz_) { switch(cmd_) { diff --git a/src/fuse_ioctl.hpp b/src/fuse_ioctl.hpp index 67db5355..98b6f863 100644 --- a/src/fuse_ioctl.hpp +++ b/src/fuse_ioctl.hpp @@ -21,10 +21,10 @@ namespace FUSE { int - ioctl(unsigned long cmd, - void *arg, - fuse_file_info *ffi, - unsigned int flags, - void *data, - uint32_t *out_bufsz); + ioctl(const fuse_file_info_t *ffi, + unsigned long cmd, + void *arg, + unsigned int flags, + void *data, + uint32_t *out_bufsz); } diff --git a/src/fuse_open.cpp b/src/fuse_open.cpp index 2a4cd628..583714f4 100644 --- a/src/fuse_open.cpp +++ b/src/fuse_open.cpp @@ -117,8 +117,8 @@ namespace l static void - config_to_ffi_flags(const Config &config_, - fuse_file_info *ffi_) + config_to_ffi_flags(const Config &config_, + fuse_file_info_t *ffi_) { switch(config_.cache_files) { @@ -203,8 +203,8 @@ namespace l namespace FUSE { int - open(const char *fusepath_, - fuse_file_info *ffi_) + open(const char *fusepath_, + fuse_file_info_t *ffi_) { const fuse_context *fc = fuse_get_context(); const Config &config = Config::ro(); diff --git a/src/fuse_open.hpp b/src/fuse_open.hpp index bb20d86e..2d7cadee 100644 --- a/src/fuse_open.hpp +++ b/src/fuse_open.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - open(const char *fusepath, - fuse_file_info *ffi); + open(const char *fusepath, + fuse_file_info_t *ffi); } diff --git a/src/fuse_opendir.cpp b/src/fuse_opendir.cpp index 3f782895..6bd5e864 100644 --- a/src/fuse_opendir.cpp +++ b/src/fuse_opendir.cpp @@ -22,8 +22,8 @@ namespace FUSE { int - opendir(const char *fusepath_, - fuse_file_info *ffi_) + opendir(const char *fusepath_, + fuse_file_info_t *ffi_) { const Config &config = Config::ro(); diff --git a/src/fuse_opendir.hpp b/src/fuse_opendir.hpp index 372dc389..7bc83339 100644 --- a/src/fuse_opendir.hpp +++ b/src/fuse_opendir.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - opendir(const char *fusepath, - fuse_file_info *ffi); + opendir(const char *fusepath, + fuse_file_info_t *ffi); } diff --git a/src/fuse_prepare_hide.cpp b/src/fuse_prepare_hide.cpp index 5a474596..73c8e74b 100644 --- a/src/fuse_prepare_hide.cpp +++ b/src/fuse_prepare_hide.cpp @@ -29,7 +29,7 @@ namespace FUSE uint64_t *fh_) { int rv; - struct fuse_file_info ffi = {0}; + fuse_file_info_t ffi = {0}; ffi.flags = O_RDONLY|O_NOFOLLOW; rv = FUSE::open(fusepath_,&ffi); diff --git a/src/fuse_read.cpp b/src/fuse_read.cpp index 3b76e52f..34a4b2e5 100644 --- a/src/fuse_read.cpp +++ b/src/fuse_read.cpp @@ -62,10 +62,10 @@ namespace l namespace FUSE { int - read(char *buf_, - size_t count_, - off_t offset_, - fuse_file_info *ffi_) + read(const fuse_file_info_t *ffi_, + char *buf_, + size_t count_, + off_t offset_) { FileInfo *fi; @@ -77,11 +77,10 @@ namespace FUSE } int - read_null(char *buf_, - size_t count_, - off_t offset_, - fuse_file_info *ffi_) - + read_null(const fuse_file_info_t *ffi_, + char *buf_, + size_t count_, + off_t offset_) { return count_; } diff --git a/src/fuse_read.hpp b/src/fuse_read.hpp index 5276c0a6..21110ee2 100644 --- a/src/fuse_read.hpp +++ b/src/fuse_read.hpp @@ -21,14 +21,14 @@ namespace FUSE { int - read(char *buf, - size_t count, - off_t offset, - fuse_file_info *ffi); + read(const fuse_file_info_t *ffi, + char *buf, + size_t count, + off_t offset); int - read_null(char *buf, - size_t count, - off_t offset, - fuse_file_info *ffi); + read_null(const fuse_file_info_t *ffi, + char *buf, + size_t count, + off_t offset); } diff --git a/src/fuse_read_buf.cpp b/src/fuse_read_buf.cpp index 5d64d326..d43355a9 100644 --- a/src/fuse_read_buf.cpp +++ b/src/fuse_read_buf.cpp @@ -54,10 +54,10 @@ namespace l namespace FUSE { int - read_buf(fuse_bufvec **bufp_, - size_t size_, - off_t offset_, - fuse_file_info *ffi_) + read_buf(const fuse_file_info_t *ffi_, + fuse_bufvec **bufp_, + size_t size_, + off_t offset_) { FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_read_buf.hpp b/src/fuse_read_buf.hpp index 6c0ec316..34ecc46f 100644 --- a/src/fuse_read_buf.hpp +++ b/src/fuse_read_buf.hpp @@ -23,8 +23,8 @@ namespace FUSE { int - read_buf(struct fuse_bufvec **buf, - size_t size, - off_t offset, - fuse_file_info *ffi); + read_buf(const fuse_file_info_t *ffi, + struct fuse_bufvec **buf, + size_t size, + off_t offset); } diff --git a/src/fuse_readdir.cpp b/src/fuse_readdir.cpp index fd8c8713..e9607442 100644 --- a/src/fuse_readdir.cpp +++ b/src/fuse_readdir.cpp @@ -29,8 +29,8 @@ namespace FUSE { int - readdir(fuse_file_info *ffi_, - fuse_dirents_t *buf_) + readdir(const fuse_file_info_t *ffi_, + fuse_dirents_t *buf_) { DirInfo *di = reinterpret_cast(ffi_->fh); const fuse_context *fc = fuse_get_context(); diff --git a/src/fuse_readdir.hpp b/src/fuse_readdir.hpp index 1e87f932..92741edd 100644 --- a/src/fuse_readdir.hpp +++ b/src/fuse_readdir.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - readdir(fuse_file_info *ffi, - fuse_dirents_t *buf); + readdir(const fuse_file_info_t *ffi, + fuse_dirents_t *buf); } diff --git a/src/fuse_readdir_plus.cpp b/src/fuse_readdir_plus.cpp index e445bf1b..6ee1f52a 100644 --- a/src/fuse_readdir_plus.cpp +++ b/src/fuse_readdir_plus.cpp @@ -29,13 +29,13 @@ namespace FUSE { int - readdir_plus(fuse_file_info *ffi_, - fuse_dirents_t *buf_) + readdir_plus(const fuse_file_info_t *ffi_, + fuse_dirents_t *buf_) { - DirInfo *di = reinterpret_cast(ffi_->fh); - const fuse_context *fc = fuse_get_context(); - const Config &config = Config::ro(); - const ugid::Set ugid(fc->uid,fc->gid); + DirInfo *di = reinterpret_cast(ffi_->fh); + const fuse_context *fc = fuse_get_context(); + const Config &config = Config::ro(); + const ugid::Set ugid(fc->uid,fc->gid); switch(config.readdir) { diff --git a/src/fuse_readdir_plus.hpp b/src/fuse_readdir_plus.hpp index dd33c3da..20278f0c 100644 --- a/src/fuse_readdir_plus.hpp +++ b/src/fuse_readdir_plus.hpp @@ -21,6 +21,6 @@ namespace FUSE { int - readdir_plus(fuse_file_info *ffi, - fuse_dirents_t *buf); + readdir_plus(const fuse_file_info_t *ffi, + fuse_dirents_t *buf); } diff --git a/src/fuse_release.cpp b/src/fuse_release.cpp index 5aff7b44..88c1357e 100644 --- a/src/fuse_release.cpp +++ b/src/fuse_release.cpp @@ -50,7 +50,7 @@ namespace l namespace FUSE { int - release(fuse_file_info *ffi_) + release(const fuse_file_info_t *ffi_) { const Config &config = Config::ro(); FileInfo *fi = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_release.hpp b/src/fuse_release.hpp index 43d64e21..547490fa 100644 --- a/src/fuse_release.hpp +++ b/src/fuse_release.hpp @@ -21,5 +21,5 @@ namespace FUSE { int - release(fuse_file_info *ffi); + release(const fuse_file_info_t *ffi); } diff --git a/src/fuse_releasedir.cpp b/src/fuse_releasedir.cpp index 83246fb7..b4a096ac 100644 --- a/src/fuse_releasedir.cpp +++ b/src/fuse_releasedir.cpp @@ -34,7 +34,7 @@ namespace l namespace FUSE { int - releasedir(fuse_file_info *ffi_) + releasedir(const fuse_file_info_t *ffi_) { DirInfo *di = reinterpret_cast(ffi_->fh); diff --git a/src/fuse_releasedir.hpp b/src/fuse_releasedir.hpp index 579e0d1b..caf7acce 100644 --- a/src/fuse_releasedir.hpp +++ b/src/fuse_releasedir.hpp @@ -21,5 +21,5 @@ namespace FUSE { int - releasedir(fuse_file_info *ffi); + releasedir(const fuse_file_info_t *ffi); } diff --git a/src/fuse_write.cpp b/src/fuse_write.cpp index 3dfe4195..9dbad931 100644 --- a/src/fuse_write.cpp +++ b/src/fuse_write.cpp @@ -102,11 +102,11 @@ namespace l static int - write(WriteFunc func_, - const char *buf_, - const size_t count_, - const off_t offset_, - fuse_file_info *ffi_) + write(const fuse_file_info_t *ffi_, + WriteFunc func_, + const char *buf_, + const size_t count_, + const off_t offset_) { int rv; FileInfo* fi; @@ -124,10 +124,10 @@ namespace l namespace FUSE { int - write(const char *buf_, - size_t count_, - off_t offset_, - fuse_file_info *ffi_) + write(const fuse_file_info_t *ffi_, + const char *buf_, + size_t count_, + off_t offset_) { WriteFunc wf; @@ -135,14 +135,14 @@ namespace FUSE l::write_direct_io : l::write_regular); - return l::write(wf,buf_,count_,offset_,ffi_); + return l::write(ffi_,wf,buf_,count_,offset_); } int - write_null(const char *buf_, - size_t count_, - off_t offset_, - fuse_file_info *ffi_) + write_null(const fuse_file_info_t *ffi_, + const char *buf_, + size_t count_, + off_t offset_) { return count_; } diff --git a/src/fuse_write.hpp b/src/fuse_write.hpp index a94ad55b..7d439b7c 100644 --- a/src/fuse_write.hpp +++ b/src/fuse_write.hpp @@ -21,14 +21,14 @@ namespace FUSE { int - write(const char *buf, - size_t count, - off_t offset, - fuse_file_info *ffi); + write(const fuse_file_info_t *ffi, + const char *buf, + size_t count, + off_t offset); int - write_null(const char *buf, - size_t count, - off_t offset, - fuse_file_info *ffi); + write_null(const fuse_file_info_t *ffi, + const char *buf, + size_t count, + off_t offset); } diff --git a/src/fuse_write_buf.cpp b/src/fuse_write_buf.cpp index 7c88a006..899e377e 100644 --- a/src/fuse_write_buf.cpp +++ b/src/fuse_write_buf.cpp @@ -86,9 +86,9 @@ namespace l namespace FUSE { int - write_buf(fuse_bufvec *src_, - off_t offset_, - fuse_file_info *ffi_) + write_buf(const fuse_file_info_t *ffi_, + fuse_bufvec *src_, + off_t offset_) { int rv; FileInfo *fi = reinterpret_cast(ffi_->fh); @@ -101,9 +101,9 @@ namespace FUSE } int - write_buf_null(fuse_bufvec *src_, - off_t offset_, - fuse_file_info *ffi_) + write_buf_null(const fuse_file_info_t *ffi_, + fuse_bufvec *src_, + off_t offset_) { return src_->buf[0].size; } diff --git a/src/fuse_write_buf.hpp b/src/fuse_write_buf.hpp index 1e1a403e..cf225918 100644 --- a/src/fuse_write_buf.hpp +++ b/src/fuse_write_buf.hpp @@ -23,12 +23,12 @@ namespace FUSE { int - write_buf(struct fuse_bufvec *buf, - off_t offset, - fuse_file_info *ffi); + write_buf(const fuse_file_info_t *ffi, + struct fuse_bufvec *buf, + off_t offset); int - write_buf_null(struct fuse_bufvec *buf, - off_t offset, - fuse_file_info *ffi); + write_buf_null(const fuse_file_info_t *ffi, + struct fuse_bufvec *buf, + off_t offset); }