]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/fstype
boot(8): merge usb boot method into local
[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 dd -if $1 -count 1 >[2]/dev/null | \
18 awk '
19 /^kfs/{fs["kfs"]++}
20 /^(blocksize|daddrbits|daddrbits|indirblks|dirblks|namelen)/{p[$1]=$2}
21 END{
22         ca["fs", "blocksize"] = 4*1024
23         ca["fs", "namelen"] = 28
24         ca["fs", "dirblks"] = 6
25         ca["fs", "indirblks"] = 2
26         ca["fs", "daddrbits"] = 32
27
28         ca["fs64", "blocksize"] = 8*1024
29         ca["fs64", "namelen"] = 56
30         ca["fs64", "dirblks"] = 6
31         ca["fs64", "indirblks"] = 4
32         ca["fs64", "daddrbits"] = 64
33
34         ca["cwfs", "blocksize"] = 16*1024
35         ca["cwfs", "namelen"] = 28
36         ca["cwfs", "dirblks"] = 6
37         ca["cwfs", "indirblks"] = 2
38         ca["cwfs", "daddrbits"] = 32
39
40         ca["cwfs64", "blocksize"] = 16*1024
41         ca["cwfs64", "namelen"] = 56
42         ca["cwfs64", "dirblks"] = 6
43         ca["cwfs64", "indirblks"] = 4
44         ca["cwfs64", "daddrbits"] = 64
45
46         ca["cwfs64x", "blocksize"] = 16*1024
47         ca["cwfs64x", "namelen"] = 144
48         ca["cwfs64x", "dirblks"] = 6
49         ca["cwfs64x", "indirblks"] = 4
50         ca["cwfs64x", "daddrbits"] = 64
51
52         for(e in ca){
53                 split(e, k, SUBSEP)
54                 if(ca[k[1],k[2]] == p[k[2]])
55                         fs[k[1]]++
56         }
57         for(i in fs)
58                 if(fs[i] > fs[j])
59                         j=i
60         if(fs[j]){
61                 print j
62                 exit
63         }
64         exit 1
65 }
66 '