Coverage Report

Created: 2026-07-16 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/util-linux/libblkid/src/superblocks/drbdmanage.c
Line
Count
Source
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 <stdio.h>
15
#include <stdlib.h>
16
#include <unistd.h>
17
#include <string.h>
18
#include <errno.h>
19
#include <ctype.h>
20
#include <inttypes.h>
21
#include <stddef.h>
22
23
#include "bitops.h"
24
#include "superblocks.h"
25
26
struct drbdmanage_hdr {
27
  unsigned char magic[11];
28
  unsigned char uuid[32];
29
  unsigned char lf;
30
} __attribute__ ((packed));
31
32
struct drbdmanage_pers {
33
  char magic[4];
34
  uint32_t version_le;
35
} __attribute__ ((packed));
36
37
38
static const char persistence_magic[4] = { '\x1a', '\xdb', '\x98', '\xa2' };
39
40
41
static int probe_drbdmanage(blkid_probe pr,
42
    const struct blkid_idmag *mag __attribute__((__unused__)))
43
37
{
44
37
  struct drbdmanage_hdr *hdr;
45
37
  unsigned char *cp;
46
37
  struct drbdmanage_pers *prs;
47
48
37
  hdr = (struct drbdmanage_hdr*)
49
37
    blkid_probe_get_buffer(pr, 0, sizeof(*hdr));
50
37
  if (!hdr)
51
0
    return errno ? -errno : 1;
52
53
195
  for(cp=hdr->uuid; cp<&hdr->lf; cp++)
54
191
    if (!isxdigit(*cp))
55
33
      return 1;
56
4
  if (hdr->lf != '\n')
57
3
    return 1;
58
59
1
  if (blkid_probe_strncpy_uuid(pr,
60
1
        hdr->uuid, sizeof(hdr->uuid)))
61
0
    return errno ? -errno : 1;
62
63
1
  prs = (struct drbdmanage_pers*)
64
1
    blkid_probe_get_buffer(pr, 0x1000, sizeof(*prs));
65
1
  if (!prs)
66
0
    return errno ? -errno : 1;
67
68
1
  if (memcmp(prs->magic, persistence_magic, sizeof(prs->magic)) == 0 &&
69
0
      blkid_probe_sprintf_version(pr, "%"PRIu32, be32_to_cpu(prs->version_le)) != 0)
70
0
    return errno ? -errno : 1;
71
72
1
  return 0;
73
1
}
74
75
76
const struct blkid_idinfo drbdmanage_idinfo =
77
{
78
  .name   = "drbdmanage_control_volume",
79
  .usage    = BLKID_USAGE_OTHER,
80
  .probefunc  = probe_drbdmanage,
81
  .minsz    = 64 * 1024,
82
  .magics   = {
83
    { .magic = "$DRBDmgr=q", .len = 10, .sboff = 0 },
84
    { NULL }
85
  },
86
};
87