forked from Hyperion/HyperionOS
NC firmware update (thanks spsf). opencomputers now uses mutiple gpus to speed up rendering and now has net drivers. currently working on kernel memory protections to prevent malicious kernel drivers. spm does not work on opencomputers, this is a known issue i am working on fixing it :D sorry for the slow development.
This commit is contained in:
1 parent
fbaafc7cff
commit
ef4b856ee6
89 files changed
+3955
-563
No files matched your search
@@ -973,6 +973,9 @@ function vfs.symlink(target, linkPath)
|
||||
if type(target) ~= "string" or type(linkPath) ~= "string" then error("EINVAL") end
|
||||
local norm = normalizePath(linkPath)
|
||||
local parent = norm:match("^(.*)/[^/]+$") or "/"
|
||||
if not vfs.exists(parent) then
|
||||
vfs.mkdir(parent)
|
||||
end
|
||||
local disk = resolveMount(linkPath)
|
||||
if disk:isReadOnly() then error("ERDONLY") end
|
||||
if parent == "" then parent = "/" end
|
||||
@@ -1017,7 +1020,7 @@ function vfs.access(path, mode)
|
||||
return true
|
||||
end
|
||||
|
||||
local function updateMeta(path, fn, noFollow)
|
||||
local function updateMeta(path, fn, noFollow, nullify)
|
||||
local real = namei(path, noFollow)
|
||||
local norm = real
|
||||
local parent = norm:match("^(.*)/[^/]+$") or "/"
|
||||
@@ -1042,9 +1045,13 @@ local function updateMeta(path, fn, noFollow)
|
||||
if uf.close then uf.close() end
|
||||
existing = parseMetafile(raw)
|
||||
end
|
||||
local entry = existing[name] or { etype=0, owner=0, group=0, perms=63, cmeta="" }
|
||||
fn(entry)
|
||||
existing[name] = entry
|
||||
if not nullify then
|
||||
local entry = existing[name] or { etype=0, owner=0, group=0, perms=63, cmeta="" }
|
||||
fn(entry)
|
||||
existing[name] = entry
|
||||
else
|
||||
existing[name] = nil
|
||||
end
|
||||
local f = disk:open(mp, "w"); f.write(makeMetafile(existing)); if f.close then f.close() end
|
||||
end
|
||||
|
||||
@@ -1055,7 +1062,7 @@ function vfs.chmod(path, perms)
|
||||
local meta = getFileMeta(path)
|
||||
local euid = (kernel.currentTask and (kernel.currentTask.euid or kernel.currentTask.uid)) or kernel.uid
|
||||
if euid ~= 0 and euid ~= meta.owner then error("EACCES") end
|
||||
updateMeta(path, function(e) e.perms = perms end)
|
||||
updateMeta(path, function(e) e.perms = perms end, nil, not perms)
|
||||
end
|
||||
|
||||
function vfs.fchmod(fd, perms)
|
||||
|
||||
@@ -239,6 +239,7 @@ if kernel.EFI.getEEPROM then
|
||||
write=function(data)
|
||||
if firstwrite then
|
||||
kernel.EFI:setEEPROM(data)
|
||||
firstwrite=false
|
||||
else
|
||||
kernel.EFI:setEEPROM(kernel.EFI:getEEPROM()..data)
|
||||
end
|
||||
@@ -276,6 +277,7 @@ if kernel.EFI.getNvram then
|
||||
write=function(data)
|
||||
if firstwrite then
|
||||
kernel.EFI:setNvram(data)
|
||||
firstwrite=false
|
||||
else
|
||||
kernel.EFI:setNvram(kernel.EFI:getNvram()..data)
|
||||
end
|
||||
|
||||
@@ -1,102 +1,283 @@
|
||||
|
||||
--:Minify:--
|
||||
local kernel = ...
|
||||
local os = os
|
||||
|
||||
if not kernel.config.tmpToDisk then
|
||||
local proxy = {}
|
||||
local data = {}
|
||||
local timestamps = {}
|
||||
|
||||
local now = function() return kernel.EFI:getEpochMs() end
|
||||
|
||||
local function touch(path, created)
|
||||
local time = now()
|
||||
timestamps[path] = timestamps[path] or {
|
||||
created = created or time,
|
||||
modified = time,
|
||||
}
|
||||
timestamps[path].modified = time
|
||||
end
|
||||
|
||||
local function getTimestamp(path)
|
||||
if not timestamps[path] then
|
||||
local time = now()
|
||||
timestamps[path] = {
|
||||
created = time,
|
||||
modified = time,
|
||||
}
|
||||
end
|
||||
return timestamps[path]
|
||||
end
|
||||
|
||||
proxy.address = "tmpfs0000"
|
||||
proxy.isvirt = true
|
||||
proxy.isReadOnly = function() return false end
|
||||
proxy.isReadOnly = function()
|
||||
return false
|
||||
end
|
||||
|
||||
proxy.spaceUsed = function() return 0 end
|
||||
proxy.spaceTotal = function() return 0 end
|
||||
proxy.spaceUsed = function()
|
||||
local function size(step)
|
||||
local total = 0
|
||||
for _, value in pairs(step) do
|
||||
if type(value) == "string" then
|
||||
total = total + #value
|
||||
elseif type(value) == "table" then
|
||||
total = total + size(value)
|
||||
end
|
||||
end
|
||||
return total
|
||||
end
|
||||
return size(data)
|
||||
end
|
||||
|
||||
proxy.spaceTotal = function()
|
||||
return math.huge
|
||||
end
|
||||
|
||||
proxy.makeDirectory = function(_, path)
|
||||
local steps = kernel.vfs.splitPath(path)
|
||||
local step = data
|
||||
for i=1,#steps do
|
||||
local current = ""
|
||||
|
||||
for i = 1, #steps do
|
||||
current = current == "" and steps[i]
|
||||
or current .. "/" .. steps[i]
|
||||
|
||||
if not step[steps[i]] then
|
||||
step[steps[i]] = {}
|
||||
touch(current)
|
||||
elseif type(step[steps[i]]) ~= "table" then
|
||||
error("ENOTDIR")
|
||||
end
|
||||
|
||||
step = step[steps[i]]
|
||||
end
|
||||
end
|
||||
|
||||
proxy.remove = function(_, path)
|
||||
local steps = kernel.vfs.splitPath(path)
|
||||
local step = data
|
||||
for i=1,#steps-1 do
|
||||
step = step[steps[i]]
|
||||
if not step then error("ENOENT") end
|
||||
if #steps == 0 then
|
||||
error("EACCES")
|
||||
end
|
||||
step[steps[#steps]] = nil
|
||||
|
||||
local step = data
|
||||
local current = ""
|
||||
|
||||
for i = 1, #steps - 1 do
|
||||
current = current == "" and steps[i]
|
||||
or current .. "/" .. steps[i]
|
||||
|
||||
step = step[steps[i]]
|
||||
if not step then
|
||||
error("ENOENT")
|
||||
end
|
||||
if type(step) ~= "table" then
|
||||
error("ENOTDIR")
|
||||
end
|
||||
end
|
||||
|
||||
local name = steps[#steps]
|
||||
if step[name] == nil then
|
||||
error("ENOENT")
|
||||
end
|
||||
|
||||
local function clearTimestamps(value, pathPrefix)
|
||||
timestamps[pathPrefix] = nil
|
||||
|
||||
if type(value) == "table" then
|
||||
for key, child in pairs(value) do
|
||||
clearTimestamps(child, pathPrefix .. "/" .. key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
clearTimestamps(step[name], path)
|
||||
step[name] = nil
|
||||
end
|
||||
|
||||
proxy.setLabel = function(_, label) end
|
||||
proxy.getLabel = function() return "tmpfs" end
|
||||
proxy.setLabel = function(_, label)
|
||||
end
|
||||
|
||||
proxy.getLabel = function()
|
||||
return "tmpfs"
|
||||
end
|
||||
|
||||
proxy.attributes = function(_, path)
|
||||
local steps = kernel.vfs.splitPath(path)
|
||||
local step = data
|
||||
for i=1,#steps do
|
||||
local current = ""
|
||||
|
||||
for i = 1, #steps do
|
||||
current = current == "" and steps[i]
|
||||
or current .. "/" .. steps[i]
|
||||
|
||||
step = step[steps[i]]
|
||||
if not step then error("ENOENT") end
|
||||
if step == nil then
|
||||
error("ENOENT")
|
||||
end
|
||||
end
|
||||
|
||||
local time = getTimestamp(current)
|
||||
return {
|
||||
size = type(step) == "string" and #step or 0,
|
||||
modified = 0,
|
||||
created = 0,
|
||||
modified = time.modified,
|
||||
created = time.created,
|
||||
}
|
||||
end
|
||||
|
||||
function proxy:open(path, mode)
|
||||
local steps = kernel.vfs.splitPath(path)
|
||||
if #steps == 0 then
|
||||
error("EISDIR")
|
||||
end
|
||||
|
||||
local step = data
|
||||
for i=1,#steps-1 do
|
||||
local current = ""
|
||||
|
||||
for i = 1, #steps - 1 do
|
||||
current = current == "" and steps[i]
|
||||
or current .. "/" .. steps[i]
|
||||
|
||||
if not step[steps[i]] then
|
||||
if mode == "w" then step[steps[i]] = {} else error("ENOENT") end
|
||||
if mode == "w" then
|
||||
step[steps[i]] = {}
|
||||
touch(current)
|
||||
else
|
||||
error("ENOENT")
|
||||
end
|
||||
elseif type(step[steps[i]]) ~= "table" then
|
||||
error("ENOTDIR")
|
||||
end
|
||||
|
||||
step = step[steps[i]]
|
||||
end
|
||||
|
||||
local filename = steps[#steps]
|
||||
local filepath = current == "" and filename
|
||||
or current .. "/" .. filename
|
||||
|
||||
if mode == "r" then
|
||||
if type(step[filename]) ~= "string" then error("ENOENT") end
|
||||
if type(step[filename]) ~= "string" then
|
||||
if type(step[filename]) == "table" then
|
||||
error("EISDIR")
|
||||
end
|
||||
error("ENOENT")
|
||||
end
|
||||
|
||||
local content = step[filename]
|
||||
local pos = 1
|
||||
|
||||
return {
|
||||
read = function(amount)
|
||||
read = function(amount)
|
||||
amount = amount or #content
|
||||
local chunk = content:sub(pos, pos+amount-1)
|
||||
local chunk = content:sub(pos, pos + amount - 1)
|
||||
pos = pos + #chunk
|
||||
if chunk == "" then
|
||||
return nil
|
||||
end
|
||||
return chunk
|
||||
end,
|
||||
close = function() end,
|
||||
}
|
||||
elseif mode == "w" then
|
||||
step[filename] = ""
|
||||
local buf = {}
|
||||
return {
|
||||
write = function(str)
|
||||
buf[#buf + 1] = str
|
||||
end,
|
||||
close = function()
|
||||
step[filename] = table.concat(buf)
|
||||
end,
|
||||
}
|
||||
elseif mode == "a" then
|
||||
if type(step[filename]) ~= "string" then step[filename] = "" end
|
||||
|
||||
elseif mode == "w" then
|
||||
if type(step[filename]) == "table" then
|
||||
error("EISDIR")
|
||||
end
|
||||
|
||||
local buf = {}
|
||||
local closed = false
|
||||
|
||||
return {
|
||||
write = function(str)
|
||||
step[filename] = step[filename] .. str
|
||||
if closed then
|
||||
error("EBADF")
|
||||
end
|
||||
buf[#buf + 1] = tostring(str)
|
||||
end,
|
||||
|
||||
close = function()
|
||||
if closed then
|
||||
return
|
||||
end
|
||||
|
||||
closed = true
|
||||
local existed = type(step[filename]) == "string"
|
||||
step[filename] = table.concat(buf)
|
||||
|
||||
if not existed then
|
||||
local time = now()
|
||||
timestamps[filepath] = {
|
||||
created = time,
|
||||
modified = time,
|
||||
}
|
||||
else
|
||||
touch(filepath)
|
||||
end
|
||||
end,
|
||||
close = function() end,
|
||||
}
|
||||
|
||||
elseif mode == "a" then
|
||||
if type(step[filename]) == "table" then
|
||||
error("EISDIR")
|
||||
end
|
||||
|
||||
local buf = {
|
||||
type(step[filename]) == "string" and step[filename] or ""
|
||||
}
|
||||
local closed = false
|
||||
|
||||
return {
|
||||
write = function(str)
|
||||
if closed then
|
||||
error("EBADF")
|
||||
end
|
||||
buf[#buf + 1] = tostring(str)
|
||||
end,
|
||||
|
||||
close = function()
|
||||
if closed then
|
||||
return
|
||||
end
|
||||
|
||||
closed = true
|
||||
local existed = type(step[filename]) == "string"
|
||||
step[filename] = table.concat(buf)
|
||||
|
||||
if not existed then
|
||||
local time = now()
|
||||
timestamps[filepath] = {
|
||||
created = time,
|
||||
modified = time,
|
||||
}
|
||||
else
|
||||
touch(filepath)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
else
|
||||
error("EACCES")
|
||||
end
|
||||
@@ -105,25 +286,57 @@ if not kernel.config.tmpToDisk then
|
||||
function proxy:type(path)
|
||||
local steps = kernel.vfs.splitPath(path)
|
||||
local step = data
|
||||
if #steps == 0 then return "directory" end
|
||||
for i=1,#steps do
|
||||
|
||||
if #steps == 0 then
|
||||
return "directory"
|
||||
end
|
||||
|
||||
for i = 1, #steps do
|
||||
if type(step) ~= "table" then
|
||||
return false
|
||||
end
|
||||
|
||||
step = step[steps[i]]
|
||||
if not step then return false end
|
||||
if step == nil then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
if type(step) == "table" then
|
||||
return "directory"
|
||||
end
|
||||
if type(step) == "string" then
|
||||
return "file"
|
||||
end
|
||||
if type(step) == "table" then return "directory" end
|
||||
if type(step) == "string" then return "file" end
|
||||
end
|
||||
|
||||
function proxy:list(path)
|
||||
local steps = kernel.vfs.splitPath(path)
|
||||
local step = data
|
||||
for i=1,#steps do
|
||||
local current = ""
|
||||
|
||||
for i = 1, #steps do
|
||||
current = current == "" and steps[i]
|
||||
or current .. "/" .. steps[i]
|
||||
|
||||
if type(step) ~= "table" then
|
||||
error("ENOTDIR")
|
||||
end
|
||||
|
||||
step = step[steps[i]]
|
||||
if not step then error("ENOENT") end
|
||||
if step == nil then
|
||||
error("ENOENT")
|
||||
end
|
||||
end
|
||||
if type(step) ~= "table" then error("ENOTDIR") end
|
||||
|
||||
if type(step) ~= "table" then
|
||||
error("ENOTDIR")
|
||||
end
|
||||
|
||||
local keys = {}
|
||||
for k,_ in pairs(step) do table.insert(keys, k) end
|
||||
for k in pairs(step) do
|
||||
keys[#keys + 1] = k
|
||||
end
|
||||
return keys
|
||||
end
|
||||
|
||||
@@ -133,9 +346,11 @@ if not kernel.config.tmpToDisk then
|
||||
end
|
||||
|
||||
kernel.disks["tmpfs0000"] = proxy
|
||||
kernel.tmpfs={data=data,proxy=proxy}
|
||||
else
|
||||
kernel.log("tmpToDisk enabled, skipping tmpfs module")
|
||||
kernel.log("tmpfs0000 will passthrough to /tmp on the disk")
|
||||
|
||||
kernel.runWhenLoaded(function()
|
||||
kernel.vfs.remove("/tmp")
|
||||
kernel.vfs.mkdir("/tmp")
|
||||
|
||||
@@ -160,7 +160,19 @@ function socket.recv(fd, amount)
|
||||
return nil, "EOPNOTSUPP"
|
||||
end
|
||||
|
||||
return fdo.handle.read(amount)
|
||||
local ret = fdo.handle.read(amount)
|
||||
if ret==nil or ret=="" then
|
||||
kernel.currentTask.io=function()
|
||||
ret = fdo.handle.read(amount)
|
||||
if ret~=nil and ret~="" then
|
||||
return ret
|
||||
end
|
||||
end
|
||||
kernel.currentTask.status="D"
|
||||
return
|
||||
else
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
function socket.sockshutdown(fd)
|
||||
|
||||
@@ -10,26 +10,62 @@ local function bit_is_set(num, bit)
|
||||
return math.floor(num / (2 ^ bit)) % 2 == 1
|
||||
end
|
||||
|
||||
|
||||
local function loadExecutable(path)
|
||||
kernel.vfs.access(path, "rx")
|
||||
|
||||
local fd = kernel.vfs.open(path, "r")
|
||||
local data = kernel.vfs.read(fd, 1024 * 1024 * 4)
|
||||
if kernel.vfs.type(path)~="file" then error("Target is not file") end
|
||||
local fd = kernel.vfs.open(path, "r")
|
||||
if not fd then
|
||||
error("ENOENT: " .. tostring(path))
|
||||
end
|
||||
|
||||
local chunks = {}
|
||||
local total = 0
|
||||
|
||||
local ok, err = pcall(function()
|
||||
while true do
|
||||
local chunk = kernel.vfs.read(fd, 2048)
|
||||
|
||||
if not chunk or #chunk == 0 then
|
||||
break
|
||||
end
|
||||
|
||||
chunks[#chunks + 1] = chunk
|
||||
total = total + #chunk
|
||||
end
|
||||
end)
|
||||
|
||||
kernel.vfs.close(fd)
|
||||
|
||||
if not ok then
|
||||
error("EIO reading executable: " .. tostring(err))
|
||||
end
|
||||
|
||||
local data = table.concat(chunks)
|
||||
|
||||
local env = kernel.freshUserEnv()
|
||||
|
||||
local func, err = load(data, "@" .. path, "t", env)
|
||||
if not func then kernel.log("Failed to load executable: " .. tostring(err).. " : ".. tostring(path)); error("ENOEXEC: " .. tostring(err)) end
|
||||
|
||||
local meta = kernel.vfs.lstat(path)
|
||||
local suid_set = bit_is_set(meta.perms, 6)
|
||||
if not func then
|
||||
kernel.log(
|
||||
"Failed to load executable: " ..
|
||||
tostring(err) .. " : " .. tostring(path)
|
||||
)
|
||||
|
||||
error("ENOEXEC: " .. tostring(err))
|
||||
end
|
||||
|
||||
local meta = kernel.vfs.lstat(path)
|
||||
local suid_set = bit_is_set(meta.perms, 6)
|
||||
local caller_uid = kernel.currentTask and kernel.currentTask.uid or kernel.uid
|
||||
local euid = suid_set and meta.owner or caller_uid
|
||||
local euid = suid_set and meta.owner or caller_uid
|
||||
|
||||
return func, euid, suid_set
|
||||
end
|
||||
|
||||
|
||||
local function createTask(func, name, envars, args, tgid, real_uid, eff_uid, clearFds)
|
||||
local id = nextpid
|
||||
nextpid = nextpid + 1
|
||||
@@ -142,6 +178,8 @@ function sys.exec(path, args, envars, clearFds)
|
||||
task.args = args or {}
|
||||
task.envars = envars or task.envars or {}
|
||||
task.name = path
|
||||
task.ivs = 0
|
||||
task.vs = 0
|
||||
|
||||
task.coro = coroutine.create(function()
|
||||
local ok, err = xpcall(func, debug.traceback, table.unpack(task.args))
|
||||
@@ -251,7 +289,7 @@ function sys.stop(pid)
|
||||
end
|
||||
end
|
||||
|
||||
function sys.continue(pid)
|
||||
function sys.cont(pid)
|
||||
local task = tasks[tostring(pid)]
|
||||
if not task then
|
||||
return false, "Task does not exist"
|
||||
@@ -394,7 +432,7 @@ sysc["getTask"] = sys.getTask
|
||||
sysc["collect"] = sys.collect
|
||||
sysc["kill"] = sys.kill
|
||||
sysc["stop"] = sys.stop
|
||||
sysc["continue"] = sys.continue
|
||||
sysc["continue"] = sys.cont
|
||||
sysc["getpid"] = sys.getpid
|
||||
sysc["getppid"] = sys.getppid
|
||||
sysc["getTasks"] = sys.getTasks
|
||||
|
||||
Reference in new issue
Block a user