diff options
Diffstat (limited to 'lib/geom/part/geom_part.c')
-rw-r--r-- | lib/geom/part/geom_part.c | 132 |
1 files changed, 35 insertions, 97 deletions
diff --git a/lib/geom/part/geom_part.c b/lib/geom/part/geom_part.c index 70eb83a66c97..04e730c7719e 100644 --- a/lib/geom/part/geom_part.c +++ b/lib/geom/part/geom_part.c @@ -30,7 +30,6 @@ __FBSDID("$FreeBSD$"); #include <sys/stat.h> -#include <sys/vtoc.h> #include <assert.h> #include <ctype.h> @@ -89,8 +88,7 @@ static _Noreturn void gpart_issue(struct gctl_req *, unsigned int); static void gpart_show(struct gctl_req *, unsigned int); static void gpart_show_geom(struct ggeom *, const char *, int); static int gpart_show_hasopt(struct gctl_req *, const char *, const char *); -static void gpart_write_partcode(struct ggeom *, int, void *, ssize_t); -static void gpart_write_partcode_vtoc8(struct ggeom *, int, void *); +static void gpart_write_partcode(struct gctl_req *, int, void *, ssize_t); static void gpart_print_error(const char *); static void gpart_backup(struct gctl_req *, unsigned int); static void gpart_restore(struct gctl_req *, unsigned int); @@ -1107,14 +1105,38 @@ gpart_bootfile_read(const char *bootfile, ssize_t *size) } static void -gpart_write_partcode(struct ggeom *gp, int idx, void *code, ssize_t size) +gpart_write_partcode(struct gctl_req *req, int idx, void *code, ssize_t size) { char dsf[128]; + struct gmesh mesh; + struct gclass *classp; + struct ggeom *gp; struct gprovider *pp; - const char *s; + const char *g, *s; char *buf; off_t bsize; - int fd; + int error, fd; + + s = gctl_get_ascii(req, "class"); + if (s == NULL) + abort(); + g = gctl_get_ascii(req, "arg0"); + if (g == NULL) + abort(); + error = geom_gettree_geom(&mesh, s, g, 0); + if (error != 0) + errc(EXIT_FAILURE, error, "Cannot get GEOM tree"); + classp = find_class(&mesh, s); + if (classp == NULL) { + geom_deletetree(&mesh); + errx(EXIT_FAILURE, "Class %s not found.", s); + } + gp = find_geom(classp, g); + if (gp == NULL) + errx(EXIT_FAILURE, "No such geom: %s.", g); + s = find_geomcfg(gp, "scheme"); + if (s == NULL) + errx(EXIT_FAILURE, "Scheme not found for geom %s", gp->lg_name); LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { s = find_provcfg(pp, "index"); @@ -1149,65 +1171,17 @@ gpart_write_partcode(struct ggeom *gp, int idx, void *code, ssize_t size) printf("partcode written to %s\n", pp->lg_name); } else errx(EXIT_FAILURE, "invalid partition index"); -} -static void -gpart_write_partcode_vtoc8(struct ggeom *gp, int idx, void *code) -{ - char dsf[128]; - struct gprovider *pp; - const char *s; - int installed, fd; - - installed = 0; - LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { - s = find_provcfg(pp, "index"); - if (s == NULL) - continue; - if (idx != 0 && atoi(s) != idx) - continue; - snprintf(dsf, sizeof(dsf), "/dev/%s", pp->lg_name); - if (pp->lg_sectorsize != sizeof(struct vtoc8)) - errx(EXIT_FAILURE, "%s: unexpected sector " - "size (%d)\n", dsf, pp->lg_sectorsize); - if (pp->lg_mediasize < VTOC_BOOTSIZE) - continue; - fd = open(dsf, O_WRONLY); - if (fd == -1) - err(EXIT_FAILURE, "%s", dsf); - /* - * We ignore the first VTOC_BOOTSIZE bytes of boot code in - * order to avoid overwriting the label. - */ - if (lseek(fd, sizeof(struct vtoc8), SEEK_SET) != - sizeof(struct vtoc8)) - err(EXIT_FAILURE, "%s", dsf); - if (write(fd, (caddr_t)code + sizeof(struct vtoc8), - VTOC_BOOTSIZE - sizeof(struct vtoc8)) != VTOC_BOOTSIZE - - sizeof(struct vtoc8)) - err(EXIT_FAILURE, "%s", dsf); - installed++; - close(fd); - if (idx != 0 && atoi(s) == idx) - break; - } - if (installed == 0) - errx(EXIT_FAILURE, "%s: no partitions", gp->lg_name); - else - printf("partcode written to %s\n", - idx != 0 ? pp->lg_name: gp->lg_name); + geom_deletetree(&mesh); } static void gpart_bootcode(struct gctl_req *req, unsigned int fl) { - struct gmesh mesh; - struct gclass *classp; - struct ggeom *gp; - const char *g, *s; + const char *s; void *bootcode, *partcode; size_t bootsize, partsize; - int error, idx, vtoc8; + int error, idx; if (gctl_get_int(req, "nargs") != 1) errx(EXIT_FAILURE, "Invalid number of arguments."); @@ -1231,31 +1205,6 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl) goto nopartcode; } - s = gctl_get_ascii(req, "class"); - if (s == NULL) - abort(); - g = gctl_get_ascii(req, "arg0"); - if (g == NULL) - abort(); - error = geom_gettree_geom(&mesh, s, g, 0); - if (error != 0) - errc(EXIT_FAILURE, error, "Cannot get GEOM tree"); - classp = find_class(&mesh, s); - if (classp == NULL) { - geom_deletetree(&mesh); - errx(EXIT_FAILURE, "Class %s not found.", s); - } - gp = find_geom(classp, g); - if (gp == NULL) - errx(EXIT_FAILURE, "No such geom: %s.", g); - s = find_geomcfg(gp, "scheme"); - if (s == NULL) - errx(EXIT_FAILURE, "Scheme not found for geom %s", gp->lg_name); - if (strcmp(s, "VTOC8") == 0) - vtoc8 = 1; - else - vtoc8 = 0; - if (gctl_has_param(req, GPART_PARAM_INDEX)) { idx = (int)gctl_get_intmax(req, GPART_PARAM_INDEX); if (idx < 1) @@ -1268,28 +1217,17 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl) if (gctl_has_param(req, GPART_PARAM_PARTCODE)) { s = gctl_get_ascii(req, GPART_PARAM_PARTCODE); - if (vtoc8 != 0) - partsize = VTOC_BOOTSIZE; - else - partsize = 1024 * 1024; /* Arbitrary limit. */ + partsize = 1024 * 1024; /* Arbitrary limit. */ partcode = gpart_bootfile_read(s, &partsize); error = gctl_delete_param(req, GPART_PARAM_PARTCODE); if (error) errc(EXIT_FAILURE, error, "internal error"); - if (vtoc8 == 0) { - if (idx == 0) - errx(EXIT_FAILURE, "missing -i option"); - gpart_write_partcode(gp, idx, partcode, partsize); - } else { - if (partsize != VTOC_BOOTSIZE) - errx(EXIT_FAILURE, "invalid bootcode"); - gpart_write_partcode_vtoc8(gp, idx, partcode); - } + if (idx == 0) + errx(EXIT_FAILURE, "missing -i option"); + gpart_write_partcode(req, idx, partcode, partsize); free(partcode); } - geom_deletetree(&mesh); - nopartcode: if (bootcode != NULL) gpart_issue(req, fl); |