/src/util-linux/libblkid/src/superblocks/adaptec_raid.c
Line | Count | Source (jump to first uncovered line) |
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 adaptec_metadata { |
19 | | |
20 | | uint32_t b0idcode; |
21 | | uint8_t lunsave[8]; |
22 | | uint16_t sdtype; |
23 | | uint16_t ssavecyl; |
24 | | uint8_t ssavehed; |
25 | | uint8_t ssavesec; |
26 | | uint8_t sb0flags; |
27 | | uint8_t jbodEnable; |
28 | | uint8_t lundsave; |
29 | | uint8_t svpdirty; |
30 | | uint16_t biosInfo; |
31 | | uint16_t svwbskip; |
32 | | uint16_t svwbcln; |
33 | | uint16_t svwbmax; |
34 | | uint16_t res3; |
35 | | uint16_t svwbmin; |
36 | | uint16_t res4; |
37 | | uint16_t svrcacth; |
38 | | uint16_t svwcacth; |
39 | | uint16_t svwbdly; |
40 | | uint8_t svsdtime; |
41 | | uint8_t res5; |
42 | | uint16_t firmval; |
43 | | uint16_t firmbln; |
44 | | uint32_t firmblk; |
45 | | uint32_t fstrsvrb; |
46 | | uint16_t svBlockStorageTid; |
47 | | uint16_t svtid; |
48 | | uint8_t svseccfl; |
49 | | uint8_t res6; |
50 | | uint8_t svhbanum; |
51 | | uint8_t resver; |
52 | | uint32_t drivemagic; |
53 | | uint8_t reserved[20]; |
54 | | uint8_t testnum; |
55 | | uint8_t testflags; |
56 | | uint16_t maxErrorCount; |
57 | | uint32_t count; |
58 | | uint32_t startTime; |
59 | | uint32_t interval; |
60 | | uint8_t tstxt0; |
61 | | uint8_t tstxt1; |
62 | | uint8_t serNum[32]; |
63 | | uint8_t res8[102]; |
64 | | uint32_t fwTestMagic; |
65 | | uint32_t fwTestSeqNum; |
66 | | uint8_t fwTestRes[8]; |
67 | | uint32_t smagic; |
68 | | uint32_t raidtbl; |
69 | | uint16_t raidline; |
70 | | uint8_t res9[0xF6]; |
71 | | } __attribute__((packed)); |
72 | | |
73 | | #define AD_SIGNATURE 0x4450544D /* "DPTM" */ |
74 | | #define AD_MAGIC 0x37FC4D1E |
75 | | |
76 | | static int probe_adraid(blkid_probe pr, |
77 | | const struct blkid_idmag *mag __attribute__((__unused__))) |
78 | 3 | { |
79 | 3 | uint64_t off; |
80 | 3 | struct adaptec_metadata *ad; |
81 | | |
82 | 3 | if (pr->size < 0x10000) |
83 | 0 | return BLKID_PROBE_NONE; |
84 | | |
85 | 3 | if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr)) |
86 | 3 | return BLKID_PROBE_NONE; |
87 | | |
88 | 0 | off = ((pr->size / 0x200)-1) * 0x200; |
89 | 0 | ad = (struct adaptec_metadata *) |
90 | 0 | blkid_probe_get_buffer(pr, |
91 | 0 | off, |
92 | 0 | sizeof(struct adaptec_metadata)); |
93 | 0 | if (!ad) |
94 | 0 | return errno ? -errno : BLKID_PROBE_NONE; |
95 | | |
96 | 0 | if (ad->smagic != be32_to_cpu(AD_SIGNATURE)) |
97 | 0 | return BLKID_PROBE_NONE; |
98 | 0 | if (ad->b0idcode != be32_to_cpu(AD_MAGIC)) |
99 | 0 | return BLKID_PROBE_NONE; |
100 | 0 | if (blkid_probe_sprintf_version(pr, "%u", ad->resver) != 0) |
101 | 0 | return BLKID_PROBE_NONE; |
102 | 0 | if (blkid_probe_set_magic(pr, off, sizeof(ad->b0idcode), |
103 | 0 | (unsigned char *) &ad->b0idcode)) |
104 | 0 | return BLKID_PROBE_NONE; |
105 | | |
106 | 0 | return BLKID_PROBE_OK; |
107 | 0 | } |
108 | | |
109 | | const struct blkid_idinfo adraid_idinfo = { |
110 | | .name = "adaptec_raid_member", |
111 | | .usage = BLKID_USAGE_RAID, |
112 | | .probefunc = probe_adraid, |
113 | | .magics = BLKID_NONE_MAGIC |
114 | | }; |
115 | | |
116 | | |