Expand PMF_FN_* macros.
[netbsd-mini2440.git] / distrib / utils / sysinst / bsddisklabel.c
blob49e6f2bbce4b6e462672d5886d44b17155da784f
1 /* $NetBSD: bsddisklabel.c,v 1.52 2009/05/14 16:23:38 sborrill Exp $ */
3 /*
4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved.
7 * Based on code written by Philip A. Nelson for Piermont Information
8 * Systems Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by
21 * Piermont Information Systems Inc.
22 * 4. The name of Piermont Information Systems Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
24 * written permission.
26 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36 * THE POSSIBILITY OF SUCH DAMAGE.
39 /* bsddisklabel.c -- generate standard BSD disklabel */
40 /* Included by appropriate arch/XXXX/md.c */
42 #include <sys/param.h>
43 #include <sys/sysctl.h>
44 #include <sys/exec.h>
45 #include <sys/utsname.h>
46 #include <sys/types.h>
47 #include <sys/stat.h>
48 #include <machine/cpu.h>
49 #include <stdio.h>
50 #include <stddef.h>
51 #include <util.h>
52 #include <dirent.h>
53 #include "defs.h"
54 #include "md.h"
55 #include "endian.h"
56 #include "msg_defs.h"
57 #include "menu_defs.h"
59 static int check_partitions(void);
61 /* For the current state of this file blame abs@NetBSD.org */
62 /* Even though he wasn't the last to hack it, but he did admit doing so :-) */
64 #define PART_ANY -1
65 #define PART_EXTRA -2
66 #define PART_TMP_RAMDISK -3
68 /* Defaults for things that might be defined in md.h */
69 #ifndef PART_ROOT
70 #define PART_ROOT PART_A
71 #endif
72 #ifndef PART_SWAP
73 #define PART_SWAP PART_B
74 #endif
75 #ifndef PART_USR
76 #define PART_USR PART_ANY
77 #endif
79 #ifndef DEFVARSIZE
80 #define DEFVARSIZE 32
81 #endif
82 #ifndef DEFROOTSIZE
83 #define DEFROOTSIZE 32
84 #endif
85 #ifndef DEFUSRSIZE
86 #define DEFUSRSIZE 128
87 #endif
88 #ifndef DEFSWAPSIZE
89 #define DEFSWAPSIZE 128
90 #endif
92 int
93 save_ptn(int ptn, daddr_t start, daddr_t size, int fstype, const char *mountpt)
95 static int maxptn;
96 partinfo *p;
97 int pp;
99 if (maxptn == 0)
100 maxptn = getmaxpartitions();
102 if (ptn < 0 || bsdlabel[ptn].pi_fstype != FS_UNUSED) {
103 ptn = getrawpartition() + 1;
104 #ifdef PART_FIRST_FREE
105 if (ptn < PART_FIRST_FREE)
106 ptn = PART_FIRST_FREE;
107 #endif
108 for (;; ptn++) {
109 if (ptn >= maxptn)
110 return -1;
111 if (ptn == PART_USR)
112 continue;
113 if (bsdlabel[ptn].pi_fstype == FS_UNUSED)
114 break;
118 if (fstype == FS_UNUSED)
119 return ptn;
121 p = bsdlabel + ptn;
122 p->pi_offset = start;
123 p->pi_size = size;
124 set_ptype(p, fstype, mountpt ? PIF_NEWFS : 0);
126 if (mountpt != NULL) {
127 for (pp = 0; pp < maxptn; pp++) {
128 if (strcmp(bsdlabel[pp].pi_mount, mountpt) == 0)
129 bsdlabel[pp].pi_flags &= ~PIF_MOUNT;
131 strlcpy(p->pi_mount, mountpt, sizeof p->pi_mount);
132 p->pi_flags |= PIF_MOUNT;
133 /* Default to logging, UFS2. */
134 if (p->pi_fstype == FS_BSDFFS) {
135 p->pi_flags |= PIF_LOG;
136 #ifdef DEFAULT_UFS2
137 #ifndef HAVE_UFS2_BOOT
138 if (strcmp(mountpt, "/") != 0)
139 #endif
140 p->pi_flags |= PIF_FFSv2;
141 #endif
145 return ptn;
148 void
149 set_ptn_titles(menudesc *m, int opt, void *arg)
151 struct ptn_info *pi = arg;
152 struct ptn_size *p;
153 int sm = MEG / sectorsize;
154 daddr_t size;
155 char inc_free[12];
157 p = &pi->ptn_sizes[opt];
158 if (p->mount[0] == 0) {
159 wprintw(m->mw, msg_string(MSG_add_another_ptn));
160 return;
162 size = p->size;
163 if (p == pi->pool_part)
164 snprintf(inc_free, sizeof inc_free, "(%" PRIi64 ")",
165 (size + pi->free_space) / sm);
166 else
167 inc_free[0] = 0;
168 wprintw(m->mw, "%6" PRIi64 "%8s%10" PRIi64 "%10" PRIi64 " %c %s",
169 size / sm, inc_free, size / dlcylsize, size,
170 p == pi->pool_part ? '+' : ' ', p->mount);
173 void
174 set_ptn_menu(struct ptn_info *pi)
176 struct ptn_size *p;
177 menu_ent *m;
179 for (m = pi->ptn_menus, p = pi->ptn_sizes;; m++, p++) {
180 m->opt_name = NULL;
181 m->opt_menu = OPT_NOMENU;
182 m->opt_flags = 0;
183 m->opt_action = set_ptn_size;
184 if (p->mount[0] == 0)
185 break;
187 if (pi->free_parts != 0)
188 m++;
189 m->opt_name = MSG_askunits;
190 m->opt_menu = MENU_sizechoice;
191 m->opt_flags = OPT_SUB;
192 m->opt_action = NULL;
193 m++;
195 if (pi->free_space >= 0)
196 snprintf(pi->exit_msg, sizeof pi->exit_msg,
197 msg_string(MSG_fssizesok),
198 (int)(pi->free_space / sizemult), multname, pi->free_parts);
199 else
200 snprintf(pi->exit_msg, sizeof pi->exit_msg,
201 msg_string(MSG_fssizesbad),
202 (int)(-pi->free_space / sizemult), multname, (uint) -pi->free_space);
204 set_menu_numopts(pi->menu_no, m - pi->ptn_menus);
208 set_ptn_size(menudesc *m, void *arg)
210 struct ptn_info *pi = arg;
211 struct ptn_size *p;
212 char answer[10];
213 char dflt[10];
214 char *cp;
215 daddr_t size, old_size;
216 int mult;
218 p = pi->ptn_sizes + m->cursel;
220 if (pi->free_parts == 0 && p->size == 0)
221 /* Don't allow 'free_parts' to go negative */
222 return 0;
224 if (p->mount[0] == 0) {
225 msg_prompt_win(MSG_askfsmount, -1, 18, 0, 0,
226 NULL, p->mount, sizeof p->mount);
227 if (p->mount[0] == 0)
228 return 0;
231 size = p->size;
232 old_size = size;
233 if (size == 0)
234 size = p->dflt_size;
235 size /= sizemult;
236 snprintf(dflt, sizeof dflt, "%" PRIi64 "%s",
237 size, p == pi->pool_part ? "+" : "");
239 for (;;) {
240 mult = sizemult;
241 msg_prompt_win(MSG_askfssize, -1, 18, 0, 0,
242 dflt, answer, sizeof answer,
243 p->mount, multname);
244 /* Some special cases when /usr is first given a size */
245 if (old_size == 0 && !strcmp(p->mount, "/usr")) {
246 /* Remove space for /usr from / */
247 if (!pi->ptn_sizes[0].changed) {
248 pi->ptn_sizes[0].size -= p->dflt_size;
249 pi->free_space += p->dflt_size;
250 pi->ptn_sizes[0].changed = 1;
252 /* hack to add free space to default sized /usr */
253 if (!strcmp(answer, dflt)) {
254 size = p->dflt_size;
255 pi->pool_part = p;
256 goto adjust_free;
259 size = strtoul(answer, &cp, 0);
260 switch (*cp++) {
261 default:
262 continue;
263 case 's':
264 mult = 1;
265 break;
266 case 'c':
267 mult = dlcylsize;
268 break;
269 case 'm':
270 case 'M':
271 mult = MEG / sectorsize;
272 break;
273 case 'g':
274 case 'G':
275 mult = 1024 * MEG / sectorsize;
276 break;
277 case '+':
278 cp--;
279 if (cp != answer)
280 break;
281 mult = 1;
282 size = old_size;
283 break;
284 case 0:
285 cp--;
286 break;
288 if (*cp == 0 || *cp == '+')
289 break;
292 size = NUMSEC(size, mult, dlcylsize);
293 if (p->ptn_id == PART_TMP_RAMDISK) {
294 p->size = size;
295 return 0;
297 if (p == pi->pool_part)
298 pi->pool_part = NULL;
299 if (*cp == '+' && p->limit == 0) {
300 pi->pool_part = p;
301 if (size == 0)
302 size = dlcylsize;
304 if (p->limit != 0 && size > p->limit)
305 size = p->limit;
306 adjust_free:
307 if (size != old_size)
308 p->changed = 1;
309 pi->free_space += old_size - size;
310 p->size = size;
311 if (size == 0) {
312 if (old_size != 0)
313 pi->free_parts++;
314 if (p->ptn_id == PART_EXTRA)
315 memmove(p, p + 1,
316 (char *)&pi->ptn_sizes[MAXPARTITIONS]
317 - (char *)p);
318 } else {
319 int f = pi->free_space;
320 if (old_size == 0)
321 pi->free_parts--;
322 if (f < mult && -f < mult) {
324 * Round size to end of available space,
325 * but keep cylinder alignment
327 if (f < 0)
328 f = -roundup(-f, dlcylsize);
329 else
330 f = rounddown(f, dlcylsize);
331 size += f;
332 if (size != 0) {
333 pi->free_space -= f;
334 p->size += f;
339 set_ptn_menu(pi);
341 return 0;
344 void
345 get_ptn_sizes(daddr_t part_start, daddr_t sectors, int no_swap)
347 int i;
348 int maxpart = getmaxpartitions();
349 int sm; /* sectors in 1MB */
350 struct ptn_size *p;
351 daddr_t size;
353 static struct ptn_info pi = { -1, {
354 #define PI_ROOT 0
355 { PART_ROOT, { '/', '\0' },
356 DEFROOTSIZE, DEFROOTSIZE , 0, 0},
357 #define PI_SWAP 1
358 { PART_SWAP, { 's', 'w', 'a', 'p', '\0' },
359 DEFSWAPSIZE, DEFSWAPSIZE, 0, 0 },
360 { PART_TMP_RAMDISK,
361 #ifdef HAVE_TMPFS
362 { 't', 'm', 'p', ' ', '(', 't', 'm', 'p', 'f', 's', ')', '\0' },
363 #else
364 { 't', 'm', 'p', ' ', '(', 'm', 'f', 's', ')', '\0' },
365 #endif
366 64, 0, 0, 0 },
367 #define PI_USR 3
368 { PART_USR, { '/', 'u', 's', 'r', '\0' }, DEFUSRSIZE,
369 0, 0, 0 },
370 { PART_ANY, { '/', 'v', 'a', 'r', '\0' }, DEFVARSIZE,
371 0, 0, 0 },
372 { PART_ANY, { '/', 'h', 'o', 'm', 'e', '\0' }, 0,
373 0, 0, 0 },
374 }, {
375 { NULL, OPT_NOMENU, 0, set_ptn_size },
376 { MSG_askunits, MENU_sizechoice, OPT_SUB, NULL },
377 }, 0, 0, NULL, { 0 } };
379 if (maxpart > MAXPARTITIONS)
380 maxpart = MAXPARTITIONS; /* sanity */
382 msg_display(MSG_ptnsizes);
383 msg_table_add(MSG_ptnheaders);
385 if (pi.menu_no < 0) {
386 /* If there is a swap partition elsewhere, don't add one here.*/
387 if (no_swap) {
388 pi.ptn_sizes[PI_SWAP].size = 0;
389 } else {
390 #if DEFSWAPSIZE == -1
391 /* Dynamic swap size. */
392 pi.ptn_sizes[PI_SWAP].dflt_size = get_ramsize();
393 pi.ptn_sizes[PI_SWAP].size =
394 pi.ptn_sizes[PI_SWAP].dflt_size;
395 #endif
398 /* If installing X increase default size of /usr */
399 if (set_X11_selected())
400 pi.ptn_sizes[PI_USR].dflt_size += XNEEDMB;
402 /* Start of planning to give free space to / */
403 pi.pool_part = &pi.ptn_sizes[PI_ROOT];
404 /* Make size of root include default size of /usr */
405 pi.ptn_sizes[PI_ROOT].size += pi.ptn_sizes[PI_USR].dflt_size;
407 sm = MEG / sectorsize;
409 if (root_limit != 0) {
410 /* Bah - bios can not read all the disk, limit root */
411 pi.ptn_sizes[PI_ROOT].limit = root_limit - part_start;
412 /* Allocate a /usr partition if bios can't read
413 * everything except swap.
415 if (pi.ptn_sizes[PI_ROOT].limit
416 < sectors - pi.ptn_sizes[PI_SWAP].size * sm) {
417 /* Root won't be able to access all the space */
418 /* Claw back space for /usr */
419 pi.ptn_sizes[PI_USR].size =
420 pi.ptn_sizes[PI_USR].dflt_size;
421 pi.ptn_sizes[PI_ROOT].size -=
422 pi.ptn_sizes[PI_USR].dflt_size;
423 pi.ptn_sizes[PI_ROOT].changed = 1;
424 /* Give free space to /usr */
425 pi.pool_part = &pi.ptn_sizes[PI_USR];
429 /* Change preset sizes from MB to sectors */
430 pi.free_space = sectors;
431 for (p = pi.ptn_sizes; p->mount[0]; p++) {
432 p->size = NUMSEC(p->size, sm, dlcylsize);
433 p->dflt_size = NUMSEC(p->dflt_size, sm, dlcylsize);
434 pi.free_space -= p->size;
437 /* Steal space from swap to make things fit.. */
438 if (pi.free_space < 0) {
439 i = roundup(-pi.free_space, dlcylsize);
440 if (i > pi.ptn_sizes[PI_SWAP].size)
441 i = pi.ptn_sizes[PI_SWAP].size;
442 pi.ptn_sizes[PI_SWAP].size -= i;
443 pi.free_space += i;
446 /* Add space for 2 system dumps to / (traditional) */
447 i = get_ramsize() * sm;
448 i = roundup(i, dlcylsize);
449 if (pi.free_space > i * 2)
450 i *= 2;
451 if (pi.free_space > i) {
452 pi.ptn_sizes[PI_ROOT].size += i;
453 pi.free_space -= i;
456 /* Ensure all of / is readable by the system boot code */
457 i = pi.ptn_sizes[PI_ROOT].limit;
458 if (i != 0 && (i -= pi.ptn_sizes[PI_ROOT].size) < 0) {
459 pi.ptn_sizes[PI_ROOT].size += i;
460 pi.free_space -= i;
463 /* Count free partition slots */
464 pi.free_parts = 0;
465 for (i = 0; i < maxpart; i++) {
466 if (bsdlabel[i].pi_size == 0)
467 pi.free_parts++;
469 for (i = 0; i < MAXPARTITIONS; i++) {
470 p = &pi.ptn_sizes[i];
471 if (i != 0 && p->ptn_id == 0)
472 p->ptn_id = PART_EXTRA;
473 if (p->size != 0)
474 pi.free_parts--;
477 pi.menu_no = new_menu(0, pi.ptn_menus, nelem(pi.ptn_menus),
478 3, -1, 12, 70,
479 MC_NOSHORTCUT |
480 MC_ALWAYS_SCROLL | MC_NOBOX | MC_NOCLEAR,
481 NULL, set_ptn_titles, NULL,
482 "help", pi.exit_msg);
484 if (pi.menu_no < 0)
485 return;
488 do {
489 set_ptn_menu(&pi);
490 current_cylsize = dlcylsize;
491 process_menu(pi.menu_no, &pi);
492 } while (pi.free_space < 0 || pi.free_parts < 0);
494 /* Give any cylinder fragment to last partition */
495 if (pi.pool_part != NULL || pi.free_space < dlcylsize) {
496 for (p = pi.ptn_sizes + nelem(pi.ptn_sizes) - 1; ;p--) {
497 if (p->size == 0) {
498 if (p == pi.ptn_sizes)
499 break;
500 continue;
502 if (p->ptn_id == PART_TMP_RAMDISK)
503 continue;
504 p->size += pi.free_space % dlcylsize;
505 break;
509 for (p = pi.ptn_sizes; p->mount[0]; p++, part_start += size) {
510 size = p->size;
511 if (p == pi.pool_part) {
512 size += rounddown(pi.free_space, dlcylsize);
513 if (p->limit != 0 && size > p->limit)
514 size = p->limit;
516 i = p->ptn_id;
517 if (i == PART_TMP_RAMDISK) {
518 tmp_ramdisk_size = size;
519 size = 0;
520 continue;
522 if (size == 0)
523 continue;
524 if (i == PART_SWAP) {
525 save_ptn(i, part_start, size, FS_SWAP, NULL);
526 continue;
528 save_ptn(i, part_start, size, FS_BSDFFS, p->mount);
533 * md back-end code for menu-driven BSD disklabel editor.
536 make_bsd_partitions(void)
538 int i;
539 int part;
540 int maxpart = getmaxpartitions();
541 daddr_t partstart;
542 int part_raw, part_bsd;
543 daddr_t ptend;
544 int no_swap = 0, valid_part = -1;
545 partinfo *p;
548 * Initialize global variables that track space used on this disk.
549 * Standard 4.4BSD 8-partition labels always cover whole disk.
551 if (ptsize == 0)
552 ptsize = dlsize - ptstart;
553 if (dlsize == 0)
554 dlsize = ptstart + ptsize;
556 partstart = ptstart;
557 ptend = ptstart + ptsize;
559 /* Ask for layout type -- standard or special */
560 msg_display(MSG_layout,
561 (int) (ptsize / (MEG / sectorsize)),
562 DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE,
563 DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE + XNEEDMB);
565 process_menu(MENU_layout, NULL);
567 /* Set so we use the 'real' geometry for rounding, input in MB */
568 current_cylsize = dlcylsize;
569 set_sizemultname_meg();
571 /* Build standard partitions */
572 memset(&bsdlabel, 0, sizeof bsdlabel);
574 /* Set initial partition types to unused */
575 for (part = 0 ; part < maxpart ; ++part)
576 bsdlabel[part].pi_fstype = FS_UNUSED;
578 /* Whole disk partition */
579 part_raw = getrawpartition();
580 if (part_raw == -1)
581 part_raw = PART_C; /* for sanity... */
582 bsdlabel[part_raw].pi_offset = 0;
583 bsdlabel[part_raw].pi_size = dlsize;
585 if (part_raw == PART_D) {
586 /* Probably a system that expects an i386 style mbr */
587 part_bsd = PART_C;
588 bsdlabel[PART_C].pi_offset = ptstart;
589 bsdlabel[PART_C].pi_size = ptsize;
590 } else {
591 part_bsd = part_raw;
594 #if defined(PART_BOOT) && defined(BOOT_SIZE)
595 i = BOOT_SIZE;
596 if (i >= 1024) {
597 /* Treat big numbers as a byte count */
598 i = (i + dlcylsize * sectorsize - 1) / (dlcylsize * sectorsize);
599 i *= dlcylsize;
601 bsdlabel[PART_BOOT].pi_fstype = FS_BOOT;
602 bsdlabel[PART_BOOT].pi_size = i;
603 #ifdef BOOT_HIGH
604 bsdlabel[PART_BOOT].pi_offset = ptend - i;
605 ptend -= i;
606 #else
607 bsdlabel[PART_BOOT].pi_offset = ptstart;
608 partstart += i;
609 #endif
610 #elif defined(PART_BOOT)
611 if (bootsize != 0) {
612 bsdlabel[PART_BOOT].pi_fstype = FS_BOOT;
613 bsdlabel[PART_BOOT].pi_size = bootsize;
614 bsdlabel[PART_BOOT].pi_offset = bootstart;
615 #if defined(PART_BOOT_PI_FLAGS)
616 bsdlabel[PART_BOOT].pi_flags |= PART_BOOT_PI_FLAGS;
617 #endif
618 #if defined(PART_BOOT_PI_MOUNT)
619 strlcpy(bsdlabel[PART_BOOT].pi_mount, PART_BOOT_PI_MOUNT,
620 sizeof bsdlabel[PART_BOOT].pi_mount);
621 #endif
623 #endif /* PART_BOOT w/o BOOT_SIZE */
625 #if defined(PART_SYSVBFS) && defined(SYSVBFS_SIZE)
626 bsdlabel[PART_SYSVBFS].pi_offset = partstart;
627 bsdlabel[PART_SYSVBFS].pi_fstype = FS_SYSVBFS;
628 bsdlabel[PART_SYSVBFS].pi_size = SYSVBFS_SIZE;
629 bsdlabel[PART_SYSVBFS].pi_flags |= PIF_NEWFS | PIF_MOUNT;
630 strlcpy(bsdlabel[PART_SYSVBFS].pi_mount, "/stand",
631 sizeof bsdlabel[PART_SYSVBFS].pi_mount);
632 partstart += SYSVBFS_SIZE;
633 #endif
635 #ifdef PART_REST
636 bsdlabel[PART_REST].pi_offset = 0;
637 bsdlabel[PART_REST].pi_size = ptstart;
638 #endif
640 if (layoutkind == 4) {
642 * If 'oldlabel' is a default label created by the kernel it
643 * will have exactly one valid partition besides raw_part
644 * which covers the whole disk - but might lie outside the
645 * mbr partition we (by now) have offset by a few sectors.
646 * Check for this and and fix ut up.
648 valid_part = -1;
649 for (i = 0; i < maxpart; i++) {
650 if (i == part_raw)
651 continue;
652 if (oldlabel[i].pi_size > 0 && PI_ISBSDFS(&oldlabel[i])) {
653 if (valid_part >= 0) {
654 /* nope, not the default case */
655 valid_part = -1;
656 break;
658 valid_part = i;
661 if (valid_part >= 0 && oldlabel[valid_part].pi_offset < ptstart) {
662 oldlabel[valid_part].pi_offset = ptstart;
663 oldlabel[valid_part].pi_size -= ptstart;
668 * Save any partitions that are outside the area we are
669 * going to use.
670 * In particular this saves details of the other MBR
671 * partitions on a multiboot i386 system.
673 for (i = maxpart; i--;) {
674 if (bsdlabel[i].pi_size != 0)
675 /* Don't overwrite special partitions */
676 continue;
677 p = &oldlabel[i];
678 if (p->pi_fstype == FS_UNUSED || p->pi_size == 0)
679 continue;
680 if (layoutkind == 4) {
681 if (PI_ISBSDFS(p)) {
682 p->pi_flags |= PIF_MOUNT;
683 if (layoutkind == 4 && i == valid_part) {
684 int fstype = p->pi_fstype;
685 p->pi_fstype = 0;
686 strcpy(p->pi_mount, "/");
687 set_ptype(p, fstype, PIF_NEWFS);
690 } else {
691 if (p->pi_offset < ptstart + ptsize &&
692 p->pi_offset + p->pi_size > ptstart)
693 /* Not outside area we are allocating */
694 continue;
695 if (p->pi_fstype == FS_SWAP)
696 no_swap = 1;
698 bsdlabel[i] = oldlabel[i];
701 if (layoutkind != 4)
702 get_ptn_sizes(partstart, ptend - partstart, no_swap);
705 * OK, we have a partition table. Give the user the chance to
706 * edit it and verify it's OK, or abort altogether.
708 edit_check:
709 if (edit_and_check_label(bsdlabel, maxpart, part_raw, part_bsd) == 0) {
710 msg_display(MSG_abort);
711 return 0;
713 if (check_partitions() == 0)
714 goto edit_check;
716 /* Disk name */
717 msg_prompt(MSG_packname, bsddiskname, bsddiskname, sizeof bsddiskname);
719 /* save label to disk for MI code to update. */
720 (void) savenewlabel(bsdlabel, maxpart);
722 /* Everything looks OK. */
723 return (1);
727 * check that there is at least a / somewhere.
729 static int
730 check_partitions(void)
732 #ifdef HAVE_BOOTXX_xFS
733 int rv;
734 char *bootxx;
735 #endif
736 #ifndef HAVE_UFS2_BOOT
737 int fstype;
738 #endif
740 #ifdef HAVE_BOOTXX_xFS
741 /* check if we have boot code for the root partition type */
742 bootxx = bootxx_name();
743 if (bootxx != NULL) {
744 rv = access(bootxx, R_OK);
745 free(bootxx);
747 if (bootxx == NULL || rv != 0) {
748 process_menu(MENU_ok, deconst(MSG_No_Bootcode));
749 return 0;
751 #endif
752 #ifndef HAVE_UFS2_BOOT
753 fstype = bsdlabel[rootpart].pi_fstype;
754 if (fstype == FS_BSDFFS &&
755 (bsdlabel[rootpart].pi_flags & PIF_FFSv2) != 0) {
756 process_menu(MENU_ok, deconst(MSG_cannot_ufs2_root));
757 return 0;
759 #endif
761 return md_check_partitions();