drivers/usb/gadget/function/f_mass_storage.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/f_mass_storage.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/f_mass_storage.c- Extension
.c- Size
- 98173 bytes
- Lines
- 3627
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/blkdev.hlinux/completion.hlinux/dcache.hlinux/delay.hlinux/device.hlinux/fcntl.hlinux/file.hlinux/fs.hlinux/kstrtox.hlinux/kthread.hlinux/sched/signal.hlinux/limits.hlinux/overflow.hlinux/pagemap.hlinux/rwsem.hlinux/slab.hlinux/spinlock.hlinux/string.hlinux/freezer.hlinux/module.hlinux/uaccess.hlinux/unaligned.hlinux/usb/ch9.hlinux/usb/gadget.hlinux/usb/composite.hlinux/nospec.hconfigfs.hstorage_common.hf_mass_storage.h
Detected Declarations
struct fsg_devstruct fsg_commonstruct fsg_commonstruct fsg_devfunction __fsg_is_setfunction exception_in_progressfunction set_bulk_out_req_lengthfunction fsg_set_haltfunction __raise_exceptionfunction raise_exceptionfunction ep0_queuefunction bulk_in_completefunction bulk_out_completefunction _fsg_common_get_max_lunfunction fsg_setupfunction start_transferfunction start_in_transferfunction start_out_transferfunction sleep_threadfunction do_readfunction DPOfunction do_writefunction do_synchronize_cachefunction invalidate_subfunction do_verifyfunction DPOfunction do_inquiryfunction do_request_sensefunction do_read_capacityfunction do_read_capacity_16function do_read_headerfunction do_read_tocfunction do_mode_sensefunction do_start_stopfunction do_prevent_allowfunction do_read_format_capacitiesfunction do_mode_selectfunction halt_bulk_in_endpointfunction wedge_bulk_in_endpointfunction throw_away_datafunction finish_replyfunction send_statusfunction check_commandfunction check_command_size_in_blocksfunction do_scsi_commandfunction received_cbwfunction get_next_commandfunction alloc_request
Annotated Snippet
struct fsg_common {
struct usb_gadget *gadget;
struct usb_composite_dev *cdev;
struct fsg_dev *fsg;
wait_queue_head_t io_wait;
wait_queue_head_t fsg_wait;
/* filesem protects: backing files in use */
struct rw_semaphore filesem;
/* lock protects: state and thread_task */
spinlock_t lock;
struct usb_ep *ep0; /* Copy of gadget->ep0 */
struct usb_request *ep0req; /* Copy of cdev->req */
unsigned int ep0_req_tag;
struct fsg_buffhd *next_buffhd_to_fill;
struct fsg_buffhd *next_buffhd_to_drain;
struct fsg_buffhd *buffhds;
unsigned int fsg_num_buffers;
int cmnd_size;
u8 cmnd[MAX_COMMAND_SIZE];
unsigned int lun;
struct fsg_lun *luns[FSG_MAX_LUNS];
struct fsg_lun *curlun;
unsigned int bulk_out_maxpacket;
enum fsg_state state; /* For exception handling */
unsigned int exception_req_tag;
void *exception_arg;
enum data_direction data_dir;
u32 data_size;
u32 data_size_from_cmnd;
u32 tag;
u32 residue;
u32 usb_amount_left;
unsigned int can_stall:1;
unsigned int free_storage_on_release:1;
unsigned int phase_error:1;
unsigned int short_packet_received:1;
unsigned int bad_lun_okay:1;
unsigned int running:1;
unsigned int sysfs:1;
struct completion thread_notifier;
struct task_struct *thread_task;
/* Gadget's private data. */
void *private_data;
char inquiry_string[INQUIRY_STRING_LEN];
};
struct fsg_dev {
struct usb_function function;
struct usb_gadget *gadget; /* Copy of cdev->gadget */
struct fsg_common *common;
u16 interface_number;
unsigned int bulk_in_enabled:1;
unsigned int bulk_out_enabled:1;
unsigned long atomic_bitflags;
#define IGNORE_BULK_OUT 0
struct usb_ep *bulk_in;
struct usb_ep *bulk_out;
};
static inline int __fsg_is_set(struct fsg_common *common,
const char *func, unsigned line)
{
if (common->fsg)
return 1;
ERROR(common, "common->fsg is NULL in %s at %u\n", func, line);
WARN_ON(1);
return 0;
}
#define fsg_is_set(common) likely(__fsg_is_set(common, __func__, __LINE__))
static inline struct fsg_dev *fsg_from_func(struct usb_function *f)
{
return container_of(f, struct fsg_dev, function);
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/completion.h`, `linux/dcache.h`, `linux/delay.h`, `linux/device.h`, `linux/fcntl.h`, `linux/file.h`, `linux/fs.h`.
- Detected declarations: `struct fsg_dev`, `struct fsg_common`, `struct fsg_common`, `struct fsg_dev`, `function __fsg_is_set`, `function exception_in_progress`, `function set_bulk_out_req_length`, `function fsg_set_halt`, `function __raise_exception`, `function raise_exception`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.