diff options
author | Iblis Lin <iblis@hs.ntnu.edu.tw> | 2017-07-31 11:25:07 +0800 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2017-08-29 13:32:52 +0000 |
commit | bf7b0b60b1710b19561a2f7c79c3be4d09842b2c (patch) | |
tree | f5529b83d75bdcb45fb6bd702fc1c55d6683da4a | |
parent | 3ec63650bb7fd874a5013e7be4a2def3b519c9b2 (diff) |
posix: fix incorrect xattr list handling on FreeBSD
Change-Id: I5be157259f0b665640aaa1eda68063bb19fd7b3d
BUG: 1484246
Signed-off-by: Pellaeon Lin <nfsmwlin@gmail.com>
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
Reviewed-on: https://review.gluster.org/17917
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
-rw-r--r-- | libglusterfs/src/compat.c | 28 | ||||
-rw-r--r-- | libglusterfs/src/compat.h | 3 | ||||
-rw-r--r-- | libglusterfs/src/syscall.c | 10 |
3 files changed, 39 insertions, 2 deletions
diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c index 621ff5f54c9..a27fe20ce64 100644 --- a/libglusterfs/src/compat.c +++ b/libglusterfs/src/compat.c @@ -535,6 +535,34 @@ out: #endif /* GF_SOLARIS_HOST_OS */ +#ifdef GF_BSD_HOST_OS +void +gf_extattr_list_reshape(char *bsd_list, ssize_t size) +{ + /* + * the format of bsd_list is + * <attr_len>attr<attr_len>attr... + * we try to reformat it as Linux's + * attr<\0>attr<\0>... + * */ + if (NULL == bsd_list || size <= 0) + return; + + size_t i = 0, j; + + while (i < size) { + size_t attr_len = bsd_list[i]; + + for (j = i; j < i+attr_len; ++j) + bsd_list[j] = bsd_list[j+1]; + bsd_list[j] = '\0'; + + i += attr_len + 1; + gf_msg_debug ("syscall", 0, "syscall debug: %lu", attr_len); + } +} +#endif /* GF_BSD_HOST_OS */ + #ifndef HAVE_STRNLEN size_t strnlen(const char *string, size_t maxlen) diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h index f4da4b2a0de..1d0ac27e836 100644 --- a/libglusterfs/src/compat.h +++ b/libglusterfs/src/compat.h @@ -189,6 +189,9 @@ enum { #ifndef _PATH_UMOUNT #define _PATH_UMOUNT "/sbin/umount" #endif + +void gf_extattr_list_reshape(char *list, ssize_t size); + #endif /* GF_BSD_HOST_OS */ #ifdef GF_DARWIN_HOST_OS diff --git a/libglusterfs/src/syscall.c b/libglusterfs/src/syscall.c index a7d4402808d..3a3d5318baa 100644 --- a/libglusterfs/src/syscall.c +++ b/libglusterfs/src/syscall.c @@ -492,7 +492,10 @@ sys_llistxattr (const char *path, char *list, size_t size) #endif #ifdef GF_BSD_HOST_OS - return extattr_list_link (path, EXTATTR_NAMESPACE_USER, list, size); + ssize_t ret = extattr_list_link (path, EXTATTR_NAMESPACE_USER, + list, size); + gf_extattr_list_reshape (list, ret); + return ret; #endif #ifdef GF_SOLARIS_HOST_OS @@ -608,7 +611,10 @@ sys_flistxattr (int filedes, char *list, size_t size) #endif #ifdef GF_BSD_HOST_OS - return extattr_list_fd (filedes, EXTATTR_NAMESPACE_USER, list, size); + ssize_t ret = extattr_list_fd (filedes, EXTATTR_NAMESPACE_USER, + list, size); + gf_extattr_list_reshape (list, ret); + return ret; #endif #ifdef GF_SOLARIS_HOST_OS |