Files

29 lines
883 B
Plaintext

--:Minify:--
local kernel=...
local io=kernel.nc.io
local function wrap(id)
return function(op, mode)
if op=="type" then
return "device"
elseif op=="open" then
if kernel.uid~=0 then error("EACCES") end
return io.wrapPeripheral(id)
end
end
end
local ok, peripherals = pcall(io.getPeripherals)
if ok and type(peripherals)=="table" then
for _, id in ipairs(peripherals) do
local obj=wrap(id)
kernel.devfs.data["raw"][tostring(id)]=obj
local okT, typ = pcall(io.getType, id)
typ = (okT and type(typ)=="string") and typ or "unknown"
local typefolder=kernel.devfs.data["raw"]["by-type"][typ]
if not typefolder then typefolder={} end
typefolder[tostring(#table.keys(typefolder)+1)] = obj
kernel.devfs.data["raw"]["by-type"][typ]=typefolder
end
end