drivers/block/floppy.c
Source file repositories/reference/linux-study-clean/drivers/block/floppy.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/floppy.c- Extension
.c- Size
- 137024 bytes
- Lines
- 5028
- Domain
- Driver Families
- Bucket
- drivers/block
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/async.hlinux/bio.hlinux/compat.hlinux/delay.hlinux/errno.hlinux/fcntl.hlinux/fd.hlinux/fdreg.hlinux/fs.hlinux/hdreg.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/ioport.hlinux/jiffies.hlinux/kernel.hlinux/major.hlinux/mc146818rtc.hlinux/mm.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/sched.hlinux/slab.hlinux/string.hlinux/timer.hlinux/uaccess.hlinux/workqueue.hasm/dma.hasm/irq.hasm/floppy.h
Detected Declarations
struct fparmstruct compat_floppy_drive_paramsstruct compat_floppy_drive_structstruct compat_floppy_fdc_statestruct compat_floppy_write_errorsstruct rb0_cbdatafunction fallback_on_nodma_allocfunction fdc_inbfunction fdc_outbfunction drive_no_geomfunction fd_ejectfunction set_debugtfunction debugtfunction set_debugtfunction is_alivefunction __reschedule_timeoutfunction reschedule_timeoutfunction loopfunction is_selectedfunction is_ready_statefunction set_dorfunction twaddlefunction reset_fdc_infofunction set_fdcfunction lock_fdcfunction unlock_fdcfunction motor_off_callbackfunction floppy_offfunction scandrivesfunction emptyfunction floppy_work_workfnfunction schedule_bhfunction fd_timer_workfnfunction cancel_activityfunction fd_watchdogfunction main_command_interruptfunction fd_wait_for_completionfunction setup_DMAfunction wait_til_readyfunction output_bytefunction resultfunction need_more_outputfunction perpendicular_modefunction fdc_configurefunction afunction commandfunction tell_sectorfunction print_errors
Annotated Snippet
static const struct blk_mq_ops floppy_mq_ops = {
.queue_rq = floppy_queue_rq,
};
static struct platform_device floppy_device[N_DRIVE];
static bool registered[N_DRIVE];
static bool floppy_available(int drive)
{
if (!(allowed_drive_mask & (1 << drive)))
return false;
if (fdc_state[FDC(drive)].version == FDC_NONE)
return false;
return true;
}
static int floppy_alloc_disk(unsigned int drive, unsigned int type)
{
struct queue_limits lim = {
.max_hw_sectors = 64,
.features = BLK_FEAT_ROTATIONAL,
};
struct gendisk *disk;
disk = blk_mq_alloc_disk(&tag_sets[drive], &lim, NULL);
if (IS_ERR(disk))
return PTR_ERR(disk);
disk->major = FLOPPY_MAJOR;
disk->first_minor = TOMINOR(drive) | (type << 2);
disk->minors = 1;
disk->fops = &floppy_fops;
disk->flags |= GENHD_FL_NO_PART;
disk->events = DISK_EVENT_MEDIA_CHANGE;
if (type)
sprintf(disk->disk_name, "fd%d_type%d", drive, type);
else
sprintf(disk->disk_name, "fd%d", drive);
/* to be cleaned up... */
disk->private_data = (void *)(long)drive;
disk->flags |= GENHD_FL_REMOVABLE;
disks[drive][type] = disk;
return 0;
}
static DEFINE_MUTEX(floppy_probe_lock);
static void floppy_probe(dev_t dev)
{
unsigned int drive = (MINOR(dev) & 3) | ((MINOR(dev) & 0x80) >> 5);
unsigned int type = (MINOR(dev) >> 2) & 0x1f;
if (drive >= N_DRIVE || !floppy_available(drive) ||
type >= ARRAY_SIZE(floppy_type))
return;
mutex_lock(&floppy_probe_lock);
if (disks[drive][type])
goto out;
if (floppy_alloc_disk(drive, type))
goto out;
if (add_disk(disks[drive][type]))
goto cleanup_disk;
out:
mutex_unlock(&floppy_probe_lock);
return;
cleanup_disk:
put_disk(disks[drive][type]);
disks[drive][type] = NULL;
mutex_unlock(&floppy_probe_lock);
}
static int __init do_floppy_init(void)
{
int i, unit, drive, err;
set_debugt();
interruptjiffies = resultjiffies = jiffies;
#if defined(CONFIG_PPC)
if (check_legacy_ioport(FDC1))
return -ENODEV;
#endif
raw_cmd = NULL;
floppy_wq = alloc_ordered_workqueue("floppy", 0);
if (!floppy_wq)
Annotation
- Immediate include surface: `linux/async.h`, `linux/bio.h`, `linux/compat.h`, `linux/delay.h`, `linux/errno.h`, `linux/fcntl.h`, `linux/fd.h`, `linux/fdreg.h`.
- Detected declarations: `struct fparm`, `struct compat_floppy_drive_params`, `struct compat_floppy_drive_struct`, `struct compat_floppy_fdc_state`, `struct compat_floppy_write_errors`, `struct rb0_cbdata`, `function fallback_on_nodma_alloc`, `function fdc_inb`, `function fdc_outb`, `function drive_no_geom`.
- Atlas domain: Driver Families / drivers/block.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.