tools/usb/usbip/libsrc/usbip_host_common.c
Source file repositories/reference/linux-study-clean/tools/usb/usbip/libsrc/usbip_host_common.c
File Facts
- System
- Linux kernel
- Corpus path
tools/usb/usbip/libsrc/usbip_host_common.c- Extension
.c- Size
- 6498 bytes
- Lines
- 286
- 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
sys/types.hsys/stat.hfcntl.herrno.hunistd.hlibudev.husbip_common.husbip_host_common.hlist.hsysfs_utils.h
Detected Declarations
function read_attr_usbip_statusfunction refresh_exported_devicesfunction udev_list_entry_foreachfunction usbip_exported_device_destroyfunction list_for_each_safefunction usbip_generic_driver_openfunction usbip_generic_driver_closefunction usbip_generic_refresh_device_listfunction usbip_export_devicefunction list_for_each
Annotated Snippet
if (hdriver->ops.is_my_device(dev)) {
edev = usbip_exported_device_new(hdriver, path);
if (!edev) {
dbg("usbip_exported_device_new failed");
continue;
}
list_add(&edev->node, &hdriver->edev_list);
hdriver->ndevs++;
}
}
if (hdriver->ndevs == 0)
info("Please load appropriate modules or export devices.");
return 0;
}
static void usbip_exported_device_destroy(struct list_head *devs)
{
struct list_head *i, *tmp;
struct usbip_exported_device *edev;
list_for_each_safe(i, tmp, devs) {
edev = list_entry(i, struct usbip_exported_device, node);
list_del(i);
free(edev);
}
}
int usbip_generic_driver_open(struct usbip_host_driver *hdriver)
{
int rc;
udev_context = udev_new();
if (!udev_context) {
err("udev_new failed");
return -1;
}
rc = refresh_exported_devices(hdriver);
if (rc < 0)
goto err;
return 0;
err:
udev_unref(udev_context);
return -1;
}
void usbip_generic_driver_close(struct usbip_host_driver *hdriver)
{
if (!hdriver)
return;
usbip_exported_device_destroy(&hdriver->edev_list);
udev_unref(udev_context);
}
int usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver)
{
int rc;
usbip_exported_device_destroy(&hdriver->edev_list);
hdriver->ndevs = 0;
INIT_LIST_HEAD(&hdriver->edev_list);
rc = refresh_exported_devices(hdriver);
if (rc < 0)
return -1;
return 0;
}
int usbip_export_device(struct usbip_exported_device *edev, int sockfd)
{
char attr_name[] = "usbip_sockfd";
char sockfd_attr_path[SYSFS_PATH_MAX];
int size;
char sockfd_buff[30];
int ret;
if (edev->status != SDEV_ST_AVAILABLE) {
dbg("device not available: %s", edev->udev.busid);
switch (edev->status) {
case SDEV_ST_ERROR:
dbg("status SDEV_ST_ERROR");
ret = ST_DEV_ERR;
break;
Annotation
- Immediate include surface: `sys/types.h`, `sys/stat.h`, `fcntl.h`, `errno.h`, `unistd.h`, `libudev.h`, `usbip_common.h`, `usbip_host_common.h`.
- Detected declarations: `function read_attr_usbip_status`, `function refresh_exported_devices`, `function udev_list_entry_foreach`, `function usbip_exported_device_destroy`, `function list_for_each_safe`, `function usbip_generic_driver_open`, `function usbip_generic_driver_close`, `function usbip_generic_refresh_device_list`, `function usbip_export_device`, `function list_for_each`.
- 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.