Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/boot0cfg/boot0cfg.c
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | |||||
static const char fmt0[] = "# flag start chs type" | static const char fmt0[] = "# flag start chs type" | ||||
" end chs offset size\n"; | " end chs offset size\n"; | ||||
static const char fmt1[] = "%d 0x%02x %4u:%3u:%2u 0x%02x" | static const char fmt1[] = "%d 0x%02x %4u:%3u:%2u 0x%02x" | ||||
" %4u:%3u:%2u %10u %10u\n"; | " %4u:%3u:%2u %10u %10u\n"; | ||||
static int geom_class_available(const char *); | static int geom_class_available(const char *); | ||||
static int read_mbr(const char *, u_int8_t **, int); | static int read_mbr(const char *, u_int8_t **, int); | ||||
static void write_mbr(const char *, int, u_int8_t *, int); | static void write_mbr(const char *, int, u_int8_t *, int, int); | ||||
static void display_mbr(u_int8_t *); | static void display_mbr(u_int8_t *); | ||||
static int boot0version(const u_int8_t *); | static int boot0version(const u_int8_t *); | ||||
static int boot0bs(const u_int8_t *); | static int boot0bs(const u_int8_t *); | ||||
static void stropt(const char *, int *, int *); | static void stropt(const char *, int *, int *); | ||||
static int argtoi(const char *, int, int, int); | static int argtoi(const char *, int, int, int); | ||||
static int set_bell(u_int8_t *, int, int); | static int set_bell(u_int8_t *, int, int); | ||||
static void usage(void); | static void usage(void); | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | || t_arg != -1; | ||||
/* open the disk and read in the existing mbr. Either here or | /* open the disk and read in the existing mbr. Either here or | ||||
* when reading the block from disk, we do check for the version | * when reading the block from disk, we do check for the version | ||||
* and abort if a suitable block is not found. | * and abort if a suitable block is not found. | ||||
*/ | */ | ||||
mbr_size = read_mbr(disk, &mbr, !B_flag); | mbr_size = read_mbr(disk, &mbr, !B_flag); | ||||
/* save the existing MBR if we are asked to do so */ | /* save the existing MBR if we are asked to do so */ | ||||
if (fpath) | if (fpath) | ||||
write_mbr(fpath, O_CREAT | O_TRUNC, mbr, mbr_size); | write_mbr(fpath, O_CREAT | O_TRUNC, mbr, mbr_size, 0); | ||||
/* | /* | ||||
* If we are installing the boot loader, read it from disk and copy the | * If we are installing the boot loader, read it from disk and copy the | ||||
* slice table over from the existing MBR. If not, then point boot0 | * slice table over from the existing MBR. If not, then point boot0 | ||||
* back at the MBR we just read in. After this, boot0 is the data to | * back at the MBR we just read in. After this, boot0 is the data to | ||||
* write back to disk if we are going to do a write. | * write back to disk if we are going to do a write. | ||||
*/ | */ | ||||
if (B_flag) { | if (B_flag) { | ||||
Show All 39 Lines | main(int argc, char *argv[]) | ||||
boot0[OFF_SERIAL] = vol_id[0]; | boot0[OFF_SERIAL] = vol_id[0]; | ||||
boot0[OFF_SERIAL+1] = vol_id[1]; | boot0[OFF_SERIAL+1] = vol_id[1]; | ||||
boot0[OFF_SERIAL+2] = vol_id[2]; | boot0[OFF_SERIAL+2] = vol_id[2]; | ||||
boot0[OFF_SERIAL+3] = vol_id[3]; | boot0[OFF_SERIAL+3] = vol_id[3]; | ||||
up = 1; /* force update */ | up = 1; /* force update */ | ||||
} | } | ||||
/* write the MBR back to disk */ | /* write the MBR back to disk */ | ||||
if (up) | if (up) | ||||
write_mbr(disk, 0, boot0, boot0_size); | write_mbr(disk, 0, boot0, boot0_size, vol_id[4] || b0_ver == 1); | ||||
/* display the MBR */ | /* display the MBR */ | ||||
if (v_flag) | if (v_flag) | ||||
display_mbr(boot0); | display_mbr(boot0); | ||||
/* clean up */ | /* clean up */ | ||||
if (mbr != boot0) | if (mbr != boot0) | ||||
free(boot0); | free(boot0); | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | geom_class_available(const char *name) | ||||
geom_deletetree(&mesh); | geom_deletetree(&mesh); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Write out the mbr to the specified file. | * Write out the mbr to the specified file. | ||||
*/ | */ | ||||
static void | static void | ||||
write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size) | write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size, | ||||
int disable_dsn) | |||||
{ | { | ||||
struct gctl_req *grq; | struct gctl_req *grq; | ||||
const char *errmsg; | const char *errmsg; | ||||
char *pname; | char *pname; | ||||
ssize_t n; | ssize_t n; | ||||
int fd; | int fd; | ||||
fd = open(fname, O_WRONLY | flags, 0666); | fd = open(fname, O_WRONLY | flags, 0666); | ||||
Show All 28 Lines | write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size, | ||||
/* First check that GEOM_PART is available */ | /* First check that GEOM_PART is available */ | ||||
if (geom_class_available("PART") != 0) { | if (geom_class_available("PART") != 0) { | ||||
grq = gctl_get_handle(); | grq = gctl_get_handle(); | ||||
gctl_ro_param(grq, "class", -1, "PART"); | gctl_ro_param(grq, "class", -1, "PART"); | ||||
gctl_ro_param(grq, "arg0", -1, pname); | gctl_ro_param(grq, "arg0", -1, pname); | ||||
gctl_ro_param(grq, "verb", -1, "bootcode"); | gctl_ro_param(grq, "verb", -1, "bootcode"); | ||||
gctl_ro_param(grq, "bootcode", mbr_size, mbr); | gctl_ro_param(grq, "bootcode", mbr_size, mbr); | ||||
gctl_ro_param(grq, "flags", -1, "C"); | gctl_ro_param(grq, "flags", -1, "C"); | ||||
if (disable_dsn) | |||||
gctl_ro_param(grq, "skip_dsn", sizeof(int), | |||||
&disable_dsn); | |||||
errmsg = gctl_issue(grq); | errmsg = gctl_issue(grq); | ||||
if (errmsg != NULL && errmsg[0] != '\0') | if (errmsg != NULL && errmsg[0] != '\0') | ||||
errx(1, "GEOM_PART: write bootcode to %s failed: %s", | errx(1, "GEOM_PART: write bootcode to %s failed: %s", | ||||
fname, errmsg); | fname, errmsg); | ||||
gctl_free(grq); | gctl_free(grq); | ||||
} else if (geom_class_available("MBR") != 0) { | } else if (geom_class_available("MBR") != 0) { | ||||
grq = gctl_get_handle(); | grq = gctl_get_handle(); | ||||
gctl_ro_param(grq, "verb", -1, "write MBR"); | gctl_ro_param(grq, "verb", -1, "write MBR"); | ||||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |