ref: 61098c719f30316c4bac054170c262d0419849a9
parent: 5cdc17dc795e0a21486c97b5a34c8dff4bd60444
author: Kaho Ng <ngkaho1234@gmail.com>
date: Thu May 12 18:38:59 EDT 2016
ext4_xattr: Changes to EA metadata handling macros - Move them from include/ext4_types.h to include/ext4_xattr.h - Use ext4_inode_get_extra_isize to better handle extra_isize field of inodes.
--- a/include/ext4_types.h
+++ b/include/ext4_types.h
@@ -786,39 +786,6 @@
#define EXT4_GOOD_OLD_INODE_SIZE 128
-#define EXT4_XATTR_PAD_BITS 2
-#define EXT4_XATTR_PAD (1<<EXT4_XATTR_PAD_BITS)
-#define EXT4_XATTR_ROUND (EXT4_XATTR_PAD-1)
-#define EXT4_XATTR_LEN(name_len) \
- (((name_len) + EXT4_XATTR_ROUND + \
- sizeof(struct ext4_xattr_entry)) & ~EXT4_XATTR_ROUND)
-#define EXT4_XATTR_NEXT(entry) \
- ((struct ext4_xattr_entry *)( \
- (char *)(entry) + EXT4_XATTR_LEN((entry)->e_name_len)))
-#define EXT4_XATTR_SIZE(size) \
- (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND)
-#define EXT4_XATTR_NAME(entry) \
- ((char *)((entry) + 1))
-
-#define EXT4_XATTR_IHDR(raw_inode) \
- ((struct ext4_xattr_ibody_header *) \
- ((char *)raw_inode + \
- EXT4_GOOD_OLD_INODE_SIZE + \
- (raw_inode)->extra_isize))
-#define EXT4_XATTR_IFIRST(hdr) \
- ((struct ext4_xattr_entry *)((hdr)+1))
-
-#define EXT4_XATTR_BHDR(block) \
- ((struct ext4_xattr_header *)((block)->data))
-#define EXT4_XATTR_ENTRY(ptr) \
- ((struct ext4_xattr_entry *)(ptr))
-#define EXT4_XATTR_BFIRST(block) \
- EXT4_XATTR_ENTRY(EXT4_XATTR_BHDR(block)+1)
-#define EXT4_XATTR_IS_LAST_ENTRY(entry) \
- (*(uint32_t *)(entry) == 0)
-
-#define EXT4_ZERO_XATTR_VALUE ((void *)-1)
-
/*****************************************************************************/
/*
--- a/include/ext4_xattr.h
+++ b/include/ext4_xattr.h
@@ -43,6 +43,7 @@
#include "ext4_config.h"
#include "ext4_types.h"
+#include "ext4_inode.h"
#include "misc/tree.h"
#include "misc/queue.h"
@@ -73,6 +74,40 @@
RB_HEAD(ext4_xattr_tree,
ext4_xattr_item) root;
};
+
+#define EXT4_XATTR_PAD_BITS 2
+#define EXT4_XATTR_PAD (1<<EXT4_XATTR_PAD_BITS)
+#define EXT4_XATTR_ROUND (EXT4_XATTR_PAD-1)
+#define EXT4_XATTR_LEN(name_len) \
+ (((name_len) + EXT4_XATTR_ROUND + \
+ sizeof(struct ext4_xattr_entry)) & ~EXT4_XATTR_ROUND)
+#define EXT4_XATTR_NEXT(entry) \
+ ((struct ext4_xattr_entry *)( \
+ (char *)(entry) + EXT4_XATTR_LEN((entry)->e_name_len)))
+#define EXT4_XATTR_SIZE(size) \
+ (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND)
+#define EXT4_XATTR_NAME(entry) \
+ ((char *)((entry) + 1))
+
+#define EXT4_XATTR_IHDR(sb, raw_inode) \
+ ((struct ext4_xattr_ibody_header *) \
+ ((char *)raw_inode + \
+ EXT4_GOOD_OLD_INODE_SIZE + \
+ ext4_inode_get_extra_isize(sb, raw_inode)))
+#define EXT4_XATTR_IFIRST(hdr) \
+ ((struct ext4_xattr_entry *)((hdr)+1))
+
+#define EXT4_XATTR_BHDR(block) \
+ ((struct ext4_xattr_header *)((block)->data))
+#define EXT4_XATTR_ENTRY(ptr) \
+ ((struct ext4_xattr_entry *)(ptr))
+#define EXT4_XATTR_BFIRST(block) \
+ EXT4_XATTR_ENTRY(EXT4_XATTR_BHDR(block)+1)
+#define EXT4_XATTR_IS_LAST_ENTRY(entry) \
+ (*(uint32_t *)(entry) == 0)
+
+#define EXT4_ZERO_XATTR_VALUE ((void *)-1)
+
#define EXT4_XATTR_ITERATE_CONT 0
#define EXT4_XATTR_ITERATE_STOP 1
--- a/src/ext4_xattr.c
+++ b/src/ext4_xattr.c
@@ -272,7 +272,8 @@
struct ext4_xattr_entry *first_entry;
int16_t inode_size =
ext4_get16(&xattr_ref->fs->sb, inode_size);
- header = EXT4_XATTR_IHDR(xattr_ref->inode_ref->inode);
+ header = EXT4_XATTR_IHDR(&xattr_ref->fs->sb,
+ xattr_ref->inode_ref->inode);
first_entry = EXT4_XATTR_IFIRST(header);
ret = ((char *)first_entry + to_le16(entry->e_value_offs));
@@ -346,7 +347,8 @@
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);
+ header = EXT4_XATTR_IHDR(&xattr_ref->fs->sb,
+ xattr_ref->inode_ref->inode);
entry = EXT4_XATTR_IFIRST(header);
size_rem = inode_size - EXT4_GOOD_OLD_INODE_SIZE -
@@ -635,7 +637,8 @@
inode_size_rem = ext4_xattr_inode_space(xattr_ref);
block_size_rem = ext4_xattr_block_space(xattr_ref);
if (inode_size_rem > sizeof(struct ext4_xattr_ibody_header)) {
- ibody_header = EXT4_XATTR_IHDR(xattr_ref->inode_ref->inode);
+ ibody_header = EXT4_XATTR_IHDR(&xattr_ref->fs->sb,
+ xattr_ref->inode_ref->inode);
entry = EXT4_XATTR_IFIRST(ibody_header);
}