backward compatibility
diff --git a/lib/Makefile.am b/lib/Makefile.am
index e370ef4..c9a2cd4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -9,4 +9,5 @@
mount.c \
fuse_i.h
-libfuse_la_LDFLAGS = -lpthread -version-number 3:0:0
+libfuse_la_LDFLAGS = -lpthread -version-number 2:2:0 \
+ -Wl,--version-script,fuse_versionscript
diff --git a/lib/fuse.c b/lib/fuse.c
index 100b50f..afc8c74 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -17,6 +17,7 @@
#include <errno.h>
#include <sys/param.h>
+#define FUSE_KERNEL_MINOR_VERSION_NEED 1
#define FUSE_VERSION_FILE_OLD "/proc/fs/fuse/version"
#define FUSE_VERSION_FILE_NEW "/sys/fs/fuse/version"
#define FUSE_DEV_OLD "/proc/fs/fuse/dev"
@@ -1067,8 +1068,12 @@
path = get_path(f, in->nodeid);
if (path != NULL) {
res = -ENOSYS;
- if (f->op.open)
- res = f->op.open(path, &fi);
+ if (f->op.open.curr) {
+ if (!f->compat)
+ res = f->op.open.curr(path, &fi);
+ else
+ res = f->op.open.compat2(path, fi.flags);
+ }
}
if (res == 0) {
int res2;
@@ -1087,8 +1092,12 @@
res2 = __send_reply(f, in, res, &outarg, sizeof(outarg), 1);
if(res2 == -ENOENT) {
/* The open syscall was interrupted, so it must be cancelled */
- if(f->op.release)
- f->op.release(path, &fi);
+ if(f->op.release.curr) {
+ if (!f->compat)
+ f->op.release.curr(path, &fi);
+ else
+ f->op.release.compat2(path, fi.flags);
+ }
} else
get_node(f, in->nodeid)->open_count ++;
pthread_mutex_unlock(&f->lock);
@@ -1146,8 +1155,12 @@
printf("RELEASE[%lu]\n", arg->fh);
fflush(stdout);
}
- if (f->op.release)
- f->op.release(path, &fi);
+ if (f->op.release.curr) {
+ if (!f->compat)
+ f->op.release.curr(path, &fi);
+ else
+ f->op.release.compat2(path, fi.flags);
+ }
if(node->is_hidden && node->open_count == 0)
/* can now clean up this hidden file */
@@ -1252,6 +1265,18 @@
return 0;
}
+static void convert_statfs_compat(struct _fuse_statfs_compat1 *compatbuf,
+ struct statfs *statfs)
+{
+ statfs->f_bsize = compatbuf->block_size;
+ statfs->f_blocks = compatbuf->blocks;
+ statfs->f_bfree = compatbuf->blocks_free;
+ statfs->f_bavail = compatbuf->blocks_free;
+ statfs->f_files = compatbuf->files;
+ statfs->f_ffree = compatbuf->files_free;
+ statfs->f_namelen = compatbuf->namelen;
+}
+
static void convert_statfs(struct statfs *statfs, struct fuse_kstatfs *kstatfs)
{
kstatfs->bsize = statfs->f_bsize;
@@ -1270,8 +1295,17 @@
struct statfs buf;
memset(&buf, 0, sizeof(struct statfs));
- if (f->op.statfs)
- res = f->op.statfs("/", &buf);
+ if (f->op.statfs.curr) {
+ if (!f->compat || f->compat > 11)
+ res = f->op.statfs.curr("/", &buf);
+ else {
+ struct _fuse_statfs_compat1 compatbuf;
+ memset(&compatbuf, 0, sizeof(struct _fuse_statfs_compat1));
+ res = f->op.statfs.compat1(&compatbuf);
+ if (res == 0)
+ convert_statfs_compat(&compatbuf, &buf);
+ }
+ }
else
res = default_statfs(&buf);
@@ -1773,7 +1807,7 @@
FUSE_KERNEL_VERSION);
return -1;
}
- if (f->minorver < FUSE_KERNEL_MINOR_VERSION) {
+ if (f->minorver < FUSE_KERNEL_MINOR_VERSION_NEED) {
fprintf(stderr, "fuse: kernel interface too old: need >= %i.%i\n",
FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
return -1;
@@ -1818,11 +1852,18 @@
return 0;
}
-struct fuse *fuse_new(int fd, const char *opts, const struct fuse_operations *op)
+struct fuse *fuse_new_common(int fd, const char *opts,
+ const struct fuse_operations *op,
+ size_t op_size, int compat)
{
struct fuse *f;
struct node *root;
+ if (sizeof(struct fuse_operations_i) < op_size) {
+ fprintf(stderr, "fuse: warning: library too old, some operations may not not work\n");
+ op_size = sizeof(struct fuse_operations_i);
+ }
+
f = (struct fuse *) calloc(1, sizeof(struct fuse));
if (f == NULL)
goto out;
@@ -1862,7 +1903,8 @@
#endif
f->numworker = 0;
f->numavail = 0;
- f->op = *op;
+ memcpy(&f->op, op, op_size);
+ f->compat = compat;
f->exited = 0;
root = (struct node *) calloc(1, sizeof(struct node));
@@ -1895,6 +1937,29 @@
return NULL;
}
+struct fuse *fuse_new(int fd, const char *opts,
+ const struct fuse_operations *op, size_t op_size)
+{
+ return fuse_new_common(fd, opts, op, op_size, 0);
+}
+
+struct fuse *_fuse_new_compat2(int fd, const char *opts,
+ const struct _fuse_operations_compat2 *op)
+{
+ return fuse_new_common(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)
+{
+ char *opts = NULL;
+ if (flags & _FUSE_DEBUG_COMPAT1)
+ opts = "debug";
+ return fuse_new_common(fd, opts, (struct fuse_operations *) op,
+ sizeof(struct _fuse_operations_compat1), 11);
+}
+
void fuse_destroy(struct fuse *f)
{
size_t i;
@@ -1923,3 +1988,5 @@
pthread_mutex_destroy(&f->lock);
free(f);
}
+
+__asm__(".symver _fuse_new_compat2,fuse_new@");
diff --git a/lib/fuse_i.h b/lib/fuse_i.h
index b9ea903..f88dda1 100644
--- a/lib/fuse_i.h
+++ b/lib/fuse_i.h
@@ -7,6 +7,7 @@
*/
#include "fuse.h"
+#include "fuse_compat.h"
#include <stdio.h>
#include <pthread.h>
@@ -40,10 +41,50 @@
int is_hidden;
};
+struct fuse_operations_i {
+ int (*getattr) (const char *, struct stat *);
+ int (*readlink) (const char *, char *, size_t);
+ int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_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 *);
+ union {
+ int (*curr) (const char *, struct fuse_file_info *);
+ int (*compat2) (const char *, int);
+ } open;
+ 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 *);
+ union {
+ int (*curr) (const char *, struct statfs *);
+ int (*compat1) (struct _fuse_statfs_compat1 *);
+ } statfs;
+ int (*flush) (const char *, struct fuse_file_info *);
+ union {
+ int (*curr) (const char *, struct fuse_file_info *);
+ int (*compat2) (const char *, int);
+ } release;
+ 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 *);
+};
+
struct fuse {
int flags;
int fd;
- struct fuse_operations op;
+ struct fuse_operations_i op;
+ int compat;
struct node **name_table;
size_t name_table_size;
struct node **id_table;
@@ -69,3 +110,7 @@
char *buf;
size_t buflen;
};
+
+struct fuse *fuse_new_common(int fd, const char *opts,
+ const struct fuse_operations *op,
+ size_t op_size, int compat);
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
new file mode 100644
index 0000000..175cf32
--- /dev/null
+++ b/lib/fuse_versionscript
@@ -0,0 +1,29 @@
+FUSE_2.2 {
+ global:
+ __fuse_exited;
+ __fuse_loop_mt;
+ __fuse_main;
+ __fuse_process_cmd;
+ __fuse_read_cmd;
+ __fuse_set_getcontext_func;
+ __fuse_setup;
+ __fuse_teardown;
+ _fuse_setup_compat2;
+ _fuse_main_compat1;
+ _fuse_main_compat2;
+ _fuse_mount_compat1;
+ _fuse_new_compat1;
+ _fuse_new_compat2;
+ fuse_destroy;
+ fuse_exit;
+ fuse_get_context;
+ fuse_invalidate;
+ fuse_is_lib_option;
+ fuse_loop;
+ fuse_loop_mt;
+ fuse_mount;
+ fuse_new;
+ fuse_unmount;
+ local:
+ *;
+};
diff --git a/lib/helper.c b/lib/helper.c
index b4d437f..50d43c1 100644
--- a/lib/helper.c
+++ b/lib/helper.c
@@ -6,7 +6,7 @@
See the file COPYING.LIB.
*/
-#include "fuse.h"
+#include "fuse_i.h"
#include <stdio.h>
#include <stdlib.h>
@@ -249,16 +249,20 @@
}
-struct fuse *__fuse_setup(int argc, char *argv[],
- const struct fuse_operations *op,
- char **mountpoint, int *multithreaded, int *fd)
+static struct fuse *fuse_setup_common(int argc, char *argv[],
+ const struct fuse_operations *op,
+ size_t op_size,
+ char **mountpoint,
+ int *multithreaded,
+ int *fd,
+ int compat)
{
struct fuse *fuse;
int background;
char *kernel_opts;
char *lib_opts;
int res;
-
+
if (fuse_instance != NULL) {
fprintf(stderr, "fuse: __fuse_setup() called twice\n");
return NULL;
@@ -274,7 +278,7 @@
if (*fd == -1)
goto err_free;
- fuse = fuse_new(*fd, lib_opts, op);
+ fuse = fuse_new_common(*fd, lib_opts, op, op_size, compat);
if (fuse == NULL)
goto err_unmount;
@@ -306,6 +310,25 @@
return NULL;
}
+struct fuse *__fuse_setup(int argc, char *argv[],
+ const struct fuse_operations *op,
+ size_t op_size, char **mountpoint,
+ int *multithreaded, int *fd)
+{
+ return fuse_setup_common(argc, argv, op, op_size, mountpoint,
+ multithreaded, fd, 0);
+}
+
+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, 21);
+}
+
void __fuse_teardown(struct fuse *fuse, int fd, char *mountpoint)
{
if (fuse_instance != fuse)
@@ -319,8 +342,9 @@
free(mountpoint);
}
-
-int fuse_main(int argc, char *argv[], const struct fuse_operations *op)
+static int fuse_main_common(int argc, char *argv[],
+ const struct fuse_operations *op, size_t op_size,
+ int compat)
{
struct fuse *fuse;
char *mountpoint;
@@ -328,7 +352,8 @@
int res;
int fd;
- fuse = __fuse_setup(argc, argv, op, &mountpoint, &multithreaded, &fd);
+ fuse = fuse_setup_common(argc, argv, op, op_size, &mountpoint,
+ &multithreaded, &fd, compat);
if (fuse == NULL)
return 1;
@@ -344,3 +369,25 @@
return 0;
}
+int __fuse_main(int argc, char *argv[],const struct fuse_operations *op,
+ size_t op_size)
+{
+ return fuse_main_common(argc, argv, op, op_size, 0);
+}
+
+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), 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), 21);
+}
+
+__asm__(".symver _fuse_setup_compat2,__fuse_setup@");
+__asm__(".symver _fuse_main_compat2,fuse_main@");
diff --git a/lib/mount.c b/lib/mount.c
index a84dbee..fd29020 100644
--- a/lib/mount.c
+++ b/lib/mount.c
@@ -7,6 +7,7 @@
*/
#include "fuse.h"
+#include "fuse_compat.h"
#include <stdio.h>
#include <stdlib.h>
@@ -124,3 +125,10 @@
return rv;
}
+
+int _fuse_mount_compat1(const char *mountpoint, const char *args[])
+{
+ /* just ignore mount args for now */
+ (void) args;
+ return fuse_mount(mountpoint, NULL);
+}