standard superblock if we haven't found a good one yet; standardize units
for -b (sectors! as before); kernel may change fs_dbsize
SCCS-vsn: sbin/fsck/fsck.h 5.5
SCCS-vsn: sbin/fsck/setup.c 5.14
SCCS-vsn: sbin/fsck/utilities.c 5.10
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
- * @(#)fsck.h 5.4 (Berkeley) %G%
+ * @(#)fsck.h 5.5 (Berkeley) %G%
*/
#define MAXDUP 10 /* limit on dup blks (per inode) */
*/
#define MAXDUP 10 /* limit on dup blks (per inode) */
int debug; /* output debugging info */
char preen; /* just fix normal inconsistencies */
char hotroot; /* checking root device */
int debug; /* output debugging info */
char preen; /* just fix normal inconsistencies */
char hotroot; /* checking root device */
+char havesb; /* superblock has been read */
char *blockmap; /* ptr to primary blk allocation map */
char *statemap; /* ptr to inode state table */
char *blockmap; /* ptr to primary blk allocation map */
char *statemap; /* ptr to inode state table */
-static char sccsid[] = "@(#)setup.c 5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)setup.c 5.14 (Berkeley) %G%";
#endif not lint
#define DKTYPENAMES
#endif not lint
#define DKTYPENAMES
{
dev_t rootdev;
long cg, ncg, size, i, j;
{
dev_t rootdev;
long cg, ncg, size, i, j;
+ struct disklabel *getdisklabel(), *lp;
struct stat statb;
struct fs proto;
struct stat statb;
struct fs proto;
if (stat("/", &statb) < 0)
errexit("Can't stat root\n");
rootdev = statb.st_dev;
if (stat("/", &statb) < 0)
errexit("Can't stat root\n");
rootdev = statb.st_dev;
initbarea(&fileblk);
initbarea(&inoblk);
initbarea(&cgblk);
initbarea(&fileblk);
initbarea(&inoblk);
initbarea(&cgblk);
+ if (lp = getdisklabel((char *)NULL, dfile.rfdes))
+ dev_bsize = secsize = lp->d_secsize;
+ else {
+ dev_bsize = DEV_BSIZE;
+ secsize = 0; /* guess later */
+ }
/*
* Read in the superblock, looking for alternates if necessary
*/
if (readsb(1) == 0) {
/*
* Read in the superblock, looking for alternates if necessary
*/
if (readsb(1) == 0) {
- if (bflag || calcsb(dev, dfile.rfdes, &proto) == 0 || preen)
+ if (bflag || preen || calcsb(dev, dfile.rfdes, &proto) == 0)
return(0);
if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
return (0);
return(0);
if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
return (0);
int listerr;
{
BUFAREA asblk;
int listerr;
{
BUFAREA asblk;
- struct disklabel *getdisklabel(), *lp;
# define altsblock asblk.b_un.b_fs
# define altsblock asblk.b_un.b_fs
- daddr_t super = bflag ? bflag * DEV_BSIZE : SBOFF;
+ off_t sboff;
+ daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
if (bread(&dfile, (char *)&sblock, super, (long)SBSIZE) != 0)
return (0);
sblk.b_bno = super;
if (bread(&dfile, (char *)&sblock, super, (long)SBSIZE) != 0)
return (0);
sblk.b_bno = super;
{ badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
if (sblock.fs_sbsize > SBSIZE)
{ badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
{ badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
if (sblock.fs_sbsize > SBSIZE)
{ badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
+ /*
+ * Compute block size that the filesystem is based on,
+ * according to fsbtodb, and adjust superblock block number
+ * so we can tell if this is an alternate later.
+ */
+ if (sblock.fs_dbsize && secsize == 0)
+ secsize = sblock.fs_dbsize;
+ super *= dev_bsize;
+ dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
+ sblk.b_bno = super / dev_bsize;
/*
* Set all possible fields that could differ, then do check
* of whole super block against an alternate super block.
* When an alternate super-block is specified this check is skipped.
*/
/*
* Set all possible fields that could differ, then do check
* of whole super block against an alternate super block.
* When an alternate super-block is specified this check is skipped.
*/
- dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
- if (lp = getdisklabel((char *)NULL, dfile.rfdes))
- secsize = lp->d_secsize;
- else
- secsize = dev_bsize;
- sblk.b_bno = sblk.b_bno / dev_bsize;
- if (bflag)
+ if (bflag) {
+ havesb = 1;
getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
if (asblk.b_errs != NULL)
return (0);
altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
if (asblk.b_errs != NULL)
return (0);
altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
+ altsblock.fs_dbsize = sblock.fs_dbsize;
altsblock.fs_link = sblock.fs_link;
altsblock.fs_rlink = sblock.fs_rlink;
altsblock.fs_time = sblock.fs_time;
altsblock.fs_link = sblock.fs_link;
altsblock.fs_rlink = sblock.fs_rlink;
altsblock.fs_time = sblock.fs_time;
"VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
return (0);
}
"VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
return (0);
}
return (1);
# undef altsblock
}
return (1);
# undef altsblock
}
else
pp = &lp->d_partitions[*cp - 'a'];
if (pp->p_fstype != FS_BSDFFS) {
else
pp = &lp->d_partitions[*cp - 'a'];
if (pp->p_fstype != FS_BSDFFS) {
- pfatal("%s: NOT FORMATTED AS A BSD FILE SYSTEM (%s)\n",
+ pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n",
dev, pp->p_fstype < FSMAXTYPES ?
fstypenames[pp->p_fstype] : "unknown");
return (0);
dev, pp->p_fstype < FSMAXTYPES ?
fstypenames[pp->p_fstype] : "unknown");
return (0);
fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg);
for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1)
fs->fs_fsbtodb++;
fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg);
for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1)
fs->fs_fsbtodb++;
+ dev_bsize = lp->d_secsize;
-static char sccsid[] = "@(#)utilities.c 5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)utilities.c 5.10 (Berkeley) %G%";
#endif not lint
#include <stdio.h>
#endif not lint
#include <stdio.h>
flush(&dfile, &fileblk);
flush(&dfile, &sblk);
flush(&dfile, &fileblk);
flush(&dfile, &sblk);
- if (dev_bsize && sblk.b_bno != SBOFF / dev_bsize &&
+ if (havesb && sblk.b_bno != SBOFF / dev_bsize &&
!preen && reply("UPDATE STANDARD SUPERBLOCK")) {
sblk.b_bno = SBOFF / dev_bsize;
sbdirty();
!preen && reply("UPDATE STANDARD SUPERBLOCK")) {
sblk.b_bno = SBOFF / dev_bsize;
sbdirty();
for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
if (read(fcp->rfdes, cp, secsize) < 0) {
lseek(fcp->rfdes, blk * dev_bsize + i + secsize, 0);
for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
if (read(fcp->rfdes, cp, secsize) < 0) {
lseek(fcp->rfdes, blk * dev_bsize + i + secsize, 0);
- if (secsize != dev_bsize)
+ if (secsize != dev_bsize && dev_bsize != 1)
printf(" %d (%d),",
(blk * dev_bsize + i) / secsize,
blk + i / dev_bsize);
printf(" %d (%d),",
(blk * dev_bsize + i) / secsize,
blk + i / dev_bsize);