add rtfsboot executable, to help make bootable rtfs volumes

This commit is contained in:
Izaya 2023-10-01 13:52:38 +10:00
parent ba8ea3c71b
commit b9216ff85b
1 changed files with 30 additions and 0 deletions

30
rtfs/exec/rtfsboot.lua Normal file
View File

@ -0,0 +1,30 @@
local diskpart = require "diskpart"
local rtfs = require "rtfs"
local tA = {...}
local fsname,fname = fs.resolve(tA[1])
local drive, part = fs.address(tA[1]):match("([%x%-]+)/(%d)")
part=tonumber(part)
print(drive,part,fname)
local m = rtfs.mount(drive.."/"..part)
local np = {fname, "boot", 0, 0}
for i, tp, ex, st, sl, n in m:allIEntries() do
if tp == 9 and n == fname then
assert(ex == 0, "boot file cannot be fragmented")
np[3], np[4] = st, math.ceil(sl/512)
end
end
local allparts = diskpart.getPartitions(drive)
local pindex = #allparts+1
np[3] = np[3] - (allparts[part][3] - 1)
for k,v in ipairs(allparts) do
if v[2] == "boot" then
pindex = k
break
end
end
allparts[pindex] = np
for k,v in ipairs(allparts) do
print(k, table.unpack(v))
end
diskpart.setPartitions(drive, allparts)