if (!test_opt(inode->i_sb, POSIX_ACL))
return 0;
- if (list && (size <= list_size))
+ if (list && size <= list_size)
memcpy(list, XATTR_NAME_ACL_ACCESS, size);
return size;
}
if (!test_opt(inode->i_sb, POSIX_ACL))
return 0;
- if (list && (size <= list_size))
+ if (list && size <= list_size)
memcpy(list, XATTR_NAME_ACL_DEFAULT, size);
return size;
}
{
struct buffer_head *bh = NULL;
struct ext2_xattr_entry *entry;
- size_t total_size = 0;
- char *buf, *end;
+ char *end;
+ size_t rest = buffer_size;
int error;
ea_idebug(inode, "buffer=%p, buffer_size=%ld",
goto cleanup;
}
+ /* check the on-disk data structure */
+ entry = FIRST_ENTRY(bh);
+ while (!IS_LAST_ENTRY(entry)) {
+ struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(entry);
+
+ if ((char *)next >= end)
+ goto bad_block;
+ entry = next;
+ }
if (ext2_xattr_cache_insert(bh))
ea_idebug(inode, "cache insert failed");
/* list the attribute names */
- buf = buffer;
for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
entry = EXT2_XATTR_NEXT(entry)) {
- struct xattr_handler *handler;
- struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(entry);
-
- if ((char *)next >= end)
- goto bad_block;
+ struct xattr_handler *handler =
+ ext2_xattr_handler(entry->e_name_index);
- handler = ext2_xattr_handler(entry->e_name_index);
if (handler) {
- size_t size = handler->list(inode, buf, buffer_size,
+ size_t size = handler->list(inode, buffer, rest,
entry->e_name,
entry->e_name_len);
- if (buf) {
- if (size > buffer_size) {
+ if (buffer) {
+ if (size > rest) {
error = -ERANGE;
goto cleanup;
}
- buf += size;
- buffer_size -= size;
+ buffer += size;
}
- total_size += size;
+ rest -= size;
}
}
- error = total_size;
+ error = buffer_size - rest; /* total size */
cleanup:
brelse(bh);
const int prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1;
const size_t total_len = prefix_len + name_len + 1;
- if (list && (total_len <= list_size)) {
+ if (list && total_len <= list_size) {
memcpy(list, XATTR_SECURITY_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
if (!capable(CAP_SYS_ADMIN))
return 0;
- if (list && (total_len <= list_size)) {
+ if (list && total_len <= list_size) {
memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
if (!test_opt(inode->i_sb, XATTR_USER))
return 0;
- if (list && (total_len <= list_size)) {
+ if (list && total_len <= list_size) {
memcpy(list, XATTR_USER_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
if (!test_opt(inode->i_sb, POSIX_ACL))
return 0;
- if (list && (size <= list_len))
+ if (list && size <= list_len)
memcpy(list, XATTR_NAME_ACL_ACCESS, size);
return size;
}
if (!test_opt(inode->i_sb, POSIX_ACL))
return 0;
- if (list && (size <= list_len))
+ if (list && size <= list_len)
memcpy(list, XATTR_NAME_ACL_DEFAULT, size);
return size;
}
{
struct buffer_head *bh = NULL;
struct ext3_xattr_entry *entry;
- size_t total_size = 0;
- char *buf, *end;
+ char *end;
+ size_t rest = buffer_size;
int error;
ea_idebug(inode, "buffer=%p, buffer_size=%ld",
goto cleanup;
}
+ /* check the on-disk data structure */
+ entry = FIRST_ENTRY(bh);
+ while (!IS_LAST_ENTRY(entry)) {
+ struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(entry);
+
+ if ((char *)next >= end)
+ goto bad_block;
+ entry = next;
+ }
if (ext3_xattr_cache_insert(bh))
ea_idebug(inode, "cache insert failed");
/* list the attribute names */
- buf = buffer;
for (entry = FIRST_ENTRY(bh); !IS_LAST_ENTRY(entry);
entry = EXT3_XATTR_NEXT(entry)) {
- struct xattr_handler *handler;
- struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(entry);
-
- if ((char *)next >= end)
- goto bad_block;
+ struct xattr_handler *handler =
+ ext3_xattr_handler(entry->e_name_index);
- handler = ext3_xattr_handler(entry->e_name_index);
if (handler) {
- size_t size = handler->list(inode, buf, buffer_size,
+ size_t size = handler->list(inode, buffer, rest,
entry->e_name,
entry->e_name_len);
- if (buf) {
- if (size > buffer_size) {
+ if (buffer) {
+ if (size > rest) {
error = -ERANGE;
goto cleanup;
}
- buf += size;
- buffer_size -= size;
+ buffer += size;
}
- total_size += size;
+ rest -= size;
}
}
- error = total_size;
+ error = buffer_size - rest; /* total size */
cleanup:
brelse(bh);
const size_t total_len = prefix_len + name_len + 1;
- if (list && (total_len <= list_size)) {
+ if (list && total_len <= list_size) {
memcpy(list, XATTR_SECURITY_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
if (!capable(CAP_SYS_ADMIN))
return 0;
- if (list && (total_len <= list_size)) {
+ if (list && total_len <= list_size) {
memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
if (!test_opt(inode->i_sb, XATTR_USER))
return 0;
- if (list && (total_len <= list_size)) {
+ if (list && total_len <= list_size) {
memcpy(list, XATTR_USER_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
}
-static const char *strcmp_prefix(const char *a, const char *a_prefix)
+static const char *
+strcmp_prefix(const char *a, const char *a_prefix)
{
while (*a_prefix && *a == *a_prefix) {
a++;