From: krw Date: Fri, 8 Aug 2008 23:49:53 +0000 (+0000) Subject: Admit b_blkno means block number; a block is DEV_BSIZE (a.k.a. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f576767c0af4eb738c184d91beb1f0a6b9e3b2e4;p=openbsd Admit b_blkno means block number; a block is DEV_BSIZE (a.k.a. 512) bytes; ffs is inextricably tied to using b_blkno and disklabel always uses sectorsize units. Thus use DEV_BSIZE units for all fields describing ffs filesystems and convert to/from sectors where required. This enables the creation and use of ffs filesystems on non-512 byte sectorsize devices. This diff allows i386 and sgi (the two test platforms) to find disklabels that are not on a sectorsize boundary. Same change to further archs coming. This is a no-op on 512-byte sectorsize devices. This work triggered by jsing@'s need to create ffs filesystems on sgi cdroms so we can create cdrom install media for sgi. sgi testing by jsing@ ok jsing@ pedro@ "looks sane" beck@ weingart@ --- diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 31979558c5f..6ae21a3f170 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfs.c,v 1.71 2008/01/05 19:51:55 otto Exp $ */ +/* $OpenBSD: mkfs.c,v 1.72 2008/08/08 23:49:53 krw Exp $ */ /* $NetBSD: mkfs.c,v 1.25 1995/06/18 21:35:38 cgd Exp $ */ /* @@ -174,7 +174,7 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, mode_t mfsmode, time(&utime); #endif if (mfs) { - quad_t sz = (quad_t)fssize * sectorsize; + quad_t sz = (quad_t)fssize * DEV_BSIZE; if (sz > SIZE_T_MAX) { errno = ENOMEM; err(12, "mmap"); @@ -197,7 +197,7 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, mode_t mfsmode, errx(13, "preposterous size %lld, max is %lld", fssize, MAXDISKSIZE); - wtfs(fssize - 1, sectorsize, (char *)&sblock); + wtfs(fssize - (sectorsize / DEV_BSIZE), sectorsize, (char *)&sblock); sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT; sblock.fs_avgfilesize = avgfilesize; @@ -248,9 +248,9 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, mode_t mfsmode, sblock.fs_bsize / MAXFRAG); } sblock.fs_fragshift = ilog2(sblock.fs_frag); - sblock.fs_fsbtodb = ilog2(sblock.fs_fsize / sectorsize); + sblock.fs_fsbtodb = ilog2(sblock.fs_fsize / DEV_BSIZE); sblock.fs_size = dbtofsb(&sblock, fssize); - sblock.fs_nspf = sblock.fs_fsize / sectorsize; + sblock.fs_nspf = sblock.fs_fsize / DEV_BSIZE; sblock.fs_maxcontig = 1; sblock.fs_nrpos = 1; sblock.fs_cpg = 1; @@ -506,15 +506,15 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, mode_t mfsmode, if (fsun1 == NULL) err(39, "calloc"); fs1 = &fsun1->fs; - rdfs(SBLOCK_UFS1 / sectorsize, SBSIZE, (char *)fs1); + rdfs(SBLOCK_UFS1 / DEV_BSIZE, SBSIZE, (char *)fs1); if (fs1->fs_magic == FS_UFS1_MAGIC) { fs1->fs_magic = FS_BAD_MAGIC; - wtfs(SBLOCK_UFS1 / sectorsize, SBSIZE, (char *)fs1); + wtfs(SBLOCK_UFS1 / DEV_BSIZE, SBSIZE, (char *)fs1); } free(fsun1); } - wtfs((int)sblock.fs_sblockloc / sectorsize, SBSIZE, (char *)&sblock); + wtfs((int)sblock.fs_sblockloc / DEV_BSIZE, SBSIZE, (char *)&sblock); sblock.fs_magic = (Oflag <= 1) ? FS_UFS1_MAGIC : FS_UFS2_MAGIC; /* @@ -583,7 +583,7 @@ mkfs(struct partition *pp, char *fsys, int fi, int fo, mode_t mfsmode, errx(32, "fsinit2 failed"); } - wtfs((int)sblock.fs_sblockloc / sectorsize, SBSIZE, (char *)&sblock); + wtfs((int)sblock.fs_sblockloc / DEV_BSIZE, SBSIZE, (char *)&sblock); for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize) wtfs(fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)), @@ -1004,10 +1004,10 @@ rdfs(daddr64_t bno, int size, void *bf) int n; if (mfs) { - memcpy(bf, membase + bno * sectorsize, size); + memcpy(bf, membase + bno * DEV_BSIZE, size); return; } - n = pread(fsi, bf, size, (off_t)bno * sectorsize); + n = pread(fsi, bf, size, (off_t)bno * DEV_BSIZE); if (n != size) { err(34, "rdfs: read error on block %lld", bno); } @@ -1022,12 +1022,12 @@ wtfs(daddr64_t bno, int size, void *bf) int n; if (mfs) { - memcpy(membase + bno * sectorsize, bf, size); + memcpy(membase + bno * DEV_BSIZE, bf, size); return; } if (Nflag) return; - n = pwrite(fso, bf, size, (off_t)bno * sectorsize); + n = pwrite(fso, bf, size, (off_t)bno * DEV_BSIZE); if (n != size) { err(36, "wtfs: write error on block %lld", bno); } diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index 23c4d5aa406..8944333ac47 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newfs.c,v 1.80 2008/08/04 18:46:32 otto Exp $ */ +/* $OpenBSD: newfs.c,v 1.81 2008/08/08 23:49:53 krw Exp $ */ /* $NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $ */ /* @@ -433,6 +433,7 @@ havelabel: if (sectorsize <= 0) fatal("%s: no default sector size", argv[0]); } + fssize *= sectorsize / DEV_BSIZE; if (fsize == 0) { fsize = DISKLABELV1_FFS_FSIZE(pp->p_fragblock); if (fsize <= 0) @@ -480,7 +481,7 @@ havelabel: struct mfs_args args; memset(&args, 0, sizeof(args)); args.base = membase; - args.size = fssize * sectorsize; + args.size = fssize * DEV_BSIZE; args.export_info.ex_root = -2; if (mntflags & MNT_RDONLY) args.export_info.ex_flags = MNT_EXRDONLY; diff --git a/sys/arch/i386/i386/disksubr.c b/sys/arch/i386/i386/disksubr.c index 35ec17d595a..ea875b7f36b 100644 --- a/sys/arch/i386/i386/disksubr.c +++ b/sys/arch/i386/i386/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.97 2008/06/12 06:58:34 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.98 2008/08/08 23:49:53 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -128,6 +128,7 @@ int writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) { int error = EIO, partoff = -1; + int offset; struct disklabel *dlp; struct buf *bp = NULL; @@ -139,14 +140,15 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) goto done; /* Read it in, slap the new label in, and write it back out */ - bp->b_blkno = partoff + LABELSECTOR; + bp->b_blkno = DL_BLKTOSEC(lp, partoff+LABELSECTOR) * DL_BLKSPERSEC(lp); + offset = DL_BLKOFFSET(lp, partoff + LABELSECTOR) + LABELOFFSET; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ | B_RAW; (*strat)(bp); if ((error = biowait(bp)) != 0) goto done; - dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); + dlp = (struct disklabel *)(bp->b_data + offset); *dlp = *lp; bp->b_flags = B_BUSY | B_WRITE | B_RAW; (*strat)(bp); diff --git a/sys/arch/sgi/sgi/disksubr.c b/sys/arch/sgi/sgi/disksubr.c index 9926730f4ae..f0745769e71 100644 --- a/sys/arch/sgi/sgi/disksubr.c +++ b/sys/arch/sgi/sgi/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.8 2008/07/20 13:46:16 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.9 2008/08/08 23:49:53 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -116,6 +116,7 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), char *msg = NULL; int i, *p, cs = 0; int fsoffs = 0; + int offset; bp->b_blkno = 0; bp->b_bcount = lp->d_secsize; @@ -138,7 +139,7 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), msg = "no BSD partition"; goto done; } - fsoffs = dlp->partitions[0].first; + fsoffs = dlp->partitions[0].first * (dlp->dp.dp_secbytes / DEV_BSIZE); if (spoofonly) goto finished; @@ -153,6 +154,7 @@ readsgilabel(struct buf *bp, void (*strat)(struct buf *), } /* Set up partitions i-l if there is no BSD label. */ + DL_SETDSIZE(lp, (DL_GETDSIZE(lp)*lp->d_secsize) / dlp->dp.dp_secbytes); lp->d_secsize = dlp->dp.dp_secbytes; lp->d_nsectors = dlp->dp.dp_secs; lp->d_ntracks = dlp->dp.dp_trks0; @@ -187,7 +189,8 @@ finished: if (spoofonly) goto done; - bp->b_blkno = fsoffs + LABELSECTOR; + bp->b_blkno = DL_BLKTOSEC(lp, fsoffs + LABELSECTOR) * DL_BLKSPERSEC(lp); + offset = DL_BLKOFFSET(lp, fsoffs + LABELSECTOR) + LABELOFFSET; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ | B_RAW; (*strat)(bp); @@ -196,7 +199,7 @@ finished: goto done; } - return checkdisklabel(bp->b_data + LABELOFFSET, lp); + return checkdisklabel(bp->b_data + offset, lp); done: return (msg); @@ -209,6 +212,7 @@ int writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) { int error = EIO, partoff = -1; + int offset; struct buf *bp = NULL; struct disklabel *dlp; @@ -221,14 +225,15 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) goto done; /* Read it in, slap the new label in, and write it back out */ - bp->b_blkno = partoff + LABELSECTOR; + bp->b_blkno = DL_BLKTOSEC(lp, partoff+LABELSECTOR) * DL_BLKSPERSEC(lp); + offset = DL_BLKOFFSET(lp, partoff + LABELSECTOR) + LABELOFFSET; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ | B_RAW; (*strat)(bp); if ((error = biowait(bp)) != 0) goto done; - dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); + dlp = (struct disklabel *)(bp->b_data + offset); *dlp = *lp; bp->b_flags = B_BUSY | B_WRITE | B_RAW; (*strat)(bp); diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 186ff615e10..41deb07f29b 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.79 2008/06/25 15:26:43 reyk Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.80 2008/08/08 23:49:53 krw Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -378,6 +378,7 @@ readdoslabel(struct buf *bp, void (*strat)(struct buf *), daddr64_t part_blkno = DOSBBSECTOR; int dospartoff = 0, i, ourpart = -1; int wander = 1, n = 0, loop = 0; + int offset; if (lp->d_secpercyl == 0) return ("invalid label, d_secpercyl == 0"); @@ -397,7 +398,8 @@ readdoslabel(struct buf *bp, void (*strat)(struct buf *), part_blkno = extoff; /* read boot record */ - bp->b_blkno = part_blkno; + bp->b_blkno = DL_BLKTOSEC(lp, part_blkno) * DL_BLKSPERSEC(lp); + offset = DL_BLKOFFSET(lp, part_blkno) + DOSPARTOFF; bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ | B_RAW; (*strat)(bp); @@ -407,7 +409,7 @@ readdoslabel(struct buf *bp, void (*strat)(struct buf *), return ("dos partition I/O error"); } - bcopy(bp->b_data + DOSPARTOFF, dp, sizeof(dp)); + bcopy(bp->b_data + offset, dp, sizeof(dp)); if (ourpart == -1) { /* Search for our MBR partition */ @@ -548,7 +550,9 @@ notfat: if (spoofonly) return (NULL); - bp->b_blkno = dospartoff + DOS_LABELSECTOR; + bp->b_blkno = DL_BLKTOSEC(lp, dospartoff + DOS_LABELSECTOR) * + DL_BLKSPERSEC(lp); + offset = DL_BLKOFFSET(lp, dospartoff + DOS_LABELSECTOR); bp->b_bcount = lp->d_secsize; bp->b_flags = B_BUSY | B_READ | B_RAW; (*strat)(bp); @@ -556,7 +560,7 @@ notfat: return ("disk label I/O error"); /* sub-MBR disklabels are always at a LABELOFFSET of 0 */ - return checkdisklabel(bp->b_data, lp); + return checkdisklabel(bp->b_data + offset, lp); } /* @@ -620,7 +624,6 @@ setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_int openmask) int bounds_check_with_label(struct buf *bp, struct disklabel *lp, int wlabel) { -#define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = &lp->d_partitions[DISKPART(bp->b_dev)]; daddr64_t sz = howmany(bp->b_bcount, DEV_BSIZE); @@ -632,8 +635,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, int wlabel) panic("bounds_check_with_label %lld %lld\n", bp->b_blkno, sz); /* beyond partition? */ - if (bp->b_blkno + sz > blockpersec(DL_GETPSIZE(p), lp)) { - sz = blockpersec(DL_GETPSIZE(p), lp) - bp->b_blkno; + if (bp->b_blkno + sz > DL_SECTOBLK(lp, DL_GETPSIZE(p))) { + sz = DL_SECTOBLK(lp, DL_GETPSIZE(p)) - bp->b_blkno; if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; @@ -648,8 +651,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp, int wlabel) } /* calculate cylinder for disksort to order transfers with */ - bp->b_cylinder = (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp)) / - blockpersec(lp->d_secpercyl, lp); + bp->b_cylinder = (bp->b_blkno + DL_SECTOBLK(lp, DL_GETPOFFSET(p))) / + DL_SECTOBLK(lp, lp->d_secpercyl); return (1); bad: diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index 9c300ec595c..a6fbc916ed1 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.41 2008/01/14 19:02:11 otto Exp $ */ +/* $OpenBSD: disklabel.h,v 1.42 2008/08/08 23:49:53 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */ /* @@ -227,6 +227,11 @@ struct __partitionv0 { /* the partition table */ (d)->d_secperunit = x; \ } while (0) +#define DL_BLKSPERSEC(d) ((d)->d_secsize / DEV_BSIZE) +#define DL_SECTOBLK(d, n) ((n) * DL_BLKSPERSEC(d)) +#define DL_BLKTOSEC(d, n) (((n) * DEV_BSIZE) / (d)->d_secsize) +#define DL_BLKOFFSET(d, n) (((n) * DEV_BSIZE) % (d)->d_secsize) + /* d_type values: */ #define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ #define DTYPE_MSCP 2 /* MSCP */ diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c index 3f6af7c9954..926ec92d59d 100644 --- a/sys/ufs/ffs/ffs_vfsops.c +++ b/sys/ufs/ffs/ffs_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_vfsops.c,v 1.115 2008/08/08 09:02:25 thib Exp $ */ +/* $OpenBSD: ffs_vfsops.c,v 1.116 2008/08/08 23:49:53 krw Exp $ */ /* $NetBSD: ffs_vfsops.c,v 1.19 1996/02/09 22:22:26 christos Exp $ */ /* @@ -554,7 +554,7 @@ ffs_reload(struct mount *mountp, struct ucred *cred, struct proc *p) fs = VFSTOUFS(mountp)->um_fs; - error = bread(devvp, (daddr64_t)(fs->fs_sblockloc / size), SBSIZE, + error = bread(devvp, (daddr64_t)(fs->fs_sblockloc / DEV_BSIZE), SBSIZE, NOCRED, &bp); if (error) { brelse(bp); @@ -716,7 +716,7 @@ ffs_mountfs(struct vnode *devvp, struct mount *mp, struct proc *p) bp = NULL; } - error = bread(devvp, sbtry[i] / size, SBSIZE, cred, &bp); + error = bread(devvp, sbtry[i] / DEV_BSIZE, SBSIZE, cred, &bp); if (error) goto out;