/src/util-linux/libblkid/src/superblocks/promise_raid.c
Line | Count | Source |
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 | 136k | #define PDC_SIGNATURE "Promise Technology, Inc." |
26 | | |
27 | | static int probe_pdcraid(blkid_probe pr, |
28 | | const struct blkid_idmag *mag __attribute__((__unused__))) |
29 | 5.26k | { |
30 | 5.26k | size_t i; |
31 | 5.26k | static unsigned int sectors[] = { |
32 | 5.26k | 63, 255, 256, 16, 399, 591, 675, 735, 911, 974, 991, 951, 3087 |
33 | 5.26k | }; |
34 | 5.26k | uint64_t nsectors; |
35 | | |
36 | 5.26k | if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr)) |
37 | 0 | return 1; |
38 | | |
39 | 5.26k | nsectors = pr->size >> 9; |
40 | | |
41 | 73.7k | for (i = 0; i < ARRAY_SIZE(sectors); i++) { |
42 | 68.4k | uint64_t off; |
43 | 68.4k | struct promise_metadata *pdc; |
44 | | |
45 | 68.4k | if (nsectors < sectors[i]) |
46 | 0 | return 1; |
47 | | |
48 | 68.4k | off = (nsectors - sectors[i]) << 9; |
49 | 68.4k | pdc = (struct promise_metadata *) |
50 | 68.4k | blkid_probe_get_buffer(pr, |
51 | 68.4k | off, |
52 | 68.4k | sizeof(struct promise_metadata)); |
53 | 68.4k | if (!pdc) |
54 | 0 | return errno ? -errno : 1; |
55 | | |
56 | 68.4k | if (memcmp(pdc->sig, PDC_SIGNATURE, |
57 | 68.4k | sizeof(PDC_SIGNATURE) - 1) == 0) { |
58 | |
|
59 | 0 | if (blkid_probe_set_magic(pr, off, sizeof(pdc->sig), |
60 | 0 | (unsigned char *) pdc->sig)) |
61 | 0 | return 1; |
62 | 0 | return 0; |
63 | 0 | } |
64 | 68.4k | } |
65 | 5.26k | return 1; |
66 | 5.26k | } |
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 | | |