aboutsummaryrefslogtreecommitdiff
path: root/sbin/newfs/mkfs.c
diff options
context:
space:
mode:
authorLuigi Rizzo <luigi@FreeBSD.org>2008-12-03 18:36:59 +0000
committerLuigi Rizzo <luigi@FreeBSD.org>2008-12-03 18:36:59 +0000
commit64c8fef580df8cb8a9dbab10ad04b8e427609f0d (patch)
treec4b9b5c278df89601572732efb3483d2b101edfd /sbin/newfs/mkfs.c
parentb87d1601b6605929ba3f800f45db4f426d3b3843 (diff)
downloadsrc-64c8fef580df8cb8a9dbab10ad04b8e427609f0d.tar.gz
src-64c8fef580df8cb8a9dbab10ad04b8e427609f0d.zip
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port can do something similar). This relies on: + minor changes to pass the consistency checks even when working on a file; + an additional option, '-p partition' , to specify the disk partition to initialize; + some changes on the I/O routines to deal with partition offsets. The latter was a bit tricky to implement, see the details in newfs.h: in newfs, I/O is done through libufs which assumes that the file descriptor refers to the whole partition. Introducing support for the offset in libufs would require a non-backward compatible change in the library, to be dealt with a version bump or with symbol versioning. I felt both approaches to be overkill for this specific application, especially because there might be other changes to libufs that might become necessary in the near future. So I used the following trick: - read access is always done by calling bread() directly, so we just add the offset in the (few) places that call bread(); - write access is done through bwrite() and sbwrite(), which in turn calls bwrite(). To avoid rewriting sbwrite(), we supply our own version of bwrite() here, which takes precedence over the version in libufs. MFC after: 4 weeks
Notes
Notes: svn path=/head/; revision=185588
Diffstat (limited to 'sbin/newfs/mkfs.c')
-rw-r--r--sbin/newfs/mkfs.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index b3bbcbf3b351..072e528113f9 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -459,7 +459,7 @@ mkfs(struct partition *pp, char *fsys)
* Wipe out old UFS1 superblock(s) if necessary.
*/
if (!Nflag && Oflag != 1) {
- i = bread(&disk, SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE);
+ i = bread(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE);
if (i == -1)
err(1, "can't read old UFS1 superblock: %s", disk.d_error);
@@ -872,7 +872,7 @@ alloc(int size, int mode)
{
int i, d, blkno, frag;
- bread(&disk, fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
+ bread(&disk, part_ofs + fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
sblock.fs_cgsize);
if (acg.cg_magic != CG_MAGIC) {
printf("cg 0: bad magic number\n");
@@ -925,7 +925,7 @@ iput(union dinode *ip, ino_t ino)
int c;
c = ino_to_cg(&sblock, ino);
- bread(&disk, fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
+ bread(&disk, part_ofs + fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
sblock.fs_cgsize);
if (acg.cg_magic != CG_MAGIC) {
printf("cg 0: bad magic number\n");
@@ -942,7 +942,7 @@ iput(union dinode *ip, ino_t ino)
exit(32);
}
d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino));
- bread(&disk, d, (char *)iobuf, sblock.fs_bsize);
+ bread(&disk, part_ofs + d, (char *)iobuf, sblock.fs_bsize);
if (sblock.fs_magic == FS_UFS1_MAGIC)
((struct ufs1_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
ip->dp1;