update to start working on SysInit

This commit is contained in:
2025-12-10 22:14:52 -05:00
parent 7bc6d87322
commit 6d9d02edf7
163 changed files with 1422 additions and 10637 deletions

View File

@@ -1,6 +1,5 @@
local args={...}
local kernel=args[1]
local args = {...}
local kernel = args[1]
function kernel.fs.mkvirtfs(address, readOnly, label, autoRegister)
if kernel.uid ~= 0 then error("Permission Denied") end
local disk = {}
@@ -55,34 +54,36 @@ function kernel.fs.mkvirtfs(address, readOnly, label, autoRegister)
-- File IO (supports string or file-object with read/write funcs)
-----------------------------------------------------------------
local function fileRead(node)
local function fileRead(node, ...)
if type(node) == "string" then
return node
elseif type(node) == "table" and node.__file and node.read then
return node.read()
return node.read(...)
end
return nil
end
local function fileWrite(parent, name, text)
local function fileWrite(parent, name, text, ...)
local node = parent[name]
if type(node) == "string" then
local ok, err = ensureWrite(); if not ok then return false, err end
parent[name] = text
return true
elseif type(node) == "table" and node.__file and node.write then
return node.write(text)
return node.write(text, ...)
end
parent[name] = text
return true
end
local function fileAppend(parent, name, text)
local function fileAppend(parent, name, text, ...)
local node = parent[name]
if type(node) == "string" then
local ok, err = ensureWrite(); if not ok then return false, err end
parent[name] = node .. text
return true
elseif type(node) == "table" and node.__file and node.write then
return node.write((node.read() or "") .. text)
return node.write((node.read() or "") .. text, ...)
end
parent[name] = text
return true
@@ -96,26 +97,22 @@ function kernel.fs.mkvirtfs(address, readOnly, label, autoRegister)
function disk:spaceUsed() return 0 end
function disk:spaceTotal() return 0 end
function disk:readAllText(path)
function disk:readAllText(path, ...)
local node = getNode(path)
if not node then return nil, "file not found" end
return fileRead(node)
return fileRead(node, ...)
end
function disk:writeAllText(path, text)
local ok, err = ensureWrite(); if not ok then return false, err end
function disk:writeAllText(path, text, ...)
local parent, name = getParent(path)
if not parent or not parent.__dir then return false, "invalid directory" end
return fileWrite(parent, name, tostring(text))
return fileWrite(parent, name, tostring(text), ...)
end
function disk:appendAllText(path, text)
local ok, err = ensureWrite(); if not ok then return false, err end
function disk:appendAllText(path, text, ...)
local parent, name = getParent(path)
if not parent or not parent.__dir then return false, "invalid directory" end
return fileAppend(parent, name, tostring(text))
return fileAppend(parent, name, tostring(text), ...)
end
function disk:list(path)
@@ -161,11 +158,11 @@ function kernel.fs.mkvirtfs(address, readOnly, label, autoRegister)
return label
end
function disk:size(path)
function disk:size(path, ...)
local node = getNode(path)
if type(node) == "string" then return #node end
if type(node) == "table" and node.__file and node.read then
local v = node.read()
local v = node.read(...)
return v and #v or 0
end
return 0
@@ -174,7 +171,7 @@ function kernel.fs.mkvirtfs(address, readOnly, label, autoRegister)
-----------------------------------------------------------------
-- Auto-register with kernel and return backend
-----------------------------------------------------------------
if kernel and kernel.fs and kernel.fs.virtDisk and autoRegister then
if autoRegister then
kernel.fs.virtDisk(disk)
end