Make file encryption type available

Bug: 28905864
Change-Id: I5f59f824fd92c32ff87aa730dc5c0f250564c0a9
This commit is contained in:
Paul Lawrence 2016-05-24 04:56:37 -07:00
parent 57de0514f0
commit 4e898a01fd
2 changed files with 29 additions and 17 deletions

View File

@ -32,12 +32,12 @@ struct fs_mgr_flag_values {
int partnum;
int swap_prio;
unsigned int zram_size;
int file_encryption_type;
unsigned int file_encryption_mode;
};
struct flag_list {
const char *name;
unsigned flag;
unsigned int flag;
};
static struct flag_list mount_flags[] = {
@ -82,9 +82,12 @@ static struct flag_list fs_mgr_flags[] = {
{ 0, 0 },
};
static struct flag_list encryption_types[] = {
{"software", ET_SOFTWARE},
{"ice", ET_ICE},
#define EM_SOFTWARE 1
#define EM_ICE 2
static struct flag_list encryption_modes[] = {
{"software", EM_SOFTWARE},
{"ice", EM_ICE},
{0, 0}
};
@ -154,20 +157,20 @@ static int parse_flags(char *flags, struct flag_list *fl,
* location of the keys. Get it and return it.
*/
flag_vals->key_loc = strdup(strchr(p, '=') + 1);
flag_vals->file_encryption_type = ET_SOFTWARE;
flag_vals->file_encryption_mode = EM_SOFTWARE;
} else if ((fl[i].flag == MF_FILEENCRYPTION) && flag_vals) {
/* The fileencryption flag is followed by an = and the
* type of the encryption. Get it and return it.
*/
const struct flag_list *j;
const char *type = strchr(p, '=') + 1;
for (j = encryption_types; j->name; ++j) {
if (!strcmp(type, j->name)) {
flag_vals->file_encryption_type = j->flag;
const char *mode = strchr(p, '=') + 1;
for (j = encryption_modes; j->name; ++j) {
if (!strcmp(mode, j->name)) {
flag_vals->file_encryption_mode = j->flag;
}
}
if (flag_vals->file_encryption_type == 0) {
ERROR("Unknown file encryption type: %s\n", type);
if (flag_vals->file_encryption_mode == 0) {
ERROR("Unknown file encryption mode: %s\n", mode);
}
} else if ((fl[i].flag == MF_LENGTH) && flag_vals) {
/* The length flag is followed by an = and the
@ -359,7 +362,7 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path)
fstab->recs[cnt].partnum = flag_vals.partnum;
fstab->recs[cnt].swap_prio = flag_vals.swap_prio;
fstab->recs[cnt].zram_size = flag_vals.zram_size;
fstab->recs[cnt].file_encryption_type = flag_vals.file_encryption_type;
fstab->recs[cnt].file_encryption_mode = flag_vals.file_encryption_mode;
cnt++;
}
/* If an A/B partition, modify block device to be the real block device */
@ -502,6 +505,17 @@ int fs_mgr_is_file_encrypted(const struct fstab_rec *fstab)
return fstab->fs_mgr_flags & MF_FILEENCRYPTION;
}
const char* fs_mgr_get_file_encryption_mode(const struct fstab_rec *fstab)
{
const struct flag_list *j;
for (j = encryption_modes; j->name; ++j) {
if (fstab->file_encryption_mode == j->flag) {
return j->name;
}
}
return NULL;
}
int fs_mgr_is_convertible_to_fbe(const struct fstab_rec *fstab)
{
return fstab->fs_mgr_flags & MF_FORCEFDEORFBE;

View File

@ -65,7 +65,7 @@ struct fstab_rec {
int partnum;
int swap_prio;
unsigned int zram_size;
int file_encryption_type;
unsigned int file_encryption_mode;
};
// Callback function for verity status
@ -87,9 +87,6 @@ int fs_mgr_mount_all(struct fstab *fstab);
#define FS_MGR_DOMNT_FAILED -1
#define FS_MGR_DOMNT_BUSY -2
#define ET_SOFTWARE 1
#define ET_ICE 2
int fs_mgr_do_mount(struct fstab *fstab, char *n_name, char *n_blk_device,
char *tmp_mount_point);
int fs_mgr_do_tmpfs_mount(char *n_name);
@ -107,6 +104,7 @@ int fs_mgr_is_nonremovable(const struct fstab_rec *fstab);
int fs_mgr_is_verified(const struct fstab_rec *fstab);
int fs_mgr_is_encryptable(const struct fstab_rec *fstab);
int fs_mgr_is_file_encrypted(const struct fstab_rec *fstab);
const char* fs_mgr_get_file_encryption_mode(const struct fstab_rec *fstab);
int fs_mgr_is_convertible_to_fbe(const struct fstab_rec *fstab);
int fs_mgr_is_noemulatedsd(const struct fstab_rec *fstab);
int fs_mgr_is_notrim(struct fstab_rec *fstab);