Module: Fat32Probe

Defined in:
lib/fs/MiqFS/modules/Fat32Probe.rb

Class Method Summary collapse

Class Method Details

.probe(dobj) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fs/MiqFS/modules/Fat32Probe.rb', line 2

def self.probe(dobj)
  unless dobj.kind_of?(MiqDisk)
    $log&.debug "Fat32Probe << FALSE because Disk Object class is not MiqDisk, but is '#{dobj.class}'"
    return false
  end

  # Assume FAT32 - read boot sector.
  dobj.seek(0)
  bs = dobj.read(512)

  # Check byte 66 for 0x29 (extended signature).
  if bs.nil? || bs[66] != 0x29
    $log&.debug("Fat32Probe << FALSE because there is no extended signature")
    return false
  end

  # Check file system label for 'FAT32   '
  # NOTE: This works for MS tools but maybe not for others.
  if bs.length < 90
    $log&.debug("Fat32Probe << FALSE because there is no filesystem label")
    return false
  end

  fslabel = bs[82, 8].unpack('a8')[0].strip
  fat32 = fslabel == 'FAT32'
  if $log
    $log.debug("Fat32Probe << TRUE") if fat32
    $log.debug("Fat32Probe << FALSE because FS label is NOT FAT32, but is '#{fslabel}'") unless fat32
  end

  fat32
end