~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/superblocks/jmicron_raid.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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
 
 
19
 
struct 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
 
 
28
 
static int probe_jmraid(blkid_probe pr, const struct blkid_idmag *mag)
29
 
{
30
 
        uint64_t off;
31
 
        struct jm_metadata *jm;
32
 
 
33
 
        if (pr->size < 0x10000)
34
 
                return -1;
35
 
        if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
36
 
                return -1;
37
 
 
38
 
        off = ((pr->size / 0x200) - 1) * 0x200;
39
 
        jm = (struct jm_metadata *)
40
 
                blkid_probe_get_buffer(pr,
41
 
                                off,
42
 
                                sizeof(struct jm_metadata));
43
 
        if (!jm)
44
 
                return -1;
45
 
        if (memcmp(jm->signature, JM_SIGNATURE, sizeof(JM_SIGNATURE) - 1) != 0)
46
 
                return -1;
47
 
        if (blkid_probe_sprintf_version(pr, "%u.%u",
48
 
                                jm->major_version, jm->minor_version) != 0)
49
 
                return -1;
50
 
        if (blkid_probe_set_magic(pr, off, sizeof(jm->signature),
51
 
                                (unsigned char *) jm->signature))
52
 
                return -1;
53
 
        return 0;
54
 
}
55
 
 
56
 
const struct blkid_idinfo jmraid_idinfo = {
57
 
        .name           = "jmicron_raid_member",
58
 
        .usage          = BLKID_USAGE_RAID,
59
 
        .probefunc      = probe_jmraid,
60
 
        .magics         = BLKID_NONE_MAGIC
61
 
};
62
 
 
63