switch (pvd->version) {
case 1:
- pe_start = (pvd->pe_on_disk.base + pvd->pe_on_disk.size) /
- SECTOR_SIZE;
+ pvd->pe_start = ((pvd->pe_on_disk.base +
+ pvd->pe_on_disk.size) / SECTOR_SIZE);
break;
case 2:
return 1;
}
+static int _check_lv(struct lv_disk *lvd)
+{
+ /* FIXME: add more checks */
+ if (lvd->lv_name[0] == '\0') {
+ log_debug("lv has no name");
+ return 0;
+ }
+
+ return 1;
+}
+
static int _read_lvs(struct disk_list *data)
{
int i;
if (!_read_lv(data->dev, pos, &ll->lv))
fail;
+ if (!_check_lv(&ll->lv))
+ fail;
+
list_add(&ll->list, &data->lvs);
}
}
if (!_munge_formats(&data->pv)) {
- log_very_verbose("Unknown metadata version %d found on %s",
+ log_very_verbose("Unknown metadata version %d found on %s",
data->pv.version, dev->name);
goto bad;
}
{
size_t len = sizeof(struct pe_disk) * data->pv.pe_total;
struct pe_disk *extents = data->extents;
+ unsigned long pos = data->pv.pe_on_disk.base;
_xlate_extents(extents, data->pv.pe_total);
- if (dev_write(data->dev, 0, len, extents) != len)
+ if (dev_write(data->dev, pos, len, extents) != len)
fail;
_xlate_extents(extents, data->pv.pe_total);
*/
static char *_create_lv_name(struct pool *mem, const char *full_name)
{
- const char *ptr = strrchr(full_name, '/') + 1;
+ const char *ptr = strrchr(full_name, '/');
+
+ if (!ptr)
+ ptr = full_name;
+ else
+ ptr++;
+
return pool_strdup(mem, ptr);
}
struct physical_volume *pv, struct pv_disk *pvd)
{
memset(pv, 0, sizeof(*pv));
- memcpy(&pv->id, &pvd->pv_uuid, ID_LEN);
+ memcpy(&pv->id, pvd->pv_uuid, ID_LEN);
pv->dev = dev;
if (!(pv->vg_name = pool_strdup(mem, pvd->vg_name))) {
pvd->id[1] = 'M';
pvd->version = 1;
- memcpy(&pvd->pv_uuid, &pv->id.uuid, ID_LEN);
+ memcpy(pvd->pv_uuid, pv->id.uuid, ID_LEN);
if (!_check_vg_name(pv->vg_name)) {
stack;
struct volume_group *vg, struct disk_list *dl)
{
struct vg_disk *vgd = &dl->vg;
- memcpy(&vg->id.uuid, &vgd->vg_uuid, ID_LEN);
+ memcpy(vg->id.uuid, vgd->vg_uuid, ID_LEN);
if (!_check_vg_name(dl->pv.vg_name)) {
stack;
int export_vg(struct vg_disk *vgd, struct volume_group *vg)
{
memset(vgd, 0, sizeof(*vgd));
- memcpy(&vgd->vg_uuid, &vg->id.uuid, ID_LEN);
+ memcpy(vgd->vg_uuid, vg->id.uuid, ID_LEN);
//vgd->vg_number = ??;
if (vg->status &= LVM_READ)
int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd)
{
int len;
- memset(&lv->id.uuid, 0, sizeof(lv->id));
+ memset(&lv->id, 0, sizeof(lv->id));
if (!(lv->name = _create_lv_name(mem, lvd->lv_name))) {
stack;
return 0;
stack;
return 0;
}
- memset(&dl->extents, 0, len);
+ memset(dl->extents, 0, len);
- list_for_each(tmp, &dl->lvs) {
+ list_for_each(tmp, &vg->lvs) {
ll = list_entry(tmp, struct lv_list, list);
if (!(lvdl = pool_alloc(dl->mem, sizeof(*lvdl)))) {
stack;
}
list_add(&lvdl->list, &dl->lvs);
+ dl->pv.lv_cur++;
}
return 1;
}
return 0;
}
- memset(&ul->uuid, 0, sizeof(ul->uuid));
- memcpy(&ul->uuid, &pvl->pv.id.uuid, ID_LEN);
+ memset(ul->uuid, 0, sizeof(ul->uuid));
+ memcpy(ul->uuid, pvl->pv.id.uuid, ID_LEN);
list_add(&ul->list, &dl->uuids);
}
pvd->vg_on_disk.size = VG_SIZE;
pvd->pv_uuidlist_on_disk.base = _next_base(&pvd->vg_on_disk);
- pvd->pv_uuidlist_on_disk.size = (MAX_PV + 1) * NAME_LEN;
+ pvd->pv_uuidlist_on_disk.size = MAX_PV * NAME_LEN;
pvd->lv_on_disk.base = _next_base(&pvd->pv_uuidlist_on_disk);
- pvd->lv_on_disk.size = (MAX_LV + 1) * sizeof(struct lv_disk);
+ pvd->lv_on_disk.size = MAX_LV * sizeof(struct lv_disk);
pvd->pe_on_disk.base = _next_base(&pvd->lv_on_disk);
pvd->pe_on_disk.size = pvd->pe_total * sizeof(struct pe_disk);
SOURCES=\
read_vg_t.c \
+ write_vg_t.c \
pretty_print.c \
get_pvs_t.c \
read_pv_t.c \
TARGETS=\
read_vg_t \
+ write_vg_t \
get_pvs_t \
read_pv_t \
get_vgs_t
read_vg_t: read_vg_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a
$(CC) -o read_vg_t read_vg_t.o pretty_print.o -L$(top_srcdir)/lib -llvm
+write_vg_t: write_vg_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a
+ $(CC) -o write_vg_t write_vg_t.o pretty_print.o \
+ -L$(top_srcdir)/lib -llvm
+
get_pvs_t: get_pvs_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a
$(CC) -o get_pvs_t get_pvs_t.o pretty_print.o -L$(top_srcdir)/lib -llvm
--- /dev/null
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */
+
+#include "log.h"
+#include "format1.h"
+#include "dbg_malloc.h"
+#include "pool.h"
+#include "pretty_print.h"
+
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ struct io_space *ios;
+ struct volume_group *vg;
+ struct pool *mem;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: read_vg_t <vg_name>\n");
+ exit(1);
+ }
+
+ init_log(stderr);
+ init_debug(_LOG_INFO);
+
+ if (!dev_cache_init()) {
+ fprintf(stderr, "init of dev-cache failed\n");
+ exit(1);
+ }
+
+ if (!dev_cache_add_dir("/dev/loop")) {
+ fprintf(stderr, "couldn't add /dev to dir-cache\n");
+ exit(1);
+ }
+
+ if (!(mem = pool_create(10 * 1024))) {
+ fprintf(stderr, "couldn't create pool\n");
+ exit(1);
+ }
+
+ ios = create_lvm1_format("/dev", mem, NULL);
+
+ if (!ios) {
+ fprintf(stderr, "failed to create io_space for format1\n");
+ exit(1);
+ }
+
+ vg = ios->vg_read(ios, argv[1]);
+
+ if (!vg) {
+ fprintf(stderr, "couldn't read vg %s\n", argv[1]);
+ exit(1);
+ }
+
+ if (!ios->vg_write(ios, vg)) {
+ fprintf(stderr, "couldn't write vg\n");
+ exit(1);
+ }
+
+ ios->destroy(ios);
+
+ pool_destroy(mem);
+ dev_cache_exit();
+ dump_memory();
+ fin_log();
+ return 0;
+}