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/build.cfg b/configs/everything.cfg similarity index 91% rename from build.cfg rename to configs/everything.cfg index d2a469a..1eba678 100755 --- a/build.cfg +++ b/configs/everything.cfg @@ -15,12 +15,12 @@ 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 -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 new file mode 100755 index 0000000..6c40f8b --- /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 +fwrap luash exec/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/configs/minimal.cfg b/configs/minimal.cfg new file mode 100755 index 0000000..45b8743 --- /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 +fwrap luash exec/luash.lua +modules/applications/genkernel.lua +modules/util/fs-automount.lua +modules/setup.lua +modules/base/footer.lua + 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) diff --git a/modules/applications/luash.lua b/exec/luash.lua similarity index 92% rename from modules/applications/luash.lua rename to exec/luash.lua index f051c19..0d58b1d 100644 --- a/modules/applications/luash.lua +++ b/exec/luash.lua @@ -1,5 +1,7 @@ -function luash(si) +local tA = {...} +local si = tA[1] spawn("lua shell",function() + _ENV = shutil.genenv() coroutine.yield() log(login()) print("\f"..MOTD) @@ -37,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 @@ -45,4 +47,3 @@ spawn("lua shell",function() end end end,{sI=si}) -end diff --git a/genkernel.sh b/genkernel.sh index eb9dde6..526bab6 100755 --- a/genkernel.sh +++ b/genkernel.sh @@ -1,3 +1,7 @@ #!/bin/bash -./genkernel.lua build.cfg "$(git rev-parse --short HEAD)" > kernel.lua -lua strip.lua kernel.lua skernel.lua +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 + lua strip.lua out/$kn.lua out/s$kn.lua +done 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 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/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") 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") 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)