-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathlvm.h
154 lines (132 loc) · 4.44 KB
/
lvm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* Ext2read
* File: lvm.h
**/
/**
* Copyright (C) 2006 2010 by Manish Regmi (regmi dot manish at gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**/
#ifndef __LVM_H
#define __LVM_H
#include <stdint.h>
#include <QString>
#include "ext2read.h"
#define LVM_SIGLEN 8
#define LVM_MAGIC_LEN 8
#define UUID_LEN 32
/* Structure to hold Physical Volumes (PV) label*/
typedef struct pv_label_header {
char pv_name[LVM_SIGLEN]; // Physical volume signature
uint64_t pv_sector_xl; // sector number of this label
uint32_t pv_crc; // CRC value
uint32_t pv_offset_xl; // Offset from start of struct to contents
char pv_vermagic[LVM_MAGIC_LEN]; // Physical Volume version "LVM2 001"
char pv_uuid[UUID_LEN];
uint64_t pv_unknown1[5]; // documentation lacks for lvm
uint64_t pv_labeloffset; // location of the label
} __attribute__ ((__packed__)) PV_LABEL_HEADER;
typedef struct pv_label {
uint32_t pv_magic;
char pv_sig[4]; // signature
uint64_t unknown1[2];
uint64_t pv_offset_low;
uint64_t unknown2;
uint64_t pv_offset_high;
uint64_t pv_length;
} __attribute__ ((__packed__)) PV_LABEL;
class VolumeGroup;
class LVM {
private:
FileHandle pv_handle;
lloff_t pv_offset;
char uuid[UUID_LEN + 1];
QString pv_metadata;
Ext2Read *ext2read;
public:
LVM(FileHandle handle, lloff_t offset, Ext2Read *rd);
~LVM();
int scan_pv();
int parse_metadata();
VolumeGroup *find_volgroup(QString &uuid);
VolumeGroup *add_volgroup(QString &uuid, QString &name, int seq, int size);
};
class PhysicalVolume {
public:
lloff_t dev_size;
FileHandle handle;
uint32_t pe_start, pe_count;
lloff_t offset; // offset from the start of disk to lvm volume
QString uuid;
PhysicalVolume(QString &id, lloff_t devsize, uint32_t start, uint32_t count, FileHandle file, lloff_t dsk_offset);
};
// Multiple stripes NOT Implemented: we only support linear for now.
struct stripe {
int stripe_pv;
uint32_t stripe_start_extent;
};
class lv_segment {
public:
uint32_t start_extent;
uint32_t extent_count;
struct stripe *stripe;
PhysicalVolume *pvolumes;
lv_segment(uint32_t start, uint32_t count)
{
start_extent = start;
extent_count = count;
}
};
class LogicalVolume {
int segment_count;
public:
VolumeGroup *this_group;
QString uuid;
QString volname;
std::list <lv_segment *> segments;
//std::list <PhysicalVolume *> pvolumes;
LogicalVolume(QString &id, int nsegs, QString &vname, VolumeGroup *);
~LogicalVolume();
lloff_t lvm_mapper(lloff_t block);
};
class VolumeGroup {
public:
QString volname;
QString uuid;
int extent_size;
int seqno;
int max_lv, max_pv;
std::list <PhysicalVolume *> pvolumes;
std::list <LogicalVolume *> lvolumes;
Ext2Read *ext2read;
public:
VolumeGroup(QString &id, QString &name, int seq, int size);
~VolumeGroup();
PhysicalVolume *find_physical_volume(QString &id);
PhysicalVolume *add_physical_volume(QString &id, lloff_t devsize, uint32_t start, uint32_t count, FileHandle file, lloff_t dsk_offset);
LogicalVolume *find_logical_volume(QString &id);
LogicalVolume *add_logical_volume(QString &id, int count, QString &vname);
void logical_mount();
void set_ext2read(Ext2Read *ext2) { ext2read = ext2; }
};
#ifdef __cplusplus
extern "C"{
#endif
int scan_lvm(FileHandle handle, lloff_t offset);
#ifdef __cplusplus
}
#endif
#endif // __LVM_H