blob: 496a3e7b0d255061c46415868ae55d2b07e8c67c [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
2 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
3 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
4 *
5 * Inspired by libvolume_id by
6 * Kay Sievers <kay.sievers@vrfy.org>
7 *
8 * This file may be redistributed under the terms of the
9 * GNU Lesser General Public License.
10 */
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <string.h>
15#include <errno.h>
16#include <ctype.h>
17#include <stdint.h>
18#include <stddef.h>
19
20#include "superblocks.h"
21
22struct silicon_metadata {
23 uint8_t unknown0[0x2E];
24 uint8_t ascii_version[0x36 - 0x2E];
25 int8_t diskname[0x56 - 0x36];
26 int8_t unknown1[0x60 - 0x56];
27 uint32_t magic;
28 int8_t unknown1a[0x6C - 0x64];
29 uint32_t array_sectors_low;
30 uint32_t array_sectors_high;
31 int8_t unknown2[0x78 - 0x74];
32 uint32_t thisdisk_sectors;
33 int8_t unknown3[0x100 - 0x7C];
34 int8_t unknown4[0x104 - 0x100];
35 uint16_t product_id;
36 uint16_t vendor_id;
37 uint16_t minor_ver;
38 uint16_t major_ver;
39 uint8_t seconds;
40 uint8_t minutes;
41 uint8_t hour;
42 uint8_t day;
43 uint8_t month;
44 uint8_t year;
45 uint16_t raid0_stride;
46 int8_t unknown6[0x116 - 0x114];
47 uint8_t disk_number;
48 uint8_t type; /* SILICON_TYPE_* */
49 int8_t drives_per_striped_set;
50 int8_t striped_set_number;
51 int8_t drives_per_mirrored_set;
52 int8_t mirrored_set_number;
53 uint32_t rebuild_ptr_low;
54 uint32_t rebuild_ptr_high;
55 uint32_t incarnation_no;
56 uint8_t member_status;
57 uint8_t mirrored_set_state; /* SILICON_MIRROR_* */
58 uint8_t reported_device_location;
59 uint8_t idechannel;
60 uint8_t auto_rebuild;
61 uint8_t unknown8;
62 uint8_t text_type[0x13E - 0x12E];
63 uint16_t checksum1;
64 int8_t assumed_zeros[0x1FE - 0x140];
65 uint16_t checksum2;
66} __attribute__((packed));
67
68#define SILICON_MAGIC 0x2F000000
69
70static int checksum(struct silicon_metadata *sil)
71{
72 int sum = 0;
73 unsigned short count = offsetof(struct silicon_metadata, checksum1) / 2;
74 uint16_t *p = (uint16_t *) sil;
75
76 while (count--)
77 sum += *p++;
78
79 return (-sum & 0xFFFF) == le16_to_cpu(sil->checksum1);
80}
81
82static int probe_silraid(blkid_probe pr,
83 const struct blkid_idmag *mag __attribute__((__unused__)))
84{
85 uint64_t off;
86 struct silicon_metadata *sil;
87
88 if (pr->size < 0x10000)
89 return -1;
90 if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
91 return -1;
92
93 off = ((pr->size / 0x200) - 1) * 0x200;
94
95 sil = (struct silicon_metadata *)
96 blkid_probe_get_buffer(pr, off,
97 sizeof(struct silicon_metadata));
98 if (!sil)
99 return -1;
100
101 if (le32_to_cpu(sil->magic) != SILICON_MAGIC)
102 return -1;
103 if (sil->disk_number >= 8)
104 return -1;
105 if (!checksum(sil)) {
106 DBG(DEBUG_LOWPROBE, printf("silicon raid: incorrect checksum\n"));
107 return -1;
108 }
109
110 if (blkid_probe_sprintf_version(pr, "%u.%u",
111 le16_to_cpu(sil->major_ver),
112 le16_to_cpu(sil->minor_ver)) != 0)
113 return -1;
114
115 if (blkid_probe_set_magic(pr,
116 off + offsetof(struct silicon_metadata, magic),
117 sizeof(sil->magic),
118 (unsigned char *) &sil->magic))
119 return -1;
120 return 0;
121}
122
123const struct blkid_idinfo silraid_idinfo = {
124 .name = "silicon_medley_raid_member",
125 .usage = BLKID_USAGE_RAID,
126 .probefunc = probe_silraid,
127 .magics = BLKID_NONE_MAGIC
128};
129
130