drivers/block/rnull/configfs.rs
Source file repositories/reference/linux-study-clean/drivers/block/rnull/configfs.rs
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/rnull/configfs.rs- Extension
.rs- Size
- 6949 bytes
- Lines
- 262
- Domain
- Driver Families
- Bucket
- drivers/block
- Inferred role
- Driver Families: implementation source
- Status
- source 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 or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct DeviceConfigInner
Annotated Snippet
struct DeviceConfigInner {
powered: bool,
name: CString,
block_size: u32,
rotational: bool,
capacity_mib: u64,
irq_mode: IRQMode,
disk: Option<GenDisk<NullBlkDevice>>,
}
#[vtable]
impl configfs::AttributeOperations<0> for DeviceConfig {
type Data = DeviceConfig;
fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
let mut writer = kernel::str::Formatter::new(page);
if this.data.lock().powered {
writer.write_str("1\n")?;
} else {
writer.write_str("0\n")?;
}
Ok(writer.bytes_written())
}
fn store(this: &DeviceConfig, page: &[u8]) -> Result {
let power_op = kstrtobool_bytes(page)?;
let mut guard = this.data.lock();
if !guard.powered && power_op {
guard.disk = Some(NullBlkDevice::new(
&guard.name,
guard.block_size,
guard.rotational,
guard.capacity_mib,
guard.irq_mode,
)?);
guard.powered = true;
} else if guard.powered && !power_op {
drop(guard.disk.take());
guard.powered = false;
}
Ok(())
}
}
#[vtable]
impl configfs::AttributeOperations<1> for DeviceConfig {
type Data = DeviceConfig;
fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
let mut writer = kernel::str::Formatter::new(page);
writer.write_fmt(fmt!("{}\n", this.data.lock().block_size))?;
Ok(writer.bytes_written())
}
fn store(this: &DeviceConfig, page: &[u8]) -> Result {
if this.data.lock().powered {
return Err(EBUSY);
}
let text = core::str::from_utf8(page)?.trim();
let value = text.parse::<u32>().map_err(|_| EINVAL)?;
GenDiskBuilder::validate_block_size(value)?;
this.data.lock().block_size = value;
Ok(())
}
}
#[vtable]
impl configfs::AttributeOperations<2> for DeviceConfig {
type Data = DeviceConfig;
fn show(this: &DeviceConfig, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
let mut writer = kernel::str::Formatter::new(page);
if this.data.lock().rotational {
writer.write_str("1\n")?;
} else {
writer.write_str("0\n")?;
}
Ok(writer.bytes_written())
}
fn store(this: &DeviceConfig, page: &[u8]) -> Result {
if this.data.lock().powered {
Annotation
- Detected declarations: `struct DeviceConfigInner`.
- Atlas domain: Driver Families / drivers/block.
- Implementation status: source 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.