Skip to content

Commit

Permalink
disks: Split disk_flags in parser
Browse files Browse the repository at this point in the history
The disk flags used in the parser were a mixture of floppy and hard
disk relevant items. Split the flags into two groups such that using
'threeinch' flag on hard disk and 'disk4096' on floppy etc are not
allowed.
  • Loading branch information
andrewbird committed Nov 13, 2016
1 parent 1bb912a commit a6144ab
Showing 1 changed file with 47 additions and 25 deletions.
72 changes: 47 additions & 25 deletions src/base/init/parser.y.in
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ line : HOGTHRESH expression { config.hogthreshold = $2; }
{ stop_disk(DISK); }
| L_FLOPPY
{ start_floppy(); }
'{' disk_flags '}'
'{' floppy_flags '}'
{ stop_disk(L_FLOPPY); }
| CDROM '{' string_expr '}'
{
Expand Down Expand Up @@ -1433,16 +1433,59 @@ optbootfile : BOOTFILE string_expr
| /* empty */
;

disk_flags : disk_flag
| disk_flags disk_flag
floppy_flags : floppy_flag
| floppy_flags floppy_flag
;
disk_flag : READONLY { dptr->wantrdonly = 1; }
floppy_flag : READONLY { dptr->wantrdonly = 1; }
| THREEINCH { dptr->default_cmos = THREE_INCH_FLOPPY; }
| THREEINCH_2880 { dptr->default_cmos = THREE_INCH_288MFLOP; }
| THREEINCH_720 { dptr->default_cmos = THREE_INCH_720KFLOP; }
| ATAPI { dptr->default_cmos = ATAPI_FLOPPY; }
| FIVEINCH { dptr->default_cmos = FIVE_INCH_FLOPPY; }
| FIVEINCH_360 { dptr->default_cmos = FIVE_INCH_360KFLOP; }
| L_FLOPPY string_expr
{
struct stat st;

if (dptr->dev_name != NULL)
yyerror("Two names for a floppy-device given.");
if (stat($2, &st) < 0) {
yyerror("Could not stat floppy device.");
}
if (S_ISREG(st.st_mode)) {
dptr->type = IMAGE;
} else if (S_ISBLK(st.st_mode)) {
dptr->type = FLOPPY;
} else if (S_ISDIR(st.st_mode)) {
dptr->type = DIR_TYPE;
} else {
yyerror("Floppy device/file %s is wrong type", $2);
}
dptr->dev_name = $2;
dptr->floppy = 1; // tell IMAGE and DIR we are a floppy
}
| DEVICE string_expr optbootfile
{
if (dptr->dev_name != NULL)
yyerror("Two names for a disk-image file or device given.");
dptr->dev_name = $2;
}
| DIRECTORY string_expr
{
if (dptr->dev_name != NULL)
yyerror("Two names for a directory given.");
dptr->type = DIR_TYPE;
dptr->dev_name = $2;
}
| STRING
{ yyerror("unrecognized floppy disk flag '%s'\n", $1); free($1); }
| error
;

disk_flags : disk_flag
| disk_flags disk_flag
;
disk_flag : READONLY { dptr->wantrdonly = 1; }
| DISKCYL4096 { dptr->diskcyl4096 = 1; }
| HDTYPE1 { dptr->hdtype = 1; }
| HDTYPE2 { dptr->hdtype = 2; }
Expand Down Expand Up @@ -1479,27 +1522,6 @@ disk_flag : READONLY { dptr->wantrdonly = 1; }
dptr->type = HDISK;
dptr->dev_name = $2;
}
| L_FLOPPY string_expr
{
struct stat st;

if (dptr->dev_name != NULL)
yyerror("Two names for a floppy-device given.");
if (stat($2, &st) < 0) {
yyerror("Could not stat floppy device.");
}
if (S_ISREG(st.st_mode)) {
dptr->type = IMAGE;
} else if (S_ISBLK(st.st_mode)) {
dptr->type = FLOPPY;
} else if (S_ISDIR(st.st_mode)) {
dptr->type = DIR_TYPE;
} else {
yyerror("Floppy device/file %s is wrong type", $2);
}
dptr->dev_name = $2;
dptr->floppy = 1; // tell IMAGE and DIR we are a floppy
}
| L_PARTITION string_expr INTEGER optbootfile
{
yywarn("{ partition \"%s\" %d } the"
Expand Down

0 comments on commit a6144ab

Please sign in to comment.