Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/6aa88380c149
branches:  trunk
changeset: 559681:6aa88380c149
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sun Mar 21 22:07:22 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:

 usr.sbin/quot/quot.c             |  47 +++++++++++++++++++++++++--------------
 usr.sbin/quotacheck/quotacheck.c |  36 +++++++++++++++++++-----------
 2 files changed, 53 insertions(+), 30 deletions(-)

diffs (151 lines):

diff -r 1327a7e70ffe -r 6aa88380c149 usr.sbin/quot/quot.c
--- a/usr.sbin/quot/quot.c      Sun Mar 21 21:20:46 2004 +0000
+++ b/usr.sbin/quot/quot.c      Sun Mar 21 22:07:22 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quot.c,v 1.21 2004/01/06 13:30:56 wiz Exp $    */
+/*     $NetBSD: quot.c,v 1.22 2004/03/21 22:07:22 dsl Exp $    */
 
 /*
  * Copyright (C) 1991, 1994 Wolfgang Solfrank.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: quot.c,v 1.21 2004/01/06 13:30:56 wiz Exp $");
+__RCSID("$NetBSD: quot.c,v 1.22 2004/03/21 22:07:22 dsl Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -566,6 +566,7 @@
 {
        int fd, i;
        struct fs *fs;
+       int sbloc;
        
        get_inode(-1, 0, 0);            /* flush cache */
        inituser();
@@ -575,25 +576,37 @@
                return;
        }
 
-       for (i = 0; sblock_try[i] != -1; i++) {
-               if (lseek(fd, sblock_try[i], 0) != sblock_try[i])
-                       continue;
-               if (read(fd, superblock, SBLOCKSIZE) != SBLOCKSIZE)
+       for (i = 0; ; i++) {
+               sbloc = sblock_try[i];
+               if (sbloc == -1) {
+                       warnx("%s: not a BSD filesystem", name);
+                       close(fd);
+                       return;
+               }
+               if (pread(fd, superblock, SBLOCKSIZE, sbloc) != SBLOCKSIZE)
                        continue;
                fs = (struct fs *)superblock;
 
-               if ((fs->fs_magic == FS_UFS1_MAGIC ||
-                   (fs->fs_magic == FS_UFS2_MAGIC &&
-                    fs->fs_sblockloc == numfrags(fs, sblock_try[i]))) &&
-                   fs->fs_bsize <= MAXBSIZE &&
-                   fs->fs_bsize >= sizeof(struct fs))
-                       break;
+               if (fs->fs_magic != FS_UFS1_MAGIC &&
+                   fs->fs_magic != FS_UFS2_MAGIC)
+                       continue;
+
+               if (fs->fs_old_flags & FS_FLAGS_UPDATED) {
+                       /* Not the main superblock */
+                       if (fs->fs_sblockloc != sbloc)
+                               continue;
+               } else {
+                       /* might be a first alt. id blocksize 64k */
+                       if (sbloc == SBLOCK_UFS2)
+                               continue;
+               }
+
+               if (fs->fs_bsize > MAXBSIZE ||
+                   fs->fs_bsize < sizeof(struct fs))
+                       continue;
+               break;
        }
-       if (sblock_try[i] == -1) {
-               warnx("%s: not a BSD filesystem", name);
-               close(fd);
-               return;
-       }
+
        ffs_oldfscompat((struct fs *)superblock);
        printf("%s:", name);
        if (mp)
diff -r 1327a7e70ffe -r 6aa88380c149 usr.sbin/quotacheck/quotacheck.c
--- a/usr.sbin/quotacheck/quotacheck.c  Sun Mar 21 21:20:46 2004 +0000
+++ b/usr.sbin/quotacheck/quotacheck.c  Sun Mar 21 22:07:22 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quotacheck.c,v 1.33 2004/01/05 23:23:38 jmmv Exp $     */
+/*     $NetBSD: quotacheck.c,v 1.34 2004/03/21 22:14:09 dsl Exp $      */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)quotacheck.c       8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: quotacheck.c,v 1.33 2004/01/05 23:23:38 jmmv Exp $");
+__RCSID("$NetBSD: quotacheck.c,v 1.34 2004/03/21 22:14:09 dsl Exp $");
 #endif
 #endif /* not lint */
 
@@ -343,32 +343,42 @@
                return 1;
        }
 
-       for (i = 0; sblock_try[i] != -1; i++) {
+       for (i = 0; ; i++) {
+               if (sblock_try[i] == -1) {
+                       warnx("%s: superblock not found", fsname);
+                       free(cgp);
+                       if (pid != NULL)
+                               exit(1);
+                       return 1;
+               }
                bread(sblock_try[i], (char *)&sblock, SBLOCKSIZE);
                switch (sblock.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*/
                case FS_UFS1_MAGIC_SWAPPED:
                        needswap = 1;
-                       goto found;
+                       ffs_sb_swap(&sblock, &sblock);
+                       break;
                default:
                        continue;
                }
+
+               if (sblock.fs_old_flags & FS_FLAGS_UPDATED) {
+                       if (sblock.fs_sblockloc != sblock_try[i])
+                               continue;
+               } else {
+                       if (sblock_try[i] == SBLOCK_UFS2)
+                               continue;
+               }
+               break;
        }
-       warnx("%s: superblock not found", fsname);
-       free(cgp);
-       if (pid != NULL)
-               exit(1);
-       return 1;
- found:;
-       if (needswap)
-               ffs_sb_swap(&sblock, &sblock);
+
        dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
        maxino = sblock.fs_ncg * sblock.fs_ipg;
        for (ino = 0, cg = 0; cg < sblock.fs_ncg; cg++) {



Home | Main Index | Thread Index | Old Index