rename fdisk to slicer, part two

This commit is contained in:
Izaya 2023-10-07 08:50:58 +10:00
parent de1ec005e6
commit 2f8abe0a0b
2 changed files with 11 additions and 11 deletions

View File

@ -1,11 +1,11 @@
local component = require "component" local component = require "component"
local tA = {...} local tA = {...}
local fdisk = {} local slicer = {}
local addr = component.get(table.remove(tA, 1)) local addr = component.get(table.remove(tA, 1))
assert(addr, "drive not found") assert(addr, "drive not found")
local cmd = table.remove(tA, 1) or "show" local cmd = table.remove(tA, 1) or "show"
function fdisk.show() function slicer.show()
local ts = component.invoke(addr, component.type(addr) == "tape_drive" and "getSize" or "getCapacity") local ts = component.invoke(addr, component.type(addr) == "tape_drive" and "getSize" or "getCapacity")
local cs = ts / 512 local cs = ts / 512
print(string.format("Drive %s - %iKiB, %0.0f sectors:", addr:sub(1,8), ts//1024,cs)) print(string.format("Drive %s - %iKiB, %0.0f sectors:", addr:sub(1,8), ts//1024,cs))
@ -14,21 +14,21 @@ function fdisk.show()
print(string.format("%2i: %-20s %4s %5i %5i %5i",k,v[1],v[2],v[3],v[4],(v[3] + v[4])-1)) 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
end end
function fdisk.del(i) function slicer.del(i)
local pt = require("diskpart").getPartitions(addr) local pt = require("diskpart").getPartitions(addr)
table.remove(pt, tonumber(i)) table.remove(pt, tonumber(i))
require("diskpart").setPartitions(addr, pt) require("diskpart").setPartitions(addr, pt)
fdisk.show() slicer.show()
end end
function fdisk.set(id, name, ftype, start, len) function slicer.set(id, name, ftype, start, len)
local pt = require("diskpart").getPartitions(addr) local pt = require("diskpart").getPartitions(addr)
pt[tonumber(id)] = {name, ftype, tonumber(start), tonumber(len)} pt[tonumber(id)] = {name, ftype, tonumber(start), tonumber(len)}
require("diskpart").setPartitions(addr, pt) require("diskpart").setPartitions(addr, pt)
fdisk.show() slicer.show()
end end
function fdisk.add(name, ftype, start, len) function slicer.add(name, ftype, start, len)
fdisk.set(#require("diskpart").getPartitions(addr)+1, name, ftype, start, len) slicer.set(#require("diskpart").getPartitions(addr)+1, name, ftype, start, len)
end end
assert(fdisk[cmd], "unknown command") assert(slicer[cmd], "unknown command")
fdisk[cmd](table.unpack(tA)) slicer[cmd](table.unpack(tA))

View File

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