1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-16 01:28:10 -05:00
OC-PsychOS2/module/devfs.lua

75 lines
1.9 KiB
Lua
Raw Normal View History

2019-10-27 08:34:02 -04:00
devfs = {}
devfs.files = {}
devfs.fds = {}
devfs.nextfd = 0
devfs.component = {}
local function rfalse()
return false
end
local function rzero()
return 0
end
2019-10-27 08:34:02 -04:00
function devfs.component.getLabel()
return "devfs"
end
devfs.component.spaceUsed, devfs.component.spaceTotal, devfs.component.isReadOnly, devfs.component.isDirectory,devfs.component.size, devfs.component.setLabel = rzero, rzero, rfalse, rfalse, rzero, rfalse
2019-10-27 08:34:02 -04:00
function devfs.component.exists(fname)
return devfs.files[fname] ~= nil
end
function devfs.component.list()
local t = {}
for k,v in pairs(devfs.files) do
t[#t+1] = k
end
return t
end
function devfs.component.open(fname, mode)
fname=fname:gsub("/","")
if devfs.files[fname] then
local r,w,c,s = devfs.files[fname](mode)
devfs.fds[devfs.nextfd] = {["read"]=r or rfalse,["write"]=w or rfalse,["seek"]=s or rfalse,["close"]=c or rfalse}
devfs.nextfd = devfs.nextfd + 1
return devfs.nextfd - 1
end
return false
end
function devfs.component.read(fd,count)
if devfs.fds[fd] then
return devfs.fds[fd].read(count)
end
end
function devfs.component.write(fd,data)
if devfs.fds[fd] then
return devfs.fds[fd].write(data)
end
end
function devfs.component.close(fd)
if devfs.fds[fd] then
devfs.fds[fd].close()
end
devfs.fds[fd] = nil
end
function devfs.component.seek(fd,...)
if devfs.fds[fd] then
return devfs.fds[fd].seek(...)
end
end
function devfs.component.remove(fname)
end
2020-03-26 02:25:36 -04:00
devfs.component.address = "devfs"
devfs.component.type = "devfs"
2019-10-27 08:34:02 -04:00
function devfs.register(fname,fopen) -- string function -- -- Register a new devfs node with the name *fname* that will run the function *fopen* when opened. This function should return a function for read, a function for write, function for close, and optionally, a function for seek, in that order.
2019-10-27 08:34:02 -04:00
devfs.files[fname] = fopen
end
2019-11-07 20:42:49 -05:00
fs.makeDirectory("/dev")
fs.mount("/dev",devfs.component)
2019-10-27 08:34:02 -04:00
--#include "module/devfs/null.lua"