mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-11-24 20:27:39 -05:00
45 lines
1.1 KiB
Lua
45 lines
1.1 KiB
Lua
local fsmanager = {}
|
|
fsmanager.filesystems = {}
|
|
local run = true
|
|
|
|
function fsmanager.mount(addr)
|
|
for k,v in ipairs(fs.mounts()) do
|
|
if fs.address(v) == addr then
|
|
return
|
|
end
|
|
end
|
|
dest = "/" .. (component.invoke(addr,"getLabel") or "mnt/"..addr:sub(1,3))
|
|
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)
|
|
return false
|
|
end
|
|
fsmanager.filesystems[addr] = dest
|
|
end
|
|
|
|
function fsmanager.start()
|
|
run = true
|
|
return os.spawn(function()
|
|
for addr, _ in component.list("filesystem") do
|
|
fsmanager.mount(addr)
|
|
end
|
|
while run do
|
|
local tE = {coroutine.yield()}
|
|
if tE[1] == "component_added" and tE[3] == "filesystem" then
|
|
fsmanager.mount(tE[2])
|
|
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]])
|
|
fsmanager.filesystems[tE[2]] = nil
|
|
end
|
|
end
|
|
end,"fsmanager")
|
|
end
|
|
function fsmanager.stop()
|
|
run = false
|
|
end
|
|
|
|
return fsmanager
|