Skip to content
Snippets Groups Projects
Commit 9a5233cd authored by Ronny Nilsson's avatar Ronny Nilsson
Browse files

When creating a new metadata volume. First give it a temporary unique name.

Then later, when it has been commited (become ready), rename it to a final value.
parent 57b1e224
Branches
No related tags found
No related merge requests found
......@@ -243,7 +243,7 @@ int ubi_create_volume(int volId, long long size)
// Generate a system unique name for the volume.
name = calloc(1, UBI_MAX_VOLUME_NAME + 1);
snprintf(name, UBI_MAX_VOLUME_NAME + 1, "%s_%d", ubiStr3, volId);
snprintf(name, UBI_MAX_VOLUME_NAME + 1, "%s_tmp_%d", ubiStr3, volId);
memset(&mkReq, 0, sizeof(mkReq));
mkReq.vol_id = volId;
......@@ -409,6 +409,35 @@ out:
}
//-------------------------------------------------------------
// Change the name of an existing UBI volume.
static int ubi_rename_volume(int volId, const char *name)
{
struct ubi_rnvol_req rnvol;
char *nodePath;
memset(&rnvol, 0, sizeof(rnvol));
rnvol.count = 1;
rnvol.ents[0].vol_id = volId;
rnvol.ents[0].name_len = strlen(name);
strncpy(rnvol.ents[0].name, name, UBI_MAX_VOLUME_NAME + 1);
nodePath = ubi_path_by_id(devInfo.dev_num, -1);
if(!nodePath || ubi_rnvols(libubi, nodePath, &rnvol)) {
fprintf(stderr, "Error renaming %d to %s: %s\n", volId,
name, strerror(errno));
free(nodePath);
return -1;
}
free(nodePath);
return 0;
}
//-------------------------------------------------------------
// Init the UBI library and query system for info.
static int ubi_probe(void)
......@@ -724,12 +753,15 @@ static int meta_generate_blob(const char *tmpPath, int seqNo)
// of time we also need a third for ensuring atomicity.
static int meta_manage_vols(int readonly)
{
int highSeqNo, highMeta, i, newMeta, delMeta, wrapSeqNo;
int highSeqNo, highMeta, i, newMeta, delMeta, wrapSeqNo, newBank, res;
struct metaInfo_t *tmpMeta;
char *newName;
highSeqNo = -1;
highMeta = 0;
wrapSeqNo = -1;
newBank = -1;
res = 0;
// What is the highest metadata sequence number?
for(i = 0; i < MAX_METAS; i++) {
......@@ -776,6 +808,7 @@ static int meta_manage_vols(int readonly)
newMeta = METAVOLID2;
delMeta = -1;
}
newBank = 1;
break;
default:
......@@ -791,6 +824,7 @@ static int meta_manage_vols(int readonly)
newMeta = METAVOLID0;
delMeta = -1;
}
newBank = 0;
break;
}
......@@ -798,7 +832,7 @@ static int meta_manage_vols(int readonly)
printf("Highest sequence number found is %d.\n", highSeqNo);
printf("Will create volume %d", newMeta);
if(delMeta >= 0) printf(" to replace volume %d", delMeta);
printf(".\n");
printf(" in flash bank %d.\n", newBank);
}
// Calc new (wrapping) sequence number and create a metadata binary.
......@@ -810,10 +844,19 @@ static int meta_manage_vols(int readonly)
if(tmpMeta) ubi_erase_volume(newMeta);
if(ubi_create_volume(newMeta, devInfo.leb_size)) return -1;
if(ubi_write_volume(newMeta, tmpMetaBlob)) return -1;
/* Rename new meta volume to name indicating
* which flash bank it belongs to. */
newName = calloc(1, UBI_MAX_VOLUME_NAME + 1);
snprintf(newName, UBI_MAX_VOLUME_NAME + 1, "%s_%d", ubiStr3, newBank);
res = ubi_rename_volume(newMeta, newName);
free(newName);
// Delete old unused meta volume.
tmpMeta = meta_by_id(delMeta);
if(tmpMeta) ubi_erase_volume(delMeta);
return 0;
return res;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment