Tizen 2.1 base
[external/device-mapper.git] / lib / label / label.h
1 /*
2  * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.  
3  * Copyright (C) 2004-2007 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_LABEL_H
17 #define _LVM_LABEL_H
18
19 #include "uuid.h"
20 #include "device.h"
21
22 #define LABEL_ID "LABELONE"
23 #define LABEL_SIZE SECTOR_SIZE  /* Think very carefully before changing this */
24 #define LABEL_SCAN_SECTORS 4L
25 #define LABEL_SCAN_SIZE (LABEL_SCAN_SECTORS << SECTOR_SHIFT)
26
27 struct labeller;
28
29 /* On disk - 32 bytes */
30 struct label_header {
31         int8_t id[8];           /* LABELONE */
32         uint64_t sector_xl;     /* Sector number of this label */
33         uint32_t crc_xl;        /* From next field to end of sector */
34         uint32_t offset_xl;     /* Offset from start of struct to contents */
35         int8_t type[8];         /* LVM2 001 */
36 } __attribute__ ((packed));
37
38 /* In core */
39 struct label {
40         char type[8];
41         uint64_t sector;
42         struct labeller *labeller;
43         void *info;
44 };
45
46 struct labeller;
47
48 struct label_ops {
49         /*
50          * Is the device labelled with this format ?
51          */
52         int (*can_handle) (struct labeller * l, void *buf, uint64_t sector);
53
54         /*
55          * Write a label to a volume.
56          */
57         int (*write) (struct label * label, void *buf);
58
59         /*
60          * Read a label from a volume.
61          */
62         int (*read) (struct labeller * l, struct device * dev,
63                      void *buf, struct label ** label);
64
65         /*
66          * Additional consistency checks for the paranoid.
67          */
68         int (*verify) (struct labeller * l, void *buf, uint64_t sector);
69
70         /*
71          * Populate label_type etc.
72          */
73         int (*initialise_label) (struct labeller * l, struct label * label);
74
75         /*
76          * Destroy a previously read label.
77          */
78         void (*destroy_label) (struct labeller * l, struct label * label);
79
80         /*
81          * Destructor.
82          */
83         void (*destroy) (struct labeller * l);
84 };
85
86 struct labeller {
87         struct label_ops *ops;
88         const void *private;
89 };
90
91 int label_init(void);
92 void label_exit(void);
93
94 int label_register_handler(const char *name, struct labeller *handler);
95
96 struct labeller *label_get_handler(const char *name);
97
98 int label_remove(struct device *dev);
99 int label_read(struct device *dev, struct label **result,
100                 uint64_t scan_sector);
101 int label_write(struct device *dev, struct label *label);
102 int label_verify(struct device *dev);
103 struct label *label_create(struct labeller *labeller);
104 void label_destroy(struct label *label);
105
106 #endif