Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bsdinstall/partedit/gpart_ops.c
Show All 24 Lines | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/mman.h> | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <libutil.h> | #include <libutil.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <libgeom.h> | #include <libgeom.h> | ||||
#include <dialog.h> | #include <dialog.h> | ||||
#include <dlg_keys.h> | #include <dlg_keys.h> | ||||
▲ Show 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
gpart_bootcode(struct ggeom *gp) | gpart_bootcode(struct ggeom *gp) | ||||
{ | { | ||||
const char *bootcode; | const char *bootcode; | ||||
struct gconfig *gc; | struct gconfig *gc; | ||||
struct gctl_req *r; | struct gctl_req *r; | ||||
const char *errstr, *scheme; | const char *errstr, *scheme; | ||||
uint8_t *boot; | uint8_t *boot; | ||||
size_t bootsize, bytes; | ssize_t bootsize; | ||||
int bootfd; | int bootfd; | ||||
/* | /* | ||||
* Write default bootcode to the newly partitioned disk, if that | * Write default bootcode to the newly partitioned disk, if that | ||||
* applies on this platform. | * applies on this platform. | ||||
*/ | */ | ||||
LIST_FOREACH(gc, &gp->lg_config, lg_config) { | LIST_FOREACH(gc, &gp->lg_config, lg_config) { | ||||
if (strcmp(gc->lg_name, "scheme") == 0) { | if (strcmp(gc->lg_name, "scheme") == 0) { | ||||
Show All 9 Lines | gpart_bootcode(struct ggeom *gp) | ||||
bootfd = open(bootcode, O_RDONLY); | bootfd = open(bootcode, O_RDONLY); | ||||
if (bootfd < 0) { | if (bootfd < 0) { | ||||
dialog_msgbox("Bootcode Error", strerror(errno), 0, 0, | dialog_msgbox("Bootcode Error", strerror(errno), 0, 0, | ||||
TRUE); | TRUE); | ||||
return; | return; | ||||
} | } | ||||
bootsize = lseek(bootfd, 0, SEEK_END); | bootsize = lseek(bootfd, 0, SEEK_END); | ||||
boot = malloc(bootsize); | if (bootsize == -1) { | ||||
lseek(bootfd, 0, SEEK_SET); | dialog_msgbox("Bootcode Error", strerror(errno), 0, 0, | ||||
bytes = 0; | TRUE); | ||||
while (bytes < bootsize) | return; | ||||
bytes += read(bootfd, boot + bytes, bootsize - bytes); | } | ||||
close(bootfd); | |||||
boot = mmap(0, bootsize, PROT_READ, 0, bootfd, 0); | |||||
if (boot == MAP_FAILED) { | |||||
dialog_msgbox("Bootcode Error", strerror(errno), 0, 0, | |||||
TRUE); | |||||
return; | |||||
} | |||||
r = gctl_get_handle(); | r = gctl_get_handle(); | ||||
gctl_ro_param(r, "class", -1, "PART"); | gctl_ro_param(r, "class", -1, "PART"); | ||||
gctl_ro_param(r, "arg0", -1, gp->lg_name); | gctl_ro_param(r, "arg0", -1, gp->lg_name); | ||||
gctl_ro_param(r, "verb", -1, "bootcode"); | gctl_ro_param(r, "verb", -1, "bootcode"); | ||||
gctl_ro_param(r, "bootcode", bootsize, boot); | gctl_ro_param(r, "bootcode", bootsize, boot); | ||||
errstr = gctl_issue(r); | errstr = gctl_issue(r); | ||||
if (errstr != NULL && errstr[0] != '\0') | if (errstr != NULL && errstr[0] != '\0') | ||||
gpart_show_error("Bootcode Error", NULL, errstr); | gpart_show_error("Bootcode Error", NULL, errstr); | ||||
gctl_free(r); | gctl_free(r); | ||||
free(boot); | munmap(boot, bootsize); | ||||
close(bootfd); | |||||
} | } | ||||
static void | static void | ||||
gpart_partcode(struct gprovider *pp, const char *fstype) | gpart_partcode(struct gprovider *pp, const char *fstype) | ||||
{ | { | ||||
struct gconfig *gc; | struct gconfig *gc; | ||||
const char *scheme; | const char *scheme; | ||||
const char *indexstr; | const char *indexstr; | ||||
▲ Show 20 Lines • Show All 1,034 Lines • Show Last 20 Lines |