ldm.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. * ldm - Part of the Linux-NTFS project.
  3. *
  4. * Copyright (C) 2001,2002 Richard Russon <ldm@flatcap.org>
  5. * Copyright (C) 2001 Anton Altaparmakov <aia21@cantab.net>
  6. * Copyright (C) 2001,2002 Jakob Kemi <jakob.kemi@telia.com>
  7. *
  8. * Documentation is available at http://linux-ntfs.sf.net/ldm
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License, or (at your option)
  13. * any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program (in the main directory of the Linux-NTFS source
  22. * in the file COPYING); if not, write to the Free Software Foundation,
  23. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #ifndef _FS_PT_LDM_H_
  26. #define _FS_PT_LDM_H_
  27. #include <linux/types.h>
  28. #include <linux/list.h>
  29. #include <linux/genhd.h>
  30. #include <linux/fs.h>
  31. #include <asm/unaligned.h>
  32. #include <asm/byteorder.h>
  33. struct parsed_partitions;
  34. /* Magic numbers in CPU format. */
  35. #define MAGIC_VMDB 0x564D4442 /* VMDB */
  36. #define MAGIC_VBLK 0x56424C4B /* VBLK */
  37. #define MAGIC_PRIVHEAD 0x5052495648454144ULL /* PRIVHEAD */
  38. #define MAGIC_TOCBLOCK 0x544F43424C4F434BULL /* TOCBLOCK */
  39. /* The defined vblk types. */
  40. #define VBLK_VOL5 0x51 /* Volume, version 5 */
  41. #define VBLK_CMP3 0x32 /* Component, version 3 */
  42. #define VBLK_PRT3 0x33 /* Partition, version 3 */
  43. #define VBLK_DSK3 0x34 /* Disk, version 3 */
  44. #define VBLK_DSK4 0x44 /* Disk, version 4 */
  45. #define VBLK_DGR3 0x35 /* Disk Group, version 3 */
  46. #define VBLK_DGR4 0x45 /* Disk Group, version 4 */
  47. /* vblk flags indicating extra information will be present */
  48. #define VBLK_FLAG_COMP_STRIPE 0x10
  49. #define VBLK_FLAG_PART_INDEX 0x08
  50. #define VBLK_FLAG_DGR3_IDS 0x08
  51. #define VBLK_FLAG_DGR4_IDS 0x08
  52. #define VBLK_FLAG_VOLU_ID1 0x08
  53. #define VBLK_FLAG_VOLU_ID2 0x20
  54. #define VBLK_FLAG_VOLU_SIZE 0x80
  55. #define VBLK_FLAG_VOLU_DRIVE 0x02
  56. /* size of a vblk's static parts */
  57. #define VBLK_SIZE_HEAD 16
  58. #define VBLK_SIZE_CMP3 22 /* Name and version */
  59. #define VBLK_SIZE_DGR3 12
  60. #define VBLK_SIZE_DGR4 44
  61. #define VBLK_SIZE_DSK3 12
  62. #define VBLK_SIZE_DSK4 45
  63. #define VBLK_SIZE_PRT3 28
  64. #define VBLK_SIZE_VOL5 59
  65. /* component types */
  66. #define COMP_STRIPE 0x01 /* Stripe-set */
  67. #define COMP_BASIC 0x02 /* Basic disk */
  68. #define COMP_RAID 0x03 /* Raid-set */
  69. /* Other constants. */
  70. #define LDM_DB_SIZE 2048 /* Size in sectors (= 1MiB). */
  71. #define OFF_PRIV1 6 /* Offset of the first privhead
  72. relative to the start of the
  73. device in sectors */
  74. /* Offsets to structures within the LDM Database in sectors. */
  75. #define OFF_PRIV2 1856 /* Backup private headers. */
  76. #define OFF_PRIV3 2047
  77. #define OFF_TOCB1 1 /* Tables of contents. */
  78. #define OFF_TOCB2 2
  79. #define OFF_TOCB3 2045
  80. #define OFF_TOCB4 2046
  81. #define OFF_VMDB 17 /* List of partitions. */
  82. #define WIN2K_DYNAMIC_PARTITION 0x42 /* Formerly SFS (Landis). */
  83. #define TOC_BITMAP1 "config" /* Names of the two defined */
  84. #define TOC_BITMAP2 "log" /* bitmaps in the TOCBLOCK. */
  85. /* Most numbers we deal with are big-endian and won't be aligned. */
  86. #define BE16(x) ((u16)be16_to_cpu(get_unaligned((__be16*)(x))))
  87. #define BE32(x) ((u32)be32_to_cpu(get_unaligned((__be32*)(x))))
  88. #define BE64(x) ((u64)be64_to_cpu(get_unaligned((__be64*)(x))))
  89. /* Borrowed from msdos.c */
  90. #define SYS_IND(p) (get_unaligned(&(p)->sys_ind))
  91. struct frag { /* VBLK Fragment handling */
  92. struct list_head list;
  93. u32 group;
  94. u8 num; /* Total number of records */
  95. u8 rec; /* This is record number n */
  96. u8 map; /* Which portions are in use */
  97. u8 data[0];
  98. };
  99. /* In memory LDM database structures. */
  100. #define GUID_SIZE 16
  101. struct privhead { /* Offsets and sizes are in sectors. */
  102. u16 ver_major;
  103. u16 ver_minor;
  104. u64 logical_disk_start;
  105. u64 logical_disk_size;
  106. u64 config_start;
  107. u64 config_size;
  108. u8 disk_id[GUID_SIZE];
  109. };
  110. struct tocblock { /* We have exactly two bitmaps. */
  111. u8 bitmap1_name[16];
  112. u64 bitmap1_start;
  113. u64 bitmap1_size;
  114. u8 bitmap2_name[16];
  115. u64 bitmap2_start;
  116. u64 bitmap2_size;
  117. };
  118. struct vmdb { /* VMDB: The database header */
  119. u16 ver_major;
  120. u16 ver_minor;
  121. u32 vblk_size;
  122. u32 vblk_offset;
  123. u32 last_vblk_seq;
  124. };
  125. struct vblk_comp { /* VBLK Component */
  126. u8 state[16];
  127. u64 parent_id;
  128. u8 type;
  129. u8 children;
  130. u16 chunksize;
  131. };
  132. struct vblk_dgrp { /* VBLK Disk Group */
  133. u8 disk_id[64];
  134. };
  135. struct vblk_disk { /* VBLK Disk */
  136. u8 disk_id[GUID_SIZE];
  137. u8 alt_name[128];
  138. };
  139. struct vblk_part { /* VBLK Partition */
  140. u64 start;
  141. u64 size; /* start, size and vol_off in sectors */
  142. u64 volume_offset;
  143. u64 parent_id;
  144. u64 disk_id;
  145. u8 partnum;
  146. };
  147. struct vblk_volu { /* VBLK Volume */
  148. u8 volume_type[16];
  149. u8 volume_state[16];
  150. u8 guid[16];
  151. u8 drive_hint[4];
  152. u64 size;
  153. u8 partition_type;
  154. };
  155. struct vblk_head { /* VBLK standard header */
  156. u32 group;
  157. u16 rec;
  158. u16 nrec;
  159. };
  160. struct vblk { /* Generalised VBLK */
  161. u8 name[64];
  162. u64 obj_id;
  163. u32 sequence;
  164. u8 flags;
  165. u8 type;
  166. union {
  167. struct vblk_comp comp;
  168. struct vblk_dgrp dgrp;
  169. struct vblk_disk disk;
  170. struct vblk_part part;
  171. struct vblk_volu volu;
  172. } vblk;
  173. struct list_head list;
  174. };
  175. struct ldmdb { /* Cache of the database */
  176. struct privhead ph;
  177. struct tocblock toc;
  178. struct vmdb vm;
  179. struct list_head v_dgrp;
  180. struct list_head v_disk;
  181. struct list_head v_volu;
  182. struct list_head v_comp;
  183. struct list_head v_part;
  184. };
  185. int ldm_partition (struct parsed_partitions *state, struct block_device *bdev);
  186. #endif /* _FS_PT_LDM_H_ */