summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdinstall/partedit/partedit_x86.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bsdinstall/partedit/partedit_x86.c')
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit_x86.c67
1 files changed, 35 insertions, 32 deletions
diff --git a/usr.sbin/bsdinstall/partedit/partedit_x86.c b/usr.sbin/bsdinstall/partedit/partedit_x86.c
index bd98ac5..8bd4027b 100644
--- a/usr.sbin/bsdinstall/partedit/partedit_x86.c
+++ b/usr.sbin/bsdinstall/partedit/partedit_x86.c
@@ -32,8 +32,21 @@
#include "partedit.h"
-static char platform[255] = "";
-static const char *platform_sysctl = "machdep.bootmethod";
+static const char *
+x86_bootmethod(void)
+{
+ static char fw[255] = "";
+ size_t len = sizeof(fw);
+ int error;
+
+ if (strlen(fw) == 0) {
+ error = sysctlbyname("machdep.bootmethod", fw, &len, NULL, -1);
+ if (error != 0)
+ return ("BIOS");
+ }
+
+ return (fw);
+}
const char *
default_scheme(void) {
@@ -41,14 +54,12 @@ default_scheme(void) {
}
int
-is_scheme_bootable(const char *part_type) {
- size_t platlen = sizeof(platform);
- if (strlen(platform) == 0)
- sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+is_scheme_bootable(const char *part_type)
+{
if (strcmp(part_type, "GPT") == 0)
return (1);
- if (strcmp(platform, "BIOS") == 0) {
+ if (strcmp(x86_bootmethod(), "BIOS") == 0) {
if (strcmp(part_type, "BSD") == 0)
return (1);
if (strcmp(part_type, "MBR") == 0)
@@ -59,31 +70,28 @@ is_scheme_bootable(const char *part_type) {
}
int
-is_fs_bootable(const char *part_type, const char *fs) {
- size_t platlen = sizeof(platform);
- if (strlen(platform) == 0)
- sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+is_fs_bootable(const char *part_type, const char *fs)
+{
if (strcmp(fs, "freebsd-ufs") == 0)
return (1);
- if (strcmp(fs, "freebsd-zfs") == 0 && strcmp(platform, "BIOS") == 0)
+ if (strcmp(fs, "freebsd-zfs") == 0 &&
+ strcmp(x86_bootmethod(), "BIOS") == 0)
return (1);
return (0);
}
size_t
-bootpart_size(const char *scheme) {
- size_t platlen = sizeof(platform);
- if (strlen(platform) == 0)
- sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+bootpart_size(const char *scheme)
+{
/* No partcode except for GPT */
if (strcmp(scheme, "GPT") != 0)
return (0);
- if (strcmp(platform, "BIOS") == 0)
+ if (strcmp(x86_bootmethod(), "BIOS") == 0)
return (512*1024);
else
return (800*1024);
@@ -92,23 +100,20 @@ bootpart_size(const char *scheme) {
}
const char *
-bootpart_type(const char *scheme) {
- size_t platlen = sizeof(platform);
- if (strlen(platform) == 0)
- sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+bootpart_type(const char *scheme)
+{
- if (strcmp(platform, "UEFI") == 0)
+ if (strcmp(x86_bootmethod(), "UEFI") == 0)
return ("efi");
return ("freebsd-boot");
}
const char *
-bootcode_path(const char *part_type) {
- size_t platlen = sizeof(platform);
- if (strlen(platform) == 0)
- sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
- if (strcmp(platform, "UEFI") == 0)
+bootcode_path(const char *part_type)
+{
+
+ if (strcmp(x86_bootmethod(), "UEFI") == 0)
return (NULL);
if (strcmp(part_type, "GPT") == 0)
@@ -122,13 +127,11 @@ bootcode_path(const char *part_type) {
}
const char *
-partcode_path(const char *part_type, const char *fs_type) {
- size_t platlen = sizeof(platform);
- if (strlen(platform) == 0)
- sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+partcode_path(const char *part_type, const char *fs_type)
+{
if (strcmp(part_type, "GPT") == 0) {
- if (strcmp(platform, "UEFI") == 0)
+ if (strcmp(x86_bootmethod(), "UEFI") == 0)
return ("/boot/boot1.efifat");
else if (strcmp(fs_type, "zfs") == 0)
return ("/boot/gptzfsboot");
OpenPOWER on IntegriCloud