Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * volume_id - reads filesystem label and uuid |
| 3 | * |
| 4 | * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
Sven-Göran Bergh | 3b45801 | 2013-07-31 15:45:20 +0200 | [diff] [blame] | 21 | //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LINUXRAID) += linux_raid.o |
| 22 | |
Sven-Göran Bergh | 15d0a86 | 2013-07-31 15:57:59 +0200 | [diff] [blame^] | 23 | //config: |
| 24 | //config:config FEATURE_VOLUMEID_LINUXRAID |
| 25 | //config: bool "linuxraid" |
| 26 | //config: default y |
| 27 | //config: depends on VOLUMEID |
| 28 | //config: help |
| 29 | //config: TODO |
| 30 | //config: |
| 31 | |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 32 | #include "volume_id_internal.h" |
| 33 | |
| 34 | struct mdp_super_block { |
| 35 | uint32_t md_magic; |
| 36 | uint32_t major_version; |
| 37 | uint32_t minor_version; |
| 38 | uint32_t patch_version; |
| 39 | uint32_t gvalid_words; |
| 40 | uint32_t set_uuid0; |
| 41 | uint32_t ctime; |
| 42 | uint32_t level; |
| 43 | uint32_t size; |
| 44 | uint32_t nr_disks; |
| 45 | uint32_t raid_disks; |
| 46 | uint32_t md_minor; |
| 47 | uint32_t not_persistent; |
| 48 | uint32_t set_uuid1; |
| 49 | uint32_t set_uuid2; |
| 50 | uint32_t set_uuid3; |
Denys Vlasenko | 8dc0e19 | 2009-09-16 00:58:11 +0200 | [diff] [blame] | 51 | } PACKED; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 52 | |
| 53 | #define MD_RESERVED_BYTES 0x10000 |
| 54 | #define MD_MAGIC 0xa92b4efc |
| 55 | |
Denys Vlasenko | 8930096 | 2009-11-01 23:07:18 +0100 | [diff] [blame] | 56 | int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/, uint64_t size) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 57 | { |
Denys Vlasenko | 12ca080 | 2010-02-04 18:41:18 +0100 | [diff] [blame] | 58 | typedef uint32_t aliased_uint32_t FIX_ALIASING; |
Denis Vlasenko | 28ea429 | 2009-02-15 05:51:19 +0000 | [diff] [blame] | 59 | #define off ((uint64_t)0) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 60 | uint64_t sboff; |
| 61 | uint8_t uuid[16]; |
| 62 | struct mdp_super_block *mdp; |
| 63 | |
| 64 | dbg("probing at offset 0x%llx, size 0x%llx", |
| 65 | (unsigned long long) off, (unsigned long long) size); |
| 66 | |
| 67 | if (size < 0x10000) |
| 68 | return -1; |
| 69 | |
| 70 | sboff = (size & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES; |
| 71 | mdp = volume_id_get_buffer(id, off + sboff, 0x800); |
| 72 | if (mdp == NULL) |
| 73 | return -1; |
| 74 | |
| 75 | if (mdp->md_magic != cpu_to_le32(MD_MAGIC)) |
| 76 | return -1; |
| 77 | |
Denys Vlasenko | 12ca080 | 2010-02-04 18:41:18 +0100 | [diff] [blame] | 78 | *(aliased_uint32_t*)uuid = mdp->set_uuid0; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 79 | memcpy(&uuid[4], &mdp->set_uuid1, 12); |
| 80 | volume_id_set_uuid(id, uuid, UUID_DCE); |
| 81 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 82 | // snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u", |
Denys Vlasenko | 6967578 | 2013-01-14 01:34:48 +0100 | [diff] [blame] | 83 | // le32_to_cpu(mdp->major_version), |
| 84 | // le32_to_cpu(mdp->minor_version), |
| 85 | // le32_to_cpu(mdp->patch_version)); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 86 | |
| 87 | dbg("found raid signature"); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 88 | // volume_id_set_usage(id, VOLUME_ID_RAID); |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 89 | IF_FEATURE_BLKID_TYPE(id->type = "linux_raid_member";) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |