Deleted Added
full compact
label.c (8681) label.c (8702)
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
7 * $Id: label.c,v 1.19 1995/05/21 17:53:27 jkh Exp $
7 * $Id: label.c,v 1.20 1995/05/21 18:24:33 jkh Exp $
8 *
9 * Copyright (c) 1995
10 * Jordan Hubbard. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright

--- 45 unchanged lines hidden (view full) ---

61 * this will catch 99.99% of all possible cases, I'm not too worried.
62 */
63#define MAX_CHUNKS 50
64
65/* Where to start printing the freebsd slices */
66#define CHUNK_SLICE_START_ROW 2
67#define CHUNK_PART_START_ROW 11
68
8 *
9 * Copyright (c) 1995
10 * Jordan Hubbard. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright

--- 45 unchanged lines hidden (view full) ---

61 * this will catch 99.99% of all possible cases, I'm not too worried.
62 */
63#define MAX_CHUNKS 50
64
65/* Where to start printing the freebsd slices */
66#define CHUNK_SLICE_START_ROW 2
67#define CHUNK_PART_START_ROW 11
68
69/* One MB worth of blocks */
70#define ONE_MEG 2048
71
69/* The smallest filesystem we're willing to create */
72/* The smallest filesystem we're willing to create */
70#define FS_MIN_SIZE 2048
73#define FS_MIN_SIZE ONE_MEG
71
72/* The smallest root filesystem we're willing to create */
74
75/* The smallest root filesystem we're willing to create */
73#define ROOT_MIN_SIZE 40960 /* 20MB */
76#define ROOT_MIN_SIZE (20 * ONE_MEG)
74
75/* All the chunks currently displayed on the screen */
76static struct {
77 struct disk *d;
78 struct chunk *c;
79 PartType type;
80} label_chunk_info[MAX_CHUNKS + 1];
81static int here;

--- 82 unchanged lines hidden (view full) ---

164 ++j;
165 }
166 }
167 }
168 else if (c1->type == fat) {
169 label_chunk_info[j].type = PART_FAT;
170 label_chunk_info[j].d = d;
171 label_chunk_info[j].c = c1;
77
78/* All the chunks currently displayed on the screen */
79static struct {
80 struct disk *d;
81 struct chunk *c;
82 PartType type;
83} label_chunk_info[MAX_CHUNKS + 1];
84static int here;

--- 82 unchanged lines hidden (view full) ---

167 ++j;
168 }
169 }
170 }
171 else if (c1->type == fat) {
172 label_chunk_info[j].type = PART_FAT;
173 label_chunk_info[j].d = d;
174 label_chunk_info[j].c = c1;
175 ++j;
172 }
173 }
174 }
175 label_chunk_info[j].d = NULL;
176 label_chunk_info[j].c = NULL;
177 if (here >= j)
178 here = j ? j - 1 : 0;
179}

--- 25 unchanged lines hidden (view full) ---

205
206/* Get the mountpoint for a partition and save it away */
207PartInfo *
208get_mountpoint(struct chunk *old)
209{
210 char *val;
211 PartInfo *tmp;
212
176 }
177 }
178 }
179 label_chunk_info[j].d = NULL;
180 label_chunk_info[j].c = NULL;
181 if (here >= j)
182 here = j ? j - 1 : 0;
183}

--- 25 unchanged lines hidden (view full) ---

209
210/* Get the mountpoint for a partition and save it away */
211PartInfo *
212get_mountpoint(struct chunk *old)
213{
214 char *val;
215 PartInfo *tmp;
216
213 dialog_clear(); clear();
214 val = msgGetInput(old && old->private ? ((PartInfo *)old->private)->mountpoint : NULL,
215 "Please specify a mount point for the partition");
216 if (!val)
217 return NULL;
218
219 /* Is it just the same value? */
220 if (old && old->private && !strcmp(((PartInfo *)old->private)->mountpoint, val))
221 return NULL;

--- 28 unchanged lines hidden (view full) ---

250 int i;
251
252 static unsigned char *fs_types[] = {
253 "FS",
254 "A file system",
255 "Swap",
256 "A swap partition.",
257 };
217 val = msgGetInput(old && old->private ? ((PartInfo *)old->private)->mountpoint : NULL,
218 "Please specify a mount point for the partition");
219 if (!val)
220 return NULL;
221
222 /* Is it just the same value? */
223 if (old && old->private && !strcmp(((PartInfo *)old->private)->mountpoint, val))
224 return NULL;

--- 28 unchanged lines hidden (view full) ---

253 int i;
254
255 static unsigned char *fs_types[] = {
256 "FS",
257 "A file system",
258 "Swap",
259 "A swap partition.",
260 };
258 dialog_clear(); clear();
259 i = dialog_menu("Please choose a partition type",
260 "If you want to use this partition for swap space, select Swap.\nIf you want to put a filesystem on it, choose FS.", -1, -1, 2, 2, fs_types, selection, NULL, NULL);
261 if (!i) {
262 if (!strcmp(selection, "FS"))
263 return PART_FILESYSTEM;
264 else if (!strcmp(selection, "Swap"))
265 return PART_SWAP;
266 }

--- 57 unchanged lines hidden (view full) ---

324 if (i == here)
325 attrset(A_REVERSE);
326 /* Is it a slice entry displayed at the top? */
327 if (label_chunk_info[i].type == PART_SLICE) {
328 sz = space_free(label_chunk_info[i].c);
329 mvprintw(srow++, 0,
330 "Disk: %s\tPartition name: %s\tFree: %d blocks (%dMB)",
331 label_chunk_info[i].d->name,
261 i = dialog_menu("Please choose a partition type",
262 "If you want to use this partition for swap space, select Swap.\nIf you want to put a filesystem on it, choose FS.", -1, -1, 2, 2, fs_types, selection, NULL, NULL);
263 if (!i) {
264 if (!strcmp(selection, "FS"))
265 return PART_FILESYSTEM;
266 else if (!strcmp(selection, "Swap"))
267 return PART_SWAP;
268 }

--- 57 unchanged lines hidden (view full) ---

326 if (i == here)
327 attrset(A_REVERSE);
328 /* Is it a slice entry displayed at the top? */
329 if (label_chunk_info[i].type == PART_SLICE) {
330 sz = space_free(label_chunk_info[i].c);
331 mvprintw(srow++, 0,
332 "Disk: %s\tPartition name: %s\tFree: %d blocks (%dMB)",
333 label_chunk_info[i].d->name,
332 label_chunk_info[i].c->name, sz, (sz / 2048));
334 label_chunk_info[i].c->name, sz, (sz / ONE_MEG));
333 }
334 /* Otherwise it's a DOS, swap or filesystem entry, at the bottom */
335 else {
336 char onestr[PART_OFF], num[10], *mountpoint, *newfs;
337
338 /*
339 * We copy this into a blank-padded string so that it looks like
340 * a solid bar in reverse-video

--- 35 unchanged lines hidden (view full) ---

376 }
377 else {
378 mountpoint = "<unknown>";
379 newfs = "*";
380 }
381 for (j = 0; j < MAX_MOUNT_NAME && mountpoint[j]; j++)
382 onestr[PART_MOUNT_COL + j] = mountpoint[j];
383 snprintf(num, 10, "%4ldMB", label_chunk_info[i].c->size ?
335 }
336 /* Otherwise it's a DOS, swap or filesystem entry, at the bottom */
337 else {
338 char onestr[PART_OFF], num[10], *mountpoint, *newfs;
339
340 /*
341 * We copy this into a blank-padded string so that it looks like
342 * a solid bar in reverse-video

--- 35 unchanged lines hidden (view full) ---

378 }
379 else {
380 mountpoint = "<unknown>";
381 newfs = "*";
382 }
383 for (j = 0; j < MAX_MOUNT_NAME && mountpoint[j]; j++)
384 onestr[PART_MOUNT_COL + j] = mountpoint[j];
385 snprintf(num, 10, "%4ldMB", label_chunk_info[i].c->size ?
384 label_chunk_info[i].c->size / 2048 : 0);
386 label_chunk_info[i].c->size / ONE_MEG : 0);
385 memcpy(onestr + PART_SIZE_COL, num, strlen(num));
386 memcpy(onestr + PART_NEWFS_COL, newfs, strlen(newfs));
387 onestr[PART_NEWFS_COL + strlen(newfs)] = '\0';
388 mvaddstr(prow, pcol, onestr);
389 ++prow;
390 }
391 if (i == here)
392 attrset(A_NORMAL);

--- 28 unchanged lines hidden (view full) ---

421 labeling = TRUE;
422 keypad(stdscr, TRUE);
423 record_label_chunks();
424
425 if (!getenv(DISK_PARTITIONED)) {
426 msgConfirm("You need to partition your disk(s) before you can assign disk labels.");
427 return 0;
428 }
387 memcpy(onestr + PART_SIZE_COL, num, strlen(num));
388 memcpy(onestr + PART_NEWFS_COL, newfs, strlen(newfs));
389 onestr[PART_NEWFS_COL + strlen(newfs)] = '\0';
390 mvaddstr(prow, pcol, onestr);
391 ++prow;
392 }
393 if (i == here)
394 attrset(A_NORMAL);

--- 28 unchanged lines hidden (view full) ---

423 labeling = TRUE;
424 keypad(stdscr, TRUE);
425 record_label_chunks();
426
427 if (!getenv(DISK_PARTITIONED)) {
428 msgConfirm("You need to partition your disk(s) before you can assign disk labels.");
429 return 0;
430 }
429 clear();
431 dialog_clear(); clear();
430 while (labeling) {
432 while (labeling) {
433 clear();
431 print_label_chunks();
432 print_command_summary();
433 if (msg) {
434 attrset(A_REVERSE); mvprintw(23, 0, msg); attrset(A_NORMAL);
435 beep();
436 msg = NULL;
437 }
438 refresh();

--- 34 unchanged lines hidden (view full) ---

473 break;
474 }
475 sz = space_free(label_chunk_info[here].c);
476 if (sz <= FS_MIN_SIZE) {
477 msg = "Not enough space to create additional FreeBSD partition";
478 break;
479 }
480 {
434 print_label_chunks();
435 print_command_summary();
436 if (msg) {
437 attrset(A_REVERSE); mvprintw(23, 0, msg); attrset(A_NORMAL);
438 beep();
439 msg = NULL;
440 }
441 refresh();

--- 34 unchanged lines hidden (view full) ---

476 break;
477 }
478 sz = space_free(label_chunk_info[here].c);
479 if (sz <= FS_MIN_SIZE) {
480 msg = "Not enough space to create additional FreeBSD partition";
481 break;
482 }
483 {
481 char *val, *cp, tmpb[20];
482 int size;
483 struct chunk *tmp;
484 u_long flags = 0;
484 char *val, *cp, tmpb[20];
485 int size;
486 struct chunk *tmp;
487 u_long flags = 0;
485
488
486 snprintf(tmpb, 20, "%d", sz);
487 val = msgGetInput(tmpb, "Please specify the size for new FreeBSD partition in blocks, or append\na trailing `M' for megabytes (e.g. 20M).");
488 if (!val || (size = strtol(val, &cp, 0)) <= 0)
489 break;
489 snprintf(tmpb, 20, "%d", sz);
490 val = msgGetInput(tmpb, "Please specify the size for new FreeBSD partition in blocks, or append\na trailing `M' for megabytes (e.g. 20M).");
491 if (!val || (size = strtol(val, &cp, 0)) <= 0)
492 break;
490
493
491 if (*cp && toupper(*cp) == 'M')
492 size *= 2048;
494 if (sz <= FS_MIN_SIZE) {
495 msgConfirm("The minimum filesystem size is %dMB", FS_MIN_SIZE / ONE_MEG);
496 break;
497 }
498 if (*cp && toupper(*cp) == 'M')
499 size *= ONE_MEG;
493
500
494 type = get_partition_type();
495 if (type == PART_NONE)
496 break;
497
498 if (type == PART_FILESYSTEM) {
499 if ((p = get_mountpoint(NULL)) == NULL)
501 type = get_partition_type();
502 if (type == PART_NONE)
500 break;
503 break;
501 else if (!strcmp(p->mountpoint, "/"))
502 flags |= CHUNK_IS_ROOT;
503 else
504 flags &= ~CHUNK_IS_ROOT;
505 } else
506 p = NULL;
507
504
508 if ((flags & CHUNK_IS_ROOT)) {
509 if (!(label_chunk_info[here].c->flags & CHUNK_BSD_COMPAT)) {
510 msgConfirm("This region cannot be used for your root partition as\nthe FreeBSD boot code cannot deal with a root partition created in\nsuch a location. Please choose another location for your root\npartition and try again!");
511 break;
505 if (type == PART_FILESYSTEM) {
506 if ((p = get_mountpoint(NULL)) == NULL)
507 break;
508 else if (!strcmp(p->mountpoint, "/"))
509 flags |= CHUNK_IS_ROOT;
510 else
511 flags &= ~CHUNK_IS_ROOT;
512 } else
513 p = NULL;
514
515 if ((flags & CHUNK_IS_ROOT)) {
516 if (!(label_chunk_info[here].c->flags & CHUNK_BSD_COMPAT)) {
517 msgConfirm("This region cannot be used for your root partition as\nthe FreeBSD boot code cannot deal with a root partition created in\nsuch a location. Please choose another location for your root\npartition and try again!");
518 break;
519 }
520 if (size < ROOT_MIN_SIZE) {
521 msgConfirm("This is too small a size for a root partition. For a variety of\nreasons, root partitions should be at least %dMB in size", ROOT_MIN_SIZE / ONE_MEG);
522 break;
523 }
512 }
524 }
513 if (size < ROOT_MIN_SIZE) {
514 msgConfirm("This is too small a size for a root partition. For a variety of\nreasons, root partitions should be at least %dMB in size", ROOT_MIN_SIZE / 2048);
525 tmp = Create_Chunk_DWIM(label_chunk_info[here].d,
526 label_chunk_info[here].c,
527 size, part,
528 (type == PART_SWAP) ? FS_SWAP : FS_BSDFFS,
529 flags);
530 if (!tmp) {
531 msgConfirm("Unable to create the partition. Too big?");
515 break;
516 }
532 break;
533 }
517 }
518 tmp = Create_Chunk_DWIM(label_chunk_info[here].d,
519 label_chunk_info[here].c,
520 size, part,
521 (type == PART_SWAP) ? FS_SWAP : FS_BSDFFS,
522 flags);
523 if (!tmp) {
524 msgConfirm("Unable to create the partition. Too big?");
525 break;
526 }
527 if ((flags & CHUNK_IS_ROOT) && (tmp->flags & CHUNK_PAST_1024)) {
534 if ((flags & CHUNK_IS_ROOT) && (tmp->flags & CHUNK_PAST_1024)) {
528 msgConfirm("This region cannot be used for your root partition as it starts\nor extends past the 1024'th cylinder mark and is thus a\npoor location to boot from. Please choose another\nlocation for your root partition and try again!");
529 Delete_Chunk(label_chunk_info[here].d, tmp);
530 break;
535 msgConfirm("This region cannot be used for your root partition as it starts\nor extends past the 1024'th cylinder mark and is thus a\npoor location to boot from. Please choose another\nlocation for your root partition and try again!");
536 Delete_Chunk(label_chunk_info[here].d, tmp);
537 break;
531 }
532 if (type != PART_SWAP) {
538 }
539 if (type != PART_SWAP) {
533 /* This is needed to tell the newfs -u about the size */
534 tmp->private = new_part(p->mountpoint,p->newfs,tmp->size);
535 safe_free(p);
540 /* This is needed to tell the newfs -u about the size */
541 tmp->private = new_part(p->mountpoint,p->newfs,tmp->size);
542 safe_free(p);
536 } else {
543 } else {
537 tmp->private = p;
544 tmp->private = p;
538 }
539 tmp->private_free = safe_free;
540 record_label_chunks();
545 }
546 tmp->private_free = safe_free;
547 record_label_chunks();
541 }
542 break;
543
544 case 'D': /* delete */
545 if (label_chunk_info[here].type == PART_SLICE) {
546 msg = MSG_NOT_APPLICABLE;
547 break;
548 }

--- 85 unchanged lines hidden (view full) ---

634 default:
635 beep();
636 msg = "Type F1 or ? for help";
637 break;
638 }
639 }
640 variable_set2(DISK_LABELLED, "yes");
641 dialog_clear();
548 }
549 break;
550
551 case 'D': /* delete */
552 if (label_chunk_info[here].type == PART_SLICE) {
553 msg = MSG_NOT_APPLICABLE;
554 break;
555 }

--- 85 unchanged lines hidden (view full) ---

641 default:
642 beep();
643 msg = "Type F1 or ? for help";
644 break;
645 }
646 }
647 variable_set2(DISK_LABELLED, "yes");
648 dialog_clear();
642 refresh();
643 return 0;
644}
645
646
647
649 return 0;
650}
651
652
653