Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / lib / format1 / lvm1-label.c
blob1b9f244863173b83ddfd6c80a852ba65a0669a28
1 /* $NetBSD$ */
3 /*
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
18 #include "lib.h"
19 #include "lvm1-label.h"
20 #include "disk-rep.h"
21 #include "label.h"
22 #include "metadata.h"
23 #include "xlate.h"
24 #include "format1.h"
26 #include <sys/stat.h>
27 #include <fcntl.h>
29 static void _not_supported(const char *op)
31 log_error("The '%s' operation is not supported for the lvm1 labeller.",
32 op);
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;
38 uint32_t version;
40 /* LVM1 label must always be in first sector */
41 if (sector)
42 return 0;
44 version = xlate16(pvd->version);
46 if (pvd->id[0] == 'H' && pvd->id[1] == 'M' &&
47 (version == 1 || version == 2))
48 return 1;
50 return 0;
53 static int _lvm1_write(struct label *label __attribute((unused)), void *buf __attribute((unused)))
55 _not_supported("write");
56 return 0;
59 static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
60 struct label **label)
62 struct pv_disk *pvd = (struct pv_disk *) buf;
63 struct vg_disk vgd;
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;
69 munge_pvd(dev, pvd);
71 if (*pvd->vg_name) {
72 if (!read_vgd(dev, &vgd, pvd))
73 return_0;
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,
80 exported)))
81 return_0;
82 *label = info->label;
84 info->device_size = xlate32(pvd->pv_size) << SECTOR_SHIFT;
85 dm_list_init(&info->mdas);
87 info->status &= ~CACHE_INVALID;
89 return 1;
92 static int _lvm1_initialise_label(struct labeller *l __attribute((unused)), struct label *label)
94 strcpy(label->type, "LVM1");
96 return 1;
99 static void _lvm1_destroy_label(struct labeller *l __attribute((unused)), struct label *label __attribute((unused)))
101 return;
104 static void _lvm1_destroy(struct labeller *l)
106 dm_free(l);
109 struct label_ops _lvm1_ops = {
110 .can_handle = _lvm1_can_handle,
111 .write = _lvm1_write,
112 .read = _lvm1_read,
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)
121 struct labeller *l;
123 if (!(l = dm_malloc(sizeof(*l)))) {
124 log_error("Couldn't allocate labeller object.");
125 return NULL;
128 l->ops = &_lvm1_ops;
129 l->private = (const void *) fmt;
131 return l;