blob: 43e544e896d001845abd80c2e94a5b77bcbd21d2 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
2 * Copyright (C) 2009 by Bastian Friedrich <bastian.friedrich@collax.com>
3 *
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
6 *
7 * defines, structs taken from drbd source; file names represent drbd source
8 * files.
9 */
10#include <stdio.h>
11#include <stdlib.h>
12#include <unistd.h>
13#include <string.h>
14#include <errno.h>
15#include <ctype.h>
16#include <inttypes.h>
17#include <stddef.h>
18
19#include "superblocks.h"
20
21/*
22 * drbd/linux/drbd.h
23 */
24#define DRBD_MAGIC 0x83740267
25
26/*
27 * user/drbdmeta.c
28 * We only support v08 for now
29 */
30#define DRBD_MD_MAGIC_08 (DRBD_MAGIC+4)
31#define DRBD_MD_MAGIC_84_UNCLEAN (DRBD_MAGIC+5)
32
33/*
34 * drbd/linux/drbd.h
35 */
36enum drbd_uuid_index {
37 UI_CURRENT,
38 UI_BITMAP,
39 UI_HISTORY_START,
40 UI_HISTORY_END,
41 UI_SIZE, /* nl-packet: number of dirty bits */
42 UI_FLAGS, /* nl-packet: flags */
43 UI_EXTENDED_SIZE /* Everything. */
44};
45
46/*
47 * user/drbdmeta.c
48 * Minor modifications wrt. types
49 */
50struct md_on_disk_08 {
51 uint64_t la_sect; /* last agreed size. */
52 uint64_t uuid[UI_SIZE]; /* UUIDs */
53 uint64_t device_uuid;
54 uint64_t reserved_u64_1;
55 uint32_t flags;
56 uint32_t magic;
57 uint32_t md_size_sect;
58 int32_t al_offset; /* signed sector offset to this block */
59 uint32_t al_nr_extents; /* important for restoring the AL */
60 int32_t bm_offset; /* signed sector offset to the bitmap, from here */
61 uint32_t bm_bytes_per_bit;
62 uint32_t reserved_u32[4];
63
64 char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)];
65};
66
67
68static int probe_drbd(blkid_probe pr,
69 const struct blkid_idmag *mag __attribute__((__unused__)))
70{
71 struct md_on_disk_08 *md;
72 off_t off;
73
74 off = pr->size - sizeof(*md);
75
76 /* Small devices cannot be drbd (?) */
77 if (pr->size < 0x10000)
78 return -1;
79
80 md = (struct md_on_disk_08 *)
81 blkid_probe_get_buffer(pr,
82 off,
83 sizeof(struct md_on_disk_08));
84 if (!md)
85 return -1;
86
87 if (be32_to_cpu(md->magic) != DRBD_MD_MAGIC_08 &&
88 be32_to_cpu(md->magic) != DRBD_MD_MAGIC_84_UNCLEAN)
89 return -1;
90
91 /*
92 * DRBD does not have "real" uuids; the following resembles DRBD's
93 * notion of uuids (64 bit, see struct above)
94 */
95 blkid_probe_sprintf_uuid(pr,
96 (unsigned char *) &md->device_uuid, sizeof(md->device_uuid),
97 "%" PRIx64, be64_to_cpu(md->device_uuid));
98
99 blkid_probe_set_version(pr, "v08");
100
101 if (blkid_probe_set_magic(pr,
102 off + offsetof(struct md_on_disk_08, magic),
103 sizeof(md->magic),
104 (unsigned char *) &md->magic))
105 return -1;
106
107 return 0;
108}
109
110const struct blkid_idinfo drbd_idinfo =
111{
112 .name = "drbd",
113 .usage = BLKID_USAGE_RAID,
114 .probefunc = probe_drbd,
115 .magics = BLKID_NONE_MAGIC
116};
117