From: Christoph Hellwig Date: Fri, 30 Jan 2009 17:52:29 +0000 (+0100) Subject: xfs_db: exit on invalid magic number X-Git-Tag: v3.0.0~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f98455ae9f393b10508c9c46f85e50dc3b0c372;p=thirdparty%2Fxfsprogs-dev.git xfs_db: exit on invalid magic number Fail gracefully and with a useful error message when we detect an invalid superblock magic in xfs_db. Add a new -F flag to continue when seeing the invalid magic number - that way xfs_check and xfs_metadump can be used on a filesystem that has a corrupted primary superblock. Signed-off-by: Christoph Hellwig Reviewed-by: Eric Sandeen Reviewed-by: Felix Blyakher --- diff --git a/db/init.c b/db/init.c index af5a850fc..e5f795188 100644 --- a/db/init.c +++ b/db/init.c @@ -33,6 +33,7 @@ char *fsdevice; int blkbb; int exitcode; int expert_mode; +int force; xfs_mount_t xmount; xfs_mount_t *mp; libxfs_init_t x; @@ -42,8 +43,8 @@ static void usage(void) { fprintf(stderr, _( - "Usage: %s [-frxV] [-p prog] [-l logdev] [-c cmd]... device\n"), - progname); + "Usage: %s [-fFrxV] [-p prog] [-l logdev] [-c cmd]... device\n" + ), progname); exit(1); } @@ -57,7 +58,7 @@ init( int c; progname = basename(argv[0]); - while ((c = getopt(argc, argv, "c:fip:rxVl:")) != EOF) { + while ((c = getopt(argc, argv, "c:fFip:rxVl:")) != EOF) { switch (c) { case 'c': cmdline = xrealloc(cmdline, (ncmdline+1)*sizeof(char*)); @@ -66,6 +67,9 @@ init( case 'f': x.disfile = 1; break; + case 'F': + force = 1; + break; case 'i': x.isreadonly = (LIBXFS_ISREADONLY|LIBXFS_ISINACTIVE); break; @@ -118,8 +122,10 @@ init( sbp = &xmount.m_sb; if (sbp->sb_magicnum != XFS_SB_MAGIC) { - fprintf(stderr, _("%s: unexpected XFS SB magic number 0x%08x\n"), - progname, sbp->sb_magicnum); + fprintf(stderr, _("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n"), + progname, fsdevice, sbp->sb_magicnum); + if (!force) + exit(EXIT_FAILURE); } mp = libxfs_mount(&xmount, sbp, x.ddev, x.logdev, x.rtdev, diff --git a/db/xfs_check.sh b/db/xfs_check.sh index 59cdf8010..7f141f923 100755 --- a/db/xfs_check.sh +++ b/db/xfs_check.sh @@ -26,7 +26,7 @@ done set -- extra $@ shift $OPTIND case $# in - 1) xfs_db$DBOPTS -i -p xfs_check -c "check$OPTS" $1 + 1) xfs_db$DBOPTS -F -i -p xfs_check -c "check$OPTS" $1 status=$? ;; *) echo $USAGE 1>&2 diff --git a/db/xfs_check64.sh b/db/xfs_check64.sh index 849970bad..c82c607dd 100755 --- a/db/xfs_check64.sh +++ b/db/xfs_check64.sh @@ -26,7 +26,7 @@ done set -- extra $@ shift $OPTIND case $# in - 1) xfs_db64$DBOPTS -i -p xfs_check64 -c "check$OPTS" $1 + 1) xfs_db64$DBOPTS -F -i -p xfs_check64 -c "check$OPTS" $1 status=$? ;; *) echo $USAGE 1>&2 diff --git a/db/xfs_metadump.sh b/db/xfs_metadump.sh index 920bdc6f8..28b04b849 100755 --- a/db/xfs_metadump.sh +++ b/db/xfs_metadump.sh @@ -29,7 +29,7 @@ done set -- extra $@ shift $OPTIND case $# in - 2) xfs_db$DBOPTS -i -p xfs_metadump -c "metadump$OPTS $2" $1 + 2) xfs_db$DBOPTS -F -i -p xfs_metadump -c "metadump$OPTS $2" $1 status=$? ;; *) echo $USAGE 1>&2 diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 85a4c02b8..629ae5840 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -7,7 +7,7 @@ xfs_db \- debug an XFS filesystem .B \-c .I cmd ] ... [ -.BR \-i | r | x +.BR \-i | r | x | F ] [ .B \-f ] [ @@ -53,6 +53,13 @@ This might happen if an image copy of a filesystem has been made into an ordinary file with .BR xfs_copy (8). .TP +.B \-F +Specifies that we want to continue even if the superblock magic is not +correct. For use in +.BR xfs_check +and +.BR xfs_metadump . +.TP .B \-i Allows execution on a mounted filesystem, provided it is mounted read-only. Useful for shell scripts such as