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