File: linux-virtblk.c

package info (click to toggle)
efivar 37-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,648 kB
  • sloc: ansic: 10,605; makefile: 234; asm: 34
file content (79 lines) | stat: -rw-r--r-- 2,332 bytes parent folder | download | duplicates (2)
1
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * 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
 * <http://www.gnu.org/licenses/>.
 *
 */

#include "fix_coverity.h"

#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdint.h>
#include <unistd.h>

#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, const char *root UNUSED)
{
        uint32_t tosser;
        int pos = 0;
        int rc;

        debug("entry");

        debug("searching for virtio0/");
        rc = sscanf(current, "virtio%x/%n", &tosser, &pos);
        debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
        /*
         * 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,
};