Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsutsui/dad2a6cd4cba3583e89b73803208690e to your computer and use it in GitHub Desktop.
Save tsutsui/dad2a6cd4cba3583e89b73803208690e to your computer and use it in GitHub Desktop.
Index: usr.sbin/sysinst/disklabel.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/sysinst/disklabel.c,v
retrieving revision 1.44
diff -u -p -d -r1.44 disklabel.c
--- usr.sbin/sysinst/disklabel.c 8 Aug 2021 21:50:10 -0000 1.44
+++ usr.sbin/sysinst/disklabel.c 15 Jun 2022 16:31:13 -0000
@@ -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_ondisk_label;
/* read partitions */
@@ -304,8 +295,52 @@ disklabel_parts_read(const char *disk, d
}
close(fd);
+ /*
+ * Verify we really have a disklabel on the target disk.
+ */
#ifndef DISKLABEL_NO_ONDISK_VERIFY
- if (!have_raw_label) {
+ have_ondisk_label = false;
+ if (run_program(RUN_SILENT | RUN_ERROR_OK,
+ "disklabel -r %s", disk) == 0)
+ have_ondisk_label = true;
+#else
+ /*
+ * disklabel(8) -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).
+ *
+ * XXX these should be checked in MD hook functions.
+ */
+
+ /* assume we have a label by default */
+ have_ondisk_label = true;
+
+ /* check default values on amiga */
+ if (parts->l.d_npartitions == RAW_PART + 1 &&
+ parts->l.d_partitions[RAW_PART].p_size == 0x1fffffff &&
+ parts->l.d_partitions[0].p_size ==
+ parts->l.d_partitions[RAW_PART].p_size &&
+ parts->l.d_partitions[0].p_offset == 0 &&
+ parts->l.d_partitions[0].p_fstype == FS_BSDFFS) {
+ have_ondisk_label = false;
+ }
+
+ /* XXX maybe we should also check mac68k with Apple Partition Map */
+
+ /* check default values on x68k */
+ if (parts->l.d_npartitions == RAW_PART + 1 &&
+ parts->l.d_partitions[0].p_size ==
+ parts->l.d_partitions[RAW_PART].p_size &&
+ parts->l.d_partitions[0].p_fstype == FS_UNUSED &&
+ parts->l.d_bbsize == 0 && parts->l.d_sbsize == 0) {
+ have_ondisk_label = false;
+ }
+#endif
+
+ if (!have_ondisk_label) {
bool found_real_part = false;
if (parts->l.d_npartitions <= RAW_PART ||
@@ -338,7 +373,6 @@ no_valid_label:
return NULL;
}
}
-#endif
return &parts->dp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment