1*99162e57Smartin /* $NetBSD: md.c,v 1.10 2022/12/09 17:02:13 martin Exp $ */
250dbef1aSdholland
350dbef1aSdholland /*
450dbef1aSdholland * Copyright 1997 Piermont Information Systems Inc.
550dbef1aSdholland * All rights reserved.
650dbef1aSdholland *
750dbef1aSdholland * Based on code written by Philip A. Nelson for Piermont Information
850dbef1aSdholland * Systems Inc.
950dbef1aSdholland *
1050dbef1aSdholland * Redistribution and use in source and binary forms, with or without
1150dbef1aSdholland * modification, are permitted provided that the following conditions
1250dbef1aSdholland * are met:
1350dbef1aSdholland * 1. Redistributions of source code must retain the above copyright
1450dbef1aSdholland * notice, this list of conditions and the following disclaimer.
1550dbef1aSdholland * 2. Redistributions in binary form must reproduce the above copyright
1650dbef1aSdholland * notice, this list of conditions and the following disclaimer in the
1750dbef1aSdholland * documentation and/or other materials provided with the distribution.
1850dbef1aSdholland * 3. The name of Piermont Information Systems Inc. may not be used to endorse
1950dbef1aSdholland * or promote products derived from this software without specific prior
2050dbef1aSdholland * written permission.
2150dbef1aSdholland *
2250dbef1aSdholland * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
2350dbef1aSdholland * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2450dbef1aSdholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2550dbef1aSdholland * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
2650dbef1aSdholland * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2750dbef1aSdholland * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2850dbef1aSdholland * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2950dbef1aSdholland * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3050dbef1aSdholland * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3150dbef1aSdholland * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3250dbef1aSdholland * THE POSSIBILITY OF SUCH DAMAGE.
3350dbef1aSdholland */
3450dbef1aSdholland
3550dbef1aSdholland /* md.c -- amiga machine specific routines */
3650dbef1aSdholland
3750dbef1aSdholland #include <stdio.h>
3850dbef1aSdholland #include <util.h>
3950dbef1aSdholland #include <sys/param.h>
4050dbef1aSdholland #include <machine/cpu.h>
4150dbef1aSdholland #include <sys/sysctl.h>
4250dbef1aSdholland
4350dbef1aSdholland #include "defs.h"
4450dbef1aSdholland #include "md.h"
4550dbef1aSdholland #include "msg_defs.h"
4650dbef1aSdholland #include "menu_defs.h"
4750dbef1aSdholland
4850dbef1aSdholland void
md_init(void)4950dbef1aSdholland md_init(void)
5050dbef1aSdholland {
5150dbef1aSdholland }
5250dbef1aSdholland
5350dbef1aSdholland void
md_init_set_status(int flags)5450dbef1aSdholland md_init_set_status(int flags)
5550dbef1aSdholland {
5650dbef1aSdholland (void)flags;
5750dbef1aSdholland }
5850dbef1aSdholland
594103857bSmartin bool
md_get_info(struct install_partition_desc * install)604103857bSmartin md_get_info(struct install_partition_desc *install)
6150dbef1aSdholland {
62*99162e57Smartin set_default_sizemult(pm->diskdev, MEG, pm->sectorsize);
634103857bSmartin return true;
6450dbef1aSdholland }
6550dbef1aSdholland
6650dbef1aSdholland /*
6750dbef1aSdholland * md back-end code for menu-driven BSD disklabel editor.
6850dbef1aSdholland */
69957b5cd6Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)704103857bSmartin md_make_bsd_partitions(struct install_partition_desc *install)
7150dbef1aSdholland {
7250dbef1aSdholland return 1;
7350dbef1aSdholland }
7450dbef1aSdholland
7550dbef1aSdholland /*
7650dbef1aSdholland * any additional partition validation
7750dbef1aSdholland */
784103857bSmartin bool
md_check_partitions(struct install_partition_desc * install)794103857bSmartin md_check_partitions(struct install_partition_desc *install)
8050dbef1aSdholland {
814103857bSmartin return true;
8250dbef1aSdholland }
8350dbef1aSdholland
8450dbef1aSdholland /*
8550dbef1aSdholland * hook called before writing new disklabel.
8650dbef1aSdholland */
874103857bSmartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)884103857bSmartin md_pre_disklabel(struct install_partition_desc *install,
894103857bSmartin struct disk_partitions *parts)
9050dbef1aSdholland {
914103857bSmartin return false;
9250dbef1aSdholland }
9350dbef1aSdholland
9450dbef1aSdholland /*
9550dbef1aSdholland * hook called after writing disklabel to new target disk.
9650dbef1aSdholland */
974103857bSmartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)984103857bSmartin md_post_disklabel(struct install_partition_desc *install,
994103857bSmartin struct disk_partitions *parts)
10050dbef1aSdholland {
1014103857bSmartin return true;
10250dbef1aSdholland }
10350dbef1aSdholland
10424b1487dStsutsui #ifdef DISKLABEL_NO_ONDISK_VERIFY
10524b1487dStsutsui /*
10624b1487dStsutsui * hook to check if disklabel returned by readdisklabel(9) via DIOCGDINFO
10724b1487dStsutsui * seems the default one, on ports that have no BSD disklabel on disks.
10824b1487dStsutsui */
10924b1487dStsutsui bool
md_disklabel_is_default(const struct disklabel * lp)11024b1487dStsutsui md_disklabel_is_default(const struct disklabel *lp)
11124b1487dStsutsui {
11224b1487dStsutsui bool maybe_default =
11324b1487dStsutsui lp->d_npartitions == RAW_PART + 1 &&
11424b1487dStsutsui lp->d_partitions[RAW_PART].p_size == 0x1fffffff &&
11524b1487dStsutsui lp->d_partitions[0].p_size == lp->d_partitions[RAW_PART].p_size &&
1166a2f9c78Smartin lp->d_partitions[0].p_offset == 0 &&
11724b1487dStsutsui lp->d_partitions[0].p_fstype == FS_BSDFFS;
11824b1487dStsutsui
11924b1487dStsutsui return maybe_default;
12024b1487dStsutsui }
12124b1487dStsutsui #endif
12224b1487dStsutsui
12350dbef1aSdholland /*
12450dbef1aSdholland * hook called after upgrade() or install() has finished setting
12550dbef1aSdholland * up the target disk but immediately before the user is given the
12650dbef1aSdholland * ``disks are now set up'' message.
12750dbef1aSdholland */
12850dbef1aSdholland int
md_post_newfs(struct install_partition_desc * install)1294103857bSmartin md_post_newfs(struct install_partition_desc *install)
13050dbef1aSdholland {
13150dbef1aSdholland /* boot blocks ... */
13224ecf24eSchristos msg_fmt_display(MSG_dobootblks, "%s", pm->diskdev);
13350dbef1aSdholland return run_program(RUN_DISPLAY,
1344b2364d9Smartin "/usr/mdec/installboot -v /usr/mdec/xxboot /dev/r%sa", pm->diskdev);
13550dbef1aSdholland }
13650dbef1aSdholland
13750dbef1aSdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)1384204f810Smartin md_post_extract(struct install_partition_desc *install, bool upgrade)
13950dbef1aSdholland {
14050dbef1aSdholland return 0;
14150dbef1aSdholland }
14250dbef1aSdholland
14350dbef1aSdholland void
md_cleanup_install(struct install_partition_desc * install)1444103857bSmartin md_cleanup_install(struct install_partition_desc *install)
14550dbef1aSdholland {
14650dbef1aSdholland #ifndef DEBUG
14750dbef1aSdholland enable_rc_conf();
14850dbef1aSdholland #endif
14950dbef1aSdholland }
15050dbef1aSdholland
15150dbef1aSdholland int
md_pre_update(struct install_partition_desc * install)1524103857bSmartin md_pre_update(struct install_partition_desc *install)
15350dbef1aSdholland {
15450dbef1aSdholland return 1;
15550dbef1aSdholland }
15650dbef1aSdholland
15750dbef1aSdholland /* Upgrade support */
15850dbef1aSdholland int
md_update(struct install_partition_desc * install)1594103857bSmartin md_update(struct install_partition_desc *install)
16050dbef1aSdholland {
1614103857bSmartin md_post_newfs(install);
16250dbef1aSdholland return 1;
16350dbef1aSdholland }
16450dbef1aSdholland
16550dbef1aSdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)1664f30cbf3Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
16750dbef1aSdholland {
16850dbef1aSdholland return 0;
16950dbef1aSdholland }
1704103857bSmartin
1714103857bSmartin #ifdef HAVE_GPT
1724103857bSmartin /*
1734103857bSmartin * New GPT partitions have been written, update bootloader or remember
1744103857bSmartin * data untill needed in md_post_newfs
1754103857bSmartin */
1764103857bSmartin bool
md_gpt_post_write(struct disk_partitions * parts,part_id root_id,bool root_is_new,part_id efi_id,bool efi_is_new)1774103857bSmartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
1784103857bSmartin bool root_is_new, part_id efi_id, bool efi_is_new)
1794103857bSmartin {
1804103857bSmartin
1814103857bSmartin return true;
1824103857bSmartin }
1834103857bSmartin #endif
1844103857bSmartin
1854103857bSmartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)1864103857bSmartin md_parts_use_wholedisk(struct disk_partitions *parts)
1874103857bSmartin {
1884103857bSmartin return parts_use_wholedisk(parts, 0, NULL);
1894103857bSmartin }
1904103857bSmartin
191