2023-10-06 20:00:57 +11:00
|
|
|
local component = require "component"
|
2023-10-01 14:51:38 +11:00
|
|
|
local tA = {...}
|
2023-10-07 09:50:58 +11:00
|
|
|
local slicer = {}
|
2023-10-01 14:51:38 +11:00
|
|
|
local addr = component.get(table.remove(tA, 1))
|
|
|
|
assert(addr, "drive not found")
|
|
|
|
local cmd = table.remove(tA, 1) or "show"
|
|
|
|
|
2023-10-07 09:50:58 +11:00
|
|
|
function slicer.show()
|
2023-10-01 14:51:38 +11:00
|
|
|
local ts = component.invoke(addr, component.type(addr) == "tape_drive" and "getSize" or "getCapacity")
|
|
|
|
local cs = ts / 512
|
|
|
|
print(string.format("Drive %s - %iKiB, %0.0f sectors:", addr:sub(1,8), ts//1024,cs))
|
|
|
|
print(" # Name Type Start Len End")
|
|
|
|
for k,v in ipairs(require("diskpart").getPartitions(addr)) do
|
|
|
|
print(string.format("%2i: %-20s %4s %5i %5i %5i",k,v[1],v[2],v[3],v[4],(v[3] + v[4])-1))
|
|
|
|
end
|
|
|
|
end
|
2023-10-07 09:50:58 +11:00
|
|
|
function slicer.del(i)
|
2023-10-01 14:51:38 +11:00
|
|
|
local pt = require("diskpart").getPartitions(addr)
|
2023-10-06 20:00:57 +11:00
|
|
|
table.remove(pt, tonumber(i))
|
2023-10-01 14:51:38 +11:00
|
|
|
require("diskpart").setPartitions(addr, pt)
|
2023-10-07 09:50:58 +11:00
|
|
|
slicer.show()
|
2023-10-01 14:51:38 +11:00
|
|
|
end
|
2023-10-07 09:50:58 +11:00
|
|
|
function slicer.set(id, name, ftype, start, len)
|
2023-10-01 14:51:38 +11:00
|
|
|
local pt = require("diskpart").getPartitions(addr)
|
2023-10-06 20:00:57 +11:00
|
|
|
pt[tonumber(id)] = {name, ftype, tonumber(start), tonumber(len)}
|
2023-10-01 14:51:38 +11:00
|
|
|
require("diskpart").setPartitions(addr, pt)
|
2023-10-07 09:50:58 +11:00
|
|
|
slicer.show()
|
2023-10-01 14:51:38 +11:00
|
|
|
end
|
2023-10-07 09:50:58 +11:00
|
|
|
function slicer.add(name, ftype, start, len)
|
|
|
|
slicer.set(#require("diskpart").getPartitions(addr)+1, name, ftype, start, len)
|
2023-10-06 20:00:57 +11:00
|
|
|
end
|
2023-10-01 14:51:38 +11:00
|
|
|
|
2023-10-07 09:50:58 +11:00
|
|
|
assert(slicer[cmd], "unknown command")
|
|
|
|
slicer[cmd](table.unpack(tA))
|