| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: md.c,v 1.10 2022/01/29 16:01:19 martin Exp $ */ | | 1 | /* $NetBSD: md.c,v 1.10.2.1 2023/08/21 11:05:54 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 1997 Piermont Information Systems Inc. | | 4 | * Copyright 1997 Piermont Information Systems Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Based on code written by Philip A. Nelson for Piermont Information | | 7 | * Based on code written by Philip A. Nelson for Piermont Information |
8 | * Systems Inc. | | 8 | * Systems Inc. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -107,45 +107,60 @@ md_get_info(struct install_partition_des | | | @@ -107,45 +107,60 @@ md_get_info(struct install_partition_des |
107 | return true; | | 107 | return true; |
108 | } | | 108 | } |
109 | | | 109 | |
110 | /* | | 110 | /* |
111 | * md back-end code for menu-driven BSD disklabel editor. | | 111 | * md back-end code for menu-driven BSD disklabel editor. |
112 | */ | | 112 | */ |
113 | int | | 113 | int |
114 | md_make_bsd_partitions(struct install_partition_desc *install) | | 114 | md_make_bsd_partitions(struct install_partition_desc *install) |
115 | { | | 115 | { |
116 | | | 116 | |
117 | return make_bsd_partitions(install); | | 117 | return make_bsd_partitions(install); |
118 | } | | 118 | } |
119 | | | 119 | |
| | | 120 | static part_id |
| | | 121 | find_boot_part(struct install_partition_desc *install) |
| | | 122 | { |
| | | 123 | for (size_t i = 0; i < install->num; i++) { |
| | | 124 | if (install->infos[i].fs_type != PART_BOOT_TYPE) |
| | | 125 | continue; |
| | | 126 | if (install->infos[i].fs_version != PART_BOOT_SUBT) |
| | | 127 | continue; |
| | | 128 | if (install->infos[i].size < (PART_BOOT/512)) |
| | | 129 | continue; |
| | | 130 | if (install->infos[i].cur_start > 0) |
| | | 131 | continue; |
| | | 132 | return i; |
| | | 133 | } |
| | | 134 | return NO_PART; |
| | | 135 | } |
| | | 136 | |
120 | /* | | 137 | /* |
121 | * any additional partition validation | | 138 | * any additional partition validation |
122 | */ | | 139 | */ |
123 | bool | | 140 | bool |
124 | md_check_partitions(struct install_partition_desc *install) | | 141 | md_check_partitions(struct install_partition_desc *install) |
125 | { | | 142 | { |
126 | | | 143 | |
127 | /* | | 144 | /* |
128 | * Make sure that a boot partition (old 4.3BSD UFS) is prepared | | 145 | * Make sure that a boot partition (old 4.3BSD UFS) is prepared |
129 | * properly for our native bootloader. | | 146 | * properly for our native bootloader. |
130 | */ | | 147 | */ |
131 | if (install->num < 1 || install->infos[0].fs_type != PART_BOOT_TYPE || | | 148 | if (find_boot_part(install) != NO_PART) |
132 | install->infos[0].fs_version != PART_BOOT_SUBT || | | 149 | return true; |
133 | !(install->infos[0].instflags & PUIINST_NEWFS)) { | | 150 | |
134 | msg_display(MSG_nobootpartdisklabel); | | 151 | msg_display(MSG_nobootpartdisklabel); |
135 | process_menu(MENU_ok, NULL); | | 152 | process_menu(MENU_ok, NULL); |
136 | return false; | | 153 | return false; |
137 | } | | | |
138 | return true; | | | |
139 | } | | 154 | } |
140 | | | 155 | |
141 | /* | | 156 | /* |
142 | * hook called before writing new disklabel. | | 157 | * hook called before writing new disklabel. |
143 | */ | | 158 | */ |
144 | bool | | 159 | bool |
145 | md_pre_disklabel(struct install_partition_desc *install, | | 160 | md_pre_disklabel(struct install_partition_desc *install, |
146 | struct disk_partitions *parts) | | 161 | struct disk_partitions *parts) |
147 | { | | 162 | { |
148 | | | 163 | |
149 | return true; | | 164 | return true; |
150 | } | | 165 | } |
151 | | | 166 | |
| @@ -177,36 +192,39 @@ copy_bootloader(const char *diskdev) | | | @@ -177,36 +192,39 @@ copy_bootloader(const char *diskdev) |
177 | } | | 192 | } |
178 | return 0; | | 193 | return 0; |
179 | } | | 194 | } |
180 | | | 195 | |
181 | /* | | 196 | /* |
182 | * hook called after install() has finished setting up the target disk | | 197 | * hook called after install() has finished setting up the target disk |
183 | * but immediately before the user is given the ``disks are now set up'' | | 198 | * but immediately before the user is given the ``disks are now set up'' |
184 | * message. | | 199 | * message. |
185 | */ | | 200 | */ |
186 | int | | 201 | int |
187 | md_post_newfs(struct install_partition_desc *install) | | 202 | md_post_newfs(struct install_partition_desc *install) |
188 | { | | 203 | { |
189 | char rdisk[STRSIZE], disk[STRSIZE]; | | 204 | char rdisk[STRSIZE], disk[STRSIZE]; |
| | | 205 | part_id boot_part = find_boot_part(install); |
190 | | | 206 | |
191 | if (install->num < 1) | | 207 | if (boot_part == NO_PART) |
192 | return 1; | | 208 | return 1; |
193 | | | 209 | |
194 | if (!install->infos[0].parts->pscheme->get_part_device( | | 210 | if (!install->infos[boot_part].parts->pscheme->get_part_device( |
195 | install->infos[0].parts, install->infos[0].cur_part_id, | | 211 | install->infos[boot_part].parts, |
| | | 212 | install->infos[boot_part].cur_part_id, |
196 | rdisk, sizeof rdisk, NULL, raw_dev_name, true, true)) | | 213 | rdisk, sizeof rdisk, NULL, raw_dev_name, true, true)) |
197 | return 1; | | 214 | return 1; |
198 | if (!install->infos[0].parts->pscheme->get_part_device( | | 215 | if (!install->infos[boot_part].parts->pscheme->get_part_device( |
199 | install->infos[0].parts, install->infos[0].cur_part_id, | | 216 | install->infos[boot_part].parts, |
| | | 217 | install->infos[boot_part].cur_part_id, |
200 | disk, sizeof disk, NULL, plain_name, true, true)) | | 218 | disk, sizeof disk, NULL, plain_name, true, true)) |
201 | return 1; | | 219 | return 1; |
202 | | | 220 | |
203 | if (run_program(RUN_DISPLAY | RUN_PROGRESS, | | 221 | if (run_program(RUN_DISPLAY | RUN_PROGRESS, |
204 | "/sbin/newfs -V2 -O 0 -b %d -f %d %s", | | 222 | "/sbin/newfs -V2 -O 0 -b %d -f %d %s", |
205 | PART_BOOT_BSIZE, PART_BOOT_FSIZE, rdisk)) | | 223 | PART_BOOT_BSIZE, PART_BOOT_FSIZE, rdisk)) |
206 | return 1; | | 224 | return 1; |
207 | return copy_bootloader(disk); | | 225 | return copy_bootloader(disk); |
208 | } | | 226 | } |
209 | | | 227 | |
210 | int | | 228 | int |
211 | md_post_extract(struct install_partition_desc *install, bool upgrade) | | 229 | md_post_extract(struct install_partition_desc *install, bool upgrade) |
212 | { | | 230 | { |
| @@ -230,32 +248,34 @@ md_pre_update(struct install_partition_d | | | @@ -230,32 +248,34 @@ md_pre_update(struct install_partition_d |
230 | { | | 248 | { |
231 | return 1; | | 249 | return 1; |
232 | } | | 250 | } |
233 | | | 251 | |
234 | /* Upgrade support */ | | 252 | /* Upgrade support */ |
235 | int | | 253 | int |
236 | md_update(struct install_partition_desc *install) | | 254 | md_update(struct install_partition_desc *install) |
237 | { | | 255 | { |
238 | const char *mntdir = "/mnt2"; | | 256 | const char *mntdir = "/mnt2"; |
239 | char bootpath[MAXPATHLEN]; | | 257 | char bootpath[MAXPATHLEN]; |
240 | struct stat sb; | | 258 | struct stat sb; |
241 | bool hasboot = false; | | 259 | bool hasboot = false; |
242 | char disk[STRSIZE]; | | 260 | char disk[STRSIZE]; |
| | | 261 | part_id boot_part = find_boot_part(install); |
243 | | | 262 | |
244 | if (install->num < 1) | | 263 | if (boot_part == NO_PART) |
245 | return 0; | | 264 | return 0; |
246 | | | 265 | |
247 | if (!install->infos[0].parts->pscheme->get_part_device( | | 266 | if (!install->infos[boot_part].parts->pscheme->get_part_device( |
248 | install->infos[0].parts, install->infos[0].cur_part_id, | | 267 | install->infos[boot_part].parts, |
| | | 268 | install->infos[boot_part].cur_part_id, |
249 | disk, sizeof disk, NULL, plain_name, true, true)) | | 269 | disk, sizeof disk, NULL, plain_name, true, true)) |
250 | return 0; | | 270 | return 0; |
251 | | | 271 | |
252 | /* | | 272 | /* |
253 | * Check if there is a boot UFS parttion and it has the old bootloader. | | 273 | * Check if there is a boot UFS parttion and it has the old bootloader. |
254 | * We'll update bootloader only if the old one was installed. | | 274 | * We'll update bootloader only if the old one was installed. |
255 | */ | | 275 | */ |
256 | if (!run_program(RUN_SILENT | RUN_ERROR_OK, | | 276 | if (!run_program(RUN_SILENT | RUN_ERROR_OK, |
257 | "mount -r %s %s", disk, mntdir)) { | | 277 | "mount -r %s %s", disk, mntdir)) { |
258 | mnt2_mounted = 1; | | 278 | mnt2_mounted = 1; |
259 | snprintf(bootpath, sizeof(bootpath), "%s/%s", mntdir, "boot"); | | 279 | snprintf(bootpath, sizeof(bootpath), "%s/%s", mntdir, "boot"); |
260 | if (stat(bootpath, &sb) == 0 && S_ISREG(sb.st_mode)) | | 280 | if (stat(bootpath, &sb) == 0 && S_ISREG(sb.st_mode)) |
261 | hasboot = true; | | 281 | hasboot = true; |
| @@ -278,14 +298,13 @@ md_parts_use_wholedisk(struct disk_parti | | | @@ -278,14 +298,13 @@ md_parts_use_wholedisk(struct disk_parti |
278 | { | | 298 | { |
279 | return parts_use_wholedisk(parts, 0, NULL); | | 299 | return parts_use_wholedisk(parts, 0, NULL); |
280 | } | | 300 | } |
281 | | | 301 | |
282 | #ifdef HAVE_GPT | | 302 | #ifdef HAVE_GPT |
283 | bool | | 303 | bool |
284 | md_gpt_post_write(struct disk_partitions *parts, part_id root_id, | | 304 | md_gpt_post_write(struct disk_partitions *parts, part_id root_id, |
285 | bool root_is_new, part_id efi_id, bool efi_is_new) | | 305 | bool root_is_new, part_id efi_id, bool efi_is_new) |
286 | { | | 306 | { |
287 | /* no GPT boot support, nothing needs to be done here */ | | 307 | /* no GPT boot support, nothing needs to be done here */ |
288 | return true; | | 308 | return true; |
289 | } | | 309 | } |
290 | #endif | | 310 | #endif |
291 | | | | |