1 | #!/bin/bash␊ |
2 | ␊ |
3 | echo "==============================================="␊ |
4 | echo "CheckFatType: Do we have FAT16 or FAT32?"␊ |
5 | echo "****************************************"␊ |
6 | ␊ |
7 | # Receives passed value for the raw Target Device␊ |
8 | # for example: /dev/rdisk0s2␊ |
9 | # Then looks for the following in the partition boot sector␊ |
10 | # Byte number 19 to see if it's either 00 or 02␊ |
11 | # Byte number 22 to see if it's either F8 or F0␊ |
12 | # Byte number 25 to see if it's either 3F or 20␊ |
13 | #␊ |
14 | # Exit with value 1 for FAT16, 2 for FAT32 ␊ |
15 | # Exit with value 0 if nothing is found - this shouldn't happen.?␊ |
16 | ␊ |
17 | if [ "$#" -eq 1 ]; then␊ |
18 | ␉targetDeviceRaw="$1"␊ |
19 | ␉echo "DEBUG: passed argument = $targetDeviceRaw"␊ |
20 | else␊ |
21 | ␉echo "Error - wrong number of values passed"␊ |
22 | ␉exit 9␊ |
23 | fi␊ |
24 | ␊ |
25 | ␊ |
26 | partitionBootSector=$( dd 2>/dev/null if="$targetDeviceRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )␊ |
27 | if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "3f" ]; then␊ |
28 | ␉echo "Found a FAT32 device formatted by Windows Explorer"␊ |
29 | ␉echo "-----------------------------------------------"␊ |
30 | ␉echo ""␊ |
31 | ␉exit 2␊ |
32 | fi␊ |
33 | if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f8" ] && [ "${partitionBootSector:48:2}" == "3f" ]; then␊ |
34 | ␉echo "Found a FAT16 device formatted by Windows Explorer"␊ |
35 | ␉echo "-----------------------------------------------"␊ |
36 | ␉echo ""␊ |
37 | ␉exit 1␊ |
38 | fi␊ |
39 | if [ "${partitionBootSector:36:2}" == "00" ] && [ "${partitionBootSector:42:2}" == "f0" ] && [ "${partitionBootSector:48:2}" == "20" ]; then␊ |
40 | ␉echo "Found a FAT32 device formatted by OSX Disk Utility"␊ |
41 | ␉echo "-----------------------------------------------"␊ |
42 | ␉echo ""␊ |
43 | ␉exit 2␊ |
44 | fi␊ |
45 | if [ "${partitionBootSector:36:2}" == "02" ] && [ "${partitionBootSector:42:2}" == "f0" ] && [ "${partitionBootSector:48:2}" == "20" ]; then␊ |
46 | ␉echo "Found a FAT16 device formatted by OSX Disk Utility"␊ |
47 | ␉echo "-----------------------------------------------"␊ |
48 | ␉echo ""␊ |
49 | ␉exit 1␊ |
50 | fi␊ |
51 | ␊ |
52 | echo "-----------------------------------------------"␊ |
53 | echo ""␊ |
54 | exit 0 |