@@ -12,15 +12,14 @@ function F16(f,o,s)
1212 f :seek (" set" ,o )local fd ,fat = f :read (s ),{}
1313 for i = 2 ,# fd - 1 ,2 do local lo ,hi = fd :byte (i ),fd :byte (i + 1 )fat [((i - 2 )// 2 )+ 2 ]= lo + hi * 256 end return fat end
1414function FD (ts ,rs ,nf ,sf ,rd ,sc )
15- local cc = math.floor ((ts - rs - (nf * sf )- rd )/ sc )
16- if cc < 4085 then return 12 elseif cc < 65525 then return 16 else return 32 end end
15+ local c ,r = math.floor ((ts - rs - (nf * sf )- rd )/ sc )r = c < 4085 and 12 or c < 65525 and 16 or 32 return r ,c end
1716function CC (fat ,sc )
1817 local h ,c = {},sc
1918 while c >= 2 and c < 0xFF8 do table.insert (h ,c )c = fat [c ] end return h
2019end
2120function FR (c )
2221 table.sort (c )local ranges ,i = {},1
23- while i <=# c do
22+ while i <=# c do
2423 local s ,j ,f = c [i ],i while j + 1 <=# c and c [j + 1 ]== c [j ]+ 1 do j = j + 1 end f = c [j ]
2524 if s == f then table.insert (ranges ,string.format (" <%d>" ,s ))
2625 else table.insert (ranges ,string.format (" <%d-%d>" ,s ,f ))end
@@ -32,15 +31,15 @@ function DE(f,o,e,fat)
3231 if fb ~= 229 and (en :byte (12 )&8 )== 0 then
3332 local n ,x = en :sub (1 ,8 ):gsub (" +$" ," " ),en :sub (9 ,11 ):gsub (" +$" ," " )
3433 io.write (string.format (" \t %8s %3s %s\n " ,n ,x ,FR (CC (fat ,R16 (en ,27 )))))end end end
35- function FC (fat ,f ,st ,s )
34+ function FC (fat ,f ,st ,s , uc )
3635 local fr ,z = {},string.rep (" \0 " ,s )io.write (" \n\t Free Space " )
37- for i = 2 ,# fat do if fat [i ]== 0 then table.insert (fr ,i )if Z then local o = st + (i - 2 )* s f :seek (" set" ,o )f :write (z )end end end print (FR (fr ))end
36+ for i = 2 ,uc + 1 do if fat [i ]== 0 then table.insert (fr ,i )if Z then local o = st + (i - 2 )* s f :seek (" set" ,o )f :write (z )end end end print (FR (fr ))end
3837F = {}for _ ,v in ipairs (arg )do if v == " -z" then Z = 1 else table.insert (F ,v )end end for _ ,file in ipairs (F )do
3938local f = io.open (file ,(Z and " r+b" or " rb" ))if f then
4039 print (file .. " :" )
4140 local b ,o = f :read (512 )o = b :sub (1 ,1 ):byte ()if o == 235 or o == 233 then
42- local bs ,sc ,rs ,nf ,re ,ts ,sf = R16 (b ,12 ),b :byte (14 ),R16 (b ,15 ),b :byte (17 ),R16 (b ,18 ),R16 (b ,19 ) or R32 (b ,32 ), R16 (b ,23 )
43- local rd ,fo ,fs ,ro ,ft = math.ceil (re * 32 / bs ),rs * bs ,sf * bs ,(rs + nf * sf )* bs ft = FD (ts ,rs ,nf ,sf ,rd ,bs )
41+ local bs ,sc ,rs ,nf ,re ,ts ,sf = R16 (b ,12 ),b :byte (14 ),R16 (b ,15 ),b :byte (17 ),R16 (b ,18 ),R16 (b ,20 ), R16 (b ,23 ) if ts == 0 then ts = R32 (b ,32 ) end
42+ local rd ,fo ,fs ,ro ,ft , uc = math.ceil (re * 32 / bs ),rs * bs ,sf * bs ,(rs + nf * sf )* bs ft , uc = FD (ts ,rs ,nf ,sf ,rd ,sc )
4443 print (string.format (" \t FAT type: FAT%s\n\t Bytes/sector: %d\n\t Sectors/cluster: %d\n\n " ,ft ,bs ,sc ))
4544 local fat = ft == 12 and F12 (f ,fo ,fs )or ft == 16 and F16 (f ,fo ,fs )or error (" Non-FAT type" )
46- DE (f ,ro ,re ,fat )FC (fat ,f ,(rs + (nf * sf )+ rd )* bs ,sc * bs )end f :close ()print ()end end
45+ DE (f ,ro ,re ,fat )FC (fat ,f ,(rs + (nf * sf )+ rd )* bs ,sc * bs , uc )end f :close ()print ()end end
0 commit comments