From b04b03b64aaa24a1e38ca416b0bcc410173fdfcd Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Tue, 1 Aug 2023 18:20:21 +1000 Subject: [PATCH] import some service packages from local dev env --- partman/package.cfg | 4 ++++ partman/service/partman.lua | 40 +++++++++++++++++++++++++++++++++++++ rtfsman/package.cfg | 4 ++++ rtfsman/service/rtfsman.lua | 38 +++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 partman/package.cfg create mode 100644 partman/service/partman.lua create mode 100644 rtfsman/package.cfg create mode 100644 rtfsman/service/rtfsman.lua diff --git a/partman/package.cfg b/partman/package.cfg new file mode 100644 index 0000000..05c7480 --- /dev/null +++ b/partman/package.cfg @@ -0,0 +1,4 @@ +{["name"]="partman", + ["description"]="Partition vcomponent management daemon", + ["authors"]="Izaya", + ["dependencies"]={"vcomponent"}} diff --git a/partman/service/partman.lua b/partman/service/partman.lua new file mode 100644 index 0000000..d1ddb42 --- /dev/null +++ b/partman/service/partman.lua @@ -0,0 +1,40 @@ +local diskpart = require "diskpart" +local vcomponent = require "vcomponent" +local partman = {} +local run = true + +local function attach(addr) + for k,v in ipairs(diskpart.getPartitions(addr)) do + if v[4] > 0 then + syslog(string.format("Registering vcomponent for partition %s/%i",addr,k)) + vcomponent.register(string.format("%s/%i",addr,k), "partition", diskpart.proxyPartition(addr, k)) + end + end +end + +function partman.start() + run = true + os.spawn(function() + for a,_ in component.list("drive") do + attach(a) + end + while run do + local tE = {coroutine.yield()} + if tE[1] == "component_added" and tE[3] == "drive" then + attach(tE[2]) + elseif tE[1] == "component_removed" and tE[3] == "drive" then + for a,t in component.list("partition") do + if a:sub(1,tE[2]:len()) == tE[2] then + syslog("Removing partition vcomponent "..a) + vcomponent.unregister(a) + end + end + end + end + end, "partman") +end +function partman.stop() + run = false +end + +return partman diff --git a/rtfsman/package.cfg b/rtfsman/package.cfg new file mode 100644 index 0000000..155575f --- /dev/null +++ b/rtfsman/package.cfg @@ -0,0 +1,4 @@ +{["name"]="rtfsman", + ["description"]="rtfs auto-attach daemon", + ["authors"]="Izaya", + ["dependencies"]={"vcomponent"}} diff --git a/rtfsman/service/rtfsman.lua b/rtfsman/service/rtfsman.lua new file mode 100644 index 0000000..b8624ca --- /dev/null +++ b/rtfsman/service/rtfsman.lua @@ -0,0 +1,38 @@ +local vcomponent = require "vcomponent" +local rtfs = require "rtfs" +local rtfsman = {} +rtfsman.filesystems = {} +local run = true + +local function attach(addr) + local w, e = pcall(rtfs.mount,component.proxy(addr)) + if w then + syslog("rtfs filesystem found on " .. addr) + rtfsman.filesystems[addr] = true + vcomponent.register(addr .. "/rtfs", "filesystem", e) + end +end + +function rtfsman.start() + run = true + return os.spawn(function() + for a,_ in component.list("partition") do + attach(a) + end + while run do + local tE = {coroutine.yield()} + if tE[1] == "component_added" and tE[3] == "partition" then + attach(tE[2]) + elseif tE[1] == "component_removed" and rtfsman.filesystems[tE[2]] and tE[3] == "partition" then + syslog("Un-registering rtfs filesystem on " .. tE[2]) + vcomponent.unregister(tE[2] .. "/rtfs") + rtfsman.filesystems[tE[2]] = nil + end + end + end,"rtfs-manager") +end +function rtfsman.stop() + run = false +end + +return rtfsman