18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/** 38c2ecf20Sopenharmony_ci * ldm - Part of the Linux-NTFS project. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2001,2002 Richard Russon <ldm@flatcap.org> 68c2ecf20Sopenharmony_ci * Copyright (c) 2001-2007 Anton Altaparmakov 78c2ecf20Sopenharmony_ci * Copyright (C) 2001,2002 Jakob Kemi <jakob.kemi@telia.com> 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Documentation is available at http://www.linux-ntfs.org/doku.php?id=downloads 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef _FS_PT_LDM_H_ 138c2ecf20Sopenharmony_ci#define _FS_PT_LDM_H_ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/types.h> 168c2ecf20Sopenharmony_ci#include <linux/list.h> 178c2ecf20Sopenharmony_ci#include <linux/genhd.h> 188c2ecf20Sopenharmony_ci#include <linux/fs.h> 198c2ecf20Sopenharmony_ci#include <asm/unaligned.h> 208c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistruct parsed_partitions; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* Magic numbers in CPU format. */ 258c2ecf20Sopenharmony_ci#define MAGIC_VMDB 0x564D4442 /* VMDB */ 268c2ecf20Sopenharmony_ci#define MAGIC_VBLK 0x56424C4B /* VBLK */ 278c2ecf20Sopenharmony_ci#define MAGIC_PRIVHEAD 0x5052495648454144ULL /* PRIVHEAD */ 288c2ecf20Sopenharmony_ci#define MAGIC_TOCBLOCK 0x544F43424C4F434BULL /* TOCBLOCK */ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* The defined vblk types. */ 318c2ecf20Sopenharmony_ci#define VBLK_VOL5 0x51 /* Volume, version 5 */ 328c2ecf20Sopenharmony_ci#define VBLK_CMP3 0x32 /* Component, version 3 */ 338c2ecf20Sopenharmony_ci#define VBLK_PRT3 0x33 /* Partition, version 3 */ 348c2ecf20Sopenharmony_ci#define VBLK_DSK3 0x34 /* Disk, version 3 */ 358c2ecf20Sopenharmony_ci#define VBLK_DSK4 0x44 /* Disk, version 4 */ 368c2ecf20Sopenharmony_ci#define VBLK_DGR3 0x35 /* Disk Group, version 3 */ 378c2ecf20Sopenharmony_ci#define VBLK_DGR4 0x45 /* Disk Group, version 4 */ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* vblk flags indicating extra information will be present */ 408c2ecf20Sopenharmony_ci#define VBLK_FLAG_COMP_STRIPE 0x10 418c2ecf20Sopenharmony_ci#define VBLK_FLAG_PART_INDEX 0x08 428c2ecf20Sopenharmony_ci#define VBLK_FLAG_DGR3_IDS 0x08 438c2ecf20Sopenharmony_ci#define VBLK_FLAG_DGR4_IDS 0x08 448c2ecf20Sopenharmony_ci#define VBLK_FLAG_VOLU_ID1 0x08 458c2ecf20Sopenharmony_ci#define VBLK_FLAG_VOLU_ID2 0x20 468c2ecf20Sopenharmony_ci#define VBLK_FLAG_VOLU_SIZE 0x80 478c2ecf20Sopenharmony_ci#define VBLK_FLAG_VOLU_DRIVE 0x02 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* size of a vblk's static parts */ 508c2ecf20Sopenharmony_ci#define VBLK_SIZE_HEAD 16 518c2ecf20Sopenharmony_ci#define VBLK_SIZE_CMP3 22 /* Name and version */ 528c2ecf20Sopenharmony_ci#define VBLK_SIZE_DGR3 12 538c2ecf20Sopenharmony_ci#define VBLK_SIZE_DGR4 44 548c2ecf20Sopenharmony_ci#define VBLK_SIZE_DSK3 12 558c2ecf20Sopenharmony_ci#define VBLK_SIZE_DSK4 45 568c2ecf20Sopenharmony_ci#define VBLK_SIZE_PRT3 28 578c2ecf20Sopenharmony_ci#define VBLK_SIZE_VOL5 58 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* component types */ 608c2ecf20Sopenharmony_ci#define COMP_STRIPE 0x01 /* Stripe-set */ 618c2ecf20Sopenharmony_ci#define COMP_BASIC 0x02 /* Basic disk */ 628c2ecf20Sopenharmony_ci#define COMP_RAID 0x03 /* Raid-set */ 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* Other constants. */ 658c2ecf20Sopenharmony_ci#define LDM_DB_SIZE 2048 /* Size in sectors (= 1MiB). */ 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define OFF_PRIV1 6 /* Offset of the first privhead 688c2ecf20Sopenharmony_ci relative to the start of the 698c2ecf20Sopenharmony_ci device in sectors */ 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/* Offsets to structures within the LDM Database in sectors. */ 728c2ecf20Sopenharmony_ci#define OFF_PRIV2 1856 /* Backup private headers. */ 738c2ecf20Sopenharmony_ci#define OFF_PRIV3 2047 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define OFF_TOCB1 1 /* Tables of contents. */ 768c2ecf20Sopenharmony_ci#define OFF_TOCB2 2 778c2ecf20Sopenharmony_ci#define OFF_TOCB3 2045 788c2ecf20Sopenharmony_ci#define OFF_TOCB4 2046 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci#define OFF_VMDB 17 /* List of partitions. */ 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#define LDM_PARTITION 0x42 /* Formerly SFS (Landis). */ 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#define TOC_BITMAP1 "config" /* Names of the two defined */ 858c2ecf20Sopenharmony_ci#define TOC_BITMAP2 "log" /* bitmaps in the TOCBLOCK. */ 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistruct frag { /* VBLK Fragment handling */ 888c2ecf20Sopenharmony_ci struct list_head list; 898c2ecf20Sopenharmony_ci u32 group; 908c2ecf20Sopenharmony_ci u8 num; /* Total number of records */ 918c2ecf20Sopenharmony_ci u8 rec; /* This is record number n */ 928c2ecf20Sopenharmony_ci u8 map; /* Which portions are in use */ 938c2ecf20Sopenharmony_ci u8 data[]; 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* In memory LDM database structures. */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistruct privhead { /* Offsets and sizes are in sectors. */ 998c2ecf20Sopenharmony_ci u16 ver_major; 1008c2ecf20Sopenharmony_ci u16 ver_minor; 1018c2ecf20Sopenharmony_ci u64 logical_disk_start; 1028c2ecf20Sopenharmony_ci u64 logical_disk_size; 1038c2ecf20Sopenharmony_ci u64 config_start; 1048c2ecf20Sopenharmony_ci u64 config_size; 1058c2ecf20Sopenharmony_ci uuid_t disk_id; 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistruct tocblock { /* We have exactly two bitmaps. */ 1098c2ecf20Sopenharmony_ci u8 bitmap1_name[16]; 1108c2ecf20Sopenharmony_ci u64 bitmap1_start; 1118c2ecf20Sopenharmony_ci u64 bitmap1_size; 1128c2ecf20Sopenharmony_ci u8 bitmap2_name[16]; 1138c2ecf20Sopenharmony_ci u64 bitmap2_start; 1148c2ecf20Sopenharmony_ci u64 bitmap2_size; 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistruct vmdb { /* VMDB: The database header */ 1188c2ecf20Sopenharmony_ci u16 ver_major; 1198c2ecf20Sopenharmony_ci u16 ver_minor; 1208c2ecf20Sopenharmony_ci u32 vblk_size; 1218c2ecf20Sopenharmony_ci u32 vblk_offset; 1228c2ecf20Sopenharmony_ci u32 last_vblk_seq; 1238c2ecf20Sopenharmony_ci}; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistruct vblk_comp { /* VBLK Component */ 1268c2ecf20Sopenharmony_ci u8 state[16]; 1278c2ecf20Sopenharmony_ci u64 parent_id; 1288c2ecf20Sopenharmony_ci u8 type; 1298c2ecf20Sopenharmony_ci u8 children; 1308c2ecf20Sopenharmony_ci u16 chunksize; 1318c2ecf20Sopenharmony_ci}; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistruct vblk_dgrp { /* VBLK Disk Group */ 1348c2ecf20Sopenharmony_ci u8 disk_id[64]; 1358c2ecf20Sopenharmony_ci}; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistruct vblk_disk { /* VBLK Disk */ 1388c2ecf20Sopenharmony_ci uuid_t disk_id; 1398c2ecf20Sopenharmony_ci u8 alt_name[128]; 1408c2ecf20Sopenharmony_ci}; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_cistruct vblk_part { /* VBLK Partition */ 1438c2ecf20Sopenharmony_ci u64 start; 1448c2ecf20Sopenharmony_ci u64 size; /* start, size and vol_off in sectors */ 1458c2ecf20Sopenharmony_ci u64 volume_offset; 1468c2ecf20Sopenharmony_ci u64 parent_id; 1478c2ecf20Sopenharmony_ci u64 disk_id; 1488c2ecf20Sopenharmony_ci u8 partnum; 1498c2ecf20Sopenharmony_ci}; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistruct vblk_volu { /* VBLK Volume */ 1528c2ecf20Sopenharmony_ci u8 volume_type[16]; 1538c2ecf20Sopenharmony_ci u8 volume_state[16]; 1548c2ecf20Sopenharmony_ci u8 guid[16]; 1558c2ecf20Sopenharmony_ci u8 drive_hint[4]; 1568c2ecf20Sopenharmony_ci u64 size; 1578c2ecf20Sopenharmony_ci u8 partition_type; 1588c2ecf20Sopenharmony_ci}; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cistruct vblk_head { /* VBLK standard header */ 1618c2ecf20Sopenharmony_ci u32 group; 1628c2ecf20Sopenharmony_ci u16 rec; 1638c2ecf20Sopenharmony_ci u16 nrec; 1648c2ecf20Sopenharmony_ci}; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cistruct vblk { /* Generalised VBLK */ 1678c2ecf20Sopenharmony_ci u8 name[64]; 1688c2ecf20Sopenharmony_ci u64 obj_id; 1698c2ecf20Sopenharmony_ci u32 sequence; 1708c2ecf20Sopenharmony_ci u8 flags; 1718c2ecf20Sopenharmony_ci u8 type; 1728c2ecf20Sopenharmony_ci union { 1738c2ecf20Sopenharmony_ci struct vblk_comp comp; 1748c2ecf20Sopenharmony_ci struct vblk_dgrp dgrp; 1758c2ecf20Sopenharmony_ci struct vblk_disk disk; 1768c2ecf20Sopenharmony_ci struct vblk_part part; 1778c2ecf20Sopenharmony_ci struct vblk_volu volu; 1788c2ecf20Sopenharmony_ci } vblk; 1798c2ecf20Sopenharmony_ci struct list_head list; 1808c2ecf20Sopenharmony_ci}; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cistruct ldmdb { /* Cache of the database */ 1838c2ecf20Sopenharmony_ci struct privhead ph; 1848c2ecf20Sopenharmony_ci struct tocblock toc; 1858c2ecf20Sopenharmony_ci struct vmdb vm; 1868c2ecf20Sopenharmony_ci struct list_head v_dgrp; 1878c2ecf20Sopenharmony_ci struct list_head v_disk; 1888c2ecf20Sopenharmony_ci struct list_head v_volu; 1898c2ecf20Sopenharmony_ci struct list_head v_comp; 1908c2ecf20Sopenharmony_ci struct list_head v_part; 1918c2ecf20Sopenharmony_ci}; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#endif /* _FS_PT_LDM_H_ */ 1948c2ecf20Sopenharmony_ci 195