Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce a preserve command line switch in debugfs 'rdump' command #8

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 48 additions & 15 deletions debugfs/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,15 @@ static void rdump_symlink(ext2_ino_t ino, struct ext2_inode *inode,
free(buf);
}

typedef struct {
char* fullname;
int preserve;
} rdump_dirent_private;

static int rdump_dirent(struct ext2_dir_entry *, int, int, char *, void *);

static int rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
const char *name, const char *dumproot)
const char *name, const char *dumproot, int preserve)
{
char *fullname;
int result = 0;
Expand All @@ -290,7 +295,7 @@ static int rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
goto errout;
}

if (dump_file("rdump", ino, fd, 1, fullname) != 0) {
if (dump_file("rdump", ino, fd, preserve, fullname) != 0) {
result = 1;
com_err("rdump", errno, "while dumping %s", fullname);
}
Expand All @@ -315,14 +320,23 @@ static int rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
goto errout;
}

rdump_dirent_private* entry = malloc(sizeof(rdump_dirent_private));
if (entry == NULL) {
com_err("rdump", errno, "while allocating entry for %s", fullname);
qkaiser marked this conversation as resolved.
Show resolved Hide resolved
goto errout;
}
entry->fullname = fullname;
entry->preserve = preserve;

retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
rdump_dirent, (void *) fullname);
rdump_dirent, (void *) entry);
free(entry);
if (retval) {
com_err("rdump", retval, "while dumping %s", fullname);
result = 1;
}

fix_perms("rdump", inode, -1, fullname);
if (preserve)
fix_perms("rdump", inode, -1, fullname);
}
/* else do nothing (don't dump device files, sockets, fifos, etc.) */

Expand All @@ -338,29 +352,42 @@ static int rdump_dirent(struct ext2_dir_entry *dirent,
{
char name[EXT2_NAME_LEN + 1];
int thislen;
const char *dumproot = private;
qkaiser marked this conversation as resolved.
Show resolved Hide resolved
struct ext2_inode inode;

rdump_dirent_private *dirent_private = (rdump_dirent_private *) private;
thislen = ext2fs_dirent_name_len(dirent);
strncpy(name, dirent->name, thislen);
name[thislen] = 0;

if (debugfs_read_inode(dirent->inode, &inode, name))
return 0;

return rdump_inode(dirent->inode, &inode, name, dumproot);
return rdump_inode(dirent->inode, &inode, name, dirent_private->fullname, dirent_private->preserve);
}

void do_rdump(int argc, char **argv, int sci_idx,
void *infop EXT2FS_ATTR((unused)))
{
struct stat st;
char *dest_dir;
int i;
int i, c;
int preserve = 0;
ext2_ino_t ino;
struct ext2_inode inode;

if (common_args_process(argc, argv, 3, INT_MAX, "rdump",
"<directory>... <native directory>", 0))
return;
reset_getopt();
while ((c = getopt(argc, argv, "p")) != EOF) {
switch (c) {
case 'p':
preserve++;
break;
default:
goto print_usage;
}
}

if (optind > argc - 2)
goto print_usage;

/* Pull out last argument */
dest_dir = argv[argc - 1];
Expand All @@ -376,10 +403,9 @@ void do_rdump(int argc, char **argv, int sci_idx,
return;
}

for (i = 1; i < argc; i++) {
for (i = optind; i < argc; i++) {
char *arg = argv[i], *basename;
struct ext2_inode inode;
ext2_ino_t ino = string_to_inode(arg);
ino = string_to_inode(arg);
if (!ino)
continue;

Expand All @@ -392,9 +418,16 @@ void do_rdump(int argc, char **argv, int sci_idx,
else
basename = arg;

if (rdump_inode(ino, &inode, basename, dest_dir) != 0)
if (rdump_inode(ino, &inode, basename, dest_dir, preserve) != 0)
ss_set_exit_status(sci_idx, 1);
}
return;

print_usage:
com_err(argv[0], 0,
"Usage: rdump [-p] "
"<fs_directory>... <output_directory>");
ss_set_exit_status(sci_idx, 1);
}

void do_cat(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
Expand Down
9 changes: 8 additions & 1 deletion e2fsck/extents.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,12 @@ static errcode_t rewrite_extent_replay(e2fsck_t ctx, struct extent_list *list,
{
errcode_t retval;
ext2_extent_handle_t handle;
unsigned int i, ext_written;
unsigned int i;
struct ext2fs_extent *ex, extent;
blk64_t start_val, delta;
#if defined(DEBUG) || defined(DEBUG_SUMMARY)
unsigned int ext_written;
#endif

/* Reset extent tree */
inode->i_flags &= ~EXT4_EXTENTS_FL;
Expand All @@ -223,7 +226,9 @@ static errcode_t rewrite_extent_replay(e2fsck_t ctx, struct extent_list *list,
if (retval)
return retval;

#if defined(DEBUG) || defined(DEBUG_SUMMARY)
ext_written = 0;
#endif

start_val = ext2fs_get_stat_i_blocks(ctx->fs, EXT2_INODE(inode));

Expand Down Expand Up @@ -263,7 +268,9 @@ static errcode_t rewrite_extent_replay(e2fsck_t ctx, struct extent_list *list,
retval = ext2fs_extent_fix_parents(handle);
if (retval)
goto err;
#if defined(DEBUG) || defined(DEBUG_SUMMARY)
ext_written++;
#endif
}

delta = ext2fs_get_stat_i_blocks(ctx->fs, EXT2_INODE(inode)) -
Expand Down
4 changes: 1 addition & 3 deletions lib/ss/test_ss.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ int main(int argc, char **argv)
}


void test_cmd (argc, argv)
int argc;
char **argv;
void test_cmd (int argc, char** argv)
{
printf("Hello, world!\n");
printf("Args: ");
Expand Down
Loading