Index: usr.sbin/bsdinstall/partedit/gpart_ops.c =================================================================== --- usr.sbin/bsdinstall/partedit/gpart_ops.c +++ usr.sbin/bsdinstall/partedit/gpart_ops.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -376,7 +377,7 @@ struct gctl_req *r; const char *errstr, *scheme; uint8_t *boot; - size_t bootsize, bytes; + ssize_t bootsize; int bootfd; /* @@ -402,12 +403,18 @@ } bootsize = lseek(bootfd, 0, SEEK_END); - boot = malloc(bootsize); - lseek(bootfd, 0, SEEK_SET); - bytes = 0; - while (bytes < bootsize) - bytes += read(bootfd, boot + bytes, bootsize - bytes); - close(bootfd); + if (bootsize == -1) { + dialog_msgbox("Bootcode Error", strerror(errno), 0, 0, + TRUE); + return; + } + + 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(); gctl_ro_param(r, "class", -1, "PART"); @@ -419,7 +426,8 @@ if (errstr != NULL && errstr[0] != '\0') gpart_show_error("Bootcode Error", NULL, errstr); gctl_free(r); - free(boot); + munmap(boot, bootsize); + close(bootfd); } static void