Compare commits

...

2 Commits

2 changed files with 51 additions and 4 deletions

49
partition/partman.lua Normal file
View File

@ -0,0 +1,49 @@
local vcomponent = require "vcomponent"
local component = require "component"
local diskpart = require "diskpart"
local event = require "event"
local listeners = {}
local function attachDrive(_,a,t)
if t ~= "drive" then return end
for k,v in ipairs(diskpart.getPartitions(a)) do
if v[4] > 0 then
vcomponent.register(string.format("%s/%i",a,k), "partition", diskpart.proxyPartition(a, k))
local w,l = pcall(require,string.format("fs.%s",v[2]))
if w and l and l.mount then
local w, f = pcall(l.mount, string.format("%s/%i",a,k))
if w then
vcomponent.register(string.format("%s/%i/%s",a,k,v[2]), f.type or "filesystem", f)
end
end
end
end
end
local function detachDrive(_,a,t)
if t ~= "drive" then return end
for ca,t in component.list() do
if (t == "partition" or t == "filesystem") and ca:sub(1,a:len()) == a then
vcomponent.unregister(ca)
end
end
end
function start()
listeners[#listeners+1] = event.listen("component_added", attachDrive)
listeners[#listeners+1] = event.listen("component_removed", detachDrive)
for k,v in component.list("drive",true) do
attachDrive(nil,k,v)
end
end
function stop()
for k,v in ipairs(listeners) do
event.cancel(v)
listeners[k] = nil
end
for k,v in component.list("drive",true) do
detachDrive(nil,k,"drive")
end
end

View File

@ -38,16 +38,14 @@ local ftypes = {
dfext = 2,
ddir = 3,
ddex = 4,
dtfile = 5,
dtext = 6,
tfile = 5,
text = 6,
dlink = 7,
unused = 8,
file = 9,
fext = 10,
dir = 11,
dex = 12,
tfile = 13,
text = 14,
link = 15
}
```