From 6320fd9e52e8303c609288050b308330fe6f6382 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 10 Oct 2001 09:36:29 +0000 Subject: [PATCH] o add munging for format1 and 2 --- lib/format1/disk-rep.c | 33 +++++++++++++++++++++++++++++---- lib/format1/disk-rep.h | 3 +++ lib/format1/layout.c | 2 -- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c index 173c16e70..7463d53c5 100644 --- a/lib/format1/disk-rep.c +++ b/lib/format1/disk-rep.c @@ -39,8 +39,6 @@ static void _xlate_pv(struct pv_disk *disk) xx32(pe_total); xx32(pe_allocated); xx32(pe_start); - - /* FIXME: put v1, v2 munging in here. */ } static void _xlate_lv(struct lv_disk *disk) @@ -95,14 +93,41 @@ static void _xlate_extents(struct pe_disk *extents, int count) } } +/* + * Handle both minor metadata formats. + */ +static int _munge_formats(struct pv_disk *pvd) +{ + uint32_t pe_start; + + switch (pvd->version) { + case 1: + pe_start = (pvd->pe_on_disk.base + pvd->pe_on_disk.size) / + SECTOR_SIZE; + break; + + case 2: + pvd->version = 1; + pe_start = pvd->pe_start * SECTOR_SIZE; + pvd->pe_on_disk.size = pe_start - pvd->pe_on_disk.base; + break; + + default: + log_err("unknown metadata version %d", pvd->version); + return 0; + } + + return 1; +} + static int _read_pv(struct disk_list *data) { struct pv_disk *pvd = &data->pv; if (dev_read(data->dev, 0, sizeof(*pvd), pvd) != sizeof(*pvd)) fail; - _xlate_pv(pvd); - return 1; + + return _munge_formats(pvd); } static int _read_lv(struct device *dev, ulong pos, struct lv_disk *disk) diff --git a/lib/format1/disk-rep.h b/lib/format1/disk-rep.h index 57ae83075..e96691dcc 100644 --- a/lib/format1/disk-rep.h +++ b/lib/format1/disk-rep.h @@ -11,6 +11,9 @@ #include "metadata.h" #include "pool.h" + +#define SECTOR_SIZE 512 + #define MAX_PV 256 #define MAX_LV 256 #define MAX_VG 99 diff --git a/lib/format1/layout.c b/lib/format1/layout.c index 84c0643c3..7a48a05e3 100644 --- a/lib/format1/layout.c +++ b/lib/format1/layout.c @@ -8,8 +8,6 @@ #include "log.h" -#define SECTOR_SIZE 512 - /* * Only works with powers of 2. */