/*
* Copyright (c) 1983, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1983, 1988, 1993\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
/*
* Each array defines a layout for a disk;
* that is, the collection of partitions totally
* covers the physical space on a disk.
*/
#define NLAYOUTS 3
static char layouts[NLAYOUTS][NPARTITIONS] = {
{ 'a', 'b', 'h', 'g' },
{ 'a', 'b', 'h', 'd', 'e', 'f' },
{ 'c' },
};
/*
* Default disk block and disk block fragment
* sizes for each file system. Those file systems
* with zero block and frag sizes are special cases
* (e.g. swap areas or for access to the entire device).
*/
static struct partition defparam[NPARTITIONS] = {
{ 0, 0, { 1024 }, FS_UNUSED, 8, { 0 }, }, /* a */
{ 0, 0, { 1024 }, FS_SWAP, 8, { 0 }, }, /* b */
{ 0, 0, { 1024 }, FS_UNUSED, 8, { 0 }, }, /* c */
{ 0, 0, { 512 }, FS_UNUSED, 8, { 0 }, }, /* d */
{ 0, 0, { 1024 }, FS_UNUSED, 8, { 0 }, }, /* e */
{ 0, 0, { 1024 }, FS_UNUSED, 8, { 0 }, }, /* f */
{ 0, 0, { 1024 }, FS_UNUSED, 8, { 0 }, }, /* g */
{ 0, 0, { 1024 }, FS_UNUSED, 8, { 0 }, } /* h */
};
/*
* Each disk has some space reserved for a bad sector
* 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.
*/
static int badsecttable = 126; /* # sectors */
static int pflag; /* print device driver partition tables */
static int dflag; /* print disktab entry */
dp = getdiskbyname(*argv);
if (dp == NULL) {
if (isatty(0))
dp = promptfordisk(*argv);
if (dp == NULL) {
fprintf(stderr, "%s: unknown disk type\n", *argv);
exit(1);
}
}
if (dp->d_flags & D_REMOVABLE)
tyname = "removable";
else if (dp->d_flags & D_RAMDISK)
tyname = "simulated";
else
tyname = "winchester";
spc = dp->d_secpercyl;
/*
* 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.
* If disk size was specified explicitly, use specified size.
*/
if (dp->d_type == DKTYPE_SMD && dp->d_flags & D_BADSECT &&
totsize == 0) {
badsecttable = dp->d_nsectors +
roundup(badsecttable, dp->d_nsectors);
threshold = howmany(spc, badsecttable);
} else {
badsecttable = 0;
threshold = 0;
}
/*
* If disk size was specified, recompute number of cylinders
* that may be used, and set badsecttable to any remaining
* fraction of the last cylinder.
*/
if (totsize != 0) {
dp->d_ncylinders = howmany(totsize, spc);
badsecttable = spc * dp->d_ncylinders - totsize;
}
/*
* Figure out if disk is large enough for
* expanded swap area and 'd', 'e', and 'f'
* partitions. Otherwise, use smaller defaults
* based on RK07.
*/
for (def = 0; def < NDEFAULTS; def++) {
curcyl = 0;
for (part = PART('a'); part < NPARTITIONS; part++)
curcyl += howmany(defpart[def][part], spc);
if (curcyl < dp->d_ncylinders - threshold)
break;
}
if (def >= NDEFAULTS) {
fprintf(stderr, "%s: disk too small, calculate by hand\n",
*argv);
exit(1);
}
/*
* Calculate number of cylinders allocated to each disk
* partition. We may waste a bit of space here, but it's
* in the interest of (very backward) compatibility
* (for mixed disk systems).
*/
for (curcyl = 0, part = PART('a'); part < NPARTITIONS; part++) {
numcyls[part] = 0;
if (defpart[def][part] != 0) {
numcyls[part] = howmany(defpart[def][part], spc);
curcyl += numcyls[part];
}
}
numcyls[PART('f')] = dp->d_ncylinders - curcyl;
numcyls[PART('g')] =
numcyls[PART('d')] + numcyls[PART('e')] + numcyls[PART('f')];
numcyls[PART('c')] = dp->d_ncylinders;
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;
#ifndef for_now
if (totsize || !pflag)
#else
if (totsize)
#endif
defpart[def][PART('c')] -= badsecttable;
/*
* Calculate starting cylinder number for each partition.
* Note the 'h' partition is physically located before the
* 'g' or 'd' partition. This is reflected in the layout
* arrays defined above.
*/
for (layout = 0; layout < NLAYOUTS; layout++) {
curcyl = 0;
for (lp = layouts[layout]; *lp != 0; lp++) {
startcyl[PART(*lp)] = curcyl;
curcyl += numcyls[PART(*lp)];
}
}
/*
* In case the disk is in the ``in-between'' range
* where the 'g' partition is smaller than the 'h'
* partition, reverse the frag sizes so the /usr partition
* is always set up with a frag size larger than the
* user's partition.
*/
if (defpart[def][PART('g')] < defpart[def][PART('h')]) {
int temp;