1*b8b586ecSmartin /* $NetBSD: md.c,v 1.10 2022/01/29 16:01:20 martin Exp $ */
226165e63Sdholland
326165e63Sdholland /*
426165e63Sdholland * Copyright 1997 Piermont Information Systems Inc.
526165e63Sdholland * All rights reserved.
626165e63Sdholland *
726165e63Sdholland * Based on code written by Philip A. Nelson for Piermont Information
826165e63Sdholland * Systems Inc.
926165e63Sdholland *
1026165e63Sdholland * Redistribution and use in source and binary forms, with or without
1126165e63Sdholland * modification, are permitted provided that the following conditions
1226165e63Sdholland * are met:
1326165e63Sdholland * 1. Redistributions of source code must retain the above copyright
1426165e63Sdholland * notice, this list of conditions and the following disclaimer.
1526165e63Sdholland * 2. Redistributions in binary form must reproduce the above copyright
1626165e63Sdholland * notice, this list of conditions and the following disclaimer in the
1726165e63Sdholland * documentation and/or other materials provided with the distribution.
1826165e63Sdholland * 3. The name of Piermont Information Systems Inc. may not be used to endorse
1926165e63Sdholland * or promote products derived from this software without specific prior
2026165e63Sdholland * written permission.
2126165e63Sdholland *
2226165e63Sdholland * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
2326165e63Sdholland * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2426165e63Sdholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2526165e63Sdholland * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
2626165e63Sdholland * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2726165e63Sdholland * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2826165e63Sdholland * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2926165e63Sdholland * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3026165e63Sdholland * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3126165e63Sdholland * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3226165e63Sdholland * THE POSSIBILITY OF SUCH DAMAGE.
3326165e63Sdholland */
3426165e63Sdholland
3526165e63Sdholland /* md.c -- sgimips machine specific routines */
3626165e63Sdholland
3726165e63Sdholland #include <sys/types.h>
3826165e63Sdholland #include <sys/ioctl.h>
3926165e63Sdholland #include <sys/param.h>
4026165e63Sdholland #include <sys/utsname.h>
4126165e63Sdholland #include <stdio.h>
4226165e63Sdholland #include <curses.h>
4326165e63Sdholland #include <unistd.h>
4426165e63Sdholland #include <fcntl.h>
4526165e63Sdholland #include <util.h>
4626165e63Sdholland #include <errno.h>
4726165e63Sdholland
4826165e63Sdholland #include "defs.h"
4926165e63Sdholland #include "md.h"
5026165e63Sdholland #include "msg_defs.h"
5126165e63Sdholland #include "menu_defs.h"
5226165e63Sdholland
5326165e63Sdholland
5426165e63Sdholland void
md_init(void)5526165e63Sdholland md_init(void)
5626165e63Sdholland {
5726165e63Sdholland }
5826165e63Sdholland
5926165e63Sdholland void
md_init_set_status(int flags)6026165e63Sdholland md_init_set_status(int flags)
6126165e63Sdholland {
62f60f7522Smartin struct utsname instsys;
63f60f7522Smartin
6426165e63Sdholland (void)flags;
6526165e63Sdholland
6626165e63Sdholland /*
6726165e63Sdholland * Get the name of the Install Kernel we are running under and
6826165e63Sdholland * enable the installation of the corresponding GENERIC kernel.
6926165e63Sdholland */
7026165e63Sdholland uname(&instsys);
71caeeae37Sjmcneill if (strstr(instsys.version, "(INSTALL32_IP3x"))
7226165e63Sdholland set_kernel_set(SET_KERNEL_2);
73caeeae37Sjmcneill else if (strstr(instsys.version, "(INSTALL32_IP2x"))
7426165e63Sdholland set_kernel_set(SET_KERNEL_1);
75caeeae37Sjmcneill else if (strstr(instsys.version, "(GENERIC32_IP12"))
7626165e63Sdholland set_kernel_set(SET_KERNEL_3);
7726165e63Sdholland }
7826165e63Sdholland
79dcc57e24Smartin bool
md_get_info(struct install_partition_desc * install)80dcc57e24Smartin md_get_info(struct install_partition_desc *install)
8126165e63Sdholland {
8226165e63Sdholland struct disklabel disklabel;
8326165e63Sdholland int fd;
8426165e63Sdholland char dev_name[100];
8526165e63Sdholland
86da5a563bSmartin snprintf(dev_name, 100, "/dev/r%s%c", pm->diskdev, 'a' + getrawpartition());
8726165e63Sdholland
8826165e63Sdholland fd = open(dev_name, O_RDONLY, 0);
8926165e63Sdholland if (fd < 0) {
9026165e63Sdholland if (logfp)
9126165e63Sdholland (void)fprintf(logfp, "Can't open %s\n", dev_name);
9226165e63Sdholland endwin();
9326165e63Sdholland fprintf(stderr, "Can't open %s\n", dev_name);
9426165e63Sdholland exit(1);
9526165e63Sdholland }
9626165e63Sdholland if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
9726165e63Sdholland if (logfp)
9826165e63Sdholland (void)fprintf(logfp, "Can't read disklabel on %s.\n",
9926165e63Sdholland dev_name);
10026165e63Sdholland endwin();
10126165e63Sdholland fprintf(stderr, "Can't read disklabel on %s.\n", dev_name);
10226165e63Sdholland close(fd);
10326165e63Sdholland exit(1);
10426165e63Sdholland }
10526165e63Sdholland close(fd);
10626165e63Sdholland
107da5a563bSmartin pm->dlcyl = disklabel.d_ncylinders;
108da5a563bSmartin pm->dlhead = disklabel.d_ntracks;
109da5a563bSmartin pm->dlsec = disklabel.d_nsectors;
110da5a563bSmartin pm->sectorsize = disklabel.d_secsize;
111da5a563bSmartin pm->dlcylsize = disklabel.d_secpercyl;
11226165e63Sdholland
11326165e63Sdholland /*
114da5a563bSmartin * Compute whole disk size. Take max of (pm->dlcyl*pm->dlhead*pm->dlsec)
11526165e63Sdholland * and secperunit, just in case the disk is already labelled.
11626165e63Sdholland * (If our new label's RAW_PART size ends up smaller than the
11726165e63Sdholland * in-core RAW_PART size value, updating the label will fail.)
11826165e63Sdholland */
119da5a563bSmartin pm->dlsize = pm->dlcyl*pm->dlhead*pm->dlsec;
120da5a563bSmartin if (disklabel.d_secperunit > pm->dlsize)
121da5a563bSmartin pm->dlsize = disklabel.d_secperunit;
12226165e63Sdholland
123dcc57e24Smartin return true;
12426165e63Sdholland }
12526165e63Sdholland
12626165e63Sdholland /*
12726165e63Sdholland * md back-end code for menu-driven BSD disklabel editor.
12826165e63Sdholland */
12980bf2417Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)130dcc57e24Smartin md_make_bsd_partitions(struct install_partition_desc *install)
13126165e63Sdholland {
132dcc57e24Smartin return make_bsd_partitions(install);
13326165e63Sdholland }
13426165e63Sdholland
13526165e63Sdholland /*
13626165e63Sdholland * any additional partition validation
13726165e63Sdholland */
138dcc57e24Smartin bool
md_check_partitions(struct install_partition_desc * install)139dcc57e24Smartin md_check_partitions(struct install_partition_desc *install)
14026165e63Sdholland {
141dcc57e24Smartin return true;
14226165e63Sdholland }
14326165e63Sdholland
14426165e63Sdholland /*
14526165e63Sdholland * hook called before writing new disklabel.
14626165e63Sdholland */
147dcc57e24Smartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)148dcc57e24Smartin md_pre_disklabel(struct install_partition_desc *install,
149dcc57e24Smartin struct disk_partitions *parts)
15026165e63Sdholland {
151dcc57e24Smartin return true;
15226165e63Sdholland }
15326165e63Sdholland
15426165e63Sdholland /*
15526165e63Sdholland * hook called after writing disklabel to new target disk.
15626165e63Sdholland */
157dcc57e24Smartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)158dcc57e24Smartin md_post_disklabel(struct install_partition_desc *install,
159dcc57e24Smartin struct disk_partitions *parts)
16026165e63Sdholland {
161f60f7522Smartin struct utsname instsys;
162f60f7522Smartin uname(&instsys);
163f60f7522Smartin
164caeeae37Sjmcneill if (strstr(instsys.version, "(INSTALL32_IP3x"))
16526165e63Sdholland return run_program(RUN_DISPLAY,
16626165e63Sdholland "%s %s", "/usr/mdec/sgivol -f -w boot /usr/mdec/ip3xboot",
167dcc57e24Smartin pm->diskdev) == 0;
16826165e63Sdholland
169caeeae37Sjmcneill if (strstr(instsys.version, "(INSTALL32_IP2x")) {
17026165e63Sdholland run_program(RUN_DISPLAY,
17126165e63Sdholland "%s %s", "/usr/mdec/sgivol -f -w aoutboot /usr/mdec/aoutboot",
172da5a563bSmartin pm->diskdev);
17326165e63Sdholland return run_program(RUN_DISPLAY,
17426165e63Sdholland "%s %s", "/usr/mdec/sgivol -f -w boot /usr/mdec/ip2xboot",
175dcc57e24Smartin pm->diskdev) == 0;
17626165e63Sdholland }
17726165e63Sdholland
17826165e63Sdholland /* Presumably an IP12, we add the boot code later... */
179dcc57e24Smartin return true;
18026165e63Sdholland }
18126165e63Sdholland
18226165e63Sdholland /*
18326165e63Sdholland * hook called after upgrade() or install() has finished setting
18426165e63Sdholland * up the target disk but immediately before the user is given the
18526165e63Sdholland * ``disks are now set up'' message.
18626165e63Sdholland */
18726165e63Sdholland int
md_post_newfs(struct install_partition_desc * install)188dcc57e24Smartin md_post_newfs(struct install_partition_desc *install)
18926165e63Sdholland {
19026165e63Sdholland return 0;
19126165e63Sdholland }
19226165e63Sdholland
19326165e63Sdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)194*b8b586ecSmartin md_post_extract(struct install_partition_desc *install, bool upgrade)
19526165e63Sdholland {
19626165e63Sdholland return 0;
19726165e63Sdholland }
19826165e63Sdholland
19926165e63Sdholland void
md_cleanup_install(struct install_partition_desc * install)200dcc57e24Smartin md_cleanup_install(struct install_partition_desc *install)
20126165e63Sdholland {
202f60f7522Smartin struct utsname instsys;
203f60f7522Smartin
20426165e63Sdholland #ifndef DEBUG
20526165e63Sdholland enable_rc_conf();
20626165e63Sdholland #endif
207f60f7522Smartin uname(&instsys);
20826165e63Sdholland
209caeeae37Sjmcneill if (strstr(instsys.version, "(GENERIC32_IP12"))
21026165e63Sdholland run_program(0, "/usr/mdec/sgivol -f -w netbsd %s %s",
211da5a563bSmartin target_expand("/netbsd.ecoff"), pm->diskdev);
21226165e63Sdholland }
21326165e63Sdholland
21426165e63Sdholland int
md_pre_update(struct install_partition_desc * install)215dcc57e24Smartin md_pre_update(struct install_partition_desc *install)
21626165e63Sdholland {
21726165e63Sdholland return 1;
21826165e63Sdholland }
21926165e63Sdholland
22026165e63Sdholland /* Upgrade support */
22126165e63Sdholland int
md_update(struct install_partition_desc * install)222dcc57e24Smartin md_update(struct install_partition_desc *install)
22326165e63Sdholland {
224dcc57e24Smartin md_post_disklabel(install, pm->parts);
22526165e63Sdholland return 1;
22626165e63Sdholland }
22726165e63Sdholland
22826165e63Sdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)229d5a9dfe9Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
23026165e63Sdholland {
23126165e63Sdholland return 0;
23226165e63Sdholland }
233dcc57e24Smartin
234dcc57e24Smartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)235dcc57e24Smartin md_parts_use_wholedisk(struct disk_partitions *parts)
236dcc57e24Smartin {
237dcc57e24Smartin return parts_use_wholedisk(parts, 0, NULL);
238dcc57e24Smartin }
239dcc57e24Smartin
240dcc57e24Smartin #ifdef HAVE_GPT
241dcc57e24Smartin 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)242dcc57e24Smartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
243dcc57e24Smartin bool root_is_new, part_id efi_id, bool efi_is_new)
244dcc57e24Smartin {
245dcc57e24Smartin /* no GPT boot support, nothing needs to be done here */
246dcc57e24Smartin return true;
247dcc57e24Smartin }
248dcc57e24Smartin #endif
249dcc57e24Smartin
250