1 /* $NetBSD: lvm1-label.c,v 1.1.1.2 2009/12/02 00:26:49 haad Exp $ */
4 * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
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.
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
19 #include "lvm1-label.h"
29 static void _not_supported(const char *op)
31 log_error("The '%s' operation is not supported for the lvm1 labeller.",
35 static int _lvm1_can_handle(struct labeller *l __attribute((unused)), void *buf, uint64_t sector)
37 struct pv_disk *pvd = (struct pv_disk *) buf;
40 /* LVM1 label must always be in first sector */
44 version = xlate16(pvd->version);
46 if (pvd->id[0] == 'H' && pvd->id[1] == 'M' &&
47 (version == 1 || version == 2))
53 static int _lvm1_write(struct label *label __attribute((unused)), void *buf __attribute((unused)))
55 _not_supported("write");
59 static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
62 struct pv_disk *pvd = (struct pv_disk *) buf;
64 struct lvmcache_info *info;
65 const char *vgid = FMT_LVM1_ORPHAN_VG_NAME;
66 const char *vgname = FMT_LVM1_ORPHAN_VG_NAME;
67 unsigned exported = 0;
72 if (!read_vgd(dev, &vgd, pvd))
74 vgid = (char *) vgd.vg_uuid;
75 vgname = (char *) pvd->vg_name;
76 exported = pvd->pv_status & VG_EXPORTED;
79 if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, vgname, vgid,
84 info->device_size = xlate32(pvd->pv_size) << SECTOR_SHIFT;
85 dm_list_init(&info->mdas);
87 info->status &= ~CACHE_INVALID;
92 static int _lvm1_initialise_label(struct labeller *l __attribute((unused)), struct label *label)
94 strcpy(label->type, "LVM1");
99 static void _lvm1_destroy_label(struct labeller *l __attribute((unused)), struct label *label __attribute((unused)))
104 static void _lvm1_destroy(struct labeller *l)
109 struct label_ops _lvm1_ops = {
110 .can_handle = _lvm1_can_handle,
111 .write = _lvm1_write,
113 .verify = _lvm1_can_handle,
114 .initialise_label = _lvm1_initialise_label,
115 .destroy_label = _lvm1_destroy_label,
116 .destroy = _lvm1_destroy,
119 struct labeller *lvm1_labeller_create(struct format_type *fmt)
123 if (!(l = dm_malloc(sizeof(*l)))) {
124 log_error("Couldn't allocate labeller object.");
129 l->private = (const void *) fmt;