ref: dc8cbeb1b0b44d8070630b71a5cd0385fd94c17d
parent: afdb70bf2ee7d570e34fda6c9fdec9ea42edcca8
author: root <[email protected]>
date: Thu Oct 8 12:11:39 EDT 2015
Do clang-format against ext4_xattr.c and ext4_xattr.h
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -63,9 +63,8 @@
#define NAME_HASH_SHIFT 5
#define VALUE_HASH_SHIFT 16
-static inline void
-ext4_xattr_compute_hash(struct ext4_xattr_header *header,
- struct ext4_xattr_entry *entry)
+static inline void ext4_xattr_compute_hash(struct ext4_xattr_header *header,
+ struct ext4_xattr_entry *entry)
{
uint32_t hash = 0;
char *name = EXT4_XATTR_NAME(entry);
@@ -73,18 +72,18 @@
for (n = 0; n < entry->e_name_len; n++) {
hash = (hash << NAME_HASH_SHIFT) ^
- (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^
- *name++;
+ (hash >> (8 * sizeof(hash) - NAME_HASH_SHIFT)) ^ *name++;
}
if (entry->e_value_block == 0 && entry->e_value_size != 0) {
- uint32_t *value = (uint32_t *)((char *)header +
- to_le16(entry->e_value_offs));
- for (n = (to_le32(entry->e_value_size) +
- EXT4_XATTR_ROUND) >> EXT4_XATTR_PAD_BITS; n; n--) {
+ uint32_t *value =
+ (uint32_t *)((char *)header + to_le16(entry->e_value_offs));
+ for (n = (to_le32(entry->e_value_size) + EXT4_XATTR_ROUND) >>
+ EXT4_XATTR_PAD_BITS;
+ n; n--) {
hash = (hash << VALUE_HASH_SHIFT) ^
- (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
- to_le32(*value++);
+ (hash >> (8 * sizeof(hash) - VALUE_HASH_SHIFT)) ^
+ to_le32(*value++);
}
}
entry->e_hash = to_le32(hash);
@@ -104,7 +103,7 @@
uint32_t hash = 0;
ext4_xattr_compute_hash(header, entry);
- here = EXT4_XATTR_ENTRY(header+1);
+ here = EXT4_XATTR_ENTRY(header + 1);
while (!EXT4_XATTR_IS_LAST_ENTRY(here)) {
if (!here->e_hash) {
/* Block is not shared if an entry's hash value == 0 */
@@ -112,7 +111,7 @@
break;
}
hash = (hash << BLOCK_HASH_SHIFT) ^
- (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
+ (hash >> (8 * sizeof(hash) - BLOCK_HASH_SHIFT)) ^
to_le32(here->e_hash);
here = EXT4_XATTR_NEXT(here);
}
@@ -120,7 +119,7 @@
}
static int ext4_xattr_item_cmp(struct ext4_xattr_item *a,
- struct ext4_xattr_item *b)
+ struct ext4_xattr_item *b)
{
int result;
result = a->name_index - b->name_index;
@@ -134,29 +133,23 @@
return memcmp(a->name, b->name, a->name_len);
}
-RB_GENERATE_INTERNAL(ext4_xattr_tree,
- ext4_xattr_item,
- node,
- ext4_xattr_item_cmp,
- static inline)
+RB_GENERATE_INTERNAL(ext4_xattr_tree, ext4_xattr_item, node,
+ ext4_xattr_item_cmp, static inline)
static struct ext4_xattr_item *
-ext4_xattr_item_alloc(uint8_t name_index,
- char *name,
- size_t name_len)
+ext4_xattr_item_alloc(uint8_t name_index, char *name, size_t name_len)
{
struct ext4_xattr_item *item;
- item = malloc(sizeof(struct ext4_xattr_item) +
- name_len);
+ item = malloc(sizeof(struct ext4_xattr_item) + name_len);
if (!item)
return NULL;
item->name_index = name_index;
- item->name = (char *)(item + 1);
- item->name_len = name_len;
- item->data = NULL;
- item->data_size = 0;
-
+ item->name = (char *)(item + 1);
+ item->name_len = name_len;
+ item->data = NULL;
+ item->data_size = 0;
+
memset(&item->node, 0, sizeof(item->node));
memcpy(item->name, name, name_len);
@@ -163,10 +156,8 @@
return item;
}
-static int
-ext4_xattr_item_alloc_data(struct ext4_xattr_item *item,
- void *orig_data,
- size_t data_size)
+static int ext4_xattr_item_alloc_data(struct ext4_xattr_item *item,
+ void *orig_data, size_t data_size)
{
void *data = NULL;
ext4_assert(!item->data);
@@ -182,8 +173,7 @@
return EOK;
}
-static void
-ext4_xattr_item_free_data(struct ext4_xattr_item *item)
+static void ext4_xattr_item_free_data(struct ext4_xattr_item *item)
{
ext4_assert(item->data);
free(item->data);
@@ -191,9 +181,8 @@
item->data_size = 0;
}
-static int
-ext4_xattr_item_resize_data(struct ext4_xattr_item *item,
- size_t new_data_size)
+static int ext4_xattr_item_resize_data(struct ext4_xattr_item *item,
+ size_t new_data_size)
{
if (new_data_size != item->data_size) {
void *new_data;
@@ -207,8 +196,7 @@
return EOK;
}
-static void
-ext4_xattr_item_free(struct ext4_xattr_item *item)
+static void ext4_xattr_item_free(struct ext4_xattr_item *item)
{
if (item->data)
ext4_xattr_item_free_data(item);
@@ -216,7 +204,6 @@
free(item);
}
-
static void *ext4_xattr_entry_data(struct ext4_xattr_ref *xattr_ref,
struct ext4_xattr_entry *entry,
bool in_inode)
@@ -225,24 +212,26 @@
if (in_inode) {
struct ext4_xattr_ibody_header *header;
struct ext4_xattr_entry *first_entry;
- uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb,
- inode_size);
+ uint16_t inode_size =
+ ext4_get16(&xattr_ref->fs->sb, inode_size);
header = EXT4_XATTR_IHDR(xattr_ref->inode_ref->inode);
first_entry = EXT4_XATTR_IFIRST(header);
-
- ret = (void *)((char *)first_entry + to_le16(entry->e_value_offs));
- if ((char *)ret + EXT4_XATTR_SIZE(to_le32(entry->e_value_size))
- - (char *)xattr_ref->inode_ref->inode >
+
+ ret = (void *)((char *)first_entry +
+ to_le16(entry->e_value_offs));
+ if ((char *)ret +
+ EXT4_XATTR_SIZE(to_le32(entry->e_value_size)) -
+ (char *)xattr_ref->inode_ref->inode >
inode_size)
ret = NULL;
} else {
- int32_t block_size =
- ext4_sb_get_block_size(&xattr_ref->fs->sb);
- ret = (void *)((char *)xattr_ref->block.data +
- to_le16(entry->e_value_offs));
- if ((char *)ret + EXT4_XATTR_SIZE(to_le32(entry->e_value_size))
- - (char *)xattr_ref->block.data >
+ int32_t block_size = ext4_sb_get_block_size(&xattr_ref->fs->sb);
+ ret = (void *)((char *)xattr_ref->block.data +
+ to_le16(entry->e_value_offs));
+ if ((char *)ret +
+ EXT4_XATTR_SIZE(to_le32(entry->e_value_size)) -
+ (char *)xattr_ref->block.data >
block_size)
ret = NULL;
}
@@ -260,30 +249,26 @@
entry = EXT4_XATTR_BFIRST(&xattr_ref->block);
size_rem = ext4_sb_get_block_size(&xattr_ref->fs->sb);
- for(;size_rem > 0 && !EXT4_XATTR_IS_LAST_ENTRY(entry);
- entry = EXT4_XATTR_NEXT(entry),
- size_rem -= EXT4_XATTR_LEN(entry->e_name_len)) {
+ for (; size_rem > 0 && !EXT4_XATTR_IS_LAST_ENTRY(entry);
+ entry = EXT4_XATTR_NEXT(entry),
+ size_rem -= EXT4_XATTR_LEN(entry->e_name_len)) {
struct ext4_xattr_item *item;
char *e_name = EXT4_XATTR_NAME(entry);
- data = ext4_xattr_entry_data(xattr_ref, entry,
- false);
+ data = ext4_xattr_entry_data(xattr_ref, entry, false);
if (!data) {
ret = EIO;
goto Finish;
}
- item = ext4_xattr_item_alloc(entry->e_name_index,
- e_name,
+ item = ext4_xattr_item_alloc(entry->e_name_index, e_name,
(size_t)entry->e_name_len);
if (!item) {
ret = ENOMEM;
goto Finish;
}
- if (ext4_xattr_item_alloc_data(item,
- data,
- to_le32(entry->e_value_size))
- != EOK) {
+ if (ext4_xattr_item_alloc_data(
+ item, data, to_le32(entry->e_value_size)) != EOK) {
ext4_xattr_item_free(item);
ret = ENOMEM;
goto Finish;
@@ -290,7 +275,7 @@
}
RB_INSERT(ext4_xattr_tree, &xattr_ref->root, item);
xattr_ref->ea_size += EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_LEN(item->name_len);
+ EXT4_XATTR_LEN(item->name_len);
}
Finish:
@@ -304,39 +289,33 @@
int ret = EOK;
struct ext4_xattr_ibody_header *header = NULL;
struct ext4_xattr_entry *entry = NULL;
- uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb,
- inode_size);
+ uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb, inode_size);
header = EXT4_XATTR_IHDR(xattr_ref->inode_ref->inode);
entry = EXT4_XATTR_IFIRST(header);
- size_rem = inode_size -
- EXT4_GOOD_OLD_INODE_SIZE -
- xattr_ref->inode_ref->inode->extra_isize;
- for(;size_rem > 0 && !EXT4_XATTR_IS_LAST_ENTRY(entry);
- entry = EXT4_XATTR_NEXT(entry),
- size_rem -= EXT4_XATTR_LEN(entry->e_name_len)) {
+ size_rem = inode_size - EXT4_GOOD_OLD_INODE_SIZE -
+ xattr_ref->inode_ref->inode->extra_isize;
+ for (; size_rem > 0 && !EXT4_XATTR_IS_LAST_ENTRY(entry);
+ entry = EXT4_XATTR_NEXT(entry),
+ size_rem -= EXT4_XATTR_LEN(entry->e_name_len)) {
struct ext4_xattr_item *item;
char *e_name = EXT4_XATTR_NAME(entry);
- data = ext4_xattr_entry_data(xattr_ref, entry,
- true);
+ data = ext4_xattr_entry_data(xattr_ref, entry, true);
if (!data) {
ret = EIO;
goto Finish;
}
- item = ext4_xattr_item_alloc(entry->e_name_index,
- e_name,
+ item = ext4_xattr_item_alloc(entry->e_name_index, e_name,
(size_t)entry->e_name_len);
if (!item) {
ret = ENOMEM;
goto Finish;
}
- if (ext4_xattr_item_alloc_data(item,
- data,
- to_le32(entry->e_value_size))
- != EOK) {
+ if (ext4_xattr_item_alloc_data(
+ item, data, to_le32(entry->e_value_size)) != EOK) {
ext4_xattr_item_free(item);
ret = ENOMEM;
goto Finish;
@@ -343,7 +322,7 @@
}
RB_INSERT(ext4_xattr_tree, &xattr_ref->root, item);
xattr_ref->ea_size += EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_LEN(item->name_len);
+ EXT4_XATTR_LEN(item->name_len);
}
Finish:
@@ -350,20 +329,15 @@
return ret;
}
-
-static size_t
-ext4_xattr_inode_space(struct ext4_xattr_ref *xattr_ref)
+static size_t ext4_xattr_inode_space(struct ext4_xattr_ref *xattr_ref)
{
- uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb,
- inode_size);
- uint16_t size_rem = inode_size -
- EXT4_GOOD_OLD_INODE_SIZE -
- xattr_ref->inode_ref->inode->extra_isize;
+ uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb, inode_size);
+ uint16_t size_rem = inode_size - EXT4_GOOD_OLD_INODE_SIZE -
+ xattr_ref->inode_ref->inode->extra_isize;
return size_rem;
}
-static size_t
-ext4_xattr_block_space(struct ext4_xattr_ref *xattr_ref)
+static size_t ext4_xattr_block_space(struct ext4_xattr_ref *xattr_ref)
{
return ext4_sb_get_block_size(&xattr_ref->fs->sb);
}
@@ -371,13 +345,11 @@
static int ext4_xattr_fetch(struct ext4_xattr_ref *xattr_ref)
{
int ret = EOK;
- uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb,
- inode_size);
+ uint16_t inode_size = ext4_get16(&xattr_ref->fs->sb, inode_size);
if (inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
ret = ext4_xattr_inode_fetch(xattr_ref);
if (ret != EOK)
return ret;
-
}
if (xattr_ref->block_loaded)
@@ -388,77 +360,61 @@
}
static struct ext4_xattr_item *
-ext4_xattr_lookup_item(struct ext4_xattr_ref *xattr_ref,
- uint8_t name_index,
- char *name,
- size_t name_len)
+ext4_xattr_lookup_item(struct ext4_xattr_ref *xattr_ref, uint8_t name_index,
+ char *name, size_t name_len)
{
struct ext4_xattr_item tmp, *ret;
tmp.name_index = name_index;
- tmp.name = name;
- tmp.name_len = name_len;
- ret = RB_FIND(ext4_xattr_tree, &xattr_ref->root,
- &tmp);
+ tmp.name = name;
+ tmp.name_len = name_len;
+ ret = RB_FIND(ext4_xattr_tree, &xattr_ref->root, &tmp);
return ret;
}
static struct ext4_xattr_item *
-ext4_xattr_insert_item(struct ext4_xattr_ref *xattr_ref,
- uint8_t name_index,
- char *name,
- size_t name_len,
- void *data,
- size_t data_size)
+ext4_xattr_insert_item(struct ext4_xattr_ref *xattr_ref, uint8_t name_index,
+ char *name, size_t name_len, void *data,
+ size_t data_size)
{
struct ext4_xattr_item *item;
- item = ext4_xattr_item_alloc(name_index,
- name,
- name_len);
+ item = ext4_xattr_item_alloc(name_index, name, name_len);
if (!item)
return NULL;
if (xattr_ref->ea_size + EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_LEN(item->name_len) >
- ext4_xattr_inode_space(xattr_ref) +
+ EXT4_XATTR_LEN(item->name_len) >
+ ext4_xattr_inode_space(xattr_ref) +
ext4_xattr_block_space(xattr_ref)) {
ext4_xattr_item_free(item);
return NULL;
}
- if (ext4_xattr_item_alloc_data(item,
- data,
- data_size) != EOK) {
+ if (ext4_xattr_item_alloc_data(item, data, data_size) != EOK) {
ext4_xattr_item_free(item);
return NULL;
}
RB_INSERT(ext4_xattr_tree, &xattr_ref->root, item);
- xattr_ref->ea_size += EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_LEN(item->name_len);
+ xattr_ref->ea_size +=
+ EXT4_XATTR_SIZE(item->data_size) + EXT4_XATTR_LEN(item->name_len);
xattr_ref->dirty = true;
return item;
}
-static int
-ext4_xattr_remove_item(struct ext4_xattr_ref *xattr_ref,
- uint8_t name_index,
- char *name,
- size_t name_len)
+static int ext4_xattr_remove_item(struct ext4_xattr_ref *xattr_ref,
+ uint8_t name_index, char *name,
+ size_t name_len)
{
int ret = ENOENT;
- struct ext4_xattr_item *item =
- ext4_xattr_lookup_item(xattr_ref,
- name_index,
- name,
- name_len);
+ struct ext4_xattr_item *item =
+ ext4_xattr_lookup_item(xattr_ref, name_index, name, name_len);
if (item) {
if (item == xattr_ref->iter_from)
- xattr_ref->iter_from = RB_NEXT(ext4_xattr_tree,
- &xattr_ref->root,
- item);
+ xattr_ref->iter_from =
+ RB_NEXT(ext4_xattr_tree, &xattr_ref->root, item);
RB_REMOVE(ext4_xattr_tree, &xattr_ref->root, item);
ext4_xattr_item_free(item);
xattr_ref->ea_size -= EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_LEN(item->name_len);
+ EXT4_XATTR_LEN(item->name_len);
xattr_ref->dirty = true;
ret = EOK;
}
@@ -465,40 +421,35 @@
return ret;
}
-static int
-ext4_xattr_resize_item(struct ext4_xattr_ref *xattr_ref,
- struct ext4_xattr_item *item,
- size_t new_data_size)
+static int ext4_xattr_resize_item(struct ext4_xattr_ref *xattr_ref,
+ struct ext4_xattr_item *item,
+ size_t new_data_size)
{
int ret = EOK;
if (xattr_ref->ea_size - EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_SIZE(new_data_size) >
- ext4_xattr_inode_space(xattr_ref) +
+ EXT4_XATTR_SIZE(new_data_size) >
+ ext4_xattr_inode_space(xattr_ref) +
ext4_xattr_block_space(xattr_ref)) {
return ENOSPC;
}
- ret = ext4_xattr_item_resize_data(item,
- new_data_size);
+ ret = ext4_xattr_item_resize_data(item, new_data_size);
if (ret != EOK) {
return ret;
}
- xattr_ref->ea_size -= EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_SIZE(new_data_size);
+ xattr_ref->ea_size -=
+ EXT4_XATTR_SIZE(item->data_size) + EXT4_XATTR_SIZE(new_data_size);
xattr_ref->dirty = true;
return ret;
}
-static void
-ext4_xattr_purge_items(struct ext4_xattr_ref *xattr_ref)
+static void ext4_xattr_purge_items(struct ext4_xattr_ref *xattr_ref)
{
struct ext4_xattr_item *item, *save_item;
- uint64_t xattr_block = ext4_inode_get_file_acl(xattr_ref->inode_ref->inode,
- &xattr_ref->fs->sb);
- RB_FOREACH_SAFE(item,
- ext4_xattr_tree,
- &xattr_ref->root,
- save_item) {
+ uint64_t xattr_block = ext4_inode_get_file_acl(
+ xattr_ref->inode_ref->inode, &xattr_ref->fs->sb);
+ RB_FOREACH_SAFE(item, ext4_xattr_tree, &xattr_ref->root, save_item)
+ {
RB_REMOVE(ext4_xattr_tree, &xattr_ref->root, item);
ext4_xattr_item_free(item);
}
@@ -511,9 +462,7 @@
xattr_ref->ea_size += sizeof(struct ext4_xattr_ibody_header);
}
-
-static int
-ext4_xattr_try_alloc_block(struct ext4_xattr_ref *xattr_ref)
+static int ext4_xattr_try_alloc_block(struct ext4_xattr_ref *xattr_ref)
{
int ret = EOK;
@@ -522,22 +471,20 @@
&xattr_ref->fs->sb);
if (!xattr_block) {
ret = ext4_balloc_alloc_block(xattr_ref->inode_ref,
- (uint32_t *)&xattr_block);
+ (uint32_t *)&xattr_block);
if (ret != EOK)
goto Finish;
- ret = ext4_block_get(xattr_ref->fs->bdev,
- &xattr_ref->block,
- xattr_block);
+ ret = ext4_block_get(xattr_ref->fs->bdev, &xattr_ref->block,
+ xattr_block);
if (ret != EOK) {
ext4_balloc_free_block(xattr_ref->inode_ref,
- xattr_block);
+ xattr_block);
goto Finish;
}
ext4_inode_set_file_acl(xattr_ref->inode_ref->inode,
- &xattr_ref->fs->sb,
- xattr_block);
+ &xattr_ref->fs->sb, xattr_block);
xattr_ref->inode_ref->dirty = true;
xattr_ref->block_loaded = true;
xattr_ref->ea_size += sizeof(struct ext4_xattr_header);
@@ -547,27 +494,21 @@
return ret;
}
-static void
-ext4_xattr_try_free_block(struct ext4_xattr_ref *xattr_ref)
+static void ext4_xattr_try_free_block(struct ext4_xattr_ref *xattr_ref)
{
uint64_t xattr_block;
- xattr_block =
- ext4_inode_get_file_acl(xattr_ref->inode_ref->inode,
- &xattr_ref->fs->sb);
- ext4_inode_set_file_acl(xattr_ref->inode_ref->inode,
- &xattr_ref->fs->sb,
- 0);
- ext4_block_set(xattr_ref->fs->bdev,
- &xattr_ref->block);
- ext4_balloc_free_block(xattr_ref->inode_ref,
- xattr_block);
+ xattr_block = ext4_inode_get_file_acl(xattr_ref->inode_ref->inode,
+ &xattr_ref->fs->sb);
+ ext4_inode_set_file_acl(xattr_ref->inode_ref->inode, &xattr_ref->fs->sb,
+ 0);
+ ext4_block_set(xattr_ref->fs->bdev, &xattr_ref->block);
+ ext4_balloc_free_block(xattr_ref->inode_ref, xattr_block);
xattr_ref->inode_ref->dirty = true;
xattr_ref->block_loaded = false;
xattr_ref->ea_size -= sizeof(struct ext4_xattr_header);
}
-static void
-ext4_xattr_set_block_header(struct ext4_xattr_ref *xattr_ref)
+static void ext4_xattr_set_block_header(struct ext4_xattr_ref *xattr_ref)
{
struct ext4_xattr_header *block_header = NULL;
block_header = EXT4_XATTR_BHDR(&xattr_ref->block);
@@ -581,34 +522,30 @@
static void
ext4_xattr_set_inode_entry(struct ext4_xattr_item *item,
struct ext4_xattr_ibody_header *ibody_header,
- struct ext4_xattr_entry *entry,
- void *ibody_data_ptr)
+ struct ext4_xattr_entry *entry, void *ibody_data_ptr)
{
- entry->e_name_len = to_le32(item->name_len);
+ entry->e_name_len = to_le32(item->name_len);
entry->e_name_index = item->name_index;
entry->e_value_offs =
- (char *)ibody_data_ptr -
- (char *)EXT4_XATTR_IFIRST(ibody_header);
+ (char *)ibody_data_ptr - (char *)EXT4_XATTR_IFIRST(ibody_header);
entry->e_value_block = 0;
entry->e_value_size = item->data_size;
}
-static void
-ext4_xattr_set_block_entry(struct ext4_xattr_item *item,
- struct ext4_xattr_header *block_header,
- struct ext4_xattr_entry *block_entry,
- void *block_data_ptr)
+static void ext4_xattr_set_block_entry(struct ext4_xattr_item *item,
+ struct ext4_xattr_header *block_header,
+ struct ext4_xattr_entry *block_entry,
+ void *block_data_ptr)
{
- block_entry->e_name_len = to_le32(item->name_len);
+ block_entry->e_name_len = to_le32(item->name_len);
block_entry->e_name_index = item->name_index;
block_entry->e_value_offs =
- (char *)block_data_ptr - (char *)block_header;
+ (char *)block_data_ptr - (char *)block_header;
block_entry->e_value_block = 0;
block_entry->e_value_size = item->data_size;
}
-static int
-ext4_xattr_write_to_disk(struct ext4_xattr_ref *xattr_ref)
+static int ext4_xattr_write_to_disk(struct ext4_xattr_ref *xattr_ref)
{
int ret = EOK;
bool block_modified = false;
@@ -633,7 +570,8 @@
memset(ibody_header, 0, inode_size_rem);
ibody_header->h_magic = EXT4_XATTR_MAGIC;
ibody_data = (char *)ibody_header + inode_size_rem;
- inode_size_rem -= sizeof(struct ext4_xattr_ibody_header);
+ inode_size_rem -=
+ sizeof(struct ext4_xattr_ibody_header);
xattr_ref->inode_ref->dirty = true;
}
@@ -643,7 +581,6 @@
ret = ext4_xattr_try_alloc_block(xattr_ref);
if (ret != EOK)
goto Finish;
-
}
block_header = EXT4_XATTR_BHDR(&xattr_ref->block);
block_entry = EXT4_XATTR_BFIRST(&xattr_ref->block);
@@ -655,19 +592,23 @@
} else {
/* We don't need an extra block.*/
if (xattr_ref->block_loaded) {
- block_header = EXT4_XATTR_BHDR(&xattr_ref->block);
- block_header->h_refcount =
- to_le32(to_le32(block_header->h_refcount) - 1);
+ block_header =
+ EXT4_XATTR_BHDR(&xattr_ref->block);
+ block_header->h_refcount = to_le32(
+ to_le32(block_header->h_refcount) - 1);
if (!block_header->h_refcount) {
ext4_xattr_try_free_block(xattr_ref);
block_header = NULL;
} else {
- block_entry = EXT4_XATTR_BFIRST(&xattr_ref->block);
- block_data = (char *)block_header + block_size_rem;
- block_size_rem -= sizeof(struct ext4_xattr_header);
- ext4_inode_set_file_acl(xattr_ref->inode_ref->inode,
- &xattr_ref->fs->sb,
- 0);
+ block_entry = EXT4_XATTR_BFIRST(
+ &xattr_ref->block);
+ block_data = (char *)block_header +
+ block_size_rem;
+ block_size_rem -=
+ sizeof(struct ext4_xattr_header);
+ ext4_inode_set_file_acl(
+ xattr_ref->inode_ref->inode,
+ &xattr_ref->fs->sb, 0);
xattr_ref->inode_ref->dirty = true;
xattr_ref->block.dirty = true;
@@ -674,49 +615,43 @@
}
}
}
- RB_FOREACH_SAFE(item,
- ext4_xattr_tree,
- &xattr_ref->root,
- save_item) {
+ RB_FOREACH_SAFE(item, ext4_xattr_tree, &xattr_ref->root,
+ save_item)
+ {
if (EXT4_XATTR_SIZE(item->data_size) +
EXT4_XATTR_LEN(item->name_len) <=
inode_size_rem) {
ibody_data = (char *)ibody_data -
- EXT4_XATTR_SIZE(item->data_size);
- ext4_xattr_set_inode_entry(item,
- ibody_header,
- entry,
- ibody_data);
- memcpy(EXT4_XATTR_NAME(entry),
- item->name, item->name_len);
+ EXT4_XATTR_SIZE(item->data_size);
+ ext4_xattr_set_inode_entry(item, ibody_header,
+ entry, ibody_data);
+ memcpy(EXT4_XATTR_NAME(entry), item->name,
+ item->name_len);
memcpy(ibody_data, item->data, item->data_size);
entry = EXT4_XATTR_NEXT(entry);
inode_size_rem -=
- EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_LEN(item->name_len);
+ EXT4_XATTR_SIZE(item->data_size) +
+ EXT4_XATTR_LEN(item->name_len);
xattr_ref->inode_ref->dirty = true;
continue;
}
if (EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_LEN(item->name_len) > block_size_rem) {
+ EXT4_XATTR_LEN(item->name_len) >
+ block_size_rem) {
ret = ENOSPC;
goto Finish;
}
block_data = (char *)block_data -
- EXT4_XATTR_SIZE(item->data_size);
- ext4_xattr_set_block_entry(item,
- block_header,
- block_entry,
- block_data);
- memcpy(EXT4_XATTR_NAME(block_entry),
- item->name, item->name_len);
- memcpy(block_data,
- item->data, item->data_size);
+ EXT4_XATTR_SIZE(item->data_size);
+ ext4_xattr_set_block_entry(item, block_header,
+ block_entry, block_data);
+ memcpy(EXT4_XATTR_NAME(block_entry), item->name,
+ item->name_len);
+ memcpy(block_data, item->data, item->data_size);
block_entry = EXT4_XATTR_NEXT(block_entry);
- block_size_rem -=
- EXT4_XATTR_SIZE(item->data_size) +
- EXT4_XATTR_LEN(item->name_len);
+ block_size_rem -= EXT4_XATTR_SIZE(item->data_size) +
+ EXT4_XATTR_LEN(item->name_len);
block_modified = true;
}
@@ -732,18 +667,16 @@
return ret;
}
-void
-ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
- int (iter)(struct ext4_xattr_ref *ref,
- struct ext4_xattr_item *item))
+void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
+ int(iter)(struct ext4_xattr_ref *ref,
+ struct ext4_xattr_item *item))
{
struct ext4_xattr_item *item;
if (!ref->iter_from)
ref->iter_from = RB_MIN(ext4_xattr_tree, &ref->root);
- RB_FOREACH_FROM(item,
- ext4_xattr_tree,
- ref->iter_from) {
+ RB_FOREACH_FROM(item, ext4_xattr_tree, ref->iter_from)
+ {
int ret = EXT4_XATTR_ITERATE_CONT;
if (iter)
iter(ref, item);
@@ -762,20 +695,13 @@
ref->iter_from = NULL;
}
-int ext4_fs_set_xattr(struct ext4_xattr_ref *ref,
- uint8_t name_index,
- char *name,
- size_t name_len,
- void *data,
- size_t data_size,
- bool replace)
+int ext4_fs_set_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
+ char *name, size_t name_len, void *data, size_t data_size,
+ bool replace)
{
int ret = EOK;
- struct ext4_xattr_item *item =
- ext4_xattr_lookup_item(ref,
- name_index,
- name,
- name_len);
+ struct ext4_xattr_item *item =
+ ext4_xattr_lookup_item(ref, name_index, name, name_len);
if (replace) {
if (!item) {
ret = ENOATTR;
@@ -782,9 +708,7 @@
goto Finish;
}
if (item->data_size != data_size)
- ret = ext4_xattr_resize_item(ref,
- item,
- data_size);
+ ret = ext4_xattr_resize_item(ref, item, data_size);
if (ret != EOK) {
goto Finish;
@@ -795,46 +719,29 @@
ret = EEXIST;
goto Finish;
}
- item = ext4_xattr_insert_item(ref,
- name_index,
- name,
- name_len,
- data,
- data_size);
+ item = ext4_xattr_insert_item(ref, name_index, name, name_len,
+ data, data_size);
if (!item)
ret = ENOMEM;
-
}
Finish:
return ret;
}
-int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref,
- uint8_t name_index,
- char *name,
- size_t name_len)
+int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
+ char *name, size_t name_len)
{
- return ext4_xattr_remove_item(ref,
- name_index,
- name,
- name_len);
+ return ext4_xattr_remove_item(ref, name_index, name, name_len);
}
-int ext4_fs_get_xattr(struct ext4_xattr_ref *ref,
- uint8_t name_index,
- char *name,
- size_t name_len,
- void *buf,
- size_t buf_size,
- size_t *size_got)
+int ext4_fs_get_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
+ char *name, size_t name_len, void *buf, size_t buf_size,
+ size_t *size_got)
{
int ret = EOK;
size_t item_size = 0;
- struct ext4_xattr_item *item =
- ext4_xattr_lookup_item(ref,
- name_index,
- name,
- name_len);
+ struct ext4_xattr_item *item =
+ ext4_xattr_lookup_item(ref, name_index, name, name_len);
if (!item) {
ret = ENOATTR;
@@ -854,23 +761,20 @@
return ret;
}
-int ext4_fs_get_xattr_ref(struct ext4_fs *fs,
- struct ext4_inode_ref *inode_ref,
+int ext4_fs_get_xattr_ref(struct ext4_fs *fs, struct ext4_inode_ref *inode_ref,
struct ext4_xattr_ref *ref)
{
int rc;
uint64_t xattr_block;
- xattr_block = ext4_inode_get_file_acl(inode_ref->inode,
- &fs->sb);
+ xattr_block = ext4_inode_get_file_acl(inode_ref->inode, &fs->sb);
RB_INIT(&ref->root);
ref->ea_size = 0;
ref->iter_from = NULL;
if (xattr_block) {
- rc = ext4_block_get(fs->bdev,
- &ref->block, xattr_block);
+ rc = ext4_block_get(fs->bdev, &ref->block, xattr_block);
if (rc != EOK)
return EIO;
-
+
ref->ea_size += sizeof(struct ext4_xattr_header);
ref->block_loaded = true;
} else
@@ -908,20 +812,18 @@
}
struct xattr_prefix {
- char *prefix;
- uint8_t name_index;
-} prefix_tbl [] = {
- {"user.", EXT4_XATTR_INDEX_USER},
- {"system.", EXT4_XATTR_INDEX_SYSTEM},
- {"system.posix_acl_access", EXT4_XATTR_INDEX_POSIX_ACL_ACCESS},
- {"system.posix_acl_default", EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT},
- {NULL, 0},
+ char *prefix;
+ uint8_t name_index;
+} prefix_tbl[] = {
+ {"user.", EXT4_XATTR_INDEX_USER},
+ {"system.", EXT4_XATTR_INDEX_SYSTEM},
+ {"system.posix_acl_access", EXT4_XATTR_INDEX_POSIX_ACL_ACCESS},
+ {"system.posix_acl_default", EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT},
+ {NULL, 0},
};
-char *ext4_extract_xattr_name(char *full_name,
- size_t full_name_len,
- uint8_t *name_index,
- size_t *name_len)
+char *ext4_extract_xattr_name(char *full_name, size_t full_name_len,
+ uint8_t *name_index, size_t *name_len)
{
int i;
ext4_assert(name_index);
@@ -928,15 +830,13 @@
if (!full_name_len)
return NULL;
- for (i = 0;prefix_tbl[i].prefix;i++) {
+ for (i = 0; prefix_tbl[i].prefix; i++) {
size_t prefix_len = strlen(prefix_tbl[i].prefix);
if (full_name_len >= prefix_len &&
- !memcmp(full_name,
- prefix_tbl[i].prefix, prefix_len)) {
+ !memcmp(full_name, prefix_tbl[i].prefix, prefix_len)) {
*name_index = prefix_tbl[i].name_index;
if (name_len)
- *name_len = full_name_len -
- prefix_len;
+ *name_len = full_name_len - prefix_len;
return full_name + prefix_len;
}
--- a/lwext4/ext4_xattr.h
+++ b/lwext4/ext4_xattr.h
@@ -4,43 +4,29 @@
#include "ext4_config.h"
#include "ext4_types.h"
-int ext4_fs_get_xattr_ref(struct ext4_fs *fs,
- struct ext4_inode_ref *inode_ref,
+int ext4_fs_get_xattr_ref(struct ext4_fs *fs, struct ext4_inode_ref *inode_ref,
struct ext4_xattr_ref *ref);
void ext4_fs_put_xattr_ref(struct ext4_xattr_ref *ref);
-int ext4_fs_set_xattr(struct ext4_xattr_ref *ref,
- uint8_t name_index,
- char *name,
- size_t name_len,
- void *data,
- size_t data_size,
- bool replace);
+int ext4_fs_set_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
+ char *name, size_t name_len, void *data, size_t data_size,
+ bool replace);
-int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref,
- uint8_t name_index,
- char *name,
- size_t name_len);
+int ext4_fs_remove_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
+ char *name, size_t name_len);
-int ext4_fs_get_xattr(struct ext4_xattr_ref *ref,
- uint8_t name_index,
- char *name,
- size_t name_len,
- void *buf,
- size_t buf_size,
- size_t *size_got);
+int ext4_fs_get_xattr(struct ext4_xattr_ref *ref, uint8_t name_index,
+ char *name, size_t name_len, void *buf, size_t buf_size,
+ size_t *size_got);
-void
-ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
- int (iter)(struct ext4_xattr_ref *ref,
- struct ext4_xattr_item *item));
+void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref,
+ int(iter)(struct ext4_xattr_ref *ref,
+ struct ext4_xattr_item *item));
void ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref);
-char *ext4_extract_xattr_name(char *full_name,
- size_t full_name_len,
- uint8_t *name_index,
- size_t *name_len);
+char *ext4_extract_xattr_name(char *full_name, size_t full_name_len,
+ uint8_t *name_index, size_t *name_len);
#endif