blob: 01e4e3752dd8229d6f17c861ddb3be03f6f3f34c [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#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
20struct promise_metadata {
21 uint8_t sig[24];
22};
23
24#define PDC_CONFIG_OFF 0x1200
25#define PDC_SIGNATURE "Promise Technology, Inc."
26
27static 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, 591, 675, 735, 911, 974, 991, 951, 3087, 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
64const 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