summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2016-04-27 16:33:17 +0000
committerjhb <jhb@FreeBSD.org>2016-04-27 16:33:17 +0000
commiteb8279b76064de06310530338834d34a265edd1c (patch)
tree9d890003db3954532ce3e8f39ed0184a8e9983dc /lib
parentc97e88d8d27379822b48e87c286771f02ec6230b (diff)
downloadFreeBSD-src-eb8279b76064de06310530338834d34a265edd1c.zip
FreeBSD-src-eb8279b76064de06310530338834d34a265edd1c.tar.gz
Add 'devctl delete' that calls device_delete_child().
'devctl delete' can be used to delete a device that is no longer present. As an anti-foot-shooting measure, 'delete' will not delete a device unless it's parent bus says it is no longer present. This can be overridden by passing the force ('-f') flag. Note that this command should be used with care. If a device is deleted that is actually present it can't be resurrected unless the parent bus device's driver supports rescans. Differential Revision: https://reviews.freebsd.org/D6019
Diffstat (limited to 'lib')
-rw-r--r--lib/libdevctl/devctl.329
-rw-r--r--lib/libdevctl/devctl.c8
-rw-r--r--lib/libdevctl/devctl.h1
3 files changed, 36 insertions, 2 deletions
diff --git a/lib/libdevctl/devctl.3 b/lib/libdevctl/devctl.3
index 7d8ddba..866bb6a 100644
--- a/lib/libdevctl/devctl.3
+++ b/lib/libdevctl/devctl.3
@@ -31,6 +31,7 @@
.Sh NAME
.Nm devctl ,
.Nm devctl_attach ,
+.Nm devctl_delete ,
.Nm devctl_detach ,
.Nm devctl_disable ,
.Nm devctl_enable ,
@@ -46,6 +47,8 @@
.Ft int
.Fn devctl_attach "const char *device"
.Ft int
+.Fn devctl_delete "const char *device" "bool force"
+.Ft int
.Fn devctl_detach "const char *device" "bool force"
.Ft int
.Fn devctl_disable "const char *device" "bool force_detach"
@@ -110,6 +113,15 @@ is true,
the current device driver will be detached even if the device is busy.
.Pp
The
+.Fn devctl_delete
+function deletes a device from the device tree.
+No
+If
+.Fa force
+is true,
+the device is deleted even if the device is physically present.
+.Pp
+The
.Fn devctl_disable
function disables a device.
If the device is currently attached to a device driver,
@@ -158,8 +170,8 @@ The
function rescans a bus device checking for devices that have been added or
removed.
.Sh RETURN VALUES
-.Rv -std devctl_attach devctl_detach devctl_disable devctl_enable \
-devctl_suspend devctl_rescan devctl_resume devctl_set_driver
+.Rv -std devctl_attach devctl_delete devctl_detach devctl_disable \
+devctl_enable devctl_suspend devctl_rescan devctl_resume devctl_set_driver
.Sh ERRORS
In addition to specific errors noted below,
all of the
@@ -298,6 +310,19 @@ The device is not attached to a driver.
.It Bq Er ENXIO
The bus driver does not support rescanning.
.El
+.Pp
+The
+.Fn devctl_delete
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EBUSY
+The device is physically present and
+.Fa force
+is false.
+.It Bq Er EINVAL
+.Fa dev
+is the root device of the device tree.
+.El
.Sh SEE ALSO
.Xr devinfo 3 ,
.Xr devstat 3 ,
diff --git a/lib/libdevctl/devctl.c b/lib/libdevctl/devctl.c
index 33c891b..9f275e7 100644
--- a/lib/libdevctl/devctl.c
+++ b/lib/libdevctl/devctl.c
@@ -129,3 +129,11 @@ devctl_rescan(const char *device)
return (devctl_simple_request(DEV_RESCAN, device, 0));
}
+
+int
+devctl_delete(const char *device, bool force)
+{
+
+ return (devctl_simple_request(DEV_DELETE, device, force ?
+ DEVF_FORCE_DELETE : 0));
+}
diff --git a/lib/libdevctl/devctl.h b/lib/libdevctl/devctl.h
index 40c64c1..670ca1a 100644
--- a/lib/libdevctl/devctl.h
+++ b/lib/libdevctl/devctl.h
@@ -39,5 +39,6 @@ int devctl_suspend(const char *device);
int devctl_resume(const char *device);
int devctl_set_driver(const char *device, const char *driver, bool force);
int devctl_rescan(const char *device);
+int devctl_delete(const char *device, bool force);
#endif /* !__DEVCTL_H__ */
OpenPOWER on IntegriCloud