diff options
author | shishir gowda <shishirng@gluster.com> | 2011-09-22 12:53:55 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2011-09-22 05:26:22 -0700 |
commit | 53b5da6dfab2e6b11ab2e40119e92ff7d4527b2c (patch) | |
tree | c0c6bd85808745b33cf2184e10cf27c24d980280 /xlators | |
parent | eede6ce87fc19878873e8320c172d1acb2deaa33 (diff) |
posix-getxattr: Honor xattr name if specified
Currently, getxattr works like listxattr, and does not honor a call
with a name (key) being specified. The fix handles such scenarios when
a name is passed. If the name param is NULL, then it behaves like a listxattr.
Changing key size to 4096, as 1024 might not be sufficient length for keys.
Change-Id: I317b2e6372e97048e3166d91145c19c9e92e647e
BUG: 3599
Reviewed-on: http://review.gluster.com/486
Reviewed-by: Amar Tumballi <amar@gluster.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/storage/posix/src/posix.c | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 7a9bdbcb9..1a5a52336 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -2490,7 +2490,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, int32_t list_offset = 0; size_t size = 0; size_t remaining_size = 0; - char key[1024] = {0,}; + char key[4096] = {0,}; char host_buf[1024] = {0,}; char * value = NULL; char * list = NULL; @@ -2560,6 +2560,29 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, goto done; } + if (name) { + strcpy (key, name); + + size = sys_lgetxattr (real_path, key, NULL, 0); + value = GF_CALLOC (size + 1, sizeof(char), gf_posix_mt_char); + if (!value) { + op_ret = -1; + goto out; + } + op_ret = sys_lgetxattr (real_path, key, value, op_ret); + if (op_ret == -1) { + op_errno = errno; + goto out; + } + value [op_ret] = '\0'; + op_ret = dict_set_dynptr (dict, key, value, op_ret); + if (op_ret < 0) { + goto out; + } + + goto done; + } + size = sys_llistxattr (real_path, NULL, 0); if (size == -1) { op_errno = errno; @@ -2613,7 +2636,10 @@ posix_getxattr (call_frame_t *frame, xlator_t *this, } value [op_ret] = '\0'; - dict_set (dict, key, data_from_dynptr (value, op_ret)); + op_ret = dict_set_dynptr (dict, key, value, op_ret); + if (op_ret < 0) { + goto out; + } remaining_size -= strlen (key) + 1; list_offset += strlen (key) + 1; @@ -2652,7 +2678,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, int32_t list_offset = 0; size_t size = 0; size_t remaining_size = 0; - char key[1024] = {0,}; + char key[4096] = {0,}; char * value = NULL; char * list = NULL; dict_t * dict = NULL; @@ -2692,6 +2718,28 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, goto done; } + if (name) { + strcpy (key, name); + + size = sys_fgetxattr (_fd, key, NULL, 0); + value = GF_CALLOC (size + 1, sizeof(char), gf_posix_mt_char); + if (!value) { + op_ret = -1; + goto out; + } + op_ret = sys_fgetxattr (_fd, key, value, op_ret); + if (op_ret == -1) { + op_errno = errno; + goto out; + } + value [op_ret] = '\0'; + op_ret = dict_set_dynptr (dict, key, value, op_ret); + if (op_ret < 0) { + goto out; + } + goto done; + } + size = sys_flistxattr (_fd, NULL, 0); if (size == -1) { op_errno = errno; @@ -2743,7 +2791,10 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this, break; value [op_ret] = '\0'; - dict_set (dict, key, data_from_dynptr (value, op_ret)); + op_ret = dict_set_dynptr (dict, key, value, op_ret); + if (op_ret) { + goto out; + } remaining_size -= strlen (key) + 1; list_offset += strlen (key) + 1; |