ref: 846df7dfc7f3bcadbe20af8ae66ba9c76c43e5b6
parent: 29a5d255e429f73fbe44ac7c878fff3003474c88
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Fri Oct 9 20:52:59 EDT 2015
ea_size accounting rework: now do not count the size of xattr headers.
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -371,11 +371,18 @@
if (!item)
return NULL;
- if (xattr_ref->ea_size + EXT4_XATTR_SIZE(item->data_size) +
+ if ((xattr_ref->ea_size + EXT4_XATTR_SIZE(data_size) +
+ EXT4_XATTR_LEN(item->name_len)
+ >
+ ext4_xattr_inode_space(xattr_ref) -
+ sizeof(struct ext4_xattr_ibody_header))
+ &&
+ (xattr_ref->ea_size + EXT4_XATTR_SIZE(data_size) +
EXT4_XATTR_LEN(item->name_len) >
- ext4_xattr_inode_space(xattr_ref) +
- ext4_xattr_block_space(xattr_ref)) {
+ ext4_xattr_block_space(xattr_ref) -
+ sizeof(struct ext4_xattr_header))) {
ext4_xattr_item_free(item);
+
return NULL;
}
if (ext4_xattr_item_alloc_data(item, data, data_size) != EOK) {
@@ -444,12 +451,6 @@
ext4_xattr_item_free(item);
}
xattr_ref->ea_size = 0;
- if (xattr_block)
- xattr_ref->ea_size += sizeof(struct ext4_xattr_header);
-
- if (ext4_xattr_inode_space(xattr_ref) >
- sizeof(struct ext4_xattr_ibody_header))
- xattr_ref->ea_size += sizeof(struct ext4_xattr_ibody_header);
}
static int ext4_xattr_try_alloc_block(struct ext4_xattr_ref *xattr_ref)
@@ -477,7 +478,6 @@
&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);
}
Finish:
@@ -495,7 +495,6 @@
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)
@@ -762,7 +761,6 @@
if (rc != EOK)
return EIO;
- ref->ea_size += sizeof(struct ext4_xattr_header);
ref->block_loaded = true;
} else
ref->block_loaded = false;
@@ -769,10 +767,6 @@
ref->inode_ref = inode_ref;
ref->fs = fs;
-
- if (ext4_xattr_inode_space(ref) >
- sizeof(struct ext4_xattr_ibody_header))
- ref->ea_size += sizeof(struct ext4_xattr_ibody_header);
rc = ext4_xattr_fetch(ref);
if (rc != EOK) {