From owner-svn-src-all@FreeBSD.ORG Sun Oct 12 17:50:26 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1E6BEB13; Sun, 12 Oct 2014 17:50:26 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 09E97272; Sun, 12 Oct 2014 17:50:26 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9CHoPkF079116; Sun, 12 Oct 2014 17:50:25 GMT (envelope-from nwhitehorn@FreeBSD.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9CHoPUm079115; Sun, 12 Oct 2014 17:50:25 GMT (envelope-from nwhitehorn@FreeBSD.org) Message-Id: <201410121750.s9CHoPUm079115@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: nwhitehorn set sender to nwhitehorn@FreeBSD.org using -f From: Nathan Whitehorn Date: Sun, 12 Oct 2014 17:50:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273003 - head/usr.sbin/bsdinstall/partedit X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Oct 2014 17:50:26 -0000 Author: nwhitehorn Date: Sun Oct 12 17:50:25 2014 New Revision: 273003 URL: https://svnweb.freebsd.org/changeset/base/273003 Log: Centralize determination of boot firmware (UEFI vs. BIOS/CSM) into a function x86_bootmethod() and fix deviations from style(9). Modified: head/usr.sbin/bsdinstall/partedit/partedit_x86.c Modified: head/usr.sbin/bsdinstall/partedit/partedit_x86.c ============================================================================== --- head/usr.sbin/bsdinstall/partedit/partedit_x86.c Sun Oct 12 17:45:22 2014 (r273002) +++ head/usr.sbin/bsdinstall/partedit/partedit_x86.c Sun Oct 12 17:50:25 2014 (r273003) @@ -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");