added file and folder perms
This commit is contained in:
13
README.md
13
README.md
@@ -10,6 +10,15 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Build requirements
|
## 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
|
* **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.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ local inputIO=syscall.IO_getBoundQueue()
|
|||||||
local pid=syscall.getpid()
|
local pid=syscall.getpid()
|
||||||
local proc=0
|
local proc=0
|
||||||
local fs=require("sys.fs")
|
local fs=require("sys.fs")
|
||||||
local timeout=1
|
local timeout=false
|
||||||
printInline("> ")
|
printInline("> ")
|
||||||
while true do
|
while true do
|
||||||
local event = {syscall.IO_pullEvent()}
|
local event = {syscall.IO_pullEvent()}
|
||||||
@@ -57,6 +57,9 @@ while true do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
timeout=false
|
||||||
|
else
|
||||||
|
timeout=true
|
||||||
end
|
end
|
||||||
if stopInput then
|
if stopInput then
|
||||||
local exited, code = syscall.collect(proc)
|
local exited, code = syscall.collect(proc)
|
||||||
@@ -77,13 +80,10 @@ while true do
|
|||||||
else
|
else
|
||||||
syscall.IO_pushEvent("bash:"..tostring(pid), table.unpack(event))
|
syscall.IO_pushEvent("bash:"..tostring(pid), table.unpack(event))
|
||||||
end
|
end
|
||||||
timeout=10
|
|
||||||
else
|
|
||||||
timeout=timeout-1
|
|
||||||
end
|
|
||||||
if timeout<0 then
|
|
||||||
sleep(.05)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if timeout then
|
||||||
|
sleep(.05)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
1
Src/Hyperion-bash/bin/startup/test.lua
Normal file
1
Src/Hyperion-bash/bin/startup/test.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
syscall.chown("/bin", 0, 0)
|
||||||
@@ -133,8 +133,8 @@ function fs.getcwd()
|
|||||||
return syscall.getcwd()
|
return syscall.getcwd()
|
||||||
end
|
end
|
||||||
|
|
||||||
function fs.setcwd(path)
|
function fs.chdir(path)
|
||||||
return syscall.setcwd(path)
|
return syscall.chdir(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fs.isDir(path)
|
function fs.isDir(path)
|
||||||
|
|||||||
@@ -46,18 +46,18 @@ for i,v in ipairs(files) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local timeout=1
|
local timeout=false
|
||||||
while true do
|
while true do
|
||||||
local event = {syscall.IO_pullEvent()}
|
local event = {syscall.IO_pullEvent()}
|
||||||
if event[1] then
|
if event[1] then
|
||||||
for i,v in ipairs(eventQueues) do
|
for i,v in ipairs(eventQueues) do
|
||||||
syscall.IO_pushEvent(v, table.unpack(event))
|
syscall.IO_pushEvent(v, table.unpack(event))
|
||||||
end
|
end
|
||||||
timeout=10
|
timeout=false
|
||||||
else
|
else
|
||||||
timeout=timeout-1
|
timeout=true
|
||||||
end
|
end
|
||||||
if timeout<0 then
|
if timeout then
|
||||||
sleep(.05)
|
sleep(.05)
|
||||||
end
|
end
|
||||||
kernel.saveLog()
|
kernel.saveLog()
|
||||||
|
|||||||
@@ -71,24 +71,34 @@ end
|
|||||||
|
|
||||||
-- Parse metafile
|
-- Parse metafile
|
||||||
local function parseMetafile(file)
|
local function parseMetafile(file)
|
||||||
local ret={}
|
if not file or file == "" then
|
||||||
local pointer=1
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local ret = {}
|
||||||
|
local pointer = 1
|
||||||
|
|
||||||
while pointer <= #file do
|
while pointer <= #file do
|
||||||
local namelen = file:byte(pointer)
|
local namelen = file:byte(pointer)
|
||||||
pointer = pointer + 1
|
pointer = pointer + 1
|
||||||
|
|
||||||
local name = file:sub(pointer, pointer + namelen - 1)
|
local name = file:sub(pointer, pointer + namelen - 1)
|
||||||
pointer = pointer + namelen
|
pointer = pointer + namelen
|
||||||
|
|
||||||
local owner = file:byte(pointer)
|
local owner = file:byte(pointer)
|
||||||
local group = file:byte(pointer+1)
|
local group = file:byte(pointer + 1)
|
||||||
local perms = file:byte(pointer+2)
|
local perms = file:byte(pointer + 2)
|
||||||
pointer = pointer + 3
|
pointer = pointer + 3
|
||||||
|
|
||||||
local cmetalen = file:byte(pointer)
|
local cmetalen = file:byte(pointer)
|
||||||
pointer = pointer + 1
|
pointer = pointer + 1
|
||||||
|
|
||||||
local cmeta = ""
|
local cmeta = ""
|
||||||
if cmetalen > 0 then
|
if cmetalen > 0 then
|
||||||
cmeta = file:sub(pointer, pointer + cmetalen - 1)
|
cmeta = file:sub(pointer, pointer + cmetalen - 1)
|
||||||
pointer = pointer + cmetalen
|
pointer = pointer + cmetalen
|
||||||
end
|
end
|
||||||
|
|
||||||
ret[name] = {
|
ret[name] = {
|
||||||
owner = owner,
|
owner = owner,
|
||||||
group = group,
|
group = group,
|
||||||
@@ -96,6 +106,7 @@ local function parseMetafile(file)
|
|||||||
cmeta = cmeta
|
cmeta = cmeta
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -112,35 +123,73 @@ local function makeMetafile(meta)
|
|||||||
return file
|
return file
|
||||||
end
|
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
|
-- Get file metadata object
|
||||||
local function getFileMeta(path)
|
local function getFileMeta(path)
|
||||||
local mpath, target = getMeta(path)
|
local disk, fullPath = resolvePath(path)
|
||||||
if not mpath then
|
fullPath = normalizePath(fullPath)
|
||||||
return { owner=0, group=0, perms=62, cmeta="" }
|
|
||||||
|
local parts = {}
|
||||||
|
for p in fullPath:gmatch("[^/]+") do
|
||||||
|
table.insert(parts, p)
|
||||||
end
|
end
|
||||||
local disk, _ = resolvePath(mpath)
|
|
||||||
local file = disk:open(mpath, "r")
|
-- default fallback
|
||||||
local text = file.read(65535)
|
local default = { owner=0, group=0, perms=62, cmeta="" }
|
||||||
file.close()
|
|
||||||
return parseMetafile(text)[target]
|
-- 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
|
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
|
-- Permission checking
|
||||||
local function checkperms(meta, mode)
|
local function checkperms(meta, mode)
|
||||||
local modes = {
|
local modes = {
|
||||||
@@ -376,20 +425,24 @@ function vfs.chmod(path, perms)
|
|||||||
local disk, diskPath = resolvePath(path)
|
local disk, diskPath = resolvePath(path)
|
||||||
local meta = getFileMeta(path)
|
local meta = getFileMeta(path)
|
||||||
checkperms(meta, "w")
|
checkperms(meta, "w")
|
||||||
|
|
||||||
meta.perms = perms
|
meta.perms = perms
|
||||||
local mpath, target = getMeta(path)
|
|
||||||
if mpath then
|
local mpath, target = ensureParentMeta(path)
|
||||||
local mf = disk:open(mpath,"r")
|
|
||||||
local text = mf.read(65535)
|
local mf = disk:open(mpath, "r")
|
||||||
mf.close()
|
local text = mf.read(65535)
|
||||||
local parsed = parseMetafile(text)
|
mf.close()
|
||||||
parsed[target] = meta
|
|
||||||
local file = disk:open(mpath,"w")
|
local parsed = parseMetafile(text)
|
||||||
file.write(makeMetafile(parsed))
|
parsed[target] = meta
|
||||||
file.close()
|
|
||||||
end
|
local f = disk:open(mpath, "w")
|
||||||
|
f.write(makeMetafile(parsed))
|
||||||
|
f.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function vfs.fchmod(fd, perms)
|
function vfs.fchmod(fd, perms)
|
||||||
local task = kernel.currentTask
|
local task = kernel.currentTask
|
||||||
local file = task.fd[fd]
|
local file = task.fd[fd]
|
||||||
@@ -401,21 +454,25 @@ function vfs.chown(path, uid, gid)
|
|||||||
local disk, diskPath = resolvePath(path)
|
local disk, diskPath = resolvePath(path)
|
||||||
local meta = getFileMeta(path)
|
local meta = getFileMeta(path)
|
||||||
checkperms(meta, "w")
|
checkperms(meta, "w")
|
||||||
|
|
||||||
meta.owner = uid
|
meta.owner = uid
|
||||||
meta.group = gid
|
meta.group = gid
|
||||||
local mpath, target = getMeta(path)
|
|
||||||
if mpath then
|
local mpath, target = ensureParentMeta(path)
|
||||||
local mf = disk:open(mpath,"r")
|
|
||||||
local text = mf.read(65535)
|
local mf = disk:open(mpath, "r")
|
||||||
mf.close()
|
local text = mf.read(65535)
|
||||||
local parsed = parseMetafile(text)
|
mf.close()
|
||||||
parsed[target] = meta
|
|
||||||
local file = disk:open(mpath,"w")
|
local parsed = parseMetafile(text)
|
||||||
file.write(makeMetafile(parsed))
|
parsed[target] = meta
|
||||||
file.close()
|
|
||||||
end
|
local f = disk:open(mpath, "w")
|
||||||
|
f.write(makeMetafile(parsed))
|
||||||
|
f.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function vfs.fchown(fd, uid, gid)
|
function vfs.fchown(fd, uid, gid)
|
||||||
local task = kernel.currentTask
|
local task = kernel.currentTask
|
||||||
local file = task.fd[fd]
|
local file = task.fd[fd]
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ function sys.spawn(func, name, envars, args, tgid)
|
|||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
|
|
||||||
function sys.sleep(ms)
|
function sys.sleep(s)
|
||||||
kernel.currentTask.status="S"
|
kernel.currentTask.status="S"
|
||||||
kernel.currentTask.sleep=kernel.computer:time()+ms
|
kernel.currentTask.sleep=kernel.computer:time()+s*1000
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
1
contributors.md
Normal file
1
contributors.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Contributors
|
||||||
Reference in New Issue
Block a user