aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/bsdinstall/partedit
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bsdinstall/partedit')
-rw-r--r--usr.sbin/bsdinstall/partedit/Makefile3
-rw-r--r--usr.sbin/bsdinstall/partedit/Makefile.depend9
-rw-r--r--usr.sbin/bsdinstall/partedit/diskmenu.c16
-rw-r--r--usr.sbin/bsdinstall/partedit/diskmenu.h8
-rw-r--r--usr.sbin/bsdinstall/partedit/gpart_ops.c130
-rw-r--r--usr.sbin/bsdinstall/partedit/part_wizard.c62
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit.c45
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit.h4
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit_efi.c2
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit_generic.c4
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit_powerpc.c4
-rw-r--r--usr.sbin/bsdinstall/partedit/partedit_x86.c4
-rw-r--r--usr.sbin/bsdinstall/partedit/sade.82
-rw-r--r--usr.sbin/bsdinstall/partedit/scripted.c59
14 files changed, 190 insertions, 162 deletions
diff --git a/usr.sbin/bsdinstall/partedit/Makefile b/usr.sbin/bsdinstall/partedit/Makefile
index 96c4ddb53961..7c784addaec0 100644
--- a/usr.sbin/bsdinstall/partedit/Makefile
+++ b/usr.sbin/bsdinstall/partedit/Makefile
@@ -1,11 +1,8 @@
-# $FreeBSD$
-
BINDIR= ${LIBEXECDIR}/bsdinstall
PROG= partedit
LINKS= ${BINDIR}/partedit ${BINDIR}/autopart \
${BINDIR}/partedit ${BINDIR}/scriptedpart
SYMLINKS= ../libexec/bsdinstall/partedit /usr/sbin/sade
-CFLAGS+= -I${SRCTOP}/contrib/bsddialog/lib -I${.OBJDIR}/..
LIBADD+= geom util bsddialog
PARTEDIT_ARCH= ${MACHINE}
diff --git a/usr.sbin/bsdinstall/partedit/Makefile.depend b/usr.sbin/bsdinstall/partedit/Makefile.depend
index 2c3bc47c6d42..f9843ec634f4 100644
--- a/usr.sbin/bsdinstall/partedit/Makefile.depend
+++ b/usr.sbin/bsdinstall/partedit/Makefile.depend
@@ -1,20 +1,15 @@
-# $FreeBSD$
# Autogenerated - do NOT edit!
DIRDEPS = \
- gnu/lib/csu \
- gnu/lib/libdialog \
include \
include/xlocale \
lib/${CSU_DIR} \
+ lib/libbsddialog \
lib/libc \
lib/libcompiler_rt \
- lib/libexpat \
lib/libgeom \
- lib/libsbuf \
lib/libutil \
- lib/msun \
- lib/ncurses/ncursesw \
+ usr.sbin/bsdinstall/include.amd64 \
.include <dirdeps.mk>
diff --git a/usr.sbin/bsdinstall/partedit/diskmenu.c b/usr.sbin/bsdinstall/partedit/diskmenu.c
index 9e16ef96171a..55ef5a200658 100644
--- a/usr.sbin/bsdinstall/partedit/diskmenu.c
+++ b/usr.sbin/bsdinstall/partedit/diskmenu.c
@@ -48,24 +48,24 @@ diskmenu_show(const char *title, const char *text, struct partedit_item *items,
for (i = 0; i < nitems; i++) {
bsditems[i].prefix = "";
bsditems[i].on = false;
- bsditems[i].depth = items[i].indentation;
+ bsditems[i].depth = 2 * items[i].indentation;
/* old menu sets max namelen to 10 */
bsditems[i].name = items[i].name;
humanize_number(size, 7, items[i].size, "B",
HN_AUTOSCALE, HN_DECIMAL);
mp = items[i].mountpoint != NULL ? items[i].mountpoint : "";
- asprintf(__DECONST(char**, &bsditems[i].desc), "%s %-15s %-10s",
- size, items[i].type, mp);
+ asprintf(__DECONST(char**, &bsditems[i].desc),
+ " %-9s %-15s %s", size, items[i].type, mp);
bsditems[i].bottomdesc = "";
}
bsddialog_initconf(&conf);
conf.title = title;
conf.menu.align_left = true;
- conf.text.highlight = true;
+ conf.text.escape = true;
conf.key.f1_message="[\\Z1\\ZbC\\Znreate]: a new partition.\n"
"[\\Z1\\ZbD\\Znelete]: selected partition(s).\n"
- "[\\Z1\\ZbC\\Znhange]: partition type or mountpoint.\n"
+ "[\\Z1\\ZbM\\Znodify]: partition type or mountpoint.\n"
"[\\Z1\\ZbR\\Znevert]: changes to disk setup.\n"
"[\\Z1\\ZbA\\Znuto]: guided partitioning tool.\n"
"[\\Z1\\ZbF\\Zninish]: will ask to apply changes.";
@@ -76,8 +76,8 @@ diskmenu_show(const char *title, const char *text, struct partedit_item *items,
conf.button.cancel_label = "Modify";
conf.button.with_help = true;
conf.button.help_label = "Revert";
- conf.button.generic1_label = "Auto";
- conf.button.generic2_label = "Finish";
+ conf.button.right1_label = "Auto";
+ conf.button.right2_label = "Finish";
conf.button.default_label = "Finish";
output = bsddialog_menu(&conf, text, 20, 0, 10, nitems, bsditems,
focusitem);
@@ -86,5 +86,5 @@ diskmenu_show(const char *title, const char *text, struct partedit_item *items,
free((char *)bsditems[i].desc);
free(bsditems);
- return output;
+ return (output);
}
diff --git a/usr.sbin/bsdinstall/partedit/diskmenu.h b/usr.sbin/bsdinstall/partedit/diskmenu.h
index 77077c8c1e05..9fce2e813214 100644
--- a/usr.sbin/bsdinstall/partedit/diskmenu.h
+++ b/usr.sbin/bsdinstall/partedit/diskmenu.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#ifndef _PARTEDIT_DISKMENU_H
@@ -35,8 +33,8 @@
#define BUTTON_DELETE BSDDIALOG_EXTRA
#define BUTTON_MODIFY BSDDIALOG_CANCEL
#define BUTTON_REVERT BSDDIALOG_HELP
-#define BUTTON_AUTO BSDDIALOG_GENERIC1
-#define BUTTON_FINISH BSDDIALOG_GENERIC2
+#define BUTTON_AUTO BSDDIALOG_RIGHT1
+#define BUTTON_FINISH BSDDIALOG_RIGHT2
struct partedit_item {
int indentation;
diff --git a/usr.sbin/bsdinstall/partedit/gpart_ops.c b/usr.sbin/bsdinstall/partedit/gpart_ops.c
index 26aedb58ef39..0bcd17950daf 100644
--- a/usr.sbin/bsdinstall/partedit/gpart_ops.c
+++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <sys/param.h>
@@ -64,12 +62,13 @@ gpart_show_error(const char *title, const char *explanation, const char *errstr)
while (errmsg[0] == ' ')
errmsg++;
if (errmsg[0] != '\0')
- sprintf(message, "%s%s. %s", explanation,
- strerror(error), errmsg);
+ snprintf(message, sizeof(message), "%s%s. %s",
+ explanation, strerror(error), errmsg);
else
- sprintf(message, "%s%s", explanation, strerror(error));
+ snprintf(message, sizeof(message), "%s%s", explanation,
+ strerror(error));
} else {
- sprintf(message, "%s%s", explanation, errmsg);
+ snprintf(message, sizeof(message), "%s%s", explanation, errmsg);
}
bsddialog_initconf(&conf);
@@ -88,12 +87,16 @@ scheme_supports_labels(const char *scheme)
return (0);
}
-static void
-newfs_command(const char *fstype, char *command, int use_default)
+static char *
+newfs_command(const char *fstype, int use_default)
{
struct bsddialog_conf conf;
+ FILE *fp;
+ char *buf;
+ size_t len;
bsddialog_initconf(&conf);
+ fp = open_memstream(&buf, &len);
if (strcmp(fstype, "freebsd-ufs") == 0) {
int i;
@@ -117,21 +120,21 @@ newfs_command(const char *fstype, char *command, int use_default)
choice = bsddialog_checklist(&conf, "", 0, 0, 0,
nitems(items), items, NULL);
if (choice == BSDDIALOG_CANCEL)
- return;
+ goto out;
}
- strcpy(command, "newfs ");
+ fputs("newfs ", fp);
for (i = 0; i < (int)nitems(items); i++) {
if (items[i].on == false)
continue;
if (strcmp(items[i].name, "UFS1") == 0)
- strcat(command, "-O1 ");
+ fputs("-O1 ", fp);
else if (strcmp(items[i].name, "SU") == 0)
- strcat(command, "-U ");
+ fputs("-U ", fp);
else if (strcmp(items[i].name, "SUJ") == 0)
- strcat(command, "-j ");
+ fputs("-j ", fp);
else if (strcmp(items[i].name, "TRIM") == 0)
- strcat(command, "-t ");
+ fputs("-t ", fp);
}
} else if (strcmp(fstype, "freebsd-zfs") == 0) {
int i;
@@ -155,30 +158,31 @@ newfs_command(const char *fstype, char *command, int use_default)
choice = bsddialog_checklist(&conf, "", 0, 0, 0,
nitems(items), items, NULL);
if (choice == BSDDIALOG_CANCEL)
- return;
+ goto out;
}
- strcpy(command, "zpool create -f -m none ");
+ fputs("zpool create -f -m none ", fp);
if (getenv("BSDINSTALL_TMPBOOT") != NULL) {
char zfsboot_path[MAXPATHLEN];
+
snprintf(zfsboot_path, sizeof(zfsboot_path), "%s/zfs",
getenv("BSDINSTALL_TMPBOOT"));
mkdir(zfsboot_path, S_IRWXU | S_IRGRP | S_IXGRP |
S_IROTH | S_IXOTH);
- sprintf(command, "%s -o cachefile=%s/zpool.cache ",
- command, zfsboot_path);
+ fprintf(fp, " -o cachefile=%s/zpool.cache ",
+ zfsboot_path);
}
for (i = 0; i < (int)nitems(items); i++) {
if (items[i].on == false)
continue;
if (strcmp(items[i].name, "fletcher4") == 0)
- strcat(command, "-O checksum=fletcher4 ");
+ fputs("-O checksum=fletcher4 ", fp);
else if (strcmp(items[i].name, "fletcher2") == 0)
- strcat(command, "-O checksum=fletcher2 ");
+ fputs("-O checksum=fletcher2 ", fp);
else if (strcmp(items[i].name, "sha256") == 0)
- strcat(command, "-O checksum=sha256 ");
+ fputs("-O checksum=sha256 ", fp);
else if (strcmp(items[i].name, "atime") == 0)
- strcat(command, "-O atime=off ");
+ fputs("-O atime=off ", fp);
}
} else if (strcmp(fstype, "fat32") == 0 || strcmp(fstype, "efi") == 0 ||
strcmp(fstype, "ms-basic-data") == 0) {
@@ -198,19 +202,19 @@ newfs_command(const char *fstype, char *command, int use_default)
choice = bsddialog_radiolist(&conf, "", 0, 0, 0,
nitems(items), items, NULL);
if (choice == BSDDIALOG_CANCEL)
- return;
+ goto out;
}
- strcpy(command, "newfs_msdos ");
+ fputs("newfs_msdos ", fp);
for (i = 0; i < (int)nitems(items); i++) {
if (items[i].on == false)
continue;
if (strcmp(items[i].name, "FAT32") == 0)
- strcat(command, "-F 32 -c 1");
+ fputs("-F 32 -c 1", fp);
else if (strcmp(items[i].name, "FAT16") == 0)
- strcat(command, "-F 16 ");
+ fputs("-F 16 ", fp);
else if (strcmp(items[i].name, "FAT12") == 0)
- strcat(command, "-F 12 ");
+ fputs("-F 12 ", fp);
}
} else {
if (!use_default) {
@@ -218,8 +222,11 @@ newfs_command(const char *fstype, char *command, int use_default)
bsddialog_msgbox(&conf, "No configurable options exist "
"for this filesystem.", 0, 0);
}
- command[0] = '\0';
}
+
+out:
+ fclose(fp);
+ return (buf);
}
const char *
@@ -257,7 +264,9 @@ parttypemenu:
if (!is_scheme_bootable(items[choice].name)) {
char message[512];
- sprintf(message, "This partition scheme (%s) is not "
+
+ snprintf(message, sizeof(message),
+ "This partition scheme (%s) is not "
"bootable on this platform. Are you sure you want "
"to proceed?", items[choice].name);
conf.button.default_cancel = true;
@@ -292,7 +301,9 @@ schememenu:
if (!is_scheme_bootable(scheme)) {
char message[512];
- sprintf(message, "This partition scheme (%s) is not "
+
+ snprintf(message, sizeof(message),
+ "This partition scheme (%s) is not "
"bootable on this platform. Are you sure you want "
"to proceed?", scheme);
conf.button.default_cancel = true;
@@ -478,10 +489,11 @@ gpart_partcode(struct gprovider *pp, const char *fstype)
}
/* Shell out to gpart for partcode for now */
- sprintf(command, "gpart bootcode -p %s -i %s %s",
+ snprintf(command, sizeof(command), "gpart bootcode -p %s -i %s %s",
partcode_path(scheme, fstype), indexstr, pp->lg_geom->lg_name);
if (system(command) != 0) {
- sprintf(message, "Error installing partcode on partition %s",
+ snprintf(message, sizeof(message),
+ "Error installing partcode on partition %s",
pp->lg_name);
bsddialog_initconf(&conf);
conf.title = "Error";
@@ -541,7 +553,7 @@ gpart_edit(struct gprovider *pp)
const char *errstr, *oldtype, *scheme;
struct partition_metadata *md;
char sizestr[32];
- char newfs[255];
+ char *newfs;
intmax_t idx;
int hadlabel, choice, nitems;
unsigned i;
@@ -641,9 +653,10 @@ gpart_edit(struct gprovider *pp)
items[1].init = sizestr;
editpart:
- conf.form.value_without_ok = true;
+ conf.button.always_active = true;
conf.title = "Edit Partition";
- choice = bsddialog_form(&conf, "", 0, 0, 0, nitems, items);
+ choice = bsddialog_form(&conf, "", 0, 0, 0, nitems, items, NULL);
+ conf.button.always_active = false;
if (choice == BSDDIALOG_CANCEL)
goto endedit;
@@ -652,7 +665,9 @@ editpart:
if (strcmp(items[2].value, "/") == 0 && !is_fs_bootable(scheme,
items[0].value)) {
char message[512];
- sprintf(message, "This file system (%s) is not bootable "
+
+ snprintf(message, sizeof(message),
+ "This file system (%s) is not bootable "
"on this system. Are you sure you want to proceed?",
items[0].value);
conf.button.default_cancel = true;
@@ -688,10 +703,11 @@ editpart:
}
gctl_free(r);
- newfs_command(items[0].value, newfs, 1);
+ newfs = newfs_command(items[0].value, 1);
set_default_part_metadata(pp->lg_name, scheme, items[0].value,
items[2].value, (strcmp(oldtype, items[0].value) != 0) ?
newfs : NULL);
+ free(newfs);
endedit:
if (strcmp(oldtype, items[0].value) != 0 && cp != NULL)
@@ -724,18 +740,16 @@ set_default_part_metadata(const char *name, const char *scheme,
}
if (newfs != NULL && newfs[0] != '\0') {
- md->newfs = malloc(strlen(newfs) + strlen(" /dev/") +
- strlen(mountpoint) + 5 + strlen(name) + 1);
if (strcmp("freebsd-zfs", type) == 0) {
zpool_name = strdup((strlen(mountpoint) == 1) ?
"root" : &mountpoint[1]);
for (i = 0; zpool_name[i] != 0; i++)
if (!isalnum(zpool_name[i]))
zpool_name[i] = '_';
- sprintf(md->newfs, "%s %s /dev/%s", newfs,
+ asprintf(&md->newfs, "%s %s /dev/%s", newfs,
zpool_name, name);
} else {
- sprintf(md->newfs, "%s /dev/%s", newfs, name);
+ asprintf(&md->newfs, "%s /dev/%s", newfs, name);
}
}
}
@@ -772,9 +786,7 @@ set_default_part_metadata(const char *name, const char *scheme,
if (strcmp("freebsd-zfs", type) == 0) {
md->fstab->fs_spec = strdup(zpool_name);
} else {
- md->fstab->fs_spec = malloc(strlen(name) +
- strlen("/dev/") + 1);
- sprintf(md->fstab->fs_spec, "/dev/%s", name);
+ asprintf(&md->fstab->fs_spec, "/dev/%s", name);
}
md->fstab->fs_file = strdup(mountpoint);
/* Get VFS from text after freebsd-, if possible */
@@ -1023,7 +1035,7 @@ gpart_create(struct gprovider *pp, const char *default_type,
struct ggeom *geom;
const char *errstr, *scheme;
char sizestr[32], startstr[32], output[64], *newpartname;
- char newfs[255], options_fstype[64];
+ char *newfs, options_fstype[64];
intmax_t maxsize, size, sector, firstfree, stripe;
uint64_t bytes;
int nitems, choice, junk;
@@ -1124,28 +1136,29 @@ gpart_create(struct gprovider *pp, const char *default_type,
/* Default options */
strncpy(options_fstype, items[0].init,
sizeof(options_fstype));
- newfs_command(options_fstype, newfs, 1);
+ newfs = newfs_command(options_fstype, 1);
init_allocated = false;
addpartform:
if (interactive) {
conf.button.with_extra = true;
conf.button.extra_label = "Options";
- conf.form.value_without_ok = true;
+ conf.button.always_active = true;
conf.title = "Add Partition";
- choice = bsddialog_form(&conf, "", 0, 0, 0, nitems, items);
+ choice = bsddialog_form(&conf, "", 0, 0, 0, nitems, items, NULL);
conf.button.with_extra = false;
conf.button.extra_label = NULL;
- conf.form.value_without_ok = false;
+ conf.button.always_active = false;
switch (choice) {
case BSDDIALOG_OK:
break;
case BSDDIALOG_CANCEL:
return;
case BSDDIALOG_EXTRA: /* Options */
+ free(newfs);
strncpy(options_fstype, items[0].value,
sizeof(options_fstype));
- newfs_command(options_fstype, newfs, 0);
+ newfs = newfs_command(options_fstype, 0);
for (i = 0; i < nitems(items); i++) {
if (init_allocated)
free((char*)items[i].init);
@@ -1167,8 +1180,9 @@ addpartform:
* their choices in favor of the new filesystem's defaults.
*/
if (strcmp(options_fstype, items[0].value) != 0) {
+ free(newfs);
strncpy(options_fstype, items[0].value, sizeof(options_fstype));
- newfs_command(options_fstype, newfs, 1);
+ newfs = newfs_command(options_fstype, 1);
}
size = maxsize;
@@ -1176,7 +1190,8 @@ addpartform:
if (expand_number(items[1].value, &bytes) != 0) {
char error[512];
- sprintf(error, "Invalid size: %s\n", strerror(errno));
+ snprintf(error, sizeof(error), "Invalid size: %s\n",
+ strerror(errno));
conf.title = "Error";
bsddialog_msgbox(&conf, error, 0, 0);
goto addpartform;
@@ -1228,7 +1243,9 @@ addpartform:
/* If this is the root partition, check that this scheme is bootable */
if (strcmp(items[2].value, "/") == 0 && !is_scheme_bootable(scheme)) {
char message[512];
- sprintf(message, "This partition scheme (%s) is not bootable "
+
+ snprintf(message, sizeof(message),
+ "This partition scheme (%s) is not bootable "
"on this platform. Are you sure you want to proceed?",
scheme);
conf.button.default_cancel = true;
@@ -1243,7 +1260,9 @@ addpartform:
if (strcmp(items[2].value, "/") == 0 && !is_fs_bootable(scheme,
items[0].value)) {
char message[512];
- sprintf(message, "This file system (%s) is not bootable "
+
+ snprintf(message, sizeof(message),
+ "This file system (%s) is not bootable "
"on this system. Are you sure you want to proceed?",
items[0].value);
conf.button.default_cancel = true;
@@ -1320,6 +1339,7 @@ addpartform:
else
set_default_part_metadata(newpartname, scheme,
items[0].value, items[2].value, newfs);
+ free(newfs);
for (i = 0; i < nitems(items); i++) {
if (items[i].value != NULL) {
diff --git a/usr.sbin/bsdinstall/partedit/part_wizard.c b/usr.sbin/bsdinstall/partedit/part_wizard.c
index 83fc29eb0359..90a8da1c3c9b 100644
--- a/usr.sbin/bsdinstall/partedit/part_wizard.c
+++ b/usr.sbin/bsdinstall/partedit/part_wizard.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <sys/param.h>
@@ -42,7 +40,7 @@
#include "partedit.h"
-#define MIN_FREE_SPACE (1024*1024*1024) /* 1 GB */
+#define MIN_FREE_SPACE (1023*1024*1024) /* Just under 1 GB */
#define SWAP_SIZE(available) MIN(available/20, 4*1024*1024*1024LL)
static char *wizard_partition(struct gmesh *mesh, const char *disk);
@@ -65,31 +63,37 @@ part_wizard(const char *fsreq)
startwizard:
error = geom_gettree(&mesh);
+ if (error != 0)
+ return (1);
- bsddialog_backtitle(&conf, "FreeBSD Installer");
- error = geom_gettree(&mesh);
+ bsddialog_backtitle(&conf, OSNAME " Installer");
disk = boot_disk_select(&mesh);
- if (disk == NULL)
+ if (disk == NULL) {
+ geom_deletetree(&mesh);
return (1);
+ }
- bsddialog_clearterminal();
- bsddialog_backtitle(&conf, "FreeBSD Installer");
+ bsddialog_clear(0);
+ bsddialog_backtitle(&conf, OSNAME " Installer");
schemeroot = wizard_partition(&mesh, disk);
free(disk);
+ geom_deletetree(&mesh);
if (schemeroot == NULL)
return (1);
- geom_deletetree(&mesh);
- bsddialog_clearterminal();
- bsddialog_backtitle(&conf, "FreeBSD Installer");
+ bsddialog_clear(0);
+ bsddialog_backtitle(&conf, OSNAME " Installer");
error = geom_gettree(&mesh);
+ if (error != 0) {
+ free(schemeroot);
+ return (1);
+ }
error = wizard_makeparts(&mesh, schemeroot, fstype, 1);
- if (error)
- goto startwizard;
free(schemeroot);
-
geom_deletetree(&mesh);
+ if (error)
+ goto startwizard;
return (0);
}
@@ -273,7 +277,8 @@ query:
char warning[512];
int subchoice;
- sprintf(warning, "The existing partition scheme on this "
+ snprintf(warning, sizeof(warning),
+ "The existing partition scheme on this "
"disk (%s) is not bootable on this platform. To install "
OSNAME ", it must be repartitioned. This will destroy all "
"data on the disk. Are you sure you want to proceed?",
@@ -310,11 +315,13 @@ query:
if (strcmp(scheme, "MBR") == 0) {
struct gmesh submesh;
- geom_gettree(&submesh);
- gpart_create(provider_for_name(&submesh, disk),
- "freebsd", NULL, NULL, &retval,
- choice /* Non-interactive for "Entire Disk" */);
- geom_deletetree(&submesh);
+
+ if (geom_gettree(&submesh) == 0) {
+ gpart_create(provider_for_name(&submesh, disk),
+ "freebsd", NULL, NULL, &retval,
+ choice /* Non-interactive for "Entire Disk" */);
+ geom_deletetree(&submesh);
+ }
} else {
retval = strdup(disk);
}
@@ -334,7 +341,7 @@ wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype,
struct gmesh submesh;
char swapsizestr[10], rootsizestr[10];
intmax_t swapsize, available;
- int retval;
+ int error, retval;
struct bsddialog_conf conf;
if (strcmp(fstype, "zfs") == 0) {
@@ -361,7 +368,8 @@ wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype,
HN_DECIMAL);
humanize_number(neededstr, 7, MIN_FREE_SPACE, "B", HN_AUTOSCALE,
HN_DECIMAL);
- sprintf(message, "There is not enough free space on %s to "
+ snprintf(message, sizeof(message),
+ "There is not enough free space on %s to "
"install " OSNAME " (%s free, %s required). Would you like "
"to choose another disk or to open the partition editor?",
disk, availablestr, neededstr);
@@ -381,12 +389,16 @@ wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype,
humanize_number(rootsizestr, 7, available - swapsize - 1024*1024,
"B", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
- geom_gettree(&submesh);
+ error = geom_gettree(&submesh);
+ if (error != 0)
+ return (error);
pp = provider_for_name(&submesh, disk);
gpart_create(pp, fsname, rootsizestr, "/", NULL, 0);
geom_deletetree(&submesh);
- geom_gettree(&submesh);
+ error = geom_gettree(&submesh);
+ if (error != 0)
+ return (error);
pp = provider_for_name(&submesh, disk);
gpart_create(pp, "freebsd-swap", swapsizestr, NULL, NULL, 0);
geom_deletetree(&submesh);
diff --git a/usr.sbin/bsdinstall/partedit/partedit.c b/usr.sbin/bsdinstall/partedit/partedit.c
index 22d1dbfca194..148cb74edc75 100644
--- a/usr.sbin/bsdinstall/partedit/partedit.c
+++ b/usr.sbin/bsdinstall/partedit/partedit.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <sys/param.h>
@@ -63,9 +61,10 @@ sigint_handler(int sig)
struct gmesh mesh;
/* Revert all changes and exit dialog-mode cleanly on SIGINT */
- geom_gettree(&mesh);
- gpart_revert_all(&mesh);
- geom_deletetree(&mesh);
+ if (geom_gettree(&mesh) == 0) {
+ gpart_revert_all(&mesh);
+ geom_deletetree(&mesh);
+ }
bsddialog_end();
@@ -124,9 +123,9 @@ main(int argc, const char **argv)
/* Show the part editor either immediately, or to confirm wizard */
while (prompt != NULL) {
- bsddialog_clearterminal();
+ bsddialog_clear(0);
if (!sade_mode)
- bsddialog_backtitle(&conf, "FreeBSD Installer");
+ bsddialog_backtitle(&conf, OSNAME " Installer");
error = geom_gettree(&mesh);
if (error == 0)
@@ -138,7 +137,7 @@ main(int argc, const char **argv)
"installation menu.", 0, 0);
break;
}
-
+
get_mount_points(items, nitems);
if (i >= nitems)
@@ -216,16 +215,17 @@ main(int argc, const char **argv)
if (prompt == NULL) {
error = geom_gettree(&mesh);
- if (validate_setup()) {
- error = apply_changes(&mesh);
- } else {
- gpart_revert_all(&mesh);
- error = -1;
+ if (error == 0) {
+ if (validate_setup()) {
+ error = apply_changes(&mesh);
+ } else {
+ gpart_revert_all(&mesh);
+ error = -1;
+ }
+ geom_deletetree(&mesh);
}
}
- geom_deletetree(&mesh);
- free(items);
bsddialog_end();
return (error);
@@ -345,6 +345,7 @@ apply_changes(struct gmesh *mesh)
const char **minilabel;
const char *fstab_path;
FILE *fstab;
+ char *command;
struct bsddialog_conf conf;
nitems = 1; /* Partition table changes */
@@ -360,8 +361,8 @@ apply_changes(struct gmesh *mesh)
TAILQ_FOREACH(md, &part_metadata, metadata) {
if (md->newfs != NULL) {
char *item;
- item = malloc(255);
- sprintf(item, "Initializing %s", md->name);
+
+ asprintf(&item, "Initializing %s", md->name);
minilabel[i] = item;
miniperc[i] = BSDDIALOG_MG_PENDING;
i++;
@@ -387,10 +388,11 @@ apply_changes(struct gmesh *mesh)
bsddialog_mixedgauge(&conf,
"Initializing file systems. Please wait.", 0, 0,
i * 100 / nitems, nitems, minilabel, miniperc);
- sprintf(message, "(echo %s; %s) >>%s 2>>%s",
+ asprintf(&command, "(echo %s; %s) >>%s 2>>%s",
md->newfs, md->newfs, getenv("BSDINSTALL_LOG"),
getenv("BSDINSTALL_LOG"));
- error = system(message);
+ error = system(command);
+ free(command);
miniperc[i] = (error == 0) ?
BSDDIALOG_MG_COMPLETED : BSDDIALOG_MG_FAILED;
i++;
@@ -434,7 +436,8 @@ apply_changes(struct gmesh *mesh)
fstab_path = "/etc/fstab";
fstab = fopen(fstab_path, "w+");
if (fstab == NULL) {
- sprintf(message, "Cannot open fstab file %s for writing (%s)\n",
+ snprintf(message, sizeof(message),
+ "Cannot open fstab file %s for writing (%s)\n",
getenv("PATH_FSTAB"), strerror(errno));
conf.title = "Error";
bsddialog_msgbox(&conf, message, 0, 0);
diff --git a/usr.sbin/bsdinstall/partedit/partedit.h b/usr.sbin/bsdinstall/partedit/partedit.h
index aa1ec285ff80..57f590113f43 100644
--- a/usr.sbin/bsdinstall/partedit/partedit.h
+++ b/usr.sbin/bsdinstall/partedit/partedit.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#ifndef _PARTEDIT_PARTEDIT_H
diff --git a/usr.sbin/bsdinstall/partedit/partedit_efi.c b/usr.sbin/bsdinstall/partedit/partedit_efi.c
index 074475e07152..7c4f85a69b8b 100644
--- a/usr.sbin/bsdinstall/partedit/partedit_efi.c
+++ b/usr.sbin/bsdinstall/partedit/partedit_efi.c
@@ -25,8 +25,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <sys/types.h>
diff --git a/usr.sbin/bsdinstall/partedit/partedit_generic.c b/usr.sbin/bsdinstall/partedit/partedit_generic.c
index e25784592a9b..dd6a44b96e91 100644
--- a/usr.sbin/bsdinstall/partedit/partedit_generic.c
+++ b/usr.sbin/bsdinstall/partedit/partedit_generic.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <string.h>
diff --git a/usr.sbin/bsdinstall/partedit/partedit_powerpc.c b/usr.sbin/bsdinstall/partedit/partedit_powerpc.c
index 5a3041df5b0c..27fc9c2bde6e 100644
--- a/usr.sbin/bsdinstall/partedit/partedit_powerpc.c
+++ b/usr.sbin/bsdinstall/partedit/partedit_powerpc.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <sys/types.h>
diff --git a/usr.sbin/bsdinstall/partedit/partedit_x86.c b/usr.sbin/bsdinstall/partedit/partedit_x86.c
index 6983188ba34f..6a536271c25e 100644
--- a/usr.sbin/bsdinstall/partedit/partedit_x86.c
+++ b/usr.sbin/bsdinstall/partedit/partedit_x86.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <sys/types.h>
diff --git a/usr.sbin/bsdinstall/partedit/sade.8 b/usr.sbin/bsdinstall/partedit/sade.8
index f80f8c5fb7d0..2e676c19ba4b 100644
--- a/usr.sbin/bsdinstall/partedit/sade.8
+++ b/usr.sbin/bsdinstall/partedit/sade.8
@@ -22,8 +22,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD$
-.\"
.Dd December 30, 2012
.Dt SADE 8
.Os
diff --git a/usr.sbin/bsdinstall/partedit/scripted.c b/usr.sbin/bsdinstall/partedit/scripted.c
index 956855eb6e54..9527f3828135 100644
--- a/usr.sbin/bsdinstall/partedit/scripted.c
+++ b/usr.sbin/bsdinstall/partedit/scripted.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2013 Nathan Whitehorn
* All rights reserved.
@@ -24,8 +24,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
#include <sys/param.h>
@@ -76,6 +74,8 @@ part_config(char *disk, const char *scheme, char *config)
scheme = default_scheme();
error = geom_gettree(&mesh);
+ if (error != 0)
+ return (-1);
if (provider_for_name(&mesh, disk) == NULL) {
fprintf(stderr, "GEOM provider %s not found\n", disk);
geom_deletetree(&mesh);
@@ -97,16 +97,22 @@ part_config(char *disk, const char *scheme, char *config)
if (strcmp(scheme, "MBR") == 0) {
struct gmesh submesh;
- geom_gettree(&submesh);
- gpart_create(provider_for_name(&submesh, disk),
- "freebsd", NULL, NULL, &disk, 0);
- geom_deletetree(&submesh);
+
+ if (geom_gettree(&submesh) == 0) {
+ gpart_create(provider_for_name(&submesh, disk),
+ "freebsd", NULL, NULL, &disk, 0);
+ geom_deletetree(&submesh);
+ }
} else {
- disk= strdup(disk);
+ disk = strdup(disk);
}
geom_deletetree(&mesh);
error = geom_gettree(&mesh);
+ if (error != 0) {
+ free(disk);
+ return (-1);
+ }
/* Create partitions */
if (config == NULL) {
@@ -133,6 +139,10 @@ part_config(char *disk, const char *scheme, char *config)
NULL, 0);
geom_deletetree(&mesh);
error = geom_gettree(&mesh);
+ if (error != 0) {
+ free(disk);
+ return (-1);
+ }
size = type = mount = NULL;
}
@@ -143,8 +153,8 @@ finished:
return (0);
}
-static
-int parse_disk_config(char *input)
+static int
+parse_disk_config(char *input)
{
char *ap;
char *disk = NULL, *scheme = NULL, *partconfig = NULL;
@@ -184,9 +194,11 @@ int parse_disk_config(char *input)
if (disk == NULL || strcmp(disk, "DEFAULT") == 0) {
struct gmesh mesh;
- geom_gettree(&mesh);
- disk = boot_disk_select(&mesh);
- geom_deletetree(&mesh);
+
+ if (geom_gettree(&mesh) == 0) {
+ disk = boot_disk_select(&mesh);
+ geom_deletetree(&mesh);
+ }
}
return (part_config(disk, scheme, partconfig));
@@ -195,23 +207,26 @@ int parse_disk_config(char *input)
int
scripted_editor(int argc, const char **argv)
{
- char *token;
- int i, error = 0, len = 0;
+ FILE *fp;
+ char *input, *token;
+ size_t len;
+ int i, error = 0;
- for (i = 1; i < argc; i++)
- len += strlen(argv[i]) + 1;
- char inputbuf[len], *input = inputbuf;
- strcpy(input, argv[1]);
+ fp = open_memstream(&input, &len);
+ fputs(argv[1], fp);
for (i = 2; i < argc; i++) {
- strcat(input, " ");
- strcat(input, argv[i]);
+ fprintf(fp, " %s", argv[i]);
}
+ fclose(fp);
while ((token = strsep(&input, ";")) != NULL) {
error = parse_disk_config(token);
- if (error != 0)
+ if (error != 0) {
+ free(input);
return (error);
+ }
}
+ free(input);
return (0);
}