local a=syscall.getTask(syscall.getpid()).name;local b,c={},{help=false,o=nil}local d=1;local e={...}while d<=#e do local f=e[d]if f:sub(1,2)=="--"then local g=f:sub(3)if g=="help"then c.help=true else print(a..": unrecognised option '"..f.."'")print("try '"..a.." --help' for more information.")syscall.exit(1)return end elseif f=="-o"then d=d+1;c.o=e[d]elseif f:sub(1,1)=="-"then local h=f:sub(2)if h:sub(1,1)=="o"then if#h>1 then c.o=h:sub(2)else d=d+1;c.o=e[d]end else print(a..": invalid option '"..f.."'")print("try '"..a.." --help' for more information.")syscall.exit(1)return end else table.insert(b,f)end;d=d+1 end;if c.help then print("Usage: "..a)print(" "..a.." ")print(" "..a.." -o loop ")print("")print("Mount a loop device or filesystem.")print("")print(" (no args) list all active mount points")print(" mount an already-attached loop device")print(" -o loop attach src as loop device and mount at dest")print(" src can be a directory (bind) or .hfs image")print("")print("Requires root for all operations except listing.")return end;if#b==0 and not c.o then local i,j=pcall(syscall.mounts or function()error("ENOSYS")end)local k={}local l,m=pcall(syscall.lolist)if l then for n,o in pairs(m)do local p=type(o)=="table"and o.path or tostring(o)local q=type(o)=="table"and o.mode or"bind"k[n]={path=p,mode=q}end end;if next(k)==nil then syscall.devctl(1,"sfgc",0xFF00FF)print("(no loop devices attached)")syscall.devctl(1,"sfgc",0xFFFFFF)return end;for n,o in pairs(k)do local r=o.mode=="image"and 0x00FFFF or 0x0000FF;syscall.devctl(1,"sfgc",r)printInline(o.mode.." "..n)syscall.devctl(1,"sfgc",0xFFFFFF)print(" on "..o.path)end;return end;if c.o and c.o:lower()=="loop"then if#b<2 then print(a..": -o loop requires and ")print("try '"..a.." --help' for more information.")syscall.exit(1)return end;local s=b[1]local t=b[2]if s:sub(1,1)~="/"then s=syscall.getcwd().."/"..s end;if t:sub(1,1)~="/"then t=syscall.getcwd().."/"..t end;local i,u=pcall(syscall.losetup,s)if not i then local v=tostring(u)if v:find("EPERM")then v="Permission denied"elseif v:find("EINVAL")then v="'"..b[1].."': not a directory or .hfs image"elseif v:find("EIO")then v="'"..b[1].."': I/O error reading image"end;print(a..": losetup: "..v)syscall.exit(1)return end;local w,x=pcall(syscall.mount,t,u)if not w then pcall(syscall.lodetach,u)local v=tostring(x)if v:find("EPERM")then v="Permission denied"elseif v:find("EBUSY")then v="'"..t.."' is already a mount point"elseif v:find("ENODEV")then v="loop device not found (internal error)"end;print(a..": mount: "..v)syscall.exit(1)return end;syscall.devctl(1,"sfgc",0x00FFFF)print(a..": "..u.." mounted at "..t)syscall.devctl(1,"sfgc",0xFFFFFF)return end;if#b==2 then local u=b[1]local t=b[2]if t:sub(1,1)~="/"then t=syscall.getcwd().."/"..t end;local i,y=pcall(syscall.mount,t,u)if not i then local v=tostring(y)if v:find("EPERM")then v="Permission denied"elseif v:find("ENODEV")then v="'"..u.."': no such device - use losetup first"elseif v:find("EBUSY")then v="'"..t.."' is already a mount point"elseif v:find("EINVAL")then v="invalid arguments"end;print(a..": "..v)syscall.exit(1)return end;syscall.devctl(1,"sfgc",0x00FFFF)print(a..": "..u.." mounted at "..t)syscall.devctl(1,"sfgc",0xFFFFFF)return end;print(a..": wrong number of arguments")print("try '"..a.." --help' for more information.")syscall.exit(1)