| 1 |
/* |
| 2 |
* Copyright (C) 2008 Karel Zak <[email protected]> |
| 3 |
* |
| 4 |
* Inspired by libvolume_id by |
| 5 |
* Kay Sievers <[email protected]> |
| 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 |
#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 |
{ |
| 40 |
uint8_t i = 50, cs = 0; |
| 41 |
|
| 42 |
while (i--) |
| 43 |
cs += ((uint8_t*) v)[i]; |
| 44 |
|
| 45 |
return cs; |
| 46 |
} |
| 47 |
|
| 48 |
static 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 (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr)) |
| 55 |
return 1; |
| 56 |
|
| 57 |
off = ((pr->size / 0x200)-1) * 0x200; |
| 58 |
|
| 59 |
v = (struct via_metadata *) |
| 60 |
blkid_probe_get_buffer(pr, |
| 61 |
off, |
| 62 |
sizeof(struct via_metadata)); |
| 63 |
if (!v) |
| 64 |
return errno ? -errno : 1; |
| 65 |
|
| 66 |
if (le16_to_cpu(v->signature) != VIA_SIGNATURE) |
| 67 |
return 1; |
| 68 |
if (v->version_number > 2) |
| 69 |
return 1; |
| 70 |
if (!blkid_probe_verify_csum(pr, via_checksum(v), v->checksum)) |
| 71 |
return 1; |
| 72 |
|
| 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 |
|
| 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 |
|