ref: 5cdc17dc795e0a21486c97b5a34c8dff4bd60444
parent: 8eff9f9971a1056ade031e646acb9b07a972fd65
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Thu May 12 09:59:44 EDT 2016
Refine extra_isize field handling
--- a/include/ext4_inode.h
+++ b/include/ext4_inode.h
@@ -205,16 +205,21 @@
void ext4_inode_set_generation(struct ext4_inode *inode, uint32_t gen);
/**@brief Get extra I-node size field.
+ * @param sb Superblock
* @param inode I-node
* @return extra I-node size
*/
-uint16_t ext4_inode_get_extra_isize(struct ext4_inode *inode);
+uint16_t ext4_inode_get_extra_isize(struct ext4_sblock *sb,
+ struct ext4_inode *inode);
/**@brief Set extra I-node size field.
+ * @param sb Superblock
* @param inode I-node
* @param size extra I-node size
*/
-void ext4_inode_set_extra_isize(struct ext4_inode *inode, uint16_t size);
+void ext4_inode_set_extra_isize(struct ext4_sblock *sb,
+ struct ext4_inode *inode,
+ uint16_t size);
/**@brief Get address of block, where are extended attributes located.
* @param inode I-node
--- a/src/ext4_fs.c
+++ b/src/ext4_fs.c
@@ -899,7 +899,7 @@
if (inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
uint16_t off = offsetof(struct ext4_inode, extra_isize);
uint16_t size = sizeof(struct ext4_inode) - off;
- ext4_inode_set_extra_isize(inode, size);
+ ext4_inode_set_extra_isize(&fs->sb, inode, size);
}
/* Reset blocks array. For symbolic link inode, just
--- a/src/ext4_inode.c
+++ b/src/ext4_inode.c
@@ -270,14 +270,21 @@
inode->generation = to_le32(gen);
}
-uint16_t ext4_inode_get_extra_isize(struct ext4_inode *inode)
+uint16_t ext4_inode_get_extra_isize(struct ext4_sblock *sb,
+ struct ext4_inode *inode)
{
- return to_le16(inode->extra_isize);
+ if (ext4_sb_feature_ro_com(sb, EXT4_FRO_COM_EXTRA_ISIZE))
+ return to_le16(inode->extra_isize);
+ else
+ return 0;
}
-void ext4_inode_set_extra_isize(struct ext4_inode *inode, uint16_t size)
+void ext4_inode_set_extra_isize(struct ext4_sblock *sb,
+ struct ext4_inode *inode,
+ uint16_t size)
{
- inode->extra_isize = to_le16(size);
+ if (ext4_sb_feature_ro_com(sb, EXT4_FRO_COM_EXTRA_ISIZE))
+ inode->extra_isize = to_le16(size);
}
uint64_t ext4_inode_get_file_acl(struct ext4_inode *inode,
--- a/src/ext4_xattr.c
+++ b/src/ext4_xattr.c
@@ -343,12 +343,14 @@
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 extra_isize = ext4_inode_get_extra_isize(&xattr_ref->fs->sb,
+ xattr_ref->inode_ref->inode);
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;
+ 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)) {
@@ -385,8 +387,10 @@
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 extra_isize = ext4_inode_get_extra_isize(&xattr_ref->fs->sb,
+ xattr_ref->inode_ref->inode);
uint16_t size_rem = inode_size - EXT4_GOOD_OLD_INODE_SIZE -
- xattr_ref->inode_ref->inode->extra_isize;
+ extra_isize;
return size_rem;
}