md.c revision 1.5 1 /* $NetBSD: md.c,v 1.5 2019/06/12 06:20:21 martin Exp $ */
2
3 /*
4 * Copyright 1997,2002 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 -- landisk 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
48 md_init(void)
49 {
50 }
51
52 void
53 md_init_set_status(int flags)
54 {
55 (void)flags;
56 }
57
58 bool
59 md_get_info(struct install_partition_desc *install)
60 {
61 return set_bios_geom_with_mbr_guess(pm->parts);
62 }
63
64 /*
65 * md back-end code for menu-driven BSD disklabel editor.
66 */
67 bool
68 md_make_bsd_partitions(struct install_partition_desc *install)
69 {
70 return make_bsd_partitions(install);
71 }
72
73 /*
74 * any additional partition validation
75 */
76 bool
77 md_check_partitions(struct install_partition_desc *install)
78 {
79 return true;
80 }
81
82 /*
83 * hook called before writing new disklabel.
84 */
85 bool
86 md_pre_disklabel(struct install_partition_desc *install,
87 struct disk_partitions *parts)
88 {
89
90 if (parts->parent == NULL)
91 return true; /* no outer partitions */
92
93 parts = parts->parent;
94
95 msg_display_subst(MSG_dofdisk, 3, parts->disk,
96 msg_string(parts->pscheme->name),
97 msg_string(parts->pscheme->short_name));
98
99 /* write edited "MBR" onto disk. */
100 if (!parts->pscheme->write_to_disk(parts)) {
101 msg_display(MSG_wmbrfail);
102 process_menu(MENU_ok, NULL);
103 return false;
104 }
105 return true;
106 }
107
108 /*
109 * hook called after writing disklabel to new target disk.
110 */
111 bool
112 md_post_disklabel(struct install_partition_desc *install,
113 struct disk_partitions *parts)
114 {
115 return true;
116 }
117
118 /*
119 * hook called after upgrade() or install() has finished setting
120 * up the target disk but immediately before the user is given the
121 * ``disks are now set up'' message.
122 *
123 * On the landisk, we use this opportunity to install the boot blocks.
124 */
125 int
126 md_post_newfs(struct install_partition_desc *install)
127 {
128 char *bootxx;
129 int error;
130
131 msg_display(MSG_dobootblks, pm->diskdev);
132 cp_to_target("/usr/mdec/boot", "/boot");
133 bootxx = bootxx_name(install);
134 if (bootxx != NULL) {
135 error = run_program(RUN_DISPLAY,
136 "/usr/sbin/installboot -v /dev/r%sa %s", pm->diskdev, bootxx);
137 free(bootxx);
138 } else
139 error = -1;
140
141 if (error != 0)
142 process_menu(MENU_ok,
143 __UNCONST("Warning: disk is probably not bootable"));
144
145 return true;
146 }
147
148 int
149 md_post_extract(struct install_partition_desc *install)
150 {
151 return 0;
152 }
153
154 void
155 md_cleanup_install(struct install_partition_desc *install)
156 {
157 #ifndef DEBUG
158 enable_rc_conf();
159 #endif
160 }
161
162 int
163 md_pre_update(struct install_partition_desc *install)
164 {
165 return 1;
166 }
167
168 /* Upgrade support */
169 int
170 md_update(struct install_partition_desc *install)
171 {
172 md_post_newfs(install);
173 return 1;
174 }
175
176 int
177 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
178 {
179 return 2;
180 }
181
182 bool
183 md_parts_use_wholedisk(struct disk_partitions *parts)
184 {
185 return parts_use_wholedisk(parts, 0, NULL);
186 }
187
188
189 int
190 md_pre_mount(struct install_partition_desc *install)
191 {
192 return 0;
193 }
194
195 bool
196 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
197 {
198 return false; /* no change, no need to write back */
199 }
200
201 #ifdef HAVE_GPT
202 bool
203 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
204 bool root_is_new, part_id efi_id, bool efi_is_new)
205 {
206 /* no GPT boot support, nothing needs to be done here */
207 return true;
208 }
209 #endif
210
211