1 /* $NetBSD: md.c,v 1.8 2020/01/27 21:21:23 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. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed for the NetBSD Project by 21 * Piermont Information Systems Inc. 22 * 4. The name of Piermont Information Systems Inc. may not be used to endorse 23 * or promote products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS'' 27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE 30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 * THE POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* md.c -- playstation2 machine specific routines */ 40 41 #include <stdio.h> 42 #include <util.h> 43 #include <sys/param.h> 44 #include <sys/sysctl.h> 45 46 #include "defs.h" 47 #include "md.h" 48 #include "msg_defs.h" 49 #include "menu_defs.h" 50 51 void 52 md_init(void) 53 { 54 } 55 56 void 57 md_init_set_status(int minimal) 58 { 59 (void)minimal; 60 } 61 62 bool 63 md_get_info(struct install_partition_desc *install) 64 { 65 int cyl, head, sec; 66 67 if (pm->no_mbr || pm->no_part) 68 return true; 69 70 if (pm->parts == NULL) { 71 72 const struct disk_partitioning_scheme *ps = 73 select_part_scheme(pm, NULL, true, NULL); 74 75 if (!ps) 76 return false; 77 78 struct disk_partitions *parts = 79 (*ps->create_new_for_disk)(pm->diskdev, 80 0, pm->dlsize, true, NULL); 81 if (!parts) 82 return false; 83 84 pm->parts = parts; 85 if (ps->size_limit > 0 && pm->dlsize > ps->size_limit) 86 pm->dlsize = ps->size_limit; 87 } 88 89 msg_fmt_display(MSG_nobiosgeom, "%d%d%d", 90 pm->dlcyl, pm->dlhead, pm->dlsec); 91 92 if (guess_biosgeom_from_parts(pm->parts, &cyl, &head, &sec) >= 0 93 && pm->parts->pscheme->change_disk_geom != NULL) 94 pm->parts->pscheme->change_disk_geom(pm->parts, 95 cyl, head, sec); 96 else 97 set_default_sizemult(pm->diskdev, MEG, pm->sectorsize); 98 99 /* 100 * If the selected scheme does not need two-stage partitioning 101 * (like GPT), do not bother to edit the outer partitions. 102 */ 103 if (pm->parts->pscheme->secondary_partitions == NULL || 104 pm->parts->pscheme->secondary_scheme == NULL) 105 return true; 106 107 if (pm->no_mbr || pm->no_part) 108 return true; 109 110 return edit_outer_parts(pm->parts); 111 } 112 113 /* 114 * md back-end code for menu-driven BSD disklabel editor. 115 */ 116 bool 117 md_make_bsd_partitions(struct install_partition_desc *install) 118 { 119 return make_bsd_partitions(install); 120 } 121 122 /* 123 * any additional partition validation 124 */ 125 bool 126 md_check_partitions(struct install_partition_desc *install) 127 { 128 return 1; 129 } 130 131 /* 132 * hook called before writing new disklabel. 133 */ 134 bool 135 md_pre_disklabel(struct install_partition_desc *install, 136 struct disk_partitions *parts) 137 { 138 139 if (parts->parent == NULL) 140 return true; /* no outer partitions */ 141 142 parts = parts->parent; 143 144 msg_display_subst(MSG_dofdisk, 3, parts->disk, 145 msg_string(parts->pscheme->name), 146 msg_string(parts->pscheme->short_name)); 147 148 /* write edited "MBR" onto disk. */ 149 if (!parts->pscheme->write_to_disk(parts)) { 150 msg_display(MSG_wmbrfail); 151 process_menu(MENU_ok, NULL); 152 return false; 153 } 154 return true; 155 } 156 157 /* 158 * hook called after writing disklabel to new target disk. 159 */ 160 bool 161 md_post_disklabel(struct install_partition_desc *install, 162 struct disk_partitions *parts) 163 { 164 return true; 165 } 166 167 /* 168 * hook called after upgrade() or install() has finished setting 169 * up the target disk but immediately before the user is given the 170 * ``disks are now set up'' message. 171 */ 172 int 173 md_post_newfs(struct install_partition_desc *install) 174 { 175 return 0; 176 } 177 178 int 179 md_post_extract(struct install_partition_desc *install) 180 { 181 return 0; 182 } 183 184 void 185 md_cleanup_install(struct install_partition_desc *install) 186 { 187 #ifndef DEBUG 188 enable_rc_conf(); 189 #endif 190 } 191 192 int 193 md_pre_update(struct install_partition_desc *install) 194 { 195 return 1; 196 } 197 198 /* Upgrade support */ 199 int 200 md_update(struct install_partition_desc *install) 201 { 202 md_post_newfs(install); 203 return 1; 204 } 205 206 int 207 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet) 208 { 209 return 2; 210 } 211 212 bool 213 md_parts_use_wholedisk(struct disk_partitions *parts) 214 { 215 return parts_use_wholedisk(parts, 0, NULL); 216 } 217 218 int 219 md_pre_mount(struct install_partition_desc *install, size_t ndx) 220 { 221 return 0; 222 } 223 224 bool 225 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri) 226 { 227 return false; /* no change, no need to write back */ 228 } 229 230 #ifdef HAVE_GPT 231 bool 232 md_gpt_post_write(struct disk_partitions *parts, part_id root_id, 233 bool root_is_new, part_id efi_id, bool efi_is_new) 234 { 235 /* no GPT boot support, nothing needs to be done here */ 236 return true; 237 } 238 #endif 239 240