diff options
author | John Baldwin <jhb@FreeBSD.org> | 2016-04-27 16:33:17 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2016-04-27 16:33:17 +0000 |
commit | 88eb5c506d00e446dcfeb0f84b36d5132a8d9f6b (patch) | |
tree | 9d890003db3954532ce3e8f39ed0184a8e9983dc /usr.sbin | |
parent | 3d0338a09278a0cc38785321f102de9775c57ed3 (diff) | |
download | src-88eb5c506d00e446dcfeb0f84b36d5132a8d9f6b.tar.gz src-88eb5c506d00e446dcfeb0f84b36d5132a8d9f6b.zip |
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
Notes
Notes:
svn path=/head/; revision=298709
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/devctl/devctl.8 | 16 | ||||
-rw-r--r-- | usr.sbin/devctl/devctl.c | 40 |
2 files changed, 54 insertions, 2 deletions
diff --git a/usr.sbin/devctl/devctl.8 b/usr.sbin/devctl/devctl.8 index bfa6dcc62031..ec8abaff233a 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 545224b502d1..824b9075c04e 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[]) { |