Compare commits
2 Commits
d3c053b661
...
c24689d1a6
Author | SHA1 | Date | |
---|---|---|---|
c24689d1a6 | |||
7f9c8d410d |
49
partition/partman.lua
Normal file
49
partition/partman.lua
Normal 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
|
@ -38,16 +38,14 @@ local ftypes = {
|
|||||||
dfext = 2,
|
dfext = 2,
|
||||||
ddir = 3,
|
ddir = 3,
|
||||||
ddex = 4,
|
ddex = 4,
|
||||||
dtfile = 5,
|
tfile = 5,
|
||||||
dtext = 6,
|
text = 6,
|
||||||
dlink = 7,
|
dlink = 7,
|
||||||
unused = 8,
|
unused = 8,
|
||||||
file = 9,
|
file = 9,
|
||||||
fext = 10,
|
fext = 10,
|
||||||
dir = 11,
|
dir = 11,
|
||||||
dex = 12,
|
dex = 12,
|
||||||
tfile = 13,
|
|
||||||
text = 14,
|
|
||||||
link = 15
|
link = 15
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user