md.c revision 1.1 1 /* $NetBSD: md.c,v 1.1 2014/07/26 19:30:45 dholland 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 -- ews4800mips machine specific routines */
36
37 #include <sys/types.h>
38 #include <sys/disklabel.h>
39 #include <sys/ioctl.h>
40 #include <sys/param.h>
41 #include <stdio.h>
42 #include <curses.h>
43 #include <unistd.h>
44 #include <fcntl.h>
45 #include <util.h>
46
47 #include "defs.h"
48 #include "md.h"
49 #include "msg_defs.h"
50 #include "menu_defs.h"
51
52 static int ews4800mips_boot_offset(void);
53
54 void
55 md_init(void)
56 {
57 }
58
59 void
60 md_init_set_status(int flags)
61 {
62 (void)flags;
63 }
64
65 int
66 md_get_info(void)
67 {
68 struct disklabel disklabel;
69 int fd;
70 char dev_name[100];
71
72 snprintf(dev_name, 100, "/dev/r%s%c", diskdev, 'a' + getrawpartition());
73
74 fd = open(dev_name, O_RDONLY, 0);
75 if (fd < 0) {
76 endwin();
77 fprintf (stderr, "Can't open %s\n", dev_name);
78 exit(1);
79 }
80 if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
81 endwin();
82 fprintf (stderr, "Can't read disklabel on %s.\n", dev_name);
83 close(fd);
84 exit(1);
85 }
86 close(fd);
87
88 dlcyl = disklabel.d_ncylinders;
89 dlhead = disklabel.d_ntracks;
90 dlsec = disklabel.d_nsectors;
91 sectorsize = disklabel.d_secsize;
92 dlcylsize = disklabel.d_secpercyl;
93
94 /*
95 * Compute whole disk size. Take max of (dlcyl*dlhead*dlsec)
96 * and secperunit, just in case the disk is already labelled.
97 * (If our new label's RAW_PART size ends up smaller than the
98 * in-core RAW_PART size value, updating the label will fail.)
99 */
100 dlsize = dlcyl * dlhead * dlsec;
101 if (disklabel.d_secperunit > dlsize)
102 dlsize = disklabel.d_secperunit;
103
104 return 1;
105 }
106
107 /*
108 * md back-end code for menu-driven BSD disklabel editor.
109 */
110 int
111 md_make_bsd_partitions(void)
112 {
113
114 return make_bsd_partitions();
115 }
116
117 /*
118 * any additional partition validation
119 */
120 int
121 md_check_partitions(void)
122 {
123 return 1;
124 }
125
126 /*
127 * hook called before writing new disklabel.
128 */
129 int
130 md_pre_disklabel(void)
131 {
132 bsdlabel[PART_BOOT].pi_offset = ews4800mips_boot_offset();
133
134 return 0;
135 }
136
137 /*
138 * hook called after writing disklabel to new target disk.
139 */
140 int
141 md_post_disklabel(void)
142 {
143 return 0;
144 }
145
146 /*
147 * hook called after upgrade() or install() has finished setting
148 * up the target disk but immediately before the user is given the
149 * ``disks are now set up'' message.
150 *
151 * On the ews4800mips, we use this opportunity to install the boot blocks.
152 */
153 int
154 md_post_newfs(void)
155 {
156 int flags;
157
158 flags = RUN_DISPLAY | RUN_FATAL;
159 cp_to_target("/usr/mdec/boot", "/stand/boot");
160 run_program(flags, "/usr/sbin/installboot /dev/r%s%c %s",
161 diskdev, 'a' + getrawpartition(),
162 "/usr/mdec/bootxx_bfs");
163
164 return 0;
165 }
166
167 int
168 md_post_extract(void)
169 {
170 return 0;
171 }
172
173 void
174 md_cleanup_install(void)
175 {
176 #ifndef DEBUG
177 enable_rc_conf();
178 #endif
179 }
180
181 int
182 md_pre_update(void)
183 {
184 return 1;
185 }
186
187 /* Upgrade support */
188 int
189 md_update(void)
190 {
191 md_post_newfs();
192 return 1;
193 }
194
195 static int
196 ews4800mips_boot_offset(void)
197 {
198 return dlcylsize;
199 }
200
201 /*
202 * used in bsddisklabel.c as BOOT_SIZE
203 */
204 int
205 ews4800mips_boot_size(void)
206 {
207 int i;
208
209 /*
210 * dlcylsize : PDINFO block
211 * dlcylsize : 100 block
212 */
213 i = dlcylsize + 100;
214 if (i >= 1024) /* XXX bsddisklabel.c hack. convert to byte count. */
215 i = dlcylsize * sectorsize * 2;
216
217 return i;
218 }
219
220 /*
221 * used in bsddisklabel.c as SYSVBFS_SIZE
222 */
223 int
224 ews4800mips_sysvbfs_size(void)
225 {
226 return (8 * 1024 * 1024) / 512; /* 8MB */
227 }
228
229 int
230 md_pre_mount()
231 {
232 return 0;
233 }
234