summaryrefslogtreecommitdiffstats
path: root/usr.sbin
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 /usr.sbin
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 'usr.sbin')
-rw-r--r--usr.sbin/devctl/devctl.816
-rw-r--r--usr.sbin/devctl/devctl.c40
2 files changed, 54 insertions, 2 deletions
diff --git a/usr.sbin/devctl/devctl.8 b/usr.sbin/devctl/devctl.8
index bfa6dcc..ec8abaf 100644
--- a/usr.sbin/devctl/devctl.8
+++ b/usr.sbin/devctl/devctl.8
@@ -59,6 +59,10 @@
.Nm
.Cm rescan
.Ar device
+.Nm
+.Cm delete
+.Op Fl f
+.Ar device
.Sh DESCRIPTION
The
.Nm
@@ -132,6 +136,18 @@ the device will not be changed.
.It Cm rescan Ar device
Rescan a bus device checking for devices that have been added or
removed.
+.It Xo Cm delete
+.Op Fl
+.Ar device
+.Xc
+Delete the device from the device tree.
+If the
+.Fl f
+flag is specified,
+the device will be deleted even if it is physically present.
+This command should be used with care as a device that is deleted but present
+can no longer be used unless the parent bus device rediscovers the device via
+a rescan request.
.El
.Sh SEE ALSO
.Xr devctl 3 ,
diff --git a/usr.sbin/devctl/devctl.c b/usr.sbin/devctl/devctl.c
index 545224b..824b907 100644
--- a/usr.sbin/devctl/devctl.c
+++ b/usr.sbin/devctl/devctl.c
@@ -70,14 +70,16 @@ DEVCTL_TABLE(top, set);
static void
usage(void)
{
- fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
+ fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
"usage: devctl attach device",
" devctl detach [-f] device",
" devctl disable [-f] device",
" devctl enable device",
" devctl suspend device",
" devctl resume device",
- " devctl set driver [-f] device driver");
+ " devctl set driver [-f] device driver",
+ " devctl rescan device",
+ " devctl delete [-f] device");
exit(1);
}
@@ -271,6 +273,40 @@ rescan(int ac, char **av)
}
DEVCTL_COMMAND(top, rescan, rescan);
+static void
+delete_usage(void)
+{
+
+ fprintf(stderr, "usage: devctl delete [-f] device\n");
+ exit(1);
+}
+
+static int
+delete(int ac, char **av)
+{
+ bool force;
+ int ch;
+
+ force = false;
+ while ((ch = getopt(ac, av, "f")) != -1)
+ switch (ch) {
+ case 'f':
+ force = true;
+ break;
+ default:
+ delete_usage();
+ }
+ ac -= optind;
+ av += optind;
+
+ if (ac != 1)
+ delete_usage();
+ if (devctl_delete(av[0], force) < 0)
+ err(1, "Failed to delete %s", av[0]);
+ return (0);
+}
+DEVCTL_COMMAND(top, delete, delete);
+
int
main(int ac, char *av[])
{
OpenPOWER on IntegriCloud