Blame SOURCES/0030-Handle-partition-name-parsing-and-formatting-for-par.patch

80b73c
From 576f55b02d9ec478bd5157352c884e3543bcca58 Mon Sep 17 00:00:00 2001
80b73c
From: Peter Jones <pjones@redhat.com>
80b73c
Date: Mon, 17 Sep 2018 16:52:57 -0400
80b73c
Subject: [PATCH 30/30] Handle partition name parsing and formatting for
80b73c
 partitioned md.
80b73c
80b73c
Signed-off-by: Peter Jones <pjones@redhat.com>
80b73c
---
80b73c
 src/linux-md.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++
80b73c
 1 file changed, 103 insertions(+)
80b73c
 create mode 100644 src/linux-md.c
80b73c
80b73c
diff --git a/src/linux-md.c b/src/linux-md.c
80b73c
new file mode 100644
80b73c
index 00000000000..0a5c1cdb435
80b73c
--- /dev/null
80b73c
+++ b/src/linux-md.c
80b73c
@@ -0,0 +1,103 @@
80b73c
+/*
80b73c
+ * libefiboot - library for the manipulation of EFI boot variables
80b73c
+ * Copyright 2012-2018 Red Hat, Inc.
80b73c
+ *
80b73c
+ * This library is free software; you can redistribute it and/or
80b73c
+ * modify it under the terms of the GNU Lesser General Public License as
80b73c
+ * published by the Free Software Foundation; either version 2.1 of the
80b73c
+ * License, or (at your option) any later version.
80b73c
+ *
80b73c
+ * This library is distributed in the hope that it will be useful,
80b73c
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
80b73c
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
80b73c
+ * Lesser General Public License for more details.
80b73c
+ *
80b73c
+ * You should have received a copy of the GNU Lesser General Public
80b73c
+ * License along with this library; if not, see
80b73c
+ * <http://www.gnu.org/licenses/>.
80b73c
+ *
80b73c
+ */
80b73c
+
80b73c
+#include "fix_coverity.h"
80b73c
+
80b73c
+#include <errno.h>
80b73c
+#include <fcntl.h>
80b73c
+#include <inttypes.h>
80b73c
+#include <stdint.h>
80b73c
+#include <unistd.h>
80b73c
+
80b73c
+#include "efiboot.h"
80b73c
+
80b73c
+/*
80b73c
+ * "support" for partitioned md devices - basically we just need to format
80b73c
+ * the partition name.
80b73c
+ *
80b73c
+ * /sys/dev/block/$major:$minor looks like:
80b73c
+ * 259:0 -> ../../devices/virtual/block/md1/md1p1
80b73c
+ * 9:1 -> ../../devices/virtual/block/md1
80b73c
+ *
80b73c
+ */
80b73c
+
80b73c
+static ssize_t
80b73c
+parse_md(struct device *dev, const char *current, const char *root UNUSED)
80b73c
+{
80b73c
+        int rc;
80b73c
+        int32_t md, tosser0, part;
80b73c
+        int pos0 = 0, pos1 = 0;
80b73c
+        char *spaces;
80b73c
+
80b73c
+        pos0 = strlen(current);
80b73c
+        spaces = alloca(pos0+1);
80b73c
+        memset(spaces, ' ', pos0+1);
80b73c
+        spaces[pos0] = '\0';
80b73c
+        pos0 = 0;
80b73c
+
80b73c
+        debug("entry");
80b73c
+
80b73c
+        debug("searching for mdM/mdMpN");
80b73c
+        rc = sscanf(current, "md%d/%nmd%dp%d%n",
80b73c
+                    &md, &pos0, &tosser0, &part, &pos1);
80b73c
+        debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
80b73c
+        arrow(LOG_DEBUG, spaces, 9, pos0, rc, 3);
80b73c
+        /*
80b73c
+         * If it isn't of that form, it's not one of our partitioned md devices.
80b73c
+         */
80b73c
+        if (rc != 3)
80b73c
+                return 0;
80b73c
+
80b73c
+        dev->interface_type = md;
80b73c
+
80b73c
+        if (dev->part == -1)
80b73c
+                dev->part = part;
80b73c
+
80b73c
+        return pos1;
80b73c
+}
80b73c
+
80b73c
+
80b73c
+static char *
80b73c
+make_part_name(struct device *dev)
80b73c
+{
80b73c
+        char *ret = NULL;
80b73c
+        ssize_t rc;
80b73c
+
80b73c
+        if (dev->part < 1)
80b73c
+                return NULL;
80b73c
+
80b73c
+        rc = asprintf(&ret, "%sp%d", dev->disk_name, dev->part);
80b73c
+        if (rc < 0) {
80b73c
+                efi_error("could not allocate memory");
80b73c
+                return NULL;
80b73c
+        }
80b73c
+
80b73c
+        return ret;
80b73c
+}
80b73c
+
80b73c
+static enum interface_type md_iftypes[] = { md, unknown };
80b73c
+
80b73c
+struct dev_probe HIDDEN md_parser = {
80b73c
+        .name = "md",
80b73c
+        .iftypes = md_iftypes,
80b73c
+        .flags = DEV_PROVIDES_HD,
80b73c
+        .parse = parse_md,
80b73c
+        .make_part_name = make_part_name,
80b73c
+};
80b73c
-- 
80b73c
2.17.1
80b73c