xref: /linux/block/partitions/ldm.h (revision 3d0fe49454652117522f60bfbefb978ba0e5300b)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /**
3  * ldm - Part of the Linux-NTFS project.
4  *
5  * Copyright (C) 2001,2002 Richard Russon <ldm@flatcap.org>
6  * Copyright (c) 2001-2007 Anton Altaparmakov
7  * Copyright (C) 2001,2002 Jakob Kemi <jakob.kemi@telia.com>
8  *
9  * Documentation is available at http://www.linux-ntfs.org/doku.php?id=downloads
10  */
11 
12 #ifndef _FS_PT_LDM_H_
13 #define _FS_PT_LDM_H_
14 
15 #include <linux/types.h>
16 #include <linux/list.h>
17 #include <linux/fs.h>
18 #include <asm/unaligned.h>
19 #include <asm/byteorder.h>
20 
21 struct parsed_partitions;
22 
23 /* Magic numbers in CPU format. */
24 #define MAGIC_VMDB	0x564D4442		/* VMDB */
25 #define MAGIC_VBLK	0x56424C4B		/* VBLK */
26 #define MAGIC_PRIVHEAD	0x5052495648454144ULL	/* PRIVHEAD */
27 #define MAGIC_TOCBLOCK	0x544F43424C4F434BULL	/* TOCBLOCK */
28 
29 /* The defined vblk types. */
30 #define VBLK_VOL5		0x51		/* Volume,     version 5 */
31 #define VBLK_CMP3		0x32		/* Component,  version 3 */
32 #define VBLK_PRT3		0x33		/* Partition,  version 3 */
33 #define VBLK_DSK3		0x34		/* Disk,       version 3 */
34 #define VBLK_DSK4		0x44		/* Disk,       version 4 */
35 #define VBLK_DGR3		0x35		/* Disk Group, version 3 */
36 #define VBLK_DGR4		0x45		/* Disk Group, version 4 */
37 
38 /* vblk flags indicating extra information will be present */
39 #define	VBLK_FLAG_COMP_STRIPE	0x10
40 #define	VBLK_FLAG_PART_INDEX	0x08
41 #define	VBLK_FLAG_DGR3_IDS	0x08
42 #define	VBLK_FLAG_DGR4_IDS	0x08
43 #define	VBLK_FLAG_VOLU_ID1	0x08
44 #define	VBLK_FLAG_VOLU_ID2	0x20
45 #define	VBLK_FLAG_VOLU_SIZE	0x80
46 #define	VBLK_FLAG_VOLU_DRIVE	0x02
47 
48 /* size of a vblk's static parts */
49 #define VBLK_SIZE_HEAD		16
50 #define VBLK_SIZE_CMP3		22		/* Name and version */
51 #define VBLK_SIZE_DGR3		12
52 #define VBLK_SIZE_DGR4		44
53 #define VBLK_SIZE_DSK3		12
54 #define VBLK_SIZE_DSK4		45
55 #define VBLK_SIZE_PRT3		28
56 #define VBLK_SIZE_VOL5		58
57 
58 /* component types */
59 #define COMP_STRIPE		0x01		/* Stripe-set */
60 #define COMP_BASIC		0x02		/* Basic disk */
61 #define COMP_RAID		0x03		/* Raid-set */
62 
63 /* Other constants. */
64 #define LDM_DB_SIZE		2048		/* Size in sectors (= 1MiB). */
65 
66 #define OFF_PRIV1		6		/* Offset of the first privhead
67 						   relative to the start of the
68 						   device in sectors */
69 
70 /* Offsets to structures within the LDM Database in sectors. */
71 #define OFF_PRIV2		1856		/* Backup private headers. */
72 #define OFF_PRIV3		2047
73 
74 #define OFF_TOCB1		1		/* Tables of contents. */
75 #define OFF_TOCB2		2
76 #define OFF_TOCB3		2045
77 #define OFF_TOCB4		2046
78 
79 #define OFF_VMDB		17		/* List of partitions. */
80 
81 #define LDM_PARTITION		0x42		/* Formerly SFS (Landis). */
82 
83 #define TOC_BITMAP1		"config"	/* Names of the two defined */
84 #define TOC_BITMAP2		"log"		/* bitmaps in the TOCBLOCK. */
85 
86 struct frag {				/* VBLK Fragment handling */
87 	struct list_head list;
88 	u32		group;
89 	u8		num;		/* Total number of records */
90 	u8		rec;		/* This is record number n */
91 	u8		map;		/* Which portions are in use */
92 	u8		data[];
93 };
94 
95 /* In memory LDM database structures. */
96 
97 struct privhead {			/* Offsets and sizes are in sectors. */
98 	u16	ver_major;
99 	u16	ver_minor;
100 	u64	logical_disk_start;
101 	u64	logical_disk_size;
102 	u64	config_start;
103 	u64	config_size;
104 	uuid_t	disk_id;
105 };
106 
107 struct tocblock {			/* We have exactly two bitmaps. */
108 	u8	bitmap1_name[16];
109 	u64	bitmap1_start;
110 	u64	bitmap1_size;
111 	u8	bitmap2_name[16];
112 	u64	bitmap2_start;
113 	u64	bitmap2_size;
114 };
115 
116 struct vmdb {				/* VMDB: The database header */
117 	u16	ver_major;
118 	u16	ver_minor;
119 	u32	vblk_size;
120 	u32	vblk_offset;
121 	u32	last_vblk_seq;
122 };
123 
124 struct vblk_comp {			/* VBLK Component */
125 	u8	state[16];
126 	u64	parent_id;
127 	u8	type;
128 	u8	children;
129 	u16	chunksize;
130 };
131 
132 struct vblk_dgrp {			/* VBLK Disk Group */
133 	u8	disk_id[64];
134 };
135 
136 struct vblk_disk {			/* VBLK Disk */
137 	uuid_t	disk_id;
138 	u8	alt_name[128];
139 };
140 
141 struct vblk_part {			/* VBLK Partition */
142 	u64	start;
143 	u64	size;			/* start, size and vol_off in sectors */
144 	u64	volume_offset;
145 	u64	parent_id;
146 	u64	disk_id;
147 	u8	partnum;
148 };
149 
150 struct vblk_volu {			/* VBLK Volume */
151 	u8	volume_type[16];
152 	u8	volume_state[16];
153 	u8	guid[16];
154 	u8	drive_hint[4];
155 	u64	size;
156 	u8	partition_type;
157 };
158 
159 struct vblk_head {			/* VBLK standard header */
160 	u32 group;
161 	u16 rec;
162 	u16 nrec;
163 };
164 
165 struct vblk {				/* Generalised VBLK */
166 	u8	name[64];
167 	u64	obj_id;
168 	u32	sequence;
169 	u8	flags;
170 	u8	type;
171 	union {
172 		struct vblk_comp comp;
173 		struct vblk_dgrp dgrp;
174 		struct vblk_disk disk;
175 		struct vblk_part part;
176 		struct vblk_volu volu;
177 	} vblk;
178 	struct list_head list;
179 };
180 
181 struct ldmdb {				/* Cache of the database */
182 	struct privhead ph;
183 	struct tocblock toc;
184 	struct vmdb     vm;
185 	struct list_head v_dgrp;
186 	struct list_head v_disk;
187 	struct list_head v_volu;
188 	struct list_head v_comp;
189 	struct list_head v_part;
190 };
191 
192 #endif /* _FS_PT_LDM_H_ */
193 
194