Module Name: src Committed By: martin Date: Fri Jul 12 18:28:08 UTC 2019
Modified Files: src/usr.sbin/sysinst: bsddisklabel.c defs.h Log Message: When adding non-disklabel boot partitions (or similar), distinguish between ones we need to add to the outer (MBR) partitions, or copy over to the inner (disklabel) partitions. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/sysinst/bsddisklabel.c cvs rdiff -u -r1.36 -r1.37 src/usr.sbin/sysinst/defs.h 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/bsddisklabel.c diff -u src/usr.sbin/sysinst/bsddisklabel.c:1.18 src/usr.sbin/sysinst/bsddisklabel.c:1.19 --- src/usr.sbin/sysinst/bsddisklabel.c:1.18 Tue Jul 9 16:25:05 2019 +++ src/usr.sbin/sysinst/bsddisklabel.c Fri Jul 12 18:28:08 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: bsddisklabel.c,v 1.18 2019/07/09 16:25:05 martin Exp $ */ +/* $NetBSD: bsddisklabel.c,v 1.19 2019/07/12 18:28:08 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -1215,8 +1215,10 @@ sort_and_sync_parts(struct partition_usa continue; if (pset->parts != pset->infos[i].parts) continue; - if (pset->infos[i].flags & - (PUIFLG_IS_OUTER|PUIFLG_JUST_MOUNTPOINT)) + if (pset->infos[i].flags & PUIFLG_JUST_MOUNTPOINT) + continue; + if ((pset->infos[i].flags & (PUIFLG_IS_OUTER|PUIFLAG_ADD_INNER)) + == PUIFLG_IS_OUTER) continue; if (pno >= pset->parts->num_part) continue; @@ -1288,7 +1290,8 @@ apply_settings_to_partitions(struct pm_d if ((wanted->infos[i].flags & PUIFLAG_EXTEND) && exp_ndx == ~0U) exp_ndx = i; - if (wanted->infos[i].flags & PUIFLG_JUST_MOUNTPOINT) + if (wanted->infos[i].flags & + (PUIFLG_JUST_MOUNTPOINT|PUIFLG_IS_OUTER)) continue; nsp = wanted->infos[i].size; if (wanted->infos[i].cur_part_id != NO_PART) { @@ -1337,14 +1340,67 @@ apply_settings_to_partitions(struct pm_d ps->pscheme->set_part_info(ps, want->cur_part_id, &infos[i], NULL); } - /* Now add new partitions */ + from = -1; + /* + * First add all outer partitions - we need to align those exactly + * with the inner counterpart later. + */ + if (parts->parent) { + ps = parts->parent; + daddr_t outer_align = ps->pscheme->get_part_alignment(ps); + + for (i = 0; i < wanted->num; i++) { + struct part_usage_info *want = &wanted->infos[i]; + + if (want->cur_part_id != NO_PART) + continue; + if (!(want->flags & PUIFLAG_ADD_OUTER)) + continue; + if (want->size <= 0) + continue; + + size_t cnt = ps->pscheme->get_free_spaces(ps, + &space, 1, want->size-2*outer_align, + outer_align, from, -1); + + if (cnt == 0) /* no free space for this partition */ + continue; + + infos[i].start = space.start; + infos[i].size = min(want->size, space.size); + infos[i].nat_type = + ps->pscheme->get_fs_part_type( + want->fs_type, want->fs_version); + infos[i].last_mounted = want->mount; + infos[i].fs_type = want->fs_type; + infos[i].fs_sub_type = want->fs_version; + if (want->fs_type != FS_UNUSED && want->type != PT_swap) + want->instflags |= PUIINST_NEWFS|PUIINST_MOUNT; + new_part_id = ps->pscheme->add_partition(ps, + &infos[i], NULL); + if (new_part_id == NO_PART) + continue; /* failed to add, skip */ + + ps->pscheme->get_part_info(ps, + new_part_id, &infos[i]); + want->cur_part_id = new_part_id; + + want->flags |= PUIFLAG_ADD_INNER|PUIFLG_IS_OUTER; + from = rounddown(infos[i].start + + infos[i].size+outer_align, outer_align); + } + } + + /* + * Now add new inner partitions + */ for (i = 0; i < wanted->num && from < wanted->parts->disk_size; i++) { struct part_usage_info *want = &wanted->infos[i]; if (want->cur_part_id != NO_PART) continue; - if (want->flags & PUIFLG_JUST_MOUNTPOINT) + if (want->flags & (PUIFLG_JUST_MOUNTPOINT|PUIFLG_IS_OUTER)) continue; if (want->size <= 0) continue; @@ -1376,15 +1432,62 @@ apply_settings_to_partitions(struct pm_d from = rounddown(infos[i].start+infos[i].size+align, align); } + + /* + * If there are any outer partitions that we need as inner ones + * too, add them to the inner partitioning scheme. + */ + for (i = 0; i < wanted->num; i++) { + struct part_usage_info *want = &wanted->infos[i]; + + if (want->cur_part_id != NO_PART) + continue; + if (want->flags & PUIFLG_JUST_MOUNTPOINT) + continue; + if (want->size <= 0) + continue; + + if ((want->flags & (PUIFLAG_ADD_INNER|PUIFLG_IS_OUTER)) != + (PUIFLAG_ADD_INNER|PUIFLG_IS_OUTER)) + continue; + + infos[i].start = want->cur_start; + infos[i].size = want->size; + infos[i].nat_type = wanted->parts->pscheme->get_fs_part_type( + want->fs_type, want->fs_version); + infos[i].last_mounted = want->mount; + infos[i].fs_type = want->fs_type; + infos[i].fs_sub_type = want->fs_version; + if (want->fs_type != FS_UNUSED && + want->type != PT_swap) + want->instflags |= PUIINST_NEWFS|PUIINST_MOUNT; + + if (wanted->parts->pscheme->add_outer_partition + != NULL) + new_part_id = wanted->parts->pscheme-> + add_outer_partition( + wanted->parts, &infos[i], NULL); + else + new_part_id = wanted->parts->pscheme-> + add_partition( + wanted->parts, &infos[i], NULL); + + if (new_part_id == NO_PART) + continue; /* failed to add, skip */ + + wanted->parts->pscheme->get_part_info( + wanted->parts, new_part_id, &infos[i]); + } + /* * Note: all part_ids are invalid now, as we have added things! */ for (i = 0; i < wanted->num; i++) wanted->infos[i].cur_part_id = NO_PART; - for (pno = 0; pno < ps->num_part; pno++) { + for (pno = 0; pno < parts->num_part; pno++) { struct disk_part_info t; - if (!ps->pscheme->get_part_info(ps, pno, &t)) + if (!parts->pscheme->get_part_info(parts, pno, &t)) continue; for (i = 0; i < wanted->num; i++) { Index: src/usr.sbin/sysinst/defs.h diff -u src/usr.sbin/sysinst/defs.h:1.36 src/usr.sbin/sysinst/defs.h:1.37 --- src/usr.sbin/sysinst/defs.h:1.36 Fri Jun 21 21:54:39 2019 +++ src/usr.sbin/sysinst/defs.h Fri Jul 12 18:28:08 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: defs.h,v 1.36 2019/06/21 21:54:39 christos Exp $ */ +/* $NetBSD: defs.h,v 1.37 2019/07/12 18:28:08 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -249,8 +249,9 @@ struct part_usage_info { * is available */ #define PUIFLAG_ADD_OUTER 2 /* Add this partition to the outer * partitions (if available) */ -#define PUIFLG_IS_OUTER 4 -#define PUIFLG_JUST_MOUNTPOINT 8 /* tmpfs of mfs mountpoints */ +#define PUIFLG_IS_OUTER 4 /* this is an existing outer one */ +#define PUIFLAG_ADD_INNER 8 /* add outer also to inner */ +#define PUIFLG_JUST_MOUNTPOINT 16 /* tmpfs of mfs mountpoints */ uint flags; struct disk_partitions *parts; /* Where does this partition live? * We currently only support