summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sysinstall/label.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1997-06-05 09:48:03 +0000
committerjkh <jkh@FreeBSD.org>1997-06-05 09:48:03 +0000
commit9160ca00b5da185787c84ae5e1b1d848847dd262 (patch)
tree3707fb988b7a0ae5cc4e493af9c486da9892a1dd /usr.sbin/sysinstall/label.c
parent4caf82f971a9e9d7368fa7667e4e43f98857e620 (diff)
downloadFreeBSD-src-9160ca00b5da185787c84ae5e1b1d848847dd262.zip
FreeBSD-src-9160ca00b5da185787c84ae5e1b1d848847dd262.tar.gz
Resurrect / implement some of the more esoteric scripting features,
such as partitioning a disk or overriding an interactive prompt.
Diffstat (limited to 'usr.sbin/sysinstall/label.c')
-rw-r--r--usr.sbin/sysinstall/label.c117
1 files changed, 115 insertions, 2 deletions
diff --git a/usr.sbin/sysinstall/label.c b/usr.sbin/sysinstall/label.c
index c57abf1..582e561 100644
--- a/usr.sbin/sysinstall/label.c
+++ b/usr.sbin/sysinstall/label.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: label.c,v 1.69 1997/03/08 16:17:49 jkh Exp $
+ * $Id: label.c,v 1.70 1997/03/11 17:51:01 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -81,6 +81,7 @@ static int ChunkPartStartRow;
static WINDOW *ChunkWin;
static int diskLabel(char *str);
+static int diskLabelNonInteractive(char *str);
int
diskLabelEditor(dialogMenuItem *self)
@@ -107,7 +108,10 @@ diskLabelEditor(dialogMenuItem *self)
"editor first to specify which disks you wish to operate on.");
return DITEM_FAILURE;
}
- i = diskLabel(devs[0]->name);
+ if (variable_get(VAR_NONINTERACTIVE))
+ i = diskLabelNonInteractive(devs[0]->name);
+ else
+ i = diskLabel(devs[0]->name);
if (DITEM_STATUS(i) != DITEM_FAILURE) {
char *cp;
@@ -936,3 +940,112 @@ diskLabel(char *str)
}
return DITEM_SUCCESS | DITEM_RESTORE;
}
+
+static int
+diskLabelNonInteractive(char *str)
+{
+ char *cp;
+ PartType type;
+ PartInfo *p;
+ u_long flags = 0;
+ int i, status;
+ Device **devs;
+ Disk *d;
+
+ status = DITEM_SUCCESS;
+ cp = variable_get(VAR_DISK);
+ if (!cp) {
+ dialog_clear();
+ msgConfirm("diskLabel: No disk selected - can't label automatically.");
+ return DITEM_FAILURE;
+ }
+
+ devs = deviceFind(cp, DEVICE_TYPE_DISK);
+ if (!devs) {
+ msgConfirm("diskLabel: No disk device %s found!", cp);
+ return DITEM_FAILURE;
+ }
+ d = devs[0]->private;
+
+ record_label_chunks(devs);
+ for (i = 0; label_chunk_info[i].c; i++) {
+ Chunk *c1 = label_chunk_info[i].c;
+
+ if (label_chunk_info[i].type == PART_SLICE) {
+ if ((cp = variable_get(c1->name)) != NULL) {
+ int sz;
+ char typ[10], mpoint[50];
+
+ if (sscanf(cp, "%s %d %s", typ, &sz, mpoint) != 3) {
+ msgConfirm("For slice entry %s, got an invalid detail entry of: %s", c1->name, cp);
+ status = DITEM_FAILURE;
+ continue;
+ }
+ else {
+ Chunk *tmp;
+
+ if (!strcmp(typ, "swap")) {
+ type = PART_SWAP;
+ strcpy(mpoint, "SWAP");
+ }
+ else {
+ type = PART_FILESYSTEM;
+ if (!strcmp(mpoint, "/"))
+ flags |= CHUNK_IS_ROOT;
+ }
+ if (!sz)
+ sz = space_free(c1);
+ if (sz > space_free(c1)) {
+ msgConfirm("Not enough free space to create partition: %s", mpoint);
+ status = DITEM_FAILURE;
+ continue;
+ }
+ if (!(tmp = Create_Chunk_DWIM(d, c1, sz, part,
+ (type == PART_SWAP) ? FS_SWAP : FS_BSDFFS, flags))) {
+ msgConfirm("Unable to create from partition spec: %s. Too big?", cp);
+ status = DITEM_FAILURE;
+ break;
+ }
+ else {
+ tmp->private_data = new_part(mpoint, TRUE, sz);
+ tmp->private_free = safe_free;
+ status = DITEM_SUCCESS;
+ }
+ }
+ }
+ }
+ else {
+ /* Must be something we can set a mountpoint */
+ cp = variable_get(c1->name);
+ if (cp) {
+ char mpoint[50], nwfs[8];
+ Boolean newfs = FALSE;
+
+ nwfs[0] = '\0';
+ if (sscanf(cp, "%s %s", mpoint, nwfs) != 2) {
+ dialog_clear();
+ msgConfirm("For slice entry %s, got an invalid detail entry of: %s", c1->name, cp);
+ status = DITEM_FAILURE;
+ continue;
+ }
+ newfs = toupper(nwfs[0]) == 'Y' ? TRUE : FALSE;
+ if (c1->private_data) {
+ p = c1->private_data;
+ p->newfs = newfs;
+ strcpy(p->mountpoint, mpoint);
+ }
+ else {
+ c1->private_data = new_part(mpoint, newfs, 0);
+ c1->private_free = safe_free;
+ }
+ if (!strcmp(mpoint, "/"))
+ c1->flags |= CHUNK_IS_ROOT;
+ else
+ c1->flags &= ~CHUNK_IS_ROOT;
+ }
+ }
+ }
+ if (status == DITEM_SUCCESS)
+ variable_set2(DISK_LABELLED, "yes");
+ return status;
+}
OpenPOWER on IntegriCloud