- fin = fopen(proto, "r");
-#endif
-#ifndef STANDALONE
- if (fin != NULL) {
- getstr();
- f = open(string, 0);
- if (f < 0) {
- printf("%s: cannot open init\n", string);
- goto noinit;
- }
- read(f, (char *)&head, sizeof head);
- c = head.a_text + head.a_data;
- if (c > BSIZE)
- printf("%s: too big\n", string);
- else {
- read(f, buf, c);
- wtfs(BBLOCK, BSIZE, buf);
- }
- close(f);
-noinit:
- n = sblock.fs_size = getnum();
- sblock.fs_ntrak = getnum();
- sblock.fs_nsect = getnum();
- sblock.fs_cpg = getnum();
- } else
-#endif
- {
- charp = "d--777 0 0 $ ";
- n = 0;
- for (f=0; c=proto[f]; f++) {
- if (c<'0' || c>'9') {
- printf("%s: cannot open\n", proto);
- exit(1);
- }
- n = n*10 + (c-'0');
+ if (sblock.fs_fsize < DEV_BSIZE) {
+ printf("fragment size %d is too small, minimum is %d\n",
+ sblock.fs_fsize, DEV_BSIZE);
+ exit(1);
+ }
+ if (sblock.fs_bsize < MINBSIZE) {
+ printf("block size %d is too small, minimum is %d\n",
+ sblock.fs_bsize, MINBSIZE);
+ exit(1);
+ }
+ if (sblock.fs_bsize < sblock.fs_fsize) {
+ printf("block size (%d) cannot be smaller than fragment size (%d)\n",
+ sblock.fs_bsize, sblock.fs_fsize);
+ exit(1);
+ }
+ sblock.fs_bmask = ~(sblock.fs_bsize - 1);
+ sblock.fs_fmask = ~(sblock.fs_fsize - 1);
+ 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_frag = numfrags(&sblock, sblock.fs_bsize);
+ if (sblock.fs_frag > MAXFRAG) {
+ printf("fragment size %d is too small, minimum with block size %d is %d\n",
+ sblock.fs_fsize, sblock.fs_bsize,
+ sblock.fs_bsize / MAXFRAG);
+ exit(1);
+ }
+ sblock.fs_sblkno =
+ roundup(howmany(BBSIZE + SBSIZE, sblock.fs_fsize), sblock.fs_frag);
+ sblock.fs_cblkno = (daddr_t)(sblock.fs_sblkno +
+ roundup(howmany(SBSIZE, sblock.fs_fsize), sblock.fs_frag));
+ sblock.fs_iblkno = sblock.fs_cblkno + sblock.fs_frag;
+ sblock.fs_cgoffset = roundup(
+ howmany(sblock.fs_nsect, sblock.fs_fsize / DEV_BSIZE),
+ sblock.fs_frag);
+ for (sblock.fs_cgmask = 0xffffffff, i = sblock.fs_ntrak; i > 1; i >>= 1)
+ sblock.fs_cgmask <<= 1;
+ if (!POWEROF2(sblock.fs_ntrak))
+ sblock.fs_cgmask <<= 1;
+ for (sblock.fs_cpc = NSPB(&sblock), i = sblock.fs_spc;
+ sblock.fs_cpc > 1 && (i & 1) == 0;
+ sblock.fs_cpc >>= 1, i >>= 1)
+ /* void */;
+ if (sblock.fs_cpc > MAXCPG) {
+ printf("maximum block size with nsect %d and ntrak %d is %d\n",
+ sblock.fs_nsect, sblock.fs_ntrak,
+ sblock.fs_bsize / (sblock.fs_cpc / MAXCPG));
+ exit(1);
+ }
+ /*
+ * collect and verify the number of cylinders per group
+ */
+ if (argc > 6) {
+ sblock.fs_cpg = atoi(argv[6]);
+ sblock.fs_fpg = (sblock.fs_cpg * sblock.fs_spc) / NSPF(&sblock);
+ } else {
+ sblock.fs_cpg = MAX(sblock.fs_cpc, DESCPG);
+ sblock.fs_fpg = (sblock.fs_cpg * sblock.fs_spc) / NSPF(&sblock);
+ while (sblock.fs_fpg / sblock.fs_frag > MAXBPG(&sblock) &&
+ sblock.fs_cpg > sblock.fs_cpc) {
+ sblock.fs_cpg -= sblock.fs_cpc;
+ sblock.fs_fpg =
+ (sblock.fs_cpg * sblock.fs_spc) / NSPF(&sblock);