Operating system for OpenComputers
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

39 lines
1015B

  1. local fsmanager = {}
  2. fsmanager.filesystems = {}
  3. local run = true
  4. local function mount(addr)
  5. dest = "/" .. (component.invoke(addr,"getLabel") or "mnt/"..addr:sub(1,3))
  6. syslog("Mounting "..addr.." to "..dest)
  7. fs.makeDirectory(dest)
  8. local w,r = fs.mount(dest,component.proxy(addr))
  9. if not w then
  10. syslog("Failed to mount: "..r)
  11. return false
  12. end
  13. fsmanager.filesystems[addr] = dest
  14. end
  15. function fsmanager.start()
  16. run = true
  17. return os.spawn(function()
  18. for addr, _ in component.list("filesystem") do
  19. mount(addr)
  20. end
  21. while run do
  22. local tE = {coroutine.yield()}
  23. if tE[1] == "component_added" and tE[3] == "filesystem" then
  24. mount(tE[2])
  25. elseif tE[1] == "component_removed" and fsmanager.filesystems[tE[2]] and tE[3] == "filesystem" then
  26. syslog("Unmounting "..tE[2].." from "..fsmanager.filesystems[tE[2]])
  27. fs.umount(fsmanager.filesystems[tE[2]])
  28. fsmanager.filesystems[tE[2]] = nil
  29. end
  30. end
  31. end,"fsmanager")
  32. end
  33. function fsmanager.stop()
  34. run = false
  35. end
  36. return fsmanager