disk_info_from_fd(): get major/minor from buf.st_rdev

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html :

  The <sys/stat.h> header shall define the structure of the data returned
  by the fstat(), lstat(), and stat() functions.

  The <sys/stat.h> header shall define the stat structure, which shall
  include at least the following members:

  [...]
  dev_t st_dev    Device ID of device containing file.
  [...]
  dev_t st_rdev   Device ID (if file is character or block special).
  [...]

In disk_info_from_fd(), we don't care about the device containing the
special file -- we care about the device the special file identifies.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
disk_get_pci(): expose detected interface type

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
produce virtio-blk device paths under EDD 3.0

OVMF is "UEFI boot firmware for virtual machines", hence a new use case
for efibootmgr. A virtual machine can have virtio-blk disks, and OVMF
supports them with the VirtioBlkDxe driver. Let's recognize such disks,
and produce correct boot options for them.

For now the user has to specify "-e 3" on the command line, to enable EDD
3.0 support under OVMF. (The autodetection code in get_edd_version() seems
to be EFI inheritance, it doesn't work under UEFI / edk2.)

With this patch, efibootmgr generates the following device path scheme for
virtio-blk disks, matching the ones installed by VirtioBlkDxe:

  ACPI(a0341d0,0)PCI(7,0)\
  HD(1,800,64000,87b09cbe-32b9-4737-8ecc-c1e65702cfb6)\
  File(\EFI\redhat\grub.efi)

Related RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=998611

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
disk_info_from_fd(): group output parameters into struct disk_info

Also expose the major and minor device numbers.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
disk_get_virt_pci(): generalize to arbitrary major & minor device numbers

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
prevent out-of-bounds access with SCSI_IOCTL_GET_PCI

SCSI_IOCTL_GET_PCI can store up to 20 non-NUL characters, and it doesn't
store a NUL character at all.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
produce virtio-scsi device paths under EDD 3.0

With this patch, efibootmgr generates the following device path scheme for
virtio-scsi disks, matching the ones installed by OVMF's VirtioScsiDxe:

  ACPI(a0341d0,0)PCI(4,0)SCSI(5,6)\
  HD(1,800,64000,87b09cbe-32b9-4737-8ecc-c1e65702cfb6)\
  File(\EFI\redhat\grub.efi)

For now the user has to specify "-e 3" on the command line, to enable EDD
3.0 support under OVMF. (The autodetection code in get_edd_version() seems
to be EFI inheritance, it doesn't work under UEFI / edk2.)

Related RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=998611

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Silence some minor compiler warnings.

Signed-off-by: Peter Jones <pjones@redhat.com>
Ignore some files so "git status" is clearer.

Signed-off-by: Peter Jones <pjones@redhat.com>
Use libefivar.

Using libefivar divorces us from the kernel api, which is a very good
thing.  It also means we don't need to know about efi_status_t or efi
error types, or carry our own headers for describing variables.

This also makes device paths > 1024 bytes long work (on newer kernels)

Signed-off-by: Peter Jones <pjones@redhat.com>
Fix error message that says "delete" on the "activate" case.

bcl found this reviewing it.

Signed-off-by: Peter Jones <pjones@redhat.com>
Don't do unnecessary math.

bcl found this one too - we know len % 5 is 4, because it's tested a few
lines up.

Signed-off-by: Peter Jones <pjones@redhat.com>
Make the error case from make_boot_var() cleaner.

bcl thinks it looks better at the end, and I agree.

Signed-off-by: Peter Jones <pjones@redhat.com>
Modernize "make tarball" for our glorious git future.

Signed-off-by: Peter Jones <pjones@redhat.com>
Fix completely wrong compiler warning.

gcc's data flow analysis still kind of blows.

Signed-off-by: Peter Jones <pjones@redhat.com>
Fix minor compiler warning.

Signed-off-by: Peter Jones <pjones@redhat.com>
Fix uninitialized variable.

valgrind found a couple of errors, one of which fixes some odd behavior
with BootOrder I was seeing.

Signed-off-by: Peter Jones <pjones@redhat.com>
Make tilt_slashes() static.

Signed-off-by: Peter Jones <pjones@redhat.com>
Make --help also -h, and don't have it exit with an error status.

Signed-off-by: Peter Jones <pjones@redhat.com>