]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/fstype
5a0665c42e9a4151fe630bcb810006cec1aa4e17
[plan9front.git] / rc / bin / fstype
1 #!/bin/rc
2 rfork e
3 m=`{dd -if $1 -bs 2048 -skip 16 >[2]/dev/null | xd -c | sed 1q | \
4         sed 's/.........(....................).*/\1/; s/ //g'}
5 if(~ $"m 01CD00101){
6         echo 9660
7         exit
8 }
9 fn fat {
10         m=`{dd -if $1 -bs 1 -count 3 -skip $2 >[2]/dev/null}
11         ~ $"m FAT
12 }
13 if(fat $1 54 || fat $1 82){
14         echo dos
15         exit
16 }
17 m=`{dd -if $1 -bs 4 -count 1 >[2]/dev/null | xd | sed 's,0000000  ,,;q'}
18 if(~ $"m 529ab12b){
19         echo paqfs
20         exit
21 }
22 dd -if $1 -count 1 >[2]/dev/null | \
23 awk '
24 /^kfs/{fs["kfs"]++}
25 /^(blocksize|daddrbits|daddrbits|indirblks|dirblks|namelen)/{p[$1]=$2}
26 END{
27         ca["fs", "blocksize"] = 4*1024
28         ca["fs", "namelen"] = 28
29         ca["fs", "dirblks"] = 6
30         ca["fs", "indirblks"] = 2
31         ca["fs", "daddrbits"] = 32
32
33         ca["fs64", "blocksize"] = 8*1024
34         ca["fs64", "namelen"] = 56
35         ca["fs64", "dirblks"] = 6
36         ca["fs64", "indirblks"] = 4
37         ca["fs64", "daddrbits"] = 64
38
39         ca["cwfs", "blocksize"] = 16*1024
40         ca["cwfs", "namelen"] = 28
41         ca["cwfs", "dirblks"] = 6
42         ca["cwfs", "indirblks"] = 2
43         ca["cwfs", "daddrbits"] = 32
44
45         ca["cwfs64", "blocksize"] = 16*1024
46         ca["cwfs64", "namelen"] = 56
47         ca["cwfs64", "dirblks"] = 6
48         ca["cwfs64", "indirblks"] = 4
49         ca["cwfs64", "daddrbits"] = 64
50
51         ca["cwfs64x", "blocksize"] = 16*1024
52         ca["cwfs64x", "namelen"] = 144
53         ca["cwfs64x", "dirblks"] = 6
54         ca["cwfs64x", "indirblks"] = 4
55         ca["cwfs64x", "daddrbits"] = 64
56
57         for(e in ca){
58                 split(e, k, SUBSEP)
59                 if(ca[k[1],k[2]] == p[k[2]])
60                         fs[k[1]]++
61         }
62         for(i in fs)
63                 if(fs[i] > fs[j])
64                         j=i
65         if(fs[j]){
66                 print j
67                 exit
68         }
69         exit 1
70 }
71 '