Wed Jul 14 18:56:05 2021 UTC ()
When converting partitions from one scheme to another, never fail
without providing (if requested) a proper error message.


(martin)
diff -r1.72 -r1.73 src/usr.sbin/sysinst/disks.c

cvs diff -r1.72 -r1.73 src/usr.sbin/sysinst/disks.c (expand / switch to unified diff)

--- src/usr.sbin/sysinst/disks.c 2021/01/31 22:45:46 1.72
+++ src/usr.sbin/sysinst/disks.c 2021/07/14 18:56:05 1.73
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: disks.c,v 1.72 2021/01/31 22:45:46 rillig Exp $ */ 1/* $NetBSD: disks.c,v 1.73 2021/07/14 18:56:05 martin Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 Piermont Information Systems Inc. 4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Philip A. Nelson for Piermont Information Systems Inc. 7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -744,37 +744,43 @@ convert_copy(struct disk_partitions *old @@ -744,37 +744,43 @@ convert_copy(struct disk_partitions *old
744 744
745bool 745bool
746convert_scheme(struct pm_devs *p, bool is_boot_drive, const char **err_msg) 746convert_scheme(struct pm_devs *p, bool is_boot_drive, const char **err_msg)
747{ 747{
748 struct disk_partitions *old_parts, *new_parts; 748 struct disk_partitions *old_parts, *new_parts;
749 const struct disk_partitioning_scheme *new_scheme; 749 const struct disk_partitioning_scheme *new_scheme;
750 750
751 *err_msg = NULL; 751 *err_msg = NULL;
752 752
753 old_parts = p->parts; 753 old_parts = p->parts;
754 new_scheme = select_part_scheme(p, old_parts->pscheme, 754 new_scheme = select_part_scheme(p, old_parts->pscheme,
755 false, MSG_select_other_partscheme); 755 false, MSG_select_other_partscheme);
756 756
757 if (new_scheme == NULL) 757 if (new_scheme == NULL) {
 758 if (err_msg)
 759 *err_msg = INTERNAL_ERROR;
758 return false; 760 return false;
 761 }
759 762
760 new_parts = new_scheme->create_new_for_disk(p->diskdev, 763 new_parts = new_scheme->create_new_for_disk(p->diskdev,
761 0, p->dlsize, is_boot_drive, NULL); 764 0, p->dlsize, is_boot_drive, NULL);
762 if (new_parts == NULL) 765 if (new_parts == NULL) {
 766 if (err_msg)
 767 *err_msg = MSG_out_of_memory;
763 return false; 768 return false;
 769 }
764 770
765 convert_copy(old_parts, new_parts); 771 convert_copy(old_parts, new_parts);
766 772
767 if (new_parts->num_part == 0) { 773 if (new_parts->num_part == 0 && old_parts->num_part != 0) {
768 /* need to cleanup */ 774 /* need to cleanup */
769 new_parts->pscheme->free(new_parts); 775 new_parts->pscheme->free(new_parts);
770 return false; 776 return false;
771 } 777 }
772 778
773 old_parts->pscheme->free(old_parts); 779 old_parts->pscheme->free(old_parts);
774 p->parts = new_parts; 780 p->parts = new_parts;
775 return true; 781 return true;
776} 782}
777 783
778static struct pm_devs * 784static struct pm_devs *
779dummy_whole_system_pm(void) 785dummy_whole_system_pm(void)
780{ 786{