tools/usb/ffs-aio-example/multibuff/host_app/test.c
Source file repositories/reference/linux-study-clean/tools/usb/ffs-aio-example/multibuff/host_app/test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/usb/ffs-aio-example/multibuff/host_app/test.c- Extension
.c- Size
- 4399 bytes
- Lines
- 176
- 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
libusb.hstdio.hstring.hunistd.h
Detected Declarations
struct test_statefunction test_initfunction test_exitfunction main
Annotated Snippet
struct test_state {
libusb_device *found;
libusb_context *ctx;
libusb_device_handle *handle;
int attached;
};
/*
* test_init - initialize test program
*/
int test_init(struct test_state *state)
{
int i, ret;
ssize_t cnt;
libusb_device **list;
state->found = NULL;
state->ctx = NULL;
state->handle = NULL;
state->attached = 0;
ret = libusb_init(&state->ctx);
if (ret) {
printf("cannot init libusb: %s\n", libusb_error_name(ret));
return 1;
}
cnt = libusb_get_device_list(state->ctx, &list);
if (cnt <= 0) {
printf("no devices found\n");
goto error1;
}
for (i = 0; i < cnt; ++i) {
libusb_device *dev = list[i];
struct libusb_device_descriptor desc;
ret = libusb_get_device_descriptor(dev, &desc);
if (ret) {
printf("unable to get device descriptor: %s\n",
libusb_error_name(ret));
goto error2;
}
if (desc.idVendor == VENDOR && desc.idProduct == PRODUCT) {
state->found = dev;
break;
}
}
if (!state->found) {
printf("no devices found\n");
goto error2;
}
ret = libusb_open(state->found, &state->handle);
if (ret) {
printf("cannot open device: %s\n", libusb_error_name(ret));
goto error2;
}
if (libusb_claim_interface(state->handle, 0)) {
ret = libusb_detach_kernel_driver(state->handle, 0);
if (ret) {
printf("unable to detach kernel driver: %s\n",
libusb_error_name(ret));
goto error3;
}
state->attached = 1;
ret = libusb_claim_interface(state->handle, 0);
if (ret) {
printf("cannot claim interface: %s\n",
libusb_error_name(ret));
goto error4;
}
}
return 0;
error4:
if (state->attached == 1)
libusb_attach_kernel_driver(state->handle, 0);
error3:
libusb_close(state->handle);
error2:
libusb_free_device_list(list, 1);
error1:
libusb_exit(state->ctx);
Annotation
- Immediate include surface: `libusb.h`, `stdio.h`, `string.h`, `unistd.h`.
- Detected declarations: `struct test_state`, `function test_init`, `function test_exit`, `function main`.
- 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.