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

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/superblocks/highpoint_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
 
#include <stdio.h>
11
 
#include <stdlib.h>
12
 
#include <unistd.h>
13
 
#include <string.h>
14
 
#include <stdint.h>
15
 
 
16
 
#include "superblocks.h"
17
 
 
18
 
struct hpt45x_metadata {
19
 
        uint32_t        magic;
20
 
};
21
 
 
22
 
#define HPT45X_MAGIC_OK                 0x5a7816f3
23
 
#define HPT45X_MAGIC_BAD                0x5a7816fd
24
 
 
25
 
static int probe_highpoint45x(blkid_probe pr, const struct blkid_idmag *mag)
26
 
{
27
 
        struct hpt45x_metadata *hpt;
28
 
        uint64_t off;
29
 
        uint32_t magic;
30
 
 
31
 
        if (pr->size < 0x10000)
32
 
                return -1;
33
 
        if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
34
 
                return -1;
35
 
 
36
 
        off = ((pr->size / 0x200) - 11) * 0x200;
37
 
        hpt = (struct hpt45x_metadata *)
38
 
                        blkid_probe_get_buffer(pr,
39
 
                                        off,
40
 
                                        sizeof(struct hpt45x_metadata));
41
 
        if (!hpt)
42
 
                return -1;
43
 
        magic = le32_to_cpu(hpt->magic);
44
 
        if (magic != HPT45X_MAGIC_OK && magic != HPT45X_MAGIC_BAD)
45
 
                return -1;
46
 
        if (blkid_probe_set_magic(pr, off, sizeof(hpt->magic),
47
 
                                (unsigned char *) &hpt->magic))
48
 
                return -1;
49
 
        return 0;
50
 
}
51
 
 
52
 
static int probe_highpoint37x(blkid_probe pr, const struct blkid_idmag *mag)
53
 
{
54
 
        if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
55
 
                return -1;
56
 
        return 0;
57
 
}
58
 
 
59
 
 
60
 
const struct blkid_idinfo highpoint45x_idinfo = {
61
 
        .name           = "hpt45x_raid_member",
62
 
        .usage          = BLKID_USAGE_RAID,
63
 
        .probefunc      = probe_highpoint45x,
64
 
        .magics         = BLKID_NONE_MAGIC
65
 
};
66
 
 
67
 
const struct blkid_idinfo highpoint37x_idinfo = {
68
 
        .name           = "hpt37x_raid_member",
69
 
        .usage          = BLKID_USAGE_RAID,
70
 
        .probefunc      = probe_highpoint37x,
71
 
        .magics         = {
72
 
                /*
73
 
                 * Superblok offset:                      4608 bytes  (9 sectors)
74
 
                 * Magic string offset within superblock:   32 bytes
75
 
                 *
76
 
                 * kboff = (4608 + 32) / 1024
77
 
                 * sboff = (4608 + 32) % kboff
78
 
                 */
79
 
                { .magic = "\xf0\x16\x78\x5a", .len = 4, .kboff = 4, .sboff = 544 },
80
 
                { .magic = "\xfd\x16\x78\x5a", .len = 4, .kboff = 4, .sboff = 544 },
81
 
                { NULL }
82
 
        }
83
 
};
84
 
 
85