All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Mike Fleetwood <mike.fleetwood@googlemail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: exit with failure when printing bad superblock
Date: Wed, 27 Jul 2022 21:04:42 +0200	[thread overview]
Message-ID: <20220727190442.GW13489@twin.jikos.cz> (raw)
In-Reply-To: <1658676734-15294-1-git-send-email-mike.fleetwood@googlemail.com>

On Sun, Jul 24, 2022 at 04:32:14PM +0100, Mike Fleetwood wrote:
> 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>

Makes sense, thanks.

> ---
>  cmds/inspect-dump-super.c                       | 11 ++++++++---
>  tests/misc-tests/015-dump-super-garbage/test.sh |  6 +++---
>  2 files changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/cmds/inspect-dump-super.c b/cmds/inspect-dump-super.c
> index d843562..4187da8 100644
> --- a/cmds/inspect-dump-super.c
> +++ b/cmds/inspect-dump-super.c
> @@ -52,9 +52,9 @@ static int load_and_dump_sb(char *filename, int fd, u64 sb_bytenr, int full,
>  	if (btrfs_super_magic(&sb) != BTRFS_MAGIC && !force) {
>  		error("bad magic on superblock on %s at %llu",

I've added a notice to use --force to show it.

>  				filename, (unsigned long long)sb_bytenr);
> -	} else {
> -		btrfs_print_superblock(&sb, full);
> +		return 1;
>  	}
> +	btrfs_print_superblock(&sb, full);
>  	return 0;
>  }
>  
> @@ -177,7 +177,12 @@ 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);
> diff --git a/tests/misc-tests/015-dump-super-garbage/test.sh b/tests/misc-tests/015-dump-super-garbage/test.sh
> index b346945..1e6afa1 100755
> --- a/tests/misc-tests/015-dump-super-garbage/test.sh
> +++ b/tests/misc-tests/015-dump-super-garbage/test.sh
> @@ -6,9 +6,9 @@ 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
>  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
> -- 
> 1.8.3.1

      reply	other threads:[~2022-07-27 19:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-24 15:32 [PATCH] btrfs-progs: exit with failure when printing bad superblock Mike Fleetwood
2022-07-27 19:04 ` David Sterba [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220727190442.GW13489@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=mike.fleetwood@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.