Patch preview - what do you think? This patch add a version number to the config file and can convert the config file if it structure has changed. Part 2 does converting. Thanks, Jens --- sheepdog-0.4.0-0+tek2b.orig/sheep/store.c +++ sheepdog-0.4.0-0+tek2b/sheep/store.c @@ -28,13 +28,34 @@ #include "util.h" #include "farm/farm.h" +#define CONFIGFILE_SIGNATURE 0x0000aaaa00000000 +#define CONFIGFILE_VERSION 3 +/* configfile version 3 */ struct sheepdog_config { + uint64_t configversion; uint64_t ctime; uint64_t space; uint16_t flags; uint8_t copies; uint8_t store[STORE_LEN]; }; +/***** remove in > v0.5.0 *****/ +/* configfile version 2 */ +struct sheepdog_config_2 { + uint64_t ctime; + uint64_t space; + uint16_t flags; + uint8_t copies; + uint8_t store[STORE_LEN]; +}; +/***** remove in > v0.5.0 *****/ +/* configfile version 1 */ +struct sheepdog_config_1 { + uint64_t ctime; + uint16_t flags; + uint8_t copies; + uint8_t store[STORE_LEN]; +}; char *obj_path; char *mnt_path; @@ -401,12 +422,55 @@ static int init_jrnl_path(const char *ba static int init_config_path(const char *base_path) { + /* + * read and convert config + * new config has a version in the first 8 bytes + * 4 bytes version number + * 4 bytes fix version signature + */ + int fd, ret; + uint64_t version; + config_path = zalloc(strlen(base_path) + strlen(CONFIG_PATH) + 1); sprintf(config_path, "%s" CONFIG_PATH, base_path); - mknod(config_path, def_fmode, S_IFREG); + fd = open(config_path, O_RDONLY); + if (fd < 0) + { + /* new config file */ + mknod(config_path, def_fmode, S_IFREG); + fd = open(config_path, O_DSYNC | O_WRONLY); + if (fd < 0) + return 1; - return 0; + version = CONFIGFILE_SIGNATURE | CONFIGFILE_VERSION; + ret = xpwrite(fd, &version, sizeof(version), offsetof(struct sheepdog_config, configversion)); + + close(fd); + if (ret != sizeof(version)) + return 1; + + return 0; + } + + ret = xpread(fd, &version, sizeof(version), + offsetof(struct sheepdog_config, configversion)); + close(fd); + + if (ret != sizeof(version)) + return 1; + if ((version & CONFIGFILE_SIGNATURE) == CONFIGFILE_SIGNATURE) + { + version = version & 0x0000000011111111; + if (version == CONFIGFILE_VERSION) + return 0; + /* convert config file with version number */ + /* unknown version */ + return 1; + } + /***** remove in > v0.5.0 *****/ + /* convert config files without version number */ + return 1; } static int init_store_driver(void) |