1 /* $NetBSD: md.c,v 1.10 2022/01/29 16:01:20 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, res; 66 67 if (pm->no_mbr || pm->no_part) 68 return true; 69 70 again: 71 if (pm->parts == NULL) { 72 73 const struct disk_partitioning_scheme *ps = 74 select_part_scheme(pm, NULL, true, NULL); 75 76 if (!ps) 77 return false; 78 79 struct disk_partitions *parts = 80 (*ps->create_new_for_disk)(pm->diskdev, 81 0, pm->dlsize, true, NULL); 82 if (!parts) 83 return false; 84 85 pm->parts = parts; 86 if (ps->size_limit > 0 && pm->dlsize > ps->size_limit) 87 pm->dlsize = ps->size_limit; 88 } 89 90 msg_fmt_display(MSG_nobiosgeom, "%d%d%d", 91 pm->dlcyl, pm->dlhead, pm->dlsec); 92 93 if (guess_biosgeom_from_parts(pm->parts, &cyl, &head, &sec) >= 0 94 && pm->parts->pscheme->change_disk_geom != NULL) 95 pm->parts->pscheme->change_disk_geom(pm->parts, 96 cyl, head, sec); 97 else 98 set_default_sizemult(pm->diskdev, MEG, pm->sectorsize); 99 100 /* 101 * If the selected scheme does not need two-stage partitioning 102 * (like GPT), do not bother to edit the outer partitions. 103 */ 104 if (pm->parts->pscheme->secondary_partitions == NULL || 105 pm->parts->pscheme->secondary_scheme == NULL) 106 return true; 107 108 if (pm->no_mbr || pm->no_part) 109 return true; 110 111 res = edit_outer_parts(pm->parts); 112 if (res == 0) 113 return false; 114 else if (res == 1) 115 return true; 116 117 pm->parts->pscheme->destroy_part_scheme(pm->parts); 118 pm->parts = NULL; 119 goto again; 120 } 121 122 /* 123 * md back-end code for menu-driven BSD disklabel editor. 124 */ 125 int 126 md_make_bsd_partitions(struct install_partition_desc *install) 127 { 128 return make_bsd_partitions(install); 129 } 130 131 /* 132 * any additional partition validation 133 */ 134 bool 135 md_check_partitions(struct install_partition_desc *install) 136 { 137 return 1; 138 } 139 140 /* 141 * hook called before writing new disklabel. 142 */ 143 bool 144 md_pre_disklabel(struct install_partition_desc *install, 145 struct disk_partitions *parts) 146 { 147 148 if (parts->parent == NULL) 149 return true; /* no outer partitions */ 150 151 parts = parts->parent; 152 153 msg_display_subst(MSG_dofdisk, 3, parts->disk, 154 msg_string(parts->pscheme->name), 155 msg_string(parts->pscheme->short_name)); 156 157 /* write edited "MBR" onto disk. */ 158 if (!parts->pscheme->write_to_disk(parts)) { 159 msg_display(MSG_wmbrfail); 160 process_menu(MENU_ok, NULL); 161 return false; 162 } 163 return true; 164 } 165 166 /* 167 * hook called after writing disklabel to new target disk. 168 */ 169 bool 170 md_post_disklabel(struct install_partition_desc *install, 171 struct disk_partitions *parts) 172 { 173 return true; 174 } 175 176 /* 177 * hook called after upgrade() or install() has finished setting 178 * up the target disk but immediately before the user is given the 179 * ``disks are now set up'' message. 180 */ 181 int 182 md_post_newfs(struct install_partition_desc *install) 183 { 184 return 0; 185 } 186 187 int 188 md_post_extract(struct install_partition_desc *install, bool upgrade) 189 { 190 return 0; 191 } 192 193 void 194 md_cleanup_install(struct install_partition_desc *install) 195 { 196 #ifndef DEBUG 197 enable_rc_conf(); 198 #endif 199 } 200 201 int 202 md_pre_update(struct install_partition_desc *install) 203 { 204 return 1; 205 } 206 207 /* Upgrade support */ 208 int 209 md_update(struct install_partition_desc *install) 210 { 211 md_post_newfs(install); 212 return 1; 213 } 214 215 int 216 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet) 217 { 218 return 2; 219 } 220 221 bool 222 md_parts_use_wholedisk(struct disk_partitions *parts) 223 { 224 return parts_use_wholedisk(parts, 0, NULL); 225 } 226 227 int 228 md_pre_mount(struct install_partition_desc *install, size_t ndx) 229 { 230 return 0; 231 } 232 233 bool 234 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri) 235 { 236 return false; /* no change, no need to write back */ 237 } 238 239 #ifdef HAVE_GPT 240 bool 241 md_gpt_post_write(struct disk_partitions *parts, part_id root_id, 242 bool root_is_new, part_id efi_id, bool efi_is_new) 243 { 244 /* no GPT boot support, nothing needs to be done here */ 245 return true; 246 } 247 #endif 248 249