md.c revision 1.2.6.2 1 1.2.6.2 tls /* $NetBSD: md.c,v 1.2.6.2 2014/08/20 00:05:16 tls Exp $ */
2 1.2.6.2 tls
3 1.2.6.2 tls /*
4 1.2.6.2 tls * Copyright 1997 Piermont Information Systems Inc.
5 1.2.6.2 tls * All rights reserved.
6 1.2.6.2 tls *
7 1.2.6.2 tls * Based on code written by Philip A. Nelson for Piermont Information
8 1.2.6.2 tls * Systems Inc.
9 1.2.6.2 tls *
10 1.2.6.2 tls * Redistribution and use in source and binary forms, with or without
11 1.2.6.2 tls * modification, are permitted provided that the following conditions
12 1.2.6.2 tls * are met:
13 1.2.6.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.2.6.2 tls * notice, this list of conditions and the following disclaimer.
15 1.2.6.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.6.2 tls * notice, this list of conditions and the following disclaimer in the
17 1.2.6.2 tls * documentation and/or other materials provided with the distribution.
18 1.2.6.2 tls * 3. The name of Piermont Information Systems Inc. may not be used to endorse
19 1.2.6.2 tls * or promote products derived from this software without specific prior
20 1.2.6.2 tls * written permission.
21 1.2.6.2 tls *
22 1.2.6.2 tls * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
23 1.2.6.2 tls * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.2.6.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.2.6.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
26 1.2.6.2 tls * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.2.6.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.2.6.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.2.6.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.2.6.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.2.6.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 1.2.6.2 tls * THE POSSIBILITY OF SUCH DAMAGE.
33 1.2.6.2 tls */
34 1.2.6.2 tls
35 1.2.6.2 tls /* md.c -- mac68k machine specific routines */
36 1.2.6.2 tls
37 1.2.6.2 tls #include <stdio.h>
38 1.2.6.2 tls #include <util.h>
39 1.2.6.2 tls #include <unistd.h>
40 1.2.6.2 tls #include <fcntl.h>
41 1.2.6.2 tls #include <sys/ioctl.h>
42 1.2.6.2 tls #include <sys/utsname.h>
43 1.2.6.2 tls #include <machine/int_fmtio.h>
44 1.2.6.2 tls
45 1.2.6.2 tls #include "defs.h"
46 1.2.6.2 tls #include "md.h"
47 1.2.6.2 tls #include "msg_defs.h"
48 1.2.6.2 tls #include "menu_defs.h"
49 1.2.6.2 tls
50 1.2.6.2 tls static int stricmp(const char *c1, const char *c2);
51 1.2.6.2 tls static void setpartition(struct apple_part_map_entry *, char *, int);
52 1.2.6.2 tls static int getFreeLabelEntry(char *);
53 1.2.6.2 tls static char *getFstype(struct apple_part_map_entry *, int, char *);
54 1.2.6.2 tls static char *getUse(struct apple_part_map_entry *, int, char *);
55 1.2.6.2 tls static char *getName(struct apple_part_map_entry *, int, char *);
56 1.2.6.2 tls static int findStdType(int, char *, int, int *, int);
57 1.2.6.2 tls static int check_for_errors(void);
58 1.2.6.2 tls static int edit_diskmap(void);
59 1.2.6.2 tls #ifdef MD_DEBUG_SORT_MERGE
60 1.2.6.2 tls static int md_debug_dump(char *);
61 1.2.6.2 tls #endif
62 1.2.6.2 tls
63 1.2.6.2 tls int blk_size;
64 1.2.6.2 tls
65 1.2.6.2 tls MAP_TYPE map_types[] = {
66 1.2.6.2 tls {MAP_RESERVED, APPLE_PART_TYPE_DRIVER},
67 1.2.6.2 tls {MAP_RESERVED, APPLE_PART_TYPE_DRIVER43},
68 1.2.6.2 tls {MAP_RESERVED, APPLE_PART_TYPE_DRIVERATA},
69 1.2.6.2 tls {MAP_RESERVED, APPLE_PART_TYPE_FWB_COMPONENT},
70 1.2.6.2 tls {MAP_MACOS, APPLE_PART_TYPE_MAC},
71 1.2.6.2 tls {MAP_NETBSD, APPLE_PART_TYPE_NETBSD},
72 1.2.6.2 tls {MAP_RESERVED, APPLE_PART_TYPE_PARTMAP},
73 1.2.6.2 tls {MAP_OTHER, APPLE_PART_TYPE_SCRATCH},
74 1.2.6.2 tls {MAP_NETBSD, APPLE_PART_TYPE_UNIX},
75 1.2.6.2 tls {MAP_EOL, NULL}
76 1.2.6.2 tls };
77 1.2.6.2 tls
78 1.2.6.2 tls MAP map = {0, 0, 0, 0, 0, 0, 0, 0, {0}, NULL};
79 1.2.6.2 tls
80 1.2.6.2 tls struct apple_part_map_entry new_map[] =
81 1.2.6.2 tls {
82 1.2.6.2 tls { APPLE_PART_MAP_ENTRY_MAGIC, 0xa5a5, 6, 1, NEW_MAP_SIZE & 0x7e,
83 1.2.6.2 tls "Apple", "Apple_Partition_Map", 0, NEW_MAP_SIZE, 0x37,
84 1.2.6.2 tls 0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
85 1.2.6.2 tls { APPLE_PART_MAP_ENTRY_MAGIC, 0, 6, 64, 32,
86 1.2.6.2 tls "Macintosh", "Apple_Driver", 0, 0, 0x37,
87 1.2.6.2 tls 0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
88 1.2.6.2 tls { APPLE_PART_MAP_ENTRY_MAGIC, 0, 6, 96, 64,
89 1.2.6.2 tls "Macintosh", "Apple_Driver43", 0, 0, 0x37,
90 1.2.6.2 tls 0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
91 1.2.6.2 tls { APPLE_PART_MAP_ENTRY_MAGIC, 0, 6, 160, 64,
92 1.2.6.2 tls "Macintosh", "Apple_Driver_ATA", 0, 0, 0x37,
93 1.2.6.2 tls 0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
94 1.2.6.2 tls { APPLE_PART_MAP_ENTRY_MAGIC, 0, 6, 224, 4096,
95 1.2.6.2 tls "untitled", "Apple_HFS", 0, 0, 0x37,
96 1.2.6.2 tls 0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}},
97 1.2.6.2 tls { APPLE_PART_MAP_ENTRY_MAGIC, 0, 6,4320, 0,
98 1.2.6.2 tls "untitled", "Apple_Free", 0, 0, 0x37,
99 1.2.6.2 tls 0, 0, 0, 0, 0, 0, 0, {0}, {0}, {0}}
100 1.2.6.2 tls };
101 1.2.6.2 tls
102 1.2.6.2 tls void
103 1.2.6.2 tls md_init(void)
104 1.2.6.2 tls {
105 1.2.6.2 tls }
106 1.2.6.2 tls
107 1.2.6.2 tls void
108 1.2.6.2 tls md_init_set_status(int flags)
109 1.2.6.2 tls {
110 1.2.6.2 tls struct utsname instsys;
111 1.2.6.2 tls
112 1.2.6.2 tls (void)flags;
113 1.2.6.2 tls
114 1.2.6.2 tls /*
115 1.2.6.2 tls * Get the name of the Install Kernel we are running under and
116 1.2.6.2 tls * enable the installation of the corresponding GENERIC kernel.
117 1.2.6.2 tls *
118 1.2.6.2 tls * Note: In md.h the two kernels are disabled. If they are
119 1.2.6.2 tls * enabled there the logic here needs to be switched.
120 1.2.6.2 tls */
121 1.2.6.2 tls uname(&instsys);
122 1.2.6.2 tls if (strstr(instsys.version, "(INSTALLSBC)"))
123 1.2.6.2 tls /*
124 1.2.6.2 tls * Running the SBC Installation Kernel, so enable GENERICSBC
125 1.2.6.2 tls */
126 1.2.6.2 tls set_kernel_set(SET_KERNEL_2);
127 1.2.6.2 tls else
128 1.2.6.2 tls /*
129 1.2.6.2 tls * Running the GENERIC Installation Kernel, so enable GENERIC
130 1.2.6.2 tls */
131 1.2.6.2 tls set_kernel_set(SET_KERNEL_1);
132 1.2.6.2 tls }
133 1.2.6.2 tls
134 1.2.6.2 tls int
135 1.2.6.2 tls md_get_info(void)
136 1.2.6.2 tls {
137 1.2.6.2 tls struct disklabel disklabel;
138 1.2.6.2 tls int fd, i;
139 1.2.6.2 tls char dev_name[100];
140 1.2.6.2 tls struct apple_part_map_entry block;
141 1.2.6.2 tls
142 1.2.6.2 tls snprintf(dev_name, sizeof(dev_name), "/dev/r%s%c",
143 1.2.6.2 tls pm->diskdev, 'a' + getrawpartition());
144 1.2.6.2 tls
145 1.2.6.2 tls /*
146 1.2.6.2 tls * Open the disk as a raw device
147 1.2.6.2 tls */
148 1.2.6.2 tls fd = open(dev_name, O_RDONLY, 0);
149 1.2.6.2 tls if (fd < 0) {
150 1.2.6.2 tls endwin();
151 1.2.6.2 tls fprintf (stderr, "Can't open %s\n", dev_name);
152 1.2.6.2 tls exit(1);
153 1.2.6.2 tls }
154 1.2.6.2 tls /*
155 1.2.6.2 tls * Try to get the default disklabel info for the device
156 1.2.6.2 tls */
157 1.2.6.2 tls if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
158 1.2.6.2 tls endwin();
159 1.2.6.2 tls fprintf (stderr, "Can't read disklabel on %s\n", dev_name);
160 1.2.6.2 tls close(fd);
161 1.2.6.2 tls exit(1);
162 1.2.6.2 tls }
163 1.2.6.2 tls /*
164 1.2.6.2 tls * Get the disk parameters from the disk driver. It should have
165 1.2.6.2 tls * obained them by querying the disk itself.
166 1.2.6.2 tls */
167 1.2.6.2 tls blk_size = disklabel.d_secsize;
168 1.2.6.2 tls pm->dlcyl = disklabel.d_ncylinders;
169 1.2.6.2 tls pm->dlhead = disklabel.d_ntracks;
170 1.2.6.2 tls pm->dlsec = disklabel.d_nsectors;
171 1.2.6.2 tls /*
172 1.2.6.2 tls * Just in case, initialize the structures we'll need if we
173 1.2.6.2 tls * need to completely initialize the disk.
174 1.2.6.2 tls */
175 1.2.6.2 tls pm->dlsize = disklabel.d_secperunit;
176 1.2.6.2 tls for (i=0;i<NEW_MAP_SIZE;i++) {
177 1.2.6.2 tls if (i > 0)
178 1.2.6.2 tls new_map[i].pmPyPartStart = new_map[i-1].pmPyPartStart +
179 1.2.6.2 tls new_map[i-1].pmPartBlkCnt;
180 1.2.6.2 tls new_map[i].pmDataCnt = new_map[i].pmPartBlkCnt;
181 1.2.6.2 tls if (new_map[i].pmPartBlkCnt == 0) {
182 1.2.6.2 tls new_map[i].pmPartBlkCnt = pm->dlsize;
183 1.2.6.2 tls new_map[i].pmDataCnt = pm->dlsize;
184 1.2.6.2 tls break;
185 1.2.6.2 tls }
186 1.2.6.2 tls pm->dlsize -= new_map[i].pmPartBlkCnt;
187 1.2.6.2 tls }
188 1.2.6.2 tls pm->dlsize = disklabel.d_secperunit;
189 1.2.6.2 tls #if 0
190 1.2.6.2 tls msg_display(MSG_dldebug, blk_size, pm->dlcyl, pm->dlhead, pm->dlsec, pm->dlsize);
191 1.2.6.2 tls process_menu(MENU_ok, NULL);
192 1.2.6.2 tls #endif
193 1.2.6.2 tls map.size = 0;
194 1.2.6.2 tls /*
195 1.2.6.2 tls * Verify the disk has been initialized for MacOS use by checking
196 1.2.6.2 tls * to see if the disk have a Boot Block
197 1.2.6.2 tls */
198 1.2.6.2 tls if (lseek(fd, (off_t)0 * blk_size, SEEK_SET) < 0 ||
199 1.2.6.2 tls read(fd, &block, sizeof(block)) - sizeof(block) != 0 ||
200 1.2.6.2 tls block.pmSig != 0x4552) {
201 1.2.6.2 tls process_menu(MENU_nodiskmap, NULL);
202 1.2.6.2 tls }
203 1.2.6.2 tls else {
204 1.2.6.2 tls /*
205 1.2.6.2 tls * Scan for the Partition Map entry that describes the Partition
206 1.2.6.2 tls * Map itself. We need to know the number of blocks allocated
207 1.2.6.2 tls * to it and the number currently in use.
208 1.2.6.2 tls */
209 1.2.6.2 tls for (i=0;i<MAXMAXPARTITIONS;i++) {
210 1.2.6.2 tls lseek(fd, (off_t)(i+1) * blk_size, SEEK_SET);
211 1.2.6.2 tls read(fd, &block, sizeof(block));
212 1.2.6.2 tls if (stricmp("Apple_partition_map", (char *)block.pmPartType) == 0) {
213 1.2.6.2 tls map.size = block.pmPartBlkCnt;
214 1.2.6.2 tls map.in_use_cnt = block.pmMapBlkCnt;
215 1.2.6.2 tls map.blk = (struct apple_part_map_entry *)malloc(map.size * blk_size);
216 1.2.6.2 tls break;
217 1.2.6.2 tls }
218 1.2.6.2 tls }
219 1.2.6.2 tls lseek(fd, (off_t)1 * blk_size, SEEK_SET);
220 1.2.6.2 tls read(fd, map.blk, map.size * blk_size);
221 1.2.6.2 tls }
222 1.2.6.2 tls close(fd);
223 1.2.6.2 tls /*
224 1.2.6.2 tls * Setup the disktype so /etc/disktab gets proper info
225 1.2.6.2 tls */
226 1.2.6.2 tls if (strncmp(pm->diskdev, "sd", 2) == 0) {
227 1.2.6.2 tls pm->disktype = "SCSI";
228 1.2.6.2 tls pm->doessf = "sf:";
229 1.2.6.2 tls } else
230 1.2.6.2 tls pm->disktype = "IDE";
231 1.2.6.2 tls
232 1.2.6.2 tls return edit_diskmap();
233 1.2.6.2 tls }
234 1.2.6.2 tls
235 1.2.6.2 tls /*
236 1.2.6.2 tls * md back-end code for menu-driven BSD disklabel editor.
237 1.2.6.2 tls */
238 1.2.6.2 tls int
239 1.2.6.2 tls md_make_bsd_partitions(void)
240 1.2.6.2 tls {
241 1.2.6.2 tls FILE *f;
242 1.2.6.2 tls int i, j, pl;
243 1.2.6.2 tls EBZB *bzb;
244 1.2.6.2 tls
245 1.2.6.2 tls /*
246 1.2.6.2 tls * Scan for any problems and report them before continuing.
247 1.2.6.2 tls * The user can abort installation and we'll take them back
248 1.2.6.2 tls * to the main menu; continue ignoring the warnings, or
249 1.2.6.2 tls * ask to reedit the Disk Partition Map.
250 1.2.6.2 tls */
251 1.2.6.2 tls while (1) {
252 1.2.6.2 tls if (check_for_errors()) {
253 1.2.6.2 tls process_menu (MENU_sanity, NULL);
254 1.2.6.2 tls if (yesno < 0)
255 1.2.6.2 tls return 0;
256 1.2.6.2 tls else if (yesno)
257 1.2.6.2 tls break;
258 1.2.6.2 tls edit_diskmap();
259 1.2.6.2 tls } else
260 1.2.6.2 tls break;
261 1.2.6.2 tls }
262 1.2.6.2 tls
263 1.2.6.2 tls /* Build standard partitions */
264 1.2.6.2 tls memset(&pm->bsdlabel, 0, sizeof pm->bsdlabel);
265 1.2.6.2 tls
266 1.2.6.2 tls /*
267 1.2.6.2 tls * The mac68k port has a predefined partition for "c" which
268 1.2.6.2 tls * is the size of the disk, everything else is unused.
269 1.2.6.2 tls */
270 1.2.6.2 tls pm->bsdlabel[RAW_PART].pi_size = pm->dlsize;
271 1.2.6.2 tls /*
272 1.2.6.2 tls * Now, scan through the Disk Partition Map and transfer the
273 1.2.6.2 tls * information into the incore disklabel.
274 1.2.6.2 tls */
275 1.2.6.2 tls for (i=0;i<map.usable_cnt;i++) {
276 1.2.6.2 tls j = map.mblk[i];
277 1.2.6.2 tls bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
278 1.2.6.2 tls if (bzb->flags.part) {
279 1.2.6.2 tls pl = bzb->flags.part - 'a';
280 1.2.6.2 tls switch (whichType(&map.blk[j])) {
281 1.2.6.2 tls case HFS_PART:
282 1.2.6.2 tls pm->bsdlabel[pl].pi_fstype = FS_HFS;
283 1.2.6.2 tls strcpy (pm->bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
284 1.2.6.2 tls break;
285 1.2.6.2 tls case ROOT_PART:
286 1.2.6.2 tls case UFS_PART:
287 1.2.6.2 tls pm->bsdlabel[pl].pi_fstype = FS_BSDFFS;
288 1.2.6.2 tls strcpy (pm->bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
289 1.2.6.2 tls pm->bsdlabel[pl].pi_flags |= PIF_NEWFS | PIF_MOUNT;
290 1.2.6.2 tls break;
291 1.2.6.2 tls case SWAP_PART:
292 1.2.6.2 tls pm->bsdlabel[pl].pi_fstype = FS_SWAP;
293 1.2.6.2 tls break;
294 1.2.6.2 tls case SCRATCH_PART:
295 1.2.6.2 tls pm->bsdlabel[pl].pi_fstype = FS_OTHER;
296 1.2.6.2 tls strcpy (pm->bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
297 1.2.6.2 tls default:
298 1.2.6.2 tls break;
299 1.2.6.2 tls }
300 1.2.6.2 tls if (pm->bsdlabel[pl].pi_fstype != FS_UNUSED) {
301 1.2.6.2 tls pm->bsdlabel[pl].pi_size = map.blk[j].pmPartBlkCnt;
302 1.2.6.2 tls pm->bsdlabel[pl].pi_offset = map.blk[j].pmPyPartStart;
303 1.2.6.2 tls if (pm->bsdlabel[pl].pi_fstype != FS_SWAP) {
304 1.2.6.2 tls pm->bsdlabel[pl].pi_frag = 8;
305 1.2.6.2 tls pm->bsdlabel[pl].pi_fsize = 1024;
306 1.2.6.2 tls }
307 1.2.6.2 tls }
308 1.2.6.2 tls }
309 1.2.6.2 tls }
310 1.2.6.2 tls
311 1.2.6.2 tls /* Disk name - don't bother asking, just use the physical name*/
312 1.2.6.2 tls strcpy (pm->bsddiskname, pm->diskdev);
313 1.2.6.2 tls
314 1.2.6.2 tls #ifdef DEBUG
315 1.2.6.2 tls f = fopen ("/tmp/disktab", "w");
316 1.2.6.2 tls #else
317 1.2.6.2 tls f = fopen ("/etc/disktab", "w");
318 1.2.6.2 tls #endif
319 1.2.6.2 tls if (f == NULL) {
320 1.2.6.2 tls endwin();
321 1.2.6.2 tls (void) fprintf (stderr, "Could not open /etc/disktab");
322 1.2.6.2 tls exit (1);
323 1.2.6.2 tls }
324 1.2.6.2 tls (void)fprintf (f, "%s|NetBSD installation generated:\\\n", pm->bsddiskname);
325 1.2.6.2 tls (void)fprintf (f, "\t:dt=%s:ty=winchester:\\\n", pm->disktype);
326 1.2.6.2 tls (void)fprintf (f, "\t:nc#%d:nt#%d:ns#%d:\\\n", pm->dlcyl, pm->dlhead, pm->dlsec);
327 1.2.6.2 tls (void)fprintf (f, "\t:sc#%d:su#%" PRIu32 ":\\\n", pm->dlhead*pm->dlsec, (uint32_t)pm->dlsize);
328 1.2.6.2 tls (void)fprintf (f, "\t:se#%d:%s\\\n", blk_size, pm->doessf);
329 1.2.6.2 tls for (i=0; i<8; i++) {
330 1.2.6.2 tls if (pm->bsdlabel[i].pi_fstype == FS_HFS)
331 1.2.6.2 tls (void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=macos:",
332 1.2.6.2 tls 'a'+i, pm->bsdlabel[i].pi_size,
333 1.2.6.2 tls 'a'+i, pm->bsdlabel[i].pi_offset,
334 1.2.6.2 tls 'a'+i);
335 1.2.6.2 tls else
336 1.2.6.2 tls (void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=%s:",
337 1.2.6.2 tls 'a'+i, pm->bsdlabel[i].pi_size,
338 1.2.6.2 tls 'a'+i, pm->bsdlabel[i].pi_offset,
339 1.2.6.2 tls 'a'+i, getfslabelname(pm->bsdlabel[i].pi_fstype));
340 1.2.6.2 tls if (pm->bsdlabel[i].pi_fstype == FS_BSDFFS)
341 1.2.6.2 tls (void)fprintf (f, "b%c#%d:f%c#%d",
342 1.2.6.2 tls 'a'+i, pm->bsdlabel[i].pi_fsize * pm->bsdlabel[i].pi_frag,
343 1.2.6.2 tls 'a'+i, pm->bsdlabel[i].pi_fsize);
344 1.2.6.2 tls if (i < 7)
345 1.2.6.2 tls (void)fprintf (f, "\\\n");
346 1.2.6.2 tls else
347 1.2.6.2 tls (void)fprintf (f, "\n");
348 1.2.6.2 tls }
349 1.2.6.2 tls fclose (f);
350 1.2.6.2 tls
351 1.2.6.2 tls /* Everything looks OK. */
352 1.2.6.2 tls return 1;
353 1.2.6.2 tls }
354 1.2.6.2 tls
355 1.2.6.2 tls /*
356 1.2.6.2 tls * any additional partition validation
357 1.2.6.2 tls */
358 1.2.6.2 tls int
359 1.2.6.2 tls md_check_partitions(void)
360 1.2.6.2 tls {
361 1.2.6.2 tls return 1;
362 1.2.6.2 tls }
363 1.2.6.2 tls
364 1.2.6.2 tls /*
365 1.2.6.2 tls * hook called before writing new disklabel.
366 1.2.6.2 tls */
367 1.2.6.2 tls int
368 1.2.6.2 tls md_pre_disklabel(void)
369 1.2.6.2 tls {
370 1.2.6.2 tls int fd;
371 1.2.6.2 tls char dev_name[100];
372 1.2.6.2 tls struct disklabel lp;
373 1.2.6.2 tls Block0 new_block0 = {APPLE_DRVR_MAP_MAGIC, 512,
374 1.2.6.2 tls 0, 0, 0, 0, 0, 0, 0, 0, {0}};
375 1.2.6.2 tls
376 1.2.6.2 tls /*
377 1.2.6.2 tls * Danger Will Robinson! We're about to turn that nice MacOS disk
378 1.2.6.2 tls * into an expensive doorstop...
379 1.2.6.2 tls */
380 1.2.6.2 tls printf ("%s", msg_string (MSG_dodiskmap));
381 1.2.6.2 tls
382 1.2.6.2 tls snprintf (dev_name, sizeof(dev_name), "/dev/r%sc", pm->diskdev);
383 1.2.6.2 tls /*
384 1.2.6.2 tls * Open the disk as a raw device
385 1.2.6.2 tls */
386 1.2.6.2 tls if ((fd = open(dev_name, O_WRONLY, 0)) < 0) {
387 1.2.6.2 tls endwin();
388 1.2.6.2 tls fprintf(stderr, "Can't open %s to rewrite the Disk Map\n", dev_name);
389 1.2.6.2 tls exit (1);
390 1.2.6.2 tls }
391 1.2.6.2 tls /*
392 1.2.6.2 tls * First check the pmSigPad field of the first block in the incore
393 1.2.6.2 tls * Partition Map. It should be zero, but if it's 0xa5a5 that means
394 1.2.6.2 tls * we need to write out Block0 too.
395 1.2.6.2 tls */
396 1.2.6.2 tls if (map.blk[0].pmSigPad == 0xa5a5) {
397 1.2.6.2 tls if (lseek (fd, (off_t)0 * blk_size, SEEK_SET) < 0) {
398 1.2.6.2 tls endwin();
399 1.2.6.2 tls fprintf (stderr, "Can't position to write Block0\n");
400 1.2.6.2 tls close (fd);
401 1.2.6.2 tls exit (1);
402 1.2.6.2 tls }
403 1.2.6.2 tls new_block0.sbBlkCount = pm->dlsize; /* Set disk size */
404 1.2.6.2 tls if (write (fd, &new_block0, blk_size) != blk_size) {
405 1.2.6.2 tls endwin();
406 1.2.6.2 tls fprintf (stderr, "I/O error writing Block0\n");
407 1.2.6.2 tls close (fd);
408 1.2.6.2 tls exit (1);
409 1.2.6.2 tls }
410 1.2.6.2 tls map.blk[0].pmSigPad = 0;
411 1.2.6.2 tls }
412 1.2.6.2 tls if (lseek (fd, (off_t)1 * blk_size, SEEK_SET) < 0) {
413 1.2.6.2 tls endwin();
414 1.2.6.2 tls fprintf (stderr, "Can't position disk to rewrite Disk Map\n");
415 1.2.6.2 tls close (fd);
416 1.2.6.2 tls exit (1);
417 1.2.6.2 tls }
418 1.2.6.2 tls if (write (fd, map.blk, map.size * blk_size) != (map.size * blk_size)) {
419 1.2.6.2 tls endwin();
420 1.2.6.2 tls fprintf(stderr, "I/O error writing Disk Map\n");
421 1.2.6.2 tls close (fd);
422 1.2.6.2 tls exit (1);
423 1.2.6.2 tls }
424 1.2.6.2 tls fsync(fd);
425 1.2.6.2 tls /*
426 1.2.6.2 tls * Well, if we get here the dirty deed has been done.
427 1.2.6.2 tls *
428 1.2.6.2 tls * Now we need to force the incore disk table to get updated. This
429 1.2.6.2 tls * should be done by disklabel -- which is normally called right after
430 1.2.6.2 tls * we return -- but may be commented out for the mac68k port. We'll
431 1.2.6.2 tls * instead update the incore table by forcing a dummy write here. This
432 1.2.6.2 tls * relies on a change in the mac68k-specific write_disklabel() routine.
433 1.2.6.2 tls * If that change doesn't exist nothing bad happens here. If disklabel
434 1.2.6.2 tls * properly updates the ondisk and incore labels everything still
435 1.2.6.2 tls * works. Only if we fail here and if disklabel fails are we in
436 1.2.6.2 tls * in a state where we've updated the disk but not the incore and
437 1.2.6.2 tls * a reboot is necessary.
438 1.2.6.2 tls *
439 1.2.6.2 tls * First, we grab a copy of the incore label as it existed before
440 1.2.6.2 tls * we did anything to it. Then we invoke the "write label" ioctl to
441 1.2.6.2 tls * rewrite it to disk. As a result, the ondisk partition map is
442 1.2.6.2 tls * re-read and the incore label is reconstructed from it. If
443 1.2.6.2 tls * disklabel() is then called to update again, either that fails
444 1.2.6.2 tls * because the mac68k port doesn't support native disklabels, or it
445 1.2.6.2 tls * succeeds and writes out a new ondisk copy.
446 1.2.6.2 tls */
447 1.2.6.2 tls ioctl(fd, DIOCGDINFO, &lp); /* Get the current disk label */
448 1.2.6.2 tls ioctl(fd, DIOCWDINFO, &lp); /* Write it out again */
449 1.2.6.2 tls
450 1.2.6.2 tls close (fd);
451 1.2.6.2 tls return 0;
452 1.2.6.2 tls }
453 1.2.6.2 tls
454 1.2.6.2 tls /*
455 1.2.6.2 tls * hook called after writing disklabel to new target disk.
456 1.2.6.2 tls */
457 1.2.6.2 tls int
458 1.2.6.2 tls md_post_disklabel(void)
459 1.2.6.2 tls {
460 1.2.6.2 tls struct disklabel updated_label;
461 1.2.6.2 tls int fd, i, no_match;
462 1.2.6.2 tls char dev_name[100], buf[80];
463 1.2.6.2 tls const char *fst[] = {"free", "swap", " v6 ", " v7 ", "sysv", "v71k",
464 1.2.6.2 tls " v8 ", "ffs ", "dos ", "lfs ", "othr", "hpfs",
465 1.2.6.2 tls "9660", "boot", "ados", "hfs ", "fcor", "ex2f",
466 1.2.6.2 tls "ntfs", "raid", "ccd "};
467 1.2.6.2 tls
468 1.2.6.2 tls snprintf(dev_name, sizeof(dev_name), "/dev/r%sc", pm->diskdev);
469 1.2.6.2 tls /*
470 1.2.6.2 tls * Open the disk as a raw device
471 1.2.6.2 tls */
472 1.2.6.2 tls if ((fd = open(dev_name, O_RDONLY, 0)) < 0)
473 1.2.6.2 tls return 0;
474 1.2.6.2 tls /*
475 1.2.6.2 tls * Get the "new" label to see if we were successful. If we aren't
476 1.2.6.2 tls * we'll return an error to keep from destroying the user's disk.
477 1.2.6.2 tls */
478 1.2.6.2 tls ioctl(fd, DIOCGDINFO, &updated_label);
479 1.2.6.2 tls close(fd);
480 1.2.6.2 tls /*
481 1.2.6.2 tls * Make sure the in-core label matches the on-disk one
482 1.2.6.2 tls */
483 1.2.6.2 tls no_match = 0;
484 1.2.6.2 tls for (i=0;i<MAXPARTITIONS;i++) {
485 1.2.6.2 tls if (i > updated_label.d_npartitions)
486 1.2.6.2 tls break;
487 1.2.6.2 tls if (pm->bsdlabel[i].pi_size != updated_label.d_partitions[i].p_size)
488 1.2.6.2 tls no_match = 1;
489 1.2.6.2 tls if (pm->bsdlabel[i].pi_size) {
490 1.2.6.2 tls if (pm->bsdlabel[i].pi_offset != updated_label.d_partitions[i].p_offset)
491 1.2.6.2 tls no_match = 1;
492 1.2.6.2 tls if (pm->bsdlabel[i].pi_fstype != updated_label.d_partitions[i].p_fstype)
493 1.2.6.2 tls no_match = 1;
494 1.2.6.2 tls }
495 1.2.6.2 tls if (no_match)
496 1.2.6.2 tls break;
497 1.2.6.2 tls }
498 1.2.6.2 tls /*
499 1.2.6.2 tls * If the labels don't match, tell the user why
500 1.2.6.2 tls */
501 1.2.6.2 tls if (no_match) {
502 1.2.6.2 tls msg_clear();
503 1.2.6.2 tls msg_display(MSG_label_error);
504 1.2.6.2 tls msg_table_add(MSG_dump_line,
505 1.2.6.2 tls " in-core: offset size type on-disk: offset size type");
506 1.2.6.2 tls for (i=0;i<MAXPARTITIONS;i++) {
507 1.2.6.2 tls sprintf(buf, " %c:%13.8x%10.8x%5s%16.8x%10.8x%5s", i+'a',
508 1.2.6.2 tls pm->bsdlabel[i].pi_offset, pm->bsdlabel[i].pi_size,
509 1.2.6.2 tls fst[pm->bsdlabel[i].pi_fstype],
510 1.2.6.2 tls updated_label.d_partitions[i].p_offset,
511 1.2.6.2 tls updated_label.d_partitions[i].p_size,
512 1.2.6.2 tls fst[updated_label.d_partitions[i].p_fstype]);
513 1.2.6.2 tls msg_table_add(MSG_dump_line, buf);
514 1.2.6.2 tls }
515 1.2.6.2 tls process_menu(MENU_ok2, NULL);
516 1.2.6.2 tls }
517 1.2.6.2 tls return no_match;
518 1.2.6.2 tls }
519 1.2.6.2 tls
520 1.2.6.2 tls /*
521 1.2.6.2 tls * hook called after upgrade() or install() has finished setting
522 1.2.6.2 tls * up the target disk but immediately before the user is given the
523 1.2.6.2 tls * ``disks are now set up'' message.
524 1.2.6.2 tls */
525 1.2.6.2 tls int
526 1.2.6.2 tls md_post_newfs(void)
527 1.2.6.2 tls {
528 1.2.6.2 tls return 0;
529 1.2.6.2 tls }
530 1.2.6.2 tls
531 1.2.6.2 tls int
532 1.2.6.2 tls md_post_extract(void)
533 1.2.6.2 tls {
534 1.2.6.2 tls return 0;
535 1.2.6.2 tls }
536 1.2.6.2 tls
537 1.2.6.2 tls void
538 1.2.6.2 tls md_cleanup_install(void)
539 1.2.6.2 tls {
540 1.2.6.2 tls #ifndef DEBUG
541 1.2.6.2 tls enable_rc_conf();
542 1.2.6.2 tls #endif
543 1.2.6.2 tls }
544 1.2.6.2 tls
545 1.2.6.2 tls int
546 1.2.6.2 tls md_pre_update(void)
547 1.2.6.2 tls {
548 1.2.6.2 tls return 1;
549 1.2.6.2 tls }
550 1.2.6.2 tls
551 1.2.6.2 tls /* Upgrade support */
552 1.2.6.2 tls int
553 1.2.6.2 tls md_update(void)
554 1.2.6.2 tls {
555 1.2.6.2 tls md_post_newfs();
556 1.2.6.2 tls return 1;
557 1.2.6.2 tls }
558 1.2.6.2 tls
559 1.2.6.2 tls /*
560 1.2.6.2 tls * Compare lexigraphically two strings
561 1.2.6.2 tls */
562 1.2.6.2 tls static int
563 1.2.6.2 tls stricmp(s1, s2)
564 1.2.6.2 tls const char *s1;
565 1.2.6.2 tls const char *s2;
566 1.2.6.2 tls {
567 1.2.6.2 tls char c1, c2;
568 1.2.6.2 tls
569 1.2.6.2 tls while (1) {
570 1.2.6.2 tls c1 = tolower((unsigned char)*s1++);
571 1.2.6.2 tls c2 = tolower((unsigned char)*s2++);
572 1.2.6.2 tls if (c1 < c2) return -1;
573 1.2.6.2 tls if (c1 > c2) return 1;
574 1.2.6.2 tls if (c1 == 0) return 0;
575 1.2.6.2 tls }
576 1.2.6.2 tls }
577 1.2.6.2 tls
578 1.2.6.2 tls static void
579 1.2.6.2 tls setpartition(part, in_use, slot)
580 1.2.6.2 tls struct apple_part_map_entry *part;
581 1.2.6.2 tls char in_use[];
582 1.2.6.2 tls int slot;
583 1.2.6.2 tls {
584 1.2.6.2 tls EBZB *bzb;
585 1.2.6.2 tls
586 1.2.6.2 tls bzb = (EBZB *)&part->pmBootArgs[0];
587 1.2.6.2 tls in_use[slot] = 1;
588 1.2.6.2 tls bzb->flags.used = 1;
589 1.2.6.2 tls bzb->flags.part = 'a' + slot;
590 1.2.6.2 tls }
591 1.2.6.2 tls
592 1.2.6.2 tls /*
593 1.2.6.2 tls * Find an entry in a use array that is unused and return it or
594 1.2.6.2 tls * -1 if no entry is available
595 1.2.6.2 tls */
596 1.2.6.2 tls static int
597 1.2.6.2 tls getFreeLabelEntry(slots)
598 1.2.6.2 tls char *slots;
599 1.2.6.2 tls {
600 1.2.6.2 tls int i;
601 1.2.6.2 tls
602 1.2.6.2 tls for ( i = 0; i < MAXPARTITIONS; i++) {
603 1.2.6.2 tls if (i != RAW_PART && slots[i] == 0)
604 1.2.6.2 tls return i;
605 1.2.6.2 tls }
606 1.2.6.2 tls return -1;
607 1.2.6.2 tls }
608 1.2.6.2 tls
609 1.2.6.2 tls /*
610 1.2.6.2 tls * Figure out what type type of the given partition is and return it.
611 1.2.6.2 tls */
612 1.2.6.2 tls int
613 1.2.6.2 tls whichType(part)
614 1.2.6.2 tls struct apple_part_map_entry *part;
615 1.2.6.2 tls {
616 1.2.6.2 tls MAP_TYPE *map_entry = (MAP_TYPE *)&map_types;
617 1.2.6.2 tls EBZB *bzb;
618 1.2.6.2 tls char partyp[32];
619 1.2.6.2 tls int type, maxsiz, entry_type = MAP_OTHER;
620 1.2.6.2 tls
621 1.2.6.2 tls bzb = (EBZB *)&part->pmBootArgs[0];
622 1.2.6.2 tls if (part->pmSig != APPLE_PART_MAP_ENTRY_MAGIC)
623 1.2.6.2 tls return 0;
624 1.2.6.2 tls maxsiz = sizeof(part->pmPartType);
625 1.2.6.2 tls if (maxsiz > (int)sizeof(partyp))
626 1.2.6.2 tls maxsiz = sizeof(partyp);
627 1.2.6.2 tls strncpy(partyp, (char *)part->pmPartType, maxsiz);
628 1.2.6.2 tls partyp[maxsiz-1] = '\0';
629 1.2.6.2 tls
630 1.2.6.2 tls /*
631 1.2.6.2 tls * Find out how to treat the partition type under NetBSD
632 1.2.6.2 tls */
633 1.2.6.2 tls while (map_entry->type != MAP_EOL) {
634 1.2.6.2 tls if (stricmp(map_entry->name, partyp) == 0) {
635 1.2.6.2 tls entry_type = map_entry->type;
636 1.2.6.2 tls break;
637 1.2.6.2 tls }
638 1.2.6.2 tls map_entry++;
639 1.2.6.2 tls }
640 1.2.6.2 tls
641 1.2.6.2 tls /*
642 1.2.6.2 tls * Now classify the use for NetBSD
643 1.2.6.2 tls */
644 1.2.6.2 tls if (entry_type == MAP_RESERVED)
645 1.2.6.2 tls type = 0;
646 1.2.6.2 tls else if (entry_type == MAP_NETBSD) {
647 1.2.6.2 tls if (bzb->magic != APPLE_BZB_MAGIC)
648 1.2.6.2 tls type = 0;
649 1.2.6.2 tls else if (bzb->type == APPLE_BZB_TYPEFS) {
650 1.2.6.2 tls if (bzb->flags.root)
651 1.2.6.2 tls type = ROOT_PART;
652 1.2.6.2 tls else if (bzb->flags.usr)
653 1.2.6.2 tls type = UFS_PART;
654 1.2.6.2 tls else
655 1.2.6.2 tls type = SCRATCH_PART;
656 1.2.6.2 tls } else if (bzb->type == APPLE_BZB_TYPESWAP)
657 1.2.6.2 tls type = SWAP_PART;
658 1.2.6.2 tls else
659 1.2.6.2 tls type = SCRATCH_PART;
660 1.2.6.2 tls } else if (entry_type == MAP_MACOS)
661 1.2.6.2 tls type = HFS_PART;
662 1.2.6.2 tls else
663 1.2.6.2 tls type = SCRATCH_PART;
664 1.2.6.2 tls return type;
665 1.2.6.2 tls }
666 1.2.6.2 tls
667 1.2.6.2 tls static char *
668 1.2.6.2 tls getFstype(part, len_type, type)
669 1.2.6.2 tls struct apple_part_map_entry *part;
670 1.2.6.2 tls int len_type;
671 1.2.6.2 tls char *type;
672 1.2.6.2 tls {
673 1.2.6.2 tls *type = '\0';
674 1.2.6.2 tls switch(whichType(part)) {
675 1.2.6.2 tls case ROOT_PART:
676 1.2.6.2 tls case UFS_PART:
677 1.2.6.2 tls strncpy(type, "4.2BSD", len_type);
678 1.2.6.2 tls break;
679 1.2.6.2 tls case SWAP_PART:
680 1.2.6.2 tls strncpy(type, "swap", len_type);
681 1.2.6.2 tls break;
682 1.2.6.2 tls case HFS_PART:
683 1.2.6.2 tls strncpy(type, "HFS", len_type);
684 1.2.6.2 tls break;
685 1.2.6.2 tls case SCRATCH_PART:
686 1.2.6.2 tls default:
687 1.2.6.2 tls break;
688 1.2.6.2 tls }
689 1.2.6.2 tls return (type);
690 1.2.6.2 tls }
691 1.2.6.2 tls
692 1.2.6.2 tls static char *
693 1.2.6.2 tls getUse(part, len_use, use)
694 1.2.6.2 tls struct apple_part_map_entry *part;
695 1.2.6.2 tls int len_use;
696 1.2.6.2 tls char *use;
697 1.2.6.2 tls {
698 1.2.6.2 tls EBZB *bzb;
699 1.2.6.2 tls char partyp[32];
700 1.2.6.2 tls
701 1.2.6.2 tls *use = '\0';
702 1.2.6.2 tls bzb = (EBZB *)&part->pmBootArgs[0];
703 1.2.6.2 tls switch(whichType(part)) {
704 1.2.6.2 tls case ROOT_PART:
705 1.2.6.2 tls if (bzb->flags.usr)
706 1.2.6.2 tls strncpy(use, "Root&Usr", len_use);
707 1.2.6.2 tls else
708 1.2.6.2 tls strncpy(use, "Root", len_use);
709 1.2.6.2 tls break;
710 1.2.6.2 tls case UFS_PART:
711 1.2.6.2 tls strncpy(use, "Usr", len_use);
712 1.2.6.2 tls break;
713 1.2.6.2 tls case SWAP_PART:
714 1.2.6.2 tls break;
715 1.2.6.2 tls case HFS_PART:
716 1.2.6.2 tls strncpy(use, "MacOS", len_use);
717 1.2.6.2 tls break;
718 1.2.6.2 tls case SCRATCH_PART:
719 1.2.6.2 tls strncpy(partyp, (char *)part->pmPartType, sizeof(partyp));
720 1.2.6.2 tls partyp[sizeof(partyp)-1] = '\0';
721 1.2.6.2 tls if (stricmp("Apple_Free", partyp) == 0)
722 1.2.6.2 tls strncpy(use, "Free", len_use);
723 1.2.6.2 tls else if (stricmp("Apple_Scratch", partyp) == 0)
724 1.2.6.2 tls strncpy(use, "Scratch", len_use);
725 1.2.6.2 tls else if (stricmp("Apple_MFS", partyp) == 0)
726 1.2.6.2 tls strncpy(use, "MFS", len_use);
727 1.2.6.2 tls else if (stricmp("Apple_PRODOS", partyp) == 0)
728 1.2.6.2 tls strncpy(use, "PRODOS", len_use);
729 1.2.6.2 tls else
730 1.2.6.2 tls strncpy(use, "unknown", len_use);
731 1.2.6.2 tls default:
732 1.2.6.2 tls break;
733 1.2.6.2 tls }
734 1.2.6.2 tls return(use);
735 1.2.6.2 tls }
736 1.2.6.2 tls
737 1.2.6.2 tls static char *
738 1.2.6.2 tls getName(part, len_name, name)
739 1.2.6.2 tls struct apple_part_map_entry *part;
740 1.2.6.2 tls int len_name;
741 1.2.6.2 tls char *name;
742 1.2.6.2 tls {
743 1.2.6.2 tls EBZB *bzb;
744 1.2.6.2 tls int fd;
745 1.2.6.2 tls off_t seek;
746 1.2.6.2 tls char dev_name[100], macosblk[512];
747 1.2.6.2 tls
748 1.2.6.2 tls *name = '\0';
749 1.2.6.2 tls bzb = (EBZB *)&part->pmBootArgs[0];
750 1.2.6.2 tls switch(whichType(part)) {
751 1.2.6.2 tls case SCRATCH_PART:
752 1.2.6.2 tls case ROOT_PART:
753 1.2.6.2 tls case UFS_PART:
754 1.2.6.2 tls strncpy(name, (char *)bzb->mount_point, len_name);
755 1.2.6.2 tls break;
756 1.2.6.2 tls case SWAP_PART:
757 1.2.6.2 tls break;
758 1.2.6.2 tls case HFS_PART:
759 1.2.6.2 tls /*
760 1.2.6.2 tls * OK, this is stupid but it's damn nice to know!
761 1.2.6.2 tls */
762 1.2.6.2 tls snprintf (dev_name, sizeof(dev_name), "/dev/r%sc", pm->diskdev);
763 1.2.6.2 tls /*
764 1.2.6.2 tls * Open the disk as a raw device
765 1.2.6.2 tls */
766 1.2.6.2 tls if ((fd = open(dev_name, O_RDONLY, 0)) >= 0) {
767 1.2.6.2 tls seek = (off_t)part->pmPyPartStart + (off_t)2;
768 1.2.6.2 tls seek *= (off_t)blk_size;
769 1.2.6.2 tls lseek(fd, seek, SEEK_SET);
770 1.2.6.2 tls read(fd, &macosblk, sizeof(macosblk));
771 1.2.6.2 tls macosblk[37+32] = '\0';
772 1.2.6.2 tls strncpy(name, (char *)bzb->mount_point, len_name);
773 1.2.6.2 tls strncat(name, " (", len_name-strlen(name));
774 1.2.6.2 tls strncat(name, &macosblk[37], len_name-strlen(name));
775 1.2.6.2 tls strncat(name, ")", len_name-strlen(name));
776 1.2.6.2 tls close(fd);
777 1.2.6.2 tls }
778 1.2.6.2 tls break;
779 1.2.6.2 tls default:
780 1.2.6.2 tls break;
781 1.2.6.2 tls }
782 1.2.6.2 tls return(name);
783 1.2.6.2 tls }
784 1.2.6.2 tls
785 1.2.6.2 tls /*
786 1.2.6.2 tls * Find the first occurance of a Standard Type partition and
787 1.2.6.2 tls * mark it for use along with the default mount slot.
788 1.2.6.2 tls */
789 1.2.6.2 tls static int
790 1.2.6.2 tls findStdType(num_parts, in_use, type, count, alt)
791 1.2.6.2 tls int num_parts;
792 1.2.6.2 tls char in_use[];
793 1.2.6.2 tls int type;
794 1.2.6.2 tls int *count;
795 1.2.6.2 tls int alt;
796 1.2.6.2 tls {
797 1.2.6.2 tls EBZB *bzb;
798 1.2.6.2 tls int i;
799 1.2.6.2 tls
800 1.2.6.2 tls for (i = 0; i < num_parts; i++) {
801 1.2.6.2 tls bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
802 1.2.6.2 tls if (whichType(&map.blk[i]) != type || bzb->flags.used)
803 1.2.6.2 tls continue;
804 1.2.6.2 tls if (type == ROOT_PART) {
805 1.2.6.2 tls if (alt >= 0 && alt != bzb->cluster)
806 1.2.6.2 tls continue;
807 1.2.6.2 tls setpartition(&map.blk[i], in_use, 0);
808 1.2.6.2 tls strcpy ((char *)bzb->mount_point, "/");
809 1.2.6.2 tls *count += 1;
810 1.2.6.2 tls } else if (type == UFS_PART) {
811 1.2.6.2 tls if (alt >= 0 && alt != bzb->cluster)
812 1.2.6.2 tls continue;
813 1.2.6.2 tls setpartition(&map.blk[i], in_use, 6);
814 1.2.6.2 tls if (bzb->mount_point[0] == '\0')
815 1.2.6.2 tls strcpy ((char *)bzb->mount_point, "/usr");
816 1.2.6.2 tls *count += 1;
817 1.2.6.2 tls } else if (type == SWAP_PART) {
818 1.2.6.2 tls setpartition(&map.blk[i], in_use, 1);
819 1.2.6.2 tls *count += 1;
820 1.2.6.2 tls }
821 1.2.6.2 tls return 0;
822 1.2.6.2 tls }
823 1.2.6.2 tls return -1;
824 1.2.6.2 tls }
825 1.2.6.2 tls
826 1.2.6.2 tls /*
827 1.2.6.2 tls * Reset the flags and reserved fields in the selected partition.
828 1.2.6.2 tls * This functions isn't called to process any of the reserved partitions
829 1.2.6.2 tls * where the boot code for MacOS is stored, so (hopefully) we won't
830 1.2.6.2 tls * do more damage that we're trying to avoid. Eventually the NetBSD
831 1.2.6.2 tls * Boot Code will need to go into a partition too, but that should go
832 1.2.6.2 tls * into a reserved partition as well. I'd suggest using a partition
833 1.2.6.2 tls * named something like "NetBSD_Boot" with a pmPartName of "Macintosh".
834 1.2.6.2 tls * The Apple Start Manager (in ROM) will then recognize the partition
835 1.2.6.2 tls * as the one containing the system bootstrip for the volume.
836 1.2.6.2 tls */
837 1.2.6.2 tls void
838 1.2.6.2 tls reset_part_flags(part)
839 1.2.6.2 tls struct apple_part_map_entry *part;
840 1.2.6.2 tls {
841 1.2.6.2 tls EBZB *bzb;
842 1.2.6.2 tls
843 1.2.6.2 tls /*
844 1.2.6.2 tls * Clear out the MacOS fields that might be used for booting just
845 1.2.6.2 tls * in case we've clobbered the boot code.
846 1.2.6.2 tls */
847 1.2.6.2 tls part->pmLgDataStart = 0;
848 1.2.6.2 tls part->pmPartStatus = 0x77; /* make sure the partition shows up */
849 1.2.6.2 tls part->pmLgBootStart = 0;
850 1.2.6.2 tls part->pmBootSize = 0;
851 1.2.6.2 tls part->pmBootLoad = 0;
852 1.2.6.2 tls part->pmBootLoad2 = 0;
853 1.2.6.2 tls part->pmBootEntry = 0;
854 1.2.6.2 tls part->pmBootEntry2 = 0;
855 1.2.6.2 tls part->pmBootCksum = 0;
856 1.2.6.2 tls
857 1.2.6.2 tls /*
858 1.2.6.2 tls * Clear out all the NetBSD fields too. We only clear out the ones
859 1.2.6.2 tls * that should get reset during our processing.
860 1.2.6.2 tls */
861 1.2.6.2 tls bzb = (EBZB *)&part->pmBootArgs[0];
862 1.2.6.2 tls bzb->magic = 0;
863 1.2.6.2 tls bzb->cluster = 0;
864 1.2.6.2 tls bzb->inode = 0;
865 1.2.6.2 tls bzb->type = 0;
866 1.2.6.2 tls bzb->flags.root = 0;
867 1.2.6.2 tls bzb->flags.usr = 0;
868 1.2.6.2 tls bzb->flags.crit = 0;
869 1.2.6.2 tls bzb->flags.slice = 0;
870 1.2.6.2 tls bzb->flags.used = 0;
871 1.2.6.2 tls return;
872 1.2.6.2 tls }
873 1.2.6.2 tls
874 1.2.6.2 tls /*
875 1.2.6.2 tls * sortmerge:
876 1.2.6.2 tls * 1) Moves all the Partition Map entries to the front of the Map.
877 1.2.6.2 tls * This is required because some disk formatters leave holes.
878 1.2.6.2 tls * 2) Sorts all entries by ascending start block number.
879 1.2.6.2 tls * Needed so the NetBSD algorithm for finding partitions works
880 1.2.6.2 tls * consistently from a user perspective.
881 1.2.6.2 tls * 3) Collapse multiple adjected "free" entries into a single entry.
882 1.2.6.2 tls * 4) Identify the NetBSD mount_points.
883 1.2.6.2 tls */
884 1.2.6.2 tls void
885 1.2.6.2 tls sortmerge(void)
886 1.2.6.2 tls {
887 1.2.6.2 tls struct apple_part_map_entry tmp_blk;
888 1.2.6.2 tls char in_use[MAXPARTITIONS];
889 1.2.6.2 tls int i, j;
890 1.2.6.2 tls EBZB *bzb;
891 1.2.6.2 tls
892 1.2.6.2 tls /*
893 1.2.6.2 tls * Step 1, squeeze out the holes that some disk formatters leave in
894 1.2.6.2 tls * the Map. Also convert any "old" Map entries to the new entry
895 1.2.6.2 tls * type. Also clear out our used flag which is used to indicte
896 1.2.6.2 tls * we've mapped the partition.
897 1.2.6.2 tls */
898 1.2.6.2 tls map.in_use_cnt = 0;
899 1.2.6.2 tls for (i=0;i<map.size-1;i++) {
900 1.2.6.2 tls if (map.blk[i].pmSig == 0x5453)
901 1.2.6.2 tls map.blk[i].pmSig = APPLE_PART_MAP_ENTRY_MAGIC;
902 1.2.6.2 tls if (map.blk[i].pmSig != APPLE_PART_MAP_ENTRY_MAGIC) {
903 1.2.6.2 tls for (j=i+1;j<map.size;j++) {
904 1.2.6.2 tls if (map.blk[j].pmSig == 0x5453)
905 1.2.6.2 tls map.blk[j].pmSig = APPLE_PART_MAP_ENTRY_MAGIC;
906 1.2.6.2 tls if (map.blk[j].pmSig == APPLE_PART_MAP_ENTRY_MAGIC) {
907 1.2.6.2 tls memcpy (&map.blk[i], &map.blk[j], sizeof(map.blk[i]));
908 1.2.6.2 tls map.blk[j].pmSig = 0;
909 1.2.6.2 tls break;
910 1.2.6.2 tls }
911 1.2.6.2 tls }
912 1.2.6.2 tls } else {
913 1.2.6.2 tls map.in_use_cnt += 1;
914 1.2.6.2 tls bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
915 1.2.6.2 tls bzb->flags.used = 0;
916 1.2.6.2 tls bzb->flags.part = 0;
917 1.2.6.2 tls }
918 1.2.6.2 tls }
919 1.2.6.2 tls
920 1.2.6.2 tls /*
921 1.2.6.2 tls * Step 2, sort by ascending starting block number. Since
922 1.2.6.2 tls * we've already removed the holes we only need to
923 1.2.6.2 tls * deal with the in_use count of blocks.
924 1.2.6.2 tls */
925 1.2.6.2 tls for (i=0;i<map.in_use_cnt-1;i++) {
926 1.2.6.2 tls for (j=i+1;j<map.in_use_cnt;j++) {
927 1.2.6.2 tls if (map.blk[i].pmPyPartStart > map.blk[j].pmPyPartStart) {
928 1.2.6.2 tls memcpy (&tmp_blk, &map.blk[i], sizeof(tmp_blk));
929 1.2.6.2 tls memcpy (&map.blk[i], &map.blk[j], sizeof(map.blk[i]));
930 1.2.6.2 tls memcpy (&map.blk[j], &tmp_blk, sizeof(map.blk[j]));
931 1.2.6.2 tls }
932 1.2.6.2 tls }
933 1.2.6.2 tls }
934 1.2.6.2 tls
935 1.2.6.2 tls /*
936 1.2.6.2 tls * Step 3, merge adjacent free space
937 1.2.6.2 tls */
938 1.2.6.2 tls for (i=0;i<map.in_use_cnt-1;i++) {
939 1.2.6.2 tls if (stricmp("Apple_Free", (char *)map.blk[i].pmPartType) == 0 &&
940 1.2.6.2 tls stricmp("Apple_Free", (char *)map.blk[i+1].pmPartType) == 0) {
941 1.2.6.2 tls map.blk[i].pmPartBlkCnt += map.blk[i+1].pmPartBlkCnt;
942 1.2.6.2 tls map.blk[i].pmDataCnt += map.blk[i+1].pmDataCnt;
943 1.2.6.2 tls map.blk[i+1].pmSig = 0;
944 1.2.6.2 tls for (j=i+1;j<map.in_use_cnt-1;j++) {
945 1.2.6.2 tls memcpy (&map.blk[j], &map.blk[j+1], sizeof(map.blk[j]));
946 1.2.6.2 tls map.blk[j+1].pmSig = 0;
947 1.2.6.2 tls }
948 1.2.6.2 tls map.in_use_cnt -= 1;
949 1.2.6.2 tls }
950 1.2.6.2 tls }
951 1.2.6.2 tls
952 1.2.6.2 tls /*
953 1.2.6.2 tls * Step 4, try to identify the mount points for the partitions
954 1.2.6.2 tls * and adjust the pmMapBlkCnt in each Map entry. Set
955 1.2.6.2 tls * up the display array for the non-reserved partitions,
956 1.2.6.2 tls * and count the number of NetBSD usable partitions
957 1.2.6.2 tls */
958 1.2.6.2 tls map.hfs_cnt = 0;
959 1.2.6.2 tls map.root_cnt = 0;
960 1.2.6.2 tls map.swap_cnt = 0;
961 1.2.6.2 tls map.usr_cnt = 0;
962 1.2.6.2 tls map.usable_cnt = 0;
963 1.2.6.2 tls /*
964 1.2.6.2 tls * Clear out record of partition slots already in use
965 1.2.6.2 tls */
966 1.2.6.2 tls memset(&in_use, 0, sizeof(in_use));
967 1.2.6.2 tls for (i=0,j=0;i<map.in_use_cnt;i++) {
968 1.2.6.2 tls map.blk[i].pmSig = APPLE_PART_MAP_ENTRY_MAGIC;
969 1.2.6.2 tls map.blk[i].pmMapBlkCnt = map.in_use_cnt;
970 1.2.6.2 tls /*
971 1.2.6.2 tls * Since MAXPARTITIONS == 8 for mac68k, and we do not display
972 1.2.6.2 tls * the c partition, we only need 7 partition slots on the screen.
973 1.2.6.2 tls * If/when MAXPARTITIONS is changed, the "Edit Disk Partition Map"
974 1.2.6.2 tls * needs to be a scrollable view of the partition table.
975 1.2.6.2 tls */
976 1.2.6.2 tls if (whichType(&map.blk[i]) && (j < MAXPARTITIONS - 1)) {
977 1.2.6.2 tls map.mblk[j++] = i;
978 1.2.6.2 tls map.usable_cnt += 1;
979 1.2.6.2 tls }
980 1.2.6.2 tls }
981 1.2.6.2 tls /*
982 1.2.6.2 tls * Fill in standard partitions. Look for a Cluster "0" first and use
983 1.2.6.2 tls * it, otherwise take any Cluster value.
984 1.2.6.2 tls */
985 1.2.6.2 tls if (findStdType(map.in_use_cnt, in_use, ROOT_PART, &map.root_cnt, 0))
986 1.2.6.2 tls findStdType(map.in_use_cnt, in_use, ROOT_PART, &map.root_cnt, -1);
987 1.2.6.2 tls if (findStdType(map.in_use_cnt, in_use, UFS_PART, &map.usr_cnt, 0))
988 1.2.6.2 tls findStdType(map.in_use_cnt, in_use, UFS_PART, &map.usr_cnt, -1);
989 1.2.6.2 tls if (findStdType(map.in_use_cnt, in_use, SWAP_PART, &map.swap_cnt, 0))
990 1.2.6.2 tls findStdType(map.in_use_cnt, in_use, SWAP_PART, &map.swap_cnt, -1);
991 1.2.6.2 tls
992 1.2.6.2 tls #ifdef MD_DEBUG_SORT_MERGE
993 1.2.6.2 tls md_debug_dump("After marking Standard Types");
994 1.2.6.2 tls #endif
995 1.2.6.2 tls /*
996 1.2.6.2 tls * Now fill in the remaining partitions counting them by type and
997 1.2.6.2 tls * assigning them the slot the where the kernel should map them.
998 1.2.6.2 tls * This will be where they are displayed in the Edit Map.
999 1.2.6.2 tls */
1000 1.2.6.2 tls for (i=0; i < map.in_use_cnt; i++) {
1001 1.2.6.2 tls bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
1002 1.2.6.2 tls if (bzb->flags.used == 0) {
1003 1.2.6.2 tls if ((j = getFreeLabelEntry(in_use)) < 0)
1004 1.2.6.2 tls break;
1005 1.2.6.2 tls switch (whichType(&map.blk[i])) {
1006 1.2.6.2 tls case ROOT_PART:
1007 1.2.6.2 tls map.root_cnt += 1;
1008 1.2.6.2 tls setpartition(&map.blk[i], in_use, j);
1009 1.2.6.2 tls break;
1010 1.2.6.2 tls case UFS_PART:
1011 1.2.6.2 tls map.usr_cnt += 1;
1012 1.2.6.2 tls setpartition(&map.blk[i], in_use, j);
1013 1.2.6.2 tls break;
1014 1.2.6.2 tls case SWAP_PART:
1015 1.2.6.2 tls map.swap_cnt += 1;
1016 1.2.6.2 tls setpartition(&map.blk[i], in_use, j);
1017 1.2.6.2 tls break;
1018 1.2.6.2 tls case HFS_PART:
1019 1.2.6.2 tls map.hfs_cnt += 1;
1020 1.2.6.2 tls setpartition(&map.blk[i], in_use, j);
1021 1.2.6.2 tls break;
1022 1.2.6.2 tls case SCRATCH_PART:
1023 1.2.6.2 tls setpartition(&map.blk[i], in_use, j);
1024 1.2.6.2 tls default:
1025 1.2.6.2 tls break;
1026 1.2.6.2 tls }
1027 1.2.6.2 tls }
1028 1.2.6.2 tls }
1029 1.2.6.2 tls #ifdef MD_DEBUG_SORT_MERGE
1030 1.2.6.2 tls md_debug_dump("After sort merge");
1031 1.2.6.2 tls #endif
1032 1.2.6.2 tls return;
1033 1.2.6.2 tls }
1034 1.2.6.2 tls
1035 1.2.6.2 tls void
1036 1.2.6.2 tls disp_selected_part(sel)
1037 1.2.6.2 tls int sel;
1038 1.2.6.2 tls {
1039 1.2.6.2 tls int i,j;
1040 1.2.6.2 tls char fstyp[16], use[16], name[32];
1041 1.2.6.2 tls EBZB *bzb;
1042 1.2.6.2 tls
1043 1.2.6.2 tls msg_table_add(MSG_part_header);
1044 1.2.6.2 tls for (i=0;i<map.usable_cnt;i++) {
1045 1.2.6.2 tls if (i == sel) msg_standout();
1046 1.2.6.2 tls j = map.mblk[i];
1047 1.2.6.2 tls getFstype(&map.blk[j], sizeof(fstyp), fstyp);
1048 1.2.6.2 tls getUse(&map.blk[j], sizeof(use), use);
1049 1.2.6.2 tls getName(&map.blk[j], sizeof(name), name);
1050 1.2.6.2 tls bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
1051 1.2.6.2 tls msg_table_add(MSG_part_row, pm->diskdev,
1052 1.2.6.2 tls bzb->flags.part, map.blk[j].pmPyPartStart,
1053 1.2.6.2 tls map.blk[j].pmPartBlkCnt, fstyp, use, name);
1054 1.2.6.2 tls if (i == sel) msg_standend();
1055 1.2.6.2 tls }
1056 1.2.6.2 tls return;
1057 1.2.6.2 tls }
1058 1.2.6.2 tls
1059 1.2.6.2 tls /*
1060 1.2.6.2 tls * check for any anomalies on the requested setup
1061 1.2.6.2 tls */
1062 1.2.6.2 tls static int
1063 1.2.6.2 tls check_for_errors()
1064 1.2.6.2 tls {
1065 1.2.6.2 tls int i, j;
1066 1.2.6.2 tls int errs = 0;
1067 1.2.6.2 tls
1068 1.2.6.2 tls errs = (!map.root_cnt) || (map.root_cnt > 1) || (!map.swap_cnt) ||
1069 1.2.6.2 tls (map.swap_cnt > 1);
1070 1.2.6.2 tls
1071 1.2.6.2 tls for (i=0;i<map.usable_cnt;i++) {
1072 1.2.6.2 tls j = map.mblk[i];
1073 1.2.6.2 tls if (map.blk[j].pmPyPartStart > pm->dlsize)
1074 1.2.6.2 tls errs++;
1075 1.2.6.2 tls if ((map.blk[j].pmPyPartStart + map.blk[j].pmPartBlkCnt) > pm->dlsize + 1)
1076 1.2.6.2 tls errs++;
1077 1.2.6.2 tls }
1078 1.2.6.2 tls return(errs);
1079 1.2.6.2 tls }
1080 1.2.6.2 tls
1081 1.2.6.2 tls /*
1082 1.2.6.2 tls * check for and report anomalies on the requested setup
1083 1.2.6.2 tls */
1084 1.2.6.2 tls void
1085 1.2.6.2 tls report_errors()
1086 1.2.6.2 tls {
1087 1.2.6.2 tls int i, j;
1088 1.2.6.2 tls int errs = 0;
1089 1.2.6.2 tls EBZB *bzb;
1090 1.2.6.2 tls
1091 1.2.6.2 tls if (!map.root_cnt) {
1092 1.2.6.2 tls msg_display_add(MSG_disksetup_no_root);
1093 1.2.6.2 tls errs++;
1094 1.2.6.2 tls }
1095 1.2.6.2 tls if (map.root_cnt > 1) {
1096 1.2.6.2 tls msg_display_add(MSG_disksetup_multiple_roots);
1097 1.2.6.2 tls errs++;
1098 1.2.6.2 tls }
1099 1.2.6.2 tls if (!map.swap_cnt) {
1100 1.2.6.2 tls msg_display_add(MSG_disksetup_no_swap);
1101 1.2.6.2 tls errs++;
1102 1.2.6.2 tls }
1103 1.2.6.2 tls if (map.swap_cnt > 1) {
1104 1.2.6.2 tls msg_display_add(MSG_disksetup_multiple_swaps);
1105 1.2.6.2 tls errs++;
1106 1.2.6.2 tls }
1107 1.2.6.2 tls for (i=0;i<map.usable_cnt;i++) {
1108 1.2.6.2 tls j = map.mblk[i];
1109 1.2.6.2 tls if (map.blk[j].pmPyPartStart > pm->dlsize) {
1110 1.2.6.2 tls bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
1111 1.2.6.2 tls msg_display_add(MSG_disksetup_part_beginning,
1112 1.2.6.2 tls pm->diskdev, bzb->flags.part);
1113 1.2.6.2 tls errs++;
1114 1.2.6.2 tls }
1115 1.2.6.2 tls if ((map.blk[j].pmPyPartStart + map.blk[j].pmPartBlkCnt) > pm->dlsize) {
1116 1.2.6.2 tls bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
1117 1.2.6.2 tls msg_display_add(MSG_disksetup_part_size,
1118 1.2.6.2 tls pm->diskdev, bzb->flags.part);
1119 1.2.6.2 tls errs++;
1120 1.2.6.2 tls }
1121 1.2.6.2 tls }
1122 1.2.6.2 tls if (!errs)
1123 1.2.6.2 tls msg_display_add(MSG_disksetup_noerrors);
1124 1.2.6.2 tls return;
1125 1.2.6.2 tls }
1126 1.2.6.2 tls
1127 1.2.6.2 tls static int
1128 1.2.6.2 tls edit_diskmap(void)
1129 1.2.6.2 tls {
1130 1.2.6.2 tls int i;
1131 1.2.6.2 tls
1132 1.2.6.2 tls /* Ask full/part */
1133 1.2.6.2 tls msg_display (MSG_fullpart, pm->diskdev);
1134 1.2.6.2 tls process_menu (MENU_fullpart, NULL);
1135 1.2.6.2 tls
1136 1.2.6.2 tls map.selected = 0;
1137 1.2.6.2 tls sortmerge();
1138 1.2.6.2 tls
1139 1.2.6.2 tls /* If blowing away the whole disk, let user know if there
1140 1.2.6.2 tls * are any active disk partitions */
1141 1.2.6.2 tls if (usefull) {
1142 1.2.6.2 tls if (map.usable_cnt > (map.root_cnt+map.swap_cnt+map.usr_cnt)) {
1143 1.2.6.2 tls msg_display (MSG_ovrwrite);
1144 1.2.6.2 tls process_menu (MENU_noyes, NULL);
1145 1.2.6.2 tls if (!yesno) {
1146 1.2.6.2 tls endwin();
1147 1.2.6.2 tls return 0;
1148 1.2.6.2 tls }
1149 1.2.6.2 tls }
1150 1.2.6.2 tls /*
1151 1.2.6.2 tls * mark all non-reserved partitions as "free"
1152 1.2.6.2 tls * then sort and merge the map into something sensible
1153 1.2.6.2 tls */
1154 1.2.6.2 tls for (i=0;i<map.size;i++)
1155 1.2.6.2 tls if (whichType(&map.blk[i]))
1156 1.2.6.2 tls strcpy ((char *)map.blk[i].pmPartType, "Apple_Free");
1157 1.2.6.2 tls sortmerge();
1158 1.2.6.2 tls }
1159 1.2.6.2 tls process_menu (MENU_editparttable, NULL);
1160 1.2.6.2 tls return 1;
1161 1.2.6.2 tls }
1162 1.2.6.2 tls
1163 1.2.6.2 tls #ifdef MD_DEBUG_SORT_MERGE
1164 1.2.6.2 tls static int
1165 1.2.6.2 tls md_debug_dump(title)
1166 1.2.6.2 tls char *title;
1167 1.2.6.2 tls {
1168 1.2.6.2 tls char buf[96], type;
1169 1.2.6.2 tls char fstyp[16], use[16], name[64];
1170 1.2.6.2 tls int i, j;
1171 1.2.6.2 tls EBZB *bzb;
1172 1.2.6.2 tls
1173 1.2.6.2 tls msg_clear();
1174 1.2.6.2 tls sprintf(buf, "Apple Disk Partition Map: %s", title);
1175 1.2.6.2 tls msg_table_add(MSG_dump_line, buf);
1176 1.2.6.2 tls msg_table_add(MSG_dump_line,
1177 1.2.6.2 tls "slot base fstype use name");
1178 1.2.6.2 tls for (i=0;i<map.in_use_cnt;i++) {
1179 1.2.6.2 tls j = whichType(&map.blk[i]);
1180 1.2.6.2 tls getFstype(&map.blk[i], sizeof(fstyp), fstyp);
1181 1.2.6.2 tls getUse(&map.blk[i], sizeof(use), use);
1182 1.2.6.2 tls getName(&map.blk[i], sizeof(name), name);
1183 1.2.6.2 tls bzb = (EBZB *) &map.blk[i].pmBootArgs[0];
1184 1.2.6.2 tls type = bzb->flags.part;
1185 1.2.6.2 tls if (type < 'a' || type > 'h') type = '?';
1186 1.2.6.2 tls if (j == 0) strcpy (name, "reserved for Apple");
1187 1.2.6.2 tls sprintf(buf, " %02d:%c %08x %8s %10s %s", i+1, type,
1188 1.2.6.2 tls map.blk[i].pmPyPartStart, fstyp, use, name);
1189 1.2.6.2 tls msg_table_add(MSG_dump_line, buf);
1190 1.2.6.2 tls }
1191 1.2.6.2 tls process_menu(MENU_okabort, NULL);
1192 1.2.6.2 tls msg_clear();
1193 1.2.6.2 tls return(yesno);
1194 1.2.6.2 tls }
1195 1.2.6.2 tls #endif /* MD_DEBUG_SORT_MERGE */
1196 1.2.6.2 tls
1197 1.2.6.2 tls int
1198 1.2.6.2 tls md_pre_mount()
1199 1.2.6.2 tls {
1200 1.2.6.2 tls return 0;
1201 1.2.6.2 tls }
1202