From 6bcf6f19a222915c10ff5403c900473d9286b843 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 20 Apr 2017 01:05:59 +1000 Subject: [PATCH] added filesystem library, is now in the default modules --- modules.cfg | 3 +++ modules/library/fs-min.lua | 6 ++++++ modules/library/fs-std.lua | 29 +++++++++++++++++++++++++++++ modules/util/fs-automount-min.lua | 1 + modules/util/fs-automount.lua | 1 + 5 files changed, 40 insertions(+) create mode 100644 modules/library/fs-min.lua create mode 100644 modules/library/fs-std.lua create mode 100644 modules/util/fs-automount-min.lua create mode 100644 modules/util/fs-automount.lua diff --git a/modules.cfg b/modules.cfg index 8714666..7e49ab6 100644 --- a/modules.cfg +++ b/modules.cfg @@ -3,5 +3,8 @@ drivers/dterm.lua library/print.lua drivers/keyboard.lua library/net.lua +library/fs-min.lua +library/fs-std.lua +util/fs-automount.lua applications/luash.lua base/footer.lua diff --git a/modules/library/fs-min.lua b/modules/library/fs-min.lua new file mode 100644 index 0000000..f717d35 --- /dev/null +++ b/modules/library/fs-min.lua @@ -0,0 +1,6 @@ +fT = {} +function fres(p) + local fid = (p:match("(%a-):.+") or p:match("/?(%a-)/.+")) + local pt = (p:match("%a-:(.+)") or p:match("/?%a-/(.+)")) + if fT[fid] ~= nil and pt ~= nil then return fT[fid],pt else return false end +end diff --git a/modules/library/fs-std.lua b/modules/library/fs-std.lua new file mode 100644 index 0000000..34ed760 --- /dev/null +++ b/modules/library/fs-std.lua @@ -0,0 +1,29 @@ +hT = {["_c"]=0} +function fopen(p,m) + local d,p = fres(p) + local f=d.open(p,m) + if f then + hT._c = hT._c + 1 + hT[hT._c] = {d,f} + return hT._c + end + return false +end +function fclose(h) + if hT[h] then + hT[h][1].close(hT[h][2]) + end + return false +end +function fread(h,n) + if hT[h] then + return hT[h][1].read(hT[h][2],n) + end + return false +end +function fwrite(h,d) + if hT[h] then + return hT[h][1].write(hT[h][2],d) + end + return false +end diff --git a/modules/util/fs-automount-min.lua b/modules/util/fs-automount-min.lua new file mode 100644 index 0000000..30d7530 --- /dev/null +++ b/modules/util/fs-automount-min.lua @@ -0,0 +1 @@ +fT.tmp,fT.boot = component.proxy(computer.tmpAddress()),component.proxy(computer.tmpAddress()) diff --git a/modules/util/fs-automount.lua b/modules/util/fs-automount.lua new file mode 100644 index 0000000..7e3594d --- /dev/null +++ b/modules/util/fs-automount.lua @@ -0,0 +1 @@ +fT.tmp,fT.boot = component.proxy(computer.tmpAddress()),component.proxy(computer.getBootAddress())