-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdrive_init.lua
63 lines (58 loc) · 1.32 KB
/
drive_init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- Fuchas Boot Manager
local proxy = component.proxy(computer.getBootAddress())
local arc = ""
for i=1, 10 do
arc = arc .. proxy.readSector(1 + i) -- start at sector 2 per OpenUPT
end
local bitOr, bitLShift
if _VERSION == "Lua 5.3" then
bitOr = function(a, b)
return a | b
end
bitLShift = function(operand, shift)
return operand << shift
end
else
bitOr = bit32.bor
bitLShift = bit32.lshift
end
local function getFilesystemDriver(pType)
local i = 1
while i < arc:len() do
local name = ""
while arc:sub(i, i) ~= "\0" do
name = name .. arc:sub(i, i)
i = i + 1
end
i = i + 1
local data = ""
while arc:sub(i, i) ~= "\0" do
data = data .. arc:sub(i, i)
i = i + 1
end
i = i + 1
if name == tostring(pType) then
return load(data)()
end
end
end
-- read little-endian number
local function readInt(pos, size)
local num = 0
for i=size, 1, -1 do
local byte = proxy.readByte(pos + i)
num = bitOr(bitLShift(num, 8), byte)
end
end
for i=0, 7 do
if readInt(20 + i * 64) == 0xCAFEBEEF then -- Fuchas' root partition GUID
local pType = readInt(8 + i * 64) -- treat the type as a int as it's easier that way
local driver = getFilesystemDriver(pType)
os_arguments = ...
load(driver.readAll(
readInt(i * 64), -- start
readInt(4 + i * 64), -- end
"Fuchas/Kernel/boot.lua" -- path
))()
end
end