| 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 |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
| 12 |
#include <unistd.h> |
| 13 |
#include <string.h> |
| 14 |
#include <stdint.h> |
| 15 |
|
| 16 |
#include "superblocks.h" |
| 17 |
|
| 18 |
struct adaptec_metadata { |
| 19 |
|
| 20 |
uint32_t b0idcode; |
| 21 |
uint8_t lunsave[8]; |
| 22 |
uint16_t sdtype; |
| 23 |
uint16_t ssavecyl; |
| 24 |
uint8_t ssavehed; |
| 25 |
uint8_t ssavesec; |
| 26 |
uint8_t sb0flags; |
| 27 |
uint8_t jbodEnable; |
| 28 |
uint8_t lundsave; |
| 29 |
uint8_t svpdirty; |
| 30 |
uint16_t biosInfo; |
| 31 |
uint16_t svwbskip; |
| 32 |
uint16_t svwbcln; |
| 33 |
uint16_t svwbmax; |
| 34 |
uint16_t res3; |
| 35 |
uint16_t svwbmin; |
| 36 |
uint16_t res4; |
| 37 |
uint16_t svrcacth; |
| 38 |
uint16_t svwcacth; |
| 39 |
uint16_t svwbdly; |
| 40 |
uint8_t svsdtime; |
| 41 |
uint8_t res5; |
| 42 |
uint16_t firmval; |
| 43 |
uint16_t firmbln; |
| 44 |
uint32_t firmblk; |
| 45 |
uint32_t fstrsvrb; |
| 46 |
uint16_t svBlockStorageTid; |
| 47 |
uint16_t svtid; |
| 48 |
uint8_t svseccfl; |
| 49 |
uint8_t res6; |
| 50 |
uint8_t svhbanum; |
| 51 |
uint8_t resver; |
| 52 |
uint32_t drivemagic; |
| 53 |
uint8_t reserved[20]; |
| 54 |
uint8_t testnum; |
| 55 |
uint8_t testflags; |
| 56 |
uint16_t maxErrorCount; |
| 57 |
uint32_t count; |
| 58 |
uint32_t startTime; |
| 59 |
uint32_t interval; |
| 60 |
uint8_t tstxt0; |
| 61 |
uint8_t tstxt1; |
| 62 |
uint8_t serNum[32]; |
| 63 |
uint8_t res8[102]; |
| 64 |
uint32_t fwTestMagic; |
| 65 |
uint32_t fwTestSeqNum; |
| 66 |
uint8_t fwTestRes[8]; |
| 67 |
uint32_t smagic; |
| 68 |
uint32_t raidtbl; |
| 69 |
uint16_t raidline; |
| 70 |
uint8_t res9[0xF6]; |
| 71 |
} __attribute__((packed)); |
| 72 |
|
| 73 |
#define AD_SIGNATURE 0x4450544D /* "DPTM" */ |
| 74 |
#define AD_MAGIC 0x37FC4D1E |
| 75 |
|
| 76 |
static int probe_adraid(blkid_probe pr, |
| 77 |
const struct blkid_idmag *mag __attribute__((__unused__))) |
| 78 |
{ |
| 79 |
uint64_t off; |
| 80 |
struct adaptec_metadata *ad; |
| 81 |
|
| 82 |
if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr)) |
| 83 |
return BLKID_PROBE_NONE; |
| 84 |
|
| 85 |
off = ((pr->size / 0x200)-1) * 0x200; |
| 86 |
ad = (struct adaptec_metadata *) |
| 87 |
blkid_probe_get_buffer(pr, |
| 88 |
off, |
| 89 |
sizeof(struct adaptec_metadata)); |
| 90 |
if (!ad) |
| 91 |
return errno ? -errno : BLKID_PROBE_NONE; |
| 92 |
|
| 93 |
if (ad->smagic != be32_to_cpu(AD_SIGNATURE)) |
| 94 |
return BLKID_PROBE_NONE; |
| 95 |
if (ad->b0idcode != be32_to_cpu(AD_MAGIC)) |
| 96 |
return BLKID_PROBE_NONE; |
| 97 |
if (blkid_probe_sprintf_version(pr, "%u", ad->resver) != 0) |
| 98 |
return BLKID_PROBE_NONE; |
| 99 |
if (blkid_probe_set_magic(pr, off, sizeof(ad->b0idcode), |
| 100 |
(unsigned char *) &ad->b0idcode)) |
| 101 |
return BLKID_PROBE_NONE; |
| 102 |
|
| 103 |
return BLKID_PROBE_OK; |
| 104 |
} |
| 105 |
|
| 106 |
const struct blkid_idinfo adraid_idinfo = { |
| 107 |
.name = "adaptec_raid_member", |
| 108 |
.usage = BLKID_USAGE_RAID, |
| 109 |
.minsz = 0x10000, |
| 110 |
.probefunc = probe_adraid, |
| 111 |
.magics = BLKID_NONE_MAGIC |
| 112 |
}; |
| 113 |
|
| 114 |
|