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

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