2023-08-01 18:20:21 +10:00
|
|
|
local diskpart = require "diskpart"
|
|
|
|
local vcomponent = require "vcomponent"
|
2023-11-13 00:21:50 +11:00
|
|
|
local partman = {
|
|
|
|
dtypes={
|
|
|
|
drive=true,
|
|
|
|
["tape_drive"]=true
|
|
|
|
}
|
|
|
|
}
|
2023-08-01 18:20:21 +10:00
|
|
|
|
2023-10-07 09:28:41 +11:00
|
|
|
local hooks = {}
|
|
|
|
|
|
|
|
function hooks.component_added(_,a,t)
|
2023-11-13 00:21:50 +11:00
|
|
|
if not partman.dtypes[t] then return end
|
2023-10-07 09:28:41 +11:00
|
|
|
for k,v in ipairs(diskpart.getPartitions(a)) do
|
|
|
|
if v[4] > 0 then
|
|
|
|
syslog(string.format("Registering vcomponent for partition %s/%i",a,k))
|
|
|
|
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
|
|
|
|
syslog(string.format("Trying to mount %s/%i as %s", a, k, v[2]))
|
|
|
|
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
|
2023-10-01 14:49:06 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-07 09:28:41 +11:00
|
|
|
function hooks.component_removed(_,a,t)
|
2023-11-13 00:21:50 +11:00
|
|
|
if not partman.dtypes[t] then return end
|
2023-10-07 09:28:41 +11:00
|
|
|
for ca,t in component.list() do
|
|
|
|
if (t == "partition" or t == "filesystem") and ca:sub(1,a:len()) == a then
|
|
|
|
vcomponent.unregister(ca)
|
2023-08-01 18:20:21 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function partman.start()
|
2023-10-07 09:28:41 +11:00
|
|
|
return os.spawn(function()
|
|
|
|
for a,t in component.list("drive") do
|
|
|
|
hooks.component_added(nil, a, t)
|
2023-08-01 18:20:21 +10:00
|
|
|
end
|
2023-10-07 09:28:41 +11:00
|
|
|
while true do
|
2023-08-01 18:20:21 +10:00
|
|
|
local tE = {coroutine.yield()}
|
2023-10-07 09:28:41 +11:00
|
|
|
if tE[1] and hooks[tE[1]] then
|
|
|
|
hooks[tE[1]](table.unpack(tE))
|
2023-08-01 18:20:21 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end, "partman")
|
|
|
|
end
|
2023-10-07 09:28:41 +11:00
|
|
|
|
2023-08-01 18:20:21 +10:00
|
|
|
function partman.stop()
|
2023-10-07 09:28:41 +11:00
|
|
|
for a,t in component.list("drive") do
|
|
|
|
hooks.component_removed(nil, a, t)
|
|
|
|
end
|
2023-08-01 18:20:21 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
return partman
|