From 395ade429a5dc255fb05358a0f8c1ee284e4da7a Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 28 Jul 2023 21:34:56 +1000 Subject: [PATCH] assorted filesystem-related improvements --- lib/shutil.lua | 2 +- module/fs.lua | 1 + service/fsmanager.lua | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/shutil.lua b/lib/shutil.lua index 5742dae..ece7a74 100644 --- a/lib/shutil.lua +++ b/lib/shutil.lua @@ -83,7 +83,7 @@ function shutil.df() -- Prints free disk space. local fstr = "%-"..tostring(ml).."s %5s %5s" print("fs"..(" "):rep(ml-2).." size used") for k,v in pairs(mt) do - local st, su = fs.spaceTotal(v), fs.spaceUsed(v) + local st, su = fs.spaceTotal(v.."/."), fs.spaceUsed(v.."/.") print(string.format(fstr,v,wrapUnits(st),wrapUnits(su))) end end diff --git a/module/fs.lua b/module/fs.lua index bc8e161..b9c3b1b 100644 --- a/module/fs.lua +++ b/module/fs.lua @@ -99,6 +99,7 @@ function fs.mount(path,proxy) -- string table -- boolean -- Mounts the filesyste end function fs.umount(path) -- string -- -- Unmounts filesystem from *path*. local fsi,_ = fs.resolve(path) + syslog(string.format("%s && %s",fs.resolve(path))) fsmounts[fsi] = nil end diff --git a/service/fsmanager.lua b/service/fsmanager.lua index d41323c..a2f906e 100644 --- a/service/fsmanager.lua +++ b/service/fsmanager.lua @@ -1,29 +1,36 @@ local fsmanager = {} +fsmanager.filesystems = {} +local run = true local function mount(addr) - dest = component.invoke(addr,"getLabel") or "mnt/"..addr:sub(1,3) - dest = "/"..dest + 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) end + fsmanager.filesystems[addr] = dest end for addr, _ in component.list("filesystem") do mount(addr) end function fsmanager.start() + run = true return os.spawn(function() - while true do + while run do local tE = {coroutine.yield()} if tE[1] == "component_added" and tE[3] == "filesystem" then mount(tE[2]) - elseif tE[1] == "component_removed" and tE[3] == "filesystem" then - fs.umount("/mnt/"..tE[2]:sub(1,3)) + 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]]) end end end,"fsmanager") end +function fsmanager.stop() + run = false +end return fsmanager