Made cowfs in p9k not depend on handles being numbers, closes #1696.

This commit is contained in:
Florian Nücke 2016-03-19 15:01:00 +01:00
parent cc02d69320
commit 755a77d6e4

View File

@ -129,7 +129,7 @@ function new(readfs, writefs)
if not hnd then if not hnd then
return hnd, err return hnd, err
end end
return hnd * 2 return {h=hnd,w=true}
elseif mode:sub(1, 1) == "a" then elseif mode:sub(1, 1) == "a" then
if readfs.exists(path) and not writefs.exists(kernel.modules.vfs.path(path)..".cfsdel."..kernel.modules.vfs.name(path)) then if readfs.exists(path) and not writefs.exists(kernel.modules.vfs.path(path)..".cfsdel."..kernel.modules.vfs.name(path)) then
if readfs.isDirectory(path) then if readfs.isDirectory(path) then
@ -158,7 +158,7 @@ function new(readfs, writefs)
return nil, "Cannot open a directory" return nil, "Cannot open a directory"
end end
local hnd, reason = writefs.open(path, mode) local hnd, reason = writefs.open(path, mode)
return hnd and hnd * 2, reason return hnd and {h=hnd,w=true}, reason
elseif mode:sub(1, 1) == "r" then elseif mode:sub(1, 1) == "r" then
local fs = getFileFS(path) local fs = getFileFS(path)
if not fs then return nil, "file not found" end if not fs then return nil, "file not found" end
@ -166,37 +166,35 @@ function new(readfs, writefs)
return nil, "Cannot open a directory" return nil, "Cannot open a directory"
end end
local hnd = fs.open(path, mode) local hnd = fs.open(path, mode)
hnd = hnd * 2 return hnd and {h=hnd,w=fs==writefs}
if fs == readfs then hnd = hnd + 1 end
return hnd
end end
end end
proxy.seek = function(h, ...) proxy.seek = function(h, ...)
if h % 2 == 0 then if h.w then
return writefs.seek(h / 2, ...) return writefs.seek(h.h, ...)
else else
return readfs.seek((h - 1) / 2, ...) return readfs.seek(h.h, ...)
end end
end end
proxy.read = function(h, ...) proxy.read = function(h, ...)
if h % 2 == 0 then if h.w then
return writefs.read(h / 2, ...) return writefs.read(h.h, ...)
else else
return readfs.read((h - 1) / 2, ...) return readfs.read(h.h, ...)
end end
end end
proxy.close = function(h, ...) proxy.close = function(h, ...)
if h % 2 == 0 then if h.w then
return writefs.close(h / 2, ...) return writefs.close(h.h, ...)
else else
return readfs.close((h - 1) / 2, ...) return readfs.close(h.h, ...)
end end
end end
proxy.write = function(h, ...) proxy.write = function(h, ...)
if h % 2 == 0 then if h.w then
return writefs.write(h / 2, ...) return writefs.write(h.h, ...)
else else
return readfs.write((h - 1) / 2, ...) return readfs.write(h.h, ...)
end end
end end
return proxy return proxy