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.

27 lines
670B

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