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