Centralize determination of boot firmware (UEFI vs. BIOS/CSM) into a
function x86_bootmethod() and fix deviations from style(9).
This commit is contained in:
parent
f0cace5d94
commit
be01d6e9f2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=273003
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user