Browse Source

Merge pull request #809 from trapexit/libfuse-cleanup

Libfuse cleanup
pull/810/head
trapexit 4 years ago
committed by GitHub
parent
commit
17925c4c93
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      libfuse/Makefile
  2. 11
      libfuse/fuse.pc.in
  3. 17
      libfuse/include/Makefile.am
  4. 87
      libfuse/include/cuse_lowlevel.h
  5. 9
      libfuse/include/extern_c.h
  6. 178
      libfuse/include/fuse.h
  7. 59
      libfuse/include/fuse_common.h
  8. 26
      libfuse/include/fuse_common_compat.h
  9. 196
      libfuse/include/fuse_compat.h
  10. 14
      libfuse/include/fuse_dirents.h
  11. 105
      libfuse/include/fuse_lowlevel.h
  12. 155
      libfuse/include/fuse_lowlevel_compat.h
  13. 16
      libfuse/include/fuse_opt.h
  14. 10
      libfuse/include/fuse_timeouts.h
  15. 9
      libfuse/include/old/fuse.h
  16. 24
      libfuse/include/ulockmgr.h
  17. 42
      libfuse/lib/Makefile.am
  18. 371
      libfuse/lib/cuse_lowlevel.c
  19. 514
      libfuse/lib/fuse.c
  20. 28
      libfuse/lib/fuse_i.h
  21. 2
      libfuse/lib/fuse_kern_chan.c
  22. 46
      libfuse/lib/fuse_loop.c
  23. 275
      libfuse/lib/fuse_lowlevel.c
  24. 7
      libfuse/lib/fuse_mt.c
  25. 23
      libfuse/lib/fuse_opt.c
  26. 33
      libfuse/lib/fuse_session.c
  27. 1
      libfuse/lib/fuse_signals.c
  28. 207
      libfuse/lib/fuse_versionscript
  29. 137
      libfuse/lib/helper.c
  30. 57
      libfuse/lib/mount_bsd.c
  31. 44
      libfuse/lib/mount_generic.c
  32. 444
      libfuse/lib/ulockmgr.c
  33. 58
      libfuse/util/Makefile.am
  34. 89
      libfuse/util/init_script
  35. 1
      libfuse/util/udev.rules
  36. 425
      libfuse/util/ulockmgr_server.c

2
libfuse/Makefile

@ -33,11 +33,9 @@ AR ?= ar
SRC = \ SRC = \
lib/buffer.c \ lib/buffer.c \
lib/cuse_lowlevel.c \
lib/fuse_dirents.c \ lib/fuse_dirents.c \
lib/fuse.c \ lib/fuse.c \
lib/fuse_kern_chan.c \ lib/fuse_kern_chan.c \
lib/fuse_loop.c \
lib/fuse_loop_mt.c \ lib/fuse_loop_mt.c \
lib/fuse_lowlevel.c \ lib/fuse_lowlevel.c \
lib/fuse_mt.c \ lib/fuse_mt.c \

11
libfuse/fuse.pc.in

@ -1,11 +0,0 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: fuse
Description: Filesystem in Userspace
Version: @VERSION@
Libs: -L${libdir} -lfuse -pthread
Libs.private: @libfuse_libs@
Cflags: -I${includedir}/fuse -D_FILE_OFFSET_BITS=64

17
libfuse/include/Makefile.am

@ -1,17 +0,0 @@
## Process this file with automake to produce Makefile.in
fuseincludedir=$(includedir)/fuse
fuseinclude_HEADERS = \
fuse.h \
fuse_compat.h \
fuse_common.h \
fuse_common_compat.h \
fuse_lowlevel.h \
fuse_lowlevel_compat.h \
fuse_opt.h \
cuse_lowlevel.h
include_HEADERS = old/fuse.h ulockmgr.h
noinst_HEADERS = fuse_kernel.h

87
libfuse/include/cuse_lowlevel.h

@ -1,87 +0,0 @@
/*
CUSE: Character device in Userspace
Copyright (C) 2008-2009 SUSE Linux Products GmbH
Copyright (C) 2008-2009 Tejun Heo <tj@kernel.org>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
Read example/cusexmp.c for usages.
*/
#ifndef _CUSE_LOWLEVEL_H_
#define _CUSE_LOWLEVEL_H_
#ifndef FUSE_USE_VERSION
#define FUSE_USE_VERSION 29
#endif
#include "fuse_lowlevel.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/uio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CUSE_UNRESTRICTED_IOCTL (1 << 0) /* use unrestricted ioctl */
struct fuse_session;
struct cuse_info {
unsigned dev_major;
unsigned dev_minor;
unsigned dev_info_argc;
const char **dev_info_argv;
unsigned flags;
};
/*
* Most ops behave almost identically to the matching fuse_lowlevel
* ops except that they don't take @ino.
*
* init_done : called after initialization is complete
* read/write : always direct IO, simultaneous operations allowed
* ioctl : might be in unrestricted mode depending on ci->flags
*/
struct cuse_lowlevel_ops {
void (*init) (void *userdata, struct fuse_conn_info *conn);
void (*init_done) (void *userdata);
void (*destroy) (void *userdata);
void (*open) (fuse_req_t req, struct fuse_file_info *fi);
void (*read) (fuse_req_t req, size_t size, off_t off,
struct fuse_file_info *fi);
void (*write) (fuse_req_t req, const char *buf, size_t size, off_t off,
struct fuse_file_info *fi);
void (*flush) (fuse_req_t req, struct fuse_file_info *fi);
void (*release) (fuse_req_t req, struct fuse_file_info *fi);
void (*fsync) (fuse_req_t req, int datasync, struct fuse_file_info *fi);
void (*ioctl) (fuse_req_t req, int cmd, void *arg,
struct fuse_file_info *fi, unsigned int flags,
const void *in_buf, size_t in_bufsz, size_t out_bufsz);
void (*poll) (fuse_req_t req, struct fuse_file_info *fi,
struct fuse_pollhandle *ph);
};
struct fuse_session *cuse_lowlevel_new(struct fuse_args *args,
const struct cuse_info *ci,
const struct cuse_lowlevel_ops *clop,
void *userdata);
struct fuse_session *cuse_lowlevel_setup(int argc, char *argv[],
const struct cuse_info *ci,
const struct cuse_lowlevel_ops *clop,
int *multithreaded, void *userdata);
void cuse_lowlevel_teardown(struct fuse_session *se);
int cuse_lowlevel_main(int argc, char *argv[], const struct cuse_info *ci,
const struct cuse_lowlevel_ops *clop, void *userdata);
#ifdef __cplusplus
}
#endif
#endif /* _CUSE_LOWLEVEL_H_ */

9
libfuse/include/extern_c.h

@ -0,0 +1,9 @@
#pragma once
#ifdef __cplusplus
#define EXTERN_C_BEGIN extern "C" {
#define EXTERN_C_END }
#else
#define EXTERN_C_BEGIN
#define EXTERN_C_END
#endif

178
libfuse/include/fuse.h

@ -23,6 +23,7 @@
#define FUSE_USE_VERSION 21 #define FUSE_USE_VERSION 21
#endif #endif
#include "extern_c.h"
#include "fuse_common.h" #include "fuse_common.h"
#include "fuse_dirents.h" #include "fuse_dirents.h"
@ -34,9 +35,7 @@
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include <sys/uio.h> #include <sys/uio.h>
#ifdef __cplusplus
extern "C" {
#endif
EXTERN_C_BEGIN
/* ----------------------------------------------------------- * /* ----------------------------------------------------------- *
* Basic FUSE API * * Basic FUSE API *
@ -70,7 +69,8 @@ struct fuse_cmd;
* See http://fuse.sourceforge.net/wiki/ for more information. There * See http://fuse.sourceforge.net/wiki/ for more information. There
* is also a snapshot of the relevant wiki pages in the doc/ folder. * is also a snapshot of the relevant wiki pages in the doc/ folder.
*/ */
struct fuse_operations {
struct fuse_operations
{
/** Get file attributes. /** Get file attributes.
* *
* Similar to stat(). The 'st_dev' and 'st_blksize' fields are * Similar to stat(). The 'st_dev' and 'st_blksize' fields are
@ -560,16 +560,14 @@ struct fuse_operations {
* Copy a range of data from one file to another * Copy a range of data from one file to another
* *
* Performs an optimized copy between two file descriptors without * Performs an optimized copy between two file descriptors without
* the
* additional cost of transferring data through the FUSE kernel
* module
* to user space (glibc) and then back into the FUSE filesystem
* the additional cost of transferring data through the FUSE kernel
* module to user space (glibc) and then back into the FUSE filesystem
* again. * again.
* *
* In case this method is not implemented, glibc falls back to * In case this method is not implemented, glibc falls back to
* reading
* data from the source and writing to the destination. Effectively
* doing an inefficient copy of the data.
* reading data from the source and writing to the
* destination. Effectively doing an inefficient copy of the
* data.
*/ */
ssize_t (*copy_file_range)(struct fuse_file_info *fi_in, ssize_t (*copy_file_range)(struct fuse_file_info *fi_in,
off_t offset_in, off_t offset_in,
@ -584,7 +582,8 @@ struct fuse_operations {
* The uid, gid and pid fields are not filled in case of a writepage * The uid, gid and pid fields are not filled in case of a writepage
* operation. * operation.
*/ */
struct fuse_context {
struct fuse_context
{
/** Pointer to the fuse object */ /** Pointer to the fuse object */
struct fuse *fuse; struct fuse *fuse;
@ -664,17 +663,6 @@ struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
*/ */
void fuse_destroy(struct fuse *f); void fuse_destroy(struct fuse *f);
/**
* FUSE event loop.
*
* Requests from the kernel are processed, and the appropriate
* operations are called.
*
* @param f the FUSE handle
* @return 0 if no error occurred, -1 otherwise
*/
int fuse_loop(struct fuse *f);
/** /**
* Exit from event loop * Exit from event loop
* *
@ -682,17 +670,7 @@ int fuse_loop(struct fuse *f);
*/ */
void fuse_exit(struct fuse *f); void fuse_exit(struct fuse *f);
void fuse_config_set_entry_timeout(struct fuse *fuse_,
const double entry_timeout_);
void fuse_config_set_negative_entry_timeout(struct fuse *fuse_,
const double entry_timeout_);
void fuse_config_set_attr_timeout(struct fuse *fuse_,
const double attr_timeout_);
int fuse_config_num_threads(const struct fuse *fuse_); int fuse_config_num_threads(const struct fuse *fuse_);
double fuse_config_get_entry_timeout(const struct fuse *fuse_);
double fuse_config_get_negative_entry_timeout(const struct fuse *fuse_);
double fuse_config_get_attr_timeout(const struct fuse *fuse_);
/** /**
* FUSE event loop with multiple threads * FUSE event loop with multiple threads
@ -719,26 +697,6 @@ int fuse_loop_mt(struct fuse *f);
*/ */
struct fuse_context *fuse_get_context(void); struct fuse_context *fuse_get_context(void);
/**
* Get the current supplementary group IDs for the current request
*
* Similar to the getgroups(2) system call, except the return value is
* always the total number of group IDs, even if it is larger than the
* specified size.
*
* The current fuse kernel module in linux (as of 2.6.30) doesn't pass
* the group list to userspace, hence this function needs to parse
* "/proc/$TID/task/$TID/status" to get the group IDs.
*
* This feature may not be supported on all operating systems. In
* such a case this function will return -ENOSYS.
*
* @param size size of given array
* @param list array of group IDs to be filled in
* @return the total number of supplementary group IDs or -errno on failure
*/
int fuse_getgroups(int size, gid_t list[]);
/** /**
* Check if the current request has already been interrupted * Check if the current request has already been interrupted
* *
@ -920,67 +878,6 @@ int fuse_notify_poll(struct fuse_pollhandle *ph);
struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size, struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
void *user_data); void *user_data);
/**
* Filesystem module
*
* Filesystem modules are registered with the FUSE_REGISTER_MODULE()
* macro.
*
* If the "-omodules=modname:..." option is present, filesystem
* objects are created and pushed onto the stack with the 'factory'
* function.
*/
struct fuse_module {
/**
* Name of filesystem
*/
const char *name;
/**
* Factory for creating filesystem objects
*
* The function may use and remove options from 'args' that belong
* to this module.
*
* For now the 'fs' vector always contains exactly one filesystem.
* This is the filesystem which will be below the newly created
* filesystem in the stack.
*
* @param args the command line arguments
* @param fs NULL terminated filesystem object vector
* @return the new filesystem object
*/
struct fuse_fs *(*factory)(struct fuse_args *args,
struct fuse_fs *fs[]);
struct fuse_module *next;
struct fusemod_so *so;
int ctr;
};
/**
* Register a filesystem module
*
* This function is used by FUSE_REGISTER_MODULE and there's usually
* no need to call it directly
*/
void fuse_register_module(struct fuse_module *mod);
/**
* Register filesystem module
*
* For the parameters, see description of the fields in 'struct
* fuse_module'
*/
#define FUSE_REGISTER_MODULE(name_, factory_) \
static __attribute__((constructor)) void name_ ## _register(void) \
{ \
static struct fuse_module mod = \
{ #name_, factory_, NULL, NULL, 0 }; \
fuse_register_module(&mod); \
}
/* ----------------------------------------------------------- * /* ----------------------------------------------------------- *
* Advanced API for event handling, don't worry about this... * * Advanced API for event handling, don't worry about this... *
* ----------------------------------------------------------- */ * ----------------------------------------------------------- */
@ -994,7 +891,7 @@ typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
/** This is the part of fuse_main() before the event loop */ /** This is the part of fuse_main() before the event loop */
struct fuse *fuse_setup(int argc, char *argv[], struct fuse *fuse_setup(int argc, char *argv[],
const struct fuse_operations *op, size_t op_size, const struct fuse_operations *op, size_t op_size,
char **mountpoint, int *multithreaded,
char **mountpoint,
void *user_data); void *user_data);
/** This is the part of fuse_main() after the event loop */ /** This is the part of fuse_main() after the event loop */
@ -1020,55 +917,6 @@ void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
/** Get session from fuse object */ /** Get session from fuse object */
struct fuse_session *fuse_get_session(struct fuse *f); struct fuse_session *fuse_get_session(struct fuse *f);
/* ----------------------------------------------------------- *
* Compatibility stuff *
* ----------------------------------------------------------- */
#if FUSE_USE_VERSION < 26
# include "fuse_compat.h"
# undef fuse_main
# if FUSE_USE_VERSION == 25
# define fuse_main(argc, argv, op) \
fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
# define fuse_new fuse_new_compat25
# define fuse_setup fuse_setup_compat25
# define fuse_teardown fuse_teardown_compat22
# define fuse_operations fuse_operations_compat25
# elif FUSE_USE_VERSION == 22
# define fuse_main(argc, argv, op) \
fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
# define fuse_new fuse_new_compat22
# define fuse_setup fuse_setup_compat22
# define fuse_teardown fuse_teardown_compat22
# define fuse_operations fuse_operations_compat22
# define fuse_file_info fuse_file_info_compat
# elif FUSE_USE_VERSION == 24
# error Compatibility with high-level API version 24 not supported
# else
# define fuse_dirfil_t fuse_dirfil_t_compat
# define __fuse_read_cmd fuse_read_cmd
# define __fuse_process_cmd fuse_process_cmd
# define __fuse_loop_mt fuse_loop_mt_proc
# if FUSE_USE_VERSION == 21
# define fuse_operations fuse_operations_compat2
# define fuse_main fuse_main_compat2
# define fuse_new fuse_new_compat2
# define __fuse_setup fuse_setup_compat2
# define __fuse_teardown fuse_teardown_compat22
# define __fuse_exited fuse_exited
# define __fuse_set_getcontext_func fuse_set_getcontext_func
# else
# define fuse_statfs fuse_statfs_compat1
# define fuse_operations fuse_operations_compat1
# define fuse_main fuse_main_compat1
# define fuse_new fuse_new_compat1
# define FUSE_DEBUG FUSE_DEBUG_COMPAT1
# endif
# endif
#endif
#ifdef __cplusplus
}
#endif
EXTERN_C_END
#endif /* _FUSE_H_ */ #endif /* _FUSE_H_ */

59
libfuse/include/fuse_common.h

@ -15,7 +15,10 @@
#ifndef _FUSE_COMMON_H_ #ifndef _FUSE_COMMON_H_
#define _FUSE_COMMON_H_ #define _FUSE_COMMON_H_
#include "extern_c.h"
#include "fuse_opt.h" #include "fuse_opt.h"
#include "fuse_timeouts.h"
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
@ -36,16 +39,7 @@
#define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32 #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
#define FUSE_MAX_MAX_PAGES 256 #define FUSE_MAX_MAX_PAGES 256
#ifdef __cplusplus
extern "C" {
#endif
typedef struct fuse_timeouts_s fuse_timeouts_t;
struct fuse_timeouts_s
{
uint64_t entry;
uint64_t attr;
};
EXTERN_C_BEGIN
/** /**
* Information about open files * Information about open files
@ -241,7 +235,6 @@ void fuse_unmount(const char *mountpoint, struct fuse_chan *ch);
* *
* '-f' foreground * '-f' foreground
* '-d' '-odebug' foreground, but keep the debug option * '-d' '-odebug' foreground, but keep the debug option
* '-s' single threaded
* '-h' '--help' help * '-h' '--help' help
* '-ho' help without header * '-ho' help without header
* '-ofsname=..' file system name, if not present, then set to the program * '-ofsname=..' file system name, if not present, then set to the program
@ -251,12 +244,12 @@ void fuse_unmount(const char *mountpoint, struct fuse_chan *ch);
* *
* @param args argument vector * @param args argument vector
* @param mountpoint the returned mountpoint, should be freed after use * @param mountpoint the returned mountpoint, should be freed after use
* @param multithreaded set to 1 unless the '-s' option is present
* @param foreground set to 1 if one of the relevant options is present * @param foreground set to 1 if one of the relevant options is present
* @return 0 on success, -1 on failure * @return 0 on success, -1 on failure
*/ */
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
int *multithreaded, int *foreground);
int fuse_parse_cmdline(struct fuse_args *args,
char **mountpoint,
int *foreground);
/** /**
* Go into the background * Go into the background
@ -485,42 +478,6 @@ int fuse_set_signal_handlers(struct fuse_session *se);
*/ */
void fuse_remove_signal_handlers(struct fuse_session *se); void fuse_remove_signal_handlers(struct fuse_session *se);
/* ----------------------------------------------------------- *
* Compatibility stuff *
* ----------------------------------------------------------- */
#if FUSE_USE_VERSION < 26
# ifdef __FreeBSD__
# if FUSE_USE_VERSION < 25
# error On FreeBSD API version 25 or greater must be used
# endif
# endif
# include "fuse_common_compat.h"
# undef FUSE_MINOR_VERSION
# undef fuse_main
# define fuse_unmount fuse_unmount_compat22
# if FUSE_USE_VERSION == 25
# define FUSE_MINOR_VERSION 5
# define fuse_mount fuse_mount_compat25
# elif FUSE_USE_VERSION == 24 || FUSE_USE_VERSION == 22
# define FUSE_MINOR_VERSION 4
# define fuse_mount fuse_mount_compat22
# elif FUSE_USE_VERSION == 21
# define FUSE_MINOR_VERSION 1
# define fuse_mount fuse_mount_compat22
# elif FUSE_USE_VERSION == 11
# warning Compatibility with API version 11 is deprecated
# undef FUSE_MAJOR_VERSION
# define FUSE_MAJOR_VERSION 1
# define FUSE_MINOR_VERSION 1
# define fuse_mount fuse_mount_compat1
# else
# error Compatibility with API version other than 21, 22, 24, 25 and 11 not supported
# endif
#endif
#ifdef __cplusplus
}
#endif
EXTERN_C_END
#endif /* _FUSE_COMMON_H_ */ #endif /* _FUSE_COMMON_H_ */

26
libfuse/include/fuse_common_compat.h

@ -1,26 +0,0 @@
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/
/* these definitions provide source compatibility to prior versions.
Do not include this file directly! */
struct fuse_file_info_compat {
int flags;
unsigned long fh;
int writepage;
unsigned int direct_io : 1;
unsigned int keep_cache : 1;
};
int fuse_mount_compat25(const char *mountpoint, struct fuse_args *args);
int fuse_mount_compat22(const char *mountpoint, const char *opts);
int fuse_mount_compat1(const char *mountpoint, const char *args[]);
void fuse_unmount_compat22(const char *mountpoint);

196
libfuse/include/fuse_compat.h

@ -1,196 +0,0 @@
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/
/* these definitions provide source compatibility to prior versions.
Do not include this file directly! */
struct fuse_operations_compat25 {
int (*getattr) (const char *, struct stat *);
int (*readlink) (const char *, char *, size_t);
int (*mknod) (const char *, mode_t, dev_t);
int (*mkdir) (const char *, mode_t);
int (*unlink) (const char *);
int (*rmdir) (const char *);
int (*symlink) (const char *, const char *);
int (*rename) (const char *, const char *);
int (*link) (const char *, const char *);
int (*chmod) (const char *, mode_t);
int (*chown) (const char *, uid_t, gid_t);
int (*truncate) (const char *, off_t);
int (*utime) (const char *, struct utimbuf *);
int (*open) (const char *, struct fuse_file_info *);
int (*read) (const char *, char *, size_t, off_t,
struct fuse_file_info *);
int (*write) (const char *, const char *, size_t, off_t,
struct fuse_file_info *);
int (*statfs) (const char *, struct statvfs *);
int (*flush) (const char *, struct fuse_file_info *);
int (*release) (const char *, struct fuse_file_info *);
int (*fsync) (const char *, int, struct fuse_file_info *);
int (*setxattr) (const char *, const char *, const char *, size_t, int);
int (*getxattr) (const char *, const char *, char *, size_t);
int (*listxattr) (const char *, char *, size_t);
int (*removexattr) (const char *, const char *);
int (*opendir) (const char *, struct fuse_file_info *);
int (*readdir) (const char *, void *, off_t,
struct fuse_file_info *);
int (*releasedir) (const char *, struct fuse_file_info *);
int (*fsyncdir) (const char *, int, struct fuse_file_info *);
void *(*init) (void);
void (*destroy) (void *);
int (*access) (const char *, int);
int (*create) (const char *, mode_t, struct fuse_file_info *);
int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
};
struct fuse *fuse_new_compat25(int fd, struct fuse_args *args,
const struct fuse_operations_compat25 *op,
size_t op_size);
int fuse_main_real_compat25(int argc, char *argv[],
const struct fuse_operations_compat25 *op,
size_t op_size);
struct fuse *fuse_setup_compat25(int argc, char *argv[],
const struct fuse_operations_compat25 *op,
size_t op_size, char **mountpoint,
int *multithreaded, int *fd);
void fuse_teardown_compat22(struct fuse *fuse, int fd, char *mountpoint);
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
#include <sys/statfs.h>
struct fuse_operations_compat22 {
int (*getattr) (const char *, struct stat *);
int (*readlink) (const char *, char *, size_t);
int (*mknod) (const char *, mode_t, dev_t);
int (*mkdir) (const char *, mode_t);
int (*unlink) (const char *);
int (*rmdir) (const char *);
int (*symlink) (const char *, const char *);
int (*rename) (const char *, const char *);
int (*link) (const char *, const char *);
int (*chmod) (const char *, mode_t);
int (*chown) (const char *, uid_t, gid_t);
int (*truncate) (const char *, off_t);
int (*utime) (const char *, struct utimbuf *);
int (*open) (const char *, struct fuse_file_info_compat *);
int (*read) (const char *, char *, size_t, off_t,
struct fuse_file_info_compat *);
int (*write) (const char *, const char *, size_t, off_t,
struct fuse_file_info_compat *);
int (*statfs) (const char *, struct statfs *);
int (*flush) (const char *, struct fuse_file_info_compat *);
int (*release) (const char *, struct fuse_file_info_compat *);
int (*fsync) (const char *, int, struct fuse_file_info_compat *);
int (*setxattr) (const char *, const char *, const char *, size_t, int);
int (*getxattr) (const char *, const char *, char *, size_t);
int (*listxattr) (const char *, char *, size_t);
int (*removexattr) (const char *, const char *);
int (*opendir) (const char *, struct fuse_file_info_compat *);
int (*readdir) (const char *, void *, off_t,
struct fuse_file_info_compat *);
int (*releasedir) (const char *, struct fuse_file_info_compat *);
int (*fsyncdir) (const char *, int, struct fuse_file_info_compat *);
void *(*init) (void);
void (*destroy) (void *);
};
struct fuse *fuse_new_compat22(int fd, const char *opts,
const struct fuse_operations_compat22 *op,
size_t op_size);
struct fuse *fuse_setup_compat22(int argc, char *argv[],
const struct fuse_operations_compat22 *op,
size_t op_size, char **mountpoint,
int *multithreaded, int *fd);
int fuse_main_real_compat22(int argc, char *argv[],
const struct fuse_operations_compat22 *op,
size_t op_size);
struct fuse_operations_compat2 {
int (*getattr) (const char *, struct stat *);
int (*readlink) (const char *, char *, size_t);
int (*mknod) (const char *, mode_t, dev_t);
int (*mkdir) (const char *, mode_t);
int (*unlink) (const char *);
int (*rmdir) (const char *);
int (*symlink) (const char *, const char *);
int (*rename) (const char *, const char *);
int (*link) (const char *, const char *);
int (*chmod) (const char *, mode_t);
int (*chown) (const char *, uid_t, gid_t);
int (*truncate) (const char *, off_t);
int (*utime) (const char *, struct utimbuf *);
int (*open) (const char *, int);
int (*read) (const char *, char *, size_t, off_t);
int (*write) (const char *, const char *, size_t, off_t);
int (*statfs) (const char *, struct statfs *);
int (*flush) (const char *);
int (*release) (const char *, int);
int (*fsync) (const char *, int);
int (*setxattr) (const char *, const char *, const char *,
size_t, int);
int (*getxattr) (const char *, const char *, char *, size_t);
int (*listxattr) (const char *, char *, size_t);
int (*removexattr) (const char *, const char *);
};
int fuse_main_compat2(int argc, char *argv[],
const struct fuse_operations_compat2 *op);
struct fuse *fuse_new_compat2(int fd, const char *opts,
const struct fuse_operations_compat2 *op);
struct fuse *fuse_setup_compat2(int argc, char *argv[],
const struct fuse_operations_compat2 *op,
char **mountpoint, int *multithreaded, int *fd);
struct fuse_statfs_compat1 {
long block_size;
long blocks;
long blocks_free;
long files;
long files_free;
long namelen;
};
struct fuse_operations_compat1 {
int (*getattr) (const char *, struct stat *);
int (*readlink) (const char *, char *, size_t);
int (*mknod) (const char *, mode_t, dev_t);
int (*mkdir) (const char *, mode_t);
int (*unlink) (const char *);
int (*rmdir) (const char *);
int (*symlink) (const char *, const char *);
int (*rename) (const char *, const char *);
int (*link) (const char *, const char *);
int (*chmod) (const char *, mode_t);
int (*chown) (const char *, uid_t, gid_t);
int (*truncate) (const char *, off_t);
int (*utime) (const char *, struct utimbuf *);
int (*open) (const char *, int);
int (*read) (const char *, char *, size_t, off_t);
int (*write) (const char *, const char *, size_t, off_t);
int (*statfs) (struct fuse_statfs_compat1 *);
int (*release) (const char *, int);
int (*fsync) (const char *, int);
};
#define FUSE_DEBUG_COMPAT1 (1 << 1)
struct fuse *fuse_new_compat1(int fd, int flags,
const struct fuse_operations_compat1 *op);
void fuse_main_compat1(int argc, char *argv[],
const struct fuse_operations_compat1 *op);
#endif /* __FreeBSD__ || __NetBSD__ */

14
libfuse/include/fuse_dirents.h

@ -18,9 +18,9 @@
#pragma once #pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "extern_c.h"
EXTERN_C_BEGIN
#include "kvec.h" #include "kvec.h"
#include "fuse_dirent.h" #include "fuse_dirent.h"
@ -36,11 +36,11 @@ extern "C" {
#include <unistd.h> #include <unistd.h>
enum fuse_dirents_type_e enum fuse_dirents_type_e
{
{
UNSET = 0, UNSET = 0,
NORMAL, NORMAL,
PLUS PLUS
};
};
typedef enum fuse_dirents_type_e fuse_dirents_type_t; typedef enum fuse_dirents_type_e fuse_dirents_type_t;
typedef struct fuse_dirents_s fuse_dirents_t; typedef struct fuse_dirents_s fuse_dirents_t;
@ -79,6 +79,4 @@ void *fuse_dirents_find(fuse_dirents_t *d,
int fuse_dirents_convert_plus2normal(fuse_dirents_t *d); int fuse_dirents_convert_plus2normal(fuse_dirents_t *d);
#ifdef __cplusplus
}
#endif
EXTERN_C_END

105
libfuse/include/fuse_lowlevel.h

@ -23,6 +23,7 @@
#define FUSE_USE_VERSION 24 #define FUSE_USE_VERSION 24
#endif #endif
#include "extern_c.h"
#include "fuse_common.h" #include "fuse_common.h"
#include <fcntl.h> #include <fcntl.h>
@ -33,9 +34,7 @@
#include <sys/uio.h> #include <sys/uio.h>
#include <utime.h> #include <utime.h>
#ifdef __cplusplus
extern "C" {
#endif
EXTERN_C_BEGIN
/* ----------------------------------------------------------- * /* ----------------------------------------------------------- *
* Miscellaneous definitions * * Miscellaneous definitions *
@ -66,17 +65,18 @@ struct fuse_session;
struct fuse_chan; struct fuse_chan;
/** Directory entry parameters supplied to fuse_reply_entry() */ /** Directory entry parameters supplied to fuse_reply_entry() */
struct fuse_entry_param {
/** Unique inode number
struct fuse_entry_param
{
/** Unique inode number
* *
* In lookup, zero means negative entry (from version 2.5) * In lookup, zero means negative entry (from version 2.5)
* Returning ENOENT also means negative entry, but by setting zero * Returning ENOENT also means negative entry, but by setting zero
* ino the kernel may cache negative entries for entry_timeout * ino the kernel may cache negative entries for entry_timeout
* seconds. * seconds.
*/ */
fuse_ino_t ino;
fuse_ino_t ino;
/** Generation number for this entry.
/** Generation number for this entry.
* *
* If the file system will be exported over NFS, the * If the file system will be exported over NFS, the
* ino/generation pairs need to be unique over the file * ino/generation pairs need to be unique over the file
@ -89,39 +89,41 @@ struct fuse_entry_param {
* it as an error. * it as an error.
* *
*/ */
uint64_t generation;
uint64_t generation;
/** Inode attributes.
/** Inode attributes.
* *
* Even if attr_timeout == 0, attr must be correct. For example, * Even if attr_timeout == 0, attr must be correct. For example,
* for open(), FUSE uses attr.st_size from lookup() to determine * for open(), FUSE uses attr.st_size from lookup() to determine
* how many bytes to request. If this value is not correct, * how many bytes to request. If this value is not correct,
* incorrect data will be returned. * incorrect data will be returned.
*/ */
struct stat attr;
struct stat attr;
fuse_timeouts_t timeout;
fuse_timeouts_t timeout;
}; };
/** Additional context associated with requests */ /** Additional context associated with requests */
struct fuse_ctx {
/** User ID of the calling process */
uid_t uid;
struct fuse_ctx
{
/** 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;
struct fuse_forget_data
{
fuse_ino_t ino;
uint64_t nlookup;
}; };
/* ----------------------------------------------------------- * /* ----------------------------------------------------------- *
@ -149,8 +151,9 @@ struct fuse_forget_data {
* fuse_reply_open() return -ENOENT means, that the release method for * fuse_reply_open() return -ENOENT means, that the release method for
* this file will not be called. * this file will not be called.
*/ */
struct fuse_lowlevel_ops {
/**
struct fuse_lowlevel_ops
{
/**
* Initialize filesystem * Initialize filesystem
* *
* Called before any other filesystem method * Called before any other filesystem method
@ -159,9 +162,9 @@ struct fuse_lowlevel_ops {
* *
* @param userdata the user data passed to fuse_lowlevel_new() * @param userdata the user data passed to fuse_lowlevel_new()
*/ */
void (*init) (void *userdata, struct fuse_conn_info *conn);
void (*init) (void *userdata, struct fuse_conn_info *conn);
/**
/**
* Clean up filesystem * Clean up filesystem
* *
* Called on filesystem exit * Called on filesystem exit
@ -170,9 +173,9 @@ struct fuse_lowlevel_ops {
* *
* @param userdata the user data passed to fuse_lowlevel_new() * @param userdata the user data passed to fuse_lowlevel_new()
*/ */
void (*destroy) (void *userdata);
void (*destroy) (void *userdata);
/**
/**
* Look up a directory entry by name and get its attributes. * Look up a directory entry by name and get its attributes.
* *
* Valid replies: * Valid replies:
@ -183,9 +186,9 @@ struct fuse_lowlevel_ops {
* @param parent inode number of the parent directory * @param parent inode number of the parent directory
* @param name the name to look up * @param name the name to look up
*/ */
void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
/**
/**
* Forget about an inode * Forget about an inode
* *
* This function is called when the kernel removes an inode * This function is called when the kernel removes an inode
@ -1536,7 +1539,8 @@ struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
* *
* This is used in session creation * This is used in session creation
*/ */
struct fuse_session_ops {
struct fuse_session_ops
{
/** /**
* Hook to process a request (mandatory) * Hook to process a request (mandatory)
* *
@ -1693,14 +1697,6 @@ int fuse_session_exited(struct fuse_session *se);
*/ */
void *fuse_session_data(struct fuse_session *se); void *fuse_session_data(struct fuse_session *se);
/**
* Enter a single threaded event loop
*
* @param se the session
* @return 0 on success, -1 on error
*/
int fuse_session_loop(struct fuse_session *se);
/** /**
* Enter a multi-threaded event loop * Enter a multi-threaded event loop
* *
@ -1718,7 +1714,8 @@ int fuse_session_loop_mt(struct fuse_session *se, const int threads);
* *
* This is used in channel creation * This is used in channel creation
*/ */
struct fuse_chan_ops {
struct fuse_chan_ops
{
/** /**
* Hook for receiving a raw request * Hook for receiving a raw request
* *
@ -1828,30 +1825,6 @@ int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[],
*/ */
void fuse_chan_destroy(struct fuse_chan *ch); void fuse_chan_destroy(struct fuse_chan *ch);
/* ----------------------------------------------------------- *
* Compatibility stuff *
* ----------------------------------------------------------- */
#if FUSE_USE_VERSION < 26
# include "fuse_lowlevel_compat.h"
# define fuse_chan_ops fuse_chan_ops_compat24
# define fuse_chan_new fuse_chan_new_compat24
# if FUSE_USE_VERSION == 25
# define fuse_lowlevel_ops fuse_lowlevel_ops_compat25
# define fuse_lowlevel_new fuse_lowlevel_new_compat25
# elif FUSE_USE_VERSION == 24
# define fuse_lowlevel_ops fuse_lowlevel_ops_compat
# define fuse_lowlevel_new fuse_lowlevel_new_compat
# define fuse_file_info fuse_file_info_compat
# define fuse_reply_statfs fuse_reply_statfs_compat
# define fuse_reply_open fuse_reply_open_compat
# else
# error Compatibility with low-level API version < 24 not supported
# endif
#endif
#ifdef __cplusplus
}
#endif
EXTERN_C_END
#endif /* _FUSE_LOWLEVEL_H_ */ #endif /* _FUSE_LOWLEVEL_H_ */

155
libfuse/include/fuse_lowlevel_compat.h

@ -1,155 +0,0 @@
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/
/* these definitions provide source compatibility to prior versions.
Do not include this file directly! */
struct fuse_lowlevel_ops_compat25 {
void (*init) (void *userdata);
void (*destroy) (void *userdata);
void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
void (*forget) (fuse_req_t req, fuse_ino_t ino, unsigned long nlookup);
void (*getattr) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi);
void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
int to_set, struct fuse_file_info *fi);
void (*readlink) (fuse_req_t req, fuse_ino_t ino);
void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode, dev_t rdev);
void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode);
void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
const char *name);
void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
fuse_ino_t newparent, const char *newname);
void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
const char *newname);
void (*open) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi);
void (*read) (fuse_req_t req, fuse_ino_t ino, 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, struct fuse_file_info *fi);
void (*flush) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi);
void (*release) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi);
void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
struct fuse_file_info *fi);
void (*opendir) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi);
void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
struct fuse_file_info *fi);
void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi);
void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
struct fuse_file_info *fi);
void (*statfs) (fuse_req_t req);
void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
const char *value, size_t size, int flags);
void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
size_t size);
void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode, struct fuse_file_info *fi);
};
struct fuse_session *fuse_lowlevel_new_compat25(struct fuse_args *args,
const struct fuse_lowlevel_ops_compat25 *op,
size_t op_size, void *userdata);
size_t fuse_dirent_size(size_t namelen);
char *fuse_add_dirent(char *buf, const char *name, const struct stat *stbuf,
off_t off);
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
#include <sys/statfs.h>
struct fuse_lowlevel_ops_compat {
void (*init) (void *userdata);
void (*destroy) (void *userdata);
void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
void (*forget) (fuse_req_t req, fuse_ino_t ino, unsigned long nlookup);
void (*getattr) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info_compat *fi);
void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
int to_set, struct fuse_file_info_compat *fi);
void (*readlink) (fuse_req_t req, fuse_ino_t ino);
void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode, dev_t rdev);
void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode);
void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
const char *name);
void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
fuse_ino_t newparent, const char *newname);
void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
const char *newname);
void (*open) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info_compat *fi);
void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
struct fuse_file_info_compat *fi);
void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
size_t size, off_t off, struct fuse_file_info_compat *fi);
void (*flush) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info_compat *fi);
void (*release) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info_compat *fi);
void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
struct fuse_file_info_compat *fi);
void (*opendir) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info_compat *fi);
void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
struct fuse_file_info_compat *fi);
void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info_compat *fi);
void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
struct fuse_file_info_compat *fi);
void (*statfs) (fuse_req_t req);
void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
const char *value, size_t size, int flags);
void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
size_t size);
void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode, struct fuse_file_info_compat *fi);
};
int fuse_reply_statfs_compat(fuse_req_t req, const struct statfs *stbuf);
int fuse_reply_open_compat(fuse_req_t req,
const struct fuse_file_info_compat *fi);
struct fuse_session *fuse_lowlevel_new_compat(const char *opts,
const struct fuse_lowlevel_ops_compat *op,
size_t op_size, void *userdata);
#endif /* __FreeBSD__ || __NetBSD__ */
struct fuse_chan_ops_compat24 {
int (*receive)(struct fuse_chan *ch, char *buf, size_t size);
int (*send)(struct fuse_chan *ch, const struct iovec iov[],
size_t count);
void (*destroy)(struct fuse_chan *ch);
};
struct fuse_chan *fuse_chan_new_compat24(struct fuse_chan_ops_compat24 *op,
int fd, size_t bufsize, void *data);
int fuse_chan_receive(struct fuse_chan *ch, char *buf, size_t size);
struct fuse_chan *fuse_kern_chan_new(int fd);

16
libfuse/include/fuse_opt.h

@ -9,14 +9,14 @@
#ifndef _FUSE_OPT_H_ #ifndef _FUSE_OPT_H_
#define _FUSE_OPT_H_ #define _FUSE_OPT_H_
#include "extern_c.h"
/** @file /** @file
* *
* This file defines the option parsing interface of FUSE * This file defines the option parsing interface of FUSE
*/ */
#ifdef __cplusplus
extern "C" {
#endif
EXTERN_C_BEGIN
/** /**
* Option description * Option description
@ -73,7 +73,8 @@ extern "C" {
* If the format is "%s", memory is allocated for the string unlike * If the format is "%s", memory is allocated for the string unlike
* with scanf(). * with scanf().
*/ */
struct fuse_opt {
struct fuse_opt
{
/** Matching template and optional parameter formatting */ /** Matching template and optional parameter formatting */
const char *templ; const char *templ;
@ -105,7 +106,8 @@ struct fuse_opt {
/** /**
* Argument list * Argument list
*/ */
struct fuse_args {
struct fuse_args
{
/** Argument count */ /** Argument count */
int argc; int argc;
@ -263,8 +265,6 @@ void fuse_opt_free_args(struct fuse_args *args);
*/ */
int fuse_opt_match(const struct fuse_opt opts[], const char *opt); int fuse_opt_match(const struct fuse_opt opts[], const char *opt);
#ifdef __cplusplus
}
#endif
EXTERN_C_END
#endif /* _FUSE_OPT_H_ */ #endif /* _FUSE_OPT_H_ */

10
libfuse/include/fuse_timeouts.h

@ -0,0 +1,10 @@
#pragma once
#include <stdint.h>
typedef struct fuse_timeouts_s fuse_timeouts_t;
struct fuse_timeouts_s
{
uint64_t entry;
uint64_t attr;
};

9
libfuse/include/old/fuse.h

@ -1,9 +0,0 @@
/*
This header is for compatibility with older software using FUSE.
Please use 'pkg-config --cflags fuse' to set include path. The
correct usage is still '#include <fuse.h>', not '#include
<fuse/fuse.h>'.
*/
#include "fuse/fuse.h"

24
libfuse/include/ulockmgr.h

@ -1,24 +0,0 @@
/*
libulockmgr: Userspace Lock Manager Library
Copyright (C) 2006 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/
#include <stdint.h>
#include <fcntl.h>
#include <sys/types.h>
/**
* Perform POSIX locking operation
*
* @param fd the file descriptor
* @param cmd the locking command (F_GETFL, F_SETLK or F_SETLKW)
* @param lock the lock parameters
* @param owner the lock owner ID cookie
* @param owner_len length of the lock owner ID cookie
* @return 0 on success -errno on error
*/
int ulockmgr_op(int fd, int cmd, struct flock *lock, const void *owner,
size_t owner_len);

42
libfuse/lib/Makefile.am

@ -1,42 +0,0 @@
## Process this file with automake to produce Makefile.in
AUTOMAKE_OPTIONS = subdir-objects
AM_CPPFLAGS = -I$(top_srcdir)/include -DFUSERMOUNT_DIR=\"$(bindir)\" \
-D_FILE_OFFSET_BITS=64 -D_REENTRANT -DFUSE_USE_VERSION=26
lib_LTLIBRARIES = libfuse.la libulockmgr.la
if BSD
mount_source = mount_bsd.c
else
mount_source = mount.c mount_util.c mount_util.h
endif
libfuse_la_SOURCES = \
fuse.c \
fuse_i.h \
fuse_kern_chan.c \
fuse_loop.c \
fuse_loop_mt.c \
fuse_lowlevel.c \
fuse_misc.h \
fuse_mt.c \
fuse_opt.c \
fuse_session.c \
fuse_signals.c \
buffer.c \
cuse_lowlevel.c \
helper.c \
$(mount_source)
libfuse_la_LDFLAGS = -pthread @libfuse_libs@ -version-number 2:9:7 \
-Wl,--version-script,$(srcdir)/fuse_versionscript
if NETBSD
libfuse_la_LIBADD = -lperfuse -lpuffs
endif
libulockmgr_la_SOURCES = ulockmgr.c
libulockmgr_la_LDFLAGS = -pthread -version-number 1:0:1
EXTRA_DIST = fuse_versionscript

371
libfuse/lib/cuse_lowlevel.c

@ -1,371 +0,0 @@
/*
CUSE: Character device in Userspace
Copyright (C) 2008 SUSE Linux Products GmbH
Copyright (C) 2008 Tejun Heo <teheo@suse.de>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/
#include "cuse_lowlevel.h"
#include "fuse_kernel.h"
#include "fuse_i.h"
#include "fuse_opt.h"
#include "fuse_misc.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <errno.h>
#include <unistd.h>
struct cuse_data {
struct cuse_lowlevel_ops clop;
unsigned max_read;
unsigned dev_major;
unsigned dev_minor;
unsigned flags;
unsigned dev_info_len;
char dev_info[];
};
static struct cuse_lowlevel_ops *req_clop(fuse_req_t req)
{
return &req->f->cuse_data->clop;
}
static void cuse_fll_open(fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi)
{
(void)ino;
req_clop(req)->open(req, fi);
}
static void cuse_fll_read(fuse_req_t req, fuse_ino_t ino, size_t size,
off_t off, struct fuse_file_info *fi)
{
(void)ino;
req_clop(req)->read(req, size, off, fi);
}
static void cuse_fll_write(fuse_req_t req, fuse_ino_t ino, const char *buf,
size_t size, off_t off, struct fuse_file_info *fi)
{
(void)ino;
req_clop(req)->write(req, buf, size, off, fi);
}
static void cuse_fll_flush(fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi)
{
(void)ino;
req_clop(req)->flush(req, fi);
}
static void cuse_fll_release(fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi)
{
(void)ino;
req_clop(req)->release(req, fi);
}
static void cuse_fll_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,
struct fuse_file_info *fi)
{
(void)ino;
req_clop(req)->fsync(req, datasync, fi);
}
static void cuse_fll_ioctl(fuse_req_t req, fuse_ino_t ino, int cmd, void *arg,
struct fuse_file_info *fi, unsigned int flags,
const void *in_buf, size_t in_bufsz, size_t out_bufsz)
{
(void)ino;
req_clop(req)->ioctl(req, cmd, arg, fi, flags, in_buf, in_bufsz,
out_bufsz);
}
static void cuse_fll_poll(fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi, struct fuse_pollhandle *ph)
{
(void)ino;
req_clop(req)->poll(req, fi, ph);
}
static size_t cuse_pack_info(int argc, const char **argv, char *buf)
{
size_t size = 0;
int i;
for (i = 0; i < argc; i++) {
size_t len;
len = strlen(argv[i]) + 1;
size += len;
if (buf) {
memcpy(buf, argv[i], len);
buf += len;
}
}
return size;
}
static struct cuse_data *cuse_prep_data(const struct cuse_info *ci,
const struct cuse_lowlevel_ops *clop)
{
struct cuse_data *cd;
size_t dev_info_len;
dev_info_len = cuse_pack_info(ci->dev_info_argc, ci->dev_info_argv,
NULL);
if (dev_info_len > CUSE_INIT_INFO_MAX) {
fprintf(stderr, "cuse: dev_info (%zu) too large, limit=%u\n",
dev_info_len, CUSE_INIT_INFO_MAX);
return NULL;
}
cd = calloc(1, sizeof(*cd) + dev_info_len);
if (!cd) {
fprintf(stderr, "cuse: failed to allocate cuse_data\n");
return NULL;
}
memcpy(&cd->clop, clop, sizeof(cd->clop));
cd->max_read = 131072;
cd->dev_major = ci->dev_major;
cd->dev_minor = ci->dev_minor;
cd->dev_info_len = dev_info_len;
cd->flags = ci->flags;
cuse_pack_info(ci->dev_info_argc, ci->dev_info_argv, cd->dev_info);
return cd;
}
struct fuse_session *cuse_lowlevel_new(struct fuse_args *args,
const struct cuse_info *ci,
const struct cuse_lowlevel_ops *clop,
void *userdata)
{
struct fuse_lowlevel_ops lop;
struct cuse_data *cd;
struct fuse_session *se;
struct fuse_ll *ll;
cd = cuse_prep_data(ci, clop);
if (!cd)
return NULL;
memset(&lop, 0, sizeof(lop));
lop.init = clop->init;
lop.destroy = clop->destroy;
lop.open = clop->open ? cuse_fll_open : NULL;
lop.read = clop->read ? cuse_fll_read : NULL;
lop.write = clop->write ? cuse_fll_write : NULL;
lop.flush = clop->flush ? cuse_fll_flush : NULL;
lop.release = clop->release ? cuse_fll_release : NULL;
lop.fsync = clop->fsync ? cuse_fll_fsync : NULL;
lop.ioctl = clop->ioctl ? cuse_fll_ioctl : NULL;
lop.poll = clop->poll ? cuse_fll_poll : NULL;
se = fuse_lowlevel_new_common(args, &lop, sizeof(lop), userdata);
if (!se) {
free(cd);
return NULL;
}
ll = se->data;
ll->cuse_data = cd;
return se;
}
static int cuse_reply_init(fuse_req_t req, struct cuse_init_out *arg,
char *dev_info, unsigned dev_info_len)
{
struct iovec iov[3];
iov[1].iov_base = arg;
iov[1].iov_len = sizeof(struct cuse_init_out);
iov[2].iov_base = dev_info;
iov[2].iov_len = dev_info_len;
return fuse_send_reply_iov_nofree(req, 0, iov, 3);
}
void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
{
struct fuse_init_in *arg = (struct fuse_init_in *) inarg;
struct cuse_init_out outarg;
struct fuse_ll *f = req->f;
struct cuse_data *cd = f->cuse_data;
size_t bufsize = fuse_chan_bufsize(req->ch);
struct cuse_lowlevel_ops *clop = req_clop(req);
(void) nodeid;
if (f->debug) {
fprintf(stderr, "CUSE_INIT: %u.%u\n", arg->major, arg->minor);
fprintf(stderr, "flags=0x%08x\n", arg->flags);
}
f->conn.proto_major = arg->major;
f->conn.proto_minor = arg->minor;
f->conn.capable = 0;
f->conn.want = 0;
if (arg->major < 7) {
fprintf(stderr, "cuse: unsupported protocol version: %u.%u\n",
arg->major, arg->minor);
fuse_reply_err(req, EPROTO);
return;
}
if (bufsize < FUSE_MIN_READ_BUFFER) {
fprintf(stderr, "cuse: warning: buffer size too small: %zu\n",
bufsize);
bufsize = FUSE_MIN_READ_BUFFER;
}
bufsize -= 4096;
if (bufsize < f->conn.max_write)
f->conn.max_write = bufsize;
f->got_init = 1;
if (f->op.init)
f->op.init(f->userdata, &f->conn);
memset(&outarg, 0, sizeof(outarg));
outarg.major = FUSE_KERNEL_VERSION;
outarg.minor = FUSE_KERNEL_MINOR_VERSION;
outarg.flags = cd->flags;
outarg.max_read = cd->max_read;
outarg.max_write = f->conn.max_write;
outarg.dev_major = cd->dev_major;
outarg.dev_minor = cd->dev_minor;
if (f->debug) {
fprintf(stderr, " CUSE_INIT: %u.%u\n",
outarg.major, outarg.minor);
fprintf(stderr, " flags=0x%08x\n", outarg.flags);
fprintf(stderr, " max_read=0x%08x\n", outarg.max_read);
fprintf(stderr, " max_write=0x%08x\n", outarg.max_write);
fprintf(stderr, " dev_major=%u\n", outarg.dev_major);
fprintf(stderr, " dev_minor=%u\n", outarg.dev_minor);
fprintf(stderr, " dev_info: %.*s\n", cd->dev_info_len,
cd->dev_info);
}
cuse_reply_init(req, &outarg, cd->dev_info, cd->dev_info_len);
if (clop->init_done)
clop->init_done(f->userdata);
fuse_free_req(req);
}
struct fuse_session *cuse_lowlevel_setup(int argc, char *argv[],
const struct cuse_info *ci,
const struct cuse_lowlevel_ops *clop,
int *multithreaded, void *userdata)
{
const char *devname = "/dev/cuse";
static const struct fuse_opt kill_subtype_opts[] = {
FUSE_OPT_KEY("subtype=", FUSE_OPT_KEY_DISCARD),
FUSE_OPT_END
};
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
struct fuse_session *se;
struct fuse_chan *ch;
int fd;
int foreground;
int res;
res = fuse_parse_cmdline(&args, NULL, multithreaded, &foreground);
if (res == -1)
goto err_args;
res = fuse_opt_parse(&args, NULL, kill_subtype_opts, NULL);
if (res == -1)
goto err_args;
/*
* Make sure file descriptors 0, 1 and 2 are open, otherwise chaos
* would ensue.
*/
do {
fd = open("/dev/null", O_RDWR);
if (fd > 2)
close(fd);
} while (fd >= 0 && fd <= 2);
se = cuse_lowlevel_new(&args, ci, clop, userdata);
fuse_opt_free_args(&args);
if (se == NULL)
goto err_args;
fd = open(devname, O_RDWR);
if (fd == -1) {
if (errno == ENODEV || errno == ENOENT)
fprintf(stderr, "cuse: device not found, try 'modprobe cuse' first\n");
else
fprintf(stderr, "cuse: failed to open %s: %s\n",
devname, strerror(errno));
goto err_se;
}
ch = fuse_kern_chan_new(fd);
if (!ch) {
close(fd);
goto err_se;
}
fuse_session_add_chan(se, ch);
res = fuse_set_signal_handlers(se);
if (res == -1)
goto err_se;
res = fuse_daemonize(foreground);
if (res == -1)
goto err_sig;
return se;
err_sig:
fuse_remove_signal_handlers(se);
err_se:
fuse_session_destroy(se);
err_args:
fuse_opt_free_args(&args);
return NULL;
}
void cuse_lowlevel_teardown(struct fuse_session *se)
{
fuse_remove_signal_handlers(se);
fuse_session_destroy(se);
}
int cuse_lowlevel_main(int argc, char *argv[], const struct cuse_info *ci,
const struct cuse_lowlevel_ops *clop, void *userdata)
{
struct fuse_session *se;
int multithreaded;
int res;
se = cuse_lowlevel_setup(argc, argv, ci, clop, &multithreaded,
userdata);
if (se == NULL)
return 1;
if (multithreaded)
res = fuse_session_loop_mt(se, 0);
else
res = fuse_session_loop(se);
cuse_lowlevel_teardown(se);
if (res == -1)
return 1;
return 0;
}

514
libfuse/lib/fuse.c

@ -15,8 +15,6 @@
#include "fuse_lowlevel.h" #include "fuse_lowlevel.h"
#include "fuse_opt.h" #include "fuse_opt.h"
#include "fuse_misc.h" #include "fuse_misc.h"
#include "fuse_common_compat.h"
#include "fuse_compat.h"
#include "fuse_kernel.h" #include "fuse_kernel.h"
#include "fuse_dirents.h" #include "fuse_dirents.h"
@ -54,7 +52,8 @@
#define NODE_TABLE_MIN_SIZE 8192 #define NODE_TABLE_MIN_SIZE 8192
struct fuse_config {
struct fuse_config
{
unsigned int uid; unsigned int uid;
unsigned int gid; unsigned int gid;
unsigned int umask; unsigned int umask;
@ -70,14 +69,15 @@ struct fuse_config {
int threads; int threads;
}; };
struct fuse_fs {
struct fuse_fs
{
struct fuse_operations op; struct fuse_operations op;
void *user_data; void *user_data;
int compat;
int debug; int debug;
}; };
struct lock_queue_element {
struct lock_queue_element
{
struct lock_queue_element *next; struct lock_queue_element *next;
pthread_cond_t cond; pthread_cond_t cond;
fuse_ino_t nodeid1; fuse_ino_t nodeid1;
@ -94,7 +94,8 @@ struct lock_queue_element {
bool done : 1; bool done : 1;
}; };
struct node_table {
struct node_table
{
struct node **array; struct node **array;
size_t use; size_t use;
size_t size; size_t size;
@ -108,12 +109,14 @@ struct node_table {
#define list_entry(ptr, type, member) \ #define list_entry(ptr, type, member) \
container_of(ptr, type, member) container_of(ptr, type, member)
struct list_head {
struct list_head
{
struct list_head *next; struct list_head *next;
struct list_head *prev; struct list_head *prev;
}; };
struct node_slab {
struct node_slab
{
struct list_head list; /* must be the first member */ struct list_head list; /* must be the first member */
struct list_head freelist; struct list_head freelist;
int used; int used;
@ -139,7 +142,8 @@ struct fuse
pthread_t prune_thread; pthread_t prune_thread;
}; };
struct lock {
struct lock
{
int type; int type;
off_t start; off_t start;
off_t end; off_t end;
@ -171,7 +175,8 @@ struct node
#define TREELOCK_WRITE -1 #define TREELOCK_WRITE -1
#define TREELOCK_WAIT_OFFSET INT_MIN #define TREELOCK_WAIT_OFFSET INT_MIN
struct node_lru {
struct node_lru
{
struct node node; struct node node;
struct list_head lru; struct list_head lru;
struct timespec forget_time; struct timespec forget_time;
@ -184,7 +189,8 @@ struct fuse_dh
fuse_dirents_t d; fuse_dirents_t d;
}; };
struct fuse_context_i {
struct fuse_context_i
{
struct fuse_context ctx; struct fuse_context ctx;
fuse_req_t req; fuse_req_t req;
}; };
@ -193,18 +199,25 @@ static pthread_key_t fuse_context_key;
static pthread_mutex_t fuse_context_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t fuse_context_lock = PTHREAD_MUTEX_INITIALIZER;
static int fuse_context_ref; static int fuse_context_ref;
static void init_list_head(struct list_head *list)
static
void
init_list_head(struct list_head *list)
{ {
list->next = list; list->next = list;
list->prev = list; list->prev = list;
} }
static int list_empty(const struct list_head *head)
static
int
list_empty(const struct list_head *head)
{ {
return head->next == head; return head->next == head;
} }
static void list_add(struct list_head *new, struct list_head *prev,
static
void
list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next) struct list_head *next)
{ {
next->prev = new; next->prev = new;
@ -213,17 +226,28 @@ static void list_add(struct list_head *new, struct list_head *prev,
prev->next = new; prev->next = new;
} }
static inline void list_add_head(struct list_head *new, struct list_head *head)
static
inline
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 inline void list_add_tail(struct list_head *new, struct list_head *head)
static
inline
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 inline void list_del(struct list_head *entry)
static
inline
void
list_del(struct list_head *entry)
{ {
struct list_head *prev = entry->prev; struct list_head *prev = entry->prev;
struct list_head *next = entry->next; struct list_head *next = entry->next;
@ -232,17 +256,25 @@ static inline void list_del(struct list_head *entry)
prev->next = next; prev->next = next;
} }
static inline int lru_enabled(struct fuse *f)
static
inline
int
lru_enabled(struct fuse *f)
{ {
return f->conf.remember > 0; return f->conf.remember > 0;
} }
static struct node_lru *node_lru(struct node *node)
static
struct
node_lru*
node_lru(struct node *node)
{ {
return (struct node_lru *) node;
return (struct node_lru*)node;
} }
static size_t get_node_size(struct fuse *f)
static
size_t
get_node_size(struct fuse *f)
{ {
if (lru_enabled(f)) if (lru_enabled(f))
return sizeof(struct node_lru); return sizeof(struct node_lru);
@ -251,17 +283,23 @@ static size_t get_node_size(struct fuse *f)
} }
#ifdef FUSE_NODE_SLAB #ifdef FUSE_NODE_SLAB
static struct node_slab *list_to_slab(struct list_head *head)
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)
static
struct node_slab*
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 int alloc_slab(struct fuse *f)
static
int
alloc_slab(struct fuse *f)
{ {
void *mem; void *mem;
struct node_slab *slab; struct node_slab *slab;
@ -293,7 +331,9 @@ static int alloc_slab(struct fuse *f)
return 0; return 0;
} }
static struct node *alloc_node(struct fuse *f)
static
struct node*
alloc_node(struct fuse *f)
{ {
struct node_slab *slab; struct node_slab *slab;
struct list_head *node; struct list_head *node;
@ -316,7 +356,10 @@ static struct node *alloc_node(struct fuse *f)
return (struct node *) node; return (struct node *) node;
} }
static void free_slab(struct fuse *f, struct node_slab *slab)
static
void
free_slab(struct fuse *f,
struct node_slab *slab)
{ {
int res; int res;
@ -326,7 +369,10 @@ static void free_slab(struct fuse *f, struct node_slab *slab)
fprintf(stderr, "fuse warning: munmap(%p) failed\n", slab); fprintf(stderr, "fuse warning: munmap(%p) failed\n", slab);
} }
static void free_node_mem(struct fuse *f, struct node *node)
static
void
free_node_mem(struct fuse *f,
struct node *node)
{ {
struct node_slab *slab = node_to_slab(f, node); struct node_slab *slab = node_to_slab(f, node);
struct list_head *n = (struct list_head *) node; struct list_head *n = (struct list_head *) node;
@ -343,19 +389,27 @@ static void free_node_mem(struct fuse *f, struct node *node)
} }
} }
#else #else
static struct node *alloc_node(struct fuse *f)
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 void free_node_mem(struct fuse *f, struct node *node)
static
void
free_node_mem(struct fuse *f,
struct node *node)
{ {
(void) f; (void) f;
free(node); free(node);
} }
#endif #endif
static size_t id_hash(struct fuse *f, fuse_ino_t ino)
static
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); uint64_t oldhash = hash % (f->id_table.size / 2);
@ -366,7 +420,10 @@ static size_t id_hash(struct fuse *f, fuse_ino_t ino)
return hash; return hash;
} }
static struct node *get_node_nocheck(struct fuse *f, fuse_ino_t nodeid)
static
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; struct node *node;
@ -399,14 +456,19 @@ static void curr_time(struct timespec *now);
static double diff_timespec(const struct timespec *t1, static double diff_timespec(const struct timespec *t1,
const struct timespec *t2); const struct timespec *t2);
static void remove_node_lru(struct node *node)
static
void
remove_node_lru(struct node *node)
{ {
struct node_lru *lnode = node_lru(node); struct node_lru *lnode = node_lru(node);
list_del(&lnode->lru); list_del(&lnode->lru);
init_list_head(&lnode->lru); init_list_head(&lnode->lru);
} }
static void set_forget_time(struct fuse *f, struct node *node)
static
void
set_forget_time(struct fuse *f,
struct node *node)
{ {
struct node_lru *lnode = node_lru(node); struct node_lru *lnode = node_lru(node);
@ -429,7 +491,9 @@ free_node(struct fuse *f_,
free_node_mem(f_,node_); free_node_mem(f_,node_);
} }
static void node_table_reduce(struct node_table *t)
static
void
node_table_reduce(struct node_table *t)
{ {
size_t newsize = t->size / 2; size_t newsize = t->size / 2;
void *newarray; void *newarray;
@ -445,7 +509,9 @@ static void node_table_reduce(struct node_table *t)
t->split = t->size / 2; t->split = t->size / 2;
} }
static void remerge_id(struct fuse *f)
static
void
remerge_id(struct fuse *f)
{ {
struct node_table *t = &f->id_table; struct node_table *t = &f->id_table;
int iter; int iter;
@ -471,7 +537,9 @@ static void remerge_id(struct fuse *f)
} }
} }
static void unhash_id(struct fuse *f, struct node *node)
static
void
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)];
@ -777,7 +845,7 @@ static struct node *find_node(struct fuse *f, fuse_ino_t parent,
remove_node_lru(node); remove_node_lru(node);
} }
inc_nlookup(node); inc_nlookup(node);
out_err:
out_err:
pthread_mutex_unlock(&f->lock); pthread_mutex_unlock(&f->lock);
return node; return node;
} }
@ -982,9 +1050,9 @@ static void queue_element_wakeup(struct fuse *f, struct lock_queue_element *qe)
/* keep trying */ /* keep trying */
return; return;
err_unlock:
err_unlock:
queue_element_unlock(f, qe); queue_element_unlock(f, qe);
done:
done:
qe->err = err; qe->err = err;
qe->done = true; qe->done = true;
pthread_cond_signal(&qe->cond); pthread_cond_signal(&qe->cond);
@ -1263,7 +1331,7 @@ static int rename_node(struct fuse *f, fuse_ino_t olddir, const char *oldname,
goto out; goto out;
} }
out:
out:
pthread_mutex_unlock(&f->lock); pthread_mutex_unlock(&f->lock);
return err; return err;
} }
@ -1353,128 +1421,6 @@ static inline void fuse_prepare_interrupt(struct fuse *f, fuse_req_t req,
fuse_do_prepare_interrupt(req, d); fuse_do_prepare_interrupt(req, d);
} }
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
static int fuse_compat_open(struct fuse_fs *fs, const char *path,
struct fuse_file_info *fi)
{
int err;
if (!fs->compat || fs->compat >= 25)
err = fs->op.open(path, fi);
else if (fs->compat == 22) {
struct fuse_file_info_compat tmp;
memcpy(&tmp, fi, sizeof(tmp));
err = ((struct fuse_operations_compat22 *) &fs->op)->open(path,&tmp);
memcpy(fi, &tmp, sizeof(tmp));
fi->fh = tmp.fh;
} else
err = ((struct fuse_operations_compat2 *) &fs->op)
->open(path, fi->flags);
return err;
}
static int fuse_compat_release(struct fuse_fs *fs,
struct fuse_file_info *fi)
{
if (!fs->compat || fs->compat >= 22)
return fs->op.release(fi);
else
return ((struct fuse_operations_compat2 *) &fs->op)
->release(NULL, fi->flags);
}
static int fuse_compat_opendir(struct fuse_fs *fs, const char *path,
struct fuse_file_info *fi)
{
if (!fs->compat || fs->compat >= 25)
return fs->op.opendir(path, fi);
else {
int err;
struct fuse_file_info_compat tmp;
memcpy(&tmp, fi, sizeof(tmp));
err = ((struct fuse_operations_compat22 *) &fs->op)
->opendir(path, &tmp);
memcpy(fi, &tmp, sizeof(tmp));
fi->fh = tmp.fh;
return err;
}
}
static void convert_statfs_compat(struct fuse_statfs_compat1 *compatbuf,
struct statvfs *stbuf)
{
stbuf->f_bsize = compatbuf->block_size;
stbuf->f_blocks = compatbuf->blocks;
stbuf->f_bfree = compatbuf->blocks_free;
stbuf->f_bavail = compatbuf->blocks_free;
stbuf->f_files = compatbuf->files;
stbuf->f_ffree = compatbuf->files_free;
stbuf->f_namemax = compatbuf->namelen;
}
static void convert_statfs_old(struct statfs *oldbuf, struct statvfs *stbuf)
{
stbuf->f_bsize = oldbuf->f_bsize;
stbuf->f_blocks = oldbuf->f_blocks;
stbuf->f_bfree = oldbuf->f_bfree;
stbuf->f_bavail = oldbuf->f_bavail;
stbuf->f_files = oldbuf->f_files;
stbuf->f_ffree = oldbuf->f_ffree;
stbuf->f_namemax = oldbuf->f_namelen;
}
static int fuse_compat_statfs(struct fuse_fs *fs, const char *path,
struct statvfs *buf)
{
int err;
if (!fs->compat || fs->compat >= 25) {
err = fs->op.statfs(fs->compat == 25 ? "/" : path, buf);
} else if (fs->compat > 11) {
struct statfs oldbuf;
err = ((struct fuse_operations_compat22 *) &fs->op)
->statfs("/", &oldbuf);
if (!err)
convert_statfs_old(&oldbuf, buf);
} else {
struct fuse_statfs_compat1 compatbuf;
memset(&compatbuf, 0, sizeof(struct fuse_statfs_compat1));
err = ((struct fuse_operations_compat1 *) &fs->op)
->statfs(&compatbuf);
if (!err)
convert_statfs_compat(&compatbuf, buf);
}
return err;
}
#else /* __FreeBSD__ || __NetBSD__ */
static inline int fuse_compat_open(struct fuse_fs *fs, char *path,
struct fuse_file_info *fi)
{
return fs->op.open(path, fi);
}
static inline int fuse_compat_release(struct fuse_fs *fs,
struct fuse_file_info *fi)
{
return fs->op.release(fi);
}
static inline int fuse_compat_opendir(struct fuse_fs *fs, const char *path,
struct fuse_file_info *fi)
{
return fs->op.opendir(path, fi);
}
static inline int fuse_compat_statfs(struct fuse_fs *fs, const char *path,
struct statvfs *buf)
{
return fs->op.statfs(fs->compat == 25 ? "/" : path, buf);
}
#endif /* __FreeBSD__ || __NetBSD__ */
int int
fuse_fs_getattr(struct fuse_fs *fs, fuse_fs_getattr(struct fuse_fs *fs,
const char *path, const char *path,
@ -1608,7 +1554,7 @@ int fuse_fs_release(struct fuse_fs *fs,
fi->flush ? "+flush" : "", fi->flush ? "+flush" : "",
(unsigned long long) fi->fh, fi->flags); (unsigned long long) fi->fh, fi->flags);
return fuse_compat_release(fs, fi);
return fs->op.release(fi);
} else { } else {
return 0; return 0;
} }
@ -1625,7 +1571,7 @@ int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
fprintf(stderr, "opendir flags: 0x%x %s\n", fi->flags, fprintf(stderr, "opendir flags: 0x%x %s\n", fi->flags,
path); path);
err = fuse_compat_opendir(fs, path, fi);
err = fs->op.opendir(path,fi);
if (fs->debug && !err) if (fs->debug && !err)
fprintf(stderr, " opendir[%lli] flags: 0x%x %s\n", fprintf(stderr, " opendir[%lli] flags: 0x%x %s\n",
@ -1648,7 +1594,7 @@ int fuse_fs_open(struct fuse_fs *fs, const char *path,
fprintf(stderr, "open flags: 0x%x %s\n", fi->flags, fprintf(stderr, "open flags: 0x%x %s\n", fi->flags,
path); path);
err = fuse_compat_open(fs, path, fi);
err = fs->op.open(path,fi);
if (fs->debug && !err) if (fs->debug && !err)
fprintf(stderr, " open[%lli] flags: 0x%x %s\n", fprintf(stderr, " open[%lli] flags: 0x%x %s\n",
@ -1790,10 +1736,10 @@ int fuse_fs_write_buf(struct fuse_fs *fs,
res = fs->op.write(flatbuf->mem, flatbuf->size, res = fs->op.write(flatbuf->mem, flatbuf->size,
off, fi); off, fi);
out_free:
out_free:
free(mem); free(mem);
} }
out:
out:
if (fs->debug && res >= 0) if (fs->debug && res >= 0)
fprintf(stderr, " write%s[%llu] %u bytes to %llu\n", fprintf(stderr, " write%s[%llu] %u bytes to %llu\n",
fi->writepage ? "page" : "", fi->writepage ? "page" : "",
@ -1870,7 +1816,7 @@ int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf)
if (fs->debug) if (fs->debug)
fprintf(stderr, "statfs %s\n", path); fprintf(stderr, "statfs %s\n", path);
return fuse_compat_statfs(fs, path, buf);
return fs->op.statfs(path,buf);
} else { } else {
buf->f_namemax = 255; buf->f_namemax = 255;
buf->f_bsize = 512; buf->f_bsize = 512;
@ -3809,7 +3755,7 @@ static int locks_insert(struct node *node, struct lock *lock)
insert_lock(lp, newl1); insert_lock(lp, newl1);
newl1 = NULL; newl1 = NULL;
} }
out:
out:
free(newl1); free(newl1);
free(newl2); free(newl2);
return 0; return 0;
@ -4032,9 +3978,9 @@ static void fuse_lib_ioctl(fuse_req_t req, fuse_ino_t ino, unsigned long cmd, vo
fuse_reply_ioctl(req, err, out_buf, out_bufsz); fuse_reply_ioctl(req, err, out_buf, out_bufsz);
goto out; goto out;
err:
err:
reply_err(req, err); reply_err(req, err);
out:
out:
free(out_buf); free(out_buf);
} }
@ -4231,79 +4177,6 @@ struct fuse_cmd *fuse_read_cmd(struct fuse *f)
return cmd; return cmd;
} }
static int fuse_session_loop_remember(struct fuse *f)
{
struct fuse_session *se = f->se;
int res = 0;
struct timespec now;
time_t next_clean;
struct fuse_chan *ch = fuse_session_next_chan(se, NULL);
size_t bufsize = fuse_chan_bufsize(ch);
char *buf = (char *) malloc(bufsize);
struct pollfd fds = {
.fd = fuse_chan_fd(ch),
.events = POLLIN
};
if (!buf) {
fprintf(stderr, "fuse: failed to allocate read buffer\n");
return -1;
}
curr_time(&now);
next_clean = now.tv_sec;
while (!fuse_session_exited(se)) {
struct fuse_chan *tmpch = ch;
struct fuse_buf fbuf = {
.mem = buf,
.size = bufsize,
};
unsigned timeout;
curr_time(&now);
if (now.tv_sec < next_clean)
timeout = next_clean - now.tv_sec;
else
timeout = 0;
res = poll(&fds, 1, timeout * 1000);
if (res == -1) {
if (errno == -EINTR)
continue;
else
break;
} else if (res > 0) {
res = fuse_session_receive_buf(se, &fbuf, &tmpch);
if (res == -EINTR)
continue;
if (res <= 0)
break;
fuse_session_process_buf(se, &fbuf, tmpch);
} else {
timeout = fuse_clean_cache(f);
curr_time(&now);
next_clean = now.tv_sec + timeout;
}
}
free(buf);
fuse_session_reset(se);
return res < 0 ? -1 : 0;
}
int fuse_loop(struct fuse *f)
{
if (!f)
return -1;
if (lru_enabled(f))
return fuse_session_loop_remember(f);
return fuse_session_loop(f->se);
}
int fuse_invalidate(struct fuse *f, const char *path) int fuse_invalidate(struct fuse *f, const char *path)
{ {
(void) f; (void) f;
@ -4321,24 +4194,6 @@ struct fuse_context *fuse_get_context(void)
return &fuse_get_context_internal()->ctx; return &fuse_get_context_internal()->ctx;
} }
/*
* The size of fuse_context got extended, so need to be careful about
* incompatibility (i.e. a new binary cannot work with an old
* library).
*/
struct fuse_context *fuse_get_context_compat22(void);
struct fuse_context *fuse_get_context_compat22(void)
{
return &fuse_get_context_internal()->ctx;
}
FUSE_SYMVER(".symver fuse_get_context_compat22,fuse_get_context@FUSE_2.2");
int fuse_getgroups(int size, gid_t list[])
{
fuse_req_t req = fuse_get_context_internal()->req;
return fuse_req_getgroups(req, size, list);
}
int fuse_interrupted(void) int fuse_interrupted(void)
{ {
return fuse_req_interrupted(fuse_get_context_internal()->req); return fuse_req_interrupted(fuse_get_context_internal()->req);
@ -4381,17 +4236,17 @@ static const struct fuse_opt fuse_lib_opts[] = {
static void fuse_lib_help(void) static void fuse_lib_help(void)
{ {
fprintf(stderr, fprintf(stderr,
" -o umask=M set file permissions (octal)\n"
" -o uid=N set file owner\n"
" -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);
" -o umask=M set file permissions (octal)\n"
" -o uid=N set file owner\n"
" -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);
} }
static int fuse_lib_opt_proc(void *data, const char *arg, int key, static int fuse_lib_opt_proc(void *data, const char *arg, int key,
@ -4517,7 +4372,7 @@ void fuse_stop_cleanup_thread(struct fuse *f)
struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args, struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args,
const struct fuse_operations *op, const struct fuse_operations *op,
size_t op_size, void *user_data, int compat)
size_t op_size, void *user_data)
{ {
struct fuse *f; struct fuse *f;
struct node *root; struct node *root;
@ -4537,7 +4392,6 @@ struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args,
if (!fs) if (!fs)
goto out_free; goto out_free;
fs->compat = compat;
f->fs = fs; f->fs = fs;
/* Oh f**k, this is ugly! */ /* Oh f**k, this is ugly! */
@ -4557,11 +4411,6 @@ struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args,
fuse_lib_opt_proc) == -1) fuse_lib_opt_proc) == -1)
goto out_free_fs; goto out_free_fs;
if (compat && compat <= 25) {
if (fuse_sync_compat_args(args) == -1)
goto out_free_fs;
}
f->se = fuse_lowlevel_new_common(args, &llop, sizeof(llop), f); f->se = fuse_lowlevel_new_common(args, &llop, sizeof(llop), f);
if (f->se == NULL) { if (f->se == NULL) {
goto out_free_fs; goto out_free_fs;
@ -4607,24 +4456,24 @@ struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args,
return f; return f;
out_free_root:
out_free_root:
free(root); free(root);
out_free_id_table:
out_free_id_table:
free(f->id_table.array); free(f->id_table.array);
out_free_name_table:
out_free_name_table:
free(f->name_table.array); free(f->name_table.array);
out_free_session:
out_free_session:
fuse_session_destroy(f->se); fuse_session_destroy(f->se);
out_free_fs:
out_free_fs:
/* Horrible compatibility hack to stop the destructor from being /* Horrible compatibility hack to stop the destructor from being
called on the filesystem without init being called first */ called on the filesystem without init being called first */
fs->op.destroy = NULL; fs->op.destroy = NULL;
fuse_fs_destroy(f->fs); fuse_fs_destroy(f->fs);
out_free:
out_free:
free(f); free(f);
out_delete_context_key:
out_delete_context_key:
fuse_delete_context_key(); fuse_delete_context_key();
out:
out:
return NULL; return NULL;
} }
@ -4632,7 +4481,7 @@ struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
const struct fuse_operations *op, size_t op_size, const struct fuse_operations *op, size_t op_size,
void *user_data) void *user_data)
{ {
return fuse_new_common(ch, args, op, op_size, user_data, 0);
return fuse_new_common(ch, args, op, op_size, user_data);
} }
void fuse_destroy(struct fuse *f) void fuse_destroy(struct fuse *f)
@ -4679,91 +4528,6 @@ void fuse_destroy(struct fuse *f)
fuse_delete_context_key(); fuse_delete_context_key();
} }
static
struct fuse *
fuse_new_common_compat25(int fd, struct fuse_args *args,
const struct fuse_operations *op,
size_t op_size, int compat)
{
struct fuse *f = NULL;
struct fuse_chan *ch = fuse_kern_chan_new(fd);
if (ch)
f = fuse_new_common(ch, args, op, op_size, NULL, compat);
return f;
}
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
static struct fuse *fuse_new_common_compat(int fd, const char *opts,
const struct fuse_operations *op,
size_t op_size, int compat)
{
struct fuse *f;
struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
if (fuse_opt_add_arg(&args, "") == -1)
return NULL;
if (opts &&
(fuse_opt_add_arg(&args, "-o") == -1 ||
fuse_opt_add_arg(&args, opts) == -1)) {
fuse_opt_free_args(&args);
return NULL;
}
f = fuse_new_common_compat25(fd, &args, op, op_size, compat);
fuse_opt_free_args(&args);
return f;
}
struct fuse *fuse_new_compat22(int fd, const char *opts,
const struct fuse_operations_compat22 *op,
size_t op_size)
{
return fuse_new_common_compat(fd, opts, (struct fuse_operations *) op,
op_size, 22);
}
struct fuse *fuse_new_compat2(int fd, const char *opts,
const struct fuse_operations_compat2 *op)
{
return fuse_new_common_compat(fd, opts, (struct fuse_operations *) op,
sizeof(struct fuse_operations_compat2),
21);
}
struct fuse *fuse_new_compat1(int fd, int flags,
const struct fuse_operations_compat1 *op)
{
const char *opts = NULL;
if (flags & FUSE_DEBUG_COMPAT1)
opts = "debug";
return fuse_new_common_compat(fd, opts, (struct fuse_operations *) op,
sizeof(struct fuse_operations_compat1),
11);
}
FUSE_SYMVER(".symver fuse_exited,__fuse_exited@");
FUSE_SYMVER(".symver fuse_process_cmd,__fuse_process_cmd@");
FUSE_SYMVER(".symver fuse_read_cmd,__fuse_read_cmd@");
FUSE_SYMVER(".symver fuse_set_getcontext_func,__fuse_set_getcontext_func@");
FUSE_SYMVER(".symver fuse_new_compat2,fuse_new@");
FUSE_SYMVER(".symver fuse_new_compat22,fuse_new@FUSE_2.2");
#endif /* __FreeBSD__ || __NetBSD__ */
struct fuse *fuse_new_compat25(int fd, struct fuse_args *args,
const struct fuse_operations_compat25 *op,
size_t op_size)
{
return fuse_new_common_compat25(fd, args, (struct fuse_operations *) op,
op_size, 25);
}
FUSE_SYMVER(".symver fuse_new_compat25,fuse_new@FUSE_2.5");
int int
fuse_config_num_threads(const struct fuse *fuse_) fuse_config_num_threads(const struct fuse *fuse_)
{ {

28
libfuse/lib/fuse_i.h

@ -12,7 +12,8 @@
struct fuse_chan; struct fuse_chan;
struct fuse_ll; struct fuse_ll;
struct fuse_session {
struct fuse_session
{
struct fuse_session_ops op; struct fuse_session_ops op;
int (*receive_buf)(struct fuse_session *se, struct fuse_buf *buf, int (*receive_buf)(struct fuse_session *se, struct fuse_buf *buf,
@ -28,7 +29,8 @@ struct fuse_session {
struct fuse_chan *ch; struct fuse_chan *ch;
}; };
struct fuse_req {
struct fuse_req
{
struct fuse_ll *f; struct fuse_ll *f;
uint64_t unique; uint64_t unique;
int ctr; int ctr;
@ -50,7 +52,8 @@ struct fuse_req {
struct fuse_req *prev; struct fuse_req *prev;
}; };
struct fuse_notify_req {
struct fuse_notify_req
{
uint64_t unique; uint64_t unique;
void (*reply)(struct fuse_notify_req *, fuse_req_t, fuse_ino_t, void (*reply)(struct fuse_notify_req *, fuse_req_t, fuse_ino_t,
const void *, const struct fuse_buf *); const void *, const struct fuse_buf *);
@ -58,10 +61,10 @@ struct fuse_notify_req {
struct fuse_notify_req *prev; struct fuse_notify_req *prev;
}; };
struct fuse_ll {
struct fuse_ll
{
int debug; int debug;
int allow_root; int allow_root;
int atomic_o_trunc;
int no_remote_posix_lock; int no_remote_posix_lock;
int no_remote_flock; int no_remote_flock;
int big_writes; int big_writes;
@ -73,7 +76,6 @@ struct fuse_ll {
int no_splice_read; int no_splice_read;
struct fuse_lowlevel_ops op; struct fuse_lowlevel_ops op;
int got_init; int got_init;
struct cuse_data *cuse_data;
void *userdata; void *userdata;
uid_t owner; uid_t owner;
struct fuse_conn_info conn; struct fuse_conn_info conn;
@ -87,7 +89,8 @@ struct fuse_ll {
struct fuse_notify_req notify_list; struct fuse_notify_req notify_list;
}; };
struct fuse_cmd {
struct fuse_cmd
{
char *buf; char *buf;
size_t buflen; size_t buflen;
struct fuse_chan *ch; struct fuse_chan *ch;
@ -95,9 +98,7 @@ struct fuse_cmd {
struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args, struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args,
const struct fuse_operations *op, const struct fuse_operations *op,
size_t op_size, void *user_data, int compat);
int fuse_sync_compat_args(struct fuse_args *args);
size_t op_size, void *user_data);
struct fuse_chan *fuse_kern_chan_new(int fd); struct fuse_chan *fuse_kern_chan_new(int fd);
@ -105,7 +106,6 @@ struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args,
const struct fuse_lowlevel_ops *op, const struct fuse_lowlevel_ops *op,
size_t op_size, void *userdata); size_t op_size, void *userdata);
void fuse_kern_unmount_compat22(const char *mountpoint);
int fuse_chan_clearfd(struct fuse_chan *ch); int fuse_chan_clearfd(struct fuse_chan *ch);
void fuse_kern_unmount(const char *mountpoint, int fd); void fuse_kern_unmount(const char *mountpoint, int fd);
@ -120,11 +120,7 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
const struct fuse_operations *op, const struct fuse_operations *op,
size_t op_size, size_t op_size,
char **mountpoint, char **mountpoint,
int *multithreaded,
int *fd, int *fd,
void *user_data,
int compat);
void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeide, const void *inarg);
void *user_data);
int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg); int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg);

2
libfuse/lib/fuse_kern_chan.c

@ -24,7 +24,7 @@ static int fuse_kern_chan_receive(struct fuse_chan **chp, char *buf,
struct fuse_session *se = fuse_chan_session(ch); struct fuse_session *se = fuse_chan_session(ch);
assert(se != NULL); assert(se != NULL);
restart:
restart:
res = read(fuse_chan_fd(ch), buf, size); res = read(fuse_chan_fd(ch), buf, size);
err = errno; err = errno;

46
libfuse/lib/fuse_loop.c

@ -1,46 +0,0 @@
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB
*/
#include "fuse_lowlevel.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int fuse_session_loop(struct fuse_session *se)
{
int res = 0;
struct fuse_chan *ch = fuse_session_next_chan(se, NULL);
size_t bufsize = fuse_chan_bufsize(ch);
char *buf = (char*)calloc(bufsize,1);
if (!buf) {
fprintf(stderr, "fuse: failed to allocate read buffer\n");
return -1;
}
while (!fuse_session_exited(se)) {
struct fuse_chan *tmpch = ch;
struct fuse_buf fbuf = {
.mem = buf,
.size = bufsize,
};
res = fuse_session_receive_buf(se, &fbuf, &tmpch);
if (res == -EINTR)
continue;
if (res <= 0)
break;
fuse_session_process_buf(se, &fbuf, tmpch);
}
free(buf);
fuse_session_reset(se);
return res < 0 ? -1 : 0;
}

275
libfuse/lib/fuse_lowlevel.c

@ -13,8 +13,6 @@
#include "fuse_kernel.h" #include "fuse_kernel.h"
#include "fuse_opt.h" #include "fuse_opt.h"
#include "fuse_misc.h" #include "fuse_misc.h"
#include "fuse_common_compat.h"
#include "fuse_lowlevel_compat.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -733,11 +731,11 @@ static int fuse_send_data_iov(struct fuse_ll *f, struct fuse_chan *ch,
} }
return 0; return 0;
clear_pipe:
clear_pipe:
fuse_ll_clear_pipe(f); fuse_ll_clear_pipe(f);
return res; return res;
fallback:
fallback:
return fuse_send_data_iov_fallback(f, ch, iov, iov_count, buf, len); return fuse_send_data_iov_fallback(f, ch, iov, iov_count, buf, len);
} }
#else #else
@ -900,13 +898,13 @@ int fuse_reply_ioctl_retry(fuse_req_t req,
} }
res = send_reply_iov(req, 0, iov, count); res = send_reply_iov(req, 0, iov, count);
out:
out:
free(in_fiov); free(in_fiov);
free(out_fiov); free(out_fiov);
return res; return res;
enomem:
enomem:
res = fuse_reply_err(req, ENOMEM); res = fuse_reply_err(req, ENOMEM);
goto out; goto out;
} }
@ -1306,7 +1304,7 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg,
req->f->op.write_buf(req, nodeid, &bufv, arg->offset, &fi); req->f->op.write_buf(req, nodeid, &bufv, arg->offset, &fi);
out:
out:
/* Need to reset the pipe if ->write_buf() didn't consume all data */ /* Need to reset the pipe if ->write_buf() didn't consume all data */
if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count) if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count)
fuse_ll_clear_pipe(f); fuse_ll_clear_pipe(f);
@ -2225,7 +2223,7 @@ static void fuse_ll_retrieve_reply(struct fuse_notify_req *nreq,
} else { } else {
fuse_reply_none(req); fuse_reply_none(req);
} }
out:
out:
free(rreq); free(rreq);
if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count) if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count)
fuse_ll_clear_pipe(f); fuse_ll_clear_pipe(f);
@ -2290,21 +2288,6 @@ const struct fuse_ctx *fuse_req_ctx(fuse_req_t req)
return &req->ctx; return &req->ctx;
} }
/*
* The size of fuse_ctx got extended, so need to be careful about
* incompatibility (i.e. a new binary cannot work with an old
* library).
*/
const struct fuse_ctx *fuse_req_ctx_compat24(fuse_req_t req);
const struct fuse_ctx *fuse_req_ctx_compat24(fuse_req_t req)
{
return fuse_req_ctx(req);
}
#ifndef __NetBSD__
FUSE_SYMVER(".symver fuse_req_ctx_compat24,fuse_req_ctx@FUSE_2.4");
#endif
void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
void *data) void *data)
{ {
@ -2377,7 +2360,6 @@ static struct {
[FUSE_NOTIFY_REPLY] = { (void *) 1, "NOTIFY_REPLY" }, [FUSE_NOTIFY_REPLY] = { (void *) 1, "NOTIFY_REPLY" },
[FUSE_BATCH_FORGET] = { do_batch_forget, "BATCH_FORGET" }, [FUSE_BATCH_FORGET] = { do_batch_forget, "BATCH_FORGET" },
[FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" }, [FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" },
[CUSE_INIT] = { cuse_lowlevel_init, "CUSE_INIT" },
}; };
#define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0])) #define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
@ -2470,13 +2452,15 @@ static void fuse_ll_process_buf(void *data, const struct fuse_buf *buf,
req->ch = ch; req->ch = ch;
err = EIO; err = EIO;
if (!f->got_init) {
if(!f->got_init)
{
enum fuse_opcode expected; enum fuse_opcode expected;
expected = f->cuse_data ? CUSE_INIT : FUSE_INIT;
expected = FUSE_INIT;
if (in->opcode != expected) if (in->opcode != expected)
goto reply_err; goto reply_err;
} else if (in->opcode == FUSE_INIT || in->opcode == CUSE_INIT)
}
else if(in->opcode == FUSE_INIT)
goto reply_err; goto reply_err;
err = EACCES; err = EACCES;
@ -2538,13 +2522,13 @@ static void fuse_ll_process_buf(void *data, const struct fuse_buf *buf,
else else
fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg); fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
out_free:
out_free:
free(mbuf); free(mbuf);
return; return;
reply_err:
reply_err:
fuse_reply_err(req, err); fuse_reply_err(req, err);
clear_pipe:
clear_pipe:
if (buf->flags & FUSE_BUF_IS_FD) if (buf->flags & FUSE_BUF_IS_FD)
fuse_ll_clear_pipe(f); fuse_ll_clear_pipe(f);
goto out_free; goto out_free;
@ -2601,16 +2585,16 @@ static void fuse_ll_version(void)
static void fuse_ll_help(void) static void fuse_ll_help(void)
{ {
fprintf(stderr, fprintf(stderr,
" -o max_readahead=N set maximum readahead\n"
" -o max_background=N set number of maximum background requests\n"
" -o congestion_threshold=N set kernel's congestion threshold\n"
" -o no_remote_lock disable remote file locking\n"
" -o no_remote_flock disable remote file locking (BSD)\n"
" -o no_remote_posix_lock disable remove file locking (POSIX)\n"
" -o [no_]splice_write use splice to write to the fuse device\n"
" -o [no_]splice_move move data while splicing to the fuse device\n"
" -o [no_]splice_read use splice to read from the fuse device\n"
);
" -o max_readahead=N set maximum readahead\n"
" -o max_background=N set number of maximum background requests\n"
" -o congestion_threshold=N set kernel's congestion threshold\n"
" -o no_remote_lock disable remote file locking\n"
" -o no_remote_flock disable remote file locking (BSD)\n"
" -o no_remote_posix_lock disable remove file locking (POSIX)\n"
" -o [no_]splice_write use splice to write to the fuse device\n"
" -o [no_]splice_move move data while splicing to the fuse device\n"
" -o [no_]splice_read use splice to read from the fuse device\n"
);
} }
static int fuse_ll_opt_proc(void *data, const char *arg, int key, static int fuse_ll_opt_proc(void *data, const char *arg, int key,
@ -2653,7 +2637,6 @@ static void fuse_ll_destroy(void *data)
fuse_ll_pipe_free(llp); fuse_ll_pipe_free(llp);
pthread_key_delete(f->pipe_key); pthread_key_delete(f->pipe_key);
pthread_mutex_destroy(&f->lock); pthread_mutex_destroy(&f->lock);
free(f->cuse_data);
free(f); free(f);
} }
@ -2752,7 +2735,7 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
return res; return res;
fallback:
fallback:
res = fuse_chan_recv(chp, buf->mem, bufsize); res = fuse_chan_recv(chp, buf->mem, bufsize);
if (res <= 0) if (res <= 0)
return res; return res;
@ -2840,214 +2823,20 @@ struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args,
return se; return se;
out_key_destroy:
out_key_destroy:
pthread_key_delete(f->pipe_key); pthread_key_delete(f->pipe_key);
out_free:
out_free:
pthread_mutex_destroy(&f->lock); pthread_mutex_destroy(&f->lock);
free(f); free(f);
out:
out:
return NULL; return NULL;
} }
struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
struct fuse_session*
fuse_lowlevel_new(struct fuse_args *args,
const struct fuse_lowlevel_ops *op, 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); return fuse_lowlevel_new_common(args, op, op_size, userdata);
} }
#ifdef linux
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
{
char *buf;
size_t bufsize = 1024;
char path[128];
int ret;
int fd;
unsigned long pid = req->ctx.pid;
char *s;
sprintf(path, "/proc/%lu/task/%lu/status", pid, pid);
retry:
buf = malloc(bufsize);
if (buf == NULL)
return -ENOMEM;
ret = -EIO;
fd = open(path, O_RDONLY);
if (fd == -1)
goto out_free;
ret = read(fd, buf, bufsize);
close(fd);
if (ret == -1) {
ret = -EIO;
goto out_free;
}
if (ret == bufsize) {
free(buf);
bufsize *= 4;
goto retry;
}
ret = -EIO;
s = strstr(buf, "\nGroups:");
if (s == NULL)
goto out_free;
s += 8;
ret = 0;
while (1) {
char *end;
unsigned long val = strtoul(s, &end, 0);
if (end == s)
break;
s = end;
if (ret < size)
list[ret] = val;
ret++;
}
out_free:
free(buf);
return ret;
}
#else /* linux */
/*
* This is currently not implemented on other than Linux...
*/
int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[])
{
return -ENOSYS;
}
#endif
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
static void fill_open_compat(struct fuse_open_out *arg,
const struct fuse_file_info_compat *f)
{
arg->fh = f->fh;
if (f->direct_io)
arg->open_flags |= FOPEN_DIRECT_IO;
if (f->keep_cache)
arg->open_flags |= FOPEN_KEEP_CACHE;
}
static void convert_statfs_compat(const struct statfs *compatbuf,
struct statvfs *buf)
{
buf->f_bsize = compatbuf->f_bsize;
buf->f_blocks = compatbuf->f_blocks;
buf->f_bfree = compatbuf->f_bfree;
buf->f_bavail = compatbuf->f_bavail;
buf->f_files = compatbuf->f_files;
buf->f_ffree = compatbuf->f_ffree;
buf->f_namemax = compatbuf->f_namelen;
}
int fuse_reply_open_compat(fuse_req_t req,
const struct fuse_file_info_compat *f)
{
struct fuse_open_out arg;
memset(&arg, 0, sizeof(arg));
fill_open_compat(&arg, f);
return send_reply_ok(req, &arg, sizeof(arg));
}
int fuse_reply_statfs_compat(fuse_req_t req, const struct statfs *stbuf)
{
struct statvfs newbuf;
memset(&newbuf, 0, sizeof(newbuf));
convert_statfs_compat(stbuf, &newbuf);
return fuse_reply_statfs(req, &newbuf);
}
struct fuse_session *fuse_lowlevel_new_compat(const char *opts,
const struct fuse_lowlevel_ops_compat *op,
size_t op_size, void *userdata)
{
struct fuse_session *se;
struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
if (opts &&
(fuse_opt_add_arg(&args, "") == -1 ||
fuse_opt_add_arg(&args, "-o") == -1 ||
fuse_opt_add_arg(&args, opts) == -1)) {
fuse_opt_free_args(&args);
return NULL;
}
se = fuse_lowlevel_new(&args, (const struct fuse_lowlevel_ops *) op,
op_size, userdata);
fuse_opt_free_args(&args);
return se;
}
struct fuse_ll_compat_conf {
unsigned max_read;
int set_max_read;
};
static const struct fuse_opt fuse_ll_opts_compat[] = {
{ "max_read=", offsetof(struct fuse_ll_compat_conf, set_max_read), 1 },
{ "max_read=%u", offsetof(struct fuse_ll_compat_conf, max_read), 0 },
FUSE_OPT_KEY("max_read=", FUSE_OPT_KEY_KEEP),
FUSE_OPT_END
};
int fuse_sync_compat_args(struct fuse_args *args)
{
struct fuse_ll_compat_conf conf;
memset(&conf, 0, sizeof(conf));
if (fuse_opt_parse(args, &conf, fuse_ll_opts_compat, NULL) == -1)
return -1;
if (fuse_opt_insert_arg(args, 1, "-osync_read"))
return -1;
if (conf.set_max_read) {
char tmpbuf[64];
sprintf(tmpbuf, "-omax_readahead=%u", conf.max_read);
if (fuse_opt_insert_arg(args, 1, tmpbuf) == -1)
return -1;
}
return 0;
}
FUSE_SYMVER(".symver fuse_reply_statfs_compat,fuse_reply_statfs@FUSE_2.4");
FUSE_SYMVER(".symver fuse_reply_open_compat,fuse_reply_open@FUSE_2.4");
FUSE_SYMVER(".symver fuse_lowlevel_new_compat,fuse_lowlevel_new@FUSE_2.4");
#else /* __FreeBSD__ || __NetBSD__ */
int fuse_sync_compat_args(struct fuse_args *args)
{
(void) args;
return 0;
}
#endif /* __FreeBSD__ || __NetBSD__ */
struct fuse_session *fuse_lowlevel_new_compat25(struct fuse_args *args,
const struct fuse_lowlevel_ops_compat25 *op,
size_t op_size, void *userdata)
{
if (fuse_sync_compat_args(args) == -1)
return NULL;
return fuse_lowlevel_new_common(args,
(const struct fuse_lowlevel_ops *) op,
op_size, userdata);
}
FUSE_SYMVER(".symver fuse_lowlevel_new_compat25,fuse_lowlevel_new@FUSE_2.5");

7
libfuse/lib/fuse_mt.c

@ -16,7 +16,8 @@
#include <pthread.h> #include <pthread.h>
#include <assert.h> #include <assert.h>
struct procdata {
struct procdata
{
struct fuse *f; struct fuse *f;
struct fuse_chan *prevch; struct fuse_chan *prevch;
struct fuse_session *prevse; struct fuse_session *prevse;
@ -61,7 +62,7 @@ static int mt_chan_receive(struct fuse_chan **chp, char *buf, size_t size)
if (cmd == NULL) if (cmd == NULL)
return 0; return 0;
*(struct fuse_cmd **) buf = cmd;
*(struct fuse_cmd **)buf = cmd;
return sizeof(cmd); return sizeof(cmd);
} }
@ -120,5 +121,3 @@ int fuse_loop_mt(struct fuse *f)
fuse_stop_cleanup_thread(f); fuse_stop_cleanup_thread(f);
return res; return res;
} }
FUSE_SYMVER(".symver fuse_loop_mt_proc,__fuse_loop_mt@");

23
libfuse/lib/fuse_opt.c

@ -14,7 +14,8 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
struct fuse_opt_context {
struct fuse_opt_context
{
void *data; void *data;
const struct fuse_opt *opt; const struct fuse_opt *opt;
fuse_opt_proc_t proc; fuse_opt_proc_t proc;
@ -26,7 +27,8 @@ struct fuse_opt_context {
int nonopt; int nonopt;
}; };
void fuse_opt_free_args(struct fuse_args *args)
void
fuse_opt_free_args(struct fuse_args *args)
{ {
if (args) { if (args) {
if (args->argv && args->allocated) { if (args->argv && args->allocated) {
@ -41,13 +43,16 @@ void fuse_opt_free_args(struct fuse_args *args)
} }
} }
static int alloc_failed(void)
static
int
alloc_failed(void)
{ {
fprintf(stderr, "fuse: memory allocation failed\n"); fprintf(stderr, "fuse: memory allocation failed\n");
return -1; return -1;
} }
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
int
fuse_opt_add_arg(struct fuse_args *args, const char *arg)
{ {
char **newargv; char **newargv;
char *newarg; char *newarg;
@ -92,13 +97,6 @@ int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg)
return fuse_opt_insert_arg_common(args, pos, arg); return fuse_opt_insert_arg_common(args, pos, arg);
} }
int fuse_opt_insert_arg_compat(struct fuse_args *args, int pos,
const char *arg);
int fuse_opt_insert_arg_compat(struct fuse_args *args, int pos, const char *arg)
{
return fuse_opt_insert_arg_common(args, pos, arg);
}
static int next_arg(struct fuse_opt_context *ctx, const char *opt) static int next_arg(struct fuse_opt_context *ctx, const char *opt)
{ {
if (ctx->argctr + 1 >= ctx->argc) { if (ctx->argctr + 1 >= ctx->argc) {
@ -421,6 +419,3 @@ int fuse_opt_parse(struct fuse_args *args, void *data,
fuse_opt_free_args(&ctx.outargs); fuse_opt_free_args(&ctx.outargs);
return res; return res;
} }
/* This symbol version was mistakenly added to the version script */
FUSE_SYMVER(".symver fuse_opt_insert_arg_compat,fuse_opt_insert_arg@FUSE_2.5");

33
libfuse/lib/fuse_session.c

@ -8,8 +8,6 @@
#include "fuse_i.h" #include "fuse_i.h"
#include "fuse_misc.h" #include "fuse_misc.h"
#include "fuse_common_compat.h"
#include "fuse_lowlevel_compat.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -17,18 +15,13 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
struct fuse_chan {
struct fuse_chan
{
struct fuse_chan_ops op; struct fuse_chan_ops op;
struct fuse_session *se; struct fuse_session *se;
int fd; int fd;
size_t bufsize; size_t bufsize;
void *data; void *data;
int compat;
}; };
struct fuse_session *fuse_session_new(struct fuse_session_ops *op, void *data) struct fuse_session *fuse_session_new(struct fuse_session_ops *op, void *data)
@ -145,8 +138,7 @@ void *fuse_session_data(struct fuse_session *se)
} }
static struct fuse_chan *fuse_chan_new_common(struct fuse_chan_ops *op, int fd, static struct fuse_chan *fuse_chan_new_common(struct fuse_chan_ops *op, int fd,
size_t bufsize, void *data,
int compat)
size_t bufsize, void *data)
{ {
struct fuse_chan *ch = (struct fuse_chan *) malloc(sizeof(*ch)); struct fuse_chan *ch = (struct fuse_chan *) malloc(sizeof(*ch));
if (ch == NULL) { if (ch == NULL) {
@ -159,7 +151,6 @@ static struct fuse_chan *fuse_chan_new_common(struct fuse_chan_ops *op, int fd,
ch->fd = fd; ch->fd = fd;
ch->bufsize = bufsize; ch->bufsize = bufsize;
ch->data = data; ch->data = data;
ch->compat = compat;
return ch; return ch;
} }
@ -167,14 +158,7 @@ static struct fuse_chan *fuse_chan_new_common(struct fuse_chan_ops *op, int fd,
struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd, struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd,
size_t bufsize, void *data) size_t bufsize, void *data)
{ {
return fuse_chan_new_common(op, fd, bufsize, data, 0);
}
struct fuse_chan *fuse_chan_new_compat24(struct fuse_chan_ops_compat24 *op,
int fd, size_t bufsize, void *data)
{
return fuse_chan_new_common((struct fuse_chan_ops *) op, fd, bufsize,
data, 24);
return fuse_chan_new_common(op, fd, bufsize, data);
} }
int fuse_chan_fd(struct fuse_chan *ch) int fuse_chan_fd(struct fuse_chan *ch)
@ -207,10 +191,7 @@ struct fuse_session *fuse_chan_session(struct fuse_chan *ch)
int fuse_chan_recv(struct fuse_chan **chp, char *buf, size_t size) int fuse_chan_recv(struct fuse_chan **chp, char *buf, size_t size)
{ {
struct fuse_chan *ch = *chp; struct fuse_chan *ch = *chp;
if (ch->compat)
return ((struct fuse_chan_ops_compat24 *) &ch->op)
->receive(ch, buf, size);
else
return ch->op.receive(chp, buf, size); return ch->op.receive(chp, buf, size);
} }
@ -234,7 +215,3 @@ void fuse_chan_destroy(struct fuse_chan *ch)
ch->op.destroy(ch); ch->op.destroy(ch);
free(ch); free(ch);
} }
#ifndef __FreeBSD__
FUSE_SYMVER(".symver fuse_chan_new_compat24,fuse_chan_new@FUSE_2.4");
#endif

1
libfuse/lib/fuse_signals.c

@ -69,4 +69,3 @@ void fuse_remove_signal_handlers(struct fuse_session *se)
set_one_signal_handler(SIGTERM, exit_handler, 1); set_one_signal_handler(SIGTERM, exit_handler, 1);
set_one_signal_handler(SIGPIPE, SIG_IGN, 1); set_one_signal_handler(SIGPIPE, SIG_IGN, 1);
} }

207
libfuse/lib/fuse_versionscript

@ -1,207 +0,0 @@
FUSE_2.2 {
global:
fuse_destroy;
fuse_exit;
fuse_exited;
fuse_invalidate;
fuse_is_lib_option;
fuse_loop;
fuse_loop_mt;
fuse_loop_mt_proc;
fuse_main;
fuse_main_compat1;
fuse_main_compat2;
fuse_mount_compat1;
fuse_new_compat1;
fuse_new_compat2;
fuse_process_cmd;
fuse_read_cmd;
fuse_set_getcontext_func;
fuse_setup_compat2;
};
FUSE_2.4 {
global:
fuse_add_dirent;
fuse_chan_bufsize;
fuse_chan_data;
fuse_chan_destroy;
fuse_chan_fd;
fuse_chan_receive;
fuse_chan_send;
fuse_chan_session;
fuse_dirent_size;
fuse_kern_chan_new;
fuse_lowlevel_is_lib_option;
fuse_reply_attr;
fuse_reply_buf;
fuse_reply_entry;
fuse_reply_err;
fuse_reply_none;
fuse_reply_readlink;
fuse_reply_write;
fuse_reply_xattr;
fuse_req_userdata;
fuse_session_add_chan;
fuse_session_destroy;
fuse_session_exit;
fuse_session_exited;
fuse_session_loop;
fuse_session_loop_mt;
fuse_session_new;
fuse_session_next_chan;
fuse_session_process;
fuse_session_reset;
} FUSE_2.2;
FUSE_2.5 {
global:
fuse_lowlevel_new_compat;
fuse_main_real_compat22;
fuse_mount_compat22;
fuse_new_compat22;
fuse_opt_parse;
fuse_opt_add_opt;
fuse_opt_add_arg;
fuse_opt_free_args;
fuse_opt_match;
fuse_parse_cmdline;
fuse_remove_signal_handlers;
fuse_reply_create;
fuse_reply_open;
fuse_reply_open_compat;
fuse_reply_statfs;
fuse_reply_statfs_compat;
fuse_setup_compat22;
fuse_set_signal_handlers;
} FUSE_2.4;
FUSE_2.6 {
global:
fuse_add_direntry;
fuse_chan_new;
fuse_chan_new_compat24;
fuse_chan_recv;
fuse_daemonize;
fuse_get_session;
fuse_interrupted;
fuse_lowlevel_new;
fuse_lowlevel_new_compat25;
fuse_main_real;
fuse_main_real_compat25;
fuse_mount;
fuse_mount_compat25;
fuse_new;
fuse_new_compat25;
fuse_opt_insert_arg;
fuse_reply_lock;
fuse_req_interrupt_func;
fuse_req_interrupted;
fuse_session_remove_chan;
fuse_setup;
fuse_setup_compat25;
fuse_teardown;
fuse_teardown_compat22;
fuse_unmount;
fuse_unmount_compat22;
} FUSE_2.5;
FUSE_2.7 {
global:
fuse_fs_access;
fuse_fs_bmap;
fuse_fs_chmod;
fuse_fs_chown;
fuse_fs_create;
fuse_fs_destroy;
fuse_fs_fgetattr;
fuse_fs_flush;
fuse_fs_fsync;
fuse_fs_fsyncdir;
fuse_fs_ftruncate;
fuse_fs_getattr;
fuse_fs_getxattr;
fuse_fs_init;
fuse_fs_link;
fuse_fs_listxattr;
fuse_fs_lock;
fuse_fs_mkdir;
fuse_fs_mknod;
fuse_fs_new;
fuse_fs_open;
fuse_fs_opendir;
fuse_fs_read;
fuse_fs_readdir;
fuse_fs_readlink;
fuse_fs_release;
fuse_fs_releasedir;
fuse_fs_removexattr;
fuse_fs_rename;
fuse_fs_rmdir;
fuse_fs_setxattr;
fuse_fs_statfs;
fuse_fs_symlink;
fuse_fs_truncate;
fuse_fs_unlink;
fuse_fs_utimens;
fuse_fs_write;
fuse_register_module;
fuse_reply_iov;
fuse_version;
} FUSE_2.6;
FUSE_2.7.5 {
global:
fuse_reply_bmap;
} FUSE_2.7;
FUSE_2.8 {
global:
cuse_lowlevel_new;
cuse_lowlevel_main;
cuse_lowlevel_setup;
cuse_lowlevel_teardown;
fuse_fs_ioctl;
fuse_fs_poll;
fuse_get_context;
fuse_getgroups;
fuse_lowlevel_notify_inval_entry;
fuse_lowlevel_notify_inval_inode;
fuse_lowlevel_notify_poll;
fuse_notify_poll;
fuse_opt_add_opt_escaped;
fuse_pollhandle_destroy;
fuse_reply_ioctl;
fuse_reply_ioctl_iov;
fuse_reply_ioctl_retry;
fuse_reply_poll;
fuse_req_ctx;
fuse_req_getgroups;
fuse_session_data;
} FUSE_2.7.5;
FUSE_2.9 {
global:
fuse_buf_copy;
fuse_buf_size;
fuse_fs_read_buf;
fuse_fs_write_buf;
fuse_lowlevel_notify_retrieve;
fuse_lowlevel_notify_store;
fuse_reply_data;
fuse_session_process_buf;
fuse_session_receive_buf;
fuse_start_cleanup_thread;
fuse_stop_cleanup_thread;
fuse_clean_cache;
fuse_lowlevel_notify_delete;
fuse_fs_flock;
} FUSE_2.8;
FUSE_2.9.1 {
global:
fuse_fs_fallocate;
local:
*;
} FUSE_2.9;

137
libfuse/lib/helper.c

@ -11,7 +11,6 @@
#include "fuse_misc.h" #include "fuse_misc.h"
#include "fuse_opt.h" #include "fuse_opt.h"
#include "fuse_lowlevel.h" #include "fuse_lowlevel.h"
#include "fuse_common_compat.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -30,7 +29,6 @@ enum {
struct helper_opts struct helper_opts
{ {
int singlethread;
int foreground; int foreground;
int nodefault_subtype; int nodefault_subtype;
char *mountpoint; char *mountpoint;
@ -45,7 +43,6 @@ struct fuse_opt fuse_helper_opts[] =
FUSE_HELPER_OPT("-d", foreground), FUSE_HELPER_OPT("-d", foreground),
FUSE_HELPER_OPT("debug", foreground), FUSE_HELPER_OPT("debug", foreground),
FUSE_HELPER_OPT("-f", foreground), FUSE_HELPER_OPT("-f", foreground),
FUSE_HELPER_OPT("-s", singlethread),
FUSE_HELPER_OPT("fsname=", nodefault_subtype), FUSE_HELPER_OPT("fsname=", nodefault_subtype),
FUSE_HELPER_OPT("subtype=", nodefault_subtype), FUSE_HELPER_OPT("subtype=", nodefault_subtype),
FUSE_OPT_KEY("-h", KEY_HELP), FUSE_OPT_KEY("-h", KEY_HELP),
@ -58,7 +55,7 @@ struct fuse_opt fuse_helper_opts[] =
FUSE_OPT_KEY("fsname=", FUSE_OPT_KEY_KEEP), FUSE_OPT_KEY("fsname=", FUSE_OPT_KEY_KEEP),
FUSE_OPT_KEY("subtype=", FUSE_OPT_KEY_KEEP), FUSE_OPT_KEY("subtype=", FUSE_OPT_KEY_KEEP),
FUSE_OPT_END FUSE_OPT_END
};
};
static void usage(const char *progname) static void usage(const char *progname)
{ {
@ -78,7 +75,6 @@ static void helper_help(void)
"FUSE options:\n" "FUSE options:\n"
" -d -o debug enable debug output (implies -f)\n" " -d -o debug enable debug output (implies -f)\n"
" -f foreground operation\n" " -f foreground operation\n"
" -s disable multi-threaded operation\n"
"\n" "\n"
); );
} }
@ -150,7 +146,6 @@ static int add_default_subtype(const char *progname, struct fuse_args *args)
int int
fuse_parse_cmdline(struct fuse_args *args_, fuse_parse_cmdline(struct fuse_args *args_,
char **mountpoint_, char **mountpoint_,
int *multithreaded_,
int *foreground_) int *foreground_)
{ {
int res; int res;
@ -177,8 +172,6 @@ fuse_parse_cmdline(struct fuse_args *args_,
else else
free(hopts.mountpoint); free(hopts.mountpoint);
if(multithreaded_)
*multithreaded_ = !hopts.singlethread;
if(foreground_) if(foreground_)
*foreground_ = hopts.foreground; *foreground_ = hopts.foreground;
@ -260,7 +253,7 @@ fuse_mount_common(const char *mountpoint_,
close(fd); close(fd);
} while(fd >= 0 && fd <= 2); } while(fd >= 0 && fd <= 2);
fd = fuse_mount_compat25(mountpoint_, args_);
fd = fuse_kern_mount(mountpoint_,args_);
if(fd == -1) if(fd == -1)
return NULL; return NULL;
@ -297,10 +290,8 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
const struct fuse_operations *op, const struct fuse_operations *op,
size_t op_size, size_t op_size,
char **mountpoint, char **mountpoint,
int *multithreaded,
int *fd, int *fd,
void *user_data,
int compat)
void *user_data)
{ {
struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
struct fuse_chan *ch; struct fuse_chan *ch;
@ -308,7 +299,7 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
int foreground; int foreground;
int res; int res;
res = fuse_parse_cmdline(&args, mountpoint, multithreaded, &foreground);
res = fuse_parse_cmdline(&args, mountpoint, &foreground);
if (res == -1) if (res == -1)
return NULL; return NULL;
@ -318,7 +309,7 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
goto err_free; goto err_free;
} }
fuse = fuse_new_common(ch, &args, op, op_size, user_data, compat);
fuse = fuse_new_common(ch, &args, op, op_size, user_data);
fuse_opt_free_args(&args); fuse_opt_free_args(&args);
if (fuse == NULL) if (fuse == NULL)
goto err_unmount; goto err_unmount;
@ -336,21 +327,21 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
return fuse; return fuse;
err_unmount:
err_unmount:
fuse_unmount_common(*mountpoint, ch); fuse_unmount_common(*mountpoint, ch);
if (fuse) if (fuse)
fuse_destroy(fuse); fuse_destroy(fuse);
err_free:
err_free:
free(*mountpoint); free(*mountpoint);
return NULL; return NULL;
} }
struct fuse *fuse_setup(int argc, char *argv[], struct fuse *fuse_setup(int argc, char *argv[],
const struct fuse_operations *op, size_t op_size, const struct fuse_operations *op, size_t op_size,
char **mountpoint, int *multithreaded, void *user_data)
char **mountpoint, void *user_data)
{ {
return fuse_setup_common(argc, argv, op, op_size, mountpoint, return fuse_setup_common(argc, argv, op, op_size, mountpoint,
multithreaded, NULL, user_data, 0);
NULL, user_data);
} }
static void fuse_teardown_common(struct fuse *fuse, char *mountpoint) static void fuse_teardown_common(struct fuse *fuse, char *mountpoint)
@ -370,22 +361,19 @@ void fuse_teardown(struct fuse *fuse, char *mountpoint)
static int fuse_main_common(int argc, char *argv[], static int fuse_main_common(int argc, char *argv[],
const struct fuse_operations *op, size_t op_size, const struct fuse_operations *op, size_t op_size,
void *user_data, int compat)
void *user_data)
{ {
struct fuse *fuse; struct fuse *fuse;
char *mountpoint; char *mountpoint;
int multithreaded;
int res; int res;
fuse = fuse_setup_common(argc, argv, op, op_size, &mountpoint,
&multithreaded, NULL, user_data, compat);
fuse = fuse_setup_common(argc, argv, op, op_size,
&mountpoint,
NULL, user_data);
if (fuse == NULL) if (fuse == NULL)
return 1; return 1;
if (multithreaded)
res = fuse_loop_mt(fuse); res = fuse_loop_mt(fuse);
else
res = fuse_loop(fuse);
fuse_teardown_common(fuse, mountpoint); fuse_teardown_common(fuse, mountpoint);
if (res == -1) if (res == -1)
@ -397,7 +385,7 @@ static int fuse_main_common(int argc, char *argv[],
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
size_t op_size, void *user_data) size_t op_size, void *user_data)
{ {
return fuse_main_common(argc, argv, op, op_size, user_data, 0);
return fuse_main_common(argc, argv, op, op_size, user_data);
} }
#undef fuse_main #undef fuse_main
@ -412,100 +400,3 @@ int fuse_version(void)
{ {
return FUSE_VERSION; return FUSE_VERSION;
} }
#include "fuse_compat.h"
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
struct fuse *fuse_setup_compat22(int argc, char *argv[],
const struct fuse_operations_compat22 *op,
size_t op_size, char **mountpoint,
int *multithreaded, int *fd)
{
return fuse_setup_common(argc, argv, (struct fuse_operations *) op,
op_size, mountpoint, multithreaded, fd, NULL,
22);
}
struct fuse *fuse_setup_compat2(int argc, char *argv[],
const struct fuse_operations_compat2 *op,
char **mountpoint, int *multithreaded,
int *fd)
{
return fuse_setup_common(argc, argv, (struct fuse_operations *) op,
sizeof(struct fuse_operations_compat2),
mountpoint, multithreaded, fd, NULL, 21);
}
int fuse_main_real_compat22(int argc, char *argv[],
const struct fuse_operations_compat22 *op,
size_t op_size)
{
return fuse_main_common(argc, argv, (struct fuse_operations *) op,
op_size, NULL, 22);
}
void fuse_main_compat1(int argc, char *argv[],
const struct fuse_operations_compat1 *op)
{
fuse_main_common(argc, argv, (struct fuse_operations *) op,
sizeof(struct fuse_operations_compat1), NULL, 11);
}
int fuse_main_compat2(int argc, char *argv[],
const struct fuse_operations_compat2 *op)
{
return fuse_main_common(argc, argv, (struct fuse_operations *) op,
sizeof(struct fuse_operations_compat2), NULL,
21);
}
int fuse_mount_compat1(const char *mountpoint, const char *args[])
{
/* just ignore mount args for now */
(void) args;
return fuse_mount_compat22(mountpoint, NULL);
}
FUSE_SYMVER(".symver fuse_setup_compat2,__fuse_setup@");
FUSE_SYMVER(".symver fuse_setup_compat22,fuse_setup@FUSE_2.2");
FUSE_SYMVER(".symver fuse_teardown,__fuse_teardown@");
FUSE_SYMVER(".symver fuse_main_compat2,fuse_main@");
FUSE_SYMVER(".symver fuse_main_real_compat22,fuse_main_real@FUSE_2.2");
#endif /* __FreeBSD__ || __NetBSD__ */
struct fuse *fuse_setup_compat25(int argc, char *argv[],
const struct fuse_operations_compat25 *op,
size_t op_size, char **mountpoint,
int *multithreaded, int *fd)
{
return fuse_setup_common(argc, argv, (struct fuse_operations *) op,
op_size, mountpoint, multithreaded, fd, NULL,
25);
}
int fuse_main_real_compat25(int argc, char *argv[],
const struct fuse_operations_compat25 *op,
size_t op_size)
{
return fuse_main_common(argc, argv, (struct fuse_operations *) op,
op_size, NULL, 25);
}
void fuse_teardown_compat22(struct fuse *fuse, int fd, char *mountpoint)
{
(void) fd;
fuse_teardown_common(fuse, mountpoint);
}
int fuse_mount_compat25(const char *mountpoint, struct fuse_args *args)
{
return fuse_kern_mount(mountpoint, args);
}
FUSE_SYMVER(".symver fuse_setup_compat25,fuse_setup@FUSE_2.5");
FUSE_SYMVER(".symver fuse_teardown_compat22,fuse_teardown@FUSE_2.2");
FUSE_SYMVER(".symver fuse_main_real_compat25,fuse_main_real@FUSE_2.5");
FUSE_SYMVER(".symver fuse_mount_compat25,fuse_mount@FUSE_2.5");

57
libfuse/lib/mount_bsd.c

@ -145,53 +145,6 @@ static int fuse_mount_opt_proc(void *data, const char *arg, int key,
return 1; return 1;
} }
void fuse_unmount_compat22(const char *mountpoint)
{
char dev[128];
char *ssc, *umount_cmd;
FILE *sf;
int rv;
char seekscript[] =
/* error message is annoying in help output */
"exec 2>/dev/null; "
"/usr/bin/fstat " FUSE_DEV_TRUNK "* | "
"/usr/bin/awk 'BEGIN{ getline; if (! ($3 == \"PID\" && $10 == \"NAME\")) exit 1; }; "
" { if ($3 == %d) print $10; }' | "
"/usr/bin/sort | "
"/usr/bin/uniq | "
"/usr/bin/awk '{ i += 1; if (i > 1){ exit 1; }; printf; }; END{ if (i == 0) exit 1; }'";
(void) mountpoint;
/*
* If we don't know the fd, we have to resort to the scripted
* solution -- iterating over the fd-s is unpractical, as we
* don't know how many of open files we have. (This could be
* looked up in procfs -- however, that's optional on FBSD; or
* read out from the kmem -- however, that's bound to
* privileges (in fact, that's what happens when we call the
* setgid kmem fstat(1) utility).
*/
if (asprintf(&ssc, seekscript, getpid()) == -1)
return;
errno = 0;
sf = popen(ssc, "r");
free(ssc);
if (! sf)
return;
fgets(dev, sizeof(dev), sf);
rv = pclose(sf);
if (rv)
return;
if (asprintf(&umount_cmd, "/sbin/umount %s", dev) == -1)
return;
system(umount_cmd);
free(umount_cmd);
}
static void do_unmount(char *dev, int fd) static void do_unmount(char *dev, int fd)
{ {
char device_path[SPECNAMELEN + 12]; char device_path[SPECNAMELEN + 12];
@ -241,7 +194,7 @@ void fuse_kern_unmount(const char *mountpoint, int fd)
do_unmount(dev, fd); do_unmount(dev, fd);
out:
out:
close(fd); close(fd);
} }
@ -295,7 +248,7 @@ static int fuse_mount_core(const char *mountpoint, const char *opts)
return -1; return -1;
} }
mount:
mount:
if (getenv("FUSE_NO_MOUNT") || ! mountpoint) if (getenv("FUSE_NO_MOUNT") || ! mountpoint)
goto out; goto out;
@ -356,7 +309,7 @@ mount:
return -1; return -1;
} }
out:
out:
return fd; return fd;
} }
@ -383,9 +336,7 @@ int fuse_kern_mount(const char *mountpoint, struct fuse_args *args)
return 0; return 0;
res = fuse_mount_core(mountpoint, mo.kernel_opts); res = fuse_mount_core(mountpoint, mo.kernel_opts);
out:
out:
free(mo.kernel_opts); free(mo.kernel_opts);
return res; return res;
} }
FUSE_SYMVER(".symver fuse_unmount_compat22,fuse_unmount@FUSE_2.2");

44
libfuse/lib/mount_generic.c

@ -10,7 +10,6 @@
#include "fuse_i.h" #include "fuse_i.h"
#include "fuse_misc.h" #include "fuse_misc.h"
#include "fuse_opt.h" #include "fuse_opt.h"
#include "fuse_common_compat.h"
#include "mount_util.h" #include "mount_util.h"
#include <stdio.h> #include <stdio.h>
@ -129,16 +128,16 @@ static const struct fuse_opt fuse_mount_opts[] = {
static void mount_help(void) static void mount_help(void)
{ {
fprintf(stderr, fprintf(stderr,
" -o allow_other allow access to other users\n"
" -o allow_root allow access to root\n"
" -o auto_unmount auto unmount on process termination\n"
" -o nonempty allow mounts over non-empty file/dir\n"
" -o default_permissions enable permission checking by kernel\n"
" -o fsname=NAME set filesystem name\n"
" -o subtype=NAME set filesystem type\n"
" -o large_read issue large read requests (2.4 only)\n"
" -o max_read=N set maximum size of read requests\n"
"\n");
" -o allow_other allow access to other users\n"
" -o allow_root allow access to root\n"
" -o auto_unmount auto unmount on process termination\n"
" -o nonempty allow mounts over non-empty file/dir\n"
" -o default_permissions enable permission checking by kernel\n"
" -o fsname=NAME set filesystem name\n"
" -o subtype=NAME set filesystem type\n"
" -o large_read issue large read requests (2.4 only)\n"
" -o max_read=N set maximum size of read requests\n"
"\n");
} }
static void exec_fusermount(const char *argv[]) static void exec_fusermount(const char *argv[])
@ -343,11 +342,6 @@ void fuse_kern_unmount(const char *mountpoint, int fd)
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
} }
void fuse_unmount_compat22(const char *mountpoint)
{
fuse_kern_unmount(mountpoint, -1);
}
static int fuse_mount_fusermount(const char *mountpoint, struct mount_opts *mo, static int fuse_mount_fusermount(const char *mountpoint, struct mount_opts *mo,
const char *opts, int quiet) const char *opts, int quiet)
{ {
@ -418,15 +412,6 @@ static int fuse_mount_fusermount(const char *mountpoint, struct mount_opts *mo,
return rv; return rv;
} }
int fuse_mount_compat22(const char *mountpoint, const char *opts)
{
struct mount_opts mo;
memset(&mo, 0, sizeof(mo));
mo.flags = MS_NOSUID | MS_NODEV;
return fuse_mount_fusermount(mountpoint, &mo, opts, 0);
}
static int fuse_mount_sys(const char *mnt, struct mount_opts *mo, static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
const char *mnt_opts) const char *mnt_opts)
{ {
@ -553,9 +538,9 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
return fd; return fd;
out_umount:
out_umount:
umount2(mnt, 2); /* lazy umount */ umount2(mnt, 2); /* lazy umount */
out_close:
out_close:
free(type); free(type);
free(source); free(source);
close(fd); close(fd);
@ -631,7 +616,7 @@ int fuse_kern_mount(const char *mountpoint, struct fuse_args *args)
res = fuse_mount_fusermount(mountpoint, &mo, mnt_opts, 0); res = fuse_mount_fusermount(mountpoint, &mo, mnt_opts, 0);
} }
} }
out:
out:
free(mnt_opts); free(mnt_opts);
free(mo.fsname); free(mo.fsname);
free(mo.subtype); free(mo.subtype);
@ -641,6 +626,3 @@ out:
free(mo.mtab_opts); free(mo.mtab_opts);
return res; return res;
} }
FUSE_SYMVER(".symver fuse_mount_compat22,fuse_mount@FUSE_2.2");
FUSE_SYMVER(".symver fuse_unmount_compat22,fuse_unmount@FUSE_2.2");

444
libfuse/lib/ulockmgr.c

@ -1,444 +0,0 @@
/*
libulockmgr: Userspace Lock Manager Library
Copyright (C) 2006 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB
*/
/* #define DEBUG 1 */
#include "ulockmgr.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <assert.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/wait.h>
struct message {
unsigned intr : 1;
unsigned nofd : 1;
pthread_t thr;
int cmd;
int fd;
struct flock lock;
int error;
};
struct fd_store {
struct fd_store *next;
int fd;
int inuse;
};
struct owner {
struct owner *next;
struct owner *prev;
struct fd_store *fds;
void *id;
size_t id_len;
int cfd;
};
static pthread_mutex_t ulockmgr_lock;
static int ulockmgr_cfd = -1;
static struct owner owner_list = { .next = &owner_list, .prev = &owner_list };
#define MAX_SEND_FDS 2
static void list_del_owner(struct owner *owner)
{
struct owner *prev = owner->prev;
struct owner *next = owner->next;
prev->next = next;
next->prev = prev;
}
static void list_add_owner(struct owner *owner, struct owner *next)
{
struct owner *prev = next->prev;
owner->next = next;
owner->prev = prev;
prev->next = owner;
next->prev = owner;
}
/*
* There's a bug in the linux kernel (< 2.6.22) recv() implementation
* on AF_UNIX, SOCK_STREAM sockets, that could cause it to return
* zero, even if data was available. Retrying the recv will return
* the data in this case.
*/
static int do_recv(int sock, void *buf, size_t len, int flags)
{
int res = recv(sock, buf, len, flags);
if (res == 0)
res = recv(sock, buf, len, flags);
return res;
}
static int ulockmgr_send_message(int sock, void *buf, size_t buflen,
int *fdp, int numfds)
{
struct msghdr msg;
struct cmsghdr *p_cmsg;
struct iovec vec;
size_t cmsgbuf[CMSG_SPACE(sizeof(int) * MAX_SEND_FDS) / sizeof(size_t)];
int res;
assert(numfds <= MAX_SEND_FDS);
msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf);
p_cmsg = CMSG_FIRSTHDR(&msg);
p_cmsg->cmsg_level = SOL_SOCKET;
p_cmsg->cmsg_type = SCM_RIGHTS;
p_cmsg->cmsg_len = CMSG_LEN(sizeof(int) * numfds);
memcpy(CMSG_DATA(p_cmsg), fdp, sizeof(int) * numfds);
msg.msg_controllen = p_cmsg->cmsg_len;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = &vec;
msg.msg_iovlen = 1;
msg.msg_flags = 0;
vec.iov_base = buf;
vec.iov_len = buflen;
res = sendmsg(sock, &msg, MSG_NOSIGNAL);
if (res == -1) {
perror("libulockmgr: sendmsg");
return -1;
}
if ((size_t) res != buflen) {
fprintf(stderr, "libulockmgr: sendmsg short\n");
return -1;
}
return 0;
}
static int ulockmgr_start_daemon(void)
{
int sv[2];
int res;
char tmp[64];
res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
if (res == -1) {
perror("libulockmgr: socketpair");
return -1;
}
snprintf(tmp, sizeof(tmp), "exec ulockmgr_server %i", sv[0]);
res = system(tmp);
close(sv[0]);
if (res == -1 || !WIFEXITED(res) || WEXITSTATUS(res) != 0) {
close(sv[1]);
return -1;
}
ulockmgr_cfd = sv[1];
return 0;
}
static struct owner *ulockmgr_new_owner(const void *id, size_t id_len)
{
int sv[2];
int res;
char c = 'm';
struct owner *o;
if (ulockmgr_cfd == -1 && ulockmgr_start_daemon() == -1)
return NULL;
o = calloc(1, sizeof(struct owner) + id_len);
if (!o) {
fprintf(stderr, "libulockmgr: failed to allocate memory\n");
return NULL;
}
o->id = o + 1;
o->id_len = id_len;
res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
if (res == -1) {
perror("libulockmgr: socketpair");
goto out_free;
}
res = ulockmgr_send_message(ulockmgr_cfd, &c, sizeof(c), &sv[0], 1);
close(sv[0]);
if (res == -1) {
close(ulockmgr_cfd);
ulockmgr_cfd = -1;
goto out_close;
}
o->cfd = sv[1];
memcpy(o->id, id, id_len);
list_add_owner(o, &owner_list);
return o;
out_close:
close(sv[1]);
out_free:
free(o);
return NULL;
}
static int ulockmgr_send_request(struct message *msg, const void *id,
size_t id_len)
{
int sv[2];
int cfd;
struct owner *o;
struct fd_store *f = NULL;
struct fd_store *newf = NULL;
struct fd_store **fp;
int fd = msg->fd;
int cmd = msg->cmd;
int res;
int unlockall = (cmd == F_SETLK && msg->lock.l_type == F_UNLCK &&
msg->lock.l_start == 0 && msg->lock.l_len == 0);
for (o = owner_list.next; o != &owner_list; o = o->next)
if (o->id_len == id_len && memcmp(o->id, id, id_len) == 0)
break;
if (o == &owner_list)
o = NULL;
if (!o && cmd != F_GETLK && msg->lock.l_type != F_UNLCK)
o = ulockmgr_new_owner(id, id_len);
if (!o) {
if (cmd == F_GETLK) {
res = fcntl(msg->fd, F_GETLK, &msg->lock);
return (res == -1) ? -errno : 0;
} else if (msg->lock.l_type == F_UNLCK)
return 0;
else
return -ENOLCK;
}
if (unlockall)
msg->nofd = 1;
else {
for (fp = &o->fds; *fp; fp = &(*fp)->next) {
f = *fp;
if (f->fd == fd) {
msg->nofd = 1;
break;
}
}
}
if (!msg->nofd) {
newf = f = calloc(1, sizeof(struct fd_store));
if (!f) {
fprintf(stderr, "libulockmgr: failed to allocate memory\n");
return -ENOLCK;
}
}
res = socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
if (res == -1) {
perror("libulockmgr: socketpair");
free(newf);
return -ENOLCK;
}
cfd = sv[1];
sv[1] = msg->fd;
res = ulockmgr_send_message(o->cfd, msg, sizeof(struct message), sv,
msg->nofd ? 1 : 2);
close(sv[0]);
if (res == -1) {
free(newf);
close(cfd);
return -EIO;
}
if (newf) {
newf->fd = msg->fd;
newf->next = o->fds;
o->fds = newf;
}
if (f)
f->inuse++;
res = do_recv(cfd, msg, sizeof(struct message), MSG_WAITALL);
if (res == -1) {
perror("libulockmgr: recv");
msg->error = EIO;
} else if (res != sizeof(struct message)) {
fprintf(stderr, "libulockmgr: recv short\n");
msg->error = EIO;
} else if (cmd == F_SETLKW && msg->error == EAGAIN) {
pthread_mutex_unlock(&ulockmgr_lock);
while (1) {
sigset_t old;
sigset_t unblock;
int errno_save;
sigemptyset(&unblock);
sigaddset(&unblock, SIGUSR1);
pthread_sigmask(SIG_UNBLOCK, &unblock, &old);
res = do_recv(cfd, msg, sizeof(struct message),
MSG_WAITALL);
errno_save = errno;
pthread_sigmask(SIG_SETMASK, &old, NULL);
if (res == sizeof(struct message))
break;
else if (res >= 0) {
fprintf(stderr, "libulockmgr: recv short\n");
msg->error = EIO;
break;
} else if (errno_save != EINTR) {
errno = errno_save;
perror("libulockmgr: recv");
msg->error = EIO;
break;
}
msg->intr = 1;
res = send(o->cfd, msg, sizeof(struct message),
MSG_NOSIGNAL);
if (res == -1) {
perror("libulockmgr: send");
msg->error = EIO;
break;
}
if (res != sizeof(struct message)) {
fprintf(stderr, "libulockmgr: send short\n");
msg->error = EIO;
break;
}
}
pthread_mutex_lock(&ulockmgr_lock);
}
if (f)
f->inuse--;
close(cfd);
if (unlockall) {
for (fp = &o->fds; *fp;) {
f = *fp;
if (f->fd == fd && !f->inuse) {
*fp = f->next;
free(f);
} else
fp = &f->next;
}
if (!o->fds) {
list_del_owner(o);
close(o->cfd);
free(o);
}
/* Force OK on unlock-all, since it _will_ succeed once the
owner is deleted */
msg->error = 0;
}
return -msg->error;
}
#ifdef DEBUG
static uint32_t owner_hash(const unsigned char *id, size_t id_len)
{
uint32_t h = 0;
size_t i;
for (i = 0; i < id_len; i++)
h = ((h << 8) | (h >> 24)) ^ id[i];
return h;
}
#endif
static int ulockmgr_canonicalize(int fd, struct flock *lock)
{
off_t offset;
if (lock->l_whence == SEEK_CUR) {
offset = lseek(fd, 0, SEEK_CUR);
if (offset == (off_t) -1)
return -errno;
} else if (lock->l_whence == SEEK_END) {
struct stat stbuf;
int res = fstat(fd, &stbuf);
if (res == -1)
return -errno;
offset = stbuf.st_size;
} else
offset = 0;
lock->l_whence = SEEK_SET;
lock->l_start += offset;
if (lock->l_start < 0)
return -EINVAL;
if (lock->l_len < 0) {
lock->l_start += lock->l_len;
if (lock->l_start < 0)
return -EINVAL;
lock->l_len = -lock->l_len;
}
if (lock->l_len && lock->l_start + lock->l_len - 1 < 0)
return -EINVAL;
return 0;
}
int ulockmgr_op(int fd, int cmd, struct flock *lock, const void *owner,
size_t owner_len)
{
int err;
struct message msg;
sigset_t old;
sigset_t block;
if (cmd != F_GETLK && cmd != F_SETLK && cmd != F_SETLKW)
return -EINVAL;
if (lock->l_type != F_RDLCK && lock->l_type != F_WRLCK &&
lock->l_type != F_UNLCK)
return -EINVAL;
if (lock->l_whence != SEEK_SET && lock->l_whence != SEEK_CUR &&
lock->l_whence != SEEK_END)
return -EINVAL;
#ifdef DEBUG
fprintf(stderr, "libulockmgr: %i %i %i %lli %lli own: 0x%08x\n",
cmd, lock->l_type, lock->l_whence, lock->l_start, lock->l_len,
owner_hash(owner, owner_len));
#endif
/* Unlock should never block anyway */
if (cmd == F_SETLKW && lock->l_type == F_UNLCK)
cmd = F_SETLK;
memset(&msg, 0, sizeof(struct message));
msg.cmd = cmd;
msg.fd = fd;
msg.lock = *lock;
err = ulockmgr_canonicalize(fd, &msg.lock);
if (err)
return err;
sigemptyset(&block);
sigaddset(&block, SIGUSR1);
pthread_sigmask(SIG_BLOCK, &block, &old);
pthread_mutex_lock(&ulockmgr_lock);
err = ulockmgr_send_request(&msg, owner, owner_len);
pthread_mutex_unlock(&ulockmgr_lock);
pthread_sigmask(SIG_SETMASK, &old, NULL);
if (!err && cmd == F_GETLK) {
if (msg.lock.l_type == F_UNLCK)
lock->l_type = F_UNLCK;
else
*lock = msg.lock;
}
return err;
}

58
libfuse/util/Makefile.am

@ -1,58 +0,0 @@
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = -D_FILE_OFFSET_BITS=64
bin_PROGRAMS = fusermount ulockmgr_server
noinst_PROGRAMS = mount.fuse
# we re-use mount_util.c from the library, but do want to keep ourself
# as stand-alone as possible. in order to make an out-of-source build
# possible, we "generate" the file from its original location by
# copying it over.
fusermount_SOURCES = fusermount.c mount_util.c
fusermount_CPPFLAGS = -I$(top_srcdir)/lib
BUILT_SOURCES = mount_util.c
mount_util.c: $(top_srcdir)/lib/mount_util.c
@cp $(top_srcdir)/lib/mount_util.c .
mount_fuse_SOURCES = mount.fuse.c
ulockmgr_server_SOURCES = ulockmgr_server.c
ulockmgr_server_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_REENTRANT
ulockmgr_server_LDFLAGS = -pthread
install-exec-hook:
-chmod u+s $(DESTDIR)$(bindir)/fusermount
@if test ! -e $(DESTDIR)/dev/fuse; then \
$(MKDIR_P) $(DESTDIR)/dev; \
echo "mknod $(DESTDIR)/dev/fuse -m 0666 c 10 229 || true"; \
mknod $(DESTDIR)/dev/fuse -m 0666 c 10 229 || true; \
fi
EXTRA_DIST = udev.rules init_script
MOUNT_FUSE_PATH = @MOUNT_FUSE_PATH@
UDEV_RULES_PATH = @UDEV_RULES_PATH@
INIT_D_PATH = @INIT_D_PATH@
install-exec-local:
$(MKDIR_P) $(DESTDIR)$(MOUNT_FUSE_PATH)
$(INSTALL_PROGRAM) $(builddir)/mount.fuse $(DESTDIR)$(MOUNT_FUSE_PATH)/mount.fuse
$(MKDIR_P) $(DESTDIR)$(INIT_D_PATH)
$(INSTALL_SCRIPT) $(srcdir)/init_script $(DESTDIR)$(INIT_D_PATH)/fuse
@if test -x /usr/sbin/update-rc.d; then \
echo "/usr/sbin/update-rc.d fuse start 34 S . start 41 0 6 . || true"; \
/usr/sbin/update-rc.d fuse start 34 S . start 41 0 6 . || true; \
fi
install-data-local:
$(MKDIR_P) $(DESTDIR)$(UDEV_RULES_PATH)
$(INSTALL_DATA) $(srcdir)/udev.rules $(DESTDIR)$(UDEV_RULES_PATH)/99-fuse.rules
uninstall-local:
rm -f $(DESTDIR)$(MOUNT_FUSE_PATH)/mount.fuse
rm -f $(DESTDIR)$(UDEV_RULES_PATH)/99-fuse.rules
rm -f $(DESTDIR)$(INIT_D_PATH)/fuse
@if test -x /usr/sbin/update-rc.d; then \
echo "/usr/sbin/update-rc.d fuse remove || true"; \
/usr/sbin/update-rc.d fuse remove || true; \
fi

89
libfuse/util/init_script

@ -1,89 +0,0 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: fuse
# Required-Start:
# Should-Start: udev
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Start and stop fuse.
# Description: Load the fuse module and mount the fuse control
# filesystem.
### END INIT INFO
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MOUNTPOINT=/sys/fs/fuse/connections
# Gracefully exit if the package has been removed.
which fusermount &>/dev/null || exit 5
case "$1" in
start|restart|force-reload)
if ! grep -qw fuse /proc/filesystems; then
echo -n "Loading fuse module"
if ! modprobe fuse >/dev/null 2>&1; then
echo " failed!"
exit 1
else
echo "."
fi
else
echo "Fuse filesystem already available."
fi
if grep -qw fusectl /proc/filesystems && \
! grep -qw $MOUNTPOINT /proc/mounts; then
echo -n "Mounting fuse control filesystem"
if ! mount -t fusectl fusectl $MOUNTPOINT >/dev/null 2>&1; then
echo " failed!"
exit 1
else
echo "."
fi
else
echo "Fuse control filesystem already available."
fi
;;
stop)
if ! grep -qw fuse /proc/filesystems; then
echo "Fuse filesystem not loaded."
exit 7
fi
if grep -qw $MOUNTPOINT /proc/mounts; then
echo -n "Unmounting fuse control filesystem"
if ! umount $MOUNTPOINT >/dev/null 2>&1; then
echo " failed!"
else
echo "."
fi
else
echo "Fuse control filesystem not mounted."
fi
if grep -qw "^fuse" /proc/modules; then
echo -n "Unloading fuse module"
if ! rmmod fuse >/dev/null 2>&1; then
echo " failed!"
else
echo "."
fi
else
echo "Fuse module not loaded."
fi
;;
status)
echo -n "Checking fuse filesystem"
if ! grep -qw fuse /proc/filesystems; then
echo " not available."
exit 3
else
echo " ok."
fi
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}"
exit 1
;;
esac
exit 0

1
libfuse/util/udev.rules

@ -1 +0,0 @@
KERNEL=="fuse", MODE="0666"

425
libfuse/util/ulockmgr_server.c

@ -1,425 +0,0 @@
/*
ulockmgr_server: Userspace Lock Manager Server
Copyright (C) 2006 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU GPL.
See the file COPYING.
*/
/* #define DEBUG 1 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <pthread.h>
#include <stdint.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
struct message {
unsigned intr : 1;
unsigned nofd : 1;
pthread_t thr;
int cmd;
int fd;
struct flock lock;
int error;
};
struct fd_store {
struct fd_store *next;
int fd;
int origfd;
int inuse;
};
struct owner {
struct fd_store *fds;
pthread_mutex_t lock;
};
struct req_data {
struct owner *o;
int cfd;
struct fd_store *f;
struct message msg;
};
#define MAX_SEND_FDS 2
static int receive_message(int sock, void *buf, size_t buflen, int *fdp,
int *numfds)
{
struct msghdr msg;
struct iovec iov;
size_t ccmsg[CMSG_SPACE(sizeof(int) * MAX_SEND_FDS) / sizeof(size_t)];
struct cmsghdr *cmsg;
int res;
int i;
assert(*numfds <= MAX_SEND_FDS);
iov.iov_base = buf;
iov.iov_len = buflen;
memset(&msg, 0, sizeof(msg));
memset(ccmsg, -1, sizeof(ccmsg));
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = ccmsg;
msg.msg_controllen = sizeof(ccmsg);
res = recvmsg(sock, &msg, MSG_WAITALL);
if (!res) {
/* retry on zero return, see do_recv() in ulockmgr.c */
res = recvmsg(sock, &msg, MSG_WAITALL);
if (!res)
return 0;
}
if (res == -1) {
perror("ulockmgr_server: recvmsg");
return -1;
}
if ((size_t) res != buflen) {
fprintf(stderr, "ulockmgr_server: short message received\n");
return -1;
}
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg) {
if (cmsg->cmsg_type != SCM_RIGHTS) {
fprintf(stderr,
"ulockmgr_server: unknown control message %d\n",
cmsg->cmsg_type);
return -1;
}
memcpy(fdp, CMSG_DATA(cmsg), sizeof(int) * *numfds);
if (msg.msg_flags & MSG_CTRUNC) {
fprintf(stderr,
"ulockmgr_server: control message truncated\n");
for (i = 0; i < *numfds; i++)
close(fdp[i]);
*numfds = 0;
}
} else {
if (msg.msg_flags & MSG_CTRUNC) {
fprintf(stderr,
"ulockmgr_server: control message truncated(*)\n");
/* There's a bug in the Linux kernel, that if
not all file descriptors were allocated,
then the cmsg header is not filled in */
cmsg = (struct cmsghdr *) ccmsg;
memcpy(fdp, CMSG_DATA(cmsg), sizeof(int) * *numfds);
for (i = 0; i < *numfds; i++)
close(fdp[i]);
}
*numfds = 0;
}
return res;
}
static int closefrom(int minfd)
{
DIR *dir = opendir("/proc/self/fd");
if (dir) {
int dfd = dirfd(dir);
struct dirent *ent;
while ((ent = readdir(dir))) {
char *end;
int fd = strtol(ent->d_name, &end, 10);
if (ent->d_name[0] && !end[0] && fd >= minfd &&
fd != dfd)
close(fd);
}
closedir(dir);
}
return 0;
}
static void send_reply(int cfd, struct message *msg)
{
int res = send(cfd, msg, sizeof(struct message), MSG_NOSIGNAL);
if (res == -1)
perror("ulockmgr_server: sending reply");
#ifdef DEBUG
fprintf(stderr, "ulockmgr_server: error: %i\n", msg->error);
#endif
}
static void *process_request(void *d_)
{
struct req_data *d = d_;
int res;
assert(d->msg.cmd == F_SETLKW);
res = fcntl(d->f->fd, F_SETLK, &d->msg.lock);
if (res == -1 && errno == EAGAIN) {
d->msg.error = EAGAIN;
d->msg.thr = pthread_self();
send_reply(d->cfd, &d->msg);
res = fcntl(d->f->fd, F_SETLKW, &d->msg.lock);
}
d->msg.error = (res == -1) ? errno : 0;
pthread_mutex_lock(&d->o->lock);
d->f->inuse--;
pthread_mutex_unlock(&d->o->lock);
send_reply(d->cfd, &d->msg);
close(d->cfd);
free(d);
return NULL;
}
static void process_message(struct owner *o, struct message *msg, int cfd,
int fd)
{
struct fd_store *f = NULL;
struct fd_store *newf = NULL;
struct fd_store **fp;
struct req_data *d;
pthread_t tid;
int res;
#ifdef DEBUG
fprintf(stderr, "ulockmgr_server: %i %i %i %lli %lli\n",
msg->cmd, msg->lock.l_type, msg->lock.l_whence,
msg->lock.l_start, msg->lock.l_len);
#endif
if (msg->cmd == F_SETLK && msg->lock.l_type == F_UNLCK &&
msg->lock.l_start == 0 && msg->lock.l_len == 0) {
for (fp = &o->fds; *fp;) {
f = *fp;
if (f->origfd == msg->fd && !f->inuse) {
close(f->fd);
*fp = f->next;
free(f);
} else
fp = &f->next;
}
if (!msg->nofd)
close(fd);
msg->error = 0;
send_reply(cfd, msg);
close(cfd);
return;
}
if (msg->nofd) {
for (fp = &o->fds; *fp; fp = &(*fp)->next) {
f = *fp;
if (f->origfd == msg->fd)
break;
}
if (!*fp) {
fprintf(stderr, "ulockmgr_server: fd %i not found\n",
msg->fd);
msg->error = EIO;
send_reply(cfd, msg);
close(cfd);
return;
}
} else {
newf = f = malloc(sizeof(struct fd_store));
if (!f) {
msg->error = ENOLCK;
send_reply(cfd, msg);
close(cfd);
return;
}
f->fd = fd;
f->origfd = msg->fd;
f->inuse = 0;
}
if (msg->cmd == F_GETLK || msg->cmd == F_SETLK ||
msg->lock.l_type == F_UNLCK) {
res = fcntl(f->fd, msg->cmd, &msg->lock);
msg->error = (res == -1) ? errno : 0;
send_reply(cfd, msg);
close(cfd);
if (newf) {
newf->next = o->fds;
o->fds = newf;
}
return;
}
d = malloc(sizeof(struct req_data));
if (!d) {
msg->error = ENOLCK;
send_reply(cfd, msg);
close(cfd);
free(newf);
return;
}
f->inuse++;
d->o = o;
d->cfd = cfd;
d->f = f;
d->msg = *msg;
res = pthread_create(&tid, NULL, process_request, d);
if (res) {
msg->error = ENOLCK;
send_reply(cfd, msg);
close(cfd);
free(d);
f->inuse--;
free(newf);
return;
}
if (newf) {
newf->next = o->fds;
o->fds = newf;
}
pthread_detach(tid);
}
static void sigusr1_handler(int sig)
{
(void) sig;
/* Nothing to do */
}
static void process_owner(int cfd)
{
struct owner o;
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = sigusr1_handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGUSR1, &sa, NULL) == -1) {
perror("ulockmgr_server: cannot set sigusr1 signal handler");
exit(1);
}
memset(&o, 0, sizeof(struct owner));
pthread_mutex_init(&o.lock, NULL);
while (1) {
struct message msg;
int rfds[2];
int res;
int numfds = 2;
res = receive_message(cfd, &msg, sizeof(msg), rfds, &numfds);
if (!res)
break;
if (res == -1)
exit(1);
if (msg.intr) {
if (numfds != 0)
fprintf(stderr,
"ulockmgr_server: too many fds for intr\n");
pthread_kill(msg.thr, SIGUSR1);
} else {
if (numfds != 2)
continue;
pthread_mutex_lock(&o.lock);
process_message(&o, &msg, rfds[0], rfds[1]);
pthread_mutex_unlock(&o.lock);
}
}
if (o.fds)
fprintf(stderr,
"ulockmgr_server: open file descriptors on exit\n");
}
int main(int argc, char *argv[])
{
int nullfd;
char *end;
int cfd;
sigset_t empty;
if (argc != 2 || !argv[1][0])
goto out_inval;
cfd = strtol(argv[1], &end, 10);
if (*end)
goto out_inval;
/* demonize current process */
switch(fork()) {
case -1:
perror("ulockmgr_server: fork");
exit(1);
case 0:
break;
default:
_exit(0);
}
if (setsid() == -1) {
perror("ulockmgr_server: setsid");
exit(1);
}
(void) chdir("/");
sigemptyset(&empty);
sigprocmask(SIG_SETMASK, &empty, NULL);
if (dup2(cfd, 4) == -1) {
perror("ulockmgr_server: dup2");
exit(1);
}
cfd = 4;
nullfd = open("/dev/null", O_RDWR);
if (nullfd >= 0) {
dup2(nullfd, 0);
dup2(nullfd, 1);
}
close(3);
closefrom(5);
while (1) {
char c;
int sock;
int pid;
int numfds = 1;
int res = receive_message(cfd, &c, sizeof(c), &sock, &numfds);
if (!res)
break;
if (res == -1)
exit(1);
assert(numfds == 1);
pid = fork();
if (pid == -1) {
perror("ulockmgr_server: fork");
close(sock);
continue;
}
if (pid == 0) {
close(cfd);
pid = fork();
if (pid == -1) {
perror("ulockmgr_server: fork");
_exit(1);
}
if (pid == 0)
process_owner(sock);
_exit(0);
}
waitpid(pid, NULL, 0);
close(sock);
}
return 0;
out_inval:
fprintf(stderr, "%s should be started by libulockmgr\n", argv[0]);
return 1;
}
Loading…
Cancel
Save