xref: /netbsd-src/usr.sbin/sysinst/arch/bebox/md.c (revision 4204f81037ec1430b81b70ee975f04b277901e24)
1 /*	$NetBSD: md.c,v 1.10 2022/01/29 16:01:17 martin Exp $ */
2 
3 /*
4  * Copyright 1997 Piermont Information Systems Inc.
5  * All rights reserved.
6  *
7  * Based on code written by Philip A. Nelson for Piermont Information
8  * Systems Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
19  *    or promote products derived from this software without specific prior
20  *    written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /* md.c -- bebox machine specific routines */
36 
37 #include <sys/param.h>
38 #include <sys/sysctl.h>
39 #include <stdio.h>
40 #include <util.h>
41 
42 #include "defs.h"
43 #include "md.h"
44 #include "msg_defs.h"
45 #include "menu_defs.h"
46 
47 void
md_init(void)48 md_init(void)
49 {
50 }
51 
52 void
md_init_set_status(int flags)53 md_init_set_status(int flags)
54 {
55 	(void)flags;
56 }
57 
58 bool
md_get_info(struct install_partition_desc * install)59 md_get_info(struct install_partition_desc *install)
60 {
61 	int res;
62 
63 	if (pm->no_mbr || pm->no_part)
64 		return true;
65 
66 again:
67 	if (pm->parts == NULL) {
68 
69 		const struct disk_partitioning_scheme *ps =
70 		    select_part_scheme(pm, NULL, true, NULL);
71 
72 		if (!ps)
73 			return false;
74 
75 		struct disk_partitions *parts =
76 		   (*ps->create_new_for_disk)(pm->diskdev,
77 		   0, pm->dlsize, true, NULL);
78 		if (!parts)
79 			return false;
80 
81 		pm->parts = parts;
82 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
83 			pm->dlsize = ps->size_limit;
84 	}
85 
86 	res = set_bios_geom_with_mbr_guess(pm->parts);
87 	if (res == 0)
88 		return false;
89 	else if (res == 1)
90 		return true;
91 
92 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
93 	pm->parts = NULL;
94 	goto again;
95 }
96 
97 /*
98  * md back-end code for menu-driven BSD disklabel editor.
99  */
100 int
md_make_bsd_partitions(struct install_partition_desc * install)101 md_make_bsd_partitions(struct install_partition_desc *install)
102 {
103 	return make_bsd_partitions(install);
104 }
105 
106 /*
107  * any additional partition validation
108  */
109 bool
md_check_partitions(struct install_partition_desc * install)110 md_check_partitions(struct install_partition_desc *install)
111 {
112 	return true;
113 }
114 
115 /*
116  * hook called before writing new disklabel.
117  */
118 bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)119 md_pre_disklabel(struct install_partition_desc *install,
120     struct disk_partitions *parts)
121 {
122 
123 	if (parts->parent == NULL)
124 		return true;	/* no outer partitions */
125 
126 	parts = parts->parent;
127 
128 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
129 	    msg_string(parts->pscheme->name),
130 	    msg_string(parts->pscheme->short_name));
131 
132 	/* write edited "MBR" onto disk. */
133 	if (!parts->pscheme->write_to_disk(parts)) {
134 		msg_display(MSG_wmbrfail);
135 		process_menu(MENU_ok, NULL);
136 		return false;
137 	}
138 	return true;
139 }
140 
141 /*
142  * hook called after writing disklabel to new target disk.
143  */
144 bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)145 md_post_disklabel(struct install_partition_desc *install,
146     struct disk_partitions *parts)
147 {
148 	return true;
149 }
150 
151 /*
152  * hook called after upgrade() or install() has finished setting
153  * up the target disk but immediately before the user is given the
154  * ``disks are now set up'' message.
155  */
156 int
md_post_newfs(struct install_partition_desc * install)157 md_post_newfs(struct install_partition_desc *install)
158 {
159 	return 0;
160 }
161 
162 int
md_post_extract(struct install_partition_desc * install,bool upgrade)163 md_post_extract(struct install_partition_desc *install, bool upgrade)
164 {
165 	return 0;
166 }
167 
168 void
md_cleanup_install(struct install_partition_desc * install)169 md_cleanup_install(struct install_partition_desc *install)
170 {
171 #ifndef DEBUG
172 	enable_rc_conf();
173 #endif
174 }
175 
176 int
md_pre_update(struct install_partition_desc * install)177 md_pre_update(struct install_partition_desc *install)
178 {
179 	return 1;
180 }
181 
182 /* Upgrade support */
183 int
md_update(struct install_partition_desc * install)184 md_update(struct install_partition_desc *install)
185 {
186 	md_post_newfs(install);
187 	return 1;
188 }
189 
190 int
md_check_mbr(struct disk_partitions * parts,mbr_info_t * mbri,bool quiet)191 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
192 {
193 	return 2;
194 }
195 
196 bool
md_parts_use_wholedisk(struct disk_partitions * parts)197 md_parts_use_wholedisk(struct disk_partitions *parts)
198 {
199 	return parts_use_wholedisk(parts, 0, NULL);
200 }
201 
202 int
md_pre_mount(struct install_partition_desc * install,size_t ndx)203 md_pre_mount(struct install_partition_desc *install, size_t ndx)
204 {
205 	return 0;
206 }
207 
208 /* returns false if no write-back of parts is required */
209 bool
md_mbr_update_check(struct disk_partitions * parts,mbr_info_t * mbri)210 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
211 {
212 	return false;
213 }
214 
215 #ifdef HAVE_GPT
216 /*
217  * New GPT partitions have been written, update bootloader or remember
218  * data untill needed in md_post_newfs
219  */
220 bool
md_gpt_post_write(struct disk_partitions * parts,part_id root_id,bool root_is_new,part_id efi_id,bool efi_is_new)221 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
222     bool root_is_new, part_id efi_id, bool efi_is_new)
223 {
224 	return true;
225 }
226 #endif
227 
228