drivers/usb/gadget/function/storage_common.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/storage_common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/storage_common.c- Extension
.c- Size
- 13633 bytes
- Lines
- 542
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/blkdev.hlinux/file.hlinux/fs.hlinux/kstrtox.hlinux/usb/composite.hstorage_common.h
Detected Declarations
function fsg_lun_closefunction fsg_lun_openfunction fsg_lun_fsync_subfunction store_cdrom_addressfunction fsg_show_rofunction fsg_show_nofuafunction fsg_show_filefunction fsg_show_cdromfunction fsg_show_removablefunction fsg_show_inquiry_stringfunction _fsg_store_rofunction fsg_store_rofunction fsg_store_nofuafunction fsg_store_filefunction fsg_store_cdromfunction fsg_store_removablefunction fsg_store_inquiry_stringfunction fsg_store_forced_ejectexport fsg_intf_descexport fsg_fs_bulk_in_descexport fsg_fs_bulk_out_descexport fsg_fs_functionexport fsg_hs_bulk_in_descexport fsg_hs_bulk_out_descexport fsg_hs_functionexport fsg_ss_bulk_in_descexport fsg_ss_bulk_in_comp_descexport fsg_ss_bulk_out_descexport fsg_ss_bulk_out_comp_descexport fsg_ss_functionexport fsg_lun_closeexport fsg_lun_openexport fsg_lun_fsync_subexport store_cdrom_addressexport fsg_show_roexport fsg_show_nofuaexport fsg_show_fileexport fsg_show_cdromexport fsg_show_removableexport fsg_show_inquiry_stringexport fsg_store_roexport fsg_store_nofuaexport fsg_store_fileexport fsg_store_cdromexport fsg_store_removableexport fsg_store_inquiry_stringexport fsg_store_forced_eject
Annotated Snippet
if (num_sectors >= 256*60*75) {
num_sectors = 256*60*75 - 1;
LINFO(curlun, "file too big: %s\n", filename);
LINFO(curlun, "using only first %d blocks\n",
(int) num_sectors);
}
}
if (num_sectors < min_sectors) {
LINFO(curlun, "file too small: %s\n", filename);
rc = -ETOOSMALL;
goto out;
}
if (fsg_lun_is_open(curlun))
fsg_lun_close(curlun);
curlun->blksize = blksize;
curlun->blkbits = blkbits;
curlun->ro = ro;
curlun->filp = filp;
curlun->file_length = size;
curlun->num_sectors = num_sectors;
LDBG(curlun, "open backing file: %s\n", filename);
return 0;
out:
fput(filp);
return rc;
}
EXPORT_SYMBOL_GPL(fsg_lun_open);
/*-------------------------------------------------------------------------*/
/*
* Sync the file data, don't bother with the metadata.
* This code was copied from fs/buffer.c:sys_fdatasync().
*/
int fsg_lun_fsync_sub(struct fsg_lun *curlun)
{
struct file *filp = curlun->filp;
if (curlun->ro || !filp)
return 0;
return vfs_fsync(filp, 1);
}
EXPORT_SYMBOL_GPL(fsg_lun_fsync_sub);
void store_cdrom_address(u8 *dest, int msf, u32 addr)
{
if (msf) {
/*
* Convert to Minutes-Seconds-Frames.
* Sector size is already set to 2048 bytes.
*/
addr += 2*75; /* Lead-in occupies 2 seconds */
dest[3] = addr % 75; /* Frames */
addr /= 75;
dest[2] = addr % 60; /* Seconds */
addr /= 60;
dest[1] = addr; /* Minutes */
dest[0] = 0; /* Reserved */
} else {
/* Absolute sector */
put_unaligned_be32(addr, dest);
}
}
EXPORT_SYMBOL_GPL(store_cdrom_address);
/*-------------------------------------------------------------------------*/
ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf)
{
return sprintf(buf, "%d\n", fsg_lun_is_open(curlun)
? curlun->ro
: curlun->initially_ro);
}
EXPORT_SYMBOL_GPL(fsg_show_ro);
ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf)
{
return sprintf(buf, "%u\n", curlun->nofua);
}
EXPORT_SYMBOL_GPL(fsg_show_nofua);
ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
char *buf)
{
char *p;
Annotation
- Immediate include surface: `linux/module.h`, `linux/blkdev.h`, `linux/file.h`, `linux/fs.h`, `linux/kstrtox.h`, `linux/usb/composite.h`, `storage_common.h`.
- Detected declarations: `function fsg_lun_close`, `function fsg_lun_open`, `function fsg_lun_fsync_sub`, `function store_cdrom_address`, `function fsg_show_ro`, `function fsg_show_nofua`, `function fsg_show_file`, `function fsg_show_cdrom`, `function fsg_show_removable`, `function fsg_show_inquiry_string`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration 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.