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