tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c
Source file repositories/reference/linux-study-clean/tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c
File Facts
- System
- Linux kernel
- Corpus path
tools/usb/ffs-aio-example/multibuff/device_app/aio_multibuff.c- Extension
.c- Size
- 9268 bytes
- Lines
- 381
- 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
endian.herrno.hfcntl.hstdarg.hstdio.hstdlib.hstring.hsys/ioctl.hsys/stat.hsys/types.hsys/poll.hunistd.hstdbool.hsys/eventfd.hlibaio.hlinux/usb/functionfs.h
Detected Declarations
struct io_bufferfunction display_eventfunction handle_ep0function init_bufsfunction delete_bufsfunction main
Annotated Snippet
struct io_buffer {
struct iocb **iocb;
unsigned char **buf;
unsigned cnt;
unsigned len;
unsigned requested;
};
/******************** Endpoints handling *******************************/
static void display_event(struct usb_functionfs_event *event)
{
static const char *const names[] = {
[FUNCTIONFS_BIND] = "BIND",
[FUNCTIONFS_UNBIND] = "UNBIND",
[FUNCTIONFS_ENABLE] = "ENABLE",
[FUNCTIONFS_DISABLE] = "DISABLE",
[FUNCTIONFS_SETUP] = "SETUP",
[FUNCTIONFS_SUSPEND] = "SUSPEND",
[FUNCTIONFS_RESUME] = "RESUME",
};
switch (event->type) {
case FUNCTIONFS_BIND:
case FUNCTIONFS_UNBIND:
case FUNCTIONFS_ENABLE:
case FUNCTIONFS_DISABLE:
case FUNCTIONFS_SETUP:
case FUNCTIONFS_SUSPEND:
case FUNCTIONFS_RESUME:
printf("Event %s\n", names[event->type]);
}
}
static void handle_ep0(int ep0, bool *ready)
{
int ret;
struct usb_functionfs_event event;
ret = read(ep0, &event, sizeof(event));
if (!ret) {
perror("unable to read event from ep0");
return;
}
display_event(&event);
switch (event.type) {
case FUNCTIONFS_SETUP:
if (event.u.setup.bRequestType & USB_DIR_IN)
write(ep0, NULL, 0);
else
read(ep0, NULL, 0);
break;
case FUNCTIONFS_ENABLE:
*ready = true;
break;
case FUNCTIONFS_DISABLE:
*ready = false;
break;
default:
break;
}
}
void init_bufs(struct io_buffer *iobuf, unsigned n, unsigned len)
{
unsigned i;
iobuf->buf = malloc(n*sizeof(*iobuf->buf));
iobuf->iocb = malloc(n*sizeof(*iobuf->iocb));
iobuf->cnt = n;
iobuf->len = len;
iobuf->requested = 0;
for (i = 0; i < n; ++i) {
iobuf->buf[i] = malloc(len*sizeof(**iobuf->buf));
iobuf->iocb[i] = malloc(sizeof(**iobuf->iocb));
}
iobuf->cnt = n;
}
void delete_bufs(struct io_buffer *iobuf)
{
unsigned i;
for (i = 0; i < iobuf->cnt; ++i) {
free(iobuf->buf[i]);
free(iobuf->iocb[i]);
}
free(iobuf->buf);
free(iobuf->iocb);
}
Annotation
- Immediate include surface: `endian.h`, `errno.h`, `fcntl.h`, `stdarg.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/ioctl.h`.
- Detected declarations: `struct io_buffer`, `function display_event`, `function handle_ep0`, `function init_bufs`, `function delete_bufs`, `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.