sun
[unix-history] / usr / src / sbin / newfs / mkfs.c
index a4222b9..81e78a5 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)mkfs.c      2.2 (Berkeley) %G%";
+static char *sccsid = "@(#)mkfs.c      2.6 (Berkeley) %G%";
 
 /*
  * make file system for cylinder-group style file systems
 
 /*
  * make file system for cylinder-group style file systems
@@ -6,6 +6,72 @@ static char *sccsid = "@(#)mkfs.c      2.2 (Berkeley) %G%";
  * usage: mkfs special size [ nsect ntrak bsize fsize cpg ]
  */
 
  * usage: mkfs special size [ nsect ntrak bsize fsize cpg ]
  */
 
+/*
+ * The following constants set the defaults used for the number
+ * of sectors (fs_nsect), and number of tracks (fs_ntrak).
+ */
+#define DFLNSECT       32
+#define DFLNTRAK       16
+
+/*
+ * The following two constants set the default block and fragment sizes.
+ * Both constants must be a power of 2 and meet the following constraints:
+ *     MINBSIZE <= DESBLKSIZE <= MAXBSIZE
+ *     DEV_BSIZE <= DESFRAGSIZE <= DESBLKSIZE
+ *     DESBLKSIZE / DESFRAGSIZE <= 8
+ */
+#define DESBLKSIZE     8192
+#define DESFRAGSIZE    1024
+
+/*
+ * Cylinder groups may have up to MAXCPG cylinders. The actual
+ * number used depends upon how much information can be stored
+ * on a single cylinder. The default is to used 16 cylinders
+ * per group.
+ */
+#define        DESCPG          16      /* desired fs_cpg */
+
+/*
+ * MINFREE gives the minimum acceptable percentage of file system
+ * blocks which may be free. If the freelist drops below this level
+ * only the superuser may continue to allocate blocks. This may
+ * be set to 0 if no reserve of free blocks is deemed necessary,
+ * however throughput drops by fifty percent if the file system
+ * is run at between 90% and 100% full; thus the default value of
+ * fs_minfree is 10%.
+ */
+#define MINFREE                10
+
+/*
+ * ROTDELAY gives the minimum number of milliseconds to initiate
+ * another disk transfer on the same cylinder. It is used in
+ * determining the rotationally optimal layout for disk blocks
+ * within a file; the default of fs_rotdelay is 2ms.
+ */
+#define ROTDELAY       2
+
+/*
+ * MAXCONTIG sets the default for the maximum number of blocks
+ * that may be allocated sequentially. Since UNIX drivers are
+ * not capable of scheduling multi-block transfers, this defaults
+ * to 1 (ie no contiguous blocks are allocated).
+ */
+#define MAXCONTIG      1
+
+/*
+ * MAXBLKPG determines the maximum number of data blocks which are
+ * placed in a single cylinder group. This is currently a function
+ * of the block and fragment size of the file system.
+ */
+#define MAXBLKPG(fs)   ((fs)->fs_fsize / sizeof(daddr_t))
+
+/*
+ * Each file system has a number of inodes statically allocated.
+ * We allocate one inode slot per NBPI bytes, expecting this
+ * to be far more than we will ever need.
+ */
+#define        NBPI            2048
+
 #ifndef STANDALONE
 #include <stdio.h>
 #include <a.out.h>
 #ifndef STANDALONE
 #include <stdio.h>
 #include <a.out.h>
@@ -20,7 +86,7 @@ static        char *sccsid = "@(#)mkfs.c      2.2 (Berkeley) %G%";
 #include "../h/inode.h"
 #include "../h/fs.h"
 #endif
 #include "../h/inode.h"
 #include "../h/fs.h"
 #endif
-#include <ndir.h>
+#include <dir.h>
 
 #define UMASK          0755
 #define MAXINOPB       (MAXBSIZE / sizeof(struct dinode))
 
 #define UMASK          0755
 #define MAXINOPB       (MAXBSIZE / sizeof(struct dinode))
@@ -113,11 +179,11 @@ main(argc, argv)
        if (argc > 4)
                sblock.fs_bsize = atoi(argv[4]);
        else
        if (argc > 4)
                sblock.fs_bsize = atoi(argv[4]);
        else
-               sblock.fs_bsize = MAXBSIZE;
+               sblock.fs_bsize = DESBLKSIZE;
        if (argc > 5)
                sblock.fs_fsize = atoi(argv[5]);
        else
        if (argc > 5)
                sblock.fs_fsize = atoi(argv[5]);
        else
-               sblock.fs_fsize = MAX(sblock.fs_bsize / DESFRAG, DEV_BSIZE);
+               sblock.fs_fsize = DESFRAGSIZE;
        if (!POWEROF2(sblock.fs_bsize)) {
                printf("block size must be a power of 2, not %d\n",
                    sblock.fs_bsize);
        if (!POWEROF2(sblock.fs_bsize)) {
                printf("block size must be a power of 2, not %d\n",
                    sblock.fs_bsize);
@@ -351,6 +417,8 @@ next:
        sblock.fs_magic = FS_MAGIC;
        sblock.fs_rotdelay = ROTDELAY;
        sblock.fs_minfree = MINFREE;
        sblock.fs_magic = FS_MAGIC;
        sblock.fs_rotdelay = ROTDELAY;
        sblock.fs_minfree = MINFREE;
+       sblock.fs_maxcontig = MAXCONTIG;
+       sblock.fs_maxbpg = MAXBLKPG(&sblock);
        sblock.fs_rps = 60;     /* assume disk speed == 60 HZ */
        sblock.fs_cgrotor = 0;
        sblock.fs_cstotal.cs_ndir = 0;
        sblock.fs_rps = 60;     /* assume disk speed == 60 HZ */
        sblock.fs_cgrotor = 0;
        sblock.fs_cstotal.cs_ndir = 0;
@@ -398,7 +466,7 @@ next:
        /* 
         * Write out the duplicate super blocks
         */
        /* 
         * Write out the duplicate super blocks
         */
-       for (cylno = 1; cylno < sblock.fs_ncg; cylno++)
+       for (cylno = 0; cylno < sblock.fs_ncg; cylno++)
                wtfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)),
                    SBSIZE, (char *)&sblock);
 #ifndef STANDALONE
                wtfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)),
                    SBSIZE, (char *)&sblock);
 #ifndef STANDALONE
@@ -431,7 +499,10 @@ initcg(cylno)
        acg.cg_time = utime;
        acg.cg_magic = CG_MAGIC;
        acg.cg_cgx = cylno;
        acg.cg_time = utime;
        acg.cg_magic = CG_MAGIC;
        acg.cg_cgx = cylno;
-       acg.cg_ncyl = sblock.fs_cpg;
+       if (cylno == sblock.fs_ncg - 1)
+               acg.cg_ncyl = sblock.fs_ncyl % sblock.fs_cpg;
+       else
+               acg.cg_ncyl = sblock.fs_cpg;
        acg.cg_niblk = sblock.fs_ipg;
        acg.cg_ndblk = dmax - cbase;
        acg.cg_cs.cs_ndir = 0;
        acg.cg_niblk = sblock.fs_ipg;
        acg.cg_ndblk = dmax - cbase;
        acg.cg_cs.cs_ndir = 0;
@@ -508,9 +579,11 @@ initcg(cylno)
                        setbit(acg.cg_free, d);
                        acg.cg_cs.cs_nffree++;
                }
                        setbit(acg.cg_free, d);
                        acg.cg_cs.cs_nffree++;
                }
+               for (; d % sblock.fs_frag != 0; d++)
+                       clrbit(acg.cg_free, d);
        }
        }
-       for (; d < MAXBPG(&sblock); d++)
-               clrbit(acg.cg_free, d);
+       for (d /= sblock.fs_frag; d < MAXBPG(&sblock); d ++)
+               clrblock(&sblock, acg.cg_free, d);
        sblock.fs_cstotal.cs_ndir += acg.cg_cs.cs_ndir;
        sblock.fs_cstotal.cs_nffree += acg.cg_cs.cs_nffree;
        sblock.fs_cstotal.cs_nbfree += acg.cg_cs.cs_nbfree;
        sblock.fs_cstotal.cs_ndir += acg.cg_cs.cs_ndir;
        sblock.fs_cstotal.cs_nffree += acg.cg_cs.cs_nffree;
        sblock.fs_cstotal.cs_nbfree += acg.cg_cs.cs_nbfree;
@@ -729,6 +802,7 @@ wtfs(bno, size, bf)
        }
 }
 
        }
 }
 
+#ifndef STANDALONE
 /*
  * copy a block
  */
 /*
  * copy a block
  */
@@ -738,6 +812,7 @@ bcopy(from, to, size)
 {
        asm("   movc3   12(ap),*4(ap),*8(ap)");
 }
 {
        asm("   movc3   12(ap),*4(ap),*8(ap)");
 }
+#endif
 
 /*
  * check if a block is available
 
 /*
  * check if a block is available
@@ -762,7 +837,11 @@ isblock(fs, cp, h)
                mask = 0x01 << (h & 0x7);
                return ((cp[h >> 3] & mask) == mask);
        default:
                mask = 0x01 << (h & 0x7);
                return ((cp[h >> 3] & mask) == mask);
        default:
+#ifdef STANDALONE
+               printf("isblock bad fs_frag %d\n", fs->fs_frag);
+#else
                fprintf(stderr, "isblock bad fs_frag %d\n", fs->fs_frag);
                fprintf(stderr, "isblock bad fs_frag %d\n", fs->fs_frag);
+#endif
                return;
        }
 }
                return;
        }
 }
@@ -789,7 +868,11 @@ clrblock(fs, cp, h)
                cp[h >> 3] &= ~(0x01 << (h & 0x7));
                return;
        default:
                cp[h >> 3] &= ~(0x01 << (h & 0x7));
                return;
        default:
+#ifdef STANDALONE
+               printf("clrblock bad fs_frag %d\n", fs->fs_frag);
+#else
                fprintf(stderr, "clrblock bad fs_frag %d\n", fs->fs_frag);
                fprintf(stderr, "clrblock bad fs_frag %d\n", fs->fs_frag);
+#endif
                return;
        }
 }
                return;
        }
 }
@@ -816,7 +899,11 @@ setblock(fs, cp, h)
                cp[h >> 3] |= (0x01 << (h & 0x7));
                return;
        default:
                cp[h >> 3] |= (0x01 << (h & 0x7));
                return;
        default:
+#ifdef STANDALONE
+               printf("setblock bad fs_frag %d\n", fs->fs_frag);
+#else
                fprintf(stderr, "setblock bad fs_frag %d\n", fs->fs_frag);
                fprintf(stderr, "setblock bad fs_frag %d\n", fs->fs_frag);
+#endif
                return;
        }
 }
                return;
        }
 }