Operating system for OpenComputers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
779B

  1. local counter = 0
  2. local td = {}
  3. local function addNode(addr)
  4. devfs.register("tape"..tonumber(counter),function()
  5. local tape = component.proxy(addr)
  6. tape.seek(-math.huge)
  7. return tape.read, tape.write, function() end, tape.seek
  8. end)
  9. devfs.register("tapen"..tonumber(counter),function()
  10. local tape = component.proxy(addr)
  11. return tape.read, tape.write, function() end, tape.seek
  12. end)
  13. td[addr] = counter
  14. counter = counter + 1
  15. end
  16. for addr in component.list("tape_drive") do
  17. addNode(addr)
  18. end
  19. while true do
  20. local tE = {coroutine.yield()}
  21. if tE[1] == "component_added" and tE[3] == "tape_drive" then
  22. addNode(tE[2])
  23. elseif tE[1] == "component_removed" and tE[3] == "tape_drive" then
  24. if td[tE[2]] then
  25. fs.remove("/dev/tape"..tostring(td[tE[2]]))
  26. end
  27. end
  28. end