md.c revision 1.10
1/*	$NetBSD: md.c,v 1.10 2020/10/12 16:14:34 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 -- hpcsh machine specific routines */
36
37#include <stdio.h>
38#include <util.h>
39#include <sys/param.h>
40#include <machine/cpu.h>
41#include <sys/sysctl.h>
42
43#include "defs.h"
44#include "md.h"
45#include "msg_defs.h"
46#include "menu_defs.h"
47#include "endian.h"
48#include "mbr.h"
49
50void
51md_init(void)
52{
53}
54
55void
56md_init_set_status(int flags)
57{
58
59	(void)flags;
60}
61
62bool
63md_get_info(struct install_partition_desc *install)
64{
65	int res;
66
67	if (pm->no_mbr || pm->no_part)
68		return true;
69
70again:
71	if (pm->parts == NULL) {
72
73		const struct disk_partitioning_scheme *ps =
74		    select_part_scheme(pm, NULL, true, NULL);
75
76		if (!ps)
77			return false;
78
79		struct disk_partitions *parts =
80		   (*ps->create_new_for_disk)(pm->diskdev,
81		   0, pm->dlsize, true, NULL);
82		if (!parts)
83			return false;
84
85		pm->parts = parts;
86		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
87			pm->dlsize = ps->size_limit;
88	}
89
90	res = set_bios_geom_with_mbr_guess(pm->parts);
91	if (res == 0)
92		return false;
93	else if (res == 1)
94		return true;
95
96	pm->parts->pscheme->destroy_part_scheme(pm->parts);
97	pm->parts = NULL;
98	goto again;
99}
100
101/*
102 * md back-end code for menu-driven BSD disklabel editor.
103 */
104int
105md_make_bsd_partitions(struct install_partition_desc *install)
106{
107
108	return make_bsd_partitions(install);
109}
110
111/*
112 * any additional partition validation
113 */
114bool
115md_check_partitions(struct install_partition_desc *install)
116{
117
118	return true;
119}
120
121/*
122 * hook called before writing new disklabel.
123 */
124bool
125md_pre_disklabel(struct install_partition_desc *install,
126    struct disk_partitions *parts)
127{
128
129	if (parts->parent == NULL)
130		return true;	/* no outer partitions */
131
132	parts = parts->parent;
133
134	msg_display_subst(MSG_dofdisk, 3, parts->disk,
135	    msg_string(parts->pscheme->name),
136	    msg_string(parts->pscheme->short_name));
137
138	/* write edited "MBR" onto disk. */
139	if (!parts->pscheme->write_to_disk(parts)) {
140		msg_display(MSG_wmbrfail);
141		process_menu(MENU_ok, NULL);
142		return false;
143	}
144	return true;
145}
146
147/*
148 * hook called after writing disklabel to new target disk.
149 */
150bool
151md_post_disklabel(struct install_partition_desc *install,
152    struct disk_partitions *parts)
153{
154        return true;
155}
156
157/*
158 * hook called after upgrade() or install() has finished setting
159 * up the target disk but immediately before the user is given the
160 * ``disks are now set up'' message.
161 */
162int
163md_post_newfs(struct install_partition_desc *install)
164{
165
166	return 0;
167}
168
169void
170md_cleanup_install(struct install_partition_desc *install)
171{
172
173#ifndef DEBUG
174	enable_rc_conf();
175#endif
176}
177
178int
179md_pre_update(struct install_partition_desc *install)
180{
181
182	return 1;
183}
184
185/* Upgrade support */
186int
187md_update(struct install_partition_desc *install)
188{
189
190	md_post_newfs(install);
191	return 1;
192}
193
194int
195md_post_extract(struct install_partition_desc *install)
196{
197
198	return 0;
199}
200
201int
202md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
203{
204
205	return 2;
206}
207
208bool
209md_parts_use_wholedisk(struct disk_partitions *parts)
210{
211
212	return parts_use_wholedisk(parts, 0, NULL);
213}
214
215int
216md_pre_mount(struct install_partition_desc *install, size_t ndx)
217{
218	return 0;
219}
220
221bool
222md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
223{
224	return false;	/* no change, no need to write back */
225}
226
227#ifdef HAVE_GPT
228bool
229md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
230    bool root_is_new, part_id efi_id, bool efi_is_new)
231{
232	/* no GPT boot support, nothing needs to be done here */
233	return true;
234}
235#endif
236
237