]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: exit on invalid magic number
authorChristoph Hellwig <hch@infradead.org>
Fri, 30 Jan 2009 17:52:29 +0000 (18:52 +0100)
committerChristoph Hellwig <hch@brick.lst.de>
Fri, 30 Jan 2009 17:52:29 +0000 (18:52 +0100)
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 <hch@lst.de>
Reviewed-by: Eric Sandeen <sandeen@sandeen.net>
Reviewed-by: Felix Blyakher <felixb@sgi.com>
db/init.c
db/xfs_check.sh
db/xfs_check64.sh
db/xfs_metadump.sh
man/man8/xfs_db.8

index af5a850fc2fd2214a11f14c2fe312b4edad78224..e5f7951883e1887579fa8ca20e6662fad3d8028b 100644 (file)
--- 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,
index 59cdf80109dba473bf9557985e2795e54b6c7e5f..7f141f92333f54f39978ae993571e37b6e8dc799 100755 (executable)
@@ -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
index 849970bad00af4a1688b658a78be542680c5c47c..c82c607dd7050fdfdf913be9419403260c320ed6 100755 (executable)
@@ -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
index 920bdc6f8402f49bc9dfd7e33d0276163bf0e0de..28b04b8492bda12f91de1603c306eb8cade0ea6d 100755 (executable)
@@ -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
index 85a4c02b8b0ce99ec74909b43e83713653b4c2f7..629ae58408865d393d7a4fa4e1913cbd850c1368 100644 (file)
@@ -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