Module: Lvm2Scanner

Defined in:
lib/VolumeManager/LVM/scanner.rb

Constant Summary collapse

LVM_PARTITION_TYPE =
142
SECTOR_SIZE =
512
LABEL_SCAN_SECTORS =
4
LVM_ID_LEN =
8
LVM_TYPE_LEN =
8
LVM_ID =
"LABELONE".freeze
PV_ID_LEN =
32
MDA_MAGIC_LEN =
16
FMTT_MAGIC =
"\040\114\126\115\062\040\170\133\065\101\045\162\060\116\052\076".freeze
LABEL_HEADER =

On disk label header.

BinaryStruct.new(
  [
    "A#{LVM_ID_LEN}",   'lvm_id',
    'Q',                'sector_xl',
    'L',                'crc_xl',
    'L',                'offset_xl',
    "A#{LVM_TYPE_LEN}", 'lvm_type'
  ]
)
PV_HEADER =

On disk physical volume header.

BinaryStruct.new(
  [
    "A#{PV_ID_LEN}", 'pv_uuid',
    "Q",             'device_size_xl'
  ]
)
DISK_LOCN =

On disk disk location structure.

BinaryStruct.new(
  [
    "Q", 'offset',
    "Q", 'size'
  ]
)
MDA_HEADER =

On disk metadata area header.

BinaryStruct.new(
  [
    "L",                 'checksum_xl',
    "A#{MDA_MAGIC_LEN}", 'magic',
    "L",                 'version',
    "Q",                 'start',
    "Q",                 'size'
  ]
)
RAW_LOCN =

On disk raw location header, points to metadata.

BinaryStruct.new(
  [
    "Q", 'offset',
    "Q", 'size',
    "L", 'checksum',
    "L", 'filler'
  ]
)

Class Method Summary collapse

Class Method Details

.labelScan(d) ⇒ Object

Scan the physical volume for LVM headers. Return nil if no label is found. Otherwise, return a physical volume header containing a list of metadata areas.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/VolumeManager/LVM/scanner.rb', line 77

def self.labelScan(d)
  lh = nil
  (0...LABEL_SCAN_SECTORS).each do |s|
    lh = readLabel(d, s)
    break if lh
  end
  return nil unless lh

  pvh = readPvHeader(d, lh)

  mdList = []
  pvh.metadataDiskLocations.each do |dlh|
    mdah = readMdah(d, dlh)
    mdah.rawLocations.each do |rl|
      mdList << readRaw(d, rl)
    end
  end
  pvh.mdList = mdList
  pvh.lvm_type = lh.lvm_type.split(" ").first
  pvh
end