3 * 2005-2007 Takahiro Hirofuchi
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "vhci_driver.h"
30 #include "usbip_common.h"
31 #include "usbip_network.h"
34 static const char usbip_detach_usage_string[] =
35 "usbip detach <args>\n"
36 " -p, --port=<port> " USBIP_VHCI_DRV_NAME
37 " port the device is on\n";
39 void usbip_detach_usage(void)
41 printf("usage: %s", usbip_detach_usage_string);
44 static int detach_port(char *port)
48 char path[PATH_MAX+1];
50 unsigned int port_len = strlen(port);
52 for (unsigned int i = 0; i < port_len; i++)
53 if (!isdigit(port[i])) {
54 err("invalid port %s", port);
62 /* remove the port state file */
64 snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", portnum);
67 rmdir(VHCI_STATE_PATH);
69 ret = usbip_vhci_driver_open();
71 err("open vhci_driver");
75 ret = usbip_vhci_detach_device(portnum);
79 usbip_vhci_driver_close();
84 int usbip_detach(int argc, char *argv[])
86 static const struct option opts[] = {
87 { "port", required_argument, NULL, 'p' },
94 opt = getopt_long(argc, argv, "p:", opts, NULL);
101 ret = detach_port(optarg);
109 usbip_detach_usage();