From: Christoph Hellwig <hch@lst.de>
To: xfs@oss.sgi.com
Subject: [PATCH] xfs_admin: exit gracefully for non-XFS fileststems
Date: Sun, 25 Jan 2009 06:03:42 +0100 [thread overview]
Message-ID: <20090125050342.GA30091@lst.de> (raw)
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@lingbrae.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
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
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next reply other threads:[~2009-01-25 5:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-25 5:03 Christoph Hellwig [this message]
2009-01-25 5:56 ` [PATCH] xfs_admin: exit gracefully for non-XFS fileststems Josef 'Jeff' Sipek
2009-01-29 21:43 ` Eric Sandeen
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=20090125050342.GA30091@lst.de \
--to=hch@lst.de \
--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