Module Name: src Committed By: martin Date: Mon Jan 2 10:13:31 UTC 2023
Modified Files: src/usr.sbin/sysinst [netbsd-9]: defs.h disklabel.c src/usr.sbin/sysinst/arch/amiga [netbsd-9]: md.c src/usr.sbin/sysinst/arch/x68k [netbsd-9]: md.c Log Message: Pull up following revision(s) (requested by tsutsui in ticket #1559): usr.sbin/sysinst/arch/x68k/md.c: revision 1.13 usr.sbin/sysinst/disklabel.c: revision 1.49 usr.sbin/sysinst/defs.h: revision 1.85 usr.sbin/sysinst/arch/amiga/md.c: revision 1.8 usr.sbin/sysinst/arch/amiga/md.c: revision 1.9 Check on-disk disklabel properly even on ports without raw BSD disklabel. Fixes PR install/56890. Fix typo To generate a diff of this commit: cvs rdiff -u -r1.42.2.11 -r1.42.2.12 src/usr.sbin/sysinst/defs.h cvs rdiff -u -r1.10.2.11 -r1.10.2.12 src/usr.sbin/sysinst/disklabel.c cvs rdiff -u -r1.5.2.3 -r1.5.2.4 src/usr.sbin/sysinst/arch/amiga/md.c cvs rdiff -u -r1.8.2.4 -r1.8.2.5 src/usr.sbin/sysinst/arch/x68k/md.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/sysinst/defs.h diff -u src/usr.sbin/sysinst/defs.h:1.42.2.11 src/usr.sbin/sysinst/defs.h:1.42.2.12 --- src/usr.sbin/sysinst/defs.h:1.42.2.11 Mon Feb 14 06:45:34 2022 +++ src/usr.sbin/sysinst/defs.h Mon Jan 2 10:13:30 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: defs.h,v 1.42.2.11 2022/02/14 06:45:34 msaitoh Exp $ */ +/* $NetBSD: defs.h,v 1.42.2.12 2023/01/02 10:13:30 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -643,6 +643,7 @@ bool md_gpt_post_write(struct disk_parti */ bool md_pre_disklabel(struct install_partition_desc*, struct disk_partitions*); bool md_post_disklabel(struct install_partition_desc*, struct disk_partitions*); +bool md_disklabel_is_default(const struct disklabel *); int md_pre_mount(struct install_partition_desc*, size_t); int md_post_newfs(struct install_partition_desc*); int md_post_extract(struct install_partition_desc*, bool upgrade); Index: src/usr.sbin/sysinst/disklabel.c diff -u src/usr.sbin/sysinst/disklabel.c:1.10.2.11 src/usr.sbin/sysinst/disklabel.c:1.10.2.12 --- src/usr.sbin/sysinst/disklabel.c:1.10.2.11 Sat Dec 31 05:03:14 2022 +++ src/usr.sbin/sysinst/disklabel.c Mon Jan 2 10:13:30 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: disklabel.c,v 1.10.2.11 2022/12/31 05:03:14 snj Exp $ */ +/* $NetBSD: disklabel.c,v 1.10.2.12 2023/01/02 10:13:30 martin Exp $ */ /* * Copyright 2018 The NetBSD Foundation, Inc. @@ -198,16 +198,7 @@ disklabel_parts_read(const char *disk, d int fd; char diskpath[MAXPATHLEN]; uint flags; -#ifndef DISKLABEL_NO_ONDISK_VERIFY - bool have_raw_label = false; - - /* - * Verify we really have a disklabel. - */ - if (run_program(RUN_SILENT | RUN_ERROR_OK, - "disklabel -r %s", disk) == 0) - have_raw_label = true; -#endif + bool have_own_label = false; /* read partitions */ @@ -304,8 +295,30 @@ disklabel_parts_read(const char *disk, d } close(fd); -#ifndef DISKLABEL_NO_ONDISK_VERIFY - if (!have_raw_label) { + /* + * Verify we really have a disklabel on the target disk. + */ + if (run_program(RUN_SILENT | RUN_ERROR_OK, + "disklabel -r %s", disk) == 0) { + have_own_label = true; + } +#ifdef DISKLABEL_NO_ONDISK_VERIFY + else { + /* + * disklabel(8) with -r checks a native disklabel at + * LABELOFFSET sector, but several ports don't have + * a native label and use emulated one translated from + * port specific MD disk partition information. + * Unfortunately, there is no MI way to check whether + * the disk has a native BSD disklabel by readdisklabel(9) + * via DIOCGDINFO. So check if returned label looks + * defaults set by readdisklabel(9) per MD way. + */ + have_own_label = !md_disklabel_is_default(&parts->l); + } +#endif + + if (!have_own_label) { bool found_real_part = false; if (parts->l.d_npartitions <= RAW_PART || @@ -338,7 +351,6 @@ no_valid_label: return NULL; } } -#endif return &parts->dp; } Index: src/usr.sbin/sysinst/arch/amiga/md.c diff -u src/usr.sbin/sysinst/arch/amiga/md.c:1.5.2.3 src/usr.sbin/sysinst/arch/amiga/md.c:1.5.2.4 --- src/usr.sbin/sysinst/arch/amiga/md.c:1.5.2.3 Wed Dec 14 15:39:45 2022 +++ src/usr.sbin/sysinst/arch/amiga/md.c Mon Jan 2 10:13:30 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: md.c,v 1.5.2.3 2022/12/14 15:39:45 snj Exp $ */ +/* $NetBSD: md.c,v 1.5.2.4 2023/01/02 10:13:30 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -101,6 +101,25 @@ md_post_disklabel(struct install_partiti return true; } +#ifdef DISKLABEL_NO_ONDISK_VERIFY +/* + * hook to check if disklabel returned by readdisklabel(9) via DIOCGDINFO + * seems the default one, on ports that have no BSD disklabel on disks. + */ +bool +md_disklabel_is_default(const struct disklabel *lp) +{ + bool maybe_default = + lp->d_npartitions == RAW_PART + 1 && + lp->d_partitions[RAW_PART].p_size == 0x1fffffff && + lp->d_partitions[0].p_size == lp->d_partitions[RAW_PART].p_size && + lp->d_partitions[0].p_offset == 0 && + lp->d_partitions[0].p_fstype == FS_BSDFFS; + + return maybe_default; +} +#endif + /* * hook called after upgrade() or install() has finished setting * up the target disk but immediately before the user is given the Index: src/usr.sbin/sysinst/arch/x68k/md.c diff -u src/usr.sbin/sysinst/arch/x68k/md.c:1.8.2.4 src/usr.sbin/sysinst/arch/x68k/md.c:1.8.2.5 --- src/usr.sbin/sysinst/arch/x68k/md.c:1.8.2.4 Wed Feb 2 04:25:36 2022 +++ src/usr.sbin/sysinst/arch/x68k/md.c Mon Jan 2 10:13:30 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: md.c,v 1.8.2.4 2022/02/02 04:25:36 msaitoh Exp $ */ +/* $NetBSD: md.c,v 1.8.2.5 2023/01/02 10:13:30 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -264,6 +264,25 @@ md_post_disklabel(struct install_partiti return true; } +#ifdef DISKLABEL_NO_ONDISK_VERIFY +/* + * hook to check if disklabel returned by readdisklabel(9) via DIOCGDINFO + * seems the default one, on ports that have no BSD disklabel on disks. + */ +bool +md_disklabel_is_default(const struct disklabel *lp) +{ + bool maybe_default = + lp->d_npartitions == RAW_PART + 1 && + lp->d_partitions[0].p_size == lp->d_partitions[RAW_PART].p_size && + lp->d_partitions[0].p_fstype == FS_UNUSED && + lp->d_bbsize == 0 && + lp->d_sbsize == 0; + + return maybe_default; +} +#endif + /* * hook called after upgrade() or install() has finished setting * up the target disk but immediately before the user is given the