add some requires and type casts to make diskpart and fdisk work on OpenOS without modification

This commit is contained in:
Izaya 2023-10-06 19:00:57 +10:00
parent b9216ff85b
commit 64951b513b
2 changed files with 10 additions and 5 deletions

View File

@ -1,3 +1,4 @@
local component = require "component"
local partition = {} local partition = {}
local eformat = "c20c4>I4>I4" local eformat = "c20c4>I4>I4"

View File

@ -1,3 +1,4 @@
local component = require "component"
local tA = {...} local tA = {...}
local fdisk = {} local fdisk = {}
local addr = component.get(table.remove(tA, 1)) local addr = component.get(table.remove(tA, 1))
@ -15,15 +16,18 @@ function fdisk.show()
end end
function fdisk.del(i) function fdisk.del(i)
local pt = require("diskpart").getPartitions(addr) local pt = require("diskpart").getPartitions(addr)
table.remove(pt, i) table.remove(pt, tonumber(i))
require("diskpart").setPartitions(addr, pt)
fdisk.show()
end
function fdisk.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) require("diskpart").setPartitions(addr, pt)
fdisk.show() fdisk.show()
end end
function fdisk.add(name, ftype, start, len) function fdisk.add(name, ftype, start, len)
local pt = require("diskpart").getPartitions(addr) fdisk.set(#require("diskpart").getPartitions(addr)+1, name, ftype, start, len)
pt[#pt+1] = {name, ftype, start, len}
require("diskpart").setPartitions(addr, pt)
fdisk.show()
end end
assert(fdisk[cmd], "unknown command") assert(fdisk[cmd], "unknown command")