summaryrefslogtreecommitdiffstats
path: root/libblkid/src/superblocks/drbdmanage.c
blob: b45f89bc8d9d399687c28c71249c830b49c57253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright (C) 2015 by Philipp Marek <philipp.marek@linbit.com>
 *
 * This file may be redistributed under the terms of the
 * GNU Lesser General Public License.
 *
 * DRBD is a blocklevel replication solution in the Linux kernel,
 * upstream since 2.6.33. (See http://drbd.linbit.com/)
 * DRBDmanage is a configuration frontend that assists in
 * creating/deleting/modifying DRBD resources across multiple machines
 * (a DRBDmanage "cluster"); this file detects its control volume,
 * which is replicated (via DRBD 9) on some of the nodes.
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <inttypes.h>
#include <stddef.h>

#include "bitops.h"
#include "superblocks.h"

struct drbdmanage_hdr {
	unsigned char magic[11];
	unsigned char uuid[32];
	unsigned char lf;
} __attribute__ ((packed));

struct drbdmanage_pers {
	char magic[4];
	uint32_t version_le;
} __attribute__ ((packed));


static const char persistence_magic[4] = { '\x1a', '\xdb', '\x98', '\xa2' };


static int probe_drbdmanage(blkid_probe pr,
		const struct blkid_idmag *mag __attribute__((__unused__)))
{
	struct drbdmanage_hdr *hdr;
	unsigned char *cp;
	struct drbdmanage_pers *prs;

	hdr = (struct drbdmanage_hdr*)
		blkid_probe_get_buffer(pr, 0, sizeof(*hdr));
	if (!hdr)
		return errno ? -errno : 1;

	for(cp=hdr->uuid; cp<&hdr->lf; cp++)
		if (!isxdigit(*cp))
			return 1;
	if (hdr->lf != '\n')
		return 1;

	if (blkid_probe_set_id_label(pr, "UUID",
				hdr->uuid, sizeof(hdr->uuid)))
		return errno ? -errno : 1;

	prs = (struct drbdmanage_pers*)
		blkid_probe_get_buffer(pr, 0x1000, sizeof(*prs));
	if (!prs)
		return errno ? -errno : 1;

	if (memcmp(prs->magic, persistence_magic, sizeof(prs->magic)) == 0 &&
	    blkid_probe_sprintf_version(pr, "%d", be32_to_cpu(prs->version_le)) != 0)
		return errno ? -errno : 1;

	return 0;
}


const struct blkid_idinfo drbdmanage_idinfo =
{
	.name		= "drbdmanage_control_volume",
	.usage		= BLKID_USAGE_OTHER,
	.probefunc	= probe_drbdmanage,
	.minsz		= 64 * 1024,
	.magics		= {
		{ .magic = "$DRBDmgr=q", .len = 10, .sboff = 0 },
		{ NULL }
	},
};