From ba8ea3c71bb0f7463ea3037c296808b16b1ed5b3 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sun, 1 Oct 2023 13:51:38 +1000 Subject: [PATCH] add fdisk utility for managing partitions --- fdisk/exec/fdisk.lua | 30 ++++++++++++++++++++++++++++++ fdisk/package.cfg | 4 ++++ 2 files changed, 34 insertions(+) create mode 100644 fdisk/exec/fdisk.lua create mode 100644 fdisk/package.cfg diff --git a/fdisk/exec/fdisk.lua b/fdisk/exec/fdisk.lua new file mode 100644 index 0000000..4189026 --- /dev/null +++ b/fdisk/exec/fdisk.lua @@ -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)) diff --git a/fdisk/package.cfg b/fdisk/package.cfg new file mode 100644 index 0000000..bb0c135 --- /dev/null +++ b/fdisk/package.cfg @@ -0,0 +1,4 @@ +{["name"]="fdisk", + ["description"]="Partition management utility", + ["authors"]="Izaya", + ["dependencies"]={"diskpart"}}