local a=import("serialize")local b=import("component")local c=import("computer")local d=import("unicode")local e,f=b.gpu.getResolution()local f={...}local g=not not(table.find(f,"-a")or table.find(f,"--all"))local h={}local i={}local j={["slot"]="SLOT",["capacity"]="CAPACITY",["managed"]="MANAGED",["readOnly"]="READ-ONLY",["id"]="FULL COMPONENT ID",["mount"]="MOUNT",["bootable"]="BOOTABLE",["label"]="LABEL"}local k={["slot"]=false,["capacity"]=true,["managed"]=false,["readOnly"]=false,["id"]=false,["mount"]=false,["bootable"]=false,["label"]=false}local function l(a)table.insert(i,{k[a],j[a]})h[a]=#i end;for a,b in pairs(h)do print(a,b)end;local function k()l("slot")l("capacity")l("managed")l("readOnly")l("id")l("mount")l("bootable")l("label")end;local function m()if e>100 then l("slot")end;l("capacity")if e>80 then l("id")end;l("mount")l("label")end;local function e(a)print(a)return shell.run("help lsdrv")end;local n=table.find(f,"-o")or table.find(f,"--output")if g then k()elseif n then table.remove(f,n)local a=table.remove(f,n)if not a then return e("Argument -o must have a value")end;if a=="all"then k()else if a:sub(1,1)=="+"then m()end;for a in string.gmatch(a:sub(2),"([^,]+)")do if j[a]then l(a)else print("\x1b[93mCategory \""..a.."\" doesn't exist\x1b[39m")end end end else m()end;local function j(a)return not not h[a]end;local k=not(table.find(f,"-H")or table.find(f,"--si"))local function l(a)local b=k and{"B","KiB","MiB","GiB"}or{"B","KB","MB","GB"}local c=1;local e=k and 1024 or 1000;while a>e and b[c]do c=c+1;a=a/e end;local a=tostring(a):sub(1,5)if d.sub(a,-2)==".0"then a=d.sub(a,1,-3)end;return a.." "..b[c]end;local function k(a,b)return a.exists(b)and not a.isDirectory(b)end;local function m(a)local a=a.readSector(1)for b=1,#a do if a:sub(b,b)=="\0"then a=a:sub(1,b-1)break end end;return a end;local function n(a,b)if b=="drive"then return not not load(m(a))elseif b=="filesystem"then return not not(k(a,"/init.lua")or k(a,"/OS.lua"))end end;local function k(a)return({[true]="Yes",[false]="No"})[a]end;local function m(d,e)if not d then return end;local f=b.proxy(d)if not f then return end;local g,m,o,p,q,r,s;local b=b.slot(d)if b==-1 then g="Virtual"elseif b==9 then g="EEPROM"else g="#"..(b+2)end;o="Yes"p="No"if e=="drive"then o="No"m=l(f.getCapacity())q="/special/drive/"..d:sub(1,3)elseif e=="filesystem"then m=l(f.spaceTotal())if f.isReadOnly()then p="Yes"end;q="/mnt/"..d:sub(1,3)if c.getBootAddress()==d then q="/"end;if c.tmpAddress()==d then q="/tmp"g="Temporary"end elseif e=="eeprom"then m=l(f.getSize()+f.getDataSize())q="/special/eeprom/"end;if j("bootable")then r=k(n(f,e))end;if f.getLabel then local b=f.getLabel()s=b and a.string(b)or"None"else s="Unsupported"end;local function a(a,b)if not h[a]then return end;table.insert(i[h[a]],b or"unknown")end;a("slot",g)a("capacity",m)a("managed",o)a("readOnly",p)a("id",d)a("mount",q)a("bootable",r)a("label",s)end;local function a(a,b)local c=1;while c<=#a do if not b(a[c])then table.remove(a,c)c=c-1 end;c=c+1 end end;local function h(a)local a,d=load("local component,computer,type,id,readonly,capacity=... local managed,eeprom,halyde,tmp,proxy,slot,all=type==\"drive\",type==\"eeprom\",id==\""..c.getBootAddress().."\",id==\""..c.tmpAddress().."\",component.proxy(id),component.slot(id)+2,true return "..a)if a then return function(d)local e,f=false,nil;if d[2]=="filesystem"then e=b.invoke(d[1],"isReadOnly")f=b.invoke(d[1],"spaceTotal")elseif d[2]=="drive"then f=b.invoke(d[1],"getCapacity")elseif d[2]=="eeprom"then f=b.invoke(d[1],"getSize")+b.invoke(d[1],"getDataSize")end;return a(b,c,d[2],d[1],e,f)end else return nil,d end end;local function j(a)if type(a)=="boolean"then if a then return 1 else return 0 end end;return a end;local k={}for a,b in b.list("filesystem")do table.insert(k,{a,b})end;for a,b in b.list("drive")do table.insert(k,{a,b})end;for a,b in b.list("eeprom")do table.insert(k,{a,b})end;if not g then local b=table.find(f,"-s")or table.find(f,"--show")if b then table.remove(f,b)local b=table.remove(f,b)if not b then return e("Argument -s must have a value")end;local b,c=h(b)if b then a(k,b)else return print("\x1b[91mInvalid component filter:\n\n"..tostring(c).."\x1b[39m")end else a(k,function(a)return a[2]~="eeprom"and a[1]~=c.tmpAddress()end)end end;local a=table.find(f,"-S")or table.find(f,"--sort")if a then table.remove(f,a)local a=table.remove(f,a)if not a then return e("Argument -S must have a value")end;local a,b=h(a)if a then table.sort(k,function(b,c)return(j(a(b))or 0)<(j(a(c))or 0)end)else return print("\x1b[91mInvalid sort expression:\n\n"..tostring(b).."\x1b[39m")end else table.sort(k,function(a,b)return a[1]0 then for a,a in ipairs(k)do m(a[1],a[2])end else return print("Could not find storage components for this filter.")end;local function a()local a={}for b=1,#i[1]-1 do table.insert(a,"")end;for b=1,#i do local c=1;for a=1,#a do i[b][a+1]=i[b][a+1]or"[nil]"c=math.max(c,d.wlen(i[b][a+1]))end;for e=1,#a do if i[b][1]then a[e]=a[e]..string.rep(" ",c-d.wlen(i[b][e+1]))..i[b][e+1]elseif b<#i then a[e]=a[e]..i[b][e+1]..string.rep(" ",c-d.wlen(i[b][e+1]))else a[e]=a[e]..i[b][e+1]end;if b<#i then a[e]=a[e].." "end end end;print(a[1].."\n")for b=2,#a do print(a[b])end end;a()