1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

o Add version number to text format.

This commit is contained in:
Joe Thornber 2002-07-02 18:47:43 +00:00
parent 547afddbab
commit 7df3006c6b
3 changed files with 69 additions and 1 deletions

View File

@ -177,7 +177,10 @@ static int _print_header(struct formatter *f,
_out(f, _out(f,
"# This file was originally generated by the LVM2 library\n" "# This file was originally generated by the LVM2 library\n"
"# Generated: %s\n", ctime(&t)); "# Generated: %s", ctime(&t));
_out(f, CONTENTS_FIELD " = \"" CONTENTS_VALUE "\"");
_out(f, FORMAT_VERSION_FIELD " = %d\n", FORMAT_VERSION_VALUE);
_out(f, "description = \"%s\"", desc); _out(f, "description = \"%s\"", desc);
_out(f, "creation_time = %lu\n", t); _out(f, "creation_time = %lu\n", t);

View File

@ -14,6 +14,19 @@
#include <stdio.h> #include <stdio.h>
/*
* Constants to help indentify which files this code can parse.
*/
#define CONTENTS_FIELD "contents"
#define CONTENTS_VALUE "Text Format Volume Group"
#define FORMAT_VERSION_FIELD "version"
#define FORMAT_VERSION_VALUE 1
/*
* VGs, PVs and LVs all have status bitsets, we gather together
* common code for reading and writing them.
*/
enum { enum {
VG_FLAGS, VG_FLAGS,
PV_FLAGS, PV_FLAGS,

View File

@ -26,6 +26,55 @@ typedef int (*section_fn) (struct format_instance * fid, struct pool * mem,
#define _read_int64(root, path, result) \ #define _read_int64(root, path, result) \
get_config_uint64(root, path, '/', result) get_config_uint64(root, path, '/', result)
/*
* Logs an attempt to read an invalid format file.
*/
static void _invalid_format(const char *str)
{
log_err("invalid text format file (%s)", str);
}
/*
* Checks that the config file contains vg metadata, and that it
* is in a version that we understand.
*/
static int _check_version(struct config_file *cf)
{
struct config_node *cn;
struct config_value *cv;
/*
* Check the contents field.
*/
if (!(cn = find_config_node(cf->root, CONTENTS_FIELD, '/'))) {
_invalid_format("no contents field");
return 0;
}
cv = cn->v;
if (!cv || cv->type != CFG_STRING || strcmp(cv->v.str, CONTENTS_VALUE))
{
_invalid_format("incorrect contents field");
return 0;
}
/*
* Check the version number.
*/
if (!(cn = find_config_node(cf->root, FORMAT_VERSION_FIELD, '/'))) {
_invalid_format("no version field");
return 0;
}
cv = cn->v;
if (!cv || cv->type != CFG_INT || cv->v.i != FORMAT_VERSION_VALUE) {
_invalid_format("incorrect version number");
return 0;
}
return 1;
}
static int _read_id(struct id *id, struct config_node *cn, const char *path) static int _read_id(struct id *id, struct config_node *cn, const char *path)
{ {
struct config_value *cv; struct config_value *cv;
@ -664,6 +713,9 @@ struct volume_group *text_vg_import(struct format_instance *fid,
goto out; goto out;
} }
if (!_check_version(cf))
goto out;
if (!(vg = _read_vg(fid, cf, um))) { if (!(vg = _read_vg(fid, cf, um))) {
stack; stack;
goto out; goto out;