The disk_drive component controls a floppy disk drive. Its API is intentionally small: it tells you whether a disk is inserted, gives you the inserted floppy's internal filesystem address, and can eject the medium back into the world.
The same component API is used by the standalone disk drive block and the rack-mountable floppy drive.
- Repository:
opencomputers - Component name:
disk_drive - Typical hosts: disk drive block, rack-mounted disk drive
local component = require("component")
local drive = component.disk_drive
if not drive then
error("disk_drive component not available")
end- Syntax:
drive.isEmpty() - Returns:
boolean - Purpose: Checks whether the drive currently contains a floppy disk.
Return value details:
truemeans the drive is empty,falsemeans a disk is inserted.
Example:
if drive.isEmpty() then
print("Insert a floppy first")
else
print("A floppy is present")
end- Syntax:
drive.eject([velocity]) - Returns:
boolean - Purpose: Ejects the inserted floppy disk into the world.
Parameter:
velocity:numberoptional: ejection speed multiplier. Source clamps it to0..1.
Return value details:
truewhen a disk was actually ejected,falsewhen the drive was already empty.
Example:
local ok = drive.eject(0.5)
print("Ejected:", ok)- Syntax:
drive.media() - Returns:
- Success:
string - Failure:
nil, reason
- Success:
- Purpose: Returns the component address of the inserted floppy's internal filesystem.
Failure reason from source: "drive is empty".
This is the usual bridge from a disk drive to a normal filesystem component:
local address, reason = drive.media()
if not address then
print("No disk:", reason)
else
local fs = component.proxy(address)
for name in fs.list("/") do
print(name)
end
endfilesystemcomponentopenos