bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 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 | #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 isw_metadata { |
| 19 | uint8_t sig[32]; |
| 20 | uint32_t check_sum; |
| 21 | uint32_t mpb_size; |
| 22 | uint32_t family_num; |
| 23 | uint32_t generation_num; |
| 24 | }; |
| 25 | |
| 26 | #define ISW_SIGNATURE "Intel Raid ISM Cfg Sig. " |
| 27 | |
| 28 | |
| 29 | static int probe_iswraid(blkid_probe pr, |
| 30 | const struct blkid_idmag *mag __attribute__((__unused__))) |
| 31 | { |
| 32 | uint64_t off; |
| 33 | struct isw_metadata *isw; |
| 34 | |
| 35 | if (pr->size < 0x10000) |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 36 | return 1; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 37 | if (!S_ISREG(pr->mode) && !blkid_probe_is_wholedisk(pr)) |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 38 | return 1; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 39 | |
| 40 | off = ((pr->size / 0x200) - 2) * 0x200; |
| 41 | isw = (struct isw_metadata *) |
| 42 | blkid_probe_get_buffer(pr, |
| 43 | off, |
| 44 | sizeof(struct isw_metadata)); |
| 45 | if (!isw) |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 46 | return errno ? -errno : 1; |
| 47 | |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 48 | if (memcmp(isw->sig, ISW_SIGNATURE, sizeof(ISW_SIGNATURE)-1) != 0) |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 49 | return 1; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 50 | if (blkid_probe_sprintf_version(pr, "%6s", |
| 51 | &isw->sig[sizeof(ISW_SIGNATURE)-1]) != 0) |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 52 | return 1; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 53 | if (blkid_probe_set_magic(pr, off, sizeof(isw->sig), |
| 54 | (unsigned char *) isw->sig)) |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 55 | return 1; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | const struct blkid_idinfo iswraid_idinfo = { |
| 60 | .name = "isw_raid_member", |
| 61 | .usage = BLKID_USAGE_RAID, |
| 62 | .probefunc = probe_iswraid, |
| 63 | .magics = BLKID_NONE_MAGIC |
| 64 | }; |
| 65 | |
| 66 | |