erofs-utils: lib: introduce erofs_sys_lsetxattr()
PATCH 1/1 erofs-utils: lib: introduce erofs_sys_lsetxattr()
To wrap raw function calls for better portability.
Signed-off-by Gao Xiang <[email protected]>
--- fsck/main.c | 12 ++---------- include/erofs/xattr.h | 3 +++ lib/xattr.c | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-)
fsck/main.c +2 -10
@@ -9,7 +9,6 @@#include <utime.h> #include <unistd.h> #include <sys/stat.h> -#include <sys/xattr.h> #include "erofs/print.h" #include "erofs/decompress.h" #include "erofs/dir.h"
@@ -457,15 +456,8 @@ static int erofsfsck_dump_xattrs(struct erofs_inode *inode)break ; }if (fsckcfg.extract_path) -#ifdef HAVE_LSETXATTR - ret =lsetxattr (fsckcfg.extract_path, key, value, size, -0 ); -#elif defined(__APPLE__) - ret =setxattr (fsckcfg.extract_path, key, value, size, -0 ,XATTR_NOFOLLOW ); -#else - ret = -EOPNOTSUPP ; -#endif + ret =erofs_sys_lsetxattr (fsckcfg.extract_path, key, + value, size);else ret =0 ;free (value);
include/erofs/xattr.h +3 -0
@@ -45,6 +45,9 @@ static inline unsigned int xattrblock_offset(struct erofs_inode *vi,struct erofs_importer ; +ssize_t erofs_sys_lsetxattr (const char *path,const char *name, +void *value,size_t size); +int erofs_xattr_init (struct erofs_sb_info *sbi);int erofs_scan_file_xattrs (struct erofs_inode *inode);int erofs_prepare_xattr_ibody (struct erofs_inode *inode,bool noroom);
lib/xattr.c +18 -0
@@ -99,6 +99,24 @@ static ssize_t erofs_sys_lgetxattr(const char *path, const char *name,return -1 ; } +ssize_t erofs_sys_lsetxattr (const char *path,const char *name, +void *value,size_t size) +{ +int ret; + +#ifdef HAVE_LSETXATTR + ret =lsetxattr (path, name, value, size,0 ); +#elif defined(__APPLE__) + ret =setxattr (path, name, value, size,0 ,XATTR_NOFOLLOW ); +#else + ret =-1 ; + errno =ENODATA ; +#endif +if (ret <0 ) +return errno; +return ret; +} +/* one extra byte for the trailing `\0` of attribute name */ #define EROFS_XATTR_KSIZE (kvlen) (kvlen[0] + 1)#define EROFS_XATTR_KVSIZE (kvlen) (EROFS_XATTR_KSIZE(kvlen) + kvlen[1])
Signature · 1 line
2.43.5