Don't use 1st alternate superblock at offset 64k for ffsv1.

Fixes part of PR kern/24809
This commit is contained in:
dsl 2004-03-21 20:12:16 +00:00
parent 2dc6ea479c
commit 3d7fa497c5
1 changed files with 13 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fsirand.c,v 1.23 2004/01/05 23:23:33 jmmv Exp $ */ /* $NetBSD: fsirand.c,v 1.24 2004/03/21 20:12:16 dsl Exp $ */
/*- /*-
* Copyright (c) 1997 The NetBSD Foundation, Inc. * Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: fsirand.c,v 1.23 2004/01/05 23:23:33 jmmv Exp $"); __RCSID("$NetBSD: fsirand.c,v 1.24 2004/03/21 20:12:16 dsl Exp $");
#endif /* lint */ #endif /* lint */
#include <sys/param.h> #include <sys/param.h>
@ -96,12 +96,10 @@ getsblock(int fd, const char *name, struct fs *fs)
{ {
int i; int i;
for (i = 0; sblock_try[i] != -1; i++) { for (i = 0; ; i++) {
if (sblock_try[i] == -1)
if (lseek(fd, sblock_try[i] , SEEK_SET) == (off_t) -1) errx(1, "%s: can't find superblock", name);
continue; if (pread(fd, fs, SBLOCKSIZE, sblock_try[i]) != SBLOCKSIZE)
if (read(fd, fs, SBLOCKSIZE) != SBLOCKSIZE)
continue; continue;
switch(fs->fs_magic) { switch(fs->fs_magic) {
@ -109,22 +107,22 @@ getsblock(int fd, const char *name, struct fs *fs)
is_ufs2 = 1; is_ufs2 = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
case FS_UFS1_MAGIC: case FS_UFS1_MAGIC:
goto found; break;
case FS_UFS2_MAGIC_SWAPPED: case FS_UFS2_MAGIC_SWAPPED:
is_ufs2 = 1; is_ufs2 = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
case FS_UFS1_MAGIC_SWAPPED: case FS_UFS1_MAGIC_SWAPPED:
needswap = 1; needswap = 1;
goto found; ffs_sb_swap(fs, fs);
break;
default: default:
continue; continue;
} }
}
errx(1, "%s: can't find superblock", name); if (!is_ufs2 && sblock_try[i] == SBLOCK_UFS2)
found: continue;
if (needswap) break;
ffs_sb_swap(fs, fs); }
if (fs->fs_ncg < 1) if (fs->fs_ncg < 1)
errx(1, "%s: bad ncg in superblock", name); errx(1, "%s: bad ncg in superblock", name);