>From e109ff62fa70074ef5bbc6406b4cd70cc57567dc Mon Sep 17 00:00:00 2001 From: Pavel Raiskup 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 . */ + +#include + +#include "xattr-at.h" +#include "openat.h" + +#include +#include +#include +#include + +#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 . */ + +#include +#include + +/* 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