blob: eba7e4bf2f4caee05e56d898fb6959fb0820f32f [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
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
19#include "superblocks.h"
20
21struct via_metadata {
22 uint16_t signature;
23 uint8_t version_number;
24 struct via_array {
25 uint16_t disk_bit_mask;
26 uint8_t disk_array_ex;
27 uint32_t capacity_low;
28 uint32_t capacity_high;
29 uint32_t serial_checksum;
30 } __attribute__((packed)) array;
31 uint32_t serial_checksum[8];
32 uint8_t checksum;
33} __attribute__((packed));
34
35#define VIA_SIGNATURE 0xAA55
36
37/* 8 bit checksum on first 50 bytes of metadata. */
38static uint8_t via_checksum(struct via_metadata *v)
39{
40 uint8_t i = 50, cs = 0;
41
42 while (i--)
43 cs += ((uint8_t*) v)[i];
44
45 return cs == v->checksum;
46}
47
48static int probe_viaraid(blkid_probe pr,
49 const struct blkid_idmag *mag __attribute__((__unused__)))
50{
51 uint64_t off;
52 struct via_metadata *v;
53
54 if (pr->size < 0x10000)
55 return -1;
56 if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
57 return -1;
58
59 off = ((pr->size / 0x200)-1) * 0x200;
60
61 v = (struct via_metadata *)
62 blkid_probe_get_buffer(pr,
63 off,
64 sizeof(struct via_metadata));
65 if (!v)
66 return -1;
67 if (le16_to_cpu(v->signature) != VIA_SIGNATURE)
68 return -1;
69 if (v->version_number > 2)
70 return -1;
71 if (!via_checksum(v))
72 return -1;
73 if (blkid_probe_sprintf_version(pr, "%u", v->version_number) != 0)
74 return -1;
75 if (blkid_probe_set_magic(pr, off,
76 sizeof(v->signature),
77 (unsigned char *) &v->signature))
78 return -1;
79 return 0;
80}
81
82const struct blkid_idinfo viaraid_idinfo = {
83 .name = "via_raid_member",
84 .usage = BLKID_USAGE_RAID,
85 .probefunc = probe_viaraid,
86 .magics = BLKID_NONE_MAGIC
87};
88
89