git: 1c1783d66bc8 - main - stand: Create common gen_setcurrdev and replace code
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 11 Jan 2023 22:17:11 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=1c1783d66bc81ebd0c1304b1f613a9403c073915
commit 1c1783d66bc81ebd0c1304b1f613a9403c073915
Author: Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-01-11 22:14:02 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-11 22:15:14 +0000
stand: Create common gen_setcurrdev and replace code
Replace 4 identical copies of *_setcurrdev with gen_setcurrdev to avoid
having to create a 5th copy. uboot_setcurrdev is actually different and
needs to remain separate (even though it's quite similar).
Sponsored by: Netflix
Reviewed by: fuz@fuz.su, kevans
Differential Revision: https://reviews.freebsd.org/D38003
---
stand/common/bootstrap.h | 3 ++-
stand/common/misc.c | 16 ++++++++++++++++
stand/efi/include/efilib.h | 2 --
stand/efi/libefi/devicename.c | 17 -----------------
stand/efi/loader/main.c | 4 ++--
stand/i386/libi386/devicename.c | 16 ----------------
stand/i386/libi386/libi386.h | 1 -
stand/i386/loader/main.c | 4 ++--
stand/i386/zfsboot/zfsboot.c | 4 ++--
stand/libofw/devicename.c | 14 --------------
stand/libofw/libofw.h | 1 -
stand/powerpc/ofw/main.c | 6 +++---
stand/userboot/userboot/devicename.c | 16 ----------------
stand/userboot/userboot/libuserboot.h | 1 -
stand/userboot/userboot/main.c | 5 ++---
15 files changed, 29 insertions(+), 81 deletions(-)
diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h
index bbe97e80323b..b16625774ce5 100644
--- a/stand/common/bootstrap.h
+++ b/stand/common/bootstrap.h
@@ -415,7 +415,8 @@ int nvstore_set_var_from_string(void *, const char *, const char *,
int nvstore_unset_var(void *, const char *);
/* common code to set currdev variable. */
-extern int mount_currdev(struct env_var *, int, const void *);
+int gen_setcurrdev(struct env_var *ev, int flags, const void *value);
+int mount_currdev(struct env_var *, int, const void *);
#ifndef CTASSERT
#define CTASSERT(x) _Static_assert(x, "compile-time assertion failed")
diff --git a/stand/common/misc.c b/stand/common/misc.c
index 9cb5550344ca..e1945b24be5a 100644
--- a/stand/common/misc.c
+++ b/stand/common/misc.c
@@ -201,3 +201,19 @@ int mount_currdev(struct env_var *ev, int flags, const void *value)
}
return (rv);
}
+
+/*
+ * Set currdev to suit the value being supplied in (value)
+ */
+int
+gen_setcurrdev(struct env_var *ev, int flags, const void *value)
+{
+ struct devdesc *ncurr;
+ int rv;
+
+ if ((rv = devparse(&ncurr, value, NULL)) != 0)
+ return (rv);
+ free(ncurr);
+
+ return (mount_currdev(ev, flags, value));
+}
diff --git a/stand/efi/include/efilib.h b/stand/efi/include/efilib.h
index bbef44fca4b3..1673ac97fdf2 100644
--- a/stand/efi/include/efilib.h
+++ b/stand/efi/include/efilib.h
@@ -85,8 +85,6 @@ efi_exit_boot_services(UINTN key)
}
int efi_getdev(void **vdev, const char *devspec, const char **path);
-int efi_setcurrdev(struct env_var *ev, int flags, const void *value);
-
int efi_register_handles(struct devsw *, EFI_HANDLE *, EFI_HANDLE *, int);
EFI_HANDLE efi_find_handle(struct devsw *, int);
diff --git a/stand/efi/libefi/devicename.c b/stand/efi/libefi/devicename.c
index 83f4e6e99201..ec821821bdf5 100644
--- a/stand/efi/libefi/devicename.c
+++ b/stand/efi/libefi/devicename.c
@@ -63,20 +63,3 @@ efi_getdev(void **vdev, const char *devspec, const char **path)
return (devparse(dev, devspec, path));
}
-
-/*
- * Set currdev to suit the value being supplied in (value)
- */
-int
-efi_setcurrdev(struct env_var *ev, int flags, const void *value)
-{
- struct devdesc *ncurr;
- int rv;
-
- rv = devparse(&ncurr, value, NULL);
- if (rv != 0)
- return (rv);
- free(ncurr);
-
- return (mount_currdev(ev, flags, value));
-}
diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
index a315fdea8edc..1e91817410b6 100644
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -189,7 +189,7 @@ static void
set_currdev(const char *devname)
{
- env_setenv("currdev", EV_VOLATILE, devname, efi_setcurrdev,
+ env_setenv("currdev", EV_VOLATILE, devname, gen_setcurrdev,
env_nounset);
/*
* Don't execute hook here; the loaddev hook makes it immutable
@@ -970,7 +970,7 @@ main(int argc, CHAR16 *argv[])
cons_probe();
/* Set up currdev variable to have hooks in place. */
- env_setenv("currdev", EV_VOLATILE, "", efi_setcurrdev, env_nounset);
+ env_setenv("currdev", EV_VOLATILE, "", gen_setcurrdev, env_nounset);
/* Init the time source */
efi_time_init();
diff --git a/stand/i386/libi386/devicename.c b/stand/i386/libi386/devicename.c
index 99d3aa7920bc..99674a4ac877 100644
--- a/stand/i386/libi386/devicename.c
+++ b/stand/i386/libi386/devicename.c
@@ -63,19 +63,3 @@ i386_getdev(void **vdev, const char *devspec, const char **path)
*/
return(devparse(dev, devspec, path));
}
-
-/*
- * Set currdev to suit the value being supplied in (value)
- */
-int
-i386_setcurrdev(struct env_var *ev, int flags, const void *value)
-{
- struct devdesc *ncurr;
- int rv;
-
- if ((rv = devparse(&ncurr, value, NULL)) != 0)
- return (rv);
- free(ncurr);
-
- return (mount_currdev(ev, flags, value));
-}
diff --git a/stand/i386/libi386/libi386.h b/stand/i386/libi386/libi386.h
index 0115f30e31c7..587a367ccf9c 100644
--- a/stand/i386/libi386/libi386.h
+++ b/stand/i386/libi386/libi386.h
@@ -80,7 +80,6 @@ extern uint16_t relocator_a20_enabled;
int i386_getdev(void **vdev, const char *devspec, const char **path);
char *i386_fmtdev(void *vdev);
-int i386_setcurrdev(struct env_var *ev, int flags, const void *value);
extern struct devdesc currdev; /* our current device */
diff --git a/stand/i386/loader/main.c b/stand/i386/loader/main.c
index e5cc766f5781..8337ca378832 100644
--- a/stand/i386/loader/main.c
+++ b/stand/i386/loader/main.c
@@ -164,7 +164,7 @@ main(void)
/* Set up currdev variable to have hooks in place. */
env_setenv("currdev", EV_VOLATILE | EV_NOHOOK, "",
- i386_setcurrdev, env_nounset);
+ gen_setcurrdev, env_nounset);
/*
* Initialise the block cache. Set the upper limit.
@@ -384,7 +384,7 @@ extract_currdev(void)
#endif
env_setenv("currdev", EV_VOLATILE, devformat(&new_currdev.dd),
- i386_setcurrdev, env_nounset);
+ gen_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, devformat(&new_currdev.dd),
env_noset, env_nounset);
}
diff --git a/stand/i386/zfsboot/zfsboot.c b/stand/i386/zfsboot/zfsboot.c
index da91fc3a5d20..6b8c72ea0fb8 100644
--- a/stand/i386/zfsboot/zfsboot.c
+++ b/stand/i386/zfsboot/zfsboot.c
@@ -208,7 +208,7 @@ main(void)
bd_bios2unit(bootinfo.bi_bios_dev));
/* Set up currdev variable to have hooks in place. */
- env_setenv("currdev", EV_VOLATILE, "", i386_setcurrdev,
+ env_setenv("currdev", EV_VOLATILE, "", gen_setcurrdev,
env_nounset);
devinit();
@@ -256,7 +256,7 @@ main(void)
free(bdev);
i386_getdev((void **)&bdev, boot_devname, NULL);
- env_setenv("currdev", EV_VOLATILE, boot_devname, i386_setcurrdev,
+ env_setenv("currdev", EV_VOLATILE, boot_devname, gen_setcurrdev,
env_nounset);
/* Process configuration file */
diff --git a/stand/libofw/devicename.c b/stand/libofw/devicename.c
index 77a53ccd90ce..76ba5530520c 100644
--- a/stand/libofw/devicename.c
+++ b/stand/libofw/devicename.c
@@ -92,20 +92,6 @@ ofw_path_to_handle(const char *ofwpath, const char *want_type, const char **path
return ((phandle_t)-1);
}
-int
-ofw_setcurrdev(struct env_var *ev, int flags, const void *value)
-{
- struct devdesc *ncurr;
- int rv;
-
- if ((rv = devparse(&ncurr, value, NULL)) != 0)
- return (rv);
-
- free(ncurr);
-
- return (mount_currdev(ev, flags, value));
-}
-
int
ofw_common_parsedev(struct devdesc **dev, const char *devspec, const char **path,
const char *ofwtype)
diff --git a/stand/libofw/libofw.h b/stand/libofw/libofw.h
index 2d6ea9a5bf24..3101dcb645be 100644
--- a/stand/libofw/libofw.h
+++ b/stand/libofw/libofw.h
@@ -45,7 +45,6 @@ struct ofw_devdesc {
};
extern int ofw_getdev(void **vdev, const char *devspec, const char **path);
-extern ev_sethook_t ofw_setcurrdev;
extern struct devsw ofwdisk;
extern struct devsw ofw_netdev;
diff --git a/stand/powerpc/ofw/main.c b/stand/powerpc/ofw/main.c
index 177e665a4dc7..83ab2647f308 100644
--- a/stand/powerpc/ofw/main.c
+++ b/stand/powerpc/ofw/main.c
@@ -180,7 +180,7 @@ main(int (*openfirm)(void *))
#endif
/* Set up currdev variable to have hooks in place. */
- env_setenv("currdev", EV_VOLATILE, "", ofw_setcurrdev, env_nounset);
+ env_setenv("currdev", EV_VOLATILE, "", gen_setcurrdev, env_nounset);
devinit();
@@ -202,11 +202,11 @@ main(int (*openfirm)(void *))
bargc = 0;
parse(&bargc, &bargv, bootargs);
if (bargc == 1)
- env_setenv("currdev", EV_VOLATILE, bargv[0], ofw_setcurrdev,
+ env_setenv("currdev", EV_VOLATILE, bargv[0], gen_setcurrdev,
env_nounset);
else
env_setenv("currdev", EV_VOLATILE, bootpath,
- ofw_setcurrdev, env_nounset);
+ gen_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, bootpath, env_noset,
env_nounset);
setenv("LINES", "24", 1); /* optional */
diff --git a/stand/userboot/userboot/devicename.c b/stand/userboot/userboot/devicename.c
index e6d7e9706c18..8caafd1cab67 100644
--- a/stand/userboot/userboot/devicename.c
+++ b/stand/userboot/userboot/devicename.c
@@ -64,19 +64,3 @@ userboot_getdev(void **vdev, const char *devspec, const char **path)
*/
return (devparse(dev, devspec, path));
}
-
-/*
- * Set currdev to suit the value being supplied in (value)
- */
-int
-userboot_setcurrdev(struct env_var *ev, int flags, const void *value)
-{
- struct devdesc *ncurr;
- int rv;
-
- if ((rv = devparse(&ncurr, value, NULL)) != 0)
- return (rv);
- free(ncurr);
-
- return (mount_currdev(ev, flags, value));
-}
diff --git a/stand/userboot/userboot/libuserboot.h b/stand/userboot/userboot/libuserboot.h
index 6d7dc0c3ff40..5539b617cdce 100644
--- a/stand/userboot/userboot/libuserboot.h
+++ b/stand/userboot/userboot/libuserboot.h
@@ -57,7 +57,6 @@ extern ssize_t userboot_copyin(const void *, vm_offset_t, size_t);
extern ssize_t userboot_copyout(vm_offset_t, void *, size_t);
extern ssize_t userboot_readin(readin_handle_t, vm_offset_t, size_t);
extern int userboot_getdev(void **, const char *, const char **);
-int userboot_setcurrdev(struct env_var *ev, int flags, const void *value);
int bi_getboothowto(char *kargs);
void bi_setboothowto(int howto);
diff --git a/stand/userboot/userboot/main.c b/stand/userboot/userboot/main.c
index b403d9b48f56..02118c2ec1ae 100644
--- a/stand/userboot/userboot/main.c
+++ b/stand/userboot/userboot/main.c
@@ -172,8 +172,7 @@ loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks)
cons_probe();
/* Set up currdev variable to have hooks in place. */
- env_setenv("currdev", EV_VOLATILE, "",
- userboot_setcurrdev, env_nounset);
+ env_setenv("currdev", EV_VOLATILE, "", gen_setcurrdev, env_nounset);
printf("\n%s", bootprog_info);
#if 0
@@ -230,7 +229,7 @@ set_currdev(const char *devname)
{
env_setenv("currdev", EV_VOLATILE, devname,
- userboot_setcurrdev, env_nounset);
+ gen_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, devname,
env_noset, env_nounset);
}