Home | History | Annotate | Line # | Download | only in hpcmips
md.c revision 1.6
      1 /*	$NetBSD: md.c,v 1.6 2019/08/14 12:55:36 martin 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 -- hpcmips machine specific routines */
     36 
     37 #include <stdio.h>
     38 #include <util.h>
     39 #include <sys/param.h>
     40 #include <machine/cpu.h>
     41 #include <sys/sysctl.h>
     42 
     43 #include "defs.h"
     44 #include "md.h"
     45 #include "msg_defs.h"
     46 #include "menu_defs.h"
     47 #include "endian.h"
     48 #include "mbr.h"
     49 
     50 void
     51 md_init(void)
     52 {
     53 }
     54 
     55 void
     56 md_init_set_status(int flags)
     57 {
     58 	(void)flags;
     59 }
     60 
     61 bool
     62 md_get_info(struct install_partition_desc *install)
     63 {
     64 
     65 	if (pm->no_mbr || pm->no_part)
     66 		return true;
     67 
     68 	if (pm->parts == NULL) {
     69 
     70 		const struct disk_partitioning_scheme *ps =
     71 		    select_part_scheme(pm, NULL, true, NULL);
     72 
     73 		if (!ps)
     74 			return false;
     75 
     76 		struct disk_partitions *parts =
     77 		   (*ps->create_new_for_disk)(pm->diskdev,
     78 		   0, pm->dlsize, pm->dlsize, true);
     79 		if (!parts)
     80 			return false;
     81 
     82 		pm->parts = parts;
     83 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
     84 			pm->dlsize = ps->size_limit;
     85 	}
     86 
     87 	return set_bios_geom_with_mbr_guess(pm->parts);
     88 }
     89 
     90 /*
     91  * md back-end code for menu-driven BSD disklabel editor.
     92  */
     93 bool
     94 md_make_bsd_partitions(struct install_partition_desc *install)
     95 {
     96 	return make_bsd_partitions(install);
     97 }
     98 
     99 /*
    100  * any additional partition validation
    101  */
    102 bool
    103 md_check_partitions(struct install_partition_desc *install)
    104 {
    105 	return true;
    106 }
    107 
    108 /*
    109  * hook called before writing new disklabel.
    110  */
    111 bool
    112 md_pre_disklabel(struct install_partition_desc *install,
    113     struct disk_partitions *parts)
    114 {
    115 
    116 	if (parts->parent == NULL)
    117 		return true;	/* no outer partitions */
    118 
    119 	parts = parts->parent;
    120 
    121 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
    122 	    msg_string(parts->pscheme->name),
    123 	    msg_string(parts->pscheme->short_name));
    124 
    125 	/* write edited "MBR" onto disk. */
    126 	if (!parts->pscheme->write_to_disk(parts)) {
    127 		msg_display(MSG_wmbrfail);
    128 		process_menu(MENU_ok, NULL);
    129 		return false;
    130 	}
    131 	return true;
    132 }
    133 
    134 /*
    135  * hook called after writing disklabel to new target disk.
    136  */
    137 bool
    138 md_post_disklabel(struct install_partition_desc *install,
    139     struct disk_partitions *parts)
    140 {
    141 #if 0	/* XXX - when did bad144 get removed and this code not? */
    142 	/* Sector forwarding / badblocks ... */
    143 	if (*pm->doessf) {
    144 		msg_display(MSG_dobad144);
    145 		return run_program(RUN_DISPLAY, "/usr/sbin/bad144 %s 0",
    146 		    pm->diskdev) == 0;
    147 	}
    148 #endif
    149 	return true;
    150 }
    151 
    152 /*
    153  * hook called after upgrade() or install() has finished setting
    154  * up the target disk but immediately before the user is given the
    155  * ``disks are now set up'' message.
    156  */
    157 int
    158 md_post_newfs(struct install_partition_desc *install)
    159 {
    160 	return 0;
    161 }
    162 
    163 void
    164 md_cleanup_install(struct install_partition_desc *install)
    165 {
    166 #ifndef DEBUG
    167 	enable_rc_conf();
    168 #endif
    169 }
    170 
    171 int
    172 md_pre_update(struct install_partition_desc *install)
    173 {
    174 	return 1;
    175 }
    176 
    177 /* Upgrade support */
    178 int
    179 md_update(struct install_partition_desc *install)
    180 {
    181 	md_post_newfs(install);
    182 	return 1;
    183 }
    184 
    185 int
    186 md_post_extract(struct install_partition_desc *install)
    187 {
    188 	return 0;
    189 }
    190 
    191 int
    192 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
    193 {
    194 	return 2;
    195 }
    196 
    197 bool
    198 md_parts_use_wholedisk(struct disk_partitions *parts)
    199 {
    200 	return parts_use_wholedisk(parts, 0, NULL);
    201 }
    202 
    203 int
    204 md_pre_mount(struct install_partition_desc *install, size_t ndx)
    205 {
    206 	return 0;
    207 }
    208 
    209 /* returns false if no write-back of parts is required */
    210 bool
    211 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
    212 {
    213 	return false;
    214 }
    215 
    216 #ifdef HAVE_GPT
    217 /*
    218  * New GPT partitions have been written, update bootloader or remember
    219  * data untill needed in md_post_newfs
    220  */
    221 bool
    222 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
    223     bool root_is_new, part_id efi_id, bool efi_is_new)
    224 {
    225 	return true;
    226 }
    227 #endif
    228 
    229