Tizen 2.1 base
[external/device-mapper.git] / lib / format_text / layout.h
1 /*
2  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
3  * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4  *
5  * This file is part of LVM2.
6  *
7  * This copyrighted material is made available to anyone wishing to use,
8  * modify, copy, or redistribute it subject to the terms and conditions
9  * of the GNU Lesser General Public License v.2.1.
10  *
11  * You should have received a copy of the GNU Lesser General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14  */
15
16 #ifndef _LVM_TEXT_LAYOUT_H
17 #define _LVM_TEXT_LAYOUT_H
18
19 #include "config.h"
20 #include "lvm-types.h"
21 #include "metadata.h"
22 #include "uuid.h"
23
24 /* On disk */
25 struct disk_locn {
26         uint64_t offset;        /* Offset in bytes to start sector */
27         uint64_t size;          /* Bytes */
28 } __attribute__ ((packed));
29
30 /* Data areas (holding PEs) */
31 struct data_area_list {
32         struct dm_list list;
33         struct disk_locn disk_locn;
34 };
35
36 /* Fields with the suffix _xl should be xlate'd wherever they appear */
37 /* On disk */
38 struct pv_header {
39         int8_t pv_uuid[ID_LEN];
40
41         /* This size can be overridden if PV belongs to a VG */
42         uint64_t device_size_xl;        /* Bytes */
43
44         /* NULL-terminated list of data areas followed by */
45         /* NULL-terminated list of metadata area headers */
46         struct disk_locn disk_areas_xl[0];      /* Two lists */
47 } __attribute__ ((packed));
48
49 /*
50  * Ignore this raw location.  This allows us to
51  * ignored metadata areas easily, and thus balance
52  * metadata across VGs with many PVs.
53  */
54 #define RAW_LOCN_IGNORED 0x00000001
55
56 /* On disk */
57 struct raw_locn {
58         uint64_t offset;        /* Offset in bytes to start sector */
59         uint64_t size;          /* Bytes */
60         uint32_t checksum;
61         uint32_t flags;
62 } __attribute__ ((packed));
63
64 int rlocn_is_ignored(const struct raw_locn *rlocn);
65 void rlocn_set_ignored(struct raw_locn *rlocn, unsigned mda_ignored);
66
67 /* On disk */
68 /* Structure size limited to one sector */
69 struct mda_header {
70         uint32_t checksum_xl;   /* Checksum of rest of mda_header */
71         int8_t magic[16];       /* To aid scans for metadata */
72         uint32_t version;
73         uint64_t start;         /* Absolute start byte of mda_header */
74         uint64_t size;          /* Size of metadata area */
75
76         struct raw_locn raw_locns[0];   /* NULL-terminated list */
77 } __attribute__ ((packed));
78
79 struct mda_header *raw_read_mda_header(const struct format_type *fmt,
80                                        struct device_area *dev_area);
81
82 struct mda_lists {
83         struct dm_list dirs;
84         struct dm_list raws;
85         struct metadata_area_ops *file_ops;
86         struct metadata_area_ops *raw_ops;
87 };
88
89 struct mda_context {
90         struct device_area area;
91         uint64_t free_sectors;
92         struct raw_locn rlocn;  /* Store inbetween write and commit */
93 };
94
95 /* FIXME Convert this at runtime */
96 #define FMTT_MAGIC "\040\114\126\115\062\040\170\133\065\101\045\162\060\116\052\076"
97 #define FMTT_VERSION 1
98 #define MDA_HEADER_SIZE 512
99 #define LVM2_LABEL "LVM2 001"
100 #define MDA_SIZE_MIN (8 * (unsigned) lvm_getpagesize())
101
102
103 const char *vgname_from_mda(const struct format_type *fmt,
104                             struct mda_header *mdah,
105                             struct device_area *dev_area, struct id *vgid,
106                             uint64_t *vgstatus, char **creation_host,
107                             uint64_t *mda_free_sectors);
108
109 #endif