remove libattr dependency

This commit is contained in:
Antonio SJ Musumeci 2018-10-09 11:58:06 -04:00
parent 602a37b231
commit 1885a82cce
11 changed files with 170 additions and 94 deletions

View File

@ -41,7 +41,7 @@ ifeq ($(PANDOC),)
$(warning "pandoc does not appear available: manpage won't be buildable") $(warning "pandoc does not appear available: manpage won't be buildable")
endif endif
XATTR_AVAILABLE = $(shell test ! -e /usr/include/attr/xattr.h; echo $$?) USE_XATTR = 1
INTERNAL_FUSE = 1 INTERNAL_FUSE = 1
EXTERNAL_FUSE_MIN_REQ = 2.9.7 EXTERNAL_FUSE_MIN_REQ = 2.9.7
@ -73,6 +73,7 @@ CFLAGS = -g -Wall \
$(FUSE_CFLAGS) \ $(FUSE_CFLAGS) \
-DFUSE_USE_VERSION=29 \ -DFUSE_USE_VERSION=29 \
-MMD \ -MMD \
-DUSE_XATTR=$(USE_XATTR) \
-DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK) -DUGID_USE_RWLOCK=$(UGID_USE_RWLOCK)
PREFIX = /usr/local PREFIX = /usr/local
@ -88,16 +89,11 @@ INSTALLBINDIR = $(DESTDIR)$(BINDIR)
INSTALLSBINDIR = $(DESTDIR)$(SBINDIR) INSTALLSBINDIR = $(DESTDIR)$(SBINDIR)
INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR) INSTALLMAN1DIR = $(DESTDIR)$(MAN1DIR)
ifeq ($(XATTR_AVAILABLE),0)
$(warning "xattr not available: disabling")
CFLAGS += -DWITHOUT_XATTR
endif
all: $(TARGET) all: $(TARGET)
help: help:
@echo "usage: make" @echo "usage: make"
@echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)" @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)" @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) $(TARGET): version obj/obj-stamp $(FUSE_TARGET) $(OBJ)
@ -218,13 +214,13 @@ install-build-pkgs:
ifeq ($(shell test -e /usr/bin/apt-get; echo $$?),0) ifeq ($(shell test -e /usr/bin/apt-get; echo $$?),0)
apt-get -qy update apt-get -qy update
apt-get -qy --no-install-suggests --no-install-recommends --force-yes \ 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) else ifeq ($(shell test -e /usr/bin/dnf; echo $$?),0)
dnf -y update 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) else ifeq ($(shell test -e /usr/bin/yum; echo $$?),0)
yum -y update 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 endif
unexport CFLAGS unexport CFLAGS

View File

@ -271,7 +271,7 @@ $ sudo apt-get -y update
$ sudo apt-get -y install git make $ sudo apt-get -y install git make
$ cd mergerfs $ cd mergerfs
$ make install-build-pkgs $ 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 $ make deb
$ sudo dpkg -i ../mergerfs_version_arch.deb $ sudo dpkg -i ../mergerfs_version_arch.deb
``` ```
@ -283,14 +283,14 @@ $ su -
# dnf -y install git make # dnf -y install git make
# cd mergerfs # cd mergerfs
# make install-build-pkgs # 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 # make rpm
# rpm -i rpmbuild/RPMS/<arch>/mergerfs-<verion>.<arch>.rpm # rpm -i rpmbuild/RPMS/<arch>/mergerfs-<verion>.<arch>.rpm
``` ```
#### Generically #### Generically
Have git, g++, make, python, libattr1, automake, libtool installed. Have git, g++, make, python, automake, libtool installed.
``` ```
$ cd mergerfs $ 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. **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). Also, install libfuse >= 2.9.7 (but not libfuse-3.x) and matching libfuse-dev (or libfuse-devel).
``` ```

3
debian/control vendored
View File

@ -2,8 +2,7 @@ Source: mergerfs
Section: utils Section: utils
Priority: optional Priority: optional
Maintainer: Antonio SJ Musumeci <trapexit@spawn.link> Maintainer: Antonio SJ Musumeci <trapexit@spawn.link>
Build-Depends: debhelper (>= 8.0.0), Build-Depends: debhelper (>= 8.0.0)
libattr1-dev
Standards-Version: 3.9.4 Standards-Version: 3.9.4
Homepage: http://github.com/trapexit/mergerfs Homepage: http://github.com/trapexit/mergerfs

View File

@ -708,7 +708,7 @@ $\ sudo\ apt\-get\ \-y\ update
$\ sudo\ apt\-get\ \-y\ install\ git\ make $\ sudo\ apt\-get\ \-y\ install\ git\ make
$\ cd\ mergerfs $\ cd\ mergerfs
$\ make\ install\-build\-pkgs $\ 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 $\ make\ deb
$\ sudo\ dpkg\ \-i\ ../mergerfs_version_arch.deb $\ sudo\ dpkg\ \-i\ ../mergerfs_version_arch.deb
\f[] \f[]
@ -722,14 +722,14 @@ $\ su\ \-
#\ dnf\ \-y\ install\ git\ make #\ dnf\ \-y\ install\ git\ make
#\ cd\ mergerfs #\ cd\ mergerfs
#\ make\ install\-build\-pkgs #\ 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 #\ make\ rpm
#\ rpm\ \-i\ rpmbuild/RPMS/<arch>/mergerfs\-<verion>.<arch>.rpm #\ rpm\ \-i\ rpmbuild/RPMS/<arch>/mergerfs\-<verion>.<arch>.rpm
\f[] \f[]
.fi .fi
.SS Generically .SS Generically
.PP .PP
Have git, g++, make, python, libattr1, automake, libtool installed. Have git, g++, make, python, automake, libtool installed.
.IP .IP
.nf .nf
\f[C] \f[C]
@ -743,7 +743,7 @@ $\ sudo\ make\ install
\f[B]NOTE:\f[] Configurable threading and thus \f[C]\-o\ threads=num\f[] \f[B]NOTE:\f[] Configurable threading and thus \f[C]\-o\ threads=num\f[]
option will be unavailable when built with system libfuse. option will be unavailable when built with system libfuse.
.PP .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 Also, install libfuse >= 2.9.7 (but not libfuse\-3.x) and matching
libfuse\-dev (or libfuse\-devel). libfuse\-dev (or libfuse\-devel).
.IP .IP

View File

@ -10,7 +10,6 @@ URL: https://github.com/trapexit/mergerfs
Source: mergerfs-%{version}.tar.gz Source: mergerfs-%{version}.tar.gz
BuildRequires: gcc-c++ BuildRequires: gcc-c++
BuildRequires: libattr-devel
# rpmbuild driven by the Makefile uses git to generate a version number # rpmbuild driven by the Makefile uses git to generate a version number
BuildRequires: git BuildRequires: git

View File

@ -18,25 +18,78 @@
#pragma once #pragma once
#include <sys/types.h>
#include "errno.hpp" #include "errno.hpp"
#include "xattr.hpp" #include "xattr.hpp"
#include <sys/types.h>
#include <string>
namespace fs namespace fs
{ {
static static
inline inline
int int
lgetxattr(const std::string &path, lgetxattr(const char *path_,
const char *attrname, const char *attrname_,
void *value, void *value_,
const size_t size) const size_t size_)
{ {
#ifndef WITHOUT_XATTR #ifdef USE_XATTR
return ::lgetxattr(path.c_str(),attrname,value,size); return ::lgetxattr(path_,attrname_,value_,size_);
#else #else
return (errno=ENOTSUP,-1); return (errno=ENOTSUP,-1);
#endif #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_)
{
#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_);
}
} }

View File

@ -18,22 +18,48 @@
#pragma once #pragma once
#include <sys/types.h>
#include "errno.hpp" #include "errno.hpp"
#include "xattr.hpp" #include "xattr.hpp"
#include <sys/types.h>
#include <string>
namespace fs namespace fs
{ {
static static
inline inline
int int
llistxattr(const std::string &path, llistxattr(const char *path_,
char *list, char *list_,
const size_t size) const size_t size_)
{ {
#ifndef WITHOUT_XATTR #ifdef USE_XATTR
return ::llistxattr(path.c_str(),list,size); 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_)
{
#ifdef USE_XATTR
return ::flistxattr(fd_,list_,size_);
#else #else
return (errno=ENOTSUP,-1); return (errno=ENOTSUP,-1);
#endif #endif

View File

@ -31,7 +31,7 @@ namespace fs
lremovexattr(const std::string &path, lremovexattr(const std::string &path,
const char *attrname) const char *attrname)
{ {
#ifndef WITHOUT_XATTR #ifdef USE_XATTR
return ::lremovexattr(path.c_str(),attrname); return ::lremovexattr(path.c_str(),attrname);
#else #else
return (errno=ENOTSUP,-1); return (errno=ENOTSUP,-1);

View File

@ -34,10 +34,26 @@ namespace fs
const size_t size, const size_t size,
const int flags) const int flags)
{ {
#ifndef WITHOUT_XATTR #ifdef USE_XATTR
return ::lsetxattr(path.c_str(),name,value,size,flags); return ::lsetxattr(path.c_str(),name,value,size,flags);
#else #else
return (errno=ENOTSUP,-1); 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 #endif
} }
} }

View File

@ -14,22 +14,20 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <fcntl.h> #include "errno.hpp"
#include <stdlib.h> #include "fs_base_close.hpp"
#include <sys/stat.h> #include "fs_base_getxattr.hpp"
#include <sys/types.h> #include "fs_base_listxattr.hpp"
#include <unistd.h> #include "fs_base_open.hpp"
#include "fs_base_removexattr.hpp"
#include "fs_base_setxattr.hpp"
#include "str.hpp"
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include <sstream> #include <sstream>
#include "errno.hpp"
#include "fs_base_open.hpp"
#include "fs_base_close.hpp"
#include "str.hpp"
#include "xattr.hpp"
using std::string; using std::string;
using std::vector; using std::vector;
@ -44,52 +42,44 @@ namespace fs
list(const int fd, list(const int fd,
vector<char> &attrs) vector<char> &attrs)
{ {
#ifndef WITHOUT_XATTR
ssize_t rv; ssize_t rv;
rv = -1; rv = -1;
errno = ERANGE; errno = ERANGE;
while((rv == -1) && (errno == ERANGE)) while((rv == -1) && (errno == ERANGE))
{ {
rv = ::flistxattr(fd,NULL,0); rv = fs::flistxattr(fd,NULL,0);
if(rv <= 0) if(rv <= 0)
return rv; return rv;
attrs.resize(rv); attrs.resize(rv);
rv = ::flistxattr(fd,&attrs[0],rv); rv = fs::flistxattr(fd,&attrs[0],rv);
} }
return rv; return rv;
#else
return (errno=ENOTSUP,-1);
#endif
} }
int int
list(const string &path, list(const string &path,
vector<char> &attrs) vector<char> &attrs)
{ {
#ifndef WITHOUT_XATTR
ssize_t rv; ssize_t rv;
rv = -1; rv = -1;
errno = ERANGE; errno = ERANGE;
while((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) if(rv <= 0)
return rv; return rv;
attrs.resize(rv); attrs.resize(rv);
rv = ::llistxattr(path.c_str(),&attrs[0],rv); rv = fs::llistxattr(path,&attrs[0],rv);
} }
return rv; return rv;
#else
return (errno=ENOTSUP,-1);
#endif
} }
int int
@ -159,26 +149,22 @@ namespace fs
const string &attr, const string &attr,
vector<char> &value) vector<char> &value)
{ {
#ifndef WITHOUT_XATTR
ssize_t rv; ssize_t rv;
rv = -1; rv = -1;
errno = ERANGE; errno = ERANGE;
while((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) if(rv <= 0)
return rv; return rv;
value.resize(rv); value.resize(rv);
rv = ::fgetxattr(fd,attr.c_str(),&value[0],rv); rv = fs::fgetxattr(fd,attr,&value[0],rv);
} }
return rv; return rv;
#else
return (errno=ENOTSUP,-1);
#endif
} }
int int
@ -186,26 +172,22 @@ namespace fs
const string &attr, const string &attr,
vector<char> &value) vector<char> &value)
{ {
#ifndef WITHOUT_XATTR
ssize_t rv; ssize_t rv;
rv = -1; rv = -1;
errno = ERANGE; errno = ERANGE;
while((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) if(rv <= 0)
return rv; return rv;
value.resize(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; return rv;
#else
return (errno=ENOTSUP,-1);
#endif
} }
int int
@ -300,15 +282,11 @@ namespace fs
const string &value, const string &value,
const int flags) const int flags)
{ {
#ifndef WITHOUT_XATTR return fs::fsetxattr(fd,
return ::fsetxattr(fd,
key.c_str(), key.c_str(),
value.data(), value.data(),
value.size(), value.size(),
flags); flags);
#else
return (errno=ENOTSUP,-1);
#endif
} }
int int
@ -317,15 +295,11 @@ namespace fs
const string &value, const string &value,
const int flags) const int flags)
{ {
#ifndef WITHOUT_XATTR return fs::lsetxattr(path.c_str(),
return ::lsetxattr(path.c_str(),
key.c_str(), key.c_str(),
value.data(), value.data(),
value.size(), value.size(),
flags); flags);
#else
return (errno=ENOTSUP,-1);
#endif
} }
int int

View File

@ -16,8 +16,21 @@
#pragma once #pragma once
#ifndef WITHOUT_XATTR #if defined(__ANDROID__)
#include <attr/xattr.h> # include <sys/cdefs.h>
#elif defined(__APPLE__)
# include <TargetConditionals.h>
#elif defined(__linux__)
# include <features.h>
#endif
#ifdef USE_XATTR
# ifdef __GLIBC__
# include <sys/xattr.h>
# else
# undef USE_XATTR
# warning "USE_XATTR unset: xattrs disabled"
# endif
#endif #endif
#ifndef XATTR_CREATE #ifndef XATTR_CREATE