From: Christoph Hellwig <hch@infradead.org>
To: xfs@oss.sgi.com
Subject: [PATCH] xfs_db: exit on invalid magic number
Date: Fri, 30 Jan 2009 02:47:14 -0500 [thread overview]
Message-ID: <20090130074714.GA30377@infradead.org> (raw)
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>
Index: xfsprogs-dev/db/init.c
===================================================================
--- xfsprogs-dev.orig/db/init.c 2009-01-30 06:42:25.000000000 +0000
+++ xfsprogs-dev/db/init.c 2009-01-30 06:47:34.000000000 +0000
@@ -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,
Index: xfsprogs-dev/db/xfs_check.sh
===================================================================
--- xfsprogs-dev.orig/db/xfs_check.sh 2009-01-30 06:47:56.000000000 +0000
+++ xfsprogs-dev/db/xfs_check.sh 2009-01-30 06:48:06.000000000 +0000
@@ -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
Index: xfsprogs-dev/db/xfs_check64.sh
===================================================================
--- xfsprogs-dev.orig/db/xfs_check64.sh 2009-01-30 06:47:56.000000000 +0000
+++ xfsprogs-dev/db/xfs_check64.sh 2009-01-30 06:48:11.000000000 +0000
@@ -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
Index: xfsprogs-dev/db/xfs_metadump.sh
===================================================================
--- xfsprogs-dev.orig/db/xfs_metadump.sh 2009-01-30 06:48:14.000000000 +0000
+++ xfsprogs-dev/db/xfs_metadump.sh 2009-01-30 06:48:20.000000000 +0000
@@ -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
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 +0000
@@ -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
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next reply other threads:[~2009-01-30 7:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-30 7:47 Christoph Hellwig [this message]
2009-01-30 13:14 ` [PATCH] xfs_db: exit on invalid magic number Eric Sandeen
2009-01-30 15:29 ` Felix Blyakher
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=20090130074714.GA30377@infradead.org \
--to=hch@infradead.org \
--cc=xfs@oss.sgi.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox