1
1
mirror of https://git.shadowkat.net/izaya/OC-PsychOS2.git synced 2024-11-25 20:48:43 -05:00

added some filesystem-related utils

This commit is contained in:
XeonSquared 2019-11-09 14:54:01 +11:00
parent aed9278433
commit faca451c57
2 changed files with 47 additions and 0 deletions

23
exec/df.lua Normal file
View File

@ -0,0 +1,23 @@
local mt = fs.mounts()
local ml = 0
for k,v in pairs(mt) do
if v:len() > ml then
ml = v:len()
end
end
local scale = {"K","M","G","T","P"}
local function wrapUnits(n)
local count = 0
while n > 1024 do
count = count + 1
if not scale[count] then return "inf" end
n = n / 1024
end
return tostring(n)..(scale[count] or "")
end
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)
print(string.format(fstr,v,wrapUnits(st),wrapUnits(su)))
end

24
exec/mount.lua Normal file
View File

@ -0,0 +1,24 @@
local tA = {...}
if #tA < 1 then
local mt = fs.mounts()
for k,v in pairs(mt) do
print(tostring(fs.address(v)).." on "..tostring(v).." type "..fs.type(v))
end
else
local addr,path = tA[1],tA[2]
local fscomp = component.list("filesystem")
if not fscomp[addr] then
for k,v in pairs(fscomp) do
if k:find(addr) then
print(tostring(addr).." not found, assuming you meant "..k)
addr = k
break
end
end
end
local proxy = component.proxy(addr)
if not proxy then
return false, "no such filesystem component"
end
print(fs.mount(path,proxy))
end