drivers/memstick/core/ms_block.c
Source file repositories/reference/linux-study-clean/drivers/memstick/core/ms_block.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/memstick/core/ms_block.c- Extension
.c- Size
- 57340 bytes
- Lines
- 2343
- Domain
- Driver Families
- Bucket
- drivers/memstick
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/module.hlinux/blk-mq.hlinux/memstick.hlinux/idr.hlinux/hdreg.hlinux/delay.hlinux/slab.hlinux/random.hlinux/bitmap.hlinux/scatterlist.hlinux/jiffies.hlinux/workqueue.hlinux/mutex.hms_block.h
Detected Declarations
function msb_sg_copyfunction msb_sg_compare_to_bufferfunction msb_get_zone_from_lbafunction msb_get_zone_from_pbafunction msb_validate_used_block_bitmapfunction msb_mark_block_usedfunction msb_mark_block_unusedfunction msb_invalidate_reg_windowfunction msb_run_state_machinefunction msb_exit_state_machinefunction msb_read_int_regfunction msb_read_regsfunction msb_write_regsfunction h_msb_default_badfunction h_msb_read_pagefunction h_msb_write_blockfunction h_msb_send_commandfunction h_msb_resetfunction h_msb_parallel_switchfunction msb_resetfunction msb_switch_to_parallelfunction msb_set_overwrite_flagfunction msb_mark_badfunction msb_mark_page_badfunction msb_erase_blockfunction msb_read_pagefunction msb_read_oobfunction msb_verify_blockfunction msb_write_blockfunction msb_get_free_blockfunction msb_update_blockfunction msb_fix_boot_page_endiannessfunction msb_read_boot_blocksfunction msb_read_bad_block_tablefunction msb_ftl_initializefunction msb_ftl_scanfunction msb_cache_flush_timerfunction msb_cache_discardfunction msb_cache_initfunction msb_cache_flushfunction msb_cache_writefunction msb_cache_readfunction msb_init_cardfunction msb_do_write_requestfunction msb_do_read_requestfunction msb_io_workfunction msb_data_clearfunction msb_bd_getgeo
Annotated Snippet
static const struct blk_mq_ops msb_mq_ops = {
.queue_rq = msb_queue_rq,
};
/* Registers the block device */
static int msb_init_disk(struct memstick_dev *card)
{
struct msb_data *msb = memstick_get_drvdata(card);
struct queue_limits lim = {
.logical_block_size = msb->page_size,
.max_hw_sectors = MS_BLOCK_MAX_PAGES,
.max_segments = MS_BLOCK_MAX_SEGS,
.max_segment_size = MS_BLOCK_MAX_PAGES * msb->page_size,
};
int rc;
unsigned long capacity;
mutex_lock(&msb_disk_lock);
msb->disk_id = idr_alloc(&msb_disk_idr, card, 0, 256, GFP_KERNEL);
mutex_unlock(&msb_disk_lock);
if (msb->disk_id < 0)
return msb->disk_id;
rc = blk_mq_alloc_sq_tag_set(&msb->tag_set, &msb_mq_ops, 2, 0);
if (rc)
goto out_release_id;
msb->disk = blk_mq_alloc_disk(&msb->tag_set, &lim, card);
if (IS_ERR(msb->disk)) {
rc = PTR_ERR(msb->disk);
goto out_free_tag_set;
}
msb->queue = msb->disk->queue;
sprintf(msb->disk->disk_name, "msblk%d", msb->disk_id);
msb->disk->fops = &msb_bdops;
msb->disk->private_data = msb;
capacity = msb->pages_in_block * msb->logical_block_count;
capacity *= (msb->page_size / 512);
set_capacity(msb->disk, capacity);
dbg("Set total disk size to %lu sectors", capacity);
msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM);
if (!msb->io_queue) {
rc = -ENOMEM;
goto out_cleanup_disk;
}
INIT_WORK(&msb->io_work, msb_io_work);
sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1);
if (msb->read_only)
set_disk_ro(msb->disk, 1);
msb_start(card);
rc = device_add_disk(&card->dev, msb->disk, NULL);
if (rc)
goto out_destroy_workqueue;
dbg("Disk added");
return 0;
out_destroy_workqueue:
destroy_workqueue(msb->io_queue);
out_cleanup_disk:
put_disk(msb->disk);
out_free_tag_set:
blk_mq_free_tag_set(&msb->tag_set);
out_release_id:
mutex_lock(&msb_disk_lock);
idr_remove(&msb_disk_idr, msb->disk_id);
mutex_unlock(&msb_disk_lock);
return rc;
}
static int msb_probe(struct memstick_dev *card)
{
struct msb_data *msb;
int rc = 0;
msb = kzalloc_obj(struct msb_data);
if (!msb)
return -ENOMEM;
memstick_set_drvdata(card, msb);
msb->card = card;
spin_lock_init(&msb->q_lock);
rc = msb_init_card(card);
if (rc)
Annotation
- Immediate include surface: `linux/module.h`, `linux/blk-mq.h`, `linux/memstick.h`, `linux/idr.h`, `linux/hdreg.h`, `linux/delay.h`, `linux/slab.h`, `linux/random.h`.
- Detected declarations: `function msb_sg_copy`, `function msb_sg_compare_to_buffer`, `function msb_get_zone_from_lba`, `function msb_get_zone_from_pba`, `function msb_validate_used_block_bitmap`, `function msb_mark_block_used`, `function msb_mark_block_unused`, `function msb_invalidate_reg_window`, `function msb_run_state_machine`, `function msb_exit_state_machine`.
- Atlas domain: Driver Families / drivers/memstick.
- Implementation status: pattern 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.