When writing xattrs to disk, move the inline_data attribute to the front of the list so that inline data always ends up in the inode body (and not a separate EA block). Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> --- lib/ext2fs/ext_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index e69275e..50f7300 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -238,6 +238,24 @@ static struct ea_name_index ea_names[] = { {0, NULL}, }; +static void move_inline_data_to_front(struct ext2_xattr_handle *h) +{ + struct ext2_xattr *x; + struct ext2_xattr tmp; + + for (x = h->attrs + 1; x < h->attrs + h->length; x++) { + if (!x->name) + continue; + + if (strcmp(x->name, "system.data") == 0) { + memcpy(&tmp, x, sizeof(tmp)); + memcpy(x, h->attrs, sizeof(tmp)); + memcpy(h->attrs, &tmp, sizeof(tmp)); + return; + } + } +} + static const char *find_ea_prefix(int index) { struct ea_name_index *e; @@ -484,6 +502,8 @@ errcode_t ext2fs_xattrs_write(struct ext2_xattr_handle *handle) if (err) goto out; + move_inline_data_to_front(handle); + x = handle->attrs; /* Does the inode have size for EA? */ if (EXT2_INODE_SIZE(handle->fs->super) <= EXT2_GOOD_OLD_INODE_SIZE + -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html