39 lines
962 B
Lua
39 lines
962 B
Lua
|
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
|