| 1 |
/* |
| 2 |
* Copyright (C) 2008 Karel Zak <[email protected]> |
| 3 |
* |
| 4 |
* Inspired by libvolume_id by |
| 5 |
* Kay Sievers <[email protected]> |
| 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 |
size_t i; |
| 31 |
static unsigned int sectors[] = { |
| 32 |
63, 255, 256, 16, 399, 591, 675, 735, 911, 974, 991, 951, 3087 |
| 33 |
}; |
| 34 |
uint64_t nsectors; |
| 35 |
|
| 36 |
if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr)) |
| 37 |
return 1; |
| 38 |
|
| 39 |
nsectors = pr->size >> 9; |
| 40 |
|
| 41 |
for (i = 0; i < ARRAY_SIZE(sectors); i++) { |
| 42 |
uint64_t off; |
| 43 |
struct promise_metadata *pdc; |
| 44 |
|
| 45 |
if (nsectors < sectors[i]) |
| 46 |
return 1; |
| 47 |
|
| 48 |
off = (nsectors - sectors[i]) << 9; |
| 49 |
pdc = (struct promise_metadata *) |
| 50 |
blkid_probe_get_buffer(pr, |
| 51 |
off, |
| 52 |
sizeof(struct promise_metadata)); |
| 53 |
if (!pdc) |
| 54 |
return errno ? -errno : 1; |
| 55 |
|
| 56 |
if (memcmp(pdc->sig, PDC_SIGNATURE, |
| 57 |
sizeof(PDC_SIGNATURE) - 1) == 0) { |
| 58 |
|
| 59 |
if (blkid_probe_set_magic(pr, off, sizeof(pdc->sig), |
| 60 |
(unsigned char *) pdc->sig)) |
| 61 |
return 1; |
| 62 |
return 0; |
| 63 |
} |
| 64 |
} |
| 65 |
return 1; |
| 66 |
} |
| 67 |
|
| 68 |
const struct blkid_idinfo pdcraid_idinfo = { |
| 69 |
.name = "promise_fasttrack_raid_member", |
| 70 |
.usage = BLKID_USAGE_RAID, |
| 71 |
.minsz = 0x40000, |
| 72 |
.probefunc = probe_pdcraid, |
| 73 |
.magics = BLKID_NONE_MAGIC |
| 74 |
}; |
| 75 |
|
| 76 |
|