int usbip_unbind(int argc, char *argv[]) { static const struct option opts[] = { { "busid", required_argument, NULL, 'b' }, { NULL, 0, NULL, 0 } }; int opt; int ret = -1; for (;;) { opt = getopt_long(argc, argv, "b:", opts, NULL); if (opt == -1) break; switch (opt) { case 'b': ret = use_device_by_other(optarg); goto out; default: goto err_out; } } err_out: usbip_unbind_usage(); out: return ret; }
static int export_to(char *host, char *busid) { int ret; if( host == NULL ) { printf( "no host given\n\n"); show_help(); return -1; } if( busid == NULL ) { /* XXX print device list and ask for busnumber, if none is * given */ printf( "no busid given, use --busid switch\n\n"); show_help(); return -1; } ret = use_device_by_usbip(busid); if( ret != 0 ) { printf( "could not bind driver to usbip\n"); return -1; } printf( "DEBUG: exporting device '%s' to '%s'\n", busid, host ); ret = export_busid_to_host(host, busid); /* usbip_export.[ch] */ if( ret != 0 ) { printf( "could not export device to host\n" ); printf( " host: %s, device: %s\n", host, busid ); use_device_by_other(busid); return -1; } return 0; }
static int unexport_from(char *host, char *busid) { int ret; if( host == NULL ) { logerr( "no host given\n\n"); show_help(); return -1; } if( busid == NULL ) { /* XXX print device list and ask for busnumber, if none is * given */ logerr( "no busid given, use --busid switch\n\n"); show_help(); return -1; } logmsg("unexport_from: host: '%s', busid: '%s'", host, busid); printf( "DEBUG: unexporting device '%s' from '%s'\n", busid, host ); ret = unexport_busid_from_host(host, busid); /* usbip_export.[ch] */ if( ret != 0 ) { logerr( "could not unexport device from host\n" ); logerr( " host: %s, device: %s\n", host, busid ); } ret = use_device_by_other(busid); if( ret != 0 ) { logerr( "could not unbind device from usbip\n"); return -1; } return 0; }
static int unexport_from(char *host, char *busid) { int ret; if (!host || !busid) g_error("no host or no busid\n"); g_message("unexport_from: host: '%s', busid: '%s'", host, busid); ret = unexport_busid_from_host(host, busid); /* usbip_export.[ch] */ if( ret != 0 ) { err( "could not unexport device from host\n" ); err( " host: %s, device: %s\n", host, busid ); } ret = use_device_by_other(busid); if (ret < 0) g_error("could not unbind device from usbip\n"); return 0; }
int main(int argc, char **argv) { char *busid = NULL; char *remote_host = NULL; enum { cmd_unknown = 0, cmd_use_by_usbip, cmd_use_by_other, cmd_list, cmd_list2, cmd_allusbip, cmd_export_to, cmd_unexport, cmd_help, } cmd = cmd_unknown; if (geteuid() != 0) g_warning("running non-root?"); for (;;) { int c; int index = 0; c = getopt_long(argc, argv, "u:o:hlLae:x:b:", longopts, &index); if (c == -1) break; switch (c) { case 'u': cmd = cmd_use_by_usbip; busid = optarg; break; case 'o' : cmd = cmd_use_by_other; busid = optarg; break; case 'l' : cmd = cmd_list; break; case 'L' : cmd = cmd_list2; break; case 'a' : cmd = cmd_allusbip; break; case 'b': busid = optarg; break; case 'e': cmd = cmd_export_to; remote_host = optarg; break; case 'x': cmd = cmd_unexport; remote_host = optarg; break; case 'h': /* fallthrough */ case '?': cmd = cmd_help; break; default: g_error("getopt"); } //if (cmd) // break; } switch (cmd) { case cmd_use_by_usbip: use_device_by_usbip(busid); break; case cmd_use_by_other: use_device_by_other(busid); break; case cmd_list: show_devices(); break; case cmd_list2: show_devices2(); break; #if 0 case cmd_allusbip: allusbip(); break; case cmd_export_to: export_to(remote_host, busid); break; case cmd_unexport: unexport_from(remote_host, busid); break; #endif case cmd_help: /* fallthrough */ case cmd_unknown: show_help(); break; default: g_error("NOT REACHED"); } return 0; }