drivers/usb/storage/usb.c
Source file repositories/reference/linux-study-clean/drivers/usb/storage/usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/storage/usb.c- Extension
.c- Size
- 33971 bytes
- Lines
- 1259
- 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/sched.hlinux/errno.hlinux/module.hlinux/slab.hlinux/kthread.hlinux/mutex.hlinux/utsname.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_device.husb.hlinux/usb/hcd.hscsiglue.htransport.hprotocol.hdebug.hinitializers.hsierra_ms.hoption_ms.huas-detect.hunusual_devs.h
Detected Declarations
function parse_delay_strfunction format_delay_msfunction delay_use_setfunction delay_use_getfunction us_set_lock_classfunction us_set_lock_classfunction usb_stor_resumefunction usb_stor_reset_resumefunction usb_stor_pre_resetfunction usb_stor_post_resetfunction arrayfunction usb_stor_control_threadfunction associate_devfunction usb_stor_adjust_quirksfunction get_device_infofunction get_transportfunction get_protocolfunction get_pipesfunction usb_stor_acquire_resourcesfunction usb_stor_release_resourcesfunction dissociate_devfunction quiesce_and_remove_hostfunction release_everythingfunction usb_stor_scan_dworkfunction usb_stor_sg_tablesizefunction usb_stor_probe1function bus_to_hcdfunction usb_stor_probe2function usb_stor_disconnectfunction storage_probeexport usb_stor_suspendexport usb_stor_resumeexport usb_stor_reset_resumeexport usb_stor_pre_resetexport usb_stor_post_resetexport fill_inquiry_responseexport usb_stor_adjust_quirksexport usb_stor_probe1export usb_stor_probe2export usb_stor_disconnect
Annotated Snippet
if (srb == NULL) {
scsi_unlock(host);
mutex_unlock(&us->dev_mutex);
usb_stor_dbg(us, "-- exiting\n");
break;
}
/* has the command timed out *already* ? */
if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
srb->result = DID_ABORT << 16;
goto SkipForAbort;
}
scsi_unlock(host);
/*
* reject the command if the direction indicator
* is UNKNOWN
*/
if (srb->sc_data_direction == DMA_BIDIRECTIONAL) {
usb_stor_dbg(us, "UNKNOWN data direction\n");
srb->result = DID_ERROR << 16;
}
/*
* reject if target != 0 or if LUN is higher than
* the maximum known LUN
*/
else if (srb->device->id &&
!(us->fflags & US_FL_SCM_MULT_TARG)) {
usb_stor_dbg(us, "Bad target number (%d:%llu)\n",
srb->device->id,
srb->device->lun);
srb->result = DID_BAD_TARGET << 16;
}
else if (srb->device->lun > us->max_lun) {
usb_stor_dbg(us, "Bad LUN (%d:%llu)\n",
srb->device->id,
srb->device->lun);
srb->result = DID_BAD_TARGET << 16;
}
/*
* Handle those devices which need us to fake
* their inquiry data
*/
else if ((srb->cmnd[0] == INQUIRY) &&
(us->fflags & US_FL_FIX_INQUIRY)) {
unsigned char data_ptr[36] = {
0x00, 0x80, 0x02, 0x02,
0x1F, 0x00, 0x00, 0x00};
usb_stor_dbg(us, "Faking INQUIRY command\n");
fill_inquiry_response(us, data_ptr, 36);
srb->result = SAM_STAT_GOOD;
}
/* we've got a command, let's do it! */
else {
US_DEBUG(usb_stor_show_command(us, srb));
us->proto_handler(srb, us);
usb_mark_last_busy(us->pusb_dev);
}
/* lock access to the state */
scsi_lock(host);
/* was the command aborted? */
if (srb->result == DID_ABORT << 16) {
SkipForAbort:
usb_stor_dbg(us, "scsi command aborted\n");
srb = NULL; /* Don't call scsi_done() */
}
/*
* If an abort request was received we need to signal that
* the abort has finished. The proper test for this is
* the TIMED_OUT flag, not srb->result == DID_ABORT, because
* the timeout might have occurred after the command had
* already completed with a different result code.
*/
if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
complete(&(us->notify));
/* Allow USB transfers to resume */
clear_bit(US_FLIDX_ABORTING, &us->dflags);
clear_bit(US_FLIDX_TIMED_OUT, &us->dflags);
}
Annotation
- Immediate include surface: `linux/sched.h`, `linux/errno.h`, `linux/module.h`, `linux/slab.h`, `linux/kthread.h`, `linux/mutex.h`, `linux/utsname.h`, `scsi/scsi.h`.
- Detected declarations: `function parse_delay_str`, `function format_delay_ms`, `function delay_use_set`, `function delay_use_get`, `function us_set_lock_class`, `function us_set_lock_class`, `function usb_stor_resume`, `function usb_stor_reset_resume`, `function usb_stor_pre_reset`, `function usb_stor_post_reset`.
- 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.