1/* $NetBSD: md.c,v 1.14 2012/01/09 11:51:41 skrll 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 -- hp700 machine specific routines */ 36/* This file is in close sync with pmax, vax, and x68k, sparc md.c */ 37 38#include <sys/types.h> 39#include <sys/disklabel.h> 40#include <sys/ioctl.h> 41#include <sys/param.h> 42#include <stdio.h> 43#include <curses.h> 44#include <unistd.h> 45#include <fcntl.h> 46#include <util.h> 47 48#include "defs.h" 49#include "md.h" 50#include "msg_defs.h" 51#include "menu_defs.h" 52 53#define HP700_PDC_LIMIT ((unsigned)2*1024*1024*1024) 54 55void 56md_init(void) 57{ 58} 59 60void 61md_init_set_status(int flags) 62{ 63 (void)flags; 64} 65 66int 67md_get_info(void) 68{ 69 struct disklabel disklabel; 70 int fd; 71 char dev_name[100]; 72 73 snprintf(dev_name, 100, "/dev/r%sc", diskdev); 74 75 fd = open(dev_name, O_RDONLY, 0); 76 if (fd < 0) { 77 if (logfp) 78 (void)fprintf(logfp, "Can't open %s\n", dev_name); 79 endwin(); 80 fprintf(stderr, "Can't open %s\n", dev_name); 81 exit(1); 82 } 83 if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) { 84 if (logfp) 85 (void)fprintf(logfp, "Can't read disklabel on %s.\n", 86 dev_name); 87 endwin(); 88 fprintf(stderr, "Can't read disklabel on %s.\n", dev_name); 89 close(fd); 90 exit(1); 91 } 92 close(fd); 93 94 dlcyl = disklabel.d_ncylinders; 95 dlhead = disklabel.d_ntracks; 96 dlsec = disklabel.d_nsectors; 97 sectorsize = disklabel.d_secsize; 98 dlcylsize = disklabel.d_secpercyl; 99 100 /* 101 * Compute whole disk size. Take max of (dlcyl*dlhead*dlsec) 102 * and secperunit, just in case the disk is already labelled. 103 * (If our new label's RAW_PART size ends up smaller than the 104 * in-core RAW_PART size value, updating the label will fail.) 105 */ 106 dlsize = dlcyl*dlhead*dlsec; 107 if (disklabel.d_secperunit > dlsize) 108 dlsize = disklabel.d_secperunit; 109 110 /* 111 * hp700 PDC can only address up to 2GB. 112 */ 113 root_limit = HP700_PDC_LIMIT / (unsigned)sectorsize; 114 115 return 1; 116} 117 118/* 119 * md back-end code for menu-driven BSD disklabel editor. 120 */ 121int 122md_make_bsd_partitions(void) 123{ 124 return make_bsd_partitions(); 125} 126 127/* 128 * any additional partition validation 129 */ 130int 131md_check_partitions(void) 132{ 133 /* Check the root partition is sane. */ 134 uint32_t limit = HP700_PDC_LIMIT / (unsigned)sectorsize; 135 int part; 136 137 for (part = PART_A; part < MAXPARTITIONS; part++) { 138 if (strcmp(bsdlabel[part].pi_mount, "/") == 0) { 139 uint32_t offset = bsdlabel[part].pi_offset; 140 uint32_t size = bsdlabel[part].pi_size; 141 142 if (offset > limit || offset + size > limit) { 143 msg_display(MSG_md_pdclimit); 144 process_menu(MENU_ok, NULL); 145 return 0; 146 } 147 } 148 } 149 150 return 1; 151} 152 153/* 154 * hook called before writing new disklabel. 155 */ 156int 157md_pre_disklabel(void) 158{ 159 return 0; 160} 161 162/* 163 * hook called after writing disklabel to new target disk. 164 */ 165int 166md_post_disklabel(void) 167{ 168 return 0; 169} 170 171/* 172 * hook called after upgrade() or install() has finished setting 173 * up the target disk but immediately before the user is given the 174 * ``disks are now set up'' message. 175 */ 176int 177md_post_newfs(void) 178{ 179 int error; 180 181 error = cp_to_target("/usr/mdec/boot", "/boot"); 182 if (error) 183 return error; 184 185 /* boot blocks ... */ 186 msg_display(MSG_dobootblks, diskdev); 187 if (run_program(RUN_DISPLAY | RUN_NO_CLEAR, 188 "/usr/sbin/installboot -v /dev/r%sc /usr/mdec/xxboot", 189 diskdev)) 190 process_menu(MENU_ok, 191 deconst("Warning: disk is probably not bootable")); 192 return 0; 193} 194 195int 196md_post_extract(void) 197{ 198 return 0; 199} 200 201void 202md_cleanup_install(void) 203{ 204#ifndef DEBUG 205 enable_rc_conf(); 206#endif 207} 208 209int 210md_pre_update(void) 211{ 212 return 1; 213} 214 215/* Upgrade support */ 216int 217md_update(void) 218{ 219 md_post_newfs(); 220 return 1; 221} 222 223int 224md_pre_mount() 225{ 226 return 0; 227} 228