blob: ee3ab658ed4953bd9e64bb04b8bc1b59a9e829c9 [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
bigbiff7b4c7a62015-01-01 19:44:14 -050045 return cs;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050046}
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)
bigbiff7b4c7a62015-01-01 19:44:14 -050055 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050056 if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr))
bigbiff7b4c7a62015-01-01 19:44:14 -050057 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050058
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)
bigbiff7b4c7a62015-01-01 19:44:14 -050066 return errno ? -errno : 1;
67
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050068 if (le16_to_cpu(v->signature) != VIA_SIGNATURE)
bigbiff7b4c7a62015-01-01 19:44:14 -050069 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050070 if (v->version_number > 2)
bigbiff7b4c7a62015-01-01 19:44:14 -050071 return 1;
72 if (!blkid_probe_verify_csum(pr, via_checksum(v), v->checksum))
73 return 1;
74
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050075 if (blkid_probe_sprintf_version(pr, "%u", v->version_number) != 0)
bigbiff7b4c7a62015-01-01 19:44:14 -050076 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050077 if (blkid_probe_set_magic(pr, off,
78 sizeof(v->signature),
79 (unsigned char *) &v->signature))
bigbiff7b4c7a62015-01-01 19:44:14 -050080 return 1;
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050081 return 0;
82}
83
84const struct blkid_idinfo viaraid_idinfo = {
85 .name = "via_raid_member",
86 .usage = BLKID_USAGE_RAID,
87 .probefunc = probe_viaraid,
88 .magics = BLKID_NONE_MAGIC
89};
90
91