mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-11 08:19:32 +00:00
btrfs-progs: dump-super: exit with failure when printing bad superblock
Attempting to dump a bad btrfs superblock returns successful exit status zero. According to the manual page non-zero should be returned on failure. Fix this. $ btrfs inspect-internal dump-super /dev/zero superblock: bytenr=65536, device=/dev/zero --------------------------------------------------------- ERROR: bad magic on superblock on /dev/zero at 65536 $ echo $? 0 Signed-off-by: Mike Fleetwood <mike.fleetwood@googlemail.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
22ffee3c6c
commit
7b6922c988
@ -50,11 +50,11 @@ static int load_and_dump_sb(char *filename, int fd, u64 sb_bytenr, int full,
|
||||
printf("superblock: bytenr=%llu, device=%s\n", sb_bytenr, filename);
|
||||
printf("---------------------------------------------------------\n");
|
||||
if (btrfs_super_magic(&sb) != BTRFS_MAGIC && !force) {
|
||||
error("bad magic on superblock on %s at %llu",
|
||||
error("bad magic on superblock on %s at %llu (use --force to dump it anyway)",
|
||||
filename, (unsigned long long)sb_bytenr);
|
||||
} else {
|
||||
btrfs_print_superblock(&sb, full);
|
||||
return 1;
|
||||
}
|
||||
btrfs_print_superblock(&sb, full);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -177,7 +177,11 @@ static int cmd_inspect_dump_super(const struct cmd_struct *cmd,
|
||||
putchar('\n');
|
||||
}
|
||||
} else {
|
||||
load_and_dump_sb(filename, fd, sb_bytenr, full, force);
|
||||
if (load_and_dump_sb(filename, fd, sb_bytenr, full, force)) {
|
||||
close(fd);
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
close(fd);
|
||||
|
@ -6,9 +6,14 @@ source "$TEST_TOP/common"
|
||||
|
||||
check_prereq btrfs
|
||||
|
||||
run_check "$TOP/btrfs" inspect-internal dump-super /dev/urandom
|
||||
run_check "$TOP/btrfs" inspect-internal dump-super -a /dev/urandom
|
||||
run_check "$TOP/btrfs" inspect-internal dump-super -fa /dev/urandom
|
||||
run_mustfail "attempt to print bad superblock without force" \
|
||||
"$TOP/btrfs" inspect-internal dump-super /dev/urandom
|
||||
run_mustfail "attempt to print bad superblock without force" \
|
||||
"$TOP/btrfs" inspect-internal dump-super -a /dev/urandom
|
||||
run_mustfail "attempt to print bad superblock without force" \
|
||||
"$TOP/btrfs" inspect-internal dump-super -fa /dev/urandom
|
||||
|
||||
# All forced, no failure
|
||||
run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
|
||||
run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
|
||||
run_check "$TOP/btrfs" inspect-internal dump-super -Ffa /dev/urandom
|
||||
|
Loading…
Reference in New Issue
Block a user