partedit_x86.c (1ce4b357402c3cd0cba264a15c06b6fd00591088) partedit_x86.c (be01d6e9f2c9e42ed7558cb31b463c4aceb88c82)
1/*-
2 * Copyright (c) 2011 Nathan Whitehorn
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 */
28
29#include <sys/types.h>
30#include <sys/sysctl.h>
31#include <string.h>
32
33#include "partedit.h"
34
1/*-
2 * Copyright (c) 2011 Nathan Whitehorn
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 */
28
29#include <sys/types.h>
30#include <sys/sysctl.h>
31#include <string.h>
32
33#include "partedit.h"
34
35static char platform[255] = "";
36static const char *platform_sysctl = "machdep.bootmethod";
35static const char *
36x86_bootmethod(void)
37{
38 static char fw[255] = "";
39 size_t len = sizeof(fw);
40 int error;
41
42 if (strlen(fw) == 0) {
43 error = sysctlbyname("machdep.bootmethod", fw, &len, NULL, -1);
44 if (error != 0)
45 return ("BIOS");
46 }
37
47
48 return (fw);
49}
50
38const char *
39default_scheme(void) {
40 return ("GPT");
41}
42
43int
51const char *
52default_scheme(void) {
53 return ("GPT");
54}
55
56int
44is_scheme_bootable(const char *part_type) {
45 size_t platlen = sizeof(platform);
46 if (strlen(platform) == 0)
47 sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
57is_scheme_bootable(const char *part_type)
58{
48
49 if (strcmp(part_type, "GPT") == 0)
50 return (1);
59
60 if (strcmp(part_type, "GPT") == 0)
61 return (1);
51 if (strcmp(platform, "BIOS") == 0) {
62 if (strcmp(x86_bootmethod(), "BIOS") == 0) {
52 if (strcmp(part_type, "BSD") == 0)
53 return (1);
54 if (strcmp(part_type, "MBR") == 0)
55 return (1);
56 }
57
58 return (0);
59}
60
61int
63 if (strcmp(part_type, "BSD") == 0)
64 return (1);
65 if (strcmp(part_type, "MBR") == 0)
66 return (1);
67 }
68
69 return (0);
70}
71
72int
62is_fs_bootable(const char *part_type, const char *fs) {
63 size_t platlen = sizeof(platform);
64 if (strlen(platform) == 0)
65 sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
73is_fs_bootable(const char *part_type, const char *fs)
74{
66
67 if (strcmp(fs, "freebsd-ufs") == 0)
68 return (1);
69
75
76 if (strcmp(fs, "freebsd-ufs") == 0)
77 return (1);
78
70 if (strcmp(fs, "freebsd-zfs") == 0 && strcmp(platform, "BIOS") == 0)
79 if (strcmp(fs, "freebsd-zfs") == 0 &&
80 strcmp(x86_bootmethod(), "BIOS") == 0)
71 return (1);
72
73 return (0);
74}
75
76size_t
81 return (1);
82
83 return (0);
84}
85
86size_t
77bootpart_size(const char *scheme) {
78 size_t platlen = sizeof(platform);
79 if (strlen(platform) == 0)
80 sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
87bootpart_size(const char *scheme)
88{
81
82 /* No partcode except for GPT */
83 if (strcmp(scheme, "GPT") != 0)
84 return (0);
85
89
90 /* No partcode except for GPT */
91 if (strcmp(scheme, "GPT") != 0)
92 return (0);
93
86 if (strcmp(platform, "BIOS") == 0)
94 if (strcmp(x86_bootmethod(), "BIOS") == 0)
87 return (512*1024);
88 else
89 return (800*1024);
90
91 return (0);
92}
93
94const char *
95 return (512*1024);
96 else
97 return (800*1024);
98
99 return (0);
100}
101
102const char *
95bootpart_type(const char *scheme) {
96 size_t platlen = sizeof(platform);
97 if (strlen(platform) == 0)
98 sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
103bootpart_type(const char *scheme)
104{
99
105
100 if (strcmp(platform, "UEFI") == 0)
106 if (strcmp(x86_bootmethod(), "UEFI") == 0)
101 return ("efi");
102
103 return ("freebsd-boot");
104}
105
106const char *
107 return ("efi");
108
109 return ("freebsd-boot");
110}
111
112const char *
107bootcode_path(const char *part_type) {
108 size_t platlen = sizeof(platform);
109 if (strlen(platform) == 0)
110 sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
111 if (strcmp(platform, "UEFI") == 0)
113bootcode_path(const char *part_type)
114{
115
116 if (strcmp(x86_bootmethod(), "UEFI") == 0)
112 return (NULL);
113
114 if (strcmp(part_type, "GPT") == 0)
115 return ("/boot/pmbr");
116 if (strcmp(part_type, "MBR") == 0)
117 return ("/boot/mbr");
118 if (strcmp(part_type, "BSD") == 0)
119 return ("/boot/boot");
120
121 return (NULL);
122}
123
124const char *
117 return (NULL);
118
119 if (strcmp(part_type, "GPT") == 0)
120 return ("/boot/pmbr");
121 if (strcmp(part_type, "MBR") == 0)
122 return ("/boot/mbr");
123 if (strcmp(part_type, "BSD") == 0)
124 return ("/boot/boot");
125
126 return (NULL);
127}
128
129const char *
125partcode_path(const char *part_type, const char *fs_type) {
126 size_t platlen = sizeof(platform);
127 if (strlen(platform) == 0)
128 sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
130partcode_path(const char *part_type, const char *fs_type)
131{
129
130 if (strcmp(part_type, "GPT") == 0) {
132
133 if (strcmp(part_type, "GPT") == 0) {
131 if (strcmp(platform, "UEFI") == 0)
134 if (strcmp(x86_bootmethod(), "UEFI") == 0)
132 return ("/boot/boot1.efifat");
133 else if (strcmp(fs_type, "zfs") == 0)
134 return ("/boot/gptzfsboot");
135 else
136 return ("/boot/gptboot");
137 }
138
139 /* No partcode except for GPT */
140 return (NULL);
141}
142
135 return ("/boot/boot1.efifat");
136 else if (strcmp(fs_type, "zfs") == 0)
137 return ("/boot/gptzfsboot");
138 else
139 return ("/boot/gptboot");
140 }
141
142 /* No partcode except for GPT */
143 return (NULL);
144}
145