1 /*        $NetBSD: label.h,v 1.1.1.1 2008/12/22 00:18:02 haad Exp $   */
2 
3 /*
4  * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
5  * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
6  *
7  * This file is part of LVM2.
8  *
9  * This copyrighted material is made available to anyone wishing to use,
10  * modify, copy, or redistribute it subject to the terms and conditions
11  * of the GNU Lesser General Public License v.2.1.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17 
18 #ifndef _LVM_LABEL_H
19 #define _LVM_LABEL_H
20 
21 #include "uuid.h"
22 #include "device.h"
23 
24 #define LABEL_ID "LABELONE"
25 #define LABEL_SIZE SECTOR_SIZE          /* Think very carefully before changing this */
26 #define LABEL_SCAN_SECTORS 4L
27 #define LABEL_SCAN_SIZE (LABEL_SCAN_SECTORS << SECTOR_SHIFT)
28 
29 struct labeller;
30 
31 /* On disk - 32 bytes */
32 struct label_header {
33           int8_t id[8];                 /* LABELONE */
34           uint64_t sector_xl; /* Sector number of this label */
35           uint32_t crc_xl;    /* From next field to end of sector */
36           uint32_t offset_xl; /* Offset from start of struct to contents */
37           int8_t type[8];               /* LVM2 001 */
38 } __attribute__ ((packed));
39 
40 /* In core */
41 struct label {
42           char type[8];
43           uint64_t sector;
44           struct labeller *labeller;
45           void *info;
46 };
47 
48 struct labeller;
49 
50 struct label_ops {
51           /*
52            * Is the device labelled with this format ?
53            */
54           int (*can_handle) (struct labeller * l, void *buf, uint64_t sector);
55 
56           /*
57            * Write a label to a volume.
58            */
59           int (*write) (struct label * label, void *buf);
60 
61           /*
62            * Read a label from a volume.
63            */
64           int (*read) (struct labeller * l, struct device * dev,
65                          void *buf, struct label ** label);
66 
67           /*
68            * Additional consistency checks for the paranoid.
69            */
70           int (*verify) (struct labeller * l, void *buf, uint64_t sector);
71 
72           /*
73            * Populate label_type etc.
74            */
75           int (*initialise_label) (struct labeller * l, struct label * label);
76 
77           /*
78            * Destroy a previously read label.
79            */
80           void (*destroy_label) (struct labeller * l, struct label * label);
81 
82           /*
83            * Destructor.
84            */
85           void (*destroy) (struct labeller * l);
86 };
87 
88 struct labeller {
89           struct label_ops *ops;
90           const void *private;
91 };
92 
93 int label_init(void);
94 void label_exit(void);
95 
96 int label_register_handler(const char *name, struct labeller *handler);
97 
98 struct labeller *label_get_handler(const char *name);
99 
100 int label_remove(struct device *dev);
101 int label_read(struct device *dev, struct label **result,
102                     uint64_t scan_sector);
103 int label_write(struct device *dev, struct label *label);
104 int label_verify(struct device *dev);
105 struct label *label_create(struct labeller *labeller);
106 void label_destroy(struct label *label);
107 
108 #endif
109