xfs_db: exit on invalid magic number
PATCH 1/1 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.
db/init.c +11 -5
@@ -33,6 +33,7 @@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 @@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 @@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 @@case 'f' : x.disfile =1 ;break ; +case 'F' : + force =1 ; +break ;case 'i' : x.isreadonly = (LIBXFS_ISREADONLY |LIBXFS_ISINACTIVE );break ;
@@ -118,8 +122,10 @@ 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,
db/xfs_check.sh +1 -1
@@ -26,7 +26,7 @@ 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
db/xfs_check64.sh +1 -1
@@ -26,7 +26,7 @@ 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
db/xfs_metadump.sh +1 -1
@@ -29,7 +29,7 @@ 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
man/man8/xfs_db.8 +8 -1
@@ -7,7 +7,7 @@ .B \-c .I cmd ] ... [ -.BR \-i | r | x +.BR \-i | r | x | F ] [ .B \-f ] [
@@ -53,6 +53,13 @@ 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
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 8 lines · Christoph Hellwig
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 wayxfs_checkandxfs_metadumpcan be used on a filesystem that has a corrupted primary superblock.Signed-off-by Christoph Hellwig <[email protected]>
Seems good to me, thanks.
-Eric
Quoted 137 lines
Index:
xfsprogs-dev/db/init.c
===================================================================db/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +2
-2@@ -33,6 +33,7 @@ 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 @@ 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); }db/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +8
-3@@ -57,7 +58,7 @@ 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 @@ case 'f': x.disfile = 1; break; + case 'F': + force = 1; + break; case 'i': x.isreadonly = (LIBXFS_ISREADONLY|LIBXFS_ISINACTIVE); break;@@ -118,8 +122,10 @@ 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:xfsprogs-dev/db/xfs_check.sh
===================================================================
---xfsprogs-dev.orig/db/xfs_check.sh2009-01-30
06:47:56.000000000 +0000
+++xfsprogs-dev/db/xfs_check.sh2009-01-30 06:48:06.000000000
+0000db/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +0
-0@@ -26,7 +26,7 @@set -- extra $@
shift $OPTIND
case $# indb/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +1
-1- 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>&2Index:
xfsprogs-dev/db/xfs_check64.sh
===================================================================
---xfsprogs-dev.orig/db/xfs_check64.sh2009-01-30
06:47:56.000000000 +0000
+++xfsprogs-dev/db/xfs_check64.sh2009-01-30 06:48:11.000000000
+0000db/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +0
-0@@ -26,7 +26,7 @@set -- extra $@
shift $OPTIND
case $# indb/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +1
-1- 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>&2Index:
xfsprogs-dev/db/xfs_metadump.sh
===================================================================
---xfsprogs-dev.orig/db/xfs_metadump.sh2009-01-30
06:48:14.000000000 +0000
+++xfsprogs-dev/db/xfs_metadump.sh2009-01-30 06:48:20.000000000
+0000db/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +0
-0@@ -29,7 +29,7 @@set -- extra $@
shift $OPTIND
case $# indb/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +1
-1- 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: xfsprogs-dev/man/man8/xfs_db.8
===================================================================
--- xfsprogs-dev.orig/man/man8/xfs_db.8 2009-01-30
06:42:43.000000000 +0000
+++ xfsprogs-dev/man/man8/xfs_db.8 2009-01-30 06:49:13.000000000
+0000db/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +0
-0@@ -7,7 +7,7 @@.B \-c
.I cmd
] ... [-.BR \-i | r | x +.BR \-i | r | x | F] [
.B \-f
] [db/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +0
-0@@ -53,6 +53,13 @@an ordinary file with
.BRxfs_copy(8).
.TP
+.B \-F
+Specifies that we want to continue even if the superblock magic is notdb/init.c 2009-01-30 06:47:34.000000000 +0000 renamed from db/init.c 2009-01-30 06:42:25.000000000 +0000 +5
-0+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
Quoted 5 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 8 lines · Christoph Hellwig
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 wayxfs_checkandxfs_metadumpcan be used on a filesystem that has a corrupted primary superblock.Signed-off-by Christoph Hellwig <[email protected]>
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs