2 * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
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.
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
17 #include "lvm1-label.h"
27 static void _not_supported(const char *op)
29 log_error("The '%s' operation is not supported for the lvm1 labeller.",
33 static int _lvm1_can_handle(struct labeller *l __attribute__((unused)), void *buf, uint64_t sector)
35 struct pv_disk *pvd = (struct pv_disk *) buf;
38 /* LVM1 label must always be in first sector */
42 version = xlate16(pvd->version);
44 if (pvd->id[0] == 'H' && pvd->id[1] == 'M' &&
45 (version == 1 || version == 2))
51 static int _lvm1_write(struct label *label __attribute__((unused)), void *buf __attribute__((unused)))
53 _not_supported("write");
57 static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
60 struct pv_disk *pvd = (struct pv_disk *) buf;
62 struct lvmcache_info *info;
63 const char *vgid = FMT_LVM1_ORPHAN_VG_NAME;
64 const char *vgname = FMT_LVM1_ORPHAN_VG_NAME;
65 unsigned exported = 0;
70 if (!read_vgd(dev, &vgd, pvd))
72 vgid = (char *) vgd.vg_uuid;
73 vgname = (char *) pvd->vg_name;
74 exported = pvd->pv_status & VG_EXPORTED;
77 if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, vgname, vgid,
82 info->device_size = xlate32(pvd->pv_size) << SECTOR_SHIFT;
83 dm_list_init(&info->mdas);
85 info->status &= ~CACHE_INVALID;
90 static int _lvm1_initialise_label(struct labeller *l __attribute__((unused)), struct label *label)
92 strcpy(label->type, "LVM1");
97 static void _lvm1_destroy_label(struct labeller *l __attribute__((unused)), struct label *label __attribute__((unused)))
101 static void _lvm1_destroy(struct labeller *l)
106 struct label_ops _lvm1_ops = {
107 .can_handle = _lvm1_can_handle,
108 .write = _lvm1_write,
110 .verify = _lvm1_can_handle,
111 .initialise_label = _lvm1_initialise_label,
112 .destroy_label = _lvm1_destroy_label,
113 .destroy = _lvm1_destroy,
116 struct labeller *lvm1_labeller_create(struct format_type *fmt)
120 if (!(l = dm_malloc(sizeof(*l)))) {
121 log_error("Couldn't allocate labeller object.");
126 l->private = (const void *) fmt;