Hi,

makefs(8) creates an ffs1 filesystem by default, and the generated
filesystem image passes fsck checks. However, when creating an ffs2
filesystem using the -o version=2 option, the generated filesystem image
fails fsck checks.

This patch resolves the issue by ensuring that the superblock parameters
for the ffs2 filesystem match those set by newfs.

---

diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c
index a4d57c008a2..6369af6ba4a 100644
--- a/usr.sbin/makefs/ffs/mkfs.c
+++ b/usr.sbin/makefs/ffs/mkfs.c
@@ -222,13 +222,9 @@ ffs_mkfs(const char *fsys, const fsinfo_t
*fsopts, time_t tstamp)
        sblock.fs_fmask = ~(sblock.fs_fsize - 1);
        sblock.fs_qbmask = ~sblock.fs_bmask;
        sblock.fs_qfmask = ~sblock.fs_fmask;
-       for (sblock.fs_bshift = 0, i = sblock.fs_bsize; i > 1; i >>= 1)
-               sblock.fs_bshift++;
-       for (sblock.fs_fshift = 0, i = sblock.fs_fsize; i > 1; i >>= 1)
-               sblock.fs_fshift++;
+       sblock.fs_bshift = ilog2(sblock.fs_bsize);
+       sblock.fs_fshift = ilog2(sblock.fs_fsize);
        sblock.fs_frag = numfrags(&sblock, sblock.fs_bsize);
-       for (sblock.fs_fragshift = 0, i = sblock.fs_frag; i > 1; i >>= 1)
-               sblock.fs_fragshift++;
        if (sblock.fs_frag > MAXFRAG) {
                printf("fragment size %d is too small, "
                        "minimum with block size %d is %d\n",
@@ -236,8 +232,12 @@ ffs_mkfs(const char *fsys, const fsinfo_t
*fsopts, time_t tstamp)
                    sblock.fs_bsize / MAXFRAG);
                exit(21);
        }
+       sblock.fs_fragshift = ilog2(sblock.fs_frag);
        sblock.fs_fsbtodb = ilog2(sblock.fs_fsize / sectorsize);
        sblock.fs_size = fssize = dbtofsb(&sblock, fssize);
+       sblock.fs_nspf = sblock.fs_fsize / sectorsize;
+       sblock.fs_nrpos = 1;
+       sblock.fs_cpg = 1;

        if (Oflag <= 1) {
                sblock.fs_magic = FS_UFS1_MAGIC;
@@ -251,13 +251,10 @@ ffs_mkfs(const char *fsys, const fsinfo_t
*fsopts, time_t tstamp)
                sblock.fs_ffs1_size = sblock.fs_size;
                sblock.fs_rotdelay = 0;
                sblock.fs_rps = 60;
-               sblock.fs_nspf = sblock.fs_fsize / sectorsize;
-               sblock.fs_cpg = 1;
                sblock.fs_interleave = 1;
                sblock.fs_trackskew = 0;
                sblock.fs_cpc = 0;
                sblock.fs_postblformat = 1;
-               sblock.fs_nrpos = 1;
        } else {
                sblock.fs_magic = FS_UFS2_MAGIC;
 #if 0 /* XXX makefs is used for small filesystems. */

Reply via email to