-/* $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 $ */
/*
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");
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;
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;
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;
/*
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)),
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);
}
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);
}
-/* $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 $ */
/*
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)
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;
-/* $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 $ */
/*
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;
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);
-/* $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
char *msg = NULL;
int i, *p, cs = 0;
int fsoffs = 0;
+ int offset;
bp->b_blkno = 0;
bp->b_bcount = lp->d_secsize;
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;
}
/* 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;
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);
goto done;
}
- return checkdisklabel(bp->b_data + LABELOFFSET, lp);
+ return checkdisklabel(bp->b_data + offset, lp);
done:
return (msg);
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;
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);
-/* $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 $ */
/*
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");
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);
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 */
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);
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);
}
/*
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);
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;
}
/* 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:
-/* $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 $ */
/*
(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 */
-/* $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 $ */
/*
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);
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;