merge common code from dmf and dmz drivers
[unix-history] / usr / src / usr.sbin / diskpart / diskpart.c
index 6315225..a8e44ff 100644 (file)
@@ -1,6 +1,18 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)diskpart.c 4.1 (Berkeley) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1983 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)diskpart.c 5.5 (Berkeley) %G%";
+#endif not lint
 
 /*
  * Program to calculate standard disk partition sizes.
 
 /*
  * Program to calculate standard disk partition sizes.
@@ -47,22 +59,24 @@ struct      defparam {
        int     p_fsize;        /* frag size */
 } defparam[NPARTITIONS] = {
        { 8192, 1024 },         /* a */
        int     p_fsize;        /* frag size */
 } defparam[NPARTITIONS] = {
        { 8192, 1024 },         /* a */
-       { 0 },                  /* b */
-       { 0 },                  /* c */
-       { 8192, 1024 },         /* d */
-       { 4096, 512 },          /* e */
-       { 4096, 1024 },         /* f */
-       { 4096, 1024 },         /* g */
-       { 4096, 512 }           /* h */
+       { 8192, 1024 },         /* b */
+       { 8192, 1024 },         /* c */
+       { 4096, 512 },          /* d */
+       { 8192, 1024 },         /* e */
+       { 8192, 1024 },         /* f */
+       { 8192, 1024 },         /* g */
+       { 8192, 1024 }          /* h */
 };
 
 /*
  * Each disk has some space reserved for a bad sector
 };
 
 /*
  * Each disk has some space reserved for a bad sector
- * forwarding table.  While DEC standard 144 uses only
- * the first 5 even numbered sectors in the last track
- * of the last cylinder, we reserve 3 tracks for expansion.
+ * forwarding table.  DEC standard 144 uses the first
+ * 5 even numbered sectors in the last track of the
+ * last cylinder for replicated storage of the bad sector
+ * table; another 126 sectors past this is needed as a
+ * pool of replacement sectors.
  */
  */
-int    badsecttable = 3;       /* # tracks */
+int    badsecttable = 126;     /* # sectors */
 
 int    pflag;                  /* print device driver partition tables */
 int    dflag;                  /* print disktab entry */
 
 int    pflag;                  /* print device driver partition tables */
 int    dflag;                  /* print disktab entry */
@@ -101,8 +115,18 @@ main(argc, argv)
                }
        }
        spc = dp->d_nsectors * dp->d_ntracks;
                }
        }
        spc = dp->d_nsectors * dp->d_ntracks;
-       badsecttable *= dp->d_nsectors;
+       /*
+        * Bad sector table contains one track for the replicated
+        * copies of the table and enough full tracks preceding
+        * the last track to hold the pool of free blocks to which
+        * bad sectors are mapped.
+        */
+       badsecttable = dp->d_nsectors + roundup(badsecttable, dp->d_nsectors);
        threshhold = howmany(spc, badsecttable);
        threshhold = howmany(spc, badsecttable);
+       if (dp->d_badsectforw == 0) {
+               badsecttable = 0;
+               threshhold = 0;
+       }
 
        /* 
         * Figure out if disk is large enough for
 
        /* 
         * Figure out if disk is large enough for
@@ -142,6 +166,8 @@ main(argc, argv)
        defpart[def][PART('f')] = numcyls[PART('f')] * spc - badsecttable;
        defpart[def][PART('g')] = numcyls[PART('g')] * spc - badsecttable;
        defpart[def][PART('c')] = numcyls[PART('c')] * spc;
        defpart[def][PART('f')] = numcyls[PART('f')] * spc - badsecttable;
        defpart[def][PART('g')] = numcyls[PART('g')] * spc - badsecttable;
        defpart[def][PART('c')] = numcyls[PART('c')] * spc;
+       if (!pflag)
+               defpart[def][PART('c')] -= badsecttable;
 
        /*
         * Calculate starting cylinder number for each partition.
 
        /*
         * Calculate starting cylinder number for each partition.
@@ -164,14 +190,23 @@ main(argc, argv)
                                printf("\t0,\t0,\n");
                                continue;
                        }
                                printf("\t0,\t0,\n");
                                continue;
                        }
-                       printf("\t%d,\t%d,\t\t/* %c=cyl %d thru %d */\n",
-                               defpart[def][part], startcyl[part],
-                               'A' + part, startcyl[part],
-                               startcyl[part] + numcyls[part] - 1);
+                       if (dp->d_sectoffset == 0) {
+                              printf("\t%d,\t%d,\t\t/* %c=cyl %d thru %d */\n",
+                                       defpart[def][part], startcyl[part],
+                                       'A' + part, startcyl[part],
+                                       startcyl[part] + numcyls[part] - 1);
+                               continue;
+                       }
+                       printf("\t%d,\t%d,\t\t/* %c=sectors %d thru %d */\n",
+                               defpart[def][part], spc * startcyl[part],
+                               'A' + part, spc * startcyl[part],
+                               spc * startcyl[part] + defpart[def][part] - 1);
                }
                exit(0);
        }
        if (dflag) {
                }
                exit(0);
        }
        if (dflag) {
+               int nparts;
+
                /*
                 * In case the disk is in the ``in-between'' range
                 * where the 'g' partition is smaller than the 'h'
                /*
                 * In case the disk is in the ``in-between'' range
                 * where the 'g' partition is smaller than the 'h'
@@ -188,17 +223,24 @@ main(argc, argv)
                        defparam[PART('g')].p_fsize = temp;
                }
                printf("%s:\\\n", dp->d_name);
                        defparam[PART('g')].p_fsize = temp;
                }
                printf("%s:\\\n", dp->d_name);
-               printf("\t:ty=%s:ns#%d:nt#%d:nc#%d:\\\n", dp->d_type,
-                       dp->d_nsectors, dp->d_ntracks, dp->d_ncylinders);
+               printf("\t:ty=%s:ns#%d:nt#%d:nc#%d:%s%s\\\n", dp->d_type,
+                       dp->d_nsectors, dp->d_ntracks, dp->d_ncylinders,
+                       dp->d_badsectforw ? "sf:" : "",
+                       dp->d_sectoffset ? "so:" : "");
+               for (nparts = 0, part = PART('a'); part < NPARTITIONS; part++)
+                       if (defpart[def][part] != 0)
+                               nparts++;
                for (part = PART('a'); part < NPARTITIONS; part++) {
                        if (defpart[def][part] == 0)
                                continue;
                        printf("\t:p%c#%d:", 'a' + part, defpart[def][part]);
                for (part = PART('a'); part < NPARTITIONS; part++) {
                        if (defpart[def][part] == 0)
                                continue;
                        printf("\t:p%c#%d:", 'a' + part, defpart[def][part]);
-                       if (defparam[part].p_bsize != 0)
+                       if (defparam[part].p_bsize != 0) {
                                printf("b%c#%d:f%c#%d:",
                                  'a' + part, defparam[part].p_bsize,
                                  'a' + part, defparam[part].p_fsize);
                                printf("b%c#%d:f%c#%d:",
                                  'a' + part, defparam[part].p_bsize,
                                  'a' + part, defparam[part].p_fsize);
-                       printf("%s\n", part != NPARTITIONS - 1 ? "\\" : "");
+                       }
+                       nparts--;
+                       printf("%s\n", nparts > 0 ? "\\" : "");
                }
                exit(0);
        }
                }
                exit(0);
        }
@@ -257,6 +299,20 @@ gettype:
        }
        dp->d_type = type;
        fprintf(stderr, "(type <cr> to get default value, if only one)\n");
        }
        dp->d_type = type;
        fprintf(stderr, "(type <cr> to get default value, if only one)\n");
+       fprintf(stderr, "Do %ss require sector or cylinder offsets (%s)? ",
+               dp->d_name, "cylinder");
+       (void) gets(buf);
+       if (*buf == 's')
+               dp->d_sectoffset = 1;
+       else
+               dp->d_sectoffset = 0;
+       fprintf(stderr, "Do %ss support bad144 bad block forwarding (yes)? ",
+               dp->d_name);
+       (void) gets(buf);
+       if (*buf != 'n')
+               dp->d_badsectforw = 1;
+       else
+               dp->d_badsectforw = 0;
        for (fp = fields; fp->f_name != NULL; fp++) {
 again:
                fprintf(stderr, "%s ", fp->f_name);
        for (fp = fields; fp->f_name != NULL; fp++) {
 again:
                fprintf(stderr, "%s ", fp->f_name);