From 438b185412916d15073df175a3a201b650c2128f Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 12:08:11 +1000 Subject: [PATCH 01/11] made a configs/ dir for kernel configurations, and ./genkernel.sh generate all of them. --- build.cfg => configs/everything.cfg | 0 configs/headless.cfg | 28 ++++++++++++++++++++++++++++ genkernel.sh | 7 +++++-- 3 files changed, 33 insertions(+), 2 deletions(-) rename build.cfg => configs/everything.cfg (100%) create mode 100755 configs/headless.cfg diff --git a/build.cfg b/configs/everything.cfg similarity index 100% rename from build.cfg rename to configs/everything.cfg diff --git a/configs/headless.cfg b/configs/headless.cfg new file mode 100755 index 0000000..4c80910 --- /dev/null +++ b/configs/headless.cfg @@ -0,0 +1,28 @@ +modules/base/loadlin.lua +modules/debug/log.lua +modules/base/header.lua +modules/base/component.lua +modules/lib/fs.lua +modules/util/logflush.lua +modules/lib/buffer.lua +modules/lib/io.lua +modules/lib/print.lua +modules/lib/cdlib.lua +modules/lib/relib.lua +modules/net/copper.lua +modules/util/motd.lua +modules/lib/readline.lua +modules/lib/shutil.lua +modules/lib/sha256.lua +modules/lib/userlib.lua +modules/net/net-ext.lua +modules/applications/login.lua +modules/applications/luash.lua +modules/applications/genkernel.lua +fwrap skex exec/skex2.lua +fwrap nshd exec/nshd.lua +fwrap nsh exec/nsh.lua +modules/util/fs-automount.lua +modules/setup.lua +modules/base/footer.lua + diff --git a/genkernel.sh b/genkernel.sh index eb9dde6..4b27abb 100755 --- a/genkernel.sh +++ b/genkernel.sh @@ -1,3 +1,6 @@ #!/bin/bash -./genkernel.lua build.cfg "$(git rev-parse --short HEAD)" > kernel.lua -lua strip.lua kernel.lua skernel.lua +for f in `dir -d configs/*`; do + kn=$(echo $f | cut -f 1 -d '.' | cut -f 2 -d "/") + ./genkernel.lua $f "$(git rev-parse --short HEAD)" > $kn.lua + lua strip.lua $kn.lua s$kn.lua +done From db6cfd9fc5e9a287a37e27b990891fd2b045692b Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 12:17:26 +1000 Subject: [PATCH 02/11] some cleaning up. --- .gitignore | 1 + configs/minimal.cfg | 27 +++++++++++++++++++++++++++ genkernel.sh | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100755 configs/minimal.cfg diff --git a/.gitignore b/.gitignore index 15d5132..cb31826 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +out/* kernel.lua skernel.lua *.swp diff --git a/configs/minimal.cfg b/configs/minimal.cfg new file mode 100755 index 0000000..31fceca --- /dev/null +++ b/configs/minimal.cfg @@ -0,0 +1,27 @@ +modules/base/loadlin.lua +modules/debug/log.lua +modules/base/header.lua +modules/base/component.lua +modules/lib/fs.lua +modules/util/logflush.lua +modules/lib/buffer.lua +modules/lib/io.lua +modules/drivers/vt52.lua +modules/lib/print.lua +modules/drivers/kbd.lua +modules/lib/cdlib.lua +modules/lib/relib.lua +modules/net/copper.lua +modules/util/motd.lua +modules/lib/readline.lua +modules/lib/shutil.lua +modules/lib/sha256.lua +modules/lib/userlib.lua +modules/net/net-ext.lua +modules/applications/login.lua +modules/applications/luash.lua +modules/applications/genkernel.lua +modules/util/fs-automount.lua +modules/setup.lua +modules/base/footer.lua + diff --git a/genkernel.sh b/genkernel.sh index 4b27abb..daf260a 100755 --- a/genkernel.sh +++ b/genkernel.sh @@ -1,6 +1,6 @@ #!/bin/bash for f in `dir -d configs/*`; do kn=$(echo $f | cut -f 1 -d '.' | cut -f 2 -d "/") - ./genkernel.lua $f "$(git rev-parse --short HEAD)" > $kn.lua - lua strip.lua $kn.lua s$kn.lua + ./genkernel.lua $f "$(git rev-parse --short HEAD)" > out/$kn.lua + lua strip.lua out/$kn.lua out/s$kn.lua done From 5557cd4d41fbe93718530fbc10e4df8061da8ecc Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 12:19:12 +1000 Subject: [PATCH 03/11] made autorun comply with my FHS --- modules/util/autorun.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/util/autorun.lua b/modules/util/autorun.lua index c50e843..d9a8859 100644 --- a/modules/util/autorun.lua +++ b/modules/util/autorun.lua @@ -1 +1 @@ -run("/boot/autorun.lua") +run("/boot/sys/init.lua") From f1f1d21ab6cdf24f0f4f342b56de66c3887bf37a Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 12:36:24 +1000 Subject: [PATCH 04/11] wrote documentation on the filesystem layout --- docs/fhs.md | 18 ++++++++++++++++++ docs/index.md | 1 + 2 files changed, 19 insertions(+) create mode 100644 docs/fhs.md diff --git a/docs/fhs.md b/docs/fhs.md new file mode 100644 index 0000000..ec8c80f --- /dev/null +++ b/docs/fhs.md @@ -0,0 +1,18 @@ +## Filesystem Hierarchy Standard +PsychOS is not a UNIX system, nor does it try to be. It doesn't have a 'real' VFS and doesn't have a devfs. As such, the filesystem is arranged differently. + +### Top level filesystems. +Filesystems devices are represented as top-level directories, eg /boot, /tmp, /fs01. +The mount points are strings, and can be of arbitrary length. However, it is recommended to keep them under 20 characters, and to not have spaces, or special characters in them. +A device can be mounted multiple times under multiple names. + +### /boot +/boot is the device the system booted from, and may be the same as /tmp under some circumstances. It contains all the special directories needed for the system to function. +#### /boot/exec +exec contains executable programs and utilities, generally separate from the kernel. +#### /boot/lib +lib contains all the libraries used by the system. +#### /boot/doc +doc contains the documentation, though it may not exist if the documentation isn't neccesary. +#### /boot/sys +sys contains miscellaneous system files like the user database and autorun scripts. diff --git a/docs/index.md b/docs/index.md index 0a69222..7bededc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -23,3 +23,4 @@ PsychOS is a single-user cooperative multitasking operating system for OpenCompu - User guide (WIP) - [Building PsychOS](building.html) - [API documentation](api.html) +- [Filesystem layout](fhs.html) From cce84dc5c5ad44a0afce30571fb0d99a7f7029de Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 12:52:03 +1000 Subject: [PATCH 05/11] convert luash to a fwrappable program --- configs/everything.cfg | 2 +- configs/headless.cfg | 2 +- configs/minimal.cfg | 2 +- {modules/applications => exec}/luash.lua | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) rename {modules/applications => exec}/luash.lua (97%) diff --git a/configs/everything.cfg b/configs/everything.cfg index d2a469a..5508bc7 100755 --- a/configs/everything.cfg +++ b/configs/everything.cfg @@ -19,8 +19,8 @@ modules/lib/sha256.lua modules/lib/userlib.lua modules/net/net-ext.lua modules/applications/login.lua -modules/applications/luash.lua modules/applications/genkernel.lua +fwrap luash exec/luash.lua fwrap skex exec/skex2.lua fwrap nshd exec/nshd.lua fwrap nsh exec/nsh.lua diff --git a/configs/headless.cfg b/configs/headless.cfg index 4c80910..6c40f8b 100755 --- a/configs/headless.cfg +++ b/configs/headless.cfg @@ -17,7 +17,7 @@ modules/lib/sha256.lua modules/lib/userlib.lua modules/net/net-ext.lua modules/applications/login.lua -modules/applications/luash.lua +fwrap luash exec/luash.lua modules/applications/genkernel.lua fwrap skex exec/skex2.lua fwrap nshd exec/nshd.lua diff --git a/configs/minimal.cfg b/configs/minimal.cfg index 31fceca..45b8743 100755 --- a/configs/minimal.cfg +++ b/configs/minimal.cfg @@ -19,7 +19,7 @@ modules/lib/sha256.lua modules/lib/userlib.lua modules/net/net-ext.lua modules/applications/login.lua -modules/applications/luash.lua +fwrap luash exec/luash.lua modules/applications/genkernel.lua modules/util/fs-automount.lua modules/setup.lua diff --git a/modules/applications/luash.lua b/exec/luash.lua similarity index 97% rename from modules/applications/luash.lua rename to exec/luash.lua index f051c19..71d3380 100644 --- a/modules/applications/luash.lua +++ b/exec/luash.lua @@ -1,4 +1,5 @@ -function luash(si) +local tA = {...} +local si = spawn("lua shell",function() coroutine.yield() log(login()) @@ -45,4 +46,3 @@ spawn("lua shell",function() end end end,{sI=si}) -end From c76bc60a20dd7f334802f2d634d883384b1a3138 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 13:06:17 +1000 Subject: [PATCH 06/11] some cleaning up --- modules/drivers/vt52.lua | 2 +- modules/lib/buffer.lua | 31 ------------------------------- strip.lua | 2 +- 3 files changed, 2 insertions(+), 33 deletions(-) diff --git a/modules/drivers/vt52.lua b/modules/drivers/vt52.lua index 7ffc5ee..4cf1617 100644 --- a/modules/drivers/vt52.lua +++ b/modules/drivers/vt52.lua @@ -53,7 +53,7 @@ function tty(gA,sA,sI,fg,bg) elseif c == "\r" then cx=1 elseif c == "\f" then cx=1 cy=1 gP.fill(1, 1, sx, sy, " ") elseif c == "\t" then cx=(cx+8-((cx+8)%8))+1 - elseif c == "\127" then cx=cx-1 gP.set(cx,cy," ") + elseif c == "\127" then cx=cx-1 gP.set(cx,cy,(" "):rep(2)) else gP.set(cx,cy,c) cx=cx+1 end end cv() diff --git a/modules/lib/buffer.lua b/modules/lib/buffer.lua index 6dac478..436c7f4 100644 --- a/modules/lib/buffer.lua +++ b/modules/lib/buffer.lua @@ -1,35 +1,4 @@ _G.buffer = {} ---[[function buffer.create(w,c) -- worker, close - local t={} - t.b="" - function t.w(s,d) - s.b=s.b..tostring(d) - end - t.write = t.w - function t.r(s,l) - if type(l) == "number" then - local ns,bs=s.b:sub(1,l+1),s.b:sub(l+2) - s.b=bs - return ns - elseif type(l) == "string" then - local oS=s.b - if l == "*a" then - s.b="" - return oS - elseif l == "*l" then - S=s.b:find("\n") or #s.b - s.b=s.b:sub(S+1) - rS = oS:sub(1,S-1) - if rS:len() < 1 then return nil end - return rS - end - end - end - t.read = t.r - t.close = c - w(t) - return t -end]]-- function buffer.ucreate() local b = {} b.b,b.s = "","open" diff --git a/strip.lua b/strip.lua index dfb79f0..4eeb6a9 100644 --- a/strip.lua +++ b/strip.lua @@ -31,7 +31,7 @@ for k,v in ipairs(replacements) do no=no+1 end end -print("\nBefore: "..sl.."\nAfter: "..tostring(ss:len()).."\n"..tostring(no).." optimisations made.\n") +print("\nBefore: "..sl.."\nAfter: "..tostring(ss:len()).."\nDelta: "..tostring(sl-ss:len())) f=io.open(tA[2],"wb") f:write(ss) From da62de5514b233001416a7b97809ee9e8339cdd8 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 13:15:38 +1000 Subject: [PATCH 07/11] added libwrap to genkernel() for wrapping require style libs --- modules/applications/genkernel.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/applications/genkernel.lua b/modules/applications/genkernel.lua index e19a9cb..dd6b0a3 100644 --- a/modules/applications/genkernel.lua +++ b/modules/applications/genkernel.lua @@ -22,6 +22,10 @@ function genkernel(modlistf,kname) nk=nk.."function "..tw[2].."(...)\n" apfile(tw[3]) nk=nk.."\nend\n" + elseif tw[1] == "libwrap" then + nk=nk.."function "..tw[2].."(...)\n" + apfile(tw[3]) + nk=nk.."\nend\n_G."..tw[2].." = "..tw[2].."()\n" elseif tw[1] == "include" then apfile(tw[2]) else From 9bbaf67696555a22a86fcc66ad987315b60128df Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 13:36:56 +1000 Subject: [PATCH 08/11] made sha a require-style lib --- configs/everything.cfg | 2 +- exec/luash.lua | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/configs/everything.cfg b/configs/everything.cfg index 5508bc7..1eba678 100755 --- a/configs/everything.cfg +++ b/configs/everything.cfg @@ -15,7 +15,7 @@ modules/net/copper.lua modules/util/motd.lua modules/lib/readline.lua modules/lib/shutil.lua -modules/lib/sha256.lua +libwrap sha modules/lib/sha256.lua modules/lib/userlib.lua modules/net/net-ext.lua modules/applications/login.lua diff --git a/exec/luash.lua b/exec/luash.lua index 71d3380..3a6fc74 100644 --- a/exec/luash.lua +++ b/exec/luash.lua @@ -1,6 +1,7 @@ local tA = {...} local si = spawn("lua shell",function() + _ENV = shutil.genenv() coroutine.yield() log(login()) print("\f"..MOTD) @@ -38,7 +39,7 @@ spawn("lua shell",function() if inp:sub(1,1) == "=" then inp="return "..inp:sub(2) end - local r={pcall(load(inp))} + local r={pcall(load(inp,_ENV))} if r[1] == true then table.remove(r,1) end From 781ac829045209d91df6144cc7741752d688b3ba Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 13:37:26 +1000 Subject: [PATCH 09/11] same as the last one except luash has better sandboxing now --- modules/lib/sha256.lua | 3 ++- modules/lib/shutil.lua | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/lib/sha256.lua b/modules/lib/sha256.lua index baa1e07..e145df1 100644 --- a/modules/lib/sha256.lua +++ b/modules/lib/sha256.lua @@ -6,7 +6,7 @@ -- Found Here: https://bitbucket.org/Boolsheet/bslf/src/1ee664885805/bit.lua -- -- Data card support added by https://github.com/SuPeRMiNoR2 -_G.sha = {} +sha = {} if component then if component.data and not component.ocemu then shamode = "hardware" @@ -216,3 +216,4 @@ local function datac256(data) return toHex(datac.sha256(data)) end end +return sha diff --git a/modules/lib/shutil.lua b/modules/lib/shutil.lua index f56a2a1..bdb4870 100644 --- a/modules/lib/shutil.lua +++ b/modules/lib/shutil.lua @@ -1,17 +1,18 @@ -cd=fs.cd -rm=fs.rm -mkdir=fs.mkdir -cp=fs.cp -mv=fs.mv -function ls(p) +local shutil = {} +shutil.cd=fs.cd +shutil.rm=fs.rm +shutil.mkdir=fs.mkdir +shutil.cp=fs.cp +shutil.mv=fs.mv +function shutil.ls(p) for k,v in ipairs(fs.list(p)) do print(v) end end -function cat(p) +function shutil.cat(p) local f=io.open(p) print(f:read("*a")) f:close() end -function ps(f) +function shutil.ps(f) local f=f or "" print("PID\tName") for k,v in pairs(os.tasks()) do @@ -20,13 +21,22 @@ function ps(f) end end end -function mem() +function shutil.mem() print(" \tTotal\tFree\tUsed") io.write("Mem\t") io.write(tostring(math.floor(computer.totalMemory()/1024)).."K\t") io.write(tostring(math.floor(computer.freeMemory()/1024)).."K\t") print(tostring(math.floor((computer.totalMemory()-computer.freeMemory())/1024)).."K\t") end +function shutil.genenv() + local et = os.genenv() + for k,v in pairs(shutil) do + if k ~= "genenv" then + et[k] = v + end + end + return et +end function loadfile(fn) local f=io.open(fn,"rb") local S=f:read("*a") From 4557dc3ad4e3a5650219cabe209a4301f0461920 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 13:45:24 +1000 Subject: [PATCH 10/11] made luash actually listen to sI being assigned --- exec/luash.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exec/luash.lua b/exec/luash.lua index 3a6fc74..0d58b1d 100644 --- a/exec/luash.lua +++ b/exec/luash.lua @@ -1,5 +1,5 @@ local tA = {...} -local si = +local si = tA[1] spawn("lua shell",function() _ENV = shutil.genenv() coroutine.yield() From 69628df044af7ccdc62fb5deec901b02f0632fab Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 13 Sep 2017 14:28:33 +1000 Subject: [PATCH 11/11] made genkernel.sh mkdir out if it doesn't exist --- genkernel.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/genkernel.sh b/genkernel.sh index daf260a..526bab6 100755 --- a/genkernel.sh +++ b/genkernel.sh @@ -1,4 +1,5 @@ #!/bin/bash +mkdir -p out/ for f in `dir -d configs/*`; do kn=$(echo $f | cut -f 1 -d '.' | cut -f 2 -d "/") ./genkernel.lua $f "$(git rev-parse --short HEAD)" > out/$kn.lua