Annotation of src/distrib/utils/sysinst/bsddisklabel.c, Revision 1.60
1.60 ! tsutsui 1: /* $NetBSD: bsddisklabel.c,v 1.59 2013/11/04 20:07:49 christos Exp $ */
1.1 abs 2:
3: /*
4: * Copyright 1997 Piermont Information Systems Inc.
5: * All rights reserved.
6: *
7: * Based on code written by Philip A. Nelson for Piermont Information
8: * Systems Inc.
9: *
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.
1.55 mbalmer 18: * 3. The name of Piermont Information Systems Inc. may not be used to endorse
1.1 abs 19: * or promote products derived from this software without specific prior
20: * written permission.
21: *
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
24: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25: * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
26: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
32: * THE POSSIBILITY OF SUCH DAMAGE.
33: */
34:
35: /* bsddisklabel.c -- generate standard BSD disklabel */
36: /* Included by appropriate arch/XXXX/md.c */
37:
1.7 dsl 38: #include <sys/param.h>
39: #include <sys/sysctl.h>
40: #include <sys/exec.h>
41: #include <sys/utsname.h>
42: #include <sys/types.h>
43: #include <sys/stat.h>
44: #include <machine/cpu.h>
45: #include <stdio.h>
46: #include <stddef.h>
47: #include <util.h>
48: #include <dirent.h>
49: #include "defs.h"
50: #include "md.h"
51: #include "endian.h"
52: #include "msg_defs.h"
53: #include "menu_defs.h"
54:
1.51 tsutsui 55: static int check_partitions(void);
56:
1.21 salo 57: /* For the current state of this file blame abs@NetBSD.org */
1.7 dsl 58: /* Even though he wasn't the last to hack it, but he did admit doing so :-) */
59:
1.53 ahoka 60: #define PART_ANY -1
61: #define PART_EXTRA -2
62: #define PART_TMP_RAMDISK -3
1.14 dsl 63:
1.7 dsl 64: /* Defaults for things that might be defined in md.h */
65: #ifndef PART_ROOT
1.26 dsl 66: #define PART_ROOT PART_A
1.7 dsl 67: #endif
68: #ifndef PART_SWAP
1.26 dsl 69: #define PART_SWAP PART_B
1.7 dsl 70: #endif
71: #ifndef PART_USR
1.14 dsl 72: #define PART_USR PART_ANY
1.7 dsl 73: #endif
74:
75: #ifndef DEFVARSIZE
76: #define DEFVARSIZE 32
77: #endif
78: #ifndef DEFROOTSIZE
79: #define DEFROOTSIZE 32
80: #endif
81: #ifndef DEFUSRSIZE
82: #define DEFUSRSIZE 128
83: #endif
1.17 dsl 84: #ifndef DEFSWAPSIZE
85: #define DEFSWAPSIZE 128
86: #endif
1.1 abs 87:
1.44 garbled 88: int
1.52 sborrill 89: save_ptn(int ptn, daddr_t start, daddr_t size, int fstype, const char *mountpt)
1.7 dsl 90: {
1.12 dsl 91: static int maxptn;
1.32 dsl 92: partinfo *p;
93: int pp;
1.7 dsl 94:
1.12 dsl 95: if (maxptn == 0)
1.7 dsl 96: maxptn = getmaxpartitions();
1.12 dsl 97:
98: if (ptn < 0 || bsdlabel[ptn].pi_fstype != FS_UNUSED) {
1.7 dsl 99: ptn = getrawpartition() + 1;
100: #ifdef PART_FIRST_FREE
101: if (ptn < PART_FIRST_FREE)
102: ptn = PART_FIRST_FREE;
103: #endif
104: for (;; ptn++) {
105: if (ptn >= maxptn)
106: return -1;
107: if (ptn == PART_USR)
108: continue;
109: if (bsdlabel[ptn].pi_fstype == FS_UNUSED)
110: break;
111: }
112: }
113:
114: if (fstype == FS_UNUSED)
115: return ptn;
116:
1.32 dsl 117: p = bsdlabel + ptn;
118: p->pi_offset = start;
119: p->pi_size = size;
1.35 dsl 120: set_ptype(p, fstype, mountpt ? PIF_NEWFS : 0);
1.12 dsl 121:
122: if (mountpt != NULL) {
1.32 dsl 123: for (pp = 0; pp < maxptn; pp++) {
124: if (strcmp(bsdlabel[pp].pi_mount, mountpt) == 0)
125: bsdlabel[pp].pi_flags &= ~PIF_MOUNT;
126: }
127: strlcpy(p->pi_mount, mountpt, sizeof p->pi_mount);
128: p->pi_flags |= PIF_MOUNT;
1.57 jakllsch 129: /* Default to UFS2. */
1.46 ad 130: if (p->pi_fstype == FS_BSDFFS) {
1.50 tsutsui 131: #ifdef DEFAULT_UFS2
132: #ifndef HAVE_UFS2_BOOT
133: if (strcmp(mountpt, "/") != 0)
134: #endif
135: p->pi_flags |= PIF_FFSv2;
1.46 ad 136: #endif
137: }
1.7 dsl 138: }
139:
140: return ptn;
141: }
142:
1.44 garbled 143: void
1.24 dsl 144: set_ptn_titles(menudesc *m, int opt, void *arg)
1.12 dsl 145: {
1.24 dsl 146: struct ptn_info *pi = arg;
1.12 dsl 147: struct ptn_size *p;
148: int sm = MEG / sectorsize;
1.52 sborrill 149: daddr_t size;
1.24 dsl 150: char inc_free[12];
151:
152: p = &pi->ptn_sizes[opt];
153: if (p->mount[0] == 0) {
1.56 joerg 154: wprintw(m->mw, "%s", msg_string(MSG_add_another_ptn));
1.24 dsl 155: return;
156: }
157: size = p->size;
158: if (p == pi->pool_part)
1.55 mbalmer 159: snprintf(inc_free, sizeof inc_free, "(%" PRIi64 ")",
1.24 dsl 160: (size + pi->free_space) / sm);
161: else
162: inc_free[0] = 0;
1.52 sborrill 163: wprintw(m->mw, "%6" PRIi64 "%8s%10" PRIi64 "%10" PRIi64 " %c %s",
1.24 dsl 164: size / sm, inc_free, size / dlcylsize, size,
165: p == pi->pool_part ? '+' : ' ', p->mount);
166: }
1.12 dsl 167:
1.44 garbled 168: void
1.24 dsl 169: set_ptn_menu(struct ptn_info *pi)
170: {
171: struct ptn_size *p;
172: menu_ent *m;
173:
174: for (m = pi->ptn_menus, p = pi->ptn_sizes;; m++, p++) {
175: m->opt_name = NULL;
1.12 dsl 176: m->opt_menu = OPT_NOMENU;
177: m->opt_flags = 0;
178: m->opt_action = set_ptn_size;
179: if (p->mount[0] == 0)
180: break;
181: }
1.24 dsl 182: if (pi->free_parts != 0)
183: m++;
184: m->opt_name = MSG_askunits;
185: m->opt_menu = MENU_sizechoice;
186: m->opt_flags = OPT_SUB;
187: m->opt_action = NULL;
188: m++;
1.12 dsl 189:
190: if (pi->free_space >= 0)
191: snprintf(pi->exit_msg, sizeof pi->exit_msg,
192: msg_string(MSG_fssizesok),
1.52 sborrill 193: (int)(pi->free_space / sizemult), multname, pi->free_parts);
1.12 dsl 194: else
195: snprintf(pi->exit_msg, sizeof pi->exit_msg,
196: msg_string(MSG_fssizesbad),
1.52 sborrill 197: (int)(-pi->free_space / sizemult), multname, (uint) -pi->free_space);
1.12 dsl 198:
1.24 dsl 199: set_menu_numopts(pi->menu_no, m - pi->ptn_menus);
1.12 dsl 200: }
201:
1.44 garbled 202: int
1.22 dsl 203: set_ptn_size(menudesc *m, void *arg)
1.12 dsl 204: {
205: struct ptn_info *pi = arg;
206: struct ptn_size *p;
1.15 dsl 207: char answer[10];
1.16 dsl 208: char dflt[10];
1.12 dsl 209: char *cp;
1.52 sborrill 210: daddr_t size, old_size;
1.12 dsl 211: int mult;
212:
1.22 dsl 213: p = pi->ptn_sizes + m->cursel;
1.12 dsl 214:
1.14 dsl 215: if (pi->free_parts == 0 && p->size == 0)
216: /* Don't allow 'free_parts' to go negative */
217: return 0;
218:
1.12 dsl 219: if (p->mount[0] == 0) {
1.16 dsl 220: msg_prompt_win(MSG_askfsmount, -1, 18, 0, 0,
1.12 dsl 221: NULL, p->mount, sizeof p->mount);
222: if (p->mount[0] == 0)
223: return 0;
224: }
225:
1.16 dsl 226: size = p->size;
1.24 dsl 227: old_size = size;
1.16 dsl 228: if (size == 0)
229: size = p->dflt_size;
230: size /= sizemult;
1.52 sborrill 231: snprintf(dflt, sizeof dflt, "%" PRIi64 "%s",
1.23 dsl 232: size, p == pi->pool_part ? "+" : "");
1.16 dsl 233:
1.12 dsl 234: for (;;) {
1.16 dsl 235: mult = sizemult;
236: msg_prompt_win(MSG_askfssize, -1, 18, 0, 0,
237: dflt, answer, sizeof answer,
238: p->mount, multname);
1.17 dsl 239: /* Some special cases when /usr is first given a size */
1.24 dsl 240: if (old_size == 0 && !strcmp(p->mount, "/usr")) {
1.17 dsl 241: /* Remove space for /usr from / */
242: if (!pi->ptn_sizes[0].changed) {
243: pi->ptn_sizes[0].size -= p->dflt_size;
244: pi->free_space += p->dflt_size;
1.33 dsl 245: pi->ptn_sizes[0].changed = 1;
1.17 dsl 246: }
247: /* hack to add free space to default sized /usr */
248: if (!strcmp(answer, dflt)) {
249: size = p->dflt_size;
250: pi->pool_part = p;
251: goto adjust_free;
252: }
1.16 dsl 253: }
1.12 dsl 254: size = strtoul(answer, &cp, 0);
255: switch (*cp++) {
256: default:
257: continue;
258: case 's':
259: mult = 1;
260: break;
261: case 'c':
262: mult = dlcylsize;
263: break;
264: case 'm':
1.14 dsl 265: case 'M':
1.12 dsl 266: mult = MEG / sectorsize;
267: break;
1.14 dsl 268: case 'g':
269: case 'G':
270: mult = 1024 * MEG / sectorsize;
271: break;
1.12 dsl 272: case '+':
273: cp--;
274: if (cp != answer)
275: break;
276: mult = 1;
1.24 dsl 277: size = old_size;
1.12 dsl 278: break;
279: case 0:
280: cp--;
281: break;
282: }
283: if (*cp == 0 || *cp == '+')
284: break;
285: }
286:
287: size = NUMSEC(size, mult, dlcylsize);
1.53 ahoka 288: if (p->ptn_id == PART_TMP_RAMDISK) {
1.25 dsl 289: p->size = size;
290: return 0;
291: }
1.12 dsl 292: if (p == pi->pool_part)
293: pi->pool_part = NULL;
1.23 dsl 294: if (*cp == '+' && p->limit == 0) {
1.12 dsl 295: pi->pool_part = p;
1.23 dsl 296: if (size == 0)
297: size = dlcylsize;
298: }
1.18 dsl 299: if (p->limit != 0 && size > p->limit)
300: size = p->limit;
1.16 dsl 301: adjust_free:
1.24 dsl 302: if (size != old_size)
1.17 dsl 303: p->changed = 1;
1.24 dsl 304: pi->free_space += old_size - size;
305: p->size = size;
1.12 dsl 306: if (size == 0) {
1.24 dsl 307: if (old_size != 0)
1.12 dsl 308: pi->free_parts++;
1.14 dsl 309: if (p->ptn_id == PART_EXTRA)
1.12 dsl 310: memmove(p, p + 1,
1.24 dsl 311: (char *)&pi->ptn_sizes[MAXPARTITIONS]
1.12 dsl 312: - (char *)p);
313: } else {
1.17 dsl 314: int f = pi->free_space;
1.24 dsl 315: if (old_size == 0)
1.12 dsl 316: pi->free_parts--;
1.17 dsl 317: if (f < mult && -f < mult) {
318: /*
319: * Round size to end of available space,
320: * but keep cylinder alignment
321: */
322: if (f < 0)
1.41 christos 323: f = -roundup(-f, dlcylsize);
1.17 dsl 324: else
1.41 christos 325: f = rounddown(f, dlcylsize);
1.17 dsl 326: size += f;
1.24 dsl 327: if (size != 0) {
328: pi->free_space -= f;
329: p->size += f;
330: }
1.12 dsl 331: }
332: }
333:
1.24 dsl 334: set_ptn_menu(pi);
1.12 dsl 335:
336: return 0;
337: }
338:
1.44 garbled 339: void
1.52 sborrill 340: get_ptn_sizes(daddr_t part_start, daddr_t sectors, int no_swap)
1.12 dsl 341: {
342: int i;
343: int maxpart = getmaxpartitions();
344: int sm; /* sectors in 1MB */
345: struct ptn_size *p;
1.52 sborrill 346: daddr_t size;
1.12 dsl 347:
1.24 dsl 348: static struct ptn_info pi = { -1, {
1.17 dsl 349: #define PI_ROOT 0
1.28 christos 350: { PART_ROOT, { '/', '\0' },
1.42 he 351: DEFROOTSIZE, DEFROOTSIZE , 0, 0},
1.17 dsl 352: #define PI_SWAP 1
1.28 christos 353: { PART_SWAP, { 's', 'w', 'a', 'p', '\0' },
1.42 he 354: DEFSWAPSIZE, DEFSWAPSIZE, 0, 0 },
1.53 ahoka 355: { PART_TMP_RAMDISK,
356: #ifdef HAVE_TMPFS
1.54 martin 357: { '/', 't', 'm', 'p', ' ', '(', 't', 'm', 'p', 'f', 's', ')', '\0' },
1.53 ahoka 358: #else
1.54 martin 359: { '/', 't', 'm', 'p', ' ', '(', 'm', 'f', 's', ')', '\0' },
1.53 ahoka 360: #endif
361: 64, 0, 0, 0 },
1.17 dsl 362: #define PI_USR 3
1.42 he 363: { PART_USR, { '/', 'u', 's', 'r', '\0' }, DEFUSRSIZE,
364: 0, 0, 0 },
365: { PART_ANY, { '/', 'v', 'a', 'r', '\0' }, DEFVARSIZE,
366: 0, 0, 0 },
367: { PART_ANY, { '/', 'h', 'o', 'm', 'e', '\0' }, 0,
368: 0, 0, 0 },
1.24 dsl 369: }, {
370: { NULL, OPT_NOMENU, 0, set_ptn_size },
371: { MSG_askunits, MENU_sizechoice, OPT_SUB, NULL },
1.42 he 372: }, 0, 0, NULL, { 0 } };
1.12 dsl 373:
374: if (maxpart > MAXPARTITIONS)
375: maxpart = MAXPARTITIONS; /* sanity */
376:
1.17 dsl 377: msg_display(MSG_ptnsizes);
378: msg_table_add(MSG_ptnheaders);
379:
1.15 dsl 380: if (pi.menu_no < 0) {
1.47 ad 381: /* If there is a swap partition elsewhere, don't add one here.*/
382: if (no_swap) {
1.24 dsl 383: pi.ptn_sizes[PI_SWAP].size = 0;
1.47 ad 384: } else {
385: #if DEFSWAPSIZE == -1
386: /* Dynamic swap size. */
1.48 ad 387: pi.ptn_sizes[PI_SWAP].dflt_size = get_ramsize();
388: pi.ptn_sizes[PI_SWAP].size =
389: pi.ptn_sizes[PI_SWAP].dflt_size;
1.47 ad 390: #endif
391: }
1.55 mbalmer 392:
1.17 dsl 393: /* If installing X increase default size of /usr */
1.39 dsl 394: if (set_X11_selected())
1.17 dsl 395: pi.ptn_sizes[PI_USR].dflt_size += XNEEDMB;
396:
1.34 dsl 397: /* Start of planning to give free space to / */
398: pi.pool_part = &pi.ptn_sizes[PI_ROOT];
399: /* Make size of root include default size of /usr */
400: pi.ptn_sizes[PI_ROOT].size += pi.ptn_sizes[PI_USR].dflt_size;
401:
1.36 dsl 402: sm = MEG / sectorsize;
403:
1.34 dsl 404: if (root_limit != 0) {
405: /* Bah - bios can not read all the disk, limit root */
1.23 dsl 406: pi.ptn_sizes[PI_ROOT].limit = root_limit - part_start;
1.34 dsl 407: /* Allocate a /usr partition if bios can't read
408: * everything except swap.
409: */
410: if (pi.ptn_sizes[PI_ROOT].limit
1.36 dsl 411: < sectors - pi.ptn_sizes[PI_SWAP].size * sm) {
1.34 dsl 412: /* Root won't be able to access all the space */
413: /* Claw back space for /usr */
414: pi.ptn_sizes[PI_USR].size =
1.18 dsl 415: pi.ptn_sizes[PI_USR].dflt_size;
1.34 dsl 416: pi.ptn_sizes[PI_ROOT].size -=
1.18 dsl 417: pi.ptn_sizes[PI_USR].dflt_size;
1.34 dsl 418: pi.ptn_sizes[PI_ROOT].changed = 1;
419: /* Give free space to /usr */
420: pi.pool_part = &pi.ptn_sizes[PI_USR];
421: }
1.18 dsl 422: }
1.12 dsl 423:
1.17 dsl 424: /* Change preset sizes from MB to sectors */
1.14 dsl 425: pi.free_space = sectors;
426: for (p = pi.ptn_sizes; p->mount[0]; p++) {
427: p->size = NUMSEC(p->size, sm, dlcylsize);
428: p->dflt_size = NUMSEC(p->dflt_size, sm, dlcylsize);
429: pi.free_space -= p->size;
430: }
1.12 dsl 431:
1.17 dsl 432: /* Steal space from swap to make things fit.. */
433: if (pi.free_space < 0) {
1.41 christos 434: i = roundup(-pi.free_space, dlcylsize);
1.17 dsl 435: if (i > pi.ptn_sizes[PI_SWAP].size)
436: i = pi.ptn_sizes[PI_SWAP].size;
437: pi.ptn_sizes[PI_SWAP].size -= i;
438: pi.free_space += i;
439: }
440:
441: /* Add space for 2 system dumps to / (traditional) */
1.30 dsl 442: i = get_ramsize() * sm;
1.41 christos 443: i = roundup(i, dlcylsize);
1.17 dsl 444: if (pi.free_space > i * 2)
445: i *= 2;
446: if (pi.free_space > i) {
447: pi.ptn_sizes[PI_ROOT].size += i;
448: pi.free_space -= i;
449: }
450:
1.18 dsl 451: /* Ensure all of / is readable by the system boot code */
452: i = pi.ptn_sizes[PI_ROOT].limit;
453: if (i != 0 && (i -= pi.ptn_sizes[PI_ROOT].size) < 0) {
454: pi.ptn_sizes[PI_ROOT].size += i;
455: pi.free_space -= i;
456: }
457:
1.14 dsl 458: /* Count free partition slots */
1.24 dsl 459: pi.free_parts = 0;
1.14 dsl 460: for (i = 0; i < maxpart; i++) {
461: if (bsdlabel[i].pi_size == 0)
462: pi.free_parts++;
463: }
1.24 dsl 464: for (i = 0; i < MAXPARTITIONS; i++) {
1.14 dsl 465: p = &pi.ptn_sizes[i];
466: if (i != 0 && p->ptn_id == 0)
467: p->ptn_id = PART_EXTRA;
1.24 dsl 468: if (p->size != 0)
469: pi.free_parts--;
1.14 dsl 470: }
1.12 dsl 471:
1.24 dsl 472: pi.menu_no = new_menu(0, pi.ptn_menus, nelem(pi.ptn_menus),
473: 3, -1, 12, 70,
474: MC_NOSHORTCUT |
475: MC_ALWAYS_SCROLL | MC_NOBOX | MC_NOCLEAR,
476: NULL, set_ptn_titles, NULL,
1.14 dsl 477: "help", pi.exit_msg);
1.15 dsl 478:
479: if (pi.menu_no < 0)
480: return;
1.12 dsl 481: }
482:
483: do {
1.24 dsl 484: set_ptn_menu(&pi);
1.29 christos 485: current_cylsize = dlcylsize;
1.12 dsl 486: process_menu(pi.menu_no, &pi);
487: } while (pi.free_space < 0 || pi.free_parts < 0);
488:
1.17 dsl 489: /* Give any cylinder fragment to last partition */
490: if (pi.pool_part != NULL || pi.free_space < dlcylsize) {
491: for (p = pi.ptn_sizes + nelem(pi.ptn_sizes) - 1; ;p--) {
492: if (p->size == 0) {
493: if (p == pi.ptn_sizes)
494: break;
495: continue;
496: }
1.53 ahoka 497: if (p->ptn_id == PART_TMP_RAMDISK)
1.17 dsl 498: continue;
499: p->size += pi.free_space % dlcylsize;
500: break;
501: }
502: }
503:
1.12 dsl 504: for (p = pi.ptn_sizes; p->mount[0]; p++, part_start += size) {
505: size = p->size;
1.34 dsl 506: if (p == pi.pool_part) {
1.41 christos 507: size += rounddown(pi.free_space, dlcylsize);
1.34 dsl 508: if (p->limit != 0 && size > p->limit)
509: size = p->limit;
510: }
1.14 dsl 511: i = p->ptn_id;
1.53 ahoka 512: if (i == PART_TMP_RAMDISK) {
513: tmp_ramdisk_size = size;
1.14 dsl 514: size = 0;
515: continue;
516: }
1.12 dsl 517: if (size == 0)
518: continue;
1.14 dsl 519: if (i == PART_SWAP) {
520: save_ptn(i, part_start, size, FS_SWAP, NULL);
1.12 dsl 521: continue;
522: }
1.14 dsl 523: save_ptn(i, part_start, size, FS_BSDFFS, p->mount);
1.12 dsl 524: }
525: }
526:
1.1 abs 527: /*
528: * md back-end code for menu-driven BSD disklabel editor.
529: */
530: int
531: make_bsd_partitions(void)
532: {
1.7 dsl 533: int i;
534: int part;
1.1 abs 535: int maxpart = getmaxpartitions();
1.52 sborrill 536: daddr_t partstart;
1.7 dsl 537: int part_raw, part_bsd;
1.52 sborrill 538: daddr_t ptend;
1.45 martin 539: int no_swap = 0, valid_part = -1;
1.19 dsl 540: partinfo *p;
1.1 abs 541:
542: /*
543: * Initialize global variables that track space used on this disk.
1.4 mrg 544: * Standard 4.4BSD 8-partition labels always cover whole disk.
1.1 abs 545: */
1.58 garbled 546: if (logfp) fprintf(logfp, "dlsize=%" PRId64 " ptsize=%" PRId64 " ptstart=%" PRId64 "\n", dlsize,ptsize,ptstart);
1.7 dsl 547: if (ptsize == 0)
548: ptsize = dlsize - ptstart;
1.10 dsl 549: if (dlsize == 0)
550: dlsize = ptstart + ptsize;
1.8 dsl 551:
552: partstart = ptstart;
1.7 dsl 553: ptend = ptstart + ptsize;
1.1 abs 554:
1.14 dsl 555: /* Ask for layout type -- standard or special */
556: msg_display(MSG_layout,
1.52 sborrill 557: (int) (ptsize / (MEG / sectorsize)),
1.17 dsl 558: DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE,
559: DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE + XNEEDMB);
1.14 dsl 560:
561: process_menu(MENU_layout, NULL);
562:
1.31 dsl 563: /* Set so we use the 'real' geometry for rounding, input in MB */
564: current_cylsize = dlcylsize;
565: set_sizemultname_meg();
1.14 dsl 566:
1.1 abs 567: /* Build standard partitions */
1.27 dsl 568: memset(&bsdlabel, 0, sizeof bsdlabel);
1.1 abs 569:
570: /* Set initial partition types to unused */
571: for (part = 0 ; part < maxpart ; ++part)
572: bsdlabel[part].pi_fstype = FS_UNUSED;
573:
574: /* Whole disk partition */
1.7 dsl 575: part_raw = getrawpartition();
576: if (part_raw == -1)
1.26 dsl 577: part_raw = PART_C; /* for sanity... */
1.7 dsl 578: bsdlabel[part_raw].pi_offset = 0;
579: bsdlabel[part_raw].pi_size = dlsize;
580:
1.26 dsl 581: if (part_raw == PART_D) {
1.12 dsl 582: /* Probably a system that expects an i386 style mbr */
1.26 dsl 583: part_bsd = PART_C;
584: bsdlabel[PART_C].pi_offset = ptstart;
585: bsdlabel[PART_C].pi_size = ptsize;
1.8 dsl 586: } else {
1.7 dsl 587: part_bsd = part_raw;
1.9 dsl 588: }
589:
590: #if defined(PART_BOOT) && defined(BOOT_SIZE)
1.12 dsl 591: i = BOOT_SIZE;
592: if (i >= 1024) {
1.9 dsl 593: /* Treat big numbers as a byte count */
1.12 dsl 594: i = (i + dlcylsize * sectorsize - 1) / (dlcylsize * sectorsize);
595: i *= dlcylsize;
1.9 dsl 596: }
1.60 ! tsutsui 597: #if defined(PART_BOOT_FFS)
! 598: bsdlabel[PART_BOOT].pi_fstype = FS_BSDFFS;
! 599: bsdlabel[PART_BOOT].pi_flags = PIF_NEWFS;
! 600: #else
1.9 dsl 601: bsdlabel[PART_BOOT].pi_fstype = FS_BOOT;
1.60 ! tsutsui 602: #endif
1.12 dsl 603: bsdlabel[PART_BOOT].pi_size = i;
1.8 dsl 604: #ifdef BOOT_HIGH
1.12 dsl 605: bsdlabel[PART_BOOT].pi_offset = ptend - i;
606: ptend -= i;
1.8 dsl 607: #else
1.9 dsl 608: bsdlabel[PART_BOOT].pi_offset = ptstart;
1.12 dsl 609: partstart += i;
1.8 dsl 610: #endif
1.40 garbled 611: #elif defined(PART_BOOT)
612: if (bootsize != 0) {
1.58 garbled 613: #if defined(PART_BOOT_MSDOS)
614: bsdlabel[PART_BOOT].pi_fstype = FS_MSDOS;
615: #else
1.40 garbled 616: bsdlabel[PART_BOOT].pi_fstype = FS_BOOT;
1.58 garbled 617: #endif
1.40 garbled 618: bsdlabel[PART_BOOT].pi_size = bootsize;
619: bsdlabel[PART_BOOT].pi_offset = bootstart;
1.43 mrg 620: #if defined(PART_BOOT_PI_FLAGS)
621: bsdlabel[PART_BOOT].pi_flags |= PART_BOOT_PI_FLAGS;
622: #endif
623: #if defined(PART_BOOT_PI_MOUNT)
624: strlcpy(bsdlabel[PART_BOOT].pi_mount, PART_BOOT_PI_MOUNT,
625: sizeof bsdlabel[PART_BOOT].pi_mount);
626: #endif
1.40 garbled 627: }
628: #endif /* PART_BOOT w/o BOOT_SIZE */
1.9 dsl 629:
1.38 tsutsui 630: #if defined(PART_SYSVBFS) && defined(SYSVBFS_SIZE)
1.37 tsutsui 631: bsdlabel[PART_SYSVBFS].pi_offset = partstart;
632: bsdlabel[PART_SYSVBFS].pi_fstype = FS_SYSVBFS;
1.38 tsutsui 633: bsdlabel[PART_SYSVBFS].pi_size = SYSVBFS_SIZE;
1.37 tsutsui 634: bsdlabel[PART_SYSVBFS].pi_flags |= PIF_NEWFS | PIF_MOUNT;
1.38 tsutsui 635: strlcpy(bsdlabel[PART_SYSVBFS].pi_mount, "/stand",
636: sizeof bsdlabel[PART_SYSVBFS].pi_mount);
1.37 tsutsui 637: partstart += SYSVBFS_SIZE;
638: #endif
639:
1.8 dsl 640: #ifdef PART_REST
1.9 dsl 641: bsdlabel[PART_REST].pi_offset = 0;
642: bsdlabel[PART_REST].pi_size = ptstart;
1.8 dsl 643: #endif
1.1 abs 644:
1.45 martin 645: if (layoutkind == 4) {
646: /*
647: * If 'oldlabel' is a default label created by the kernel it
648: * will have exactly one valid partition besides raw_part
649: * which covers the whole disk - but might lie outside the
650: * mbr partition we (by now) have offset by a few sectors.
651: * Check for this and and fix ut up.
652: */
653: valid_part = -1;
654: for (i = 0; i < maxpart; i++) {
655: if (i == part_raw)
656: continue;
657: if (oldlabel[i].pi_size > 0 && PI_ISBSDFS(&oldlabel[i])) {
658: if (valid_part >= 0) {
659: /* nope, not the default case */
660: valid_part = -1;
661: break;
662: }
663: valid_part = i;
664: }
665: }
666: if (valid_part >= 0 && oldlabel[valid_part].pi_offset < ptstart) {
667: oldlabel[valid_part].pi_offset = ptstart;
668: oldlabel[valid_part].pi_size -= ptstart;
669: }
670: }
671:
1.19 dsl 672: /*
673: * Save any partitions that are outside the area we are
674: * going to use.
675: * In particular this saves details of the other MBR
1.24 dsl 676: * partitions on a multiboot i386 system.
1.19 dsl 677: */
678: for (i = maxpart; i--;) {
679: if (bsdlabel[i].pi_size != 0)
680: /* Don't overwrite special partitions */
681: continue;
682: p = &oldlabel[i];
683: if (p->pi_fstype == FS_UNUSED || p->pi_size == 0)
684: continue;
1.12 dsl 685: if (layoutkind == 4) {
1.45 martin 686: if (PI_ISBSDFS(p)) {
1.19 dsl 687: p->pi_flags |= PIF_MOUNT;
1.45 martin 688: if (layoutkind == 4 && i == valid_part) {
689: int fstype = p->pi_fstype;
690: p->pi_fstype = 0;
691: strcpy(p->pi_mount, "/");
692: set_ptype(p, fstype, PIF_NEWFS);
693: }
694: }
1.19 dsl 695: } else {
1.55 mbalmer 696: if (p->pi_offset < ptstart + ptsize &&
1.24 dsl 697: p->pi_offset + p->pi_size > ptstart)
698: /* Not outside area we are allocating */
699: continue;
700: if (p->pi_fstype == FS_SWAP)
701: no_swap = 1;
1.19 dsl 702: }
703: bsdlabel[i] = oldlabel[i];
704: }
705:
1.45 martin 706: if (layoutkind != 4)
1.24 dsl 707: get_ptn_sizes(partstart, ptend - partstart, no_swap);
1.1 abs 708:
709: /*
710: * OK, we have a partition table. Give the user the chance to
711: * edit it and verify it's OK, or abort altogether.
712: */
713: edit_check:
1.7 dsl 714: if (edit_and_check_label(bsdlabel, maxpart, part_raw, part_bsd) == 0) {
1.1 abs 715: msg_display(MSG_abort);
716: return 0;
717: }
1.51 tsutsui 718: if (check_partitions() == 0)
1.1 abs 719: goto edit_check;
720:
721: /* Disk name */
1.24 dsl 722: msg_prompt(MSG_packname, bsddiskname, bsddiskname, sizeof bsddiskname);
1.1 abs 723:
724: /* save label to disk for MI code to update. */
725: (void) savenewlabel(bsdlabel, maxpart);
726:
727: /* Everything looks OK. */
728: return (1);
729: }
1.51 tsutsui 730:
731: /*
732: * check that there is at least a / somewhere.
733: */
734: static int
735: check_partitions(void)
736: {
737: #ifdef HAVE_BOOTXX_xFS
738: int rv;
739: char *bootxx;
740: #endif
741: #ifndef HAVE_UFS2_BOOT
742: int fstype;
743: #endif
744:
745: #ifdef HAVE_BOOTXX_xFS
746: /* check if we have boot code for the root partition type */
747: bootxx = bootxx_name();
748: if (bootxx != NULL) {
749: rv = access(bootxx, R_OK);
750: free(bootxx);
1.59 christos 751: } else
752: rv = -1;
753: if (rv != 0) {
1.51 tsutsui 754: process_menu(MENU_ok, deconst(MSG_No_Bootcode));
755: return 0;
756: }
757: #endif
758: #ifndef HAVE_UFS2_BOOT
759: fstype = bsdlabel[rootpart].pi_fstype;
760: if (fstype == FS_BSDFFS &&
761: (bsdlabel[rootpart].pi_flags & PIF_FFSv2) != 0) {
762: process_menu(MENU_ok, deconst(MSG_cannot_ufs2_root));
763: return 0;
764: }
765: #endif
766:
767: return md_check_partitions();
768: }
CVSweb <webmaster@jp.NetBSD.org>