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 nh = io.open("/sys/block/"..ent.."/device/model", "r") local name = nh:read("*a"):gsub("%s+$", "") nh:close() nh = io.open("/sys/block/"..ent.."/device/vendor", "r") local vendor = nh:read("*a"):gsub("%s+$", "") nh:close() nh = io.open("/sys/block/"..ent.."/device/wwid", "r") local wwid if nh then wwid = nh:read("*a"):gsub("%s+$", "") nh:close() end 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 name end function component.setLabel(str) -- stub return name 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 local gid = wwid or (vendor.." "..name.." "..ent) modules.component.api.register(modules.uuidmgr.lookup("drive", gid), "drive", component) else lprint("Can't open blkdev: "..ent..": "..disk) end end end end return drive