@@ -466,6 +466,14 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
dir_entry->inum = parent_inum;
list_add_tail(&dir_entry->list, &dir_head->list);
+ ret = add_xattr_item(trans, root, btrfs_root_dirid(&root->root_item),
+ dir_name);
+ if (ret < 0) {
+ errno = -ret;
+ error("failed to add xattr item for the top level inode: %m");
+ goto fail_no_dir;
+ }
+
root_dir_key.objectid = btrfs_root_dirid(&root->root_item);
root_dir_key.offset = 0;
root_dir_key.type = BTRFS_INODE_ITEM_KEY;
[BUG] When using "mkfs.btrfs" with "--rootdir" option, the top level inode (rootdir) will not get the same xattr from the source dir: mkdir -p source_dir/ touch source_dir/file setfattr -n user.rootdir_xattr source_dir/ setfattr -n user.regular_xattr source_dir/file mkfs.btrfs -f --rootdir source_dir $dev mount $dev $mnt getfattr $mnt # Nothing <<< getfattr $mnt/file # file: $mnt/file user.regular_xattr <<< [CAUSE] In function traverse_directory(), we only call add_xattr_item() for all the child inodes, not really for the rootdir inode itself, leading to the missing xattr items. [FIX] Also call add_xattr_item() for the rootdir inode. Issue: #688 Signed-off-by: Qu Wenruo <wqu@suse.com> --- mkfs/rootdir.c | 8 ++++++++ 1 file changed, 8 insertions(+)