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

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