Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --since the raid blocks are managed only, we need a way to make server act as unmanaged raids, allowing us to treat them as single drives. Preferably someting that runs on an EEPROM to not cost drive space, I'd say.
- --this would also require rewriting the raid manager we wrote before slightly, replacing the drive.readByte() and drive.writeByte() with reading from/writing to the raid racks
- --this program should allow all unmanaged drives on a server to be treated like a single drive
- local comp = require("component")
- local event = require("event") --this will have to be replaced to use on an EEPROM. Maybe grab and copy the event implementation from OpenOS? Maybe we can install OpenOS on and run this from a floppy?
- local drives = {}
- comp.modem.open(12345)
- for k,v in pairs(comp.list("drive")) do
- drives[1+#drives] = comp.proxy(v) --pretty sure comp.list() returns componentName, address
- end
- local findByte = function(loc)
- if loc < 0 then
- return "Invalid position"
- end
- local temp = loc
- for k,v in ipairs(drives) do
- if temp < v.getCapacity() then
- return v, temp
- else
- temp = temp - v.getCapacity()
- end
- end
- return "Out of bounds"
- end
- local readByte = function(loc)
- local drive, loc = findByte(loc)
- if type(drive) == "string" then
- return drive
- else
- return drive.readByte(loc)
- end
- end
- local writeByte = function(loc, data)
- local drive, loc = findByte(loc)
- if type(drive) == "string" then
- return drive
- else
- return drive.writeByte(loc, data)
- end
- end
- local readBulk = function(start, length)
- local buffer = ""
- for i=start, length + start - 1 do
- buffer = buffer .. string.char(readByte(i))
- end
- return buffer
- end
- local writeBulk = function(start, data)
- for i=1, length do
- writeByte(i+start-1, string.byte(data, i))
- end
- end
- local getCapacity = function()
- local cap
- for k,v in pairs(driveTbl) do
- cap = cap + v.getCapacity()
- end
- return cap
- end
- local waitForPackets = function(...)
- local _, _, sender, _, _, command, arg1, arg2, arg3 = table.unpack({...})
- print(sender, command, arg1, arg2, arg3)
- if command == "readByte" then
- comp.modem.send(sender, 12345, readByte(arg1))
- elseif command == "writeByte" then
- comp.modem.send(sender, 12345, writeByte(arg1))
- elseif command == "readStr" then
- comp.modem.send(sender, 12345, readBulk(arg1, arg2))
- elseif command == "writeStr" then
- comp.modem.send(sender, 12345, writeBulk(arg1, arg2))
- elseif command == "getCapacity" then
- comp.modem.send(sender, 12345, getCapacity())
- elseif command == "raidConnectionCheck" then
- os.sleep(1)
- comp.modem.send(sender, 12345, "raidConnectionConfirm")
- end --if not the command for this one, ignore it
- end
- event.listen("modem_message", waitForPackets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement