Revision 9516bb47 usb-linux.c
b/usb-linux.c | ||
---|---|---|
115 | 115 |
typedef struct USBHostDevice { |
116 | 116 |
USBDevice dev; |
117 | 117 |
int fd; |
118 |
int hub_fd; |
|
118 | 119 |
|
119 | 120 |
uint8_t descr[8192]; |
120 | 121 |
int descr_len; |
... | ... | |
525 | 526 |
USBHostDevice *s = (USBHostDevice *)dev; |
526 | 527 |
|
527 | 528 |
usb_host_close(s); |
529 |
if (s->hub_fd != -1) { |
|
530 |
close(s->hub_fd); |
|
531 |
} |
|
528 | 532 |
QTAILQ_REMOVE(&hostdevs, s, next); |
529 | 533 |
qemu_remove_exit_notifier(&s->exit); |
530 | 534 |
} |
... | ... | |
1266 | 1270 |
|
1267 | 1271 |
dev->auto_attach = 0; |
1268 | 1272 |
s->fd = -1; |
1273 |
s->hub_fd = -1; |
|
1274 |
|
|
1269 | 1275 |
QTAILQ_INSERT_TAIL(&hostdevs, s, next); |
1270 | 1276 |
s->exit.notify = usb_host_exit_notifier; |
1271 | 1277 |
qemu_add_exit_notifier(&s->exit); |
1272 | 1278 |
usb_host_auto_check(NULL); |
1279 |
|
|
1280 |
#ifdef USBDEVFS_CLAIM_PORT |
|
1281 |
if (s->match.bus_num != 0 && s->match.port != NULL) { |
|
1282 |
char *h, hub_name[64], line[1024]; |
|
1283 |
int hub_addr, portnr, ret; |
|
1284 |
|
|
1285 |
snprintf(hub_name, sizeof(hub_name), "%d-%s", |
|
1286 |
s->match.bus_num, s->match.port); |
|
1287 |
|
|
1288 |
/* try strip off last ".$portnr" to get hub */ |
|
1289 |
h = strrchr(hub_name, '.'); |
|
1290 |
if (h != NULL) { |
|
1291 |
portnr = atoi(h+1); |
|
1292 |
*h = '\0'; |
|
1293 |
} else { |
|
1294 |
/* no dot in there -> it is the root hub */ |
|
1295 |
snprintf(hub_name, sizeof(hub_name), "usb%d", |
|
1296 |
s->match.bus_num); |
|
1297 |
portnr = atoi(s->match.port); |
|
1298 |
} |
|
1299 |
|
|
1300 |
if (!usb_host_read_file(line, sizeof(line), "devnum", |
|
1301 |
hub_name)) { |
|
1302 |
goto out; |
|
1303 |
} |
|
1304 |
if (sscanf(line, "%d", &hub_addr) != 1) { |
|
1305 |
goto out; |
|
1306 |
} |
|
1307 |
|
|
1308 |
if (!usb_host_device_path) { |
|
1309 |
goto out; |
|
1310 |
} |
|
1311 |
snprintf(line, sizeof(line), "%s/%03d/%03d", |
|
1312 |
usb_host_device_path, s->match.bus_num, hub_addr); |
|
1313 |
s->hub_fd = open(line, O_RDWR | O_NONBLOCK); |
|
1314 |
if (s->hub_fd < 0) { |
|
1315 |
goto out; |
|
1316 |
} |
|
1317 |
|
|
1318 |
ret = ioctl(s->hub_fd, USBDEVFS_CLAIM_PORT, &portnr); |
|
1319 |
if (ret < 0) { |
|
1320 |
close(s->hub_fd); |
|
1321 |
s->hub_fd = -1; |
|
1322 |
goto out; |
|
1323 |
} |
|
1324 |
|
|
1325 |
trace_usb_host_claim_port(s->match.bus_num, hub_addr, portnr); |
|
1326 |
} |
|
1327 |
out: |
|
1328 |
#endif |
|
1329 |
|
|
1273 | 1330 |
return 0; |
1274 | 1331 |
} |
1275 | 1332 |
|
Also available in: Unified diff