forked from jnode/jnode
-
Notifications
You must be signed in to change notification settings - Fork 0
RamDisk Driver
opencode-agent[bot] edited this page May 10, 2026
·
2 revisions
Virtual block device using RAM as backing store for testing and initrd.
The RamDisk Driver provides a software-only block device that uses system RAM as its backing store. It implements the FSBlockDeviceAPI interface, making it appear as a regular block device to the filesystem layer. This enables filesystem testing without physical disk hardware and can serve as a RAM disk for boot-time initialization.
| File | Purpose |
|---|---|
RamDiskDriver.java |
Main driver implementation, extends Driver and implements FSBlockDeviceAPI
|
RamDiskDevice.java |
Device class extending Device with size parameter |
RamDiskCommand.java |
Shell command for creating/managing RAM disks at runtime |
RamDiskDriver extends Driver
└── implements FSBlockDeviceAPI
├── read(long devOffset, ByteBuffer dest)
├── write(long devOffset, ByteBuffer src)
├── getLength()
├── getSectorSize() -> 512
├── flush()
└── getPartitionTableEntry() -> null
public RamDiskDriver(String deviceName) {
this.devName = deviceName;
}
protected void startDevice() throws DriverException {
this.device = (RamDiskDevice) getDevice();
// Register with DeviceManager
if (this.data == null) {
this.data = new byte[device.getSize()];
this.device.registerAPI(BlockDeviceAPI.class, this);
} else {
this.device.registerAPI(FSBlockDeviceAPI.class, this);
}
}The driver uses a simple byte[] array to store all data:
private byte[] data;
public void read(long devOffset, ByteBuffer dest) {
dest.put(this.data, (int) devOffset, dest.remaining());
}
public void write(long devOffset, ByteBuffer src) {
src.get(this.data, (int) devOffset, src.remaining());
}This provides fast read/write performance since all operations are in-memory.
The RamDisk Driver is extensively used in the test framework (fs/src/test/) to test filesystem implementations without requiring real disk hardware:
RamDiskDevice device = new RamDiskDevice(bus, name, size);
RamDiskDriver driver = new RamDiskDriver(name);
init(null, driver, device);The RamDiskCommand allows shell-based RAM disk creation:
RamDiskDevice dev = new RamDiskDevice(null, "dummy", size);
dev.setDriver(new RamDiskDriver(null));- No Persistence: Data is lost on system reboot or power cycle
- Memory Consumption: RAM disks consume heap memory proportional to their size
-
No Partition Support:
getPartitionTableEntry()returnsnull - Fixed Sector Size: Always returns 512 bytes regardless of actual device size
-
No Flush Implementation:
flush()is a no-op since RAM requires no syncing
- Block-Device-Layer - Parent block device abstraction
- VirtualDevices - Virtual device framework
- Driver-Framework - Device driver infrastructure
- Testing - Test framework using RamDisk
- Boot-Sequence - Can use RamDisk for initrd