dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
d2bdca
diff -up util-linux-2.23.2/libblkid/src/superblocks/superblocks.c.kzak util-linux-2.23.2/libblkid/src/superblocks/superblocks.c
d2bdca
--- util-linux-2.23.2/libblkid/src/superblocks/superblocks.c.kzak	2015-06-24 12:58:20.790115492 +0200
d2bdca
+++ util-linux-2.23.2/libblkid/src/superblocks/superblocks.c	2015-06-24 12:57:57.961286166 +0200
d2bdca
@@ -49,6 +49,8 @@
d2bdca
  *
d2bdca
  * @UUID_SUB: subvolume uuid (e.g. btrfs)
d2bdca
  *
d2bdca
+ * @LOGUUID: external log UUID (e.g. xfs)
d2bdca
+ *
d2bdca
  * @UUID_RAW: raw UUID from FS superblock
d2bdca
  *
d2bdca
  * @EXT_JOURNAL: external journal UUID
d2bdca
@@ -113,6 +115,7 @@ static const struct blkid_idinfo *idinfo
d2bdca
 	&swsuspend_idinfo,
d2bdca
 	&swap_idinfo,
d2bdca
 	&xfs_idinfo,
d2bdca
+	&xfs_log_idinfo,
d2bdca
 	&ext4dev_idinfo,
d2bdca
 	&ext4_idinfo,
d2bdca
 	&ext3_idinfo,
d2bdca
diff -up util-linux-2.23.2/libblkid/src/superblocks/superblocks.h.kzak util-linux-2.23.2/libblkid/src/superblocks/superblocks.h
d2bdca
--- util-linux-2.23.2/libblkid/src/superblocks/superblocks.h.kzak	2015-06-24 12:58:48.533908071 +0200
d2bdca
+++ util-linux-2.23.2/libblkid/src/superblocks/superblocks.h	2015-06-24 12:59:00.098821476 +0200
d2bdca
@@ -29,6 +29,7 @@ extern const struct blkid_idinfo ext2_id
d2bdca
 extern const struct blkid_idinfo jbd_idinfo;
d2bdca
 extern const struct blkid_idinfo jfs_idinfo;
d2bdca
 extern const struct blkid_idinfo xfs_idinfo;
d2bdca
+extern const struct blkid_idinfo xfs_log_idinfo;
d2bdca
 extern const struct blkid_idinfo gfs_idinfo;
d2bdca
 extern const struct blkid_idinfo gfs2_idinfo;
d2bdca
 extern const struct blkid_idinfo romfs_idinfo;
d2bdca
diff -up util-linux-2.23.2/libblkid/src/superblocks/xfs.c.kzak util-linux-2.23.2/libblkid/src/superblocks/xfs.c
d2bdca
--- util-linux-2.23.2/libblkid/src/superblocks/xfs.c.kzak	2015-06-24 12:39:34.300507071 +0200
d2bdca
+++ util-linux-2.23.2/libblkid/src/superblocks/xfs.c	2015-06-24 12:39:45.389427015 +0200
d2bdca
@@ -4,6 +4,7 @@
d2bdca
  * Copyright (C) 2001 by Andreas Dilger
d2bdca
  * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
d2bdca
  * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
d2bdca
+ * Copyright (C) 2013 Eric Sandeen <sandeen@redhat.com>
d2bdca
  *
d2bdca
  * This file may be redistributed under the terms of the
d2bdca
  * GNU Lesser General Public License.
d2bdca
@@ -187,3 +188,90 @@ const struct blkid_idinfo xfs_idinfo =
d2bdca
 	}
d2bdca
 };
d2bdca
 
d2bdca
+struct xlog_rec_header {
d2bdca
+	uint32_t	h_magicno;
d2bdca
+	uint32_t	h_dummy1[1];
d2bdca
+	uint32_t	h_version;
d2bdca
+	uint32_t	h_len;
d2bdca
+	uint32_t	h_dummy2[71];
d2bdca
+	uint32_t	h_fmt;
d2bdca
+	unsigned char	h_uuid[16];
d2bdca
+} __attribute__((packed));
d2bdca
+
d2bdca
+#define XLOG_HEADER_MAGIC_NUM 0xFEEDbabe
d2bdca
+
d2bdca
+/*
d2bdca
+ * For very small filesystems, the minimum log size
d2bdca
+ * can be smaller, but that seems vanishingly unlikely
d2bdca
+ * when used with an external log (which is used for
d2bdca
+ * performance reasons; tiny conflicts with that goal).
d2bdca
+ */
d2bdca
+#define XFS_MIN_LOG_BYTES	(10 * 1024 * 1024)
d2bdca
+
d2bdca
+#define XLOG_FMT_LINUX_LE	1
d2bdca
+#define XLOG_FMT_LINUX_BE	2
d2bdca
+#define XLOG_FMT_IRIX_BE	3
d2bdca
+
d2bdca
+#define XLOG_VERSION_1		1
d2bdca
+#define XLOG_VERSION_2		2	/* Large IClogs, Log sunit */
d2bdca
+#define XLOG_VERSION_OKBITS	(XLOG_VERSION_1 | XLOG_VERSION_2)
d2bdca
+
d2bdca
+static int xlog_valid_rec_header(struct xlog_rec_header *rhead)
d2bdca
+{
d2bdca
+	uint32_t hlen;
d2bdca
+
d2bdca
+	if (rhead->h_magicno != cpu_to_be32(XLOG_HEADER_MAGIC_NUM))
d2bdca
+		return 0;
d2bdca
+
d2bdca
+	if (!rhead->h_version ||
d2bdca
+            (be32_to_cpu(rhead->h_version) & (~XLOG_VERSION_OKBITS)))
d2bdca
+		return 0;
d2bdca
+
d2bdca
+	/* LR body must have data or it wouldn't have been written */
d2bdca
+	hlen = be32_to_cpu(rhead->h_len);
d2bdca
+	if (hlen <= 0 || hlen > INT_MAX)
d2bdca
+		return 0;
d2bdca
+
d2bdca
+	if (rhead->h_fmt != cpu_to_be32(XLOG_FMT_LINUX_LE) &&
d2bdca
+	    rhead->h_fmt != cpu_to_be32(XLOG_FMT_LINUX_BE) &&
d2bdca
+	    rhead->h_fmt != cpu_to_be32(XLOG_FMT_IRIX_BE))
d2bdca
+		return 0;
d2bdca
+
d2bdca
+	return 1;
d2bdca
+}
d2bdca
+
d2bdca
+/* xlog record header will be in some sector in the first 256k */
d2bdca
+static int probe_xfs_log(blkid_probe pr, const struct blkid_idmag *mag)
d2bdca
+{
d2bdca
+	int i;
d2bdca
+	struct xlog_rec_header *rhead;
d2bdca
+	unsigned char *buf;
d2bdca
+
d2bdca
+	buf = blkid_probe_get_buffer(pr, 0, 256*1024);
d2bdca
+	if (!buf)
d2bdca
+		return errno ? -errno : 1;
d2bdca
+
d2bdca
+	if (memcmp(buf, "XFSB", 4) == 0)
d2bdca
+		return 1;			/* this is regular XFS, ignore */
d2bdca
+
d2bdca
+	/* check the first 512 512-byte sectors */
d2bdca
+	for (i = 0; i < 512; i++) {
d2bdca
+		rhead = (struct xlog_rec_header *)&buf[i*512];
d2bdca
+
d2bdca
+		if (xlog_valid_rec_header(rhead)) {
d2bdca
+			blkid_probe_set_uuid_as(pr, rhead->h_uuid, "LOGUUID");
d2bdca
+			return 0;
d2bdca
+		}
d2bdca
+	}
d2bdca
+
d2bdca
+	return 1;
d2bdca
+}
d2bdca
+
d2bdca
+const struct blkid_idinfo xfs_log_idinfo =
d2bdca
+{
d2bdca
+	.name		= "xfs_external_log",
d2bdca
+	.usage		= BLKID_USAGE_OTHER,
d2bdca
+	.probefunc	= probe_xfs_log,
d2bdca
+	.magics		= BLKID_NONE_MAGIC,
d2bdca
+	.minsz		= XFS_MIN_LOG_BYTES,
d2bdca
+};