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

« back to all changes in this revision

Viewing changes to libblkid/src/superblocks/promise_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 <errno.h>
 
15
#include <ctype.h>
 
16
#include <stdint.h>
 
17
 
 
18
#include "superblocks.h"
 
19
 
 
20
struct promise_metadata {
 
21
        uint8_t sig[24];
 
22
};
 
23
 
 
24
#define PDC_CONFIG_OFF          0x1200
 
25
#define PDC_SIGNATURE           "Promise Technology, Inc."
 
26
 
 
27
static int probe_pdcraid(blkid_probe pr,
 
28
                const struct blkid_idmag *mag __attribute__((__unused__)))
 
29
{
 
30
        unsigned int i;
 
31
        static unsigned int sectors[] = {
 
32
                63, 255, 256, 16, 399, 0
 
33
        };
 
34
 
 
35
        if (pr->size < 0x40000)
 
36
                return -1;
 
37
        if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
 
38
                return -1;
 
39
 
 
40
        for (i = 0; sectors[i] != 0; i++) {
 
41
                uint64_t off;
 
42
                struct promise_metadata *pdc;
 
43
 
 
44
                off = ((pr->size / 0x200) - sectors[i]) * 0x200;
 
45
                pdc = (struct promise_metadata *)
 
46
                                blkid_probe_get_buffer(pr,
 
47
                                        off,
 
48
                                        sizeof(struct promise_metadata));
 
49
                if (!pdc)
 
50
                        return -1;
 
51
 
 
52
                if (memcmp(pdc->sig, PDC_SIGNATURE,
 
53
                                sizeof(PDC_SIGNATURE) - 1) == 0) {
 
54
 
 
55
                        if (blkid_probe_set_magic(pr, off, sizeof(pdc->sig),
 
56
                                                (unsigned char *) pdc->sig))
 
57
                                return -1;
 
58
                        return 0;
 
59
                }
 
60
        }
 
61
        return -1;
 
62
}
 
63
 
 
64
const struct blkid_idinfo pdcraid_idinfo = {
 
65
        .name           = "promise_fasttrack_raid_member",
 
66
        .usage          = BLKID_USAGE_RAID,
 
67
        .probefunc      = probe_pdcraid,
 
68
        .magics         = BLKID_NONE_MAGIC
 
69
};
 
70
 
 
71