Module Name:    src
Committed By:   martin
Date:           Wed Nov 13 18:57:26 UTC 2019

Modified Files:
        src/usr.sbin/sysinst: Makefile.inc bsddisklabel.c defs.h disks.c
            install.c label.c part_edit.c util.c

Log Message:
Make cloning support optional, so we can save some space on very small
install media.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.sbin/sysinst/Makefile.inc
cvs rdiff -u -r1.30 -r1.31 src/usr.sbin/sysinst/bsddisklabel.c
cvs rdiff -u -r1.46 -r1.47 src/usr.sbin/sysinst/defs.h
cvs rdiff -u -r1.55 -r1.56 src/usr.sbin/sysinst/disks.c
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/sysinst/install.c
cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/sysinst/label.c
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/sysinst/part_edit.c
cvs rdiff -u -r1.36 -r1.37 src/usr.sbin/sysinst/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/sysinst/Makefile.inc
diff -u src/usr.sbin/sysinst/Makefile.inc:1.28 src/usr.sbin/sysinst/Makefile.inc:1.29
--- src/usr.sbin/sysinst/Makefile.inc:1.28	Thu Oct 31 09:44:13 2019
+++ src/usr.sbin/sysinst/Makefile.inc	Wed Nov 13 18:57:26 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.28 2019/10/31 09:44:13 martin Exp $
+#	$NetBSD: Makefile.inc,v 1.29 2019/11/13 18:57:26 martin Exp $
 #
 # Makefile for sysinst
 
@@ -43,6 +43,9 @@ CPPFLAGS.gpt.c+=	-I${GPT_DIR}
 CPPFLAGS+=	-DHAVE_MBR
 SRCS+=	mbr.c
 .endif
+.if ${NO_CLONES:Uno} == "yes"
+CPPFLAGS+=	-DNO_CLONES
+.endif
 
 MSG_MD?=	msg.md.${SYSINSTLANG}
 MENUS_MD?=	menus.md.${SYSINSTLANG}

Index: src/usr.sbin/sysinst/bsddisklabel.c
diff -u src/usr.sbin/sysinst/bsddisklabel.c:1.30 src/usr.sbin/sysinst/bsddisklabel.c:1.31
--- src/usr.sbin/sysinst/bsddisklabel.c:1.30	Tue Nov 12 16:33:14 2019
+++ src/usr.sbin/sysinst/bsddisklabel.c	Wed Nov 13 18:57:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bsddisklabel.c,v 1.30 2019/11/12 16:33:14 martin Exp $	*/
+/*	$NetBSD: bsddisklabel.c,v 1.31 2019/11/13 18:57:26 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -251,11 +251,13 @@ draw_size_menu_line(menudesc *m, int opt
 		mount = swap;
 	} else if (pset->infos[opt].mount[0]) {
 		mount = pset->infos[opt].mount;
+#ifndef NO_CLONES
 	} else if (pset->infos[opt].flags & PUIFLG_CLONE_PARTS) {
 		snprintf(swap, sizeof swap, "%zu %s",
 		    pset->infos[opt].clone_src->num_sel,
 		    msg_string(MSG_clone_target_disp));
 		mount = swap;
+#endif
 	} else {
 		mount = NULL;
 		if (pset->infos[opt].parts->pscheme->other_partition_identifier
@@ -353,6 +355,7 @@ add_other_ptn_size(menudesc *menu, void 
 	return -1;
 }
 
+#ifndef NO_CLONES
 static int
 inst_ext_clone(menudesc *menu, void *arg)
 {
@@ -430,6 +433,7 @@ err:
 	free_selected_partitions(&selected);
 	return 0;
 }
+#endif
 
 static size_t
 fill_ptn_menu(struct partition_usage_set *pset)
@@ -440,7 +444,14 @@ fill_ptn_menu(struct partition_usage_set
 	size_t i;
 	daddr_t free_space;
 
-	memset(pset->menu_opts, 0, (pset->num+4)*sizeof(*pset->menu_opts));
+#ifdef NO_CLONES
+#define	ADD_ITEMS	3
+#else
+#define	ADD_ITEMS	4
+#endif
+
+	memset(pset->menu_opts, 0, (pset->num+ADD_ITEMS)
+	    *sizeof(*pset->menu_opts));
 	for (m = pset->menu_opts, p = pset->infos, i = 0; i < pset->num;
 	    m++, p++, i++) {
 		if (p->flags & PUIFLG_CLONE_PARTS)
@@ -457,9 +468,11 @@ fill_ptn_menu(struct partition_usage_set
 	m->opt_action = add_other_ptn_size;
 	m++;
 
+#ifndef NO_CLONES
 	m->opt_name = MSG_clone_from_elsewhere;
 	m->opt_action = inst_ext_clone;
 	m++;
+#endif
 
 	m->opt_name = MSG_askunits;
 	m->opt_menu = MENU_sizechoice;
@@ -1136,6 +1149,7 @@ sort_and_sync_parts(struct partition_usa
 	pset->infos = infos;
 }
 
+#ifndef NO_CLONES
 /*
  * Convert clone entries with more than one source into
  * several entries with a single source each.
@@ -1188,6 +1202,7 @@ normalize_clones(struct part_usage_info 
 	free(*infos);
 	*infos = ui;
 }
+#endif
 
 static void
 apply_settings_to_partitions(struct pm_devs *p, struct disk_partitions *parts,
@@ -1195,13 +1210,18 @@ apply_settings_to_partitions(struct pm_d
 {
 	size_t i, exp_ndx = ~0U;
 	daddr_t planned_space = 0, nsp, from, align;
-	struct disk_part_info *infos, cinfo, srcinfo;
+	struct disk_part_info *infos;
+#ifndef NO_CLONES
+	struct disk_part_info cinfo, srcinfo;
+	struct selected_partition *sp;
+#endif
 	struct disk_part_free_space space;
 	struct disk_partitions *ps = NULL;
-	struct selected_partition *sp;
 	part_id pno, new_part_id;
 
+#ifndef NO_CLONES
 	normalize_clones(&wanted->infos, &wanted->num);
+#endif
 
 	infos = calloc(wanted->num, sizeof(*infos));
 	if (infos == NULL) {
@@ -1329,6 +1349,7 @@ apply_settings_to_partitions(struct pm_d
 			continue;
 		if (want->flags & (PUIFLG_JUST_MOUNTPOINT|PUIFLG_IS_OUTER))
 			continue;
+#ifndef NO_CLONES
 		if ((want->flags & PUIFLG_CLONE_PARTS) &&
 		    want->clone_src != NULL &&
 		    want->clone_ndx < want->clone_src->num_sel) {
@@ -1358,6 +1379,9 @@ apply_settings_to_partitions(struct pm_d
 			new_part_id = wanted->parts->pscheme->add_partition(
 			    wanted->parts, &infos[i], NULL);
 		} else {
+#else
+		{
+#endif
 			if (want->size <= 0)
 				continue;
 			size_t cnt = wanted->parts->pscheme->get_free_spaces(

Index: src/usr.sbin/sysinst/defs.h
diff -u src/usr.sbin/sysinst/defs.h:1.46 src/usr.sbin/sysinst/defs.h:1.47
--- src/usr.sbin/sysinst/defs.h:1.46	Tue Nov 12 16:33:14 2019
+++ src/usr.sbin/sysinst/defs.h	Wed Nov 13 18:57:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: defs.h,v 1.46 2019/11/12 16:33:14 martin Exp $	*/
+/*	$NetBSD: defs.h,v 1.47 2019/11/13 18:57:26 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -283,6 +283,7 @@ struct part_usage_info {
 	unsigned int instflags;		/* installer handling flags */
 	uint fs_type, fs_version;	/* e.g. FS_LFS, or FS_BSDFS,
 					 * version = 2 for FFSv2 */
+#ifndef	NO_CLONES
 	/*
 	 * Only != NULL when PUIFLG_CLONE_PARTS is set, describes the
 	 * source partitions to clone here.
@@ -294,6 +295,7 @@ struct part_usage_info {
 	 * (>= 0 && <= clone_src->num_sel, or all of them if clone_ndx = ~0U.
 	 */
 	size_t clone_ndx;
+#endif
 };
 
 /*
@@ -619,6 +621,8 @@ bool is_cdrom_device(const char *dev, bo
 bool is_bootable_device(const char *dev);
 bool is_partitionable_device(const char *dev);
 bool convert_scheme(struct pm_devs *p, bool is_boot_drive, const char **err_msg);
+
+#ifndef	NO_CLONES
 /* a single partition selected for cloning (etc) */
 struct selected_partition {
 	struct disk_partitions *parts;
@@ -643,6 +647,7 @@ struct clone_target_menu_data {
 int	clone_target_select(menudesc *m, void *arg);
 bool	clone_partition_data(struct disk_partitions *dest_parts, part_id did,
 	struct disk_partitions *src_parts, part_id sid);
+#endif
 
 struct menudesc;
 void	disp_cur_fspart(int, int);

Index: src/usr.sbin/sysinst/disks.c
diff -u src/usr.sbin/sysinst/disks.c:1.55 src/usr.sbin/sysinst/disks.c:1.56
--- src/usr.sbin/sysinst/disks.c:1.55	Tue Nov 12 16:33:14 2019
+++ src/usr.sbin/sysinst/disks.c	Wed Nov 13 18:57:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: disks.c,v 1.55 2019/11/12 16:33:14 martin Exp $ */
+/*	$NetBSD: disks.c,v 1.56 2019/11/13 18:57:26 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -2046,6 +2046,7 @@ get_dkwedges(struct dkwedge_info **dkw, 
 	return dkwl.dkwl_nwedges;
 }
 
+#ifndef NO_CLONES
 /*
  * Helper structures used in the partition select menu
  */
@@ -2514,3 +2515,5 @@ clone_partition_data(struct disk_partiti
 	    "progress -f %s -b 1m dd bs=1m of=%s",
 	    src_dev, target_dev) == 0;
 }
+#endif
+

Index: src/usr.sbin/sysinst/install.c
diff -u src/usr.sbin/sysinst/install.c:1.12 src/usr.sbin/sysinst/install.c:1.13
--- src/usr.sbin/sysinst/install.c:1.12	Tue Nov 12 16:33:14 2019
+++ src/usr.sbin/sysinst/install.c	Wed Nov 13 18:57:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: install.c,v 1.12 2019/11/12 16:33:14 martin Exp $	*/
+/*	$NetBSD: install.c,v 1.13 2019/11/13 18:57:26 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -50,7 +50,9 @@ static bool
 write_all_parts(struct install_partition_desc *install)
 {
 	struct disk_partitions **allparts, *parts;
+#ifndef NO_CLONES
 	struct selected_partition *src;
+#endif
 	size_t num_parts, i, j;
 	bool found, res;
 
@@ -100,6 +102,7 @@ write_all_parts(struct install_partition
 	/* phase 3: now we may have a first chance to enable swap space */
 	set_swap_if_low_ram(install);
 
+#ifndef NO_CLONES
 	/* phase 4: copy any cloned partitions data (if requested) */
 	for (i = 0; i < install->num; i++) {
 		if ((install->infos[i].flags & PUIFLG_CLONE_PARTS) == 0
@@ -112,6 +115,7 @@ write_all_parts(struct install_partition
 		    install->infos[i].cur_part_id,
 		    src->parts, src->id);
 	}
+#endif
 
 	/* phase 5: post disklabel (used for updating boot loaders) */
 	for (i = 0; i < num_parts; i++) {

Index: src/usr.sbin/sysinst/label.c
diff -u src/usr.sbin/sysinst/label.c:1.13 src/usr.sbin/sysinst/label.c:1.14
--- src/usr.sbin/sysinst/label.c:1.13	Tue Nov 12 16:33:14 2019
+++ src/usr.sbin/sysinst/label.c	Wed Nov 13 18:57:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: label.c,v 1.13 2019/11/12 16:33:14 martin Exp $	*/
+/*	$NetBSD: label.c,v 1.14 2019/11/13 18:57:26 martin Exp $	*/
 
 /*
  * Copyright 1997 Jonathan Stone
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: label.c,v 1.13 2019/11/12 16:33:14 martin Exp $");
+__RCSID("$NetBSD: label.c,v 1.14 2019/11/13 18:57:26 martin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -1187,12 +1187,15 @@ fmt_fspart_row(menudesc *m, int ptn, voi
 	static const char *Yes;
 	char flag_str[MENUSTRSIZE], *fp;
 	unsigned inst_flags;
+#ifndef NO_CLONES
 	size_t clone_cnt;
+#endif
 	bool with_inst_flag = pset->parts->parent == NULL;
 
 	if (Yes == NULL)
 		Yes = msg_string(MSG_Yes);
 
+#ifndef NO_CLONES
 	if ((pset->infos[ptn].flags & PUIFLG_CLONE_PARTS) &&
 	   pset->infos[ptn].cur_part_id == NO_PART) {
 		psize = pset->infos[ptn].size / sizemult;
@@ -1220,6 +1223,7 @@ fmt_fspart_row(menudesc *m, int ptn, voi
 			m->opts[ptn].opt_flags &= ~OPT_IGNORE;
 		return;
 	}
+#endif
 
 	if (!real_partition(pset, ptn))
 		return;
@@ -1296,6 +1300,7 @@ fmt_fspart_row(menudesc *m, int ptn, voi
 		     info.last_mounted[0] ? info.last_mounted : "");
 }
 
+#ifndef NO_CLONES
 static int
 part_ext_clone(menudesc *m, void *arg)
 {
@@ -1442,6 +1447,7 @@ err:
 	free_selected_partitions(&selected);
 	return 0;
 }
+#endif
 
 static int
 edit_fspart_pack(menudesc *m, void *arg)
@@ -1594,8 +1600,13 @@ edit_and_check_label(struct pm_devs *p, 
 	    pset->parts->pscheme->get_disk_pack_name != NULL &&
 	    pset->parts->pscheme->set_disk_pack_name != NULL;
 
+#ifdef NO_CLONES
+#define	C_M_ITEMS	0
+#else
+#define	C_M_ITEMS	1
+#endif
 	pset->menu_opts = calloc(pset->parts->num_part
-	     +4+may_add+may_edit_pack,
+	     +3+C_M_ITEMS+may_add+may_edit_pack,
 	     sizeof *pset->menu_opts);
 	if (pset->menu_opts == NULL)
 		return 0;
@@ -1632,10 +1643,12 @@ edit_and_check_label(struct pm_devs *p, 
 		op++;
 	}
 
+#ifndef NO_CLONES
 	/* add a clone-from-elsewhere option */
 	op->opt_name = MSG_clone_from_elsewhere;
 	op->opt_action = part_ext_clone;
 	op++;
+#endif
 	        
 	/* and abort option */
 	op->opt_name = MSG_cancel;
@@ -1643,7 +1656,7 @@ edit_and_check_label(struct pm_devs *p, 
 	op->opt_action = edit_fspart_abort;
 	op++;
 	cnt = op - pset->menu_opts;
-	assert(cnt == pset->parts->num_part+4+may_add+may_edit_pack);
+	assert(cnt == pset->parts->num_part+3+C_M_ITEMS+may_add+may_edit_pack);
 
 	pset->menu = new_menu(fspart_title, pset->menu_opts, cnt,
 			0, -1, 0, 74,

Index: src/usr.sbin/sysinst/part_edit.c
diff -u src/usr.sbin/sysinst/part_edit.c:1.11 src/usr.sbin/sysinst/part_edit.c:1.12
--- src/usr.sbin/sysinst/part_edit.c:1.11	Tue Nov 12 16:33:14 2019
+++ src/usr.sbin/sysinst/part_edit.c	Wed Nov 13 18:57:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: part_edit.c,v 1.11 2019/11/12 16:33:14 martin Exp $ */
+/*	$NetBSD: part_edit.c,v 1.12 2019/11/13 18:57:26 martin Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -57,14 +57,18 @@ struct part_edit_info {
 	bool num_changed;		/* number of partitions has changed */
 };
 
+#ifndef NO_CLONES
 struct single_clone_data {
 	struct selected_partitions clone_src;
 	part_id *clone_ids;	/* partition IDs in target */
 };
+#endif
 struct outer_parts_data {
 	struct arg_rv av;
+#ifndef NO_CLONES
 	struct single_clone_data *clones;
 	size_t num_clone_entries;
+#endif
 };
 
 static menu_ent *part_menu_opts;		/* the currently edited partitions */
@@ -445,6 +449,7 @@ edit_part_entry(menudesc *m, void *arg)
 	return 0;
 }
 
+#ifndef NO_CLONES
 static int
 add_part_clone(menudesc *menu, void *arg)
 {
@@ -553,7 +558,7 @@ err:
 	free_selected_partitions(&selected);
 	return -1;
 }
-
+#endif
 
 static int
 add_part_entry(menudesc *m, void *arg)
@@ -814,7 +819,10 @@ outer_fill_part_menu_opts(const struct d
 	bool may_add;
 
 	may_add = parts->pscheme->can_add_partition(parts);
-	num_opts = 4 + parts->num_part;
+	num_opts = 3 + parts->num_part;
+#ifndef NO_CLONES
+	num_opts++;
+#endif
 	if (parts->num_part == 0)
 		num_opts++;
 	if (may_add)
@@ -852,10 +860,12 @@ outer_fill_part_menu_opts(const struct d
 		op++;
 	}
 
+#ifndef NO_CLONES
 	/* and a partition cloner */
 	op->opt_name = MSG_clone_from_elsewhere;
 	op->opt_action = add_part_clone;
 	op++;
+#endif
 
 	/* and unit changer */
 	op->opt_name = MSG_askunits;
@@ -1158,7 +1168,10 @@ ask_outer_partsizes(struct disk_partitio
 {
 	int j;
 	int part_menu;
-	size_t num_opts, i, ci;
+	size_t num_opts;
+#ifndef NO_CLONES
+	size_t i, ci;
+#endif
 	struct outer_parts_data data;
 
 	part_menu_opts = outer_fill_part_menu_opts(parts, &num_opts);
@@ -1197,6 +1210,7 @@ ask_outer_partsizes(struct disk_partitio
 		break;
 	}
 
+#ifndef NO_CLONES
 	/* handle cloned partitions content copies now */
 	for (i = 0; i < data.num_clone_entries; i++) {
 		for (ci = 0; ci < data.clones[i].clone_src.num_sel; ci++) {
@@ -1215,6 +1229,7 @@ ask_outer_partsizes(struct disk_partitio
 			free_selected_partitions(&data.clones[i].clone_src);
 		free(data.clones);
 	}
+#endif
 
 	free_menu(part_menu);
 	free(part_menu_opts);

Index: src/usr.sbin/sysinst/util.c
diff -u src/usr.sbin/sysinst/util.c:1.36 src/usr.sbin/sysinst/util.c:1.37
--- src/usr.sbin/sysinst/util.c:1.36	Tue Nov 12 18:04:37 2019
+++ src/usr.sbin/sysinst/util.c	Wed Nov 13 18:57:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.36 2019/11/12 18:04:37 martin Exp $	*/
+/*	$NetBSD: util.c,v 1.37 2019/11/13 18:57:26 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -2100,6 +2100,7 @@ free_usage_set(struct partition_usage_se
 void
 free_install_desc(struct install_partition_desc *install)
 {
+#ifndef NO_CLONES
 	size_t i, j;
 
 	for (i = 0; i < install->num; i++) {
@@ -2112,6 +2113,7 @@ free_install_desc(struct install_partiti
 			if (install->infos[j].clone_src == src)
 				install->infos[j].clone_src = NULL; 
 	}
+#endif
 	free(install->infos);
 }
 

Reply via email to