blob: ca79867330eb1bc65b0fbf297f67f33abb453bea [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
2 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
3 *
4 * Inspired by libvolume_id by
5 * Kay Sievers <kay.sievers@vrfy.org>
6 *
7 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
9 */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <string.h>
15#include <stdint.h>
16
17#include "superblocks.h"
18
19struct jm_metadata {
20 int8_t signature[2];
21 uint8_t minor_version;
22 uint8_t major_version;
23 uint16_t checksum;
24};
25
26#define JM_SIGNATURE "JM"
27
28static int probe_jmraid(blkid_probe pr,
29 const struct blkid_idmag *mag __attribute__((__unused__)))
30{
31 uint64_t off;
32 struct jm_metadata *jm;
33
34 if (pr->size < 0x10000)
bigbiff7b4c7a62015-01-01 19:44:14 -050035 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050036 if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
bigbiff7b4c7a62015-01-01 19:44:14 -050037 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050038
39 off = ((pr->size / 0x200) - 1) * 0x200;
40 jm = (struct jm_metadata *)
41 blkid_probe_get_buffer(pr,
42 off,
43 sizeof(struct jm_metadata));
44 if (!jm)
bigbiff7b4c7a62015-01-01 19:44:14 -050045 return errno ? -errno : 1;
46
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050047 if (memcmp(jm->signature, JM_SIGNATURE, sizeof(JM_SIGNATURE) - 1) != 0)
bigbiff7b4c7a62015-01-01 19:44:14 -050048 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050049 if (blkid_probe_sprintf_version(pr, "%u.%u",
50 jm->major_version, jm->minor_version) != 0)
bigbiff7b4c7a62015-01-01 19:44:14 -050051 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050052 if (blkid_probe_set_magic(pr, off, sizeof(jm->signature),
53 (unsigned char *) jm->signature))
bigbiff7b4c7a62015-01-01 19:44:14 -050054 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050055 return 0;
56}
57
58const struct blkid_idinfo jmraid_idinfo = {
59 .name = "jmicron_raid_member",
60 .usage = BLKID_USAGE_RAID,
61 .probefunc = probe_jmraid,
62 .magics = BLKID_NONE_MAGIC
63};
64
65