config.y:

Support slice numbers in device names.  The syntax is `<driver name>
[<unit number>] ['s' <slice number>] [<partition letter>]'.  Only
`['s' <slice number>]' is new here.  The slice number defaults to 0
so that there is no change in the output from config if this new
feature is not used.

Replace some magic disk numbers by `dk' slice and label macros.

mkswapconf.c:
Improve the output formatting:
Generate <> style includes.
Print minor numbers in hex so that slice numbers are easy to see and edit.
Print the rootdev and dumpdev names in comments like the swapdev names.
This commit is contained in:
Bruce Evans 1995-02-16 12:17:30 +00:00
parent 8b47b44cc0
commit da12c6d2aa
2 changed files with 81 additions and 27 deletions

View File

@ -110,6 +110,10 @@
*/
#include "config.h"
#include <sys/disklabel.h>
#include <sys/diskslice.h>
#include <ctype.h>
#include <stdio.h>
#include <err.h>
@ -245,7 +249,7 @@ System_parameter:
addr_spec:
AT NUMBER
= { loadaddress = $2; };
= { loadaddress = $2; }
;
swap_spec:
@ -270,7 +274,8 @@ swap_device_spec:
if (eq($1, "generic"))
fl->f_fn = $1;
else {
fl->f_swapdev = nametodev($1, 0, 'b');
fl->f_swapdev = nametodev($1, 0,
COMPATIBILITY_SLICE, 'b');
fl->f_fn = devtoname(fl->f_swapdev);
}
$$ = fl;
@ -308,7 +313,7 @@ root_device_specs:
root_device_spec:
device_name
= { $$ = nametodev($1, 0, 'a'); }
= { $$ = nametodev($1, 0, COMPATIBILITY_SLICE, 'a'); }
| major_minor
;
@ -327,7 +332,7 @@ dump_spec:
dump_device_spec:
device_name
= { $$ = nametodev($1, 0, 'b'); }
= { $$ = nametodev($1, 0, COMPATIBILITY_SLICE, 'b'); }
| major_minor
;
@ -338,7 +343,7 @@ arg_spec:
arg_device_spec:
device_name
= { $$ = nametodev($1, 0, 'b'); }
= { $$ = nametodev($1, 0, COMPATIBILITY_SLICE, 'b'); }
| major_minor
;
@ -383,6 +388,20 @@ device_name:
(void) sprintf(buf, "%s%d%s", $1, $2, $3);
$$ = ns(buf); free($1);
}
| Save_id NUMBER ID NUMBER
= {
char buf[80];
(void) sprintf(buf, "%s%d%s%d", $1, $2, $3, $4);
$$ = ns(buf); free($1);
}
| Save_id NUMBER ID NUMBER ID
= {
char buf[80];
(void) sprintf(buf, "%s%d%s%d%s", $1, $2, $3, $4, $5);
$$ = ns(buf); free($1);
}
;
Opt_list:
@ -503,7 +522,8 @@ comp_device_spec:
= {
struct file_list *fl = newflist(COMPSPEC);
fl->f_compdev = nametodev($1, 0, 'c');
fl->f_compdev = nametodev($1, 0, COMPATIBILITY_SLICE,
'c');
fl->f_fn = devtoname(fl->f_compdev);
$$ = fl;
}
@ -979,14 +999,13 @@ checksystemspec(fl)
swap = newflist(SWAPSPEC);
dev = fl->f_rootdev;
if (minor(dev) & 07) {
if (dkpart(dev) != 0) {
(void) sprintf(buf,
"Warning, swap defaulted to 'b' partition with root on '%c' partition",
(minor(dev) & 07) + 'a');
dkpart(dev) + 'a');
yyerror(buf);
}
swap->f_swapdev =
makedev(major(dev), (minor(dev) &~ 07) | ('b' - 'a'));
swap->f_swapdev = dkmodpart(dev, SWAP_PART);
swap->f_fn = devtoname(swap->f_swapdev);
mkswap(fl, swap, 0);
}
@ -1036,8 +1055,6 @@ verifysystemspecs()
deverror(fl->f_needs, "root");
*pchecked++ = fl->f_rootdev;
pchecked = verifyswap(fl->f_next, checked, pchecked);
#define samedev(dev1, dev2) \
((minor(dev1) &~ 07) != (minor(dev2) &~ 07))
if (!alreadychecked(fl->f_dumpdev, checked, pchecked)) {
if (!finddev(fl->f_dumpdev))
deverror(fl->f_needs, "dump");
@ -1088,7 +1105,7 @@ verifycomp(fl)
/*
* Has a device already been checked
* for it's existence in the configuration?
* for its existence in the configuration?
*/
alreadychecked(dev, list, last)
dev_t dev, list[];
@ -1097,7 +1114,7 @@ alreadychecked(dev, list, last)
register dev_t *p;
for (p = list; p < last; p++)
if (samedev(*p, dev))
if (dkmodpart(*p, 0) != dkmodpart(dev, 0))
return (1);
return (0);
}

View File

@ -40,8 +40,11 @@ static char sccsid[] = "@(#)mkswapconf.c 8.1 (Berkeley) 6/6/93";
*/
#include "config.h"
#include <stdio.h>
#include <sys/disklabel.h>
#include <sys/diskslice.h>
#include <ctype.h>
#include <stdio.h>
swapconf()
{
@ -77,8 +80,8 @@ do_swap(fl)
perror(path(swapname));
exit(1);
}
fprintf(fp, "#include \"sys/param.h\"\n");
fprintf(fp, "#include \"sys/conf.h\"\n");
fprintf(fp, "#include <sys/param.h>\n");
fprintf(fp, "#include <sys/conf.h>\n");
fprintf(fp, "\n");
/*
* If there aren't any swap devices
@ -91,15 +94,17 @@ do_swap(fl)
fclose(fp);
return (swap);
}
fprintf(fp, "dev_t\trootdev = makedev(%d, %d);\n",
major(fl->f_rootdev), minor(fl->f_rootdev));
fprintf(fp, "dev_t\tdumpdev = makedev(%d, %d);\n",
major(fl->f_dumpdev), minor(fl->f_dumpdev));
fprintf(fp, "dev_t\trootdev = makedev(%d, 0x%08x);\t\t/* %s */\n",
major(fl->f_rootdev), minor(fl->f_rootdev),
devtoname(fl->f_rootdev));
fprintf(fp, "dev_t\tdumpdev = makedev(%d, 0x%08x);\t\t/* %s */\n",
major(fl->f_dumpdev), minor(fl->f_dumpdev),
devtoname(fl->f_dumpdev));
fprintf(fp, "\n");
fprintf(fp, "struct\tswdevt swdevt[] = {\n");
do {
dev = swap->f_swapdev;
fprintf(fp, "\t{ makedev(%d, %d),\t%d,\t%d },\t/* %s */\n",
fprintf(fp, "\t{ makedev(%d, 0x%08x),\t%d,\t%d },\t/* %s */\n",
major(dev), minor(dev), swap->f_swapflag,
swap->f_swapsize, swap->f_fn);
swap = swap->f_next;
@ -128,13 +133,14 @@ static struct devdescription {
* terms of major/minor instead of string names.
*/
dev_t
nametodev(name, defunit, defpartition)
nametodev(name, defunit, defslice, defpartition)
char *name;
int defunit;
int defslice;
char defpartition;
{
char *cp, partition;
int unit;
int unit, slice;
register struct devdescription *dp;
cp = name;
@ -155,6 +161,23 @@ nametodev(name, defunit, defpartition)
while (*cp && isdigit(*cp))
cp++;
}
slice = defslice;
if (*cp == 's') {
++cp;
if (*cp) {
slice = atoi(cp);
if (slice < 0 || slice >= MAX_SLICES - 1) {
fprintf(stderr,
"config: %s: invalid device specification, slice out of range\n", cp);
slice = defslice;
}
if (slice != COMPATIBILITY_SLICE)
slice++;
*cp++ = '\0';
while (*cp && isdigit(*cp))
cp++;
}
}
partition = *cp ? *cp : defpartition;
if (partition < 'a' || partition > 'h') {
fprintf(stderr,
@ -170,7 +193,8 @@ nametodev(name, defunit, defpartition)
fprintf(stderr, "config: %s: unknown device\n", name);
return (NODEV);
}
return (makedev(dp->dev_major, (unit << 3) + (partition - 'a')));
return (makedev(dp->dev_major,
dkmakeminor(unit, slice, partition - 'a')));
}
char *
@ -179,6 +203,10 @@ devtoname(dev)
{
char buf[80];
register struct devdescription *dp;
int part;
char partname[2];
int slice;
char slicename[32];
if (devtablenotread)
initdevtable();
@ -187,8 +215,17 @@ devtoname(dev)
break;
if (dp == 0)
dp = devtable;
(void) sprintf(buf, "%s%d%c", dp->dev_name,
minor(dev) >> 3, (minor(dev) & 07) + 'a');
part = dkpart(dev);
slice = dkslice(dev);
slicename[0] = partname[0] = '\0';
if (slice != WHOLE_DISK_SLICE || part != RAW_PART) {
partname[0] = 'a' + part;
partname[1] = '\0';
if (slice != COMPATIBILITY_SLICE)
sprintf(slicename, "s%d", slice - 1);
}
(void) sprintf(buf, "%s%d%s%s", dp->dev_name,
dkunit(dev), slicename, partname);
return (ns(buf));
}