Skip to content

Commit

Permalink
dump.f2fs: Dump symlinks as symlinks
Browse files Browse the repository at this point in the history
Previously, dumped symlinks would create regular files. This creates
symlinks instead.

Change-Id: I9c25bcdd44274108b5720f317b187515f64c3622
Signed-off-by: Daniel Rosenberg <[email protected]>
  • Loading branch information
drosen-google committed Jul 13, 2024
1 parent 584ebc7 commit f7783f7
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions fsck/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,36 @@ static void dump_file(struct f2fs_sb_info *sbi, struct node_info *ni,
close(c.dump_fd);
}

static void dump_link(struct f2fs_sb_info *sbi, struct node_info *ni,
struct f2fs_node *node_blk, char *path)
{
struct f2fs_inode *inode = &node_blk->i;
int len = le32_to_cpu(inode->i_size);
int link_fd;
int ret;
char buf[len + 1];

dump_file(sbi, ni, node_blk, path);

link_fd = open(path, O_RDONLY);
ASSERT(link_fd);

read(link_fd, buf, len);
buf[len] = 0;

close(link_fd);
ret = unlink(path);
ASSERT(ret >= 0);

#if defined(__MINGW32__)
ret = mklink(buf, path);
ASSERT(ret >= 0);
#else
ret = symlink(buf, path);
ASSERT(ret >= 0);
#endif
}

static void dump_folder(struct f2fs_sb_info *sbi, struct node_info *ni,
struct f2fs_node *node_blk, char *path, int is_root)
{
Expand Down Expand Up @@ -639,8 +669,10 @@ static int dump_filesystem(struct f2fs_sb_info *sbi, struct node_info *ni,
name[namelen] = 0;
}

if (S_ISREG(imode) || S_ISLNK(imode)) {
if (S_ISREG(imode)) {
dump_file(sbi, ni, node_blk, name);
} else if S_ISLNK(imode) {
dump_link(sbi, ni, node_blk, name);
} else {
dump_folder(sbi, ni, node_blk, name, is_root);
}
Expand All @@ -650,8 +682,9 @@ static int dump_filesystem(struct f2fs_sb_info *sbi, struct node_info *ni,
if (c.preserve_perms) {
if (is_root)
strncpy(name, ".", 2);
ASSERT(chmod(name, imode) == 0);
ASSERT(chown(name, inode->i_uid, inode->i_gid) == 0);
if (!S_ISLNK(imode))
ASSERT(chmod(name, imode) == 0);
ASSERT(lchown(name, inode->i_uid, inode->i_gid) == 0);
}
#endif
if (is_base)
Expand Down

0 comments on commit f7783f7

Please sign in to comment.