]> git.ipfire.org Git - thirdparty/util-linux.git/blame - libblkid/src/superblocks/drbdmanage.c
libblkid: (drbdmanage) improve version setting code
[thirdparty/util-linux.git] / libblkid / src / superblocks / drbdmanage.c
CommitLineData
2dc8cfb9
PM
1/*
2 * Copyright (C) 2015 by Philipp Marek <philipp.marek@linbit.com>
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
6 *
7 * DRBD is a blocklevel replication solution in the Linux kernel,
8 * upstream since 2.6.33. (See http://drbd.linbit.com/)
9 * DRBDmanage is a configuration frontend that assists in
10 * creating/deleting/modifying DRBD resources across multiple machines
11 * (a DRBDmanage "cluster"); this file detects its control volume,
12 * which is replicated (via DRBD 9) on some of the nodes.
13 */
14#include <endian.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <unistd.h>
18#include <string.h>
19#include <errno.h>
20#include <ctype.h>
21#include <inttypes.h>
22#include <stddef.h>
23
24#include "superblocks.h"
25
26struct drbdmanage_hdr {
27 unsigned char magic[11];
28 unsigned char uuid[32];
29 unsigned char lf;
30} __attribute__ ((packed));
31
32struct drbdmanage_pers {
33 char magic[4];
34 uint32_t version_le;
35} __attribute__ ((packed));
36
37
38const char persistence_magic[4] = "\x1a\xdb\x98\xa2";
39
40
41static int probe_drbdmanage(blkid_probe pr,
42 const struct blkid_idmag *mag __attribute__((__unused__)))
43{
44 struct drbdmanage_hdr *hdr;
45 unsigned char *cp;
46 struct drbdmanage_pers *prs;
2dc8cfb9
PM
47
48 hdr = (struct drbdmanage_hdr*)
49 blkid_probe_get_buffer(pr, 0, sizeof(*hdr));
50 if (!hdr)
51 return errno ? -errno : 1;
52
53 for(cp=hdr->uuid; cp<&hdr->lf; cp++)
54 if (!isxdigit(*cp))
55 return 1;
56 if (hdr->lf != '\n')
57 return 1;
58
59 if (blkid_probe_set_id_label(pr, "UUID",
60 hdr->uuid, sizeof(hdr->uuid)))
61 return errno ? -errno : 1;
62
63 prs = (struct drbdmanage_pers*)
64 blkid_probe_get_buffer(pr, 0x1000, sizeof(*prs));
65 if (!prs)
66 return errno ? -errno : 1;
67
7430affd
KZ
68 if (memcmp(prs->magic, persistence_magic, sizeof(prs->magic)) == 0 &&
69 blkid_probe_sprintf_value(pr, "PERSISTENCE_VERSION",
70 "%d", be32_to_cpu(prs->version_le)) != 0)
71 return errno ? -errno : 1;
2dc8cfb9
PM
72
73 return 0;
74}
75
76
77const struct blkid_idinfo drbdmanage_idinfo =
78{
79 .name = "drbdmanage_control_volume",
80 .usage = BLKID_USAGE_OTHER,
81 .probefunc = probe_drbdmanage,
1198e390 82 .minsz = 64 * 1024,
2dc8cfb9
PM
83 .magics = {
84 { .magic = "$DRBDmgr=q", .len = 10, .sboff = 0 },
1198e390 85 { NULL }
2dc8cfb9
PM
86 },
87};
88