From 4acb54ca337d73de694931528d1db3d04c6799a4 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Mon, 25 Nov 2024 00:00:38 +0100 Subject: [PATCH] Update squashfuse and add support for Zstd This update allows us to remove all the patches and makes the configuration step a lot easier, too. --- cmake/dependencies.cmake | 23 +- src/patches/patch-squashfuse.sh.in | 8 - src/patches/squashfuse.patch | 57 --- src/patches/squashfuse_dlopen.c | 12 - src/patches/squashfuse_dlopen.h | 262 ------------ src/patches/squashfuse_dlopen.patch | 640 ---------------------------- 6 files changed, 8 insertions(+), 994 deletions(-) delete mode 100755 src/patches/patch-squashfuse.sh.in delete mode 100644 src/patches/squashfuse.patch delete mode 100644 src/patches/squashfuse_dlopen.c delete mode 100644 src/patches/squashfuse_dlopen.h delete mode 100644 src/patches/squashfuse_dlopen.patch diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index dce62588..a3540706 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -36,6 +36,9 @@ set(LDFLAGS ${DEPENDENCIES_LDFLAGS}) if (NOT LIBAPPIMAGE_SHARED_ONLY) import_pkgconfig_target(TARGET_NAME liblzma PKGCONFIG_TARGET liblzma) + import_pkgconfig_target(TARGET_NAME libzstd PKGCONFIG_TARGET libzstd) + + # as distros don't provide suitable squashfuse and squashfs-tools, those dependencies are bundled in, can, and should # be used from this repository for AppImageKit # for distro packaging, it can be linked to an existing package just fine @@ -48,27 +51,16 @@ if (NOT LIBAPPIMAGE_SHARED_ONLY) import_pkgconfig_target(TARGET_NAME libfuse PKGCONFIG_TARGET fuse) # TODO: implement out-of-source builds for squashfuse, as for the other dependencies - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/src/patches/patch-squashfuse.sh.in - ${CMAKE_CURRENT_BINARY_DIR}/patch-squashfuse.sh - @ONLY - ) ExternalProject_Add( squashfuse-EXTERNAL GIT_REPOSITORY https://github.com/vasi/squashfuse/ - GIT_TAG 1f98030 + # release 0.5.2 + GIT_TAG 775b4cc72ab47641637897f11ce0da15d5c1f115 UPDATE_COMMAND "" # make sure CMake won't try to fetch updates unnecessarily and hence rebuild the dependency every time - PATCH_COMMAND bash -xe ${CMAKE_CURRENT_BINARY_DIR}/patch-squashfuse.sh - CONFIGURE_COMMAND ${LIBTOOLIZE} --force - COMMAND env ACLOCAL_FLAGS="-I /usr/share/aclocal" aclocal - COMMAND ${AUTOHEADER} - COMMAND ${AUTOMAKE} --force-missing --add-missing - COMMAND ${AUTORECONF} -fi || true - COMMAND ${SED} -i "/PKG_CHECK_MODULES.*/,/,:./d" configure # https://github.com/vasi/squashfuse/issues/12 + CONFIGURE_COMMAND /autogen.sh COMMAND ${SED} -i "s/typedef off_t sqfs_off_t/typedef int64_t sqfs_off_t/g" common.h # off_t's size might differ, see https://stackoverflow.com/a/9073762 - COMMAND CC=${CC} CXX=${CXX} CFLAGS=${CFLAGS} LDFLAGS=${LDFLAGS} /configure --disable-demo --disable-high-level --without-lzo --without-lz4 --prefix= --libdir=/lib --with-xz=${xz_PREFIX} ${EXTRA_CONFIGURE_FLAGS} - COMMAND ${SED} -i "s|XZ_LIBS = -llzma |XZ_LIBS = -Bstatic ${xz_LIBRARIES}/|g" Makefile + COMMAND CC=${CC} CXX=${CXX} CFLAGS=${CFLAGS} LDFLAGS=${LDFLAGS} /configure --disable-demo --disable-high-level --without-lzo --without-lz4 --prefix= --libdir=/lib ${EXTRA_CONFIGURE_FLAGS} BUILD_COMMAND ${MAKE} BUILD_IN_SOURCE ON INSTALL_COMMAND ${MAKE} install @@ -85,6 +77,7 @@ if (NOT LIBAPPIMAGE_SHARED_ONLY) target_link_libraries( libsquashfuse INTERFACE liblzma + INTERFACE libzstd INTERFACE libzlib ) else() diff --git a/src/patches/patch-squashfuse.sh.in b/src/patches/patch-squashfuse.sh.in deleted file mode 100755 index bd3452f2..00000000 --- a/src/patches/patch-squashfuse.sh.in +++ /dev/null @@ -1,8 +0,0 @@ -#! /bin/bash - -git checkout ll.c Makefile.am fuseprivate.c fuseprivate.h hl.c ll.h ll_inode.c nonstd-daemon.c - -patch -p1 < @PROJECT_SOURCE_DIR@/src/patches/squashfuse.patch -patch -p1 < @PROJECT_SOURCE_DIR@/src/patches/squashfuse_dlopen.patch - -cp -v @PROJECT_SOURCE_DIR@/src/patches/squashfuse_dlopen.c @PROJECT_SOURCE_DIR@/src/patches/squashfuse_dlopen.h . diff --git a/src/patches/squashfuse.patch b/src/patches/squashfuse.patch deleted file mode 100644 index db94d2f7..00000000 --- a/src/patches/squashfuse.patch +++ /dev/null @@ -1,57 +0,0 @@ -diff --git a/Makefile.am b/Makefile.am -index f0d7cde..70c4aa0 100644 ---- a/Makefile.am -+++ b/Makefile.am -@@ -14,6 +14,7 @@ bin_PROGRAMS = - noinst_PROGRAMS = - - noinst_LTLIBRARIES = libsquashfuse.la -+noinst_LTLIBRARIES += libsquashfuse_ll.la - - # Main library: libsquashfuse - libsquashfuse_la_SOURCES = swap.c cache.c table.c dir.c file.c fs.c \ -@@ -46,10 +47,9 @@ endif - - # Low-level squashfuse_ll, if supported - if SQ_WANT_LOWLEVEL --bin_PROGRAMS += squashfuse_ll --squashfuse_ll_SOURCES = ll.c ll_inode.c nonstd-daemon.c ll.h --squashfuse_ll_CPPFLAGS = $(FUSE_CPPFLAGS) --squashfuse_ll_LDADD = libsquashfuse.la libfuseprivate.la $(COMPRESSION_LIBS) \ -+libsquashfuse_ll_la_SOURCES = ll.c ll_inode.c nonstd-daemon.c ll.h -+libsquashfuse_ll_la_CPPFLAGS = $(FUSE_CPPFLAGS) -+libsquashfuse_ll_la_LIBADD = libsquashfuse.la libfuseprivate.la $(COMPRESSION_LIBS) \ - $(FUSE_LIBS) - - noinst_LTLIBRARIES += libfuseprivate.la -diff --git a/ll.c b/ll.c -index a2c7902..8fcb3f4 100644 ---- a/ll.c -+++ b/ll.c -@@ -390,7 +390,7 @@ static sqfs_ll *sqfs_ll_open(const char *path, size_t offset) { - return NULL; - } - --int main(int argc, char *argv[]) { -+int fusefs_main(int argc, char *argv[], void (*mounted) (void)) { - struct fuse_args args; - sqfs_opts opts; - -@@ -451,6 +451,8 @@ int main(int argc, char *argv[]) { - if (sqfs_ll_daemonize(fg) != -1) { - if (fuse_set_signal_handlers(se) != -1) { - fuse_session_add_chan(se, ch.ch); -+ if (mounted) -+ mounted (); - /* FIXME: multithreading */ - err = fuse_session_loop(se); - fuse_remove_signal_handlers(se); -@@ -466,6 +468,8 @@ int main(int argc, char *argv[]) { - } - } - fuse_opt_free_args(&args); -+ if (mounted) -+ rmdir (mountpoint); - free(ll); - free(mountpoint); - diff --git a/src/patches/squashfuse_dlopen.c b/src/patches/squashfuse_dlopen.c deleted file mode 100644 index fec4b761..00000000 --- a/src/patches/squashfuse_dlopen.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "squashfuse_dlopen.h" - -void *libhandle = NULL; -int have_libloaded = 0; - -const char *load_library_errmsg = - "AppImages require FUSE to run. \n" - "You might still be able to extract the contents of this AppImage \n" - "if you run it with the --appimage-extract option. \n" - "See https://github.com/AppImage/AppImageKit/wiki/FUSE \n" - "for more information\n"; - diff --git a/src/patches/squashfuse_dlopen.h b/src/patches/squashfuse_dlopen.h deleted file mode 100644 index 1b93a8e9..00000000 --- a/src/patches/squashfuse_dlopen.h +++ /dev/null @@ -1,262 +0,0 @@ -#ifndef SQFS_DLOPEN_H -#define SQFS_DLOPEN_H - -//#define ENABLE_DLOPEN - -#ifdef ENABLE_DLOPEN - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -/*** dlopen() stuff ***/ - -#define LIBNAME "libfuse.so.2" - -extern void *libhandle; -extern int have_libloaded; -extern const char *load_library_errmsg; - -#define LOAD_LIBRARY \ -if (have_libloaded != 1) { \ - if (!(libhandle = dlopen(LIBNAME, RTLD_LAZY))) { \ - fprintf(stderr, "dlopen(): error loading " LIBNAME "\n\n%s", load_library_errmsg ); \ - exit(1); \ - } else { \ - have_libloaded = 1; \ - } \ -} - -#define STRINGIFY(x) #x - -#define LOAD_SYMBOL(type,x,param) \ -type (*dl_##x) param; \ -*(void **) (&dl_##x) = dlsym(libhandle, STRINGIFY(x)); \ -if (dlerror()) { \ - fprintf(stderr, "dlsym(): error loading symbol from " LIBNAME "\n\n%s", load_library_errmsg ); \ - CLOSE_LIBRARY; \ - exit(1); \ -} - -#define DL(x) dl_##x -#define CLOSE_LIBRARY dlclose(libhandle); - - -/*** libfuse stuff ***/ - -#define FUSE_ROOT_ID 1 -#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 } -#define FUSE_OPT_KEY(templ, key) { templ, -1U, key } -#define FUSE_OPT_KEY_OPT -1 -#define FUSE_OPT_KEY_NONOPT -2 -#define FUSE_OPT_END { NULL, 0, 0 } - -enum fuse_buf_flags { - FUSE_BUF_IS_FD = (1 << 1), - FUSE_BUF_FD_SEEK = (1 << 2), - FUSE_BUF_FD_RETRY = (1 << 3), -}; - -typedef unsigned long fuse_ino_t; -typedef struct fuse_req *fuse_req_t; - -struct fuse_chan; -struct fuse_pollhandle; - -struct fuse_args { - int argc; - char **argv; - int allocated; -}; - -typedef int (*fuse_fill_dir_t) (void *buf, const char *name, const struct stat *stbuf, off_t off); -typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key, struct fuse_args *outargs); -typedef struct fuse_dirhandle *fuse_dirh_t; -typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type, ino_t ino); - -struct fuse_file_info { - int flags; - unsigned long fh_old; - int writepage; - unsigned int direct_io : 1; - unsigned int keep_cache : 1; - unsigned int flush : 1; - unsigned int nonseekable : 1; - unsigned int flock_release : 1; - unsigned int padding : 27; - uint64_t fh; - uint64_t lock_owner; -}; - -struct fuse_entry_param { - fuse_ino_t ino; - unsigned long generation; - struct stat attr; - double attr_timeout; - double entry_timeout; -}; - -struct fuse_opt { - const char *templ; - unsigned long offset; - int value; -}; - -struct fuse_forget_data { - uint64_t ino; - uint64_t nlookup; -}; - -struct fuse_conn_info { - unsigned proto_major; - unsigned proto_minor; - unsigned async_read; - unsigned max_write; - unsigned max_readahead; - unsigned capable; - unsigned want; - unsigned max_background; - unsigned congestion_threshold; - unsigned reserved[23]; -}; - -struct fuse_buf { - size_t size; - enum fuse_buf_flags flags; - void *mem; - int fd; - off_t pos; -}; - -struct fuse_bufvec { - size_t count; - size_t idx; - size_t off; - struct fuse_buf buf[1]; -}; - -struct fuse_context { - struct fuse *fuse; - uid_t uid; - gid_t gid; - pid_t pid; - void *private_data; - mode_t umask; -}; - -struct fuse_operations { - 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 *); - 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 *, fuse_fill_dir_t, 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) (struct fuse_conn_info *conn); - 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 *); - int (*lock) (const char *, struct fuse_file_info *, int cmd, struct flock *); - int (*utimens) (const char *, const struct timespec tv[2]); - int (*bmap) (const char *, size_t blocksize, uint64_t *idx); - unsigned int flag_nullpath_ok:1; - unsigned int flag_nopath:1; - unsigned int flag_utime_omit_ok:1; - unsigned int flag_reserved:29; - int (*ioctl) (const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void *data); - int (*poll) (const char *, struct fuse_file_info *, struct fuse_pollhandle *ph, unsigned *reventsp); - int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *); - int (*read_buf) (const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *); - int (*flock) (const char *, struct fuse_file_info *, int op); - int (*fallocate) (const char *, int, off_t, off_t, struct fuse_file_info *); -}; - -struct fuse_lowlevel_ops { - void (*init) (void *userdata, struct fuse_conn_info *conn); - 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, fuse_ino_t ino); - 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); - void (*getlk) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock); - void (*setlk) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock, int sleep); - void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize, uint64_t idx); - void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg, struct fuse_file_info *fi, unsigned flags, const void *in_buf, size_t in_bufsz, size_t out_bufsz); - void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct fuse_pollhandle *ph); - void (*write_buf) (fuse_req_t req, fuse_ino_t ino, struct fuse_bufvec *bufv, off_t off, struct fuse_file_info *fi); - void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino, off_t offset, struct fuse_bufvec *bufv); - void (*forget_multi) (fuse_req_t req, size_t count, struct fuse_forget_data *forgets); - void (*flock) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, int op); - void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode, off_t offset, off_t length, struct fuse_file_info *fi); -}; - -#else /* !ENABLE_DLOPEN */ - -#define LOAD_LIBRARY -#define LOAD_SYMBOL(x) -#define DL(x) -#define CLOSE_LIBRARY - -#endif /* !ENABLE_DLOPEN */ - -#endif /* SQFS_DLOPEN_H */ - diff --git a/src/patches/squashfuse_dlopen.patch b/src/patches/squashfuse_dlopen.patch deleted file mode 100644 index 59e1e6e6..00000000 --- a/src/patches/squashfuse_dlopen.patch +++ /dev/null @@ -1,640 +0,0 @@ ---- a/Makefile.am -+++ b/Makefile.am -@@ -1,6 +1,7 @@ - COMPRESSION_LIBS = $(ZLIB_LIBS) $(XZ_LIBS) $(LZO_LIBS) $(LZ4_LIBS) - - ACLOCAL_AMFLAGS = -I m4 --install -+AM_CFLAGS = -fno-strict-aliasing -DENABLE_DLOPEN - - # Suppress AppleDouble - if MAKE_EXPORT -@@ -19,13 +20,13 @@ - # Main library: libsquashfuse - libsquashfuse_la_SOURCES = swap.c cache.c table.c dir.c file.c fs.c \ - decompress.c xattr.c hash.c stack.c traverse.c util.c \ -- nonstd-pread.c nonstd-stat.c \ -+ nonstd-pread.c nonstd-stat.c squashfuse_dlopen.c \ - squashfs_fs.h common.h nonstd-internal.h nonstd.h swap.h cache.h table.h \ - dir.h file.h decompress.h xattr.h squashfuse.h hash.h stack.h traverse.h \ -- util.h fs.h -+ util.h fs.h squashfuse_dlopen.h - libsquashfuse_la_CPPFLAGS = $(ZLIB_CPPFLAGS) $(XZ_CPPFLAGS) $(LZO_CPPFLAGS) \ - $(LZ4_CPPFLAGS) --libsquashfuse_la_LIBADD = -+libsquashfuse_la_LIBADD = -ldl - - # Helper for FUSE clients: libfuseprivate - libfuseprivate_la_SOURCES = fuseprivate.c nonstd-makedev.c nonstd-enoattr.c \ ---- a/fuseprivate.c -+++ b/fuseprivate.c -@@ -94,15 +94,17 @@ - } - - void sqfs_usage(char *progname, bool fuse_usage) { -+ LOAD_SYMBOL(int,fuse_opt_add_arg,(struct fuse_args *args, const char *arg)); -+ LOAD_SYMBOL(int,fuse_parse_cmdline,(struct fuse_args *args, char **mountpoint, int *multithreaded, int *foreground)); - fprintf(stderr, "%s (c) 2012 Dave Vasilevsky\n\n", PACKAGE_STRING); - fprintf(stderr, "Usage: %s [options] ARCHIVE MOUNTPOINT\n", - progname ? progname : PACKAGE_NAME); - if (fuse_usage) { - struct fuse_args args = FUSE_ARGS_INIT(0, NULL); -- fuse_opt_add_arg(&args, ""); /* progname */ -- fuse_opt_add_arg(&args, "-ho"); -+ DL(fuse_opt_add_arg)(&args, ""); /* progname */ -+ DL(fuse_opt_add_arg)(&args, "-ho"); - fprintf(stderr, "\n"); -- fuse_parse_cmdline(&args, NULL, NULL, NULL); -+ DL(fuse_parse_cmdline)(&args, NULL, NULL, NULL); - } - exit(-2); - } ---- a/fuseprivate.h -+++ b/fuseprivate.h -@@ -27,7 +27,10 @@ - - #include "squashfuse.h" - --#include -+#include "squashfuse_dlopen.h" -+#ifndef ENABLE_DLOPEN -+# include -+#endif - - #include - ---- a/hl.c -+++ b/hl.c -@@ -33,6 +33,7 @@ - #include - #include - -+int have_libloaded = 0; - - typedef struct sqfs_hl sqfs_hl; - struct sqfs_hl { -@@ -42,9 +43,10 @@ - - static sqfs_err sqfs_hl_lookup(sqfs **fs, sqfs_inode *inode, - const char *path) { -+ LOAD_SYMBOL(struct fuse_context *,fuse_get_context,(void)); - bool found; - -- sqfs_hl *hl = fuse_get_context()->private_data; -+ sqfs_hl *hl = DL(fuse_get_context)()->private_data; - *fs = &hl->fs; - if (inode) - *inode = hl->root; /* copy */ -@@ -67,7 +69,8 @@ - } - - static void *sqfs_hl_op_init(struct fuse_conn_info *conn) { -- return fuse_get_context()->private_data; -+ LOAD_SYMBOL(struct fuse_context *,fuse_get_context,(void)); -+ return DL(fuse_get_context)()->private_data; - } - - static int sqfs_hl_op_getattr(const char *path, struct stat *st) { -@@ -264,7 +267,16 @@ - return NULL; - } - -+#ifdef ENABLE_DLOPEN -+#define fuse_main(argc, argv, op, user_data) \ -+ DL(fuse_main_real)(argc, argv, op, sizeof(*(op)), user_data) -+#endif -+ - int main(int argc, char *argv[]) { -+ LOAD_SYMBOL(int,fuse_opt_parse,(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)); -+ LOAD_SYMBOL(int,fuse_opt_add_arg,(struct fuse_args *args, const char *arg)); -+ LOAD_SYMBOL(int,fuse_main_real,(int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *user_data)); /* fuse_main */ -+ LOAD_SYMBOL(void,fuse_opt_free_args,(struct fuse_args *args)); - struct fuse_args args; - sqfs_opts opts; - sqfs_hl *hl; -@@ -299,7 +311,7 @@ - opts.image = NULL; - opts.mountpoint = 0; - opts.offset = 0; -- if (fuse_opt_parse(&args, &opts, fuse_opts, sqfs_opt_proc) == -1) -+ if (DL(fuse_opt_parse)(&args, &opts, fuse_opts, sqfs_opt_proc) == -1) - sqfs_usage(argv[0], true); - if (!opts.image) - sqfs_usage(argv[0], true); -@@ -308,8 +320,9 @@ - if (!hl) - return -1; - -- fuse_opt_add_arg(&args, "-s"); /* single threaded */ -+ DL(fuse_opt_add_arg)(&args, "-s"); /* single threaded */ - ret = fuse_main(args.argc, args.argv, &sqfs_hl_ops, hl); -- fuse_opt_free_args(&args); -+ DL(fuse_opt_free_args)(&args); -+ CLOSE_LIBRARY; - return ret; - } ---- a/ll.h -+++ b/ll.h -@@ -27,7 +27,10 @@ - - #include "squashfuse.h" - --#include -+#include "squashfuse_dlopen.h" -+#ifndef ENABLE_DLOPEN -+# include -+#endif - - typedef struct sqfs_ll sqfs_ll; - struct sqfs_ll { ---- a/ll_inode.c -+++ b/ll_inode.c -@@ -348,12 +348,14 @@ - - - sqfs_err sqfs_ll_iget(fuse_req_t req, sqfs_ll_i *lli, fuse_ino_t i) { -+ LOAD_SYMBOL(void *,fuse_req_userdata,(fuse_req_t req)); -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); - sqfs_err err = SQFS_OK; -- lli->ll = fuse_req_userdata(req); -+ lli->ll = DL(fuse_req_userdata)(req); - if (i != SQFS_FUSE_INODE_NONE) { - err = sqfs_ll_inode(lli->ll, &lli->inode, i); - if (err) -- fuse_reply_err(req, ENOENT); -+ DL(fuse_reply_err)(req, ENOENT); - } - return err; - } ---- a/nonstd-daemon.c -+++ b/nonstd-daemon.c -@@ -28,11 +28,16 @@ - #include "nonstd-internal.h" - - #include --#include -+ -+#include "squashfuse_dlopen.h" -+#ifndef ENABLE_DLOPEN -+# include -+#endif - - int sqfs_ll_daemonize(int fg) { - #if HAVE_DECL_FUSE_DAEMONIZE -- return fuse_daemonize(fg); -+ LOAD_SYMBOL(int,fuse_daemonize,(int foreground)); -+ return DL(fuse_daemonize)(fg); - #else - return daemon(0,0); - #endif ---- a/ll.c -+++ b/ll.c -@@ -38,37 +38,41 @@ - - static void sqfs_ll_op_getattr(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_attr,(fuse_req_t req, const struct stat *attr, double attr_timeout)); - sqfs_ll_i lli; - struct stat st; - if (sqfs_ll_iget(req, &lli, ino)) - return; - - if (sqfs_stat(&lli.ll->fs, &lli.inode, &st)) { -- fuse_reply_err(req, ENOENT); -+ DL(fuse_reply_err)(req, ENOENT); - } else { - st.st_ino = ino; -- fuse_reply_attr(req, &st, SQFS_TIMEOUT); -+ DL(fuse_reply_attr)(req, &st, SQFS_TIMEOUT); - } - } - - static void sqfs_ll_op_opendir(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_open,(fuse_req_t req, const struct fuse_file_info *fi)); - sqfs_ll_i *lli; - - fi->fh = (intptr_t)NULL; - - lli = malloc(sizeof(*lli)); - if (!lli) { -- fuse_reply_err(req, ENOMEM); -+ DL(fuse_reply_err)(req, ENOMEM); - return; - } - - if (sqfs_ll_iget(req, lli, ino) == SQFS_OK) { - if (!S_ISDIR(lli->inode.base.mode)) { -- fuse_reply_err(req, ENOTDIR); -+ DL(fuse_reply_err)(req, ENOTDIR); - } else { - fi->fh = (intptr_t)lli; -- fuse_reply_open(req, fi); -+ DL(fuse_reply_open)(req, fi); - return; - } - } -@@ -77,28 +81,35 @@ - - static void sqfs_ll_op_create(fuse_req_t req, fuse_ino_t parent, const char *name, - mode_t mode, struct fuse_file_info *fi) { -- fuse_reply_err(req, EROFS); -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ DL(fuse_reply_err)(req, EROFS); - } - - static void sqfs_ll_op_releasedir(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) { - free((sqfs_ll_i*)(intptr_t)fi->fh); -- fuse_reply_err(req, 0); /* yes, this is necessary */ -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ DL(fuse_reply_err)(req, 0); /* yes, this is necessary */ - } - - static size_t sqfs_ll_add_direntry(fuse_req_t req, char *buf, size_t bufsize, - const char *name, const struct stat *st, off_t off) { - #if HAVE_DECL_FUSE_ADD_DIRENTRY -- return fuse_add_direntry(req, buf, bufsize, name, st, off); -+ LOAD_SYMBOL(size_t,fuse_add_direntry,(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)); -+ return DL(fuse_add_direntry)(req, buf, bufsize, name, st, off); - #else -- size_t esize = fuse_dirent_size(strlen(name)); -+ LOAD_SYMBOL(size_t,fuse_dirent_size(size_t namelen)); -+ LOAD_SYMBOL(char *,fuse_add_dirent,(char *buf, const char *name, const struct stat *stbuf, off_t off)); -+ size_t esize = DL(fuse_dirent_size)(strlen(name)); - if (bufsize >= esize) -- fuse_add_dirent(buf, name, st, off); -+ DL(fuse_add_dirent)(buf, name, st, off); - return esize; - #endif - } - static void sqfs_ll_op_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, - off_t off, struct fuse_file_info *fi) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_buf,(fuse_req_t req, const char *buf, size_t size)); - sqfs_err sqerr; - sqfs_dir dir; - sqfs_name namebuf; -@@ -135,14 +146,16 @@ - } - - if (err) -- fuse_reply_err(req, err); -+ DL(fuse_reply_err)(req, err); - else -- fuse_reply_buf(req, buf, bufpos - buf); -+ DL(fuse_reply_buf)(req, buf, bufpos - buf); - free(buf); - } - - static void sqfs_ll_op_lookup(fuse_req_t req, fuse_ino_t parent, - const char *name) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_entry,(fuse_req_t req, const struct fuse_entry_param *e)); - sqfs_ll_i lli; - sqfs_err sqerr; - sqfs_name namebuf; -@@ -154,7 +167,7 @@ - return; - - if (!S_ISDIR(lli.inode.base.mode)) { -- fuse_reply_err(req, ENOTDIR); -+ DL(fuse_reply_err)(req, ENOTDIR); - return; - } - -@@ -162,55 +175,58 @@ - sqerr = sqfs_dir_lookup(&lli.ll->fs, &lli.inode, name, strlen(name), &entry, - &found); - if (sqerr) { -- fuse_reply_err(req, EIO); -+ DL(fuse_reply_err)(req, EIO); - return; - } - if (!found) { -- fuse_reply_err(req, ENOENT); -+ DL(fuse_reply_err)(req, ENOENT); - return; - } - - if (sqfs_inode_get(&lli.ll->fs, &inode, sqfs_dentry_inode(&entry))) { -- fuse_reply_err(req, ENOENT); -+ DL(fuse_reply_err)(req, ENOENT); - } else { - struct fuse_entry_param fentry; - memset(&fentry, 0, sizeof(fentry)); - if (sqfs_stat(&lli.ll->fs, &inode, &fentry.attr)) { -- fuse_reply_err(req, EIO); -+ DL(fuse_reply_err)(req, EIO); - } else { - fentry.attr_timeout = fentry.entry_timeout = SQFS_TIMEOUT; - fentry.ino = lli.ll->ino_register(lli.ll, &entry); - fentry.attr.st_ino = fentry.ino; -- fuse_reply_entry(req, &fentry); -+ DL(fuse_reply_entry)(req, &fentry); - } - } - } - - static void sqfs_ll_op_open(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_open,(fuse_req_t req, const struct fuse_file_info *fi)); -+ LOAD_SYMBOL(void *,fuse_req_userdata,(fuse_req_t req)); - sqfs_inode *inode; - sqfs_ll *ll; - - if (fi->flags & (O_WRONLY | O_RDWR)) { -- fuse_reply_err(req, EROFS); -+ DL(fuse_reply_err)(req, EROFS); - return; - } - - inode = malloc(sizeof(sqfs_inode)); - if (!inode) { -- fuse_reply_err(req, ENOMEM); -+ DL(fuse_reply_err)(req, ENOMEM); - return; - } - -- ll = fuse_req_userdata(req); -+ ll = DL(fuse_req_userdata)(req); - if (sqfs_ll_inode(ll, inode, ino)) { -- fuse_reply_err(req, ENOENT); -+ DL(fuse_reply_err)(req, ENOENT); - } else if (!S_ISREG(inode->base.mode)) { -- fuse_reply_err(req, EISDIR); -+ DL(fuse_reply_err)(req, EISDIR); - } else { - fi->fh = (intptr_t)inode; - fi->keep_cache = 1; -- fuse_reply_open(req, fi); -+ DL(fuse_reply_open)(req, fi); - return; - } - free(inode); -@@ -218,37 +234,43 @@ - - static void sqfs_ll_op_release(fuse_req_t req, fuse_ino_t ino, - struct fuse_file_info *fi) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); - free((sqfs_inode*)(intptr_t)fi->fh); - fi->fh = 0; -- fuse_reply_err(req, 0); -+ DL(fuse_reply_err)(req, 0); - } - - static void sqfs_ll_op_read(fuse_req_t req, fuse_ino_t ino, - size_t size, off_t off, struct fuse_file_info *fi) { -- sqfs_ll *ll = fuse_req_userdata(req); -+ LOAD_SYMBOL(void *,fuse_req_userdata,(fuse_req_t req)); -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_buf,(fuse_req_t req, const char *buf, size_t size)); -+ sqfs_ll *ll = DL(fuse_req_userdata)(req); - sqfs_inode *inode = (sqfs_inode*)(intptr_t)fi->fh; - sqfs_err err = SQFS_OK; - - off_t osize; - char *buf = malloc(size); - if (!buf) { -- fuse_reply_err(req, ENOMEM); -+ DL(fuse_reply_err)(req, ENOMEM); - return; - } - - osize = size; - err = sqfs_read_range(&ll->fs, inode, off, &osize, buf); - if (err) { -- fuse_reply_err(req, EIO); -+ DL(fuse_reply_err)(req, EIO); - } else if (osize == 0) { /* EOF */ -- fuse_reply_buf(req, NULL, 0); -+ DL(fuse_reply_buf)(req, NULL, 0); - } else { -- fuse_reply_buf(req, buf, osize); -+ DL(fuse_reply_buf)(req, buf, osize); - } - free(buf); - } - - static void sqfs_ll_op_readlink(fuse_req_t req, fuse_ino_t ino) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_readlink,(fuse_req_t req, const char *link)); - char *dst; - size_t size; - sqfs_ll_i lli; -@@ -256,21 +278,24 @@ - return; - - if (!S_ISLNK(lli.inode.base.mode)) { -- fuse_reply_err(req, EINVAL); -+ DL(fuse_reply_err)(req, EINVAL); - } else if (sqfs_readlink(&lli.ll->fs, &lli.inode, NULL, &size)) { -- fuse_reply_err(req, EIO); -+ DL(fuse_reply_err)(req, EIO); - } else if (!(dst = malloc(size + 1))) { -- fuse_reply_err(req, ENOMEM); -+ DL(fuse_reply_err)(req, ENOMEM); - } else if (sqfs_readlink(&lli.ll->fs, &lli.inode, dst, &size)) { -- fuse_reply_err(req, EIO); -+ DL(fuse_reply_err)(req, EIO); - free(dst); - } else { -- fuse_reply_readlink(req, dst); -+ DL(fuse_reply_readlink)(req, dst); - free(dst); - } - } - - static void sqfs_ll_op_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_xattr,(fuse_req_t req, size_t count)); -+ LOAD_SYMBOL(int,fuse_reply_buf,(fuse_req_t req, const char *buf, size_t size)); - sqfs_ll_i lli; - char *buf; - int ferr; -@@ -280,17 +305,17 @@ - - buf = NULL; - if (size && !(buf = malloc(size))) { -- fuse_reply_err(req, ENOMEM); -+ DL(fuse_reply_err)(req, ENOMEM); - return; - } - - ferr = sqfs_listxattr(&lli.ll->fs, &lli.inode, buf, &size); - if (ferr) { -- fuse_reply_err(req, ferr); -+ DL(fuse_reply_err)(req, ferr); - } else if (buf) { -- fuse_reply_buf(req, buf, size); -+ DL(fuse_reply_buf)(req, buf, size); - } else { -- fuse_reply_xattr(req, size); -+ DL(fuse_reply_xattr)(req, size); - } - free(buf); - } -@@ -301,13 +326,16 @@ - , uint32_t position - #endif - ) { -+ LOAD_SYMBOL(int,fuse_reply_err,(fuse_req_t req, int err)); -+ LOAD_SYMBOL(int,fuse_reply_xattr,(fuse_req_t req, size_t count)); -+ LOAD_SYMBOL(int,fuse_reply_buf,(fuse_req_t req, const char *buf, size_t size)); - sqfs_ll_i lli; - char *buf = NULL; - size_t real = size; - - #ifdef FUSE_XATTR_POSITION - if (position != 0) { /* We don't support resource forks */ -- fuse_reply_err(req, EINVAL); -+ DL(fuse_reply_err)(req, EINVAL); - return; - } - #endif -@@ -316,26 +344,27 @@ - return; - - if (!(buf = malloc(size))) -- fuse_reply_err(req, ENOMEM); -+ DL(fuse_reply_err)(req, ENOMEM); - else if (sqfs_xattr_lookup(&lli.ll->fs, &lli.inode, name, buf, &real)) -- fuse_reply_err(req, EIO); -+ DL(fuse_reply_err)(req, EIO); - else if (real == 0) -- fuse_reply_err(req, sqfs_enoattr()); -+ DL(fuse_reply_err)(req, sqfs_enoattr()); - else if (size == 0) -- fuse_reply_xattr(req, real); -+ DL(fuse_reply_xattr)(req, real); - else if (size < real) -- fuse_reply_err(req, ERANGE); -+ DL(fuse_reply_err)(req, ERANGE); - else -- fuse_reply_buf(req, buf, real); -+ DL(fuse_reply_buf)(req, buf, real); - free(buf); - } - - static void sqfs_ll_op_forget(fuse_req_t req, fuse_ino_t ino, - unsigned long nlookup) { -+ LOAD_SYMBOL(void,fuse_reply_none,(fuse_req_t req)); - sqfs_ll_i lli; - sqfs_ll_iget(req, &lli, SQFS_FUSE_INODE_NONE); - lli.ll->ino_forget(lli.ll, ino, nlookup); -- fuse_reply_none(req); -+ DL(fuse_reply_none)(req); - } - - -@@ -348,23 +377,27 @@ - - static sqfs_err sqfs_ll_mount(sqfs_ll_chan *ch, const char *mountpoint, - struct fuse_args *args) { -+ LOAD_SYMBOL(struct fuse_chan *,fuse_mount,(const char *mountpoint, struct fuse_args *args)); - #ifdef HAVE_NEW_FUSE_UNMOUNT -- ch->ch = fuse_mount(mountpoint, args); -+ ch->ch = DL(fuse_mount)(mountpoint, args); - #else -- ch->fd = fuse_mount(mountpoint, args); -+ LOAD_SYMBOL(struct fuse_chan *,fuse_kern_chan_new,(int fd)); -+ ch->fd = DL(fuse_mount)(mountpoint, args); - if (ch->fd == -1) - return SQFS_ERR; -- ch->ch = fuse_kern_chan_new(ch->fd); -+ ch->ch = DL(fuse_kern_chan_new)(ch->fd); - #endif - return ch->ch ? SQFS_OK : SQFS_ERR; - } - - static void sqfs_ll_unmount(sqfs_ll_chan *ch, const char *mountpoint) { - #ifdef HAVE_NEW_FUSE_UNMOUNT -- fuse_unmount(mountpoint, ch->ch); -+ LOAD_SYMBOL(void,fuse_unmount,(const char *mountpoint, struct fuse_chan *ch)); -+ DL(fuse_unmount)(mountpoint, ch->ch); - #else -+ LOAD_SYMBOL(void,fuse_unmount,(const char *mountpoint)); - close(ch->fd); -- fuse_unmount(mountpoint); -+ DL(fuse_unmount)(mountpoint); - #endif - } - -@@ -391,6 +424,19 @@ - } - - int fusefs_main(int argc, char *argv[], void (*mounted) (void)) { -+ LOAD_SYMBOL(int,fuse_opt_parse,(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)); -+ LOAD_SYMBOL(int,fuse_parse_cmdline,(struct fuse_args *args, char **mountpoint, int *multithreaded, int *foreground)); -+ LOAD_SYMBOL(struct fuse_session *,fuse_lowlevel_new,(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)); -+ LOAD_SYMBOL(int,fuse_set_signal_handlers,(struct fuse_session *se)); -+ LOAD_SYMBOL(void,fuse_session_add_chan,(struct fuse_session *se, struct fuse_chan *ch)); -+ LOAD_SYMBOL(int,fuse_session_loop,(struct fuse_session *se)); -+ LOAD_SYMBOL(void,fuse_remove_signal_handlers,(struct fuse_session *se)); -+#if HAVE_DECL_FUSE_SESSION_REMOVE_CHAN -+ LOAD_SYMBOL(void,fuse_session_remove_chan,(struct fuse_chan *ch)); -+#endif -+ LOAD_SYMBOL(void,fuse_session_destroy,(struct fuse_session *se)); -+ LOAD_SYMBOL(void,fuse_opt_free_args,(struct fuse_args *args)); -+ - struct fuse_args args; - sqfs_opts opts; - -@@ -429,10 +475,10 @@ - opts.image = NULL; - opts.mountpoint = 0; - opts.offset = 0; -- if (fuse_opt_parse(&args, &opts, fuse_opts, sqfs_opt_proc) == -1) -+ if (DL(fuse_opt_parse)(&args, &opts, fuse_opts, sqfs_opt_proc) == -1) - sqfs_usage(argv[0], true); - -- if (fuse_parse_cmdline(&args, &mountpoint, &mt, &fg) == -1) -+ if (DL(fuse_parse_cmdline)(&args, &mountpoint, &mt, &fg) == -1) - sqfs_usage(argv[0], true); - if (mountpoint == NULL) - sqfs_usage(argv[0], true); -@@ -445,33 +491,34 @@ - sqfs_ll_chan ch; - err = -1; - if (sqfs_ll_mount(&ch, mountpoint, &args) == SQFS_OK) { -- struct fuse_session *se = fuse_lowlevel_new(&args, -+ struct fuse_session *se = DL(fuse_lowlevel_new)(&args, - &sqfs_ll_ops, sizeof(sqfs_ll_ops), ll); - if (se != NULL) { - if (sqfs_ll_daemonize(fg) != -1) { -- if (fuse_set_signal_handlers(se) != -1) { -- fuse_session_add_chan(se, ch.ch); -+ if (DL(fuse_set_signal_handlers)(se) != -1) { -+ DL(fuse_session_add_chan)(se, ch.ch); - if (mounted) - mounted (); - /* FIXME: multithreading */ -- err = fuse_session_loop(se); -- fuse_remove_signal_handlers(se); -+ err = DL(fuse_session_loop)(se); -+ DL(fuse_remove_signal_handlers)(se); - #if HAVE_DECL_FUSE_SESSION_REMOVE_CHAN -- fuse_session_remove_chan(ch.ch); -+ DL(fuse_session_remove_chan)(ch.ch); - #endif - } - } -- fuse_session_destroy(se); -+ DL(fuse_session_destroy)(se); - } - sqfs_ll_destroy(ll); - sqfs_ll_unmount(&ch, mountpoint); - } - } -- fuse_opt_free_args(&args); -+ DL(fuse_opt_free_args)(&args); - if (mounted) - rmdir (mountpoint); - free(ll); - free(mountpoint); -+ CLOSE_LIBRARY; - - return -err; - }