From e6f4d404853f017adc716d261f1463276444a3e8 Mon Sep 17 00:00:00 2001 From: sam <30084950+lunaboards-dev@users.noreply.github.com> Date: Sat, 29 May 2021 20:18:59 -0400 Subject: [PATCH] bugfixes --- src/lua/core/drive.lua | 21 ++++++++++++++++++--- src/lua/core/filesystem.lua | 4 ++-- src/lua/core/init.lua | 8 ++++---- src/lua/core/uuidmgr.lua | 17 +++++++++++++---- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/lua/core/drive.lua b/src/lua/core/drive.lua index f3ec1bb..c1e828d 100644 --- a/src/lua/core/drive.lua +++ b/src/lua/core/drive.lua @@ -9,6 +9,19 @@ function drive.register() 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) @@ -20,12 +33,12 @@ function drive.register() end function component.getLabel() - return ent + return name end function component.setLabel(str) -- stub - return ent + return name end function component.readSector(sec) @@ -48,7 +61,9 @@ function drive.register() return blk.size(disk) 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 lprint("Can't open blkdev: "..ent..": "..disk) end diff --git a/src/lua/core/filesystem.lua b/src/lua/core/filesystem.lua index 70d6924..039a846 100644 --- a/src/lua/core/filesystem.lua +++ b/src/lua/core/filesystem.lua @@ -50,7 +50,7 @@ local function concat(pathA, pathB, ...) return canonical(_concat(2, pathA, pathB, ...)) end -function filesystem.register(basePath, uuid) +function filesystem.register(basePath, identifier) checkArg(1, basePath, "string") if not native.fs_exists(basePath) then @@ -156,7 +156,7 @@ function filesystem.register(basePath, uuid) checkArg(1, value, "number") return value --TODO: Implement, use real labels 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 return filesystem diff --git a/src/lua/core/init.lua b/src/lua/core/init.lua index 8e06cbb..a7921b1 100644 --- a/src/lua/core/init.lua +++ b/src/lua/core/init.lua @@ -114,15 +114,15 @@ function main() modules.eeprom.register() modules.gpio.register() modules.internet.start() - modules.filesystem.register("root") + modules.filesystem.register("root", "root") if native.debug and native.platform():match("unix") then - modules.filesystem.register("/", "11111111-1111-1111-1111-111111111111") + modules.filesystem.register("/", "realroot") end 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 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 end diff --git a/src/lua/core/uuidmgr.lua b/src/lua/core/uuidmgr.lua index 76611c8..81e72f0 100644 --- a/src/lua/core/uuidmgr.lua +++ b/src/lua/core/uuidmgr.lua @@ -1,19 +1,28 @@ -local uuidmgr = {} +local uuidmgr = { + fileversion = 0 +} local uuidstorage = {} -local storeheader = "c32BH" +local storeheader = "c36HH" -- oops do local store = io.open("uuidstore.dat", "r") if store then + if native.debug then lprint("DEBUG: Loading uuidstore.dat...") end 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 local uuid, clen, ilen = storeheader:unpack(store:read(storeheader:packsize())) local cname, id = store:read(clen), store:read(ilen) uuidstorage[cname] = uuidstorage[cname] or {} uuidstorage[cname][id] = uuid + if native.debug then lprint(string.format("DEBUG: Found %s:%s's UUID of %s", cname, id, uuid)) end end store:close() end) @@ -49,7 +58,7 @@ function uuidmgr.store() if native.debug then lprint(string.format("DEBUG: Saving %d static UUIDs", #saved_ids)) end - store:write(string.pack("H", #saved_ids)) + store:write(string.pack("IH", uuidmgr.fileversion, #saved_ids)) for i=1, #saved_ids do 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)