| @@ -1,550 +1,655 @@ | | | @@ -1,550 +1,655 @@ |
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. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * 3. The name of Piermont Information Systems Inc. may not be used to endorse | | 18 | * 3. The name of Piermont Information Systems Inc. may not be used to endorse |
19 | * or promote products derived from this software without specific prior | | 19 | * or promote products derived from this software without specific prior |
20 | * written permission. | | 20 | * written permission. |
21 | * | | 21 | * |
22 | * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' | | 22 | * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' |
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE | | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE |
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 */ |
104 | msg_display(MSG_layout, | | 149 | msg_display(MSG_layout, |
105 | ptsize / (MEG / sectorsize), | | 150 | ptsize / (MEG / sectorsize), |
106 | DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE, | | 151 | DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE, |
107 | DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE + XNEEDMB); | | 152 | DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE + XNEEDMB); |
108 | | | 153 | |
109 | process_menu(MENU_layout, NULL); | | 154 | process_menu(MENU_layout, NULL); |
110 | | | 155 | |
111 | /* Set so we use the 'real' geometry for rounding, input in MB */ | | 156 | /* Set so we use the 'real' geometry for rounding, input in MB */ |
112 | current_cylsize = dlcylsize; | | 157 | current_cylsize = dlcylsize; |
113 | set_sizemultname_meg(); | | 158 | set_sizemultname_meg(); |
114 | | | 159 | |
115 | /* Build standard partitions */ | | 160 | /* Build standard partitions */ |
116 | memset(&bsdlabel, 0, sizeof bsdlabel); | | 161 | memset(&bsdlabel, 0, sizeof bsdlabel); |
117 | | | 162 | |
118 | /* Set initial partition types to unused */ | | 163 | /* Set initial partition types to unused */ |
119 | for (part = 0 ; part < maxpart ; ++part) | | 164 | for (part = 0 ; part < maxpart ; ++part) |
120 | bsdlabel[part].pi_fstype = FS_UNUSED; | | 165 | bsdlabel[part].pi_fstype = FS_UNUSED; |
121 | | | 166 | |
122 | /* Whole disk partition */ | | 167 | /* Whole disk partition */ |
123 | part_raw = getrawpartition(); | | 168 | part_raw = getrawpartition(); |
124 | if (part_raw == -1) | | 169 | if (part_raw == -1) |
125 | part_raw = PART_C; /* for sanity... */ | | 170 | part_raw = PART_C; /* for sanity... */ |
126 | bsdlabel[part_raw].pi_offset = 0; | | 171 | bsdlabel[part_raw].pi_offset = 0; |
127 | bsdlabel[part_raw].pi_size = dlsize; | | 172 | bsdlabel[part_raw].pi_size = dlsize; |
128 | | | 173 | |
129 | if (part_raw == PART_D) { | | 174 | if (part_raw == PART_D) { |
130 | /* Probably a system that expects an i386 style mbr */ | | 175 | /* Probably a system that expects an i386 style mbr */ |
131 | part_bsd = PART_C; | | 176 | part_bsd = PART_C; |
132 | bsdlabel[PART_C].pi_offset = ptstart; | | 177 | bsdlabel[PART_C].pi_offset = ptstart; |
133 | bsdlabel[PART_C].pi_size = ptsize; | | 178 | bsdlabel[PART_C].pi_size = ptsize; |
134 | } else { | | 179 | } else { |
135 | part_bsd = part_raw; | | 180 | part_bsd = part_raw; |
136 | } | | 181 | } |
137 | | | 182 | |
138 | if (bootsize != 0) { | | 183 | if (bootsize != 0) { |
139 | bsdlabel[PART_BOOT_FAT12].pi_fstype = FS_MSDOS; | | 184 | bsdlabel[PART_BOOT_FAT12].pi_fstype = FS_MSDOS; |
140 | bsdlabel[PART_BOOT_FAT12].pi_size = bootsize; | | 185 | bsdlabel[PART_BOOT_FAT12].pi_size = bootsize; |
141 | bsdlabel[PART_BOOT_FAT12].pi_offset = bootstart; | | 186 | bsdlabel[PART_BOOT_FAT12].pi_offset = bootstart; |
142 | bsdlabel[PART_BOOT_FAT12].pi_flags |= PART_BOOT_FAT12_PI_FLAGS; | | 187 | bsdlabel[PART_BOOT_FAT12].pi_flags |= PART_BOOT_FAT12_PI_FLAGS; |
143 | strlcpy(bsdlabel[PART_BOOT_FAT12].pi_mount, | | 188 | strlcpy(bsdlabel[PART_BOOT_FAT12].pi_mount, |
144 | PART_BOOT_FAT12_PI_MOUNT, | | 189 | PART_BOOT_FAT12_PI_MOUNT, |
145 | sizeof bsdlabel[PART_BOOT_FAT12].pi_mount); | | 190 | sizeof bsdlabel[PART_BOOT_FAT12].pi_mount); |
146 | } | | 191 | } |
147 | if (binfosize != 0) { | | 192 | if (binfosize != 0) { |
148 | bsdlabel[PART_BOOT_BINFO].pi_fstype = FS_OTHER; | | 193 | bsdlabel[PART_BOOT_BINFO].pi_fstype = FS_OTHER; |
149 | bsdlabel[PART_BOOT_BINFO].pi_size = binfosize; | | 194 | bsdlabel[PART_BOOT_BINFO].pi_size = binfosize; |
150 | bsdlabel[PART_BOOT_BINFO].pi_offset = binfostart; | | 195 | bsdlabel[PART_BOOT_BINFO].pi_offset = binfostart; |
151 | } | | 196 | } |
152 | if (bprepsize != 0) { | | 197 | if (bprepsize != 0) { |
153 | bsdlabel[PART_BOOT_PREP].pi_fstype = FS_BOOT; | | 198 | bsdlabel[PART_BOOT_PREP].pi_fstype = FS_BOOT; |
154 | bsdlabel[PART_BOOT_PREP].pi_size = bprepsize; | | 199 | bsdlabel[PART_BOOT_PREP].pi_size = bprepsize; |
155 | bsdlabel[PART_BOOT_PREP].pi_offset = bprepstart; | | 200 | bsdlabel[PART_BOOT_PREP].pi_offset = bprepstart; |
156 | } | | 201 | } |
157 | | | 202 | |
158 | #ifdef PART_REST | | 203 | #ifdef PART_REST |
159 | bsdlabel[PART_REST].pi_offset = 0; | | 204 | bsdlabel[PART_REST].pi_offset = 0; |
160 | bsdlabel[PART_REST].pi_size = ptstart; | | 205 | bsdlabel[PART_REST].pi_size = ptstart; |
161 | #endif | | 206 | #endif |
162 | | | 207 | |
163 | /* | | 208 | /* |
164 | * Save any partitions that are outside the area we are | | 209 | * Save any partitions that are outside the area we are |
165 | * going to use. | | 210 | * going to use. |
166 | * In particular this saves details of the other MBR | | 211 | * In particular this saves details of the other MBR |
167 | * partitions on a multiboot i386 system. | | 212 | * partitions on a multiboot i386 system. |
168 | */ | | 213 | */ |
169 | for (i = maxpart; i--;) { | | 214 | for (i = maxpart; i--;) { |
170 | if (bsdlabel[i].pi_size != 0) | | 215 | if (bsdlabel[i].pi_size != 0) |
171 | /* Don't overwrite special partitions */ | | 216 | /* Don't overwrite special partitions */ |
172 | continue; | | 217 | continue; |
173 | p = &oldlabel[i]; | | 218 | p = &oldlabel[i]; |
174 | if (p->pi_fstype == FS_UNUSED || p->pi_size == 0) | | 219 | if (p->pi_fstype == FS_UNUSED || p->pi_size == 0) |
175 | continue; | | 220 | continue; |
176 | if (layoutkind == 4) { | | 221 | if (layoutkind == 4) { |
177 | if (PI_ISBSDFS(p)) | | 222 | if (PI_ISBSDFS(p)) |
178 | p->pi_flags |= PIF_MOUNT; | | 223 | p->pi_flags |= PIF_MOUNT; |
179 | } else { | | 224 | } else { |
180 | if (p->pi_offset < ptstart + ptsize && | | 225 | if (p->pi_offset < ptstart + ptsize && |
181 | p->pi_offset + p->pi_size > ptstart) | | 226 | p->pi_offset + p->pi_size > ptstart) |
182 | /* Not outside area we are allocating */ | | 227 | /* Not outside area we are allocating */ |
183 | continue; | | 228 | continue; |
184 | if (p->pi_fstype == FS_SWAP) | | 229 | if (p->pi_fstype == FS_SWAP) |
185 | no_swap = 1; | | 230 | no_swap = 1; |
186 | } | | 231 | } |
187 | bsdlabel[i] = oldlabel[i]; | | 232 | bsdlabel[i] = oldlabel[i]; |
188 | } | | 233 | } |
189 | | | 234 | |
190 | if (layoutkind == 4) { | | 235 | if (layoutkind == 4) { |
191 | /* XXX Check we have a sensible layout */ | | 236 | /* XXX Check we have a sensible layout */ |
192 | ; | | 237 | ; |
193 | } else | | 238 | } else |
194 | get_ptn_sizes(partstart, ptend - partstart, no_swap); | | 239 | get_ptn_sizes(partstart, ptend - partstart, no_swap); |
195 | | | 240 | |
196 | /* | | 241 | /* |
197 | * OK, we have a partition table. Give the user the chance to | | 242 | * OK, we have a partition table. Give the user the chance to |
198 | * edit it and verify it's OK, or abort altogether. | | 243 | * edit it and verify it's OK, or abort altogether. |
199 | */ | | 244 | */ |
200 | edit_check: | | 245 | edit_check: |
201 | if (edit_and_check_label(bsdlabel, maxpart, part_raw, part_bsd) == 0) { | | 246 | if (edit_and_check_label(bsdlabel, maxpart, part_raw, part_bsd) == 0) { |
202 | msg_display(MSG_abort); | | 247 | msg_display(MSG_abort); |
203 | return 0; | | 248 | return 0; |
204 | } | | 249 | } |
205 | if (md_check_partitions() == 0) | | 250 | if (md_check_partitions() == 0) |
206 | goto edit_check; | | 251 | goto edit_check; |
207 | | | 252 | |
208 | /* Disk name */ | | 253 | /* Disk name */ |
209 | msg_prompt(MSG_packname, bsddiskname, bsddiskname, sizeof bsddiskname); | | 254 | msg_prompt(MSG_packname, bsddiskname, bsddiskname, sizeof bsddiskname); |
210 | | | 255 | |
211 | /* save label to disk for MI code to update. */ | | 256 | /* save label to disk for MI code to update. */ |
212 | (void) savenewlabel(bsdlabel, maxpart); | | 257 | (void) savenewlabel(bsdlabel, maxpart); |
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) { |
239 | bootpart_binfo = part; | | 287 | bootpart_binfo = part; |
240 | fprep++; | | 288 | fprep++; |
241 | } | | 289 | } |
242 | } | | 290 | } |
243 | /* oh, the confusion */ | | 291 | /* oh, the confusion */ |
244 | if (ffat >= 1 && fprep < 2) | | 292 | if (ffat >= 1 && fprep < 2) |
245 | return 1; | | 293 | return 1; |
246 | if (ffat < 1 && fprep >= 2) | | 294 | if (ffat < 1 && fprep >= 2) |
247 | return 2; | | 295 | return 2; |
248 | if (ffat >=1 && fprep >= 2) | | 296 | if (ffat >=1 && fprep >= 2) |
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. |
295 | */ | | 347 | */ |
296 | int | | 348 | 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()); |
324 | run_program(RUN_DISPLAY, "/bin/cp /tmp/bootinfo.txt " | | 376 | run_program(RUN_DISPLAY, "/bin/cp /tmp/bootinfo.txt " |
325 | "/%s/boot/ppc", target_prefix()); | | 377 | "/%s/boot/ppc", target_prefix()); |
326 | run_program(RUN_DISPLAY, "/bin/cp /usr/mdec/ofwboot " | | 378 | run_program(RUN_DISPLAY, "/bin/cp /usr/mdec/ofwboot " |
327 | "/%s/boot/ofwboot", target_prefix()); | | 379 | "/%s/boot/ofwboot", target_prefix()); |
328 | } | | 380 | } |
329 | | | 381 | |
330 | if (!noprepfix) { | | 382 | if (!noprepfix) { |
331 | snprintf(bootdev, sizeof bootdev, "/dev/r%s%c", diskdev, | | 383 | snprintf(bootdev, sizeof bootdev, "/dev/r%s%c", diskdev, |
332 | 'a'+bootpart_prep); | | 384 | 'a'+bootpart_prep); |
333 | snprintf(bootbdev, sizeof bootbdev, "/dev/%s%c", diskdev, | | 385 | snprintf(bootbdev, sizeof bootbdev, "/dev/%s%c", diskdev, |
334 | 'a'+bootpart_prep); | | 386 | 'a'+bootpart_prep); |
335 | run_program(RUN_DISPLAY, "/bin/dd if=/dev/zero of=%s bs=512", | | 387 | run_program(RUN_DISPLAY, "/bin/dd if=/dev/zero of=%s bs=512", |
336 | bootdev); | | 388 | bootdev); |
337 | run_program(RUN_DISPLAY, "/bin/dd if=/usr/mdec/ofwboot " | | 389 | run_program(RUN_DISPLAY, "/bin/dd if=/usr/mdec/ofwboot " |
338 | "of=%s bs=512", bootbdev); | | 390 | "of=%s bs=512", bootbdev); |
339 | | | 391 | |
340 | snprintf(bootdev, sizeof bootdev, "/dev/r%s%c", diskdev, | | 392 | snprintf(bootdev, sizeof bootdev, "/dev/r%s%c", diskdev, |
341 | 'a'+bootpart_binfo); | | 393 | 'a'+bootpart_binfo); |
342 | snprintf(bootbdev, sizeof bootbdev, "/dev/%s%c", diskdev, | | 394 | snprintf(bootbdev, sizeof bootbdev, "/dev/%s%c", diskdev, |
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); |
381 | if (!yesno) | | 437 | if (!yesno) |
382 | return 0; | | 438 | return 0; |
383 | nobootfix = 1; | | 439 | nobootfix = 1; |
384 | } | | 440 | } |
385 | } | | 441 | } |
386 | } | | 442 | } |
387 | | | 443 | |
388 | i = md_check_partitions(); | | 444 | i = md_check_partitions(); |
389 | switch (i) { | | 445 | switch (i) { |
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 | |
416 | for (ext = mbri; ext; ext = ext->extended) { | | 473 | for (ext = mbri; ext; ext = ext->extended) { |
417 | part = ext->mbr.mbr_parts; | | 474 | part = ext->mbr.mbr_parts; |
418 | for (i = 0; i < MBR_PART_COUNT; part++, i++) { | | 475 | for (i = 0; i < MBR_PART_COUNT; part++, i++) { |
419 | if (part->mbrp_type == MBR_PTYPE_FAT12) { | | 476 | if (part->mbrp_type == MBR_PTYPE_FAT12) { |
420 | bootstart = part->mbrp_start; | | 477 | bootstart = part->mbrp_start; |
421 | bootsize = part->mbrp_size; | | 478 | bootsize = part->mbrp_size; |
422 | } else if (part->mbrp_type == MBR_PTYPE_PREP && | | 479 | } else if (part->mbrp_type == MBR_PTYPE_PREP && |
423 | part->mbrp_size < 50) { | | 480 | part->mbrp_size < 50) { |
424 | /* this is the bootinfo partition */ | | 481 | /* this is the bootinfo partition */ |
425 | binfostart = part->mbrp_start; | | 482 | binfostart = part->mbrp_start; |
426 | binfosize = part->mbrp_size; | | 483 | binfosize = part->mbrp_size; |
427 | bootinfo_mbr = i+1; | | 484 | bootinfo_mbr = i+1; |
428 | } else if (part->mbrp_type == MBR_PTYPE_PREP && | | 485 | } else if (part->mbrp_type == MBR_PTYPE_PREP && |
429 | part->mbrp_size > 50) { | | 486 | part->mbrp_size > 50) { |
430 | bprepstart = part->mbrp_start; | | 487 | bprepstart = part->mbrp_start; |
431 | bprepsize = part->mbrp_size; | | 488 | bprepsize = part->mbrp_size; |
432 | } | | 489 | } |
433 | break; | | 490 | break; |
434 | } | | 491 | } |
435 | } | | 492 | } |
436 | | | 493 | |
437 | /* we need to either have a pair of prep partitions, or a single | | 494 | /* we need to either have a pair of prep partitions, or a single |
438 | * fat. if neither, things are broken. */ | | 495 | * fat. if neither, things are broken. */ |
439 | if (!(bootsize >= (MIN_FAT12_BOOT/512) || | | 496 | if (!(bootsize >= (MIN_FAT12_BOOT/512) || |
440 | (binfosize >= (MIN_BINFO_BOOT/512) && | | 497 | (binfosize >= (MIN_BINFO_BOOT/512) && |
441 | bprepsize >= (MIN_PREP_BOOT/512)))) { | | 498 | bprepsize >= (MIN_PREP_BOOT/512)))) { |
442 | msg_display(MSG_bootnotright); | | 499 | msg_display(MSG_bootnotright); |
443 | msg_display_add(MSG_reeditpart, 0); | | 500 | msg_display_add(MSG_reeditpart, 0); |
444 | process_menu(MENU_yesno, NULL); | | 501 | process_menu(MENU_yesno, NULL); |
445 | if (!yesno) | | 502 | if (!yesno) |
446 | return 0; | | 503 | return 0; |
447 | return 1; | | 504 | return 1; |
448 | } | | 505 | } |
449 | | | 506 | |
450 | /* check the prep partitions */ | | 507 | /* check the prep partitions */ |
451 | if ((binfosize > 0 || bprepsize > 0) && | | 508 | if ((binfosize > 0 || bprepsize > 0) && |
452 | (binfosize < (MIN_BINFO_BOOT/512) || | | 509 | (binfosize < (MIN_BINFO_BOOT/512) || |
453 | bprepsize < (MIN_PREP_BOOT/512))) { | | 510 | bprepsize < (MIN_PREP_BOOT/512))) { |
454 | msg_display(MSG_preptoosmall); | | 511 | msg_display(MSG_preptoosmall); |
455 | msg_display_add(MSG_reeditpart, 0); | | 512 | msg_display_add(MSG_reeditpart, 0); |
456 | process_menu(MENU_yesno, NULL); | | 513 | process_menu(MENU_yesno, NULL); |
457 | if (!yesno) | | 514 | if (!yesno) |
458 | return 0; | | 515 | return 0; |
459 | return 1; | | 516 | return 1; |
460 | } | | 517 | } |
461 | | | 518 | |
462 | /* check the fat12 parititons */ | | 519 | /* check the fat12 parititons */ |
463 | if (bootsize > 0 && bootsize < (MIN_FAT12_BOOT/512)) { | | 520 | if (bootsize > 0 && bootsize < (MIN_FAT12_BOOT/512)) { |
464 | msg_display(MSG_boottoosmall); | | 521 | msg_display(MSG_boottoosmall); |
465 | msg_display_add(MSG_reeditpart, 0); | | 522 | msg_display_add(MSG_reeditpart, 0); |
466 | process_menu(MENU_yesno, NULL); | | 523 | process_menu(MENU_yesno, NULL); |
467 | if (!yesno) | | 524 | if (!yesno) |
468 | return 0; | | 525 | return 0; |
469 | return 1; | | 526 | return 1; |
470 | } | | 527 | } |
471 | | | 528 | |
472 | /* if both sets contain zero, thats bad */ | | 529 | /* if both sets contain zero, thats bad */ |
473 | if ((bootstart == 0 || bootsize == 0) && | | 530 | if ((bootstart == 0 || bootsize == 0) && |
474 | (binfosize == 0 || binfostart == 0 || | | 531 | (binfosize == 0 || binfostart == 0 || |
475 | bprepsize == 0 || bprepstart == 0)) { | | 532 | bprepsize == 0 || bprepstart == 0)) { |
476 | msg_display(MSG_nobootpart); | | 533 | msg_display(MSG_nobootpart); |
477 | msg_display_add(MSG_reeditpart, 0); | | 534 | msg_display_add(MSG_reeditpart, 0); |
478 | process_menu(MENU_yesno, NULL); | | 535 | process_menu(MENU_yesno, NULL); |
479 | if (!yesno) | | 536 | if (!yesno) |
480 | return 0; | | 537 | return 0; |
481 | return 1; | | 538 | return 1; |
482 | } | | 539 | } |
483 | return 2; | | 540 | return 2; |
484 | } | | 541 | } |
485 | | | 542 | |
486 | /* | | 543 | /* |
487 | * NOTE, we use a reserved partition type, because some RS/6000 machines hang | | 544 | * NOTE, we use a reserved partition type, because some RS/6000 machines hang |
488 | * hard if they find a FAT12, and if we use type prep, that indicates that | | 545 | * hard if they find a FAT12, and if we use type prep, that indicates that |
489 | * it should be read raw. | | 546 | * it should be read raw. |
490 | * One partition for FAT12 booting | | 547 | * One partition for FAT12 booting |
491 | * One partition for NetBSD | | 548 | * One partition for NetBSD |
492 | * One partition to hold the bootinfo.txt file | | 549 | * One partition to hold the bootinfo.txt file |
493 | * One partition to hold ofwboot | | 550 | * One partition to hold ofwboot |
494 | */ | | 551 | */ |
495 | | | 552 | |
496 | int | | 553 | int |
497 | md_mbr_use_wholedisk(mbr_info_t *mbri) | | 554 | md_mbr_use_wholedisk(mbr_info_t *mbri) |
498 | { | | 555 | { |
499 | struct mbr_sector *mbrs = &mbri->mbr; | | 556 | struct mbr_sector *mbrs = &mbri->mbr; |
500 | mbr_info_t *ext; | | 557 | mbr_info_t *ext; |
501 | struct mbr_partition *part; | | 558 | struct mbr_partition *part; |
502 | | | 559 | |
503 | part = &mbrs->mbr_parts[0]; | | 560 | part = &mbrs->mbr_parts[0]; |
504 | /* Set the partition information for full disk usage. */ | | 561 | /* Set the partition information for full disk usage. */ |
505 | while ((ext = mbri->extended)) { | | 562 | while ((ext = mbri->extended)) { |
506 | mbri->extended = ext->extended; | | 563 | mbri->extended = ext->extended; |
507 | free(ext); | | 564 | free(ext); |
508 | } | | 565 | } |
509 | memset(part, 0, MBR_PART_COUNT * sizeof *part); | | 566 | memset(part, 0, MBR_PART_COUNT * sizeof *part); |
510 | | | 567 | |
511 | part[0].mbrp_type = MBR_PTYPE_RESERVED_x21; | | 568 | part[0].mbrp_type = MBR_PTYPE_RESERVED_x21; |
512 | part[0].mbrp_size = FAT12_BOOT_SIZE/512; | | 569 | part[0].mbrp_size = FAT12_BOOT_SIZE/512; |
513 | part[0].mbrp_start = bsec; | | 570 | part[0].mbrp_start = bsec; |
514 | part[0].mbrp_flag = 0; | | 571 | part[0].mbrp_flag = 0; |
515 | | | 572 | |
516 | part[1].mbrp_type = MBR_PTYPE_NETBSD; | | 573 | part[1].mbrp_type = MBR_PTYPE_NETBSD; |
517 | part[1].mbrp_size = dlsize - (bsec + FAT12_BOOT_SIZE/512 + | | 574 | part[1].mbrp_size = dlsize - (bsec + FAT12_BOOT_SIZE/512 + |
518 | BINFO_BOOT_SIZE/512 + PREP_BOOT_SIZE/512); | | 575 | BINFO_BOOT_SIZE/512 + PREP_BOOT_SIZE/512); |
519 | part[1].mbrp_start = bsec + FAT12_BOOT_SIZE/512 + BINFO_BOOT_SIZE/512 + | | 576 | part[1].mbrp_start = bsec + FAT12_BOOT_SIZE/512 + BINFO_BOOT_SIZE/512 + |
520 | PREP_BOOT_SIZE/512; | | 577 | PREP_BOOT_SIZE/512; |
521 | part[1].mbrp_flag = MBR_PFLAG_ACTIVE; | | 578 | part[1].mbrp_flag = MBR_PFLAG_ACTIVE; |
522 | | | 579 | |
523 | part[2].mbrp_type = MBR_PTYPE_PREP; | | 580 | part[2].mbrp_type = MBR_PTYPE_PREP; |
524 | part[2].mbrp_size = BINFO_BOOT_SIZE/512; | | 581 | part[2].mbrp_size = BINFO_BOOT_SIZE/512; |
525 | part[2].mbrp_start = bsec + FAT12_BOOT_SIZE/512; | | 582 | part[2].mbrp_start = bsec + FAT12_BOOT_SIZE/512; |
526 | part[2].mbrp_flag = 0; | | 583 | part[2].mbrp_flag = 0; |
527 | | | 584 | |
528 | part[3].mbrp_type = MBR_PTYPE_PREP; | | 585 | part[3].mbrp_type = MBR_PTYPE_PREP; |
529 | part[3].mbrp_size = PREP_BOOT_SIZE/512; | | 586 | part[3].mbrp_size = PREP_BOOT_SIZE/512; |
530 | part[3].mbrp_start = bsec + FAT12_BOOT_SIZE/512 + BINFO_BOOT_SIZE/512; | | 587 | part[3].mbrp_start = bsec + FAT12_BOOT_SIZE/512 + BINFO_BOOT_SIZE/512; |
531 | part[3].mbrp_flag = 0; | | 588 | part[3].mbrp_flag = 0; |
532 | | | 589 | |
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 | } |