Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c198d3e authored by Paul Lawrence's avatar Paul Lawrence Committed by android-build-merger
Browse files

Make file encryption type available

am: 4e898a01

* commit '4e898a01':
  Make file encryption type available

Change-Id: I72de48f819ab957f4e87a194b714ae667798f136
parents 74521c93 4e898a01
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -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;
+2 −4
Original line number Diff line number Diff line
@@ -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);