diff options
author | Warner Losh <imp@FreeBSD.org> | 2023-03-02 17:57:43 +0000 |
---|---|---|
committer | Warner Losh <imp@FreeBSD.org> | 2023-03-02 18:12:10 +0000 |
commit | 7b4299eb4e7ccf3f2a9ecf7b3fadaa8e5aa78dc3 (patch) | |
tree | d30c7576effbb491b26cc5e34f69d6d3c747e5c3 | |
parent | 35b4acad2f1f7ba87eb9e0c7276ef8eef55b4a9c (diff) | |
download | src-7b4299eb4e7ccf3f2a9ecf7b3fadaa8e5aa78dc3.tar.gz src-7b4299eb4e7ccf3f2a9ecf7b3fadaa8e5aa78dc3.zip |
kboot: Fix hostdisk_override
We were assuming that hostdisk_override was both a directory and a
file, which is not going to work very well. It's supposed to be a
single file, so recode it as such. Simplify erorr handling a little as
well and fix a return type-mismatch that doesn't matter for the
generated code (return NULL is the same as return false in this
context)
Sponsored by: Netflix
-rw-r--r-- | stand/kboot/hostdisk.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/stand/kboot/hostdisk.c b/stand/kboot/hostdisk.c index b71ae256b0f6..5cc7825034dd 100644 --- a/stand/kboot/hostdisk.c +++ b/stand/kboot/hostdisk.c @@ -249,31 +249,22 @@ hostdisk_one_disk(struct host_dirent64 *dent, void *argp __unused) return (true); } -static bool -hostdisk_fake_one_disk(struct host_dirent64 *dent, void *argp) +static void +hostdisk_fake_one_disk(char *override) { - char *override_dir = argp; - char *fn = NULL; hdinfo_t *hd = NULL; struct host_kstat sb; - /* - * We only do regular files. Each one is treated as a disk image - * accessible via /dev/${dent->d_name}. - */ - if (dent->d_type != HOST_DT_REG && dent->d_type != HOST_DT_LNK) - return (true); - if (asprintf(&fn, "%s/%s", override_dir, dent->d_name) == -1) - return (true); - if (host_stat(fn, &sb) != 0) - goto err; + if (host_stat(override, &sb) != 0) + return; if (!HOST_S_ISREG(sb.st_mode)) - return (true); + return; if (sb.st_size == 0) - goto err; + return; if ((hd = calloc(1, sizeof(*hd))) == NULL) + return; + if ((hd->hd_dev = strdup(override)) == NULL) goto err; - hd->hd_dev = fn; hd->hd_size = sb.st_size; hd->hd_sectorsize = 512; /* XXX configurable? */ hd->hd_sectors = hd->hd_size / hd->hd_sectorsize; @@ -284,12 +275,10 @@ hostdisk_fake_one_disk(struct host_dirent64 *dent, void *argp) printf("%s: %ju %ju %ju\n", hd->hd_dev, hd->hd_size, hd->hd_sectors, hd->hd_sectorsize); STAILQ_INSERT_TAIL(&hdinfo, hd, hd_link); - /* XXX no partiions? -- is that OK? */ - return (true); + return; err: + free(__DECONST(void *, hd->hd_dev)); free(hd); - free(fn); - return (true); } static void @@ -299,7 +288,7 @@ hostdisk_find_block_devices(void) override=getenv("hostdisk_override"); if (override != NULL) - foreach_file(override, hostdisk_fake_one_disk, override, 0); + hostdisk_fake_one_disk(override); else foreach_file(SYSBLK, hostdisk_one_disk, NULL, 0); } @@ -540,7 +529,7 @@ hostdisk_gen_probe(void) return (rv); } } - return (false); + return (NULL); } #ifdef LOADER_ZFS_SUPPORT |