From: Peter Jones Date: Wed, 6 Jun 2018 20:41:50 +0000 (-0400) Subject: Move virtblk device parsing to linux-virtblk.c X-Git-Tag: android-x86-8.1-r1~69 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=580ad56d9a789792a374a622c77a70612767b28f;p=android-x86%2Fexternal-efivar.git Move virtblk device parsing to linux-virtblk.c This won't actually *work* yet, because the infrastructure to use it (replacing "struct disk_info") won't land for a few more patches. Signed-off-by: Peter Jones --- diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c new file mode 100644 index 0000000..6dedf0f --- /dev/null +++ b/src/linux-virtblk.c @@ -0,0 +1,87 @@ +/* + * libefiboot - library for the manipulation of EFI boot variables + * Copyright 2012-2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + * . + * + */ + +#include "fix_coverity.h" + +#include +#include +#include +#include +#include + +#include "efiboot.h" + +/* + * support for virtio block devices + * /sys/dev/block/maj:min look like: + * 252:0 -> ../../devices/pci0000:00/0000:00:07.0/virtio2/block/vda + * 252:1 -> ../../devices/pci0000:00/0000:00:07.0/virtio2/block/vda/vda1 + * + * vda/device looks like: + * device -> ../../../virtio2 + * + * In this case we get 1 storage controller per pci device, so we actually + * write the device path as: + * + * PciRoot(0x0)/Pci(0x7,0x0)/HD(1,GPT,14d30998-b5e3-4b8f-9be3-58a454dd06bf,0x800,0x53000)/File(\EFI\fedora\shimx64.efi) + * + * But usually we just write the HD() entry, of course. + */ +static ssize_t +parse_virtblk(struct device *dev, const char *current) +{ + uint32_t tosser; + int pos; + int rc; + char *spaces; + + pos = strlen(current); + spaces = alloca(pos+1); + memset(spaces, ' ', pos+1); + spaces[pos] = '\0'; + pos = 0; + + debug(DEBUG, "entry"); + + debug(DEBUG, "searching for virtio0/"); + rc = sscanf(current, "virtio%x/%n", &tosser, &pos); + debug(DEBUG, "current:\"%s\" rc:%d pos:%d\n", current, rc, pos); + arrow(DEBUG, spaces, 9, pos, rc, 1); + /* + * If we couldn't find virtioX/ then it isn't a virtio device. + */ + if (rc < 1) + return 0; + + dev->interface_type = virtblk; + + return pos; +} + +enum interface_type virtblk_iftypes[] = { virtblk, unknown }; + +struct dev_probe HIDDEN virtblk_parser = { + .name = "virtio block", + .iftypes = virtblk_iftypes, + .flags = DEV_PROVIDES_HD, + .parse = parse_virtblk, + .create = NULL, +}; + diff --git a/src/linux.c b/src/linux.c index 0d6c0d3..2d72546 100644 --- a/src/linux.c +++ b/src/linux.c @@ -883,26 +883,6 @@ make_blockdev_path(uint8_t *buf, ssize_t size, struct disk_info *info) } - if (!found && - (info->interface_type == interface_type_unknown || - info->interface_type == atapi || - info->interface_type == usb || - info->interface_type == i1394 || - info->interface_type == fibre || - info->interface_type == md)) { - uint32_t tosser; - int tmpoff; - - rc = sscanf(linkbuf+loff, "virtio%x/%n", &tosser, &tmpoff); - if (rc < 0) { - return -1; - } else if (rc == 1) { - info->interface_type = virtblk; - loff += tmpoff; - found = 1; - } - } - /* /dev/nvme0n1 looks like: * /sys/dev/block/259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1 */ diff --git a/src/linux.h b/src/linux.h index 97907bc..c684617 100644 --- a/src/linux.h +++ b/src/linux.h @@ -259,6 +259,7 @@ extern ssize_t parse_scsi_link(const char *current, uint32_t *host, #define set_part(x, y) /* XXX remove later */ /* device support implementations */ +extern struct dev_probe virtblk_parser; extern struct dev_probe i2o_parser; extern struct dev_probe scsi_parser; extern struct dev_probe ata_parser;