Hello,

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.

This is my first gnulib proposal - please, forgive me if I made any
mistake.  I tried inspire with selinux-at module and others as much as
possible.  But I'll be happy to repair any possible problem.

Pavel

>From b00fff657574e7ca98336af9a35d672d349dc9be 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/attr-xattr.in.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 m4/attr-xattr-h.m4  | 28 +++++++++++++++++++++++
 modules/xattr-h     | 44 ++++++++++++++++++++++++++++++++++++
 3 files changed, 137 insertions(+)
 create mode 100644 lib/attr-xattr.in.h
 create mode 100644 m4/attr-xattr-h.m4
 create mode 100644 modules/xattr-h

diff --git a/lib/attr-xattr.in.h b/lib/attr-xattr.in.h
new file mode 100644
index 0000000..ae3e28f
--- /dev/null
+++ b/lib/attr-xattr.in.h
@@ -0,0 +1,65 @@
+#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/>.  */
+
+#if HAVE_ATTR_XATTR_H
+
+#include <sys/types.h>
+#include_next <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 /* if HAVE_ATTR_XATTR_H */
+#endif /* _@GUARD_PREFIX@_ATTR_XATTR_H */
diff --git a/m4/attr-xattr-h.m4 b/m4/attr-xattr-h.m4
new file mode 100644
index 0000000..271834b
--- /dev/null
+++ b/m4/attr-xattr-h.m4
@@ -0,0 +1,28 @@
+# 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 <attr/xattr.h>, if necessary
+
+AC_DEFUN([gl_HEADERS_ATTR_XATTR_H],
+[
+  AC_ARG_WITH([xattrs],
+    AS_HELP_STRING([--without-xattrs], [don't use linux exteneded atttributes]),
+    [], [with_xattrs=maybe]
+  )
+
+  AC_CHECK_HEADERS([attr/xattr.h])
+  if test "$ac_cv_header_attr_xattr_h" = yes; then
+    AC_CHECK_FUNCS(getxattr  fgetxattr  lgetxattr \
+                   setxattr  fsetxattr  lsetxattr \
+                   listxattr flistxattr llistxattr,
+        # only when functions are present
+        AC_DEFINE([HAVE_ATTR_XATTR_H], [1],
+                    [define to 1 if we have <attr/xattr.h> header])
+        if test "$with_xattrs" != 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..691e7fe
--- /dev/null
+++ b/modules/xattr-h
@@ -0,0 +1,44 @@
+Description:
+xattr headers for systems that lack them
+
+Files:
+lib/attr-xattr.in.h
+m4/attr-xattr-h.m4
+
+Depends-on:
+errno
+sys_types
+include_next
+
+configure.ac:
+gl_HEADERS_ATTR_XATTR_H
+
+Makefile.am:
+lib_SOURCES += attr-xattr.in.h
+BUILT_SOURCES += attr/xattr.h
+attr/xattr.h: attr-xattr.in.h $(top_builddir)/config.status
+	$(AM_V_at)$(MKDIR_P) attr
+	$(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|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e '/definition of _GL_UNUSED_PARAMETER/r $(UNUSED_PARAMETER_H)' \
+	      < $(srcdir)/attr-xattr.in.h; \
+	} > $@-t && \
+	chmod a-x $@-t && \
+	mv $@-t $@
+MOSTLYCLEANFILES += attr/xattr.h attr/xattr.h-t
+
+Include:
+<sys/types.h>
+<attr/xattr.h>
+
+Link:
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-- 
1.7.11.2

>From 8c68bbb088bada4179d410a025b3212e6e9679c5 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

Reply via email to