diff --git a/Makefile b/Makefile index a3b4c678..daf3d53a 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ ifeq ($(PANDOC),) $(warning "pandoc does not appear available: manpage won't be buildable") endif -XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?) +USE_XATTR = 1 INTERNAL_FUSE = 1 EXTERNAL_FUSE_MIN_REQ = 2.9.7 @@ -73,6 +73,7 @@ CFLAGS = -g -Wall \ $(FUSE_CFLAGS) \ -DFUSE_USE_VERSION=29 \ -MMD \ + -DUSE_XATTR=$(USE_XATTR) \ -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK) PREFIX = /usr/local @@ -88,17 +89,12 @@ INSTALLBINDIR = $(DESTDIR)$(BINDIR) INSTALLSBINDIR = $(DESTDIR)$(SBINDIR) INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR) -ifeq ($(XATTR_AVAILABLE),0) -$(warning "xattr not available: disabling") -CFLAGS += -DWITHOUT_XATTR -endif - all: $(TARGET) help: @echo "usage: make" - @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)" - @echo "make INTERNAL_FUSE=0 - to build program with external (system) libfuse rather than the bundled one ('-o threads=' option will be unavailable)" + @echo "make USE_XATTR=0 - build program without xattrs functionality" + @echo "make INTERNAL_FUSE=0 - to build program with external (system) libfuse rather than the bundled one ('-o threads=' option will be unavailable)" $(TARGET): version obj/obj-stamp $(FUSE_TARGET) $(OBJ) $(CXX) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@ $(FUSE_LIBS) -ldl -pthread -lrt @@ -218,13 +214,13 @@ install-build-pkgs: ifeq ($(shell test -e /usr/bin/apt-get; echo $$?),0) apt-get -qy update apt-get -qy --no-install-suggests --no-install-recommends --force-yes \ - install build-essential git g++ debhelper libattr1-dev python automake libtool lsb-release + install build-essential git g++ debhelper python automake libtool lsb-release else ifeq ($(shell test -e /usr/bin/dnf; echo $$?),0) dnf -y update - dnf -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel + dnf -y install git rpm-build gcc-c++ make which python automake libtool gettext-devel else ifeq ($(shell test -e /usr/bin/yum; echo $$?),0) yum -y update - yum -y install git rpm-build libattr-devel gcc-c++ make which python automake libtool gettext-devel + yum -y install git rpm-build gcc-c++ make which python automake libtool gettext-devel endif unexport CFLAGS diff --git a/README.md b/README.md index 86ef1f9e..7bad3838 100644 --- a/README.md +++ b/README.md @@ -271,7 +271,7 @@ $ sudo apt-get -y update $ sudo apt-get -y install git make $ cd mergerfs $ make install-build-pkgs -$ # build-essential git g++ debhelper libattr1-dev python automake libtool lsb-release +$ # build-essential git g++ debhelper python automake libtool lsb-release $ make deb $ sudo dpkg -i ../mergerfs_version_arch.deb ``` @@ -283,14 +283,14 @@ $ su - # dnf -y install git make # cd mergerfs # make install-build-pkgs -# # rpm-build libattr-devel gcc-c++ which python automake libtool gettext-devel +# # rpm-build gcc-c++ which python automake libtool gettext-devel # make rpm # rpm -i rpmbuild/RPMS//mergerfs-..rpm ``` #### Generically -Have git, g++, make, python, libattr1, automake, libtool installed. +Have git, g++, make, python, automake, libtool installed. ``` $ cd mergerfs @@ -302,7 +302,7 @@ $ sudo make install **NOTE:** Configurable threading and thus `-o threads=num` option will be unavailable when built with system libfuse. -Have git, g++, make, python, libattr1, pkg-config installed. +Have git, g++, make, python, pkg-config installed. Also, install libfuse >= 2.9.7 (but not libfuse-3.x) and matching libfuse-dev (or libfuse-devel). ``` diff --git a/debian/control b/debian/control index c6576844..33c2af62 100644 --- a/debian/control +++ b/debian/control @@ -2,8 +2,7 @@ Source: mergerfs Section: utils Priority: optional Maintainer: Antonio SJ Musumeci -Build-Depends: debhelper (>= 8.0.0), - libattr1-dev +Build-Depends: debhelper (>= 8.0.0) Standards-Version: 3.9.4 Homepage: http://github.com/trapexit/mergerfs diff --git a/man/mergerfs.1 b/man/mergerfs.1 index 27a13511..181d44e2 100644 --- a/man/mergerfs.1 +++ b/man/mergerfs.1 @@ -708,7 +708,7 @@ $\ sudo\ apt\-get\ \-y\ update $\ sudo\ apt\-get\ \-y\ install\ git\ make $\ cd\ mergerfs $\ make\ install\-build\-pkgs -$\ #\ build\-essential\ git\ g++\ debhelper\ libattr1\-dev\ python\ automake\ libtool\ lsb\-release +$\ #\ build\-essential\ git\ g++\ debhelper\ python\ automake\ libtool\ lsb\-release $\ make\ deb $\ sudo\ dpkg\ \-i\ ../mergerfs_version_arch.deb \f[] @@ -722,14 +722,14 @@ $\ su\ \- #\ dnf\ \-y\ install\ git\ make #\ cd\ mergerfs #\ make\ install\-build\-pkgs -#\ #\ rpm\-build\ libattr\-devel\ gcc\-c++\ which\ python\ automake\ libtool\ gettext\-devel +#\ #\ rpm\-build\ gcc\-c++\ which\ python\ automake\ libtool\ gettext\-devel #\ make\ rpm #\ rpm\ \-i\ rpmbuild/RPMS//mergerfs\-..rpm \f[] .fi .SS Generically .PP -Have git, g++, make, python, libattr1, automake, libtool installed. +Have git, g++, make, python, automake, libtool installed. .IP .nf \f[C] @@ -743,7 +743,7 @@ $\ sudo\ make\ install \f[B]NOTE:\f[] Configurable threading and thus \f[C]\-o\ threads=num\f[] option will be unavailable when built with system libfuse. .PP -Have git, g++, make, python, libattr1, pkg\-config installed. +Have git, g++, make, python, pkg\-config installed. Also, install libfuse >= 2.9.7 (but not libfuse\-3.x) and matching libfuse\-dev (or libfuse\-devel). .IP diff --git a/mergerfs.spec b/mergerfs.spec index 55adfeca..58739784 100644 --- a/mergerfs.spec +++ b/mergerfs.spec @@ -10,7 +10,6 @@ URL: https://github.com/trapexit/mergerfs Source: mergerfs-%{version}.tar.gz BuildRequires: gcc-c++ -BuildRequires: libattr-devel # rpmbuild driven by the Makefile uses git to generate a version number BuildRequires: git diff --git a/src/fs_base_getxattr.hpp b/src/fs_base_getxattr.hpp index ebc67cdf..edecc1f9 100644 --- a/src/fs_base_getxattr.hpp +++ b/src/fs_base_getxattr.hpp @@ -18,25 +18,78 @@ #pragma once -#include - #include "errno.hpp" #include "xattr.hpp" +#include + +#include + namespace fs { static inline int - lgetxattr(const std::string &path, - const char *attrname, - void *value, - const size_t size) + lgetxattr(const char *path_, + const char *attrname_, + void *value_, + const size_t size_) + { +#ifdef USE_XATTR + return ::lgetxattr(path_,attrname_,value_,size_); +#else + return (errno=ENOTSUP,-1); +#endif + } + + static + inline + int + lgetxattr(const std::string &path_, + const char *attrname_, + void *value_, + const size_t size_) + { + return fs::lgetxattr(path_.c_str(),attrname_,value_,size_); + } + + static + inline + int + lgetxattr(const std::string &path_, + const std::string &attrname_, + void *value_, + const size_t size_) + { + return fs::lgetxattr(path_.c_str(), + attrname_.c_str(), + value_, + size_); + } + + static + inline + int + fgetxattr(const int fd_, + const char *attrname_, + void *value_, + const size_t size_) { -#ifndef WITHOUT_XATTR - return ::lgetxattr(path.c_str(),attrname,value,size); +#ifdef USE_XATTR + return ::fgetxattr(fd_,attrname_,value_,size_); #else return (errno=ENOTSUP,-1); #endif } + + static + inline + int + fgetxattr(const int fd_, + const std::string &attrname_, + void *value_, + const size_t size_) + { + return fs::fgetxattr(fd_,attrname_.c_str(),value_,size_); + } } diff --git a/src/fs_base_listxattr.hpp b/src/fs_base_listxattr.hpp index 196dc703..766e4857 100644 --- a/src/fs_base_listxattr.hpp +++ b/src/fs_base_listxattr.hpp @@ -18,22 +18,48 @@ #pragma once -#include - #include "errno.hpp" #include "xattr.hpp" +#include + +#include + namespace fs { static inline int - llistxattr(const std::string &path, - char *list, - const size_t size) + llistxattr(const char *path_, + char *list_, + const size_t size_) + { +#ifdef USE_XATTR + return ::llistxattr(path_,list_,size_); +#else + return (errno=ENOTSUP,-1); +#endif + } + + static + inline + int + llistxattr(const std::string &path_, + char *list_, + const size_t size_) + { + return fs::llistxattr(path_.c_str(),list_,size_); + } + + static + inline + int + flistxattr(const int fd_, + char *list_, + const size_t size_) { -#ifndef WITHOUT_XATTR - return ::llistxattr(path.c_str(),list,size); +#ifdef USE_XATTR + return ::flistxattr(fd_,list_,size_); #else return (errno=ENOTSUP,-1); #endif diff --git a/src/fs_base_removexattr.hpp b/src/fs_base_removexattr.hpp index 39254229..08357d23 100644 --- a/src/fs_base_removexattr.hpp +++ b/src/fs_base_removexattr.hpp @@ -31,7 +31,7 @@ namespace fs lremovexattr(const std::string &path, const char *attrname) { -#ifndef WITHOUT_XATTR +#ifdef USE_XATTR return ::lremovexattr(path.c_str(),attrname); #else return (errno=ENOTSUP,-1); diff --git a/src/fs_base_setxattr.hpp b/src/fs_base_setxattr.hpp index ebac9070..0a149bb2 100644 --- a/src/fs_base_setxattr.hpp +++ b/src/fs_base_setxattr.hpp @@ -34,10 +34,26 @@ namespace fs const size_t size, const int flags) { -#ifndef WITHOUT_XATTR +#ifdef USE_XATTR return ::lsetxattr(path.c_str(),name,value,size,flags); #else return (errno=ENOTSUP,-1); +#endif + } + + static + inline + int + fsetxattr(const int fd_, + const char *name_, + const void *value_, + const size_t size_, + const int flags_) + { +#ifdef USE_XATTR + return ::fsetxattr(fd_,name_,value_,size_,flags_); +#else + return (errno=ENOTSUP,-1); #endif } } diff --git a/src/fs_xattr.cpp b/src/fs_xattr.cpp index acd8fb05..12a7cc53 100644 --- a/src/fs_xattr.cpp +++ b/src/fs_xattr.cpp @@ -14,22 +14,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include -#include -#include -#include +#include "errno.hpp" +#include "fs_base_close.hpp" +#include "fs_base_getxattr.hpp" +#include "fs_base_listxattr.hpp" +#include "fs_base_open.hpp" +#include "fs_base_removexattr.hpp" +#include "fs_base_setxattr.hpp" +#include "str.hpp" #include #include #include #include -#include "errno.hpp" -#include "fs_base_open.hpp" -#include "fs_base_close.hpp" -#include "str.hpp" -#include "xattr.hpp" using std::string; using std::vector; @@ -44,57 +42,49 @@ namespace fs list(const int fd, vector &attrs) { -#ifndef WITHOUT_XATTR ssize_t rv; rv = -1; errno = ERANGE; while((rv == -1) && (errno == ERANGE)) { - rv = ::flistxattr(fd,NULL,0); + rv = fs::flistxattr(fd,NULL,0); if(rv <= 0) return rv; attrs.resize(rv); - rv = ::flistxattr(fd,&attrs[0],rv); + rv = fs::flistxattr(fd,&attrs[0],rv); } return rv; -#else - return (errno=ENOTSUP,-1); -#endif } int list(const string &path, vector &attrs) { -#ifndef WITHOUT_XATTR ssize_t rv; rv = -1; errno = ERANGE; while((rv == -1) && (errno == ERANGE)) { - rv = ::llistxattr(path.c_str(),NULL,0); + rv = fs::llistxattr(path,NULL,0); if(rv <= 0) return rv; attrs.resize(rv); - rv = ::llistxattr(path.c_str(),&attrs[0],rv); + rv = fs::llistxattr(path,&attrs[0],rv); } return rv; -#else - return (errno=ENOTSUP,-1); -#endif } int list(const int fd, - vector &attrvector) + vector &attrvector) { int rv; vector attrs; @@ -159,26 +149,22 @@ namespace fs const string &attr, vector &value) { -#ifndef WITHOUT_XATTR ssize_t rv; rv = -1; errno = ERANGE; while((rv == -1) && (errno == ERANGE)) { - rv = ::fgetxattr(fd,attr.c_str(),NULL,0); + rv = fs::fgetxattr(fd,attr,NULL,0); if(rv <= 0) return rv; value.resize(rv); - rv = ::fgetxattr(fd,attr.c_str(),&value[0],rv); + rv = fs::fgetxattr(fd,attr,&value[0],rv); } return rv; -#else - return (errno=ENOTSUP,-1); -#endif } int @@ -186,26 +172,22 @@ namespace fs const string &attr, vector &value) { -#ifndef WITHOUT_XATTR ssize_t rv; rv = -1; errno = ERANGE; while((rv == -1) && (errno == ERANGE)) { - rv = ::lgetxattr(path.c_str(),attr.c_str(),NULL,0); + rv = fs::lgetxattr(path,attr,NULL,0); if(rv <= 0) return rv; value.resize(rv); - rv = ::lgetxattr(path.c_str(),attr.c_str(),&value[0],rv); + rv = fs::lgetxattr(path,attr,&value[0],rv); } return rv; -#else - return (errno=ENOTSUP,-1); -#endif } int @@ -300,15 +282,11 @@ namespace fs const string &value, const int flags) { -#ifndef WITHOUT_XATTR - return ::fsetxattr(fd, - key.c_str(), - value.data(), - value.size(), - flags); -#else - return (errno=ENOTSUP,-1); -#endif + return fs::fsetxattr(fd, + key.c_str(), + value.data(), + value.size(), + flags); } int @@ -317,15 +295,11 @@ namespace fs const string &value, const int flags) { -#ifndef WITHOUT_XATTR - return ::lsetxattr(path.c_str(), - key.c_str(), - value.data(), - value.size(), - flags); -#else - return (errno=ENOTSUP,-1); -#endif + return fs::lsetxattr(path.c_str(), + key.c_str(), + value.data(), + value.size(), + flags); } int diff --git a/src/xattr.hpp b/src/xattr.hpp index 75635e8c..f4052975 100644 --- a/src/xattr.hpp +++ b/src/xattr.hpp @@ -16,8 +16,21 @@ #pragma once -#ifndef WITHOUT_XATTR -#include +#if defined(__ANDROID__) +# include +#elif defined(__APPLE__) +# include +#elif defined(__linux__) +# include +#endif + +#ifdef USE_XATTR +# ifdef __GLIBC__ +# include +# else +# undef USE_XATTR +# warning "USE_XATTR unset: xattrs disabled" +# endif #endif #ifndef XATTR_CREATE