3
0

linux_raid.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LINUXRAID) += linux_raid.o
  21. //config:
  22. //config:config FEATURE_VOLUMEID_LINUXRAID
  23. //config: bool "linuxraid"
  24. //config: default y
  25. //config: depends on VOLUMEID
  26. //config: help
  27. //config: TODO
  28. //config:
  29. #include "volume_id_internal.h"
  30. struct mdp_super_block {
  31. uint32_t md_magic;
  32. uint32_t major_version;
  33. uint32_t minor_version;
  34. uint32_t patch_version;
  35. uint32_t gvalid_words;
  36. uint32_t set_uuid0;
  37. uint32_t ctime;
  38. uint32_t level;
  39. uint32_t size;
  40. uint32_t nr_disks;
  41. uint32_t raid_disks;
  42. uint32_t md_minor;
  43. uint32_t not_persistent;
  44. uint32_t set_uuid1;
  45. uint32_t set_uuid2;
  46. uint32_t set_uuid3;
  47. } PACKED;
  48. #define MD_RESERVED_BYTES 0x10000
  49. #define MD_MAGIC 0xa92b4efc
  50. int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/, uint64_t size)
  51. {
  52. typedef uint32_t aliased_uint32_t FIX_ALIASING;
  53. #define off ((uint64_t)0)
  54. uint64_t sboff;
  55. uint8_t uuid[16];
  56. struct mdp_super_block *mdp;
  57. dbg("probing at offset 0x%llx, size 0x%llx",
  58. (unsigned long long) off, (unsigned long long) size);
  59. if (size < 0x10000)
  60. return -1;
  61. sboff = (size & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES;
  62. mdp = volume_id_get_buffer(id, off + sboff, 0x800);
  63. if (mdp == NULL)
  64. return -1;
  65. if (mdp->md_magic != cpu_to_le32(MD_MAGIC))
  66. return -1;
  67. *(aliased_uint32_t*)uuid = mdp->set_uuid0;
  68. memcpy(&uuid[4], &mdp->set_uuid1, 12);
  69. volume_id_set_uuid(id, uuid, UUID_DCE);
  70. // snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u",
  71. // le32_to_cpu(mdp->major_version),
  72. // le32_to_cpu(mdp->minor_version),
  73. // le32_to_cpu(mdp->patch_version));
  74. dbg("found raid signature");
  75. // volume_id_set_usage(id, VOLUME_ID_RAID);
  76. IF_FEATURE_BLKID_TYPE(id->type = "linux_raid_member";)
  77. return 0;
  78. }