Files
HyperionOS/prod/hysh/bin/umount

2 lines
2.4 KiB
Plaintext

local a=syscall.getTask(syscall.getpid()).name;local b,c={},{l=false,["no-detach"]=false,help=false}for d,e in ipairs({...})do if e:sub(1,2)=="--"then local f=e:sub(3)if c[f]~=nil then c[f]=true else print(a..": unrecognised option '"..e.."'")print("try '"..a.." --help' for more information.")syscall.exit(1)return end elseif e:sub(1,1)=="-"then for g=2,#e do local h=e:sub(g,g)if c[h]~=nil then c[h]=true else print(a..": invalid option '-"..h.."'")print("try '"..a.." --help' for more information.")syscall.exit(1)return end end else table.insert(b,e)end end;if c.help then print("Usage: "..a.." <mountpoint>")print(" "..a.." --no-detach <mountpoint>")print(" "..a.." -l <loopid>")print("")print("Unmount a filesystem mounted at <mountpoint>.")print("")print(" <mountpoint> unmount and auto-detach any loop device")print(" --no-detach unmount but keep the loop device attached")print(" -l <loopid> forcibly detach a loop device (no unmount)")print("")print("Requires root.")return end;if c.l then if#b<1 then print(a..": -l requires a loop device id")print("try '"..a.." --help' for more information.")syscall.exit(1)return end;local i=b[1]local j,k=pcall(syscall.lodetach,i)if not j then local l=tostring(k)if l:find("EPERM")then l="Permission denied"elseif l:find("ENXIO")then l="no such loop device '"..i.."'"elseif l:find("EBUSY")then l="'"..i.."' is still mounted - unmount first or omit -l"end;print(a..": "..l)syscall.exit(1)return end;syscall.devctl(1,"sfgc",0x00FFFF)print(a..": detached "..i)syscall.devctl(1,"sfgc",0xFFFFFF)return end;if#b<1 then print(a..": missing mount point operand")print("try '"..a.." --help' for more information.")syscall.exit(1)return end;local m=b[1]if m:sub(1,1)~="/"then m=syscall.getcwd().."/"..m end;local n=nil;if not c["no-detach"]then local o,p=pcall(syscall.lolist)if o then n={}for i in pairs(p)do n[#n+1]=i end end end;local j,k=pcall(syscall.umount,m)if not j then local l=tostring(k)if l:find("EPERM")then l="Permission denied"elseif l:find("EINVAL")then l="'"..b[1].."' is not a mount point"elseif l:find("EBUSY")then l="'"..b[1].."' is busy - close open files first"end;print(a..": "..l)syscall.exit(1)return end;syscall.devctl(1,"sfgc",0x00FFFF)print(a..": unmounted "..m)syscall.devctl(1,"sfgc",0xFFFFFF)if n then for d,i in ipairs(n)do local q=pcall(syscall.lodetach,i)if q then syscall.devctl(1,"sfgc",0xFF00FF)print(a..": auto-detached "..i)syscall.devctl(1,"sfgc",0xFFFFFF)end end end