blob: 02e900df0dd494544dd4a20393a622852993e949 [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 <stdint.h>
15
16#include "superblocks.h"
17
18struct 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
76static int probe_adraid(blkid_probe pr,
77 const struct blkid_idmag *mag __attribute__((__unused__)))
78{
79 uint64_t off;
80 struct adaptec_metadata *ad;
81
82 if (pr->size < 0x10000)
83 return -1;
84
85 if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
86 return -1;
87
88 off = ((pr->size / 0x200)-1) * 0x200;
89 ad = (struct adaptec_metadata *)
90 blkid_probe_get_buffer(pr,
91 off,
92 sizeof(struct adaptec_metadata));
93 if (!ad)
94 return -1;
95 if (ad->smagic != be32_to_cpu(AD_SIGNATURE))
96 return -1;
97 if (ad->b0idcode != be32_to_cpu(AD_MAGIC))
98 return -1;
99 if (blkid_probe_sprintf_version(pr, "%u", ad->resver) != 0)
100 return -1;
101 if (blkid_probe_set_magic(pr, off, sizeof(ad->b0idcode),
102 (unsigned char *) &ad->b0idcode))
103 return -1;
104 return 0;
105}
106
107const struct blkid_idinfo adraid_idinfo = {
108 .name = "adaptec_raid_member",
109 .usage = BLKID_USAGE_RAID,
110 .probefunc = probe_adraid,
111 .magics = BLKID_NONE_MAGIC
112};
113
114