add fdisk utility for managing partitions

This commit is contained in:
Izaya 2023-10-01 13:51:38 +10:00
parent 99f0449eb1
commit ba8ea3c71b
2 changed files with 34 additions and 0 deletions

30
fdisk/exec/fdisk.lua Normal file
View File

@ -0,0 +1,30 @@
local tA = {...}
local fdisk = {}
local addr = component.get(table.remove(tA, 1))
assert(addr, "drive not found")
local cmd = table.remove(tA, 1) or "show"
function fdisk.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
function fdisk.del(i)
local pt = require("diskpart").getPartitions(addr)
table.remove(pt, i)
require("diskpart").setPartitions(addr, pt)
fdisk.show()
end
function fdisk.add(name, ftype, start, len)
local pt = require("diskpart").getPartitions(addr)
pt[#pt+1] = {name, ftype, start, len}
require("diskpart").setPartitions(addr, pt)
fdisk.show()
end
assert(fdisk[cmd], "unknown command")
fdisk[cmd](table.unpack(tA))

4
fdisk/package.cfg Normal file
View File

@ -0,0 +1,4 @@
{["name"]="fdisk",
["description"]="Partition management utility",
["authors"]="Izaya",
["dependencies"]={"diskpart"}}