tools/usb/usbip/src/usbipd.c
Source file repositories/reference/linux-study-clean/tools/usb/usbip/src/usbipd.c
File Facts
- System
- Linux kernel
- Corpus path
tools/usb/usbip/src/usbipd.c- Extension
.c- Size
- 14481 bytes
- Lines
- 687
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
../config.herrno.hunistd.hnetdb.hstring.hstdlib.hsys/types.hsys/stat.harpa/inet.hsys/socket.hnetinet/in.htcpd.hgetopt.hsignal.hpoll.husbip_host_driver.husbip_host_common.husbip_device_driver.husbip_common.husbip_network.hlist.h
Detected Declarations
function usbipd_helpfunction recv_request_importfunction list_for_eachfunction send_reply_devlistfunction list_for_eachfunction recv_request_devlistfunction recv_pdufunction tcpd_authfunction do_acceptfunction process_requestfunction addrinfo_to_textfunction listen_all_addrinfofunction signal_handlerfunction set_signalfunction write_pid_filefunction remove_pid_filefunction do_standalone_modefunction main
Annotated Snippet
if (!strncmp(req.busid, edev->udev.busid, SYSFS_BUS_ID_SIZE)) {
info("found requested device: %s", req.busid);
found = 1;
break;
}
}
if (found) {
/* should set TCP_NODELAY for usbip */
usbip_net_set_nodelay(sockfd);
/* export device needs a TCP/IP socket descriptor */
status = usbip_export_device(edev, sockfd);
if (status < 0)
status = ST_NA;
} else {
info("requested device not found: %s", req.busid);
status = ST_NODEV;
}
rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT, status);
if (rc < 0) {
dbg("usbip_net_send_op_common failed: %#0x", OP_REP_IMPORT);
return -1;
}
if (status) {
dbg("import request busid %s: failed", req.busid);
return -1;
}
memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev));
usbip_net_pack_usb_device(1, &pdu_udev);
rc = usbip_net_send(sockfd, &pdu_udev, sizeof(pdu_udev));
if (rc < 0) {
dbg("usbip_net_send failed: devinfo");
return -1;
}
dbg("import request busid %s: complete", req.busid);
return 0;
}
static int send_reply_devlist(int connfd)
{
struct usbip_exported_device *edev;
struct usbip_usb_device pdu_udev;
struct usbip_usb_interface pdu_uinf;
struct op_devlist_reply reply;
struct list_head *j;
int rc, i;
/*
* Exclude devices that are already exported to a client from
* the exportable device list to avoid:
* - import requests for devices that are exported only to
* fail the request.
* - revealing devices that are imported by a client to
* another client.
*/
reply.ndev = 0;
/* number of exported devices */
list_for_each(j, &driver->edev_list) {
edev = list_entry(j, struct usbip_exported_device, node);
if (edev->status != SDEV_ST_USED)
reply.ndev += 1;
}
info("exportable devices: %d", reply.ndev);
rc = usbip_net_send_op_common(connfd, OP_REP_DEVLIST, ST_OK);
if (rc < 0) {
dbg("usbip_net_send_op_common failed: %#0x", OP_REP_DEVLIST);
return -1;
}
PACK_OP_DEVLIST_REPLY(1, &reply);
rc = usbip_net_send(connfd, &reply, sizeof(reply));
if (rc < 0) {
dbg("usbip_net_send failed: %#0x", OP_REP_DEVLIST);
return -1;
}
list_for_each(j, &driver->edev_list) {
edev = list_entry(j, struct usbip_exported_device, node);
if (edev->status == SDEV_ST_USED)
continue;
Annotation
- Immediate include surface: `../config.h`, `errno.h`, `unistd.h`, `netdb.h`, `string.h`, `stdlib.h`, `sys/types.h`, `sys/stat.h`.
- Detected declarations: `function usbipd_help`, `function recv_request_import`, `function list_for_each`, `function send_reply_devlist`, `function list_for_each`, `function recv_request_devlist`, `function recv_pdu`, `function tcpd_auth`, `function do_accept`, `function process_request`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.