simplify partman significantly, only attempt to mount filesystems according to the partition's type
This commit is contained in:
parent
ce02798aeb
commit
fc6f168bbd
@ -1,59 +1,54 @@
|
|||||||
local diskpart = require "diskpart"
|
local diskpart = require "diskpart"
|
||||||
local vcomponent = require "vcomponent"
|
local vcomponent = require "vcomponent"
|
||||||
local partman = {}
|
local partman = {}
|
||||||
partman.fstypes = {"rtfs"}
|
|
||||||
local run = true
|
|
||||||
|
|
||||||
local function attachPartition(addr)
|
local hooks = {}
|
||||||
syslog("Finding filesystem that will mount "..addr)
|
|
||||||
for _,n in ipairs(partman.fstypes) do
|
function hooks.component_added(_,a,t)
|
||||||
local w,l = pcall(require,string.format("fs.%s",n))
|
if t ~= "drive" then return end
|
||||||
if w then
|
for k,v in ipairs(diskpart.getPartitions(a)) do
|
||||||
syslog("Trying "..n)
|
if v[4] > 0 then
|
||||||
local w, f = pcall(l.mount,addr)
|
syslog(string.format("Registering vcomponent for partition %s/%i",a,k))
|
||||||
if w then
|
vcomponent.register(string.format("%s/%i",a,k), "partition", diskpart.proxyPartition(a, k))
|
||||||
syslog(n.." successful!")
|
local w,l = pcall(require,string.format("fs.%s",v[2]))
|
||||||
vcomponent.register(string.format("%s/%s",addr,n), "filesystem",f)
|
if w and l and l.mount then
|
||||||
break
|
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function attachDrive(addr)
|
function hooks.component_removed(_,a,t)
|
||||||
for k,v in ipairs(diskpart.getPartitions(addr)) do
|
if t ~= "drive" then return end
|
||||||
if v[4] > 0 then
|
for ca,t in component.list() do
|
||||||
syslog(string.format("Registering vcomponent for partition %s/%i",addr,k))
|
if (t == "partition" or t == "filesystem") and ca:sub(1,a:len()) == a then
|
||||||
vcomponent.register(string.format("%s/%i",addr,k), "partition", diskpart.proxyPartition(addr, k))
|
vcomponent.unregister(ca)
|
||||||
syslog("Attempting to mount a filesystem...")
|
|
||||||
attachPartition(string.format("%s/%i",addr,k))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function partman.start()
|
function partman.start()
|
||||||
run = true
|
return os.spawn(function()
|
||||||
os.spawn(function()
|
for a,t in component.list("drive") do
|
||||||
for a,_ in component.list("drive") do
|
hooks.component_added(nil, a, t)
|
||||||
attachDrive(a)
|
|
||||||
end
|
end
|
||||||
while run do
|
while true do
|
||||||
local tE = {coroutine.yield()}
|
local tE = {coroutine.yield()}
|
||||||
if tE[1] == "component_added" and tE[3] == "drive" then
|
if tE[1] and hooks[tE[1]] then
|
||||||
attachDrive(tE[2])
|
hooks[tE[1]](table.unpack(tE))
|
||||||
elseif tE[1] == "component_removed" and tE[3] == "drive" then
|
|
||||||
for a,t in component.list() do
|
|
||||||
if (t == "partition" or t == "filesystem") and a:sub(1,tE[2]:len()) == tE[2] then
|
|
||||||
syslog("Removing "..t.." vcomponent "..a)
|
|
||||||
vcomponent.unregister(a)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end, "partman")
|
end, "partman")
|
||||||
end
|
end
|
||||||
|
|
||||||
function partman.stop()
|
function partman.stop()
|
||||||
run = false
|
for a,t in component.list("drive") do
|
||||||
|
hooks.component_removed(nil, a, t)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return partman
|
return partman
|
||||||
|
Loading…
Reference in New Issue
Block a user