This commit is contained in:
sam 2021-05-29 20:18:59 -04:00
parent ecbee6c83a
commit e6f4d40485
4 changed files with 37 additions and 13 deletions

View File

@ -9,6 +9,19 @@ function drive.register()
lprint("Attempting to open: "..ent) lprint("Attempting to open: "..ent)
local ok, disk = pcall(blk.open, ent) local ok, disk = pcall(blk.open, ent)
if ok then 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 = {} local component = {}
function component.readByte(offset) function component.readByte(offset)
@ -20,12 +33,12 @@ function drive.register()
end end
function component.getLabel() function component.getLabel()
return ent return name
end end
function component.setLabel(str) function component.setLabel(str)
-- stub -- stub
return ent return name
end end
function component.readSector(sec) function component.readSector(sec)
@ -48,7 +61,9 @@ function drive.register()
return blk.size(disk) return blk.size(disk)
end end
modules.component.api.register(modules.uuidmgr.lookup("drive", ent), "drive", component) local gid = wwid or (vendor.." "..name.." "..ent)
modules.component.api.register(modules.uuidmgr.lookup("drive", gid), "drive", component)
else else
lprint("Can't open blkdev: "..ent..": "..disk) lprint("Can't open blkdev: "..ent..": "..disk)
end end

View File

@ -50,7 +50,7 @@ local function concat(pathA, pathB, ...)
return canonical(_concat(2, pathA, pathB, ...)) return canonical(_concat(2, pathA, pathB, ...))
end end
function filesystem.register(basePath, uuid) function filesystem.register(basePath, identifier)
checkArg(1, basePath, "string") checkArg(1, basePath, "string")
if not native.fs_exists(basePath) then if not native.fs_exists(basePath) then
@ -156,7 +156,7 @@ function filesystem.register(basePath, uuid)
checkArg(1, value, "number") checkArg(1, value, "number")
return value --TODO: Implement, use real labels return value --TODO: Implement, use real labels
end end
return modules.component.api.register(modules.uuidmgr.lookup("filesystem", basePath), "filesystem", fs) return modules.component.api.register(modules.uuidmgr.lookup("filesystem", basePath or identifier), "filesystem", fs)
end end
return filesystem return filesystem

View File

@ -114,15 +114,15 @@ function main()
modules.eeprom.register() modules.eeprom.register()
modules.gpio.register() modules.gpio.register()
modules.internet.start() modules.internet.start()
modules.filesystem.register("root") modules.filesystem.register("root", "root")
if native.debug and native.platform():match("unix") then if native.debug and native.platform():match("unix") then
modules.filesystem.register("/", "11111111-1111-1111-1111-111111111111") modules.filesystem.register("/", "realroot")
end end
if native.platform():match("unix") then if native.platform():match("unix") then
modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid()) modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid(), "tmpfs")
else else
native.fs_mkdir("tmp") native.fs_mkdir("tmp")
modules.computer.tmp = modules.filesystem.register("tmp/lupi-" .. modules.random.uuid()) modules.computer.tmp = modules.filesystem.register("tmp/lupi-" .. modules.random.uuid(), "tmpfs")
--TODO: cleaning hook or something --TODO: cleaning hook or something
end end

View File

@ -1,19 +1,28 @@
local uuidmgr = {} local uuidmgr = {
fileversion = 0
}
local uuidstorage = {} local uuidstorage = {}
local storeheader = "c32BH" local storeheader = "c36HH" -- oops
do do
local store = io.open("uuidstore.dat", "r") local store = io.open("uuidstore.dat", "r")
if store then if store then
if native.debug then lprint("DEBUG: Loading uuidstore.dat...") end
pcall(function() pcall(function()
local count = string.unpack("H", store:read(2)) local version, count = string.unpack("IH", store:read(6))
if native.debug then lprint(string.format("DEBUG: File version %u, count %u", version, count)) end
if version > uuidmgr.fileversion then
lprint("ERROR: Invalid version!")
error("invalid version")
end
for i=1, count do for i=1, count do
local uuid, clen, ilen = storeheader:unpack(store:read(storeheader:packsize())) local uuid, clen, ilen = storeheader:unpack(store:read(storeheader:packsize()))
local cname, id = store:read(clen), store:read(ilen) local cname, id = store:read(clen), store:read(ilen)
uuidstorage[cname] = uuidstorage[cname] or {} uuidstorage[cname] = uuidstorage[cname] or {}
uuidstorage[cname][id] = uuid uuidstorage[cname][id] = uuid
if native.debug then lprint(string.format("DEBUG: Found %s:%s's UUID of %s", cname, id, uuid)) end
end end
store:close() store:close()
end) end)
@ -49,7 +58,7 @@ function uuidmgr.store()
if native.debug then if native.debug then
lprint(string.format("DEBUG: Saving %d static UUIDs", #saved_ids)) lprint(string.format("DEBUG: Saving %d static UUIDs", #saved_ids))
end end
store:write(string.pack("H", #saved_ids)) store:write(string.pack("IH", uuidmgr.fileversion, #saved_ids))
for i=1, #saved_ids do for i=1, #saved_ids do
local uuid, component, id = saved_ids[i].uuid, saved_ids[i].component, saved_ids[i].id local uuid, component, id = saved_ids[i].uuid, saved_ids[i].component, saved_ids[i].id
store:write(storeheader:pack(uuid, #component, #id),component,id) store:write(storeheader:pack(uuid, #component, #id),component,id)