git: 9ff8ab26dcac - main - loader.efi: Give the md probe a struct disk_devdesc
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 12 Nov 2026 09:23:16 UTC
The branch main has been updated by olivier:
URL: https://cgit.FreeBSD.org/src/commit/?id=9ff8ab26dcacebb50183c5bd767e7c5939116598
commit 9ff8ab26dcacebb50183c5bd767e7c5939116598
Author: Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-11-08 21:39:43 +0000
Commit: Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-11-12 09:17:34 +0000
loader.efi: Give the md probe a struct disk_devdesc
probe_md_currdev() named md through set_currdev_devsw(), which builds a plain
struct devdesc. Once md uses disk_fmtdev(), that reads d_slice and d_partition
past the end of the struct, and currdev becomes a name built from stack garbage.
Use a struct disk_devdesc instead, and open the device first so the name shows
the slice and partition actually found. When the image has no partition table,
fall back to the whole image, as before.
Add md_get_size() and move MD_BLOCK_SIZE to bootstrap.h so main.c
can open the device.
Reviewed by: imp
Approved by: imp
Sponsored by: Netflix
Differential Revision: https://ron-dev.freebsd.org/FreeBSD/src/pulls/98
---
stand/common/bootstrap.h | 3 +++
stand/common/md.c | 17 ++++++++++++++++-
stand/efi/loader/main.c | 32 +++++++++++++++++++++++++++++++-
3 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h
index 7dab530a368a..c091dc3266e5 100644
--- a/stand/common/bootstrap.h
+++ b/stand/common/bootstrap.h
@@ -387,5 +387,8 @@ void set_currdev(const char *devname);
extern struct devsw md_dev;
int md_register(void *image, size_t size, unsigned int flags);
void md_export_to_kernel(uint64_t start, uint64_t len);
+int md_get_size(int unit, uint64_t *size);
+
+#define MD_BLOCK_SIZE 512
#endif /* !_BOOTSTRAP_H_ */
diff --git a/stand/common/md.c b/stand/common/md.c
index c8692a8948fb..93301e39a2f5 100644
--- a/stand/common/md.c
+++ b/stand/common/md.c
@@ -32,7 +32,6 @@
#include "bootstrap.h"
-#define MD_BLOCK_SIZE 512
#define MD_FLAG_MASK MD_FLAG_KERNEL
struct md_info {
@@ -95,6 +94,22 @@ md_get_info(int unit)
return (NULL);
}
+/*
+ * Report a registered md's size, so probe_md_currdev() can hand it to
+ * disk_open() without reaching into the private struct md_info.
+ */
+int
+md_get_size(int unit, uint64_t *size)
+{
+ struct md_info *md;
+
+ md = md_get_info(unit);
+ if (md == NULL)
+ return (ENXIO);
+ *size = md->md_size;
+ return (0);
+}
+
int
md_register(void *image, size_t size, unsigned int flags)
{
diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
index bac8cab552f5..1b8bed045253 100644
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -328,9 +328,39 @@ static bool
probe_md_currdev(void)
{
#ifdef LOADER_MD_SUPPORT
+ struct disk_devdesc dev;
+ uint64_t mediasize;
bool rv;
- set_currdev_devsw(&md_dev, 0);
+ /*
+ * md is a DEVT_DISK, so it needs a disk_devdesc: set_currdev_devsw()
+ * would pass a plain devdesc and devformat() would read the slice and
+ * partition off the end of it. Leave both wild for md_open() to
+ * resolve against whatever partition table the image carries.
+ */
+ dev.dd.d_dev = &md_dev;
+ dev.dd.d_unit = 0;
+ dev.dd.d_opendata = NULL;
+ dev.d_slice = D_SLICEWILD;
+ dev.d_partition = D_PARTWILD;
+ dev.d_offset = 0;
+
+ /*
+ * devformat() prints d_slice verbatim, and D_SLICEWILD is 0, which
+ * would name a slice that cannot exist. Open the device first so
+ * disk_open() writes the resolved slice and partition back, then
+ * name that.
+ */
+ if (md_get_size(0, &mediasize) == 0 &&
+ disk_open(&dev, mediasize, MD_BLOCK_SIZE) == 0) {
+ disk_close(&dev);
+ } else {
+ /* No partition table: use the whole image as the filesystem. */
+ dev.d_slice = D_SLICENONE;
+ dev.d_partition = D_PARTNONE;
+ }
+
+ set_currdev_devdesc((struct devdesc *)&dev);
rv = sanity_check_currdev();
if (!rv)
printf("MD not present\n");