Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. --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.
  2. --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
  3.  
  4. --this program should allow all unmanaged drives on a server to be treated like a single drive
  5.  
  6. local comp = require("component")
  7.  
  8. 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?
  9.  
  10. local drives = {}
  11.  
  12. comp.modem.open(12345)
  13.  
  14. for k,v in pairs(comp.list("drive")) do
  15. drives[1+#drives] = comp.proxy(v) --pretty sure comp.list() returns componentName, address
  16. end
  17.  
  18. local findByte = function(loc)
  19. if loc < 0 then
  20. return "Invalid position"
  21. end
  22. local temp = loc
  23. for k,v in ipairs(drives) do
  24. if temp < v.getCapacity() then
  25. return v, temp
  26. else
  27. temp = temp - v.getCapacity()
  28. end
  29. end
  30. return "Out of bounds"
  31. end
  32.  
  33. local readByte = function(loc)
  34. local drive, loc = findByte(loc)
  35. if type(drive) == "string" then
  36. return drive
  37. else
  38. return drive.readByte(loc)
  39. end
  40. end
  41.  
  42. local writeByte = function(loc, data)
  43. local drive, loc = findByte(loc)
  44. if type(drive) == "string" then
  45. return drive
  46. else
  47. return drive.writeByte(loc, data)
  48. end
  49. end
  50.  
  51. local readBulk = function(start, length)
  52. local buffer = ""
  53. for i=start, length + start - 1 do
  54. buffer = buffer .. string.char(readByte(i))
  55. end
  56. return buffer
  57. end
  58.  
  59. local writeBulk = function(start, data)
  60. for i=1, length do
  61. writeByte(i+start-1, string.byte(data, i))
  62. end
  63. end
  64.  
  65. local getCapacity = function()
  66. local cap
  67. for k,v in pairs(driveTbl) do
  68. cap = cap + v.getCapacity()
  69. end
  70. return cap
  71. end
  72.  
  73. local waitForPackets = function(...)
  74. local _, _, sender, _, _, command, arg1, arg2, arg3 = table.unpack({...})
  75. print(sender, command, arg1, arg2, arg3)
  76. if command == "readByte" then
  77. comp.modem.send(sender, 12345, readByte(arg1))
  78. elseif command == "writeByte" then
  79. comp.modem.send(sender, 12345, writeByte(arg1))
  80. elseif command == "readStr" then
  81. comp.modem.send(sender, 12345, readBulk(arg1, arg2))
  82. elseif command == "writeStr" then
  83. comp.modem.send(sender, 12345, writeBulk(arg1, arg2))
  84. elseif command == "getCapacity" then
  85. comp.modem.send(sender, 12345, getCapacity())
  86. elseif command == "raidConnectionCheck" then
  87. os.sleep(1)
  88. comp.modem.send(sender, 12345, "raidConnectionConfirm")
  89. end --if not the command for this one, ignore it
  90. end
  91.  
  92. event.listen("modem_message", waitForPackets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement