lvm.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* lvm.h - On disk structures for LVM. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2006,2007 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB 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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef GRUB_LVM_H
  20. #define GRUB_LVM_H 1
  21. #include <grub/types.h>
  22. /* Length of ID string, excluding terminating zero. */
  23. #define GRUB_LVM_ID_STRLEN 38
  24. struct grub_lvm_vg {
  25. char id[GRUB_LVM_ID_STRLEN+1];
  26. char *name;
  27. int extent_size;
  28. struct grub_lvm_pv *pvs;
  29. struct grub_lvm_lv *lvs;
  30. struct grub_lvm_vg *next;
  31. };
  32. struct grub_lvm_pv {
  33. char id[GRUB_LVM_ID_STRLEN+1];
  34. char *name;
  35. grub_disk_t disk;
  36. int start; /* Sector number where the data area starts. */
  37. struct grub_lvm_pv *next;
  38. };
  39. struct grub_lvm_lv {
  40. char *name;
  41. unsigned int number;
  42. unsigned int segment_count;
  43. grub_uint64_t size;
  44. struct grub_lvm_segment *segments; /* Pointer to segment_count segments. */
  45. struct grub_lvm_vg *vg;
  46. struct grub_lvm_lv *next;
  47. };
  48. struct grub_lvm_segment {
  49. unsigned int start_extent;
  50. unsigned int extent_count;
  51. unsigned int stripe_count;
  52. unsigned int stripe_size;
  53. struct grub_lvm_stripe *stripes; /* Pointer to stripe_count stripes. */
  54. };
  55. struct grub_lvm_stripe {
  56. int start;
  57. struct grub_lvm_pv *pv;
  58. };
  59. #define GRUB_LVM_LABEL_SIZE GRUB_DISK_SECTOR_SIZE
  60. #define GRUB_LVM_LABEL_SCAN_SECTORS 4L
  61. #define GRUB_LVM_LABEL_ID "LABELONE"
  62. #define GRUB_LVM_LVM2_LABEL "LVM2 001"
  63. #define GRUB_LVM_ID_LEN 32
  64. /* On disk - 32 bytes */
  65. struct grub_lvm_label_header {
  66. grub_int8_t id[8]; /* LABELONE */
  67. grub_uint64_t sector_xl; /* Sector number of this label */
  68. grub_uint32_t crc_xl; /* From next field to end of sector */
  69. grub_uint32_t offset_xl; /* Offset from start of struct to contents */
  70. grub_int8_t type[8]; /* LVM2 001 */
  71. } __attribute__ ((packed));
  72. /* On disk */
  73. struct grub_lvm_disk_locn {
  74. grub_uint64_t offset; /* Offset in bytes to start sector */
  75. grub_uint64_t size; /* Bytes */
  76. } __attribute__ ((packed));
  77. /* Fields with the suffix _xl should be xlate'd wherever they appear */
  78. /* On disk */
  79. struct grub_lvm_pv_header {
  80. grub_int8_t pv_uuid[GRUB_LVM_ID_LEN];
  81. /* This size can be overridden if PV belongs to a VG */
  82. grub_uint64_t device_size_xl; /* Bytes */
  83. /* NULL-terminated list of data areas followed by */
  84. /* NULL-terminated list of metadata area headers */
  85. struct grub_lvm_disk_locn disk_areas_xl[0]; /* Two lists */
  86. } __attribute__ ((packed));
  87. #define GRUB_LVM_FMTT_MAGIC "\040\114\126\115\062\040\170\133\065\101\045\162\060\116\052\076"
  88. #define GRUB_LVM_FMTT_VERSION 1
  89. #define GRUB_LVM_MDA_HEADER_SIZE 512
  90. /* On disk */
  91. struct grub_lvm_raw_locn {
  92. grub_uint64_t offset; /* Offset in bytes to start sector */
  93. grub_uint64_t size; /* Bytes */
  94. grub_uint32_t checksum;
  95. grub_uint32_t filler;
  96. } __attribute__ ((packed));
  97. /* On disk */
  98. /* Structure size limited to one sector */
  99. struct grub_lvm_mda_header {
  100. grub_uint32_t checksum_xl; /* Checksum of rest of mda_header */
  101. grub_int8_t magic[16]; /* To aid scans for metadata */
  102. grub_uint32_t version;
  103. grub_uint64_t start; /* Absolute start byte of mda_header */
  104. grub_uint64_t size; /* Size of metadata area */
  105. struct grub_lvm_raw_locn raw_locns[0]; /* NULL-terminated list */
  106. } __attribute__ ((packed));
  107. #endif /* ! GRUB_LVM_H */