Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin When searching for the superblock, don't pick an ffsv1 ...



details:   https://anonhg.NetBSD.org/src/rev/ea369da43c7b
branches:  trunk
changeset: 559676:ea369da43c7b
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sun Mar 21 20:30:38 2004 +0000

description:
When searching for the superblock, don't pick an ffsv1 superblock from the
location where we expect to find an ffsv2 superblock.
It could be the first alternate for a ffsv1 filesystem with 64k blocks.
Fixes part of PR kern/24809

diffstat:

 sbin/dump/ffs_inode.c |  22 +++++++++++++---------
 sbin/tunefs/tunefs.c  |  25 +++++++++++++++----------
 2 files changed, 28 insertions(+), 19 deletions(-)

diffs (122 lines):

diff -r adf11eb54bec -r ea369da43c7b sbin/dump/ffs_inode.c
--- a/sbin/dump/ffs_inode.c     Sun Mar 21 20:12:16 2004 +0000
+++ b/sbin/dump/ffs_inode.c     Sun Mar 21 20:30:38 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_inode.c,v 1.13 2003/08/07 10:04:14 agc Exp $ */
+/*     $NetBSD: ffs_inode.c,v 1.14 2004/03/21 20:30:38 dsl Exp $ */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -36,7 +36,7 @@
 #endif /* not lint */
 
 #ifndef lint
-__RCSID("$NetBSD: ffs_inode.c,v 1.13 2003/08/07 10:04:14 agc Exp $");
+__RCSID("$NetBSD: ffs_inode.c,v 1.14 2004/03/21 20:30:38 dsl Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -78,7 +78,9 @@
        int ns = 0;
 
        sblock = (struct fs *)superblock;
-       for (i = 0; i < sblock_try[i] != -1; i++) {
+       for (i = 0; ; i++) {
+               if (sblock_try[i] == -1)
+                       quit("can't find superblock\n");
                rawread(sblock_try[i], (char *)superblock, MAXBSIZE);
 
                switch(sblock->fs_magic) {
@@ -86,22 +88,24 @@
                        is_ufs2 = 1;
                        /*FALLTHROUGH*/
                case FS_UFS1_MAGIC:
-                       goto found;
+                       break;
                case FS_UFS2_MAGIC_SWAPPED:
                        is_ufs2 = 1;
                        /*FALLTHROUGH*/
                case FS_UFS1_MAGIC_SWAPPED:
                        ns = 1;
                        ffs_sb_swap(sblock, sblock);
-                       goto found;
+                       break;
                 default:
                         continue;
                 }
+               if (!is_ufs2 && sblock_try[i] == SBLOCK_UFS2)
+                       continue;
+               if (sblock->fs_old_flags & FS_FLAGS_UPDATED
+                   && sblock_try[i] != sblock->fs_sblockloc)
+                       continue;
+               break;
         }
-       quit("can't find superblock\n");
-found:
-       if (is_ufs2 && sblock_try[i] != sblock->fs_sblockloc)
-               quit("bad superblock\n");
        return 0;
 }
 
diff -r adf11eb54bec -r ea369da43c7b sbin/tunefs/tunefs.c
--- a/sbin/tunefs/tunefs.c      Sun Mar 21 20:12:16 2004 +0000
+++ b/sbin/tunefs/tunefs.c      Sun Mar 21 20:30:38 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tunefs.c,v 1.29 2004/01/05 23:23:34 jmmv Exp $ */
+/*     $NetBSD: tunefs.c,v 1.30 2004/03/21 20:38:08 dsl Exp $  */
 
 /*
  * Copyright (c) 1983, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)tunefs.c   8.3 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: tunefs.c,v 1.29 2004/01/05 23:23:34 jmmv Exp $");
+__RCSID("$NetBSD: tunefs.c,v 1.30 2004/03/21 20:38:08 dsl Exp $");
 #endif
 #endif /* not lint */
 
@@ -332,14 +332,16 @@
 {
        int i;
 
-       for (i = 0; sblock_try[i] != -1; i++) {
+       for (i = 0; ; i++) {
+               if (sblock_try[i] == -1)
+                       errx(5, "cannot find filesystem superblock");
                bread(sblock_try[i] / dev_bsize, (char *)fs, SBLOCKSIZE, file);
                switch(fs->fs_magic) {
                case FS_UFS2_MAGIC:
                        is_ufs2 = 1;
                        /*FALLTHROUGH*/
                case FS_UFS1_MAGIC:
-                       goto found;
+                       break;
                case FS_UFS2_MAGIC_SWAPPED:
                        is_ufs2 = 1;
                        /*FALLTHROUGH*/
@@ -347,15 +349,18 @@
                        warnx("%s: swapping byte order", file);
                        needswap = 1;
                        ffs_sb_swap(fs, fs);
-                       goto found;
+                       break;
                default:
-                       break;
+                       continue;
                }
+               if (!is_ufs2 && sblock_try[i] == SBLOCK_UFS2)
+                       continue;
+               if (fs->fs_old_flags & FS_FLAGS_UPDATED
+                   && fs->fs_sblockloc != sblock_try[i])
+                       continue;
+               break;
        }
-       errx(5, "cannot find filesystem superblock");
-found:
-       if (is_ufs2 && fs->fs_sblockloc != sblock_try[i])
-               errx(5, "bad super block");
+
        dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
        sblockloc = sblock_try[i] / dev_bsize;
 }



Home | Main Index | Thread Index | Old Index