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

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