diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index b8131febb6d8..7492a4bbc08f 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -1199,6 +1199,25 @@ device_shutdown(device_t dev) return DEVICE_SHUTDOWN(dev); } +int +device_set_unit(device_t dev, int unit) +{ + devclass_t dc; + int err; + + dc = device_get_devclass(dev); + if (unit < dc->maxunit && dc->devices[unit]) + return EBUSY; + err = devclass_delete_device(dc, dev); + if (err) + return err; + dev->unit = unit; + err = devclass_add_device(dc, dev); + if (err) + return err; + return 0; +} + #ifdef DEVICE_SYSCTLS /* diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 84176db97551..77bd9030d572 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -257,6 +257,7 @@ void device_set_desc_copy(device_t dev, const char* desc); int device_set_devclass(device_t dev, const char *classname); int device_set_driver(device_t dev, driver_t *driver); void device_set_flags(device_t dev, u_int32_t flags); +int device_set_unit(device_t dev, int unit); /* XXX DONT USE XXX */ int device_shutdown(device_t dev); void device_unbusy(device_t dev); void device_verbose(device_t dev);