/src/util-linux/libblkid/src/superblocks/via_raid.c
Line | Count | Source |
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 | | |
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 | | |
21 | | struct 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 | 4.70k | #define VIA_SIGNATURE 0xAA55 |
36 | | |
37 | | /* 8 bit checksum on first 50 bytes of metadata. */ |
38 | | static uint8_t via_checksum(struct via_metadata *v) |
39 | 0 | { |
40 | 0 | uint8_t i = 50, cs = 0; |
41 | |
|
42 | 0 | while (i--) |
43 | 0 | cs += ((uint8_t*) v)[i]; |
44 | |
|
45 | 0 | return cs; |
46 | 0 | } |
47 | | |
48 | | static int probe_viaraid(blkid_probe pr, |
49 | | const struct blkid_idmag *mag __attribute__((__unused__))) |
50 | 4.70k | { |
51 | 4.70k | uint64_t off; |
52 | 4.70k | struct via_metadata *v; |
53 | | |
54 | 4.70k | if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr)) |
55 | 0 | return 1; |
56 | | |
57 | 4.70k | off = ((pr->size / 0x200)-1) * 0x200; |
58 | | |
59 | 4.70k | v = (struct via_metadata *) |
60 | 4.70k | blkid_probe_get_buffer(pr, |
61 | 4.70k | off, |
62 | 4.70k | sizeof(struct via_metadata)); |
63 | 4.70k | if (!v) |
64 | 0 | return errno ? -errno : 1; |
65 | | |
66 | 4.70k | if (le16_to_cpu(v->signature) != VIA_SIGNATURE) |
67 | 4.70k | return 1; |
68 | 0 | if (v->version_number > 2) |
69 | 0 | return 1; |
70 | 0 | if (!blkid_probe_verify_csum(pr, via_checksum(v), v->checksum)) |
71 | 0 | return 1; |
72 | | |
73 | 0 | if (blkid_probe_sprintf_version(pr, "%u", v->version_number) != 0) |
74 | 0 | return 1; |
75 | 0 | if (blkid_probe_set_magic(pr, off, |
76 | 0 | sizeof(v->signature), |
77 | 0 | (unsigned char *) &v->signature)) |
78 | 0 | return 1; |
79 | 0 | return 0; |
80 | 0 | } |
81 | | |
82 | | const struct blkid_idinfo viaraid_idinfo = { |
83 | | .name = "via_raid_member", |
84 | | .usage = BLKID_USAGE_RAID, |
85 | | .minsz = 0x10000, |
86 | | .probefunc = probe_viaraid, |
87 | | .magics = BLKID_NONE_MAGIC |
88 | | }; |
89 | | |
90 | | |