LuPPC/src/lua/core/drive.lua

59 lines
1.3 KiB
Lua

local drive = {}
function drive.register()
local list = native.fs_list("/sys/block")
for _, ent in ipairs(list) do
-- Match hard drives. floppy drives, an rewindable tape drives
if (ent:match("sd%a%d*") or ent:match("hd%a%d*") or ent:match("fd%d+") or ent:match("n?st%d+[lma]?") or ent:match("n?ht%d+[lma]?")) then
--if true then
lprint("Attempting to open: "..ent)
local ok, disk = pcall(blk.open, ent)
if ok then
local component = {}
function component.readByte(offset)
return blk.readbyte(disk, offset)
end
function component.writeByte(offset, value)
return blk.writebyte(disk, offset, value)
end
function component.getLabel()
return ent
end
function component.setLabel(str)
-- stub
return ent
end
function component.readSector(sec)
return blk.readsector(disk, sec)
end
function component.writeSector(sec, val)
return blk.writesector(disk, sec, val)
end
function component.getPlatterCount()
return blk.platcount(disk)
end
function component.getSectorSize()
return blk.secsize(disk)
end
function component.getCapacity()
return blk.size(disk)
end
modules.component.api.register("Block:"..ent, "drive", component)
else
lprint("Can't open blkdev: "..ent..": "..disk)
end
end
end
end
return drive