From: krw Date: Fri, 9 May 2014 13:19:34 +0000 (+0000) Subject: Fix '-b' option to work with the superblock locations output by newfs X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=17af71c173759db243fc6e8c16a0148fa5802a36;p=openbsd Fix '-b' option to work with the superblock locations output by newfs on 4096-byte sector disks. No-op on 512-byte sector disks. Adhering to the bedrock idea that ffs will *never* use anything but 512-byte block disk addressing (a.k.a. daddr_t), and believing that the 'fake' bread()/bwrite() functions should always be using 512-btye block numbers like their kernel big brothers, nuke the computed dev_bsize and use DEV_BSIZE for conversions to/from byte offsets. Spotted and various fixes tested by David Vasek. Still to fix: scanning for superblocks on 4K disks. ok otto@ --- diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h index 378d31c7ca4..a2f82b8e0fb 100644 --- a/sbin/fsck_ffs/fsck.h +++ b/sbin/fsck_ffs/fsck.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fsck.h,v 1.28 2013/11/02 00:08:17 krw Exp $ */ +/* $OpenBSD: fsck.h,v 1.29 2014/05/09 13:19:34 krw Exp $ */ /* $NetBSD: fsck.h,v 1.13 1996/10/11 20:15:46 thorpej Exp $ */ /* @@ -230,7 +230,6 @@ struct inoinfo { extern long numdirs, listmax, inplast; -long dev_bsize; /* computed value of DEV_BSIZE */ long secsize; /* actual disk sector size */ char nflag; /* assume a no response */ char yflag; /* assume a yes response */ diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index bdbc4aaf3f4..2b0415804f1 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setup.c,v 1.51 2013/11/22 04:38:02 guenther Exp $ */ +/* $OpenBSD: setup.c,v 1.52 2014/05/09 13:19:34 krw Exp $ */ /* $NetBSD: setup.c,v 1.27 1996/09/27 22:45:19 christos Exp $ */ /* @@ -131,9 +131,9 @@ setup(char *dev) if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL) errexit("cannot allocate space for superblock\n"); if ((lp = getdisklabel(NULL, fsreadfd)) != NULL) - dev_bsize = secsize = lp->d_secsize; + secsize = lp->d_secsize; else - dev_bsize = secsize = DEV_BSIZE; + secsize = DEV_BSIZE; /* * Read in the superblock, looking for alternates if necessary */ @@ -445,7 +445,7 @@ readsb(int listerr) } } else { for (i = 0; sbtry[i] != -1; i++) { - super = sbtry[i] / dev_bsize; + super = sbtry[i] / DEV_BSIZE; if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0) @@ -515,15 +515,6 @@ readsb(int listerr) 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. - */ - super *= dev_bsize; - dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); - sblk.b_bno = super / dev_bsize; if (bflag) goto out; getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize); @@ -643,7 +634,6 @@ again: fs->fs_spc >>= 1; goto again; } - dev_bsize = lp->d_secsize; return (1); } diff --git a/sbin/fsck_ffs/utilities.c b/sbin/fsck_ffs/utilities.c index 44ef7afc2d1..6793460e5a9 100644 --- a/sbin/fsck_ffs/utilities.c +++ b/sbin/fsck_ffs/utilities.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utilities.c,v 1.42 2013/11/01 17:36:18 krw Exp $ */ +/* $OpenBSD: utilities.c,v 1.43 2014/05/09 13:19:34 krw Exp $ */ /* $NetBSD: utilities.c,v 1.18 1996/09/27 22:45:20 christos Exp $ */ /* @@ -229,7 +229,7 @@ flush(int fd, struct bufarea *bp) return; if (bp->b_errs != 0) pfatal("WRITING %sZERO'ED BLOCK %lld TO DISK\n", - (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ", + (bp->b_errs == bp->b_size / DEV_BSIZE) ? "" : "PARTIALLY ", (long long)bp->b_bno); bp->b_dirty = 0; bp->b_errs = 0; @@ -288,9 +288,9 @@ ckfini(int markclean) } else sblockloc = SBLOCK_UFS2; flush(fswritefd, &sblk); - if (havesb && sblk.b_bno != sblockloc / dev_bsize && !preen && + if (havesb && sblk.b_bno != sblockloc / DEV_BSIZE && !preen && reply("UPDATE STANDARD SUPERBLOCK")) { - sblk.b_bno = sblockloc / dev_bsize; + sblk.b_bno = sblockloc / DEV_BSIZE; sbdirty(); flush(fswritefd, &sblk); } @@ -338,7 +338,7 @@ bread(int fd, char *buf, daddr_t blk, long size) off_t offset; offset = blk; - offset *= dev_bsize; + offset *= DEV_BSIZE; if (lseek(fd, offset, SEEK_SET) < 0) rwerror("SEEK", blk); else if (read(fd, buf, (int)size) == size) @@ -352,14 +352,14 @@ bread(int fd, char *buf, daddr_t blk, long size) for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) { if (read(fd, cp, (int)secsize) != secsize) { (void)lseek(fd, offset + i + secsize, SEEK_SET); - if (secsize != dev_bsize && dev_bsize != 1) + if (secsize != DEV_BSIZE) printf(" %lld (%lld),", - (long long)((blk * dev_bsize + i) / + (long long)((blk * DEV_BSIZE + i) / secsize), - (long long)(blk + i / dev_bsize)); + (long long)(blk + i / DEV_BSIZE)); else printf(" %lld,", - (long long)(blk + i / dev_bsize)); + (long long)(blk + i / DEV_BSIZE)); errs++; } } @@ -377,7 +377,7 @@ bwrite(int fd, char *buf, daddr_t blk, long size) if (fd < 0) return; offset = blk; - offset *= dev_bsize; + offset *= DEV_BSIZE; if (lseek(fd, offset, SEEK_SET) < 0) rwerror("SEEK", blk); else if (write(fd, buf, (int)size) == size) { @@ -388,10 +388,17 @@ bwrite(int fd, char *buf, daddr_t blk, long size) if (lseek(fd, offset, SEEK_SET) < 0) rwerror("SEEK", blk); printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:"); - for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize) - if (write(fd, cp, (int)dev_bsize) != dev_bsize) { - (void)lseek(fd, offset + i + dev_bsize, SEEK_SET); - printf(" %lld,", (long long)(blk + i / dev_bsize)); + for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) + if (write(fd, cp, (int)secsize) != secsize) { + (void)lseek(fd, offset + i + secsize, SEEK_SET); + if (secsize != DEV_BSIZE) + printf(" %lld (%lld),", + (long long)((blk * DEV_BSIZE + i) / + secsize), + (long long)(blk + i / DEV_BSIZE)); + else + printf(" %lld,", + (long long)(blk + i / DEV_BSIZE)); } printf("\n"); return;