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

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