2021-06-22 02:39:10 -04:00
|
|
|
local fsmanager = {}
|
2023-07-28 07:34:56 -04:00
|
|
|
fsmanager.filesystems = {}
|
|
|
|
local run = true
|
2019-11-08 23:56:43 -05:00
|
|
|
local function mount(addr)
|
2023-07-28 07:34:56 -04:00
|
|
|
dest = "/" .. (component.invoke(addr,"getLabel") or "mnt/"..addr:sub(1,3))
|
2019-11-08 23:56:43 -05:00
|
|
|
syslog("Mounting "..addr.." to "..dest)
|
|
|
|
fs.makeDirectory(dest)
|
|
|
|
local w,r = fs.mount(dest,component.proxy(addr))
|
|
|
|
if not w then
|
|
|
|
syslog("Failed to mount: "..r)
|
|
|
|
end
|
2023-07-28 07:34:56 -04:00
|
|
|
fsmanager.filesystems[addr] = dest
|
2019-11-08 23:56:43 -05:00
|
|
|
end
|
|
|
|
for addr, _ in component.list("filesystem") do
|
|
|
|
mount(addr)
|
|
|
|
end
|
2020-03-26 02:35:14 -04:00
|
|
|
|
2021-06-22 02:39:10 -04:00
|
|
|
function fsmanager.start()
|
2023-07-28 07:34:56 -04:00
|
|
|
run = true
|
2020-03-26 02:35:14 -04:00
|
|
|
return os.spawn(function()
|
2023-07-28 07:34:56 -04:00
|
|
|
while run do
|
2020-03-26 02:35:14 -04:00
|
|
|
local tE = {coroutine.yield()}
|
|
|
|
if tE[1] == "component_added" and tE[3] == "filesystem" then
|
|
|
|
mount(tE[2])
|
2023-07-28 07:34:56 -04:00
|
|
|
elseif tE[1] == "component_removed" and fsmanager.filesystems[tE[2]] and tE[3] == "filesystem" then
|
|
|
|
syslog("Unmounting "..tE[2].." from "..fsmanager.filesystems[tE[2]])
|
|
|
|
fs.umount(fsmanager.filesystems[tE[2]])
|
2020-03-26 02:35:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,"fsmanager")
|
2019-08-01 08:41:43 -04:00
|
|
|
end
|
2023-07-28 07:34:56 -04:00
|
|
|
function fsmanager.stop()
|
|
|
|
run = false
|
|
|
|
end
|
2021-06-22 02:39:10 -04:00
|
|
|
|
|
|
|
return fsmanager
|