| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: md.c,v 1.10 2011/11/04 11:27:04 martin Exp $ */ | | 1 | /* $NetBSD: md.c,v 1.11 2012/01/29 16:01:36 phx 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. |
| @@ -26,78 +26,123 @@ | | | @@ -26,78 +26,123 @@ |
26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
32 | * THE POSSIBILITY OF SUCH DAMAGE. | | 32 | * THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | /* md.c -- ofppc machine specific routines */ | | 35 | /* md.c -- ofppc machine specific routines */ |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/sysctl.h> | | 38 | #include <sys/sysctl.h> |
| | | 39 | #include <sys/disklabel_rdb.h> |
39 | #include <stdio.h> | | 40 | #include <stdio.h> |
40 | #include <util.h> | | 41 | #include <util.h> |
41 | #include <machine/cpu.h> | | 42 | #include <machine/cpu.h> |
42 | | | 43 | |
43 | #include "defs.h" | | 44 | #include "defs.h" |
44 | #include "md.h" | | 45 | #include "md.h" |
45 | #include "msg_defs.h" | | 46 | #include "msg_defs.h" |
46 | #include "menu_defs.h" | | 47 | #include "menu_defs.h" |
47 | #include "endian.h" | | 48 | #include "endian.h" |
48 | | | 49 | |
| | | 50 | static int check_rdb(void); |
| | | 51 | static uint32_t rdbchksum(void *); |
| | | 52 | |
49 | /* We use MBR_PTYPE_PREP like port-prep does. */ | | 53 | /* We use MBR_PTYPE_PREP like port-prep does. */ |
50 | static int nonewfsmsdos = 0, nobootfix = 0, noprepfix=0; | | 54 | static int nonewfsmsdos = 0, nobootfix = 0, noprepfix=0; |
51 | static int bootpart_fat12 = PART_BOOT_FAT12; | | 55 | static int bootpart_fat12 = PART_BOOT_FAT12; |
52 | static int bootpart_binfo = PART_BOOT_BINFO; | | 56 | static int bootpart_binfo = PART_BOOT_BINFO; |
53 | static int bootpart_prep = PART_BOOT_PREP; | | 57 | static int bootpart_prep = PART_BOOT_PREP; |
54 | static int bootinfo_mbr = 1; | | 58 | static int bootinfo_mbr = 1; |
| | | 59 | static int rdb_found = 0; |
55 | | | 60 | |
56 | /* bootstart/bootsize are for the fat */ | | 61 | /* bootstart/bootsize are for the fat */ |
57 | int binfostart, binfosize, bprepstart, bprepsize; | | 62 | int binfostart, binfosize, bprepstart, bprepsize; |
58 | | | 63 | |
59 | void | | 64 | void |
60 | md_init(void) | | 65 | md_init(void) |
61 | { | | 66 | { |
62 | } | | 67 | } |
63 | | | 68 | |
64 | void | | 69 | void |
65 | md_init_set_status(int flags) | | 70 | md_init_set_status(int flags) |
66 | { | | 71 | { |
| | | 72 | |
67 | (void)flags; | | 73 | (void)flags; |
68 | } | | 74 | } |
69 | | | 75 | |
70 | int | | 76 | int |
71 | md_get_info(void) | | 77 | md_get_info(void) |
72 | { | | 78 | { |
| | | 79 | |
| | | 80 | if (check_rdb()) |
| | | 81 | return 1; |
| | | 82 | |
73 | return set_bios_geom_with_mbr_guess(); | | 83 | return set_bios_geom_with_mbr_guess(); |
74 | } | | 84 | } |
75 | | | 85 | |
76 | /* | | 86 | /* |
77 | * md back-end code for menu-driven BSD disklabel editor. | | 87 | * md back-end code for menu-driven BSD disklabel editor. |
78 | */ | | 88 | */ |
79 | int | | 89 | int |
80 | md_make_bsd_partitions(void) | | 90 | md_make_bsd_partitions(void) |
81 | { | | 91 | { |
82 | int i; | | 92 | int i; |
83 | int part; | | 93 | int part; |
84 | int maxpart = getmaxpartitions(); | | 94 | int maxpart = getmaxpartitions(); |
85 | int partstart; | | 95 | int partstart; |
86 | int part_raw, part_bsd; | | 96 | int part_raw, part_bsd; |
87 | int ptend; | | 97 | int ptend; |
88 | int no_swap = 0; | | 98 | int no_swap = 0; |
89 | partinfo *p; | | 99 | partinfo *p; |
90 | | | 100 | |
| | | 101 | if (rdb_found) { |
| | | 102 | /* |
| | | 103 | * We found RDB partitions on the disk, which cannot be |
| | | 104 | * modified by rewriting the disklabel. |
| | | 105 | * So just use what we have got. |
| | | 106 | */ |
| | | 107 | for (part = 0; part < maxpart; part++) { |
| | | 108 | if (PI_ISBSDFS(&bsdlabel[part])) { |
| | | 109 | bsdlabel[part].pi_flags |= |
| | | 110 | PIF_NEWFS | PIF_MOUNT; |
| | | 111 | |
| | | 112 | if (part == PART_A) |
| | | 113 | strcpy(bsdlabel[part].pi_mount, "/"); |
| | | 114 | } |
| | | 115 | } |
| | | 116 | |
| | | 117 | part_bsd = part_raw = getrawpartition(); |
| | | 118 | if (part_raw == -1) |
| | | 119 | part_raw = PART_C; /* for sanity... */ |
| | | 120 | bsdlabel[part_raw].pi_offset = 0; |
| | | 121 | bsdlabel[part_raw].pi_size = dlsize; |
| | | 122 | |
| | | 123 | set_sizemultname_meg(); |
| | | 124 | rdb_edit_check: |
| | | 125 | if (edit_and_check_label(bsdlabel, maxpart, part_raw, |
| | | 126 | part_bsd) == 0) { |
| | | 127 | msg_display(MSG_abort); |
| | | 128 | return 0; |
| | | 129 | } |
| | | 130 | if (md_check_partitions() == 0) |
| | | 131 | goto rdb_edit_check; |
| | | 132 | |
| | | 133 | return 1; |
| | | 134 | } |
| | | 135 | |
91 | /* | | 136 | /* |
92 | * Initialize global variables that track space used on this disk. | | 137 | * Initialize global variables that track space used on this disk. |
93 | * Standard 4.4BSD 8-partition labels always cover whole disk. | | 138 | * Standard 4.4BSD 8-partition labels always cover whole disk. |
94 | */ | | 139 | */ |
95 | if (ptsize == 0) | | 140 | if (ptsize == 0) |
96 | ptsize = dlsize - ptstart; | | 141 | ptsize = dlsize - ptstart; |
97 | if (dlsize == 0) | | 142 | if (dlsize == 0) |
98 | dlsize = ptstart + ptsize; | | 143 | dlsize = ptstart + ptsize; |
99 | | | 144 | |
100 | partstart = ptstart; | | 145 | partstart = ptstart; |
101 | ptend = ptstart + ptsize; | | 146 | ptend = ptstart + ptsize; |
102 | | | 147 | |
103 | /* Ask for layout type -- standard or special */ | | 148 | /* Ask for layout type -- standard or special */ |
| @@ -213,26 +258,29 @@ md_make_bsd_partitions(void) | | | @@ -213,26 +258,29 @@ md_make_bsd_partitions(void) |
213 | | | 258 | |
214 | /* Everything looks OK. */ | | 259 | /* Everything looks OK. */ |
215 | return 1; | | 260 | return 1; |
216 | } | | 261 | } |
217 | | | 262 | |
218 | /* | | 263 | /* |
219 | * any additional partition validation | | 264 | * any additional partition validation |
220 | */ | | 265 | */ |
221 | int | | 266 | int |
222 | md_check_partitions(void) | | 267 | md_check_partitions(void) |
223 | { | | 268 | { |
224 | int part, fprep=0, ffat=0; | | 269 | int part, fprep=0, ffat=0; |
225 | | | 270 | |
| | | 271 | if (rdb_found) |
| | | 272 | return 1; |
| | | 273 | |
226 | /* we need to find a boot partition, otherwise we can't create | | 274 | /* we need to find a boot partition, otherwise we can't create |
227 | * our msdos fs boot partition. We make the assumption that | | 275 | * our msdos fs boot partition. We make the assumption that |
228 | * the user hasn't done something stupid, like move it away | | 276 | * the user hasn't done something stupid, like move it away |
229 | * from the MBR partition. | | 277 | * from the MBR partition. |
230 | */ | | 278 | */ |
231 | for (part = PART_A; part < MAXPARTITIONS; part++) { | | 279 | for (part = PART_A; part < MAXPARTITIONS; part++) { |
232 | if (bsdlabel[part].pi_fstype == FS_MSDOS) { | | 280 | if (bsdlabel[part].pi_fstype == FS_MSDOS) { |
233 | bootpart_fat12 = part; | | 281 | bootpart_fat12 = part; |
234 | ffat++; | | 282 | ffat++; |
235 | } else if (bsdlabel[part].pi_fstype == FS_BOOT) { | | 283 | } else if (bsdlabel[part].pi_fstype == FS_BOOT) { |
236 | bootpart_prep = part; | | 284 | bootpart_prep = part; |
237 | fprep++; | | 285 | fprep++; |
238 | } else if (bsdlabel[part].pi_fstype == FS_OTHER) { | | 286 | } else if (bsdlabel[part].pi_fstype == FS_OTHER) { |
| @@ -249,46 +297,50 @@ md_check_partitions(void) | | | @@ -249,46 +297,50 @@ md_check_partitions(void) |
249 | return 3; | | 297 | return 3; |
250 | | | 298 | |
251 | msg_display(MSG_nobootpartdisklabel); | | 299 | msg_display(MSG_nobootpartdisklabel); |
252 | process_menu(MENU_ok, NULL); | | 300 | process_menu(MENU_ok, NULL); |
253 | return 0; | | 301 | return 0; |
254 | } | | 302 | } |
255 | | | 303 | |
256 | /* | | 304 | /* |
257 | * hook called before writing new disklabel. | | 305 | * hook called before writing new disklabel. |
258 | */ | | 306 | */ |
259 | int | | 307 | int |
260 | md_pre_disklabel(void) | | 308 | md_pre_disklabel(void) |
261 | { | | 309 | { |
| | | 310 | |
| | | 311 | if (rdb_found) |
| | | 312 | return 0; |
| | | 313 | |
262 | msg_display(MSG_dofdisk); | | 314 | msg_display(MSG_dofdisk); |
263 | | | 315 | |
264 | /* write edited MBR onto disk. */ | | 316 | /* write edited MBR onto disk. */ |
265 | if (write_mbr(diskdev, &mbr, 1) != 0) { | | 317 | if (write_mbr(diskdev, &mbr, 1) != 0) { |
266 | msg_display(MSG_wmbrfail); | | 318 | msg_display(MSG_wmbrfail); |
267 | process_menu(MENU_ok, NULL); | | 319 | process_menu(MENU_ok, NULL); |
268 | return 1; | | 320 | return 1; |
269 | } | | 321 | } |
270 | return 0; | | 322 | return 0; |
271 | } | | 323 | } |
272 | | | 324 | |
273 | /* | | 325 | /* |
274 | * hook called after writing disklabel to new target disk. | | 326 | * hook called after writing disklabel to new target disk. |
275 | */ | | 327 | */ |
276 | int | | 328 | int |
277 | md_post_disklabel(void) | | 329 | md_post_disklabel(void) |
278 | { | | 330 | { |
279 | char bootdev[100]; | | 331 | char bootdev[100]; |
280 | | | 332 | |
281 | if (bootstart == 0 || bootsize == 0) | | 333 | if (bootstart == 0 || bootsize == 0 || rdb_found) |
282 | return 0; | | 334 | return 0; |
283 | | | 335 | |
284 | snprintf(bootdev, sizeof bootdev, "/dev/r%s%c", diskdev, | | 336 | snprintf(bootdev, sizeof bootdev, "/dev/r%s%c", diskdev, |
285 | 'a'+bootpart_fat12); | | 337 | 'a'+bootpart_fat12); |
286 | run_program(RUN_DISPLAY, "/sbin/newfs_msdos %s", bootdev); | | 338 | run_program(RUN_DISPLAY, "/sbin/newfs_msdos %s", bootdev); |
287 | | | 339 | |
288 | return 0; | | 340 | return 0; |
289 | } | | 341 | } |
290 | | | 342 | |
291 | /* | | 343 | /* |
292 | * hook called after upgrade() or install() has finished setting | | 344 | * hook called after upgrade() or install() has finished setting |
293 | * up the target disk but immediately before the user is given the | | 345 | * up the target disk but immediately before the user is given the |
294 | * ``disks are now set up'' message. | | 346 | * ``disks are now set up'' message. |
| @@ -297,27 +349,27 @@ int | | | @@ -297,27 +349,27 @@ int |
297 | md_post_newfs(void) | | 349 | md_post_newfs(void) |
298 | { | | 350 | { |
299 | | | 351 | |
300 | /* No bootblock. We use ofwboot from a partition visiable by OFW. */ | | 352 | /* No bootblock. We use ofwboot from a partition visiable by OFW. */ |
301 | return 0; | | 353 | return 0; |
302 | } | | 354 | } |
303 | | | 355 | |
304 | int | | 356 | int |
305 | md_post_extract(void) | | 357 | md_post_extract(void) |
306 | { | | 358 | { |
307 | char bootdev[100], bootbdev[100], version[64]; | | 359 | char bootdev[100], bootbdev[100], version[64]; |
308 | | | 360 | |
309 | /* if we can't make it bootable, just punt */ | | 361 | /* if we can't make it bootable, just punt */ |
310 | if (nobootfix && noprepfix) | | 362 | if ((nobootfix && noprepfix) || rdb_found) |
311 | return 0; | | 363 | return 0; |
312 | | | 364 | |
313 | snprintf(version, sizeof version, "NetBSD/%s %s", MACH, REL); | | 365 | snprintf(version, sizeof version, "NetBSD/%s %s", MACH, REL); |
314 | run_program(RUN_DISPLAY, "/usr/mdec/mkbootinfo '%s' %d " | | 366 | run_program(RUN_DISPLAY, "/usr/mdec/mkbootinfo '%s' %d " |
315 | "/tmp/bootinfo.txt", version, bootinfo_mbr); | | 367 | "/tmp/bootinfo.txt", version, bootinfo_mbr); |
316 | | | 368 | |
317 | if (!nobootfix) { | | 369 | if (!nobootfix) { |
318 | run_program(RUN_DISPLAY, "/bin/mkdir -p /%s/boot/ppc", | | 370 | run_program(RUN_DISPLAY, "/bin/mkdir -p /%s/boot/ppc", |
319 | target_prefix()); | | 371 | target_prefix()); |
320 | run_program(RUN_DISPLAY, "/bin/mkdir -p /%s/boot/netbsd", | | 372 | run_program(RUN_DISPLAY, "/bin/mkdir -p /%s/boot/netbsd", |
321 | target_prefix()); | | 373 | target_prefix()); |
322 | run_program(RUN_DISPLAY, "/bin/cp /usr/mdec/ofwboot " | | 374 | run_program(RUN_DISPLAY, "/bin/cp /usr/mdec/ofwboot " |
323 | "/%s/boot/netbsd", target_prefix()); | | 375 | "/%s/boot/netbsd", target_prefix()); |
| @@ -343,38 +395,42 @@ md_post_extract(void) | | | @@ -343,38 +395,42 @@ md_post_extract(void) |
343 | 'a'+bootpart_binfo); | | 395 | 'a'+bootpart_binfo); |
344 | run_program(RUN_DISPLAY, "/bin/dd if=/dev/zero of=%s bs=512", | | 396 | run_program(RUN_DISPLAY, "/bin/dd if=/dev/zero of=%s bs=512", |
345 | bootdev); | | 397 | bootdev); |
346 | run_program(RUN_DISPLAY, "/bin/dd if=/tmp/bootinfo.txt " | | 398 | run_program(RUN_DISPLAY, "/bin/dd if=/tmp/bootinfo.txt " |
347 | "of=%s bs=512", bootbdev); | | 399 | "of=%s bs=512", bootbdev); |
348 | } | | 400 | } |
349 | | | 401 | |
350 | return 0; | | 402 | return 0; |
351 | } | | 403 | } |
352 | | | 404 | |
353 | void | | 405 | void |
354 | md_cleanup_install(void) | | 406 | md_cleanup_install(void) |
355 | { | | 407 | { |
| | | 408 | |
356 | #ifndef DEBUG | | 409 | #ifndef DEBUG |
357 | enable_rc_conf(); | | 410 | enable_rc_conf(); |
358 | #endif | | 411 | #endif |
359 | } | | 412 | } |
360 | | | 413 | |
361 | int | | 414 | int |
362 | md_pre_update(void) | | 415 | md_pre_update(void) |
363 | { | | 416 | { |
364 | struct mbr_partition *part; | | 417 | struct mbr_partition *part; |
365 | mbr_info_t *ext; | | 418 | mbr_info_t *ext; |
366 | int i; | | 419 | int i; |
367 | | | 420 | |
| | | 421 | if (check_rdb()) |
| | | 422 | return 1; |
| | | 423 | |
368 | read_mbr(diskdev, &mbr); | | 424 | read_mbr(diskdev, &mbr); |
369 | /* do a sanity check of the partition table */ | | 425 | /* do a sanity check of the partition table */ |
370 | for (ext = &mbr; ext; ext = ext->extended) { | | 426 | for (ext = &mbr; ext; ext = ext->extended) { |
371 | part = ext->mbr.mbr_parts; | | 427 | part = ext->mbr.mbr_parts; |
372 | for (i = 0; i < MBR_PART_COUNT; part++, i++) { | | 428 | for (i = 0; i < MBR_PART_COUNT; part++, i++) { |
373 | if (part->mbrp_type == MBR_PTYPE_PREP && | | 429 | if (part->mbrp_type == MBR_PTYPE_PREP && |
374 | part->mbrp_size > 50) | | 430 | part->mbrp_size > 50) |
375 | bootinfo_mbr = i+1; | | 431 | bootinfo_mbr = i+1; |
376 | if (part->mbrp_type == MBR_PTYPE_RESERVED_x21 && | | 432 | if (part->mbrp_type == MBR_PTYPE_RESERVED_x21 && |
377 | part->mbrp_size < (MIN_FAT12_BOOT/512)) { | | 433 | part->mbrp_size < (MIN_FAT12_BOOT/512)) { |
378 | msg_display(MSG_boottoosmall); | | 434 | msg_display(MSG_boottoosmall); |
379 | msg_display_add(MSG_nobootpartdisklabel, 0); | | 435 | msg_display_add(MSG_nobootpartdisklabel, 0); |
380 | process_menu(MENU_yesno, NULL); | | 436 | process_menu(MENU_yesno, NULL); |
| @@ -390,26 +446,27 @@ md_pre_update(void) | | | @@ -390,26 +446,27 @@ md_pre_update(void) |
390 | case 0: nobootfix=1; noprepfix=1; break; | | 446 | case 0: nobootfix=1; noprepfix=1; break; |
391 | case 1: noprepfix=1; break; | | 447 | case 1: noprepfix=1; break; |
392 | case 2: nobootfix=1; break; | | 448 | case 2: nobootfix=1; break; |
393 | default: break; | | 449 | default: break; |
394 | } | | 450 | } |
395 | | | 451 | |
396 | return 1; | | 452 | return 1; |
397 | } | | 453 | } |
398 | | | 454 | |
399 | /* Upgrade support */ | | 455 | /* Upgrade support */ |
400 | int | | 456 | int |
401 | md_update(void) | | 457 | md_update(void) |
402 | { | | 458 | { |
| | | 459 | |
403 | nonewfsmsdos = 1; | | 460 | nonewfsmsdos = 1; |
404 | md_post_newfs(); | | 461 | md_post_newfs(); |
405 | return 1; | | 462 | return 1; |
406 | } | | 463 | } |
407 | | | 464 | |
408 | | | 465 | |
409 | int | | 466 | int |
410 | md_check_mbr(mbr_info_t *mbri) | | 467 | md_check_mbr(mbr_info_t *mbri) |
411 | { | | 468 | { |
412 | mbr_info_t *ext; | | 469 | mbr_info_t *ext; |
413 | struct mbr_partition *part; | | 470 | struct mbr_partition *part; |
414 | int i; | | 471 | int i; |
415 | | | 472 | |
| @@ -533,18 +590,66 @@ md_mbr_use_wholedisk(mbr_info_t *mbri) | | | @@ -533,18 +590,66 @@ md_mbr_use_wholedisk(mbr_info_t *mbri) |
533 | ptstart = part[1].mbrp_start; | | 590 | ptstart = part[1].mbrp_start; |
534 | ptsize = part[1].mbrp_size; | | 591 | ptsize = part[1].mbrp_size; |
535 | bootstart = part[0].mbrp_start; | | 592 | bootstart = part[0].mbrp_start; |
536 | bootsize = part[0].mbrp_size; | | 593 | bootsize = part[0].mbrp_size; |
537 | binfostart = part[2].mbrp_start; | | 594 | binfostart = part[2].mbrp_start; |
538 | binfosize= part[2].mbrp_size; | | 595 | binfosize= part[2].mbrp_size; |
539 | bprepstart = part[3].mbrp_start; | | 596 | bprepstart = part[3].mbrp_start; |
540 | bprepsize = part[3].mbrp_size; | | 597 | bprepsize = part[3].mbrp_size; |
541 | bootinfo_mbr = 4; | | 598 | bootinfo_mbr = 4; |
542 | | | 599 | |
543 | return 1; | | 600 | return 1; |
544 | } | | 601 | } |
545 | | | 602 | |
| | | 603 | const char *md_disklabel_cmd(void) |
| | | 604 | { |
| | | 605 | |
| | | 606 | /* we cannot rewrite an RDB disklabel */ |
| | | 607 | if (rdb_found) |
| | | 608 | return "echo No disklabel"; |
| | | 609 | |
| | | 610 | return "disklabel -w -r"; |
| | | 611 | } |
| | | 612 | |
| | | 613 | static int |
| | | 614 | check_rdb(void) |
| | | 615 | { |
| | | 616 | char buf[512], diskpath[MAXPATHLEN]; |
| | | 617 | struct rdblock *rdb; |
| | | 618 | off_t blk; |
| | | 619 | int fd; |
| | | 620 | |
| | | 621 | /* Find out if this disk has a valid RDB, before continuing. */ |
| | | 622 | rdb = (struct rdblock *)buf; |
| | | 623 | fd = opendisk(diskdev, O_RDONLY, diskpath, sizeof(diskpath), 0); |
| | | 624 | if (fd < 0) |
| | | 625 | return 0; |
| | | 626 | for (blk = 0; blk < RDB_MAXBLOCKS; blk++) { |
| | | 627 | if (pread(fd, rdb, 512, blk * 512) != 512) |
| | | 628 | return 0; |
| | | 629 | if (rdb->id == RDBLOCK_ID && rdbchksum(rdb) == 0) { |
| | | 630 | rdb_found = 1; /* do not repartition! */ |
| | | 631 | return 1; |
| | | 632 | } |
| | | 633 | } |
| | | 634 | return 0; |
| | | 635 | } |
| | | 636 | |
| | | 637 | static uint32_t |
| | | 638 | rdbchksum(void *bdata) |
| | | 639 | { |
| | | 640 | uint32_t *blp, cnt, val; |
| | | 641 | |
| | | 642 | blp = bdata; |
| | | 643 | cnt = blp[1]; |
| | | 644 | val = 0; |
| | | 645 | while (cnt--) |
| | | 646 | val += *blp++; |
| | | 647 | return val; |
| | | 648 | } |
| | | 649 | |
546 | int | | 650 | int |
547 | md_pre_mount() | | 651 | md_pre_mount() |
548 | { | | 652 | { |
| | | 653 | |
549 | return 0; | | 654 | return 0; |
550 | } | | 655 | } |