Skip to content

Commit

Permalink
dump.f2fs: Fix xattr dumping
Browse files Browse the repository at this point in the history
Xattrs for files with inline data were being skipped. This dumps those,
as well as xattrs for folders.

Change-Id: I57eec9356993d840b7d868e7b712ed4a4b54a441
Signed-off-by: Daniel Rosenberg <drosen@google.com>
  • Loading branch information
drosen-google authored and Jaegeuk Kim committed May 22, 2024
1 parent 252f760 commit 994f6a1
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions fsck/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static void dump_node_blk(struct f2fs_sb_info *sbi, int ntype,
}

#ifdef HAVE_FSETXATTR
static void dump_xattr(struct f2fs_sb_info *sbi, struct f2fs_node *node_blk)
static void dump_xattr(struct f2fs_sb_info *sbi, struct f2fs_node *node_blk, int is_dir)
{
void *xattr;
void *last_base_addr;
Expand Down Expand Up @@ -431,12 +431,24 @@ static void dump_xattr(struct f2fs_sb_info *sbi, struct f2fs_node *node_blk)

DBG(1, "fd %d xattr_name %s\n", c.dump_fd, xattr_name);
#if defined(__linux__)
ret = fsetxattr(c.dump_fd, xattr_name, value,
le16_to_cpu(ent->e_value_size), 0);
if (is_dir) {
ret = setxattr(".", xattr_name, value,
le16_to_cpu(ent->e_value_size), 0);
} else {
ret = fsetxattr(c.dump_fd, xattr_name, value,
le16_to_cpu(ent->e_value_size), 0);
}

#elif defined(__APPLE__)
ret = fsetxattr(c.dump_fd, xattr_name, value,
le16_to_cpu(ent->e_value_size), 0,
XATTR_CREATE);
if (is_dir) {
ret = setxattr(".", xattr_name, value,
le16_to_cpu(ent->e_value_size), 0,
XATTR_CREATE);
} else {
ret = fsetxattr(c.dump_fd, xattr_name, value,
le16_to_cpu(ent->e_value_size), 0,
XATTR_CREATE);
}
#endif
if (ret)
MSG(0, "XATTR index 0x%x set xattr failed error %d\n",
Expand All @@ -449,7 +461,7 @@ static void dump_xattr(struct f2fs_sb_info *sbi, struct f2fs_node *node_blk)
}
#else
static void dump_xattr(struct f2fs_sb_info *UNUSED(sbi),
struct f2fs_node *UNUSED(node_blk))
struct f2fs_node *UNUSED(node_blk), int UNUSED(is_dir))
{
MSG(0, "XATTR does not support\n");
}
Expand All @@ -462,13 +474,15 @@ static int dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
u64 ofs = 0;
u32 addr_per_block;
bool is_dir = S_ISDIR(le16_to_cpu(node_blk->i.i_mode));
int ret = 0;

if ((node_blk->i.i_inline & F2FS_INLINE_DATA)) {
DBG(3, "ino[0x%x] has inline data!\n", nid);
/* recover from inline data */
dev_write_dump(((unsigned char *)node_blk) + INLINE_DATA_OFFSET,
0, MAX_INLINE_DATA(node_blk));
return -1;
ret = -1;
goto dump_xattr;
}

if ((node_blk->i.i_inline & F2FS_INLINE_DENTRY)) {
Expand All @@ -480,7 +494,8 @@ static int dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
DBG(3, "ino[0x%x] has inline dentries!\n", nid);
/* recover from inline dentry */
dump_folder_contents(sbi, d.bitmap, d.dentry, d.filename, d.max);
return -1;
ret = -1;
goto dump_xattr;
}

c.show_file_map_max_offset = f2fs_max_file_offset(&node_blk->i);
Expand Down Expand Up @@ -516,9 +531,9 @@ static int dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
}
/* last block in extent cache */
print_extent(true);

dump_xattr(sbi, node_blk);
return 0;
dump_xattr:
dump_xattr(sbi, node_blk, is_dir);
return ret;
}

static void dump_file(struct f2fs_sb_info *sbi, struct node_info *ni,
Expand Down

0 comments on commit 994f6a1

Please sign in to comment.