From cb73f4996253e9e0fa0a7d8139bcb154917cde1a Mon Sep 17 00:00:00 2001 From: Astronand Date: Fri, 30 Jan 2026 18:29:01 -0500 Subject: [PATCH] added file and folder perms --- README.md | 13 +- Src/Hyperion-bash/bin/bashex | 14 +- Src/Hyperion-bash/bin/startup/test.lua | 1 + Src/Hyperion-core/lib/sys/fs | 4 +- Src/Hyperion-core/sbin/init.lua | 8 +- .../lib/modules/Hyperion/10_vfs.kmod | 157 ++++++++++++------ .../lib/modules/Hyperion/45_hypervisor.kmod | 4 +- contributors.md | 1 + 8 files changed, 135 insertions(+), 67 deletions(-) create mode 100644 Src/Hyperion-bash/bin/startup/test.lua create mode 100644 contributors.md diff --git a/README.md b/README.md index 229e91b..1d096a9 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,15 @@ --- ## Build requirements -* **Source:** None it builds directly in vs-code, altough it is the biggest build method it gives the most readability +* **Source:** None it builds directly in vs-code, altough it is the biggest build method it gives the most readability -## Contributing \ No newline at end of file +* **Minifyed:** You need node.js and luamin + +--- + +## Contributing +* **Credit:** if you contributed feel free to add your name to contributors.md +--- + +## Rules/guidelines +* **AI:** AI **stays out of the kernel** you may use AI to create tests and for debugging. if it is not important you may use AI. diff --git a/Src/Hyperion-bash/bin/bashex b/Src/Hyperion-bash/bin/bashex index 300a85f..5ef82e6 100644 --- a/Src/Hyperion-bash/bin/bashex +++ b/Src/Hyperion-bash/bin/bashex @@ -9,7 +9,7 @@ local inputIO=syscall.IO_getBoundQueue() local pid=syscall.getpid() local proc=0 local fs=require("sys.fs") -local timeout=1 +local timeout=false printInline("> ") while true do local event = {syscall.IO_pullEvent()} @@ -57,6 +57,9 @@ while true do end end end + timeout=false + else + timeout=true end if stopInput then local exited, code = syscall.collect(proc) @@ -77,13 +80,10 @@ while true do else syscall.IO_pushEvent("bash:"..tostring(pid), table.unpack(event)) end - timeout=10 - else - timeout=timeout-1 - end - if timeout<0 then - sleep(.05) end end end + if timeout then + sleep(.05) + end end \ No newline at end of file diff --git a/Src/Hyperion-bash/bin/startup/test.lua b/Src/Hyperion-bash/bin/startup/test.lua new file mode 100644 index 0000000..1025215 --- /dev/null +++ b/Src/Hyperion-bash/bin/startup/test.lua @@ -0,0 +1 @@ +syscall.chown("/bin", 0, 0) \ No newline at end of file diff --git a/Src/Hyperion-core/lib/sys/fs b/Src/Hyperion-core/lib/sys/fs index d9c9828..182d9ef 100644 --- a/Src/Hyperion-core/lib/sys/fs +++ b/Src/Hyperion-core/lib/sys/fs @@ -133,8 +133,8 @@ function fs.getcwd() return syscall.getcwd() end -function fs.setcwd(path) - return syscall.setcwd(path) +function fs.chdir(path) + return syscall.chdir(path) end function fs.isDir(path) diff --git a/Src/Hyperion-core/sbin/init.lua b/Src/Hyperion-core/sbin/init.lua index b274d7c..e834bc9 100644 --- a/Src/Hyperion-core/sbin/init.lua +++ b/Src/Hyperion-core/sbin/init.lua @@ -46,18 +46,18 @@ for i,v in ipairs(files) do end end -local timeout=1 +local timeout=false while true do local event = {syscall.IO_pullEvent()} if event[1] then for i,v in ipairs(eventQueues) do syscall.IO_pushEvent(v, table.unpack(event)) end - timeout=10 + timeout=false else - timeout=timeout-1 + timeout=true end - if timeout<0 then + if timeout then sleep(.05) end kernel.saveLog() diff --git a/Src/Hyperion-kernel/lib/modules/Hyperion/10_vfs.kmod b/Src/Hyperion-kernel/lib/modules/Hyperion/10_vfs.kmod index d4d05ea..e321de5 100644 --- a/Src/Hyperion-kernel/lib/modules/Hyperion/10_vfs.kmod +++ b/Src/Hyperion-kernel/lib/modules/Hyperion/10_vfs.kmod @@ -71,24 +71,34 @@ end -- Parse metafile local function parseMetafile(file) - local ret={} - local pointer=1 + if not file or file == "" then + return {} + end + + local ret = {} + local pointer = 1 + while pointer <= #file do local namelen = file:byte(pointer) pointer = pointer + 1 + local name = file:sub(pointer, pointer + namelen - 1) pointer = pointer + namelen + local owner = file:byte(pointer) - local group = file:byte(pointer+1) - local perms = file:byte(pointer+2) + local group = file:byte(pointer + 1) + local perms = file:byte(pointer + 2) pointer = pointer + 3 + local cmetalen = file:byte(pointer) pointer = pointer + 1 + local cmeta = "" if cmetalen > 0 then cmeta = file:sub(pointer, pointer + cmetalen - 1) pointer = pointer + cmetalen end + ret[name] = { owner = owner, group = group, @@ -96,6 +106,7 @@ local function parseMetafile(file) cmeta = cmeta } end + return ret end @@ -112,35 +123,73 @@ local function makeMetafile(meta) return file end --- Get metafile path and target -local function getMeta(path) - local disk, newPath = resolvePath(path) - - while newPath ~= "/" and newPath~="" do - local target = newPath:match("([^/]+)/?$") - if target == ".meta" then error("Cannot open metafile") end - if disk:fileExists(newPath .. ".meta") then - return newPath .. ".meta", target - end - newPath = newPath:gsub("/[^/]+/?$", "") - end - - return nil -end - -- Get file metadata object local function getFileMeta(path) - local mpath, target = getMeta(path) - if not mpath then - return { owner=0, group=0, perms=62, cmeta="" } + local disk, fullPath = resolvePath(path) + fullPath = normalizePath(fullPath) + + local parts = {} + for p in fullPath:gmatch("[^/]+") do + table.insert(parts, p) end - local disk, _ = resolvePath(mpath) - local file = disk:open(mpath, "r") - local text = file.read(65535) - file.close() - return parseMetafile(text)[target] + + -- default fallback + local default = { owner=0, group=0, perms=62, cmeta="" } + + -- walk from deepest parent upward + for i = #parts, 1, -1 do + local parent = "/" .. table.concat(parts, "/", 1, i-1) + if parent ~= "/" then parent = parent .. "/" end + + local target = parts[i] + local metaPath = parent .. ".meta" + + if disk:fileExists(metaPath) then + local f = disk:open(metaPath, "r") + local text = f.read(65535) + f.close() + + local parsed = parseMetafile(text) + if parsed[target] then + return parsed[target] + end + end + end + + return default end +local function ensureParentMeta(path) + local disk, fullPath = resolvePath(path) + fullPath = normalizePath(fullPath) + + -- split parent + name + local parent, name = fullPath:match("^(.*)/([^/]+)$") + if not parent then + parent = "/" + name = fullPath:gsub("^/", "") + end + + if name == ".meta" then + error("Cannot open metafile") + end + + if parent ~= "/" and parent:sub(-1) ~= "/" then + parent = parent .. "/" + end + + local metaPath = parent .. ".meta" + + if not disk:fileExists(metaPath) then + local f = disk:open(metaPath, "w") + f.write("") + f.close() + end + + return metaPath, name +end + + -- Permission checking local function checkperms(meta, mode) local modes = { @@ -376,20 +425,24 @@ function vfs.chmod(path, perms) local disk, diskPath = resolvePath(path) local meta = getFileMeta(path) checkperms(meta, "w") + meta.perms = perms - local mpath, target = getMeta(path) - if mpath then - local mf = disk:open(mpath,"r") - local text = mf.read(65535) - mf.close() - local parsed = parseMetafile(text) - parsed[target] = meta - local file = disk:open(mpath,"w") - file.write(makeMetafile(parsed)) - file.close() - end + + local mpath, target = ensureParentMeta(path) + + local mf = disk:open(mpath, "r") + local text = mf.read(65535) + mf.close() + + local parsed = parseMetafile(text) + parsed[target] = meta + + local f = disk:open(mpath, "w") + f.write(makeMetafile(parsed)) + f.close() end + function vfs.fchmod(fd, perms) local task = kernel.currentTask local file = task.fd[fd] @@ -401,21 +454,25 @@ function vfs.chown(path, uid, gid) local disk, diskPath = resolvePath(path) local meta = getFileMeta(path) checkperms(meta, "w") + meta.owner = uid meta.group = gid - local mpath, target = getMeta(path) - if mpath then - local mf = disk:open(mpath,"r") - local text = mf.read(65535) - mf.close() - local parsed = parseMetafile(text) - parsed[target] = meta - local file = disk:open(mpath,"w") - file.write(makeMetafile(parsed)) - file.close() - end + + local mpath, target = ensureParentMeta(path) + + local mf = disk:open(mpath, "r") + local text = mf.read(65535) + mf.close() + + local parsed = parseMetafile(text) + parsed[target] = meta + + local f = disk:open(mpath, "w") + f.write(makeMetafile(parsed)) + f.close() end + function vfs.fchown(fd, uid, gid) local task = kernel.currentTask local file = task.fd[fd] diff --git a/Src/Hyperion-kernel/lib/modules/Hyperion/45_hypervisor.kmod b/Src/Hyperion-kernel/lib/modules/Hyperion/45_hypervisor.kmod index 455ff70..96f08af 100644 --- a/Src/Hyperion-kernel/lib/modules/Hyperion/45_hypervisor.kmod +++ b/Src/Hyperion-kernel/lib/modules/Hyperion/45_hypervisor.kmod @@ -64,9 +64,9 @@ function sys.spawn(func, name, envars, args, tgid) return id end -function sys.sleep(ms) +function sys.sleep(s) kernel.currentTask.status="S" - kernel.currentTask.sleep=kernel.computer:time()+ms + kernel.currentTask.sleep=kernel.computer:time()+s*1000 coroutine.yield() end diff --git a/contributors.md b/contributors.md new file mode 100644 index 0000000..77e8114 --- /dev/null +++ b/contributors.md @@ -0,0 +1 @@ +# Contributors