Home | History | Annotate | Line # | Download | only in landisk
md.c revision 1.4
      1 /*	$NetBSD: md.c,v 1.4 2018/05/18 12:23:22 joerg Exp $	*/
      2 
      3 /*
      4  * Copyright 1997,2002 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 -- landisk machine specific routines */
     36 
     37 #include <sys/param.h>
     38 #include <sys/sysctl.h>
     39 #include <stdio.h>
     40 #include <util.h>
     41 
     42 #include "defs.h"
     43 #include "md.h"
     44 #include "msg_defs.h"
     45 #include "menu_defs.h"
     46 
     47 void
     48 md_init(void)
     49 {
     50 }
     51 
     52 void
     53 md_init_set_status(int flags)
     54 {
     55 	(void)flags;
     56 }
     57 
     58 int
     59 md_get_info(void)
     60 {
     61 	return set_bios_geom_with_mbr_guess();
     62 }
     63 
     64 /*
     65  * md back-end code for menu-driven BSD disklabel editor.
     66  */
     67 int
     68 md_make_bsd_partitions(void)
     69 {
     70 	return make_bsd_partitions();
     71 }
     72 
     73 /*
     74  * any additional partition validation
     75  */
     76 int
     77 md_check_partitions(void)
     78 {
     79 	return 1;
     80 }
     81 
     82 /*
     83  * hook called before writing new disklabel.
     84  */
     85 int
     86 md_pre_disklabel(void)
     87 {
     88 	if (pm->no_mbr)
     89 		return 0;
     90 
     91 	msg_display(MSG_dofdisk);
     92 
     93 	/* write edited MBR onto disk. */
     94 	if (write_mbr(pm->diskdev, &mbr, 1) != 0 ||
     95 	    run_program(RUN_SILENT | RUN_ERROR_OK,
     96 	    "/sbin/fdisk -f -i -c /usr/mdec/mbr %s", pm->diskdev)) {
     97 		msg_display(MSG_wmbrfail);
     98 		process_menu(MENU_ok, NULL);
     99 		return 1;
    100 	}
    101 
    102 	return 0;
    103 }
    104 
    105 /*
    106  * hook called after writing disklabel to new target disk.
    107  */
    108 int
    109 md_post_disklabel(void)
    110 {
    111 	return 0;
    112 }
    113 
    114 /*
    115  * hook called after upgrade() or install() has finished setting
    116  * up the target disk but immediately before the user is given the
    117  * ``disks are now set up'' message.
    118  *
    119  * On the landisk, we use this opportunity to install the boot blocks.
    120  */
    121 int
    122 md_post_newfs(void)
    123 {
    124 	char *bootxx;
    125 	int error;
    126 
    127 	msg_display(MSG_dobootblks, pm->diskdev);
    128 	cp_to_target("/usr/mdec/boot", "/boot");
    129 	bootxx = bootxx_name();
    130 	if (bootxx != NULL) {
    131 		error = run_program(RUN_DISPLAY,
    132 		    "/usr/sbin/installboot -v /dev/r%sa %s", pm->diskdev, bootxx);
    133 		free(bootxx);
    134 	} else
    135 		error = -1;
    136 
    137 	if (error != 0)
    138 		process_menu(MENU_ok,
    139 		    __UNCONST("Warning: disk is probably not bootable"));
    140 
    141 	return 0;
    142 }
    143 
    144 int
    145 md_post_extract(void)
    146 {
    147 	return 0;
    148 }
    149 
    150 void
    151 md_cleanup_install(void)
    152 {
    153 #ifndef DEBUG
    154 	enable_rc_conf();
    155 #endif
    156 }
    157 
    158 int
    159 md_pre_update(void)
    160 {
    161 	return 1;
    162 }
    163 
    164 /* Upgrade support */
    165 int
    166 md_update(void)
    167 {
    168 	md_post_newfs();
    169 	return 1;
    170 }
    171 
    172 int
    173 md_check_mbr(mbr_info_t *mbri)
    174 {
    175 	return 2;
    176 }
    177 
    178 int
    179 md_mbr_use_wholedisk(mbr_info_t *mbri)
    180 {
    181 	return mbr_use_wholedisk(mbri);
    182 }
    183 
    184 
    185 int
    186 md_pre_mount()
    187 {
    188 	return 0;
    189 }
    190