Fix the bug when mixing usages with and without -f argument.

The SMBIOS requires the offset in type 241 table is absolute address.
We get in trouble if only VPD partition is read from BIOS (for speed)
because we have no overview scope to know the absolute address in BIOS.

Added a guess_offset() function to consider all combinations of how the
structure was made, and whether the whole file is read at parsing.
Please refer for the function comments for details.

Also fix the 64-bit integer issue for off_t.

TEST=tested on broken bios, and following commands (switch between w/ and w/o -f):
  vpd -O -s A=B
  vpd -l
  flashrom -r /tmp/bios
  vpd -f /tmp/bios -l
  vpd -f /tmp/bios -s C=D
  vpd -f /tmp/bios -l
  flashrom -w /tmp/bios
  vpd -l
  vpd -f /tmp/bios -O -s E=F
  flashrom -w /tmp/bios
  vpd -l
  vpd -s G=H
  vpd -l

Reviewed-by: Hung-Te Lin <>
Tested-by: Louis Yung-Chieh Lo <>

(cherry picked from commit 729bd30559906260d12a4ec7626bac7e9ae71e8c)

Change-Id: Iaf9a924f8a8982eceffc97483ec1d5bf5eaadab0
Reviewed-by: Hung-Te Lin <>
Reviewed-by: Yung-Chieh Lo <>
Tested-by: Yung-Chieh Lo <>
1 file changed
tree: 6371f74ee46294f3a26e31faaf68421369821892
  2. Makefile
  4. include/
  5. lib/
  6. util/
  7. vpd.c