added some basic fs attribute support, stored in memory.
This commit is contained in:
parent
ff56e4f2f2
commit
10f7a53cdd
@ -1,6 +1,23 @@
|
||||
do
|
||||
_G.fs = {}
|
||||
local dfsattr = {read = "*", write = "*"}
|
||||
local fsattr = {}
|
||||
local fT,hT = {},{["_c"]=0}
|
||||
local function getattr(fn,k)
|
||||
if fsattr[fn] then
|
||||
return fsattr[fn][k]
|
||||
else
|
||||
return dfsattr[k]
|
||||
end
|
||||
end
|
||||
local function setattr(fn,k,v)
|
||||
if k:find("\t") or v:find("\t") then return false end
|
||||
if not fsattr[fn] then
|
||||
fsattr[fn] = {}
|
||||
setmetatable(fsattr[fn],{__index=dfsattr})
|
||||
end
|
||||
fsattr[fn][k] = v
|
||||
end
|
||||
function fs.mount(mp,pr)
|
||||
fT[mp] = pr
|
||||
end
|
||||
@ -109,6 +126,59 @@ do
|
||||
local _,d,p = fs.resolve(s)
|
||||
return fT[d].isDirectory(p)
|
||||
end
|
||||
local function flushattr()
|
||||
local f = fs.open("/boot/sys/fsattr.dat","wb")
|
||||
if f then
|
||||
for k,v in pairs(fsattr) do
|
||||
fs.write(f,k.."\t")
|
||||
for l,m in pairs(v) do
|
||||
fs.write(f,"\t"..l.."="..m)
|
||||
end
|
||||
fs.write(f,"\n")
|
||||
end
|
||||
fs.close(f)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
local function readattr()
|
||||
local f=fs.open("/boot/sys/fsattr.dat","rb")
|
||||
if not f then return false end
|
||||
local C=fs.readall(f)
|
||||
fs.close(f)
|
||||
log(C)
|
||||
for line in C:gmatch("[^\n]+") do
|
||||
local ifn = true
|
||||
local fn = ""
|
||||
for kv in line:gmatch("[^\t]+") do
|
||||
if ifn then
|
||||
fn = kv
|
||||
log(fn)
|
||||
ifn = false
|
||||
else
|
||||
log("attr: "..kv)
|
||||
local k,v = kv:match("(.+)%=(.+)")
|
||||
log(tostring(k),tostring(v))
|
||||
setattr(fn,k,v)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
spawn("read fs attributes",readattr)
|
||||
function fs.getattr(fn,k)
|
||||
if fs.exists(fn) then
|
||||
return getattr(fn,k)
|
||||
end
|
||||
return false
|
||||
end
|
||||
function fs.setattr(fn,k,v)
|
||||
if fs.exists(fn) then
|
||||
local res={setattr(fn,k,v)}
|
||||
flushattr()
|
||||
return table.unpack(res)
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
function fs.cd(p)
|
||||
if p:sub(1,1) ~= "/" then
|
||||
|
Loading…
Reference in New Issue
Block a user