LuPPC/src/lua/core/drive.lua

59 lines
1.4 KiB
Lua
Raw Normal View History

2021-05-30 07:18:55 +10:00
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
2021-05-30 09:19:29 +10:00
modules.component.api.register(modules.uuidmgr.lookup("drive", ent), "drive", component)
2021-05-30 07:18:55 +10:00
else
lprint("Can't open blkdev: "..ent..": "..disk)
end
end
end
end
return drive