Change upgrade code to allow multiple versions
In the future, we'd like to have the ability to upgrade from any supported version to any future version. Change the upgrade function slightly to support this. Change-Id: I3b20ccfff51c4c86f1e5e08690c263dc95ff5ce4
This commit is contained in:
parent
9caab76c6b
commit
7434b3111b
1 changed files with 35 additions and 35 deletions
16
cryptfs.c
16
cryptfs.c
|
@ -250,17 +250,13 @@ static void init_empty_persist_data(struct crypt_persist_data *pdata, int len)
|
|||
*/
|
||||
static void upgrade_crypt_ftr(int fd, struct crypt_mnt_ftr *crypt_ftr, off64_t offset)
|
||||
{
|
||||
int orig_major = crypt_ftr->major_version;
|
||||
int orig_minor = crypt_ftr->minor_version;
|
||||
|
||||
if ((crypt_ftr->major_version == 1) && (crypt_ftr->minor_version == 0)) {
|
||||
struct crypt_persist_data *pdata;
|
||||
off64_t pdata_offset = offset + CRYPT_FOOTER_TO_PERSIST_OFFSET;
|
||||
|
||||
/* This routine can currently only handle upgrading from 1.0 to 1.1.
|
||||
* Do nothing if the passed structure is not version 1.0
|
||||
*/
|
||||
|
||||
if ((crypt_ftr->major_version != 1) && (crypt_ftr->minor_version != 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pdata = malloc(CRYPT_PERSIST_DATA_SIZE);
|
||||
if (pdata == NULL) {
|
||||
SLOGE("Cannot allocate persisent data\n");
|
||||
|
@ -285,12 +281,16 @@ static void upgrade_crypt_ftr(int fd, struct crypt_mnt_ftr *crypt_ftr, off64_t o
|
|||
crypt_ftr->persist_data_offset[0] = pdata_offset;
|
||||
crypt_ftr->persist_data_offset[1] = pdata_offset + CRYPT_PERSIST_DATA_SIZE;
|
||||
crypt_ftr->minor_version = 1;
|
||||
}
|
||||
|
||||
if ((orig_major != crypt_ftr->major_version) || (orig_minor != crypt_ftr->minor_version)) {
|
||||
if (lseek64(fd, offset, SEEK_SET) == -1) {
|
||||
SLOGE("Cannot seek to crypt footer\n");
|
||||
return;
|
||||
}
|
||||
unix_write(fd, crypt_ftr, sizeof(struct crypt_mnt_ftr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int get_crypt_ftr_and_key(struct crypt_mnt_ftr *crypt_ftr)
|
||||
|
|
Loading…
Reference in a new issue