version 1.11.2.2, 2007/12/07 17:25:04 |
version 1.11.2.3, 2008/01/21 09:37:15 |
|
|
#include <libi386.h> |
#include <libi386.h> |
#include "devopen.h" |
#include "devopen.h" |
|
|
|
#ifdef SUPPORT_USTARFS |
|
#include "ustarfs.h" |
|
#endif |
#ifdef SUPPORT_PS2 |
#ifdef SUPPORT_PS2 |
#include <biosmca.h> |
#include <biosmca.h> |
#endif |
#endif |
Line 266 atoi(const char *in) |
|
Line 269 atoi(const char *in) |
|
} |
} |
|
|
/* |
/* |
* This function parses a boot.cnf file in the root of the filesystem |
* This function parses a boot.cfg file in the root of the filesystem |
* (if present) and populates the global boot configuration. |
* (if present) and populates the global boot configuration. |
* |
* |
* The file consists of a number of lines each terminated by \n |
* The file consists of a number of lines each terminated by \n |
Line 280 atoi(const char *in) |
|
Line 283 atoi(const char *in) |
|
* default: the default menu option to use if Return is pressed |
* default: the default menu option to use if Return is pressed |
* consdev: the console device to use |
* consdev: the console device to use |
* |
* |
* Example boot.cnf file: |
* Example boot.cfg file: |
* banner=Welcome to NetBSD |
* banner=Welcome to NetBSD |
* banner=Please choose the boot type from the following menu |
* banner=Please choose the boot type from the following menu |
* menu=Boot NetBSD:boot netbsd |
* menu=Boot NetBSD:boot netbsd |
* menu=Boot into single user mode:boot netbsd -s |
* menu=Boot into single user mode:boot netbsd -s |
|
* menu=:boot hd1a:netbsd -cs |
* menu=Goto boot comand line:prompt |
* menu=Goto boot comand line:prompt |
* timeout=10 |
* timeout=10 |
* consdev=com0 |
* consdev=com0 |
Line 297 parsebootconf(const char *conf) |
|
Line 301 parsebootconf(const char *conf) |
|
int cmenu, cbanner, len; |
int cmenu, cbanner, len; |
int fd, err, off; |
int fd, err, off; |
struct stat st; |
struct stat st; |
char *value, *key; |
char *key, *value, *v2; |
|
#ifdef SUPPORT_USTARFS |
|
void *op_open; |
|
#endif |
|
|
/* Clear bootconf structure */ |
/* Clear bootconf structure */ |
bzero((void *)&bootconf, sizeof(bootconf)); |
bzero((void *)&bootconf, sizeof(bootconf)); |
Line 305 parsebootconf(const char *conf) |
|
Line 312 parsebootconf(const char *conf) |
|
/* Set timeout to configured */ |
/* Set timeout to configured */ |
bootconf.timeout = boot_params.bp_timeout; |
bootconf.timeout = boot_params.bp_timeout; |
|
|
err = stat(BOOTCONF, &st); |
/* don't try to open BOOTCONF if the target fs is ustarfs */ |
if (err == -1) |
#ifdef SUPPORT_USTARFS |
|
#if !defined(LIBSA_SINGLE_FILESYSTEM) |
|
fd = open("boot", 0); /* assume we are loaded as "boot" from here */ |
|
if (fd < 0) |
|
op_open = NULL; /* XXX */ |
|
else { |
|
op_open = files[fd].f_ops->open; |
|
close(fd); |
|
} |
|
#else |
|
op_open = file_system[0].open; |
|
#endif /* !LIBSA_SINGLE_FILESYSTEM */ |
|
if (op_open == ustarfs_open) |
return; |
return; |
|
#endif /* SUPPORT_USTARFS */ |
|
|
fd = open(BOOTCONF, 0); |
fd = open(BOOTCONF, 0); |
if (fd < 0) |
if (fd < 0) |
return; |
return; |
|
|
|
err = fstat(fd, &st); |
|
if (err == -1) { |
|
close(fd); |
|
return; |
|
} |
|
|
bc = alloc(st.st_size + 1); |
bc = alloc(st.st_size + 1); |
if (bc == NULL) { |
if (bc == NULL) { |
printf("Could not allocate memory for boot configuration\n"); |
printf("Could not allocate memory for boot configuration\n"); |
Line 329 parsebootconf(const char *conf) |
|
Line 355 parsebootconf(const char *conf) |
|
bc[off] = '\0'; |
bc[off] = '\0'; |
|
|
close(fd); |
close(fd); |
/* bc now contains the whole boot.cnf file */ |
/* bc now contains the whole boot.cfg file */ |
|
|
cmenu = 0; |
cmenu = 0; |
cbanner = 0; |
cbanner = 0; |
Line 350 parsebootconf(const char *conf) |
|
Line 376 parsebootconf(const char *conf) |
|
*c = 0; |
*c = 0; |
|
|
if (!strncmp(key, "menu", 4)) { |
if (!strncmp(key, "menu", 4)) { |
|
/* |
|
* Parse "menu=<description>:<command>". If the |
|
* description is empty ("menu=:<command>)", |
|
* then re-use the command as the description. |
|
* Note that the command may contain embedded |
|
* colons. |
|
*/ |
if (cmenu >= MAXMENU) |
if (cmenu >= MAXMENU) |
continue; |
continue; |
bootconf.desc[cmenu] = value; |
bootconf.desc[cmenu] = value; |
/* Look for : between description and command */ |
for (v2=value; *v2 && *v2 != ':'; v2++) |
for (; *value && *value != ':'; value++) |
|
continue; |
continue; |
if(*value) { |
if (*v2) { |
*value++ = 0; |
*v2++ = 0; |
bootconf.command[cmenu] = value; |
bootconf.command[cmenu] = v2; |
|
if (! *value) |
|
bootconf.desc[cmenu] = v2; |
cmenu++; |
cmenu++; |
} else { |
} else { |
/* No delimiter means invalid line */ |
/* No delimiter means invalid line */ |
Line 482 boot2(int biosdev, u_int biossector) |
|
Line 516 boot2(int biosdev, u_int biossector) |
|
parsebootconf(BOOTCONF); |
parsebootconf(BOOTCONF); |
|
|
/* |
/* |
* If console set in boot.cnf, switch to it. |
* If console set in boot.cfg, switch to it. |
* This will print the banner, so we don't need to explicitly do it |
* This will print the banner, so we don't need to explicitly do it |
*/ |
*/ |
if (bootconf.consdev) |
if (bootconf.consdev) |
Line 534 command_help(char *arg) |
|
Line 568 command_help(char *arg) |
|
{ |
{ |
|
|
printf("commands are:\n" |
printf("commands are:\n" |
"boot [xdNx:][filename] [-acdqsv]\n" |
"boot [xdNx:][filename] [-acdqsvxz]\n" |
" (ex. \"hd0a:netbsd.old -s\"\n" |
" (ex. \"hd0a:netbsd.old -s\"\n" |
"ls [path]\n" |
"ls [path]\n" |
"dev xd[N[x]]:\n" |
"dev xd[N[x]]:\n" |