Drives and serial. #3
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user