Hello again, > I'd like to ask you whether it would be possible to add support of > extended file system attributes into Gnulib code base. The reason is > that I would like to add support for extended attributes into upstream > GNU tar. > > I'm proposing two patches. > > 1) First is adding basic xattrs support into gnulib - module 'xattr'. > This should guarantee that (even if they are just stubs) basic > setxattr/getxattr/listxattr/etc methods always exist. > > 2) Second patch adds module 'xattr-at' that depends on 'xattr'. This > module implements *at() wrappers for extended attributes calls.
I have repaired several problems in first patch so I'm attaching these two patches again. The main mistake was that I included <attr/xattr.h> header which is now usually substituted by <sys/xattr.h> from glibc. I still cannot understand some magic in gnulib properly, sorry for that. All modules which are dependent on include_next module are using sed inside modules/MODULE file. I tried to cut&paste this part into xattr-h module also. But there are also variables like $(NEXT_*) in sed rules, which I'm not able to force to exist for me (NEXT_SYS_XATTR_H). Instead, I added the similar hardwired rule for now: ... -e 's|@''NEXT_SYS_XATTR_H''@|<sys/xattr.h>|g' \ ... Do you see where is the problem? And could you please look at these patches in general? I'll be glad to repair any principal/technical mistake I'll be able to. Or do you think that this is unacceptable in general? Thank you, Pavel
>From aa80da8643a3c3025b547df765886f4c5c2dc7a4 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup <pa...@raiskup.cz> Date: Mon, 6 Aug 2012 13:15:16 +0200 Subject: [PATCH 1/2] adding module 'xattr' --- lib/sys_xattr.in.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ m4/sys_xattr_h.m4 | 53 +++++++++++++++++++++++++++++++++++++++++++ modules/xattr-h | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 lib/sys_xattr.in.h create mode 100644 m4/sys_xattr_h.m4 create mode 100644 modules/xattr-h diff --git a/lib/sys_xattr.in.h b/lib/sys_xattr.in.h new file mode 100644 index 0000000..e12303f --- /dev/null +++ b/lib/sys_xattr.in.h @@ -0,0 +1,66 @@ +#ifndef _@GUARD_PREFIX@_ATTR_XATTR_H +#define _@GUARD_PREFIX@_ATTR_XATTR_H + +/* Replacement <attr/xattr.h> for platforms that lack it. + Copyright (C) 2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <sys/types.h> + +#ifdef HAVE_SYS_XATTR_H +#@INCLUDE_NEXT@ @NEXT_SYS_XATTR_H@ +#elif defined HAVE_ATTR_XATTR_H +# include <attr/xattr.h> +#else +# include <errno.h> + +/* setting */ +static inline int setxattr (const char *path, const char *name, const void + *value, size_t size, int flags) +{ errno = ENOTSUP; return -1; } + +static inline int lsetxattr (const char *path, const char *name, const void + *value, size_t size, int flags) +{ errno = ENOTSUP; return -1; } + +static inline int fsetxattr (int filedes, const char *name, const void *value, + size_t size, int flags) +{ errno = ENOTSUP; return -1; } + + +/* getting */ +static inline ssize_t getxattr (const char *path, const char *name, void *value, + size_t size) +{ errno = ENOTSUP; return -1; } +static inline ssize_t lgetxattr (const char *path, const char *name, void + *value, size_t size) +{ errno = ENOTSUP; return -1; } +static inline ssize_t fgetxattr (int filedes, const char *name, void *value, + size_t size) +{ errno = ENOTSUP; return -1; } + + +/* listing */ +static inline ssize_t listxattr (const char *path, char *list, size_t size) +{ errno = ENOTSUP; return -1; } + +static inline ssize_t llistxattr (const char *path, char *list, size_t size) +{ errno = ENOTSUP; return -1; } + +static inline ssize_t flistxattr (int filedes, char *list, size_t size) +{ errno = ENOTSUP; return -1; } + +#endif +#endif /* _@GUARD_PREFIX@_ATTR_XATTR_H */ diff --git a/m4/sys_xattr_h.m4 b/m4/sys_xattr_h.m4 new file mode 100644 index 0000000..4f005dd --- /dev/null +++ b/m4/sys_xattr_h.m4 @@ -0,0 +1,53 @@ +# Copyright (C) 2012 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Provide <sys/xattr.h>, if necessary + +AC_DEFUN([gl_HEADERS_SYS_XATTR_H], +[ + AC_ARG_WITH([xattrs], + AS_HELP_STRING([--without-xattrs], [don't use linux exteneded atttributes]), + [], [with_xattrs=maybe] + ) + + if test "x$with_xattrs" != "xno"; then + found=no + + # check for regular glibcs implementation of extended attributes + AC_CHECK_HEADERS([sys/xattr.h], + [ + AC_CHECK_FUNCS(getxattr fgetxattr lgetxattr \ + setxattr fsetxattr lsetxattr \ + listxattr flistxattr llistxattr, + # only when functions are present + AC_DEFINE([HAVE_SYS_XATTR_H], [1], + [define to 1 if we have <sys/xattr.h> header]) + found=glibc + ) + ], + [], + [[#include <sys/xattr.h>]] + ) + + # before xattr support was added into glibc, -lattr & attr/xattr.h was used + if test "$found" = "no"; then + AC_CHECK_HEADERS([attr/xattr.h], + [ + AC_SEARCH_LIBS(getxattr, attr) + if test "$ac_cv_search_getxattr" != "no"; then + AC_DEFINE([HAVE_ATTR_XATTR_H], [1], + [define to 1 if we have <attr/xattr.h> header] + ) + found=libattr + fi + ] + ) + fi + + if test "$found" != "no"; then + AC_DEFINE([HAVE_XATTRS],,[Define when we have working linux xattrs.]) + fi +fi +]) diff --git a/modules/xattr-h b/modules/xattr-h new file mode 100644 index 0000000..0ef5a9c --- /dev/null +++ b/modules/xattr-h @@ -0,0 +1,46 @@ +Description: +xattr headers for systems that lack them + +Files: +lib/sys_xattr.in.h +m4/sys_xattr_h.m4 + +Depends-on: +include_next +errno +sys_types +snippet/unused-parameter + +configure.ac: +gl_HEADERS_SYS_XATTR_H + +Makefile.am: +lib_SOURCES += sys_xattr.in.h + +BUILT_SOURCES += sys/xattr.h +sys/xattr.h: sys_xattr.in.h $(top_builddir)/config.status $(UNUSED_PARAMETER_H) + $(AM_V_at)$(MKDIR_P) sys + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''NEXT_SYS_XATTR_H''@|<sys/xattr.h>|g' \ + -e '/definition of _GL_UNUSED_PARAMETER/r $(UNUSED_PARAMETER_H)' \ + < $(srcdir)/sys_xattr.in.h; \ + } > $@-t && \ + chmod a-x $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += sys/xattr.h sys/xattr.h-t +MOSTLYCLEANDIRS += sys + +Include: +<sys/types.h> +<sys/xattr.h> + +Link: + +License: +LGPLv2+ + +Maintainer: +all -- 1.7.11.2
>From e109ff62fa70074ef5bbc6406b4cd70cc57567dc Mon Sep 17 00:00:00 2001 From: Pavel Raiskup <pa...@raiskup.cz> Date: Mon, 6 Aug 2012 13:16:19 +0200 Subject: [PATCH 2/2] adding module xattr-at --- lib/xattr-at.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/xattr-at.h | 66 +++++++++++++++++++++++++++++++++ modules/xattr-at | 36 ++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 lib/xattr-at.c create mode 100644 lib/xattr-at.h create mode 100644 modules/xattr-at diff --git a/lib/xattr-at.c b/lib/xattr-at.c new file mode 100644 index 0000000..746578c --- /dev/null +++ b/lib/xattr-at.c @@ -0,0 +1,110 @@ +/* openat-style fd-relative functions for operating with extended file + attributes. + + Copyright (C) 2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +#include "xattr-at.h" +#include "openat.h" + +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> +#include <fcntl.h> + +#include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ +#include "save-cwd.h" + +#include "openat-priv.h" + +/* setxattrat */ +#define AT_FUNC_NAME setxattrat +#define AT_FUNC_F1 setxattr +#define AT_FUNC_POST_FILE_PARAM_DECLS , const char *name, const void *value \ + , size_t size, int flags +#define AT_FUNC_POST_FILE_ARGS , name, value, size, flags +#include "at-func.c" +#undef AT_FUNC_NAME +#undef AT_FUNC_F1 +#undef AT_FUNC_POST_FILE_PARAM_DECLS +#undef AT_FUNC_POST_FILE_ARGS + +/* lsetxattrat */ +#define AT_FUNC_NAME lsetxattrat +#define AT_FUNC_F1 lsetxattr +#define AT_FUNC_POST_FILE_PARAM_DECLS , const char *name, const void *value \ + , size_t size, int flags +#define AT_FUNC_POST_FILE_ARGS , name, value, size, flags +#include "at-func.c" +#undef AT_FUNC_NAME +#undef AT_FUNC_F1 +#undef AT_FUNC_POST_FILE_PARAM_DECLS +#undef AT_FUNC_POST_FILE_ARGS + +/* getxattrat */ +#define AT_FUNC_NAME getxattrat +#define AT_FUNC_RESULT ssize_t +#define AT_FUNC_F1 getxattr +#define AT_FUNC_POST_FILE_PARAM_DECLS , const char *name, void *value \ + , size_t size +#define AT_FUNC_POST_FILE_ARGS , name, value, size +#include "at-func.c" +#undef AT_FUNC_NAME +#undef AT_FUNC_F1 +#undef AT_FUNC_RESULT +#undef AT_FUNC_POST_FILE_PARAM_DECLS +#undef AT_FUNC_POST_FILE_ARGS + +/* lgetxattrat */ +#define AT_FUNC_NAME lgetxattrat +#define AT_FUNC_RESULT ssize_t +#define AT_FUNC_F1 lgetxattr +#define AT_FUNC_POST_FILE_PARAM_DECLS , const char *name, void *value \ + , size_t size +#define AT_FUNC_POST_FILE_ARGS , name, value, size +#include "at-func.c" +#undef AT_FUNC_NAME +#undef AT_FUNC_F1 +#undef AT_FUNC_RESULT +#undef AT_FUNC_POST_FILE_PARAM_DECLS +#undef AT_FUNC_POST_FILE_ARGS + +/* listxattrat */ +#define AT_FUNC_NAME listxattrat +#define AT_FUNC_RESULT ssize_t +#define AT_FUNC_F1 listxattr +#define AT_FUNC_POST_FILE_PARAM_DECLS , char *list , size_t size +#define AT_FUNC_POST_FILE_ARGS , list , size +#include "at-func.c" +#undef AT_FUNC_NAME +#undef AT_FUNC_F1 +#undef AT_FUNC_RESULT +#undef AT_FUNC_POST_FILE_PARAM_DECLS +#undef AT_FUNC_POST_FILE_ARGS + +/* llistxattrat */ +#define AT_FUNC_NAME llistxattrat +#define AT_FUNC_RESULT ssize_t +#define AT_FUNC_F1 llistxattr +#define AT_FUNC_POST_FILE_PARAM_DECLS , char *list , size_t size +#define AT_FUNC_POST_FILE_ARGS , list , size +#include "at-func.c" +#undef AT_FUNC_NAME +#undef AT_FUNC_F1 +#undef AT_FUNC_RESULT +#undef AT_FUNC_POST_FILE_PARAM_DECLS +#undef AT_FUNC_POST_FILE_ARGS diff --git a/lib/xattr-at.h b/lib/xattr-at.h new file mode 100644 index 0000000..480b9f3 --- /dev/null +++ b/lib/xattr-at.h @@ -0,0 +1,66 @@ +#ifndef XATTRS_AT_H +#define XATTRS_AT_H + +/* Prototypes for openat-style fd-relative functions for operating with + extended file attributes. + + Copyright (C) 2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <sys/types.h> +#include <attr/xattr.h> + +/* These are the dir-fd-relative variants of the functions without the + "at" suffix. For example, setxattrat (AT_FDCWD, path, name, value, size, + flags &c) is usually equivalent to setxattr (file, name, value, size, + flags). For more info use the setxattr(2), getxattr(2) or listxattr(2) + manpages. */ + +/* dir-fd-relative setxattr. Operation sets the VALUE of the extended + attribute identified by NAME and associated with the given PATH in the + filesystem relatively to directory identified by DIR_FD. See the + setxattr(2) manpage for the description of all parameters. */ +int setxattrat (int dir_fd, const char *path, const char *name, + const void *value, size_t size, int flags); + +/* dir-fd-relative lsetxattr. This function is just like setxattrat, + except when DIR_FD and FILE specify a symlink: lsetxattrat operates on the + symlink, while the setxattrat operates on the referent of the symlink. */ +int lsetxattrat (int dir_fd, const char *path, const char *name, + const void *value, size_t size, int flags); + +/* dir-fd-relative getxattr. Operation gets the VALUE of the extended + attribute idenfified by NAME and associated with the given PATH in the + filesystem relatively to directory identified by DIR_FD. For more info + about all parameters see the getxattr(2) manpage. */ +ssize_t getxattrat (int dir_fd, const char *path, const char *name, + void *value, size_t size); + +/* dir-fd-relative lgetxattr. This function is just like getxattrat, + except when DIR_FD and FILE specify a symlink: lgetxattrat operates on the + symlink, while the getxattrat operates on the referent of the symlink. */ +ssize_t lgetxattrat (int dir_fd, const char *path, const char *name, + void *value, size_t size); + +/* dir-fd-relative listxattr. Obtain the list of extended attrubtes names. For + more info see the listxattr(2) manpage. */ +ssize_t listxattrat (int dir_fd, const char *path, char *list, size_t size); + +/* dir-fd-relative llistxattr. This function is just like listxattrat, + except when DIR_FD and FILE specify a symlink: llistxattr operates on the + symlink, while the listxattrat operates on the referent of the symlink. */ +ssize_t llistxattrat (int dir_fd, const char *path, char *list, size_t size); + +#endif /* XATTRS_AT_H */ diff --git a/modules/xattr-at b/modules/xattr-at new file mode 100644 index 0000000..c9aa995 --- /dev/null +++ b/modules/xattr-at @@ -0,0 +1,36 @@ +Description: +openat-style fd-relative functions for extended attributes + +Files: +lib/xattr-at.h +lib/xattr-at.c +lib/at-func.c + +Depends-on: +at-internal +dosname +errno +extensions +fchdir +fcntl-h +openat-die +openat-h +save-cwd +unistd +sys_types +xattr-h + +configure.ac: +AC_CHECK_HEADERS([attr/xattr.h]) +AC_LIBOBJ([xattr-at]) + +Makefile.am: + +Include: +"xattr-at.h" + +License: +LGPLv2+ + +Maintainer: +all -- 1.7.11.2