Home | History | Annotate | Line # | Download | only in sgimips
md.c revision 1.6
      1 /*	$NetBSD: md.c,v 1.6 2018/09/17 15:19:29 tsutsui 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 -- sgimips 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 <sys/utsname.h>
     42 #include <stdio.h>
     43 #include <curses.h>
     44 #include <unistd.h>
     45 #include <fcntl.h>
     46 #include <util.h>
     47 #include <errno.h>
     48 
     49 #include "defs.h"
     50 #include "md.h"
     51 #include "msg_defs.h"
     52 #include "menu_defs.h"
     53 
     54 
     55 void
     56 md_init(void)
     57 {
     58 }
     59 
     60 void
     61 md_init_set_status(int flags)
     62 {
     63 	struct utsname instsys;
     64 
     65 	(void)flags;
     66 
     67         /*
     68          * Get the name of the Install Kernel we are running under and
     69          * enable the installation of the corresponding GENERIC kernel.
     70          */
     71 	uname(&instsys);
     72         if (strstr(instsys.version, "(INSTALL32_IP3x"))
     73                 set_kernel_set(SET_KERNEL_2);
     74         else if (strstr(instsys.version, "(INSTALL32_IP2x"))
     75                 set_kernel_set(SET_KERNEL_1);
     76 	else if (strstr(instsys.version, "(GENERIC32_IP12"))
     77 		set_kernel_set(SET_KERNEL_3);
     78 }
     79 
     80 int
     81 md_get_info(void)
     82 {
     83 	struct disklabel disklabel;
     84 	int fd;
     85 	char dev_name[100];
     86 
     87 	snprintf(dev_name, 100, "/dev/r%s%c", pm->diskdev, 'a' + getrawpartition());
     88 
     89 	fd = open(dev_name, O_RDONLY, 0);
     90 	if (fd < 0) {
     91 		if (logfp)
     92 			(void)fprintf(logfp, "Can't open %s\n", dev_name);
     93 		endwin();
     94 		fprintf(stderr, "Can't open %s\n", dev_name);
     95 		exit(1);
     96 	}
     97 	if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
     98 		if (logfp)
     99 			(void)fprintf(logfp, "Can't read disklabel on %s.\n",
    100 				dev_name);
    101 		endwin();
    102 		fprintf(stderr, "Can't read disklabel on %s.\n", dev_name);
    103 		close(fd);
    104 		exit(1);
    105 	}
    106 	close(fd);
    107 
    108 	pm->dlcyl = disklabel.d_ncylinders;
    109 	pm->dlhead = disklabel.d_ntracks;
    110 	pm->dlsec = disklabel.d_nsectors;
    111 	pm->sectorsize = disklabel.d_secsize;
    112 	pm->dlcylsize = disklabel.d_secpercyl;
    113 
    114 	/*
    115 	 * Compute whole disk size. Take max of (pm->dlcyl*pm->dlhead*pm->dlsec)
    116 	 * and secperunit,  just in case the disk is already labelled.
    117 	 * (If our new label's RAW_PART size ends up smaller than the
    118 	 * in-core RAW_PART size  value, updating the label will fail.)
    119 	 */
    120 	pm->dlsize = pm->dlcyl*pm->dlhead*pm->dlsec;
    121 	if (disklabel.d_secperunit > pm->dlsize)
    122 		pm->dlsize = disklabel.d_secperunit;
    123 
    124 	return 1;
    125 }
    126 
    127 /*
    128  * md back-end code for menu-driven BSD disklabel editor.
    129  */
    130 int
    131 md_make_bsd_partitions(void)
    132 {
    133 	return make_bsd_partitions();
    134 }
    135 
    136 /*
    137  * any additional partition validation
    138  */
    139 int
    140 md_check_partitions(void)
    141 {
    142 	return 1;
    143 }
    144 
    145 /*
    146  * hook called before writing new disklabel.
    147  */
    148 int
    149 md_pre_disklabel(void)
    150 {
    151 	return 0;
    152 }
    153 
    154 /*
    155  * hook called after writing disklabel to new target disk.
    156  */
    157 int
    158 md_post_disklabel(void)
    159 {
    160 	struct utsname instsys;
    161 	uname(&instsys);
    162 
    163 	if (strstr(instsys.version, "(INSTALL32_IP3x"))
    164 		return run_program(RUN_DISPLAY,
    165 		    "%s %s", "/usr/mdec/sgivol -f -w boot /usr/mdec/ip3xboot",
    166 		    pm->diskdev);
    167 
    168 	if (strstr(instsys.version, "(INSTALL32_IP2x")) {
    169 		run_program(RUN_DISPLAY,
    170 		  "%s %s", "/usr/mdec/sgivol -f -w aoutboot /usr/mdec/aoutboot",
    171 		  pm->diskdev);
    172 		return run_program(RUN_DISPLAY,
    173 		  "%s %s", "/usr/mdec/sgivol -f -w boot /usr/mdec/ip2xboot",
    174 		  pm->diskdev);
    175 	}
    176 
    177 	/* Presumably an IP12, we add the boot code later... */
    178 	return 0;
    179 }
    180 
    181 /*
    182  * hook called after upgrade() or install() has finished setting
    183  * up the target disk but immediately before the user is given the
    184  * ``disks are now set up'' message.
    185  */
    186 int
    187 md_post_newfs(void)
    188 {
    189 	return 0;
    190 }
    191 
    192 int
    193 md_post_extract(void)
    194 {
    195 	return 0;
    196 }
    197 
    198 void
    199 md_cleanup_install(void)
    200 {
    201 	struct utsname instsys;
    202 
    203 #ifndef DEBUG
    204 	enable_rc_conf();
    205 #endif
    206 	uname(&instsys);
    207 
    208 	if (strstr(instsys.version, "(GENERIC32_IP12"))
    209 		run_program(0, "/usr/mdec/sgivol -f -w netbsd %s %s",
    210 			    target_expand("/netbsd.ecoff"), pm->diskdev);
    211 }
    212 
    213 int
    214 md_pre_update(void)
    215 {
    216 	return 1;
    217 }
    218 
    219 /* Upgrade support */
    220 int
    221 md_update(void)
    222 {
    223 	md_post_disklabel();
    224 	return 1;
    225 }
    226 
    227 int
    228 md_pre_mount()
    229 {
    230 	return 0;
    231 }
    232