1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/lib/format1/lvm1-label.c

129 lines
2.9 KiB
C
Raw Normal View History

2002-11-18 17:01:16 +03:00
/*
2004-03-30 23:35:44 +04:00
* Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
2002-11-18 17:01:16 +03:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
2004-03-30 23:35:44 +04:00
*
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2002-11-18 17:01:16 +03:00
*/
#include "lib.h"
#include "lvm1-label.h"
#include "disk-rep.h"
#include "label.h"
#include "metadata.h"
#include "xlate.h"
#include "lvmcache.h"
2002-11-18 17:01:16 +03:00
#include <sys/stat.h>
#include <fcntl.h>
static void _not_supported(const char *op)
{
log_err("The '%s' operation is not supported for the lvm1 labeller.",
op);
}
static int _lvm1_can_handle(struct labeller *l __attribute((unused)), void *buf, uint64_t sector)
2002-11-18 17:01:16 +03:00
{
struct pv_disk *pvd = (struct pv_disk *) buf;
uint32_t version;
/* LVM1 label must always be in first sector */
if (sector)
return 0;
version = xlate16(pvd->version);
if (pvd->id[0] == 'H' && pvd->id[1] == 'M' &&
(version == 1 || version == 2))
return 1;
return 0;
}
static int _lvm1_write(struct label *label __attribute((unused)), void *buf __attribute((unused)))
2002-11-18 17:01:16 +03:00
{
_not_supported("write");
return 0;
}
static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
2002-11-18 17:01:16 +03:00
struct label **label)
{
struct pv_disk *pvd = (struct pv_disk *) buf;
2006-04-11 02:09:00 +04:00
struct vg_disk vgd;
struct lvmcache_info *info;
2006-04-11 02:09:00 +04:00
const char *vgid = NULL;
unsigned exported = 0;
2002-11-18 17:01:16 +03:00
munge_pvd(dev, pvd);
if (*pvd->vg_name && read_vgd(dev, &vgd, pvd)) {
vgid = (char *) vgd.vg_uuid;
exported = pvd->pv_status & VG_EXPORTED;
}
2006-04-11 02:09:00 +04:00
if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, (char *)pvd->vg_name, vgid,
exported))) {
2003-08-20 19:48:27 +04:00
stack;
2002-11-18 17:01:16 +03:00
return 0;
2003-08-20 19:48:27 +04:00
}
2002-11-18 17:01:16 +03:00
*label = info->label;
info->device_size = xlate32(pvd->pv_size) << SECTOR_SHIFT;
list_init(&info->mdas);
info->status &= ~CACHE_INVALID;
return 1;
}
static int _lvm1_initialise_label(struct labeller *l __attribute((unused)), struct label *label)
2002-11-18 17:01:16 +03:00
{
strcpy(label->type, "LVM1");
return 1;
}
static void _lvm1_destroy_label(struct labeller *l __attribute((unused)), struct label *label __attribute((unused)))
2002-11-18 17:01:16 +03:00
{
return;
}
static void _lvm1_destroy(struct labeller *l)
2002-11-18 17:01:16 +03:00
{
dm_free(l);
2002-11-18 17:01:16 +03:00
}
struct label_ops _lvm1_ops = {
.can_handle = _lvm1_can_handle,
.write = _lvm1_write,
.read = _lvm1_read,
.verify = _lvm1_can_handle,
.initialise_label = _lvm1_initialise_label,
.destroy_label = _lvm1_destroy_label,
.destroy = _lvm1_destroy,
2002-11-18 17:01:16 +03:00
};
struct labeller *lvm1_labeller_create(struct format_type *fmt)
{
struct labeller *l;
if (!(l = dm_malloc(sizeof(*l)))) {
2002-11-18 17:01:16 +03:00
log_err("Couldn't allocate labeller object.");
return NULL;
}
l->ops = &_lvm1_ops;
l->private = (const void *) fmt;
2002-11-18 17:01:16 +03:00
return l;
}