File: linux-soc-root.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 (65 lines) | stat: -rw-r--r-- 2,084 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
/*
 * 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 soc platforms
 *
 * various devices /sys/dev/block/$major:$minor start with:
 * maj:min ->  ../../devices/platform/soc/$DEVICETREE_NODE/$BLOCKDEV_STUFF/block/$DISK/$PART
 * i.e.:                              soc/1a400000.sata/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
 *                                        ^ dt node     ^ blockdev stuff                     ^ disk
 * I don't *think* the devicetree nodes stack.
 */
static ssize_t
parse_soc_root(struct device *dev UNUSED, const char *current, const char *root UNUSED)
{
        int rc;
        int pos = 0;
        const char *devpart = current;

        debug("entry");

        rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos);
        if (rc != 0)
                return 0;
        devpart += pos;
        debug("new position is \"%s\"", devpart);

        return devpart - current;
}

enum interface_type soc_root_iftypes[] = { soc_root, unknown };

struct dev_probe HIDDEN soc_root_parser = {
        .name = "soc_root",
        .iftypes = soc_root_iftypes,
        .flags = DEV_ABBREV_ONLY|DEV_PROVIDES_ROOT,
        .parse = parse_soc_root,
};