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
This commit is contained in:
parent
39633fc173
commit
1c1783d66b
@ -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")
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user