1 /* $NetBSD: md.c,v 1.6 2019/08/14 12:55:35 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 -- bebox 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 bool 59 md_get_info(struct install_partition_desc *install) 60 { 61 62 if (pm->no_mbr || pm->no_part) 63 return true; 64 65 if (pm->parts == NULL) { 66 67 const struct disk_partitioning_scheme *ps = 68 select_part_scheme(pm, NULL, true, NULL); 69 70 if (!ps) 71 return false; 72 73 struct disk_partitions *parts = 74 (*ps->create_new_for_disk)(pm->diskdev, 75 0, pm->dlsize, pm->dlsize, true); 76 if (!parts) 77 return false; 78 79 pm->parts = parts; 80 if (ps->size_limit > 0 && pm->dlsize > ps->size_limit) 81 pm->dlsize = ps->size_limit; 82 } 83 84 return set_bios_geom_with_mbr_guess(pm->parts); 85 } 86 87 /* 88 * md back-end code for menu-driven BSD disklabel editor. 89 */ 90 bool 91 md_make_bsd_partitions(struct install_partition_desc *install) 92 { 93 return make_bsd_partitions(install); 94 } 95 96 /* 97 * any additional partition validation 98 */ 99 bool 100 md_check_partitions(struct install_partition_desc *install) 101 { 102 return true; 103 } 104 105 /* 106 * hook called before writing new disklabel. 107 */ 108 bool 109 md_pre_disklabel(struct install_partition_desc *install, 110 struct disk_partitions *parts) 111 { 112 113 if (parts->parent == NULL) 114 return true; /* no outer partitions */ 115 116 parts = parts->parent; 117 118 msg_display_subst(MSG_dofdisk, 3, parts->disk, 119 msg_string(parts->pscheme->name), 120 msg_string(parts->pscheme->short_name)); 121 122 /* write edited "MBR" onto disk. */ 123 if (!parts->pscheme->write_to_disk(parts)) { 124 msg_display(MSG_wmbrfail); 125 process_menu(MENU_ok, NULL); 126 return false; 127 } 128 return true; 129 } 130 131 /* 132 * hook called after writing disklabel to new target disk. 133 */ 134 bool 135 md_post_disklabel(struct install_partition_desc *install, 136 struct disk_partitions *parts) 137 { 138 return true; 139 } 140 141 /* 142 * hook called after upgrade() or install() has finished setting 143 * up the target disk but immediately before the user is given the 144 * ``disks are now set up'' message. 145 */ 146 int 147 md_post_newfs(struct install_partition_desc *install) 148 { 149 return 0; 150 } 151 152 int 153 md_post_extract(struct install_partition_desc *install) 154 { 155 return 0; 156 } 157 158 void 159 md_cleanup_install(struct install_partition_desc *install) 160 { 161 #ifndef DEBUG 162 enable_rc_conf(); 163 #endif 164 } 165 166 int 167 md_pre_update(struct install_partition_desc *install) 168 { 169 return 1; 170 } 171 172 /* Upgrade support */ 173 int 174 md_update(struct install_partition_desc *install) 175 { 176 md_post_newfs(install); 177 return 1; 178 } 179 180 int 181 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet) 182 { 183 return 2; 184 } 185 186 bool 187 md_parts_use_wholedisk(struct disk_partitions *parts) 188 { 189 return parts_use_wholedisk(parts, 0, NULL); 190 } 191 192 int 193 md_pre_mount(struct install_partition_desc *install, size_t ndx) 194 { 195 return 0; 196 } 197 198 /* returns false if no write-back of parts is required */ 199 bool 200 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri) 201 { 202 return false; 203 } 204 205 #ifdef HAVE_GPT 206 /* 207 * New GPT partitions have been written, update bootloader or remember 208 * data untill needed in md_post_newfs 209 */ 210 bool 211 md_gpt_post_write(struct disk_partitions *parts, part_id root_id, 212 bool root_is_new, part_id efi_id, bool efi_is_new) 213 { 214 return true; 215 } 216 #endif 217 218