PsychOSPackages/slicer/exec/slicer.lua

35 lines
1.2 KiB
Lua
Raw Permalink Normal View History

local component = require "component"
local tA = {...}
2023-10-07 09:50:58 +11:00
local slicer = {}
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()
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)
local pt = require("diskpart").getPartitions(addr)
table.remove(pt, tonumber(i))
require("diskpart").setPartitions(addr, pt)
2023-10-07 09:50:58 +11:00
slicer.show()
end
2023-10-07 09:50:58 +11:00
function slicer.set(id, name, ftype, start, len)
local pt = require("diskpart").getPartitions(addr)
pt[tonumber(id)] = {name, ftype, tonumber(start), tonumber(len)}
require("diskpart").setPartitions(addr, pt)
2023-10-07 09:50:58 +11:00
slicer.show()
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)
end
2023-10-07 09:50:58 +11:00
assert(slicer[cmd], "unknown command")
slicer[cmd](table.unpack(tA))