xfs
[Top] [All Lists]

[PATCH] xfs_admin: exit gracefully for non-XFS fileststems

To: xfs@xxxxxxxxxxx
Subject: [PATCH] xfs_admin: exit gracefully for non-XFS fileststems
From: Christoph Hellwig <hch@xxxxxx>
Date: Sun, 25 Jan 2009 06:03:42 +0100
User-agent: Mutt/1.3.28i
Exit gracefully if the magic number doesn't match xfs in xfs_admin
and xfs_ncheck.  This is implemented by a new -C option to xfs_db
which makes it exit with a useful error message in case the filesystem
doesn't match the XFS superblock magic number.


Reported-by: Dick Middleton <dick@xxxxxxxxxxxx>
Signed-off-by: Christoph Hellwig <hch@xxxxxx>

Index: xfsprogs-dev/db/init.c
===================================================================
--- xfsprogs-dev.orig/db/init.c 2009-01-24 19:04:48.517429102 +0100
+++ xfsprogs-dev/db/init.c      2009-01-24 19:11:03.003555709 +0100
@@ -42,7 +42,7 @@ static void
 usage(void)
 {
        fprintf(stderr, _(
-               "Usage: %s [-frxV] [-p prog] [-l logdev] [-c cmd]... device\n"),
+               "Usage: %s [-CfrxV] [-p prog] [-l logdev] [-c cmd]... 
device\n"),
                progname);
        exit(1);
 }
@@ -55,10 +55,14 @@ init(
        xfs_sb_t        *sbp;
        void            *bufp = NULL;
        int             c;
+       int             check = 0;
 
        progname = basename(argv[0]);
-       while ((c = getopt(argc, argv, "c:fip:rxVl:")) != EOF) {
+       while ((c = getopt(argc, argv, "c:Cfip:rxVl:")) != EOF) {
                switch (c) {
+               case 'C':
+                       check = 1;
+                       break;
                case 'c':
                        cmdline = xrealloc(cmdline, (ncmdline+1)*sizeof(char*));
                        cmdline[ncmdline++] = optarg;
@@ -118,6 +122,11 @@ init(
 
        sbp = &xmount.m_sb;
        if (sbp->sb_magicnum != XFS_SB_MAGIC) {
+               if (check) {
+                       fprintf(stderr, _("%s: not an XFS filesystem\n"),
+                               progname);
+                       exit(1);
+               }
                fprintf(stderr, _("%s: unexpected XFS SB magic number 
0x%08x\n"),
                        progname, sbp->sb_magicnum);
        }
Index: xfsprogs-dev/db/xfs_admin.sh
===================================================================
--- xfsprogs-dev.orig/db/xfs_admin.sh   2009-01-24 19:11:26.867554445 +0100
+++ xfsprogs-dev/db/xfs_admin.sh        2009-01-24 19:13:55.950426543 +0100
@@ -30,7 +30,7 @@ shift $OPTIND
 case $# in
        1)      if [ -n "$DB_OPTS" ]
                then
-                       eval xfs_db -x -p xfs_admin $DB_OPTS $1
+                       eval xfs_db -x -p xfs_admin -C $DB_OPTS $1
                        status=$?
                fi
                if [ -n "$REPAIR_OPTS" ]
Index: xfsprogs-dev/db/xfs_ncheck.sh
===================================================================
--- xfsprogs-dev.orig/db/xfs_ncheck.sh  2009-01-24 19:14:34.903429336 +0100
+++ xfsprogs-dev/db/xfs_ncheck.sh       2009-01-24 19:14:42.105429164 +0100
@@ -25,7 +25,7 @@ done
 set -- extra $@
 shift $OPTIND
 case $# in
-       1)      xfs_db$DBOPTS -r -p xfs_ncheck -c "blockget -ns" -c 
"ncheck$OPTS" $1
+       1)      xfs_db$DBOPTS -r -p xfs_ncheck -C -c "blockget -ns" -c 
"ncheck$OPTS" $1
                status=$?
                ;;
        *)      echo $USAGE 1>&2
Index: xfsprogs-dev/db/xfs_ncheck64.sh
===================================================================
--- xfsprogs-dev.orig/db/xfs_ncheck64.sh        2009-01-24 19:14:34.924457708 
+0100
+++ xfsprogs-dev/db/xfs_ncheck64.sh     2009-01-24 19:14:52.707429049 +0100
@@ -24,7 +24,7 @@ done
 set -- extra $@
 shift $OPTIND
 case $# in
-       1)      xfs_db64$DBOPTS -r -p xfs_ncheck64 -c "blockget -ns" -c 
"ncheck$OPTS" $1
+       1)      xfs_db64$DBOPTS -r -p xfs_ncheck64 -C -c "blockget -ns" -c 
"ncheck$OPTS" $1
                status=$?
                ;;
        *)      echo $USAGE 1>&2
Index: xfsprogs-dev/man/man8/xfs_db.8
===================================================================
--- xfsprogs-dev.orig/man/man8/xfs_db.8 2009-01-24 19:15:16.855428751 +0100
+++ xfsprogs-dev/man/man8/xfs_db.8      2009-01-24 19:17:21.689554003 +0100
@@ -11,6 +11,8 @@ xfs_db \- debug an XFS filesystem
 ] [
 .B \-f
 ] [
+.B \-C
+] [
 .B \-l
 .I logdev
 ] [
@@ -32,6 +34,10 @@ that run
 .PP
 .SH OPTIONS
 .TP
+.B \-C
+Check the superblock magic number and exit gracefully if the filesystem is not
+an XFS filesystem.
+.TP
 .BI \-c " cmd"
 .B xfs_db
 commands may be run interactively (the default) or as arguments

<Prev in Thread] Current Thread [Next in Thread>