summaryrefslogtreecommitdiffstats
path: root/crypto/lollipop/cryptfs.c
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2015-12-10 17:19:45 +0100
committerDees Troy <dees_troy@teamw.in>2016-01-25 23:59:17 +0100
commit66a1949df91cc558bf5573c395fa9084c1365e81 (patch)
tree2a2e3c959e8f19f2489bc19f86df6e5a6caa1ccf /crypto/lollipop/cryptfs.c
parentgui: add icons on settings tabs (diff)
downloadandroid_bootable_recovery-66a1949df91cc558bf5573c395fa9084c1365e81.tar
android_bootable_recovery-66a1949df91cc558bf5573c395fa9084c1365e81.tar.gz
android_bootable_recovery-66a1949df91cc558bf5573c395fa9084c1365e81.tar.bz2
android_bootable_recovery-66a1949df91cc558bf5573c395fa9084c1365e81.tar.lz
android_bootable_recovery-66a1949df91cc558bf5573c395fa9084c1365e81.tar.xz
android_bootable_recovery-66a1949df91cc558bf5573c395fa9084c1365e81.tar.zst
android_bootable_recovery-66a1949df91cc558bf5573c395fa9084c1365e81.zip
Diffstat (limited to '')
-rw-r--r--crypto/lollipop/cryptfs.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/crypto/lollipop/cryptfs.c b/crypto/lollipop/cryptfs.c
index 1e65a2263..fa440ed17 100644
--- a/crypto/lollipop/cryptfs.c
+++ b/crypto/lollipop/cryptfs.c
@@ -1060,6 +1060,7 @@ static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr, unsigned c
if (! ioctl(fd, DM_TABLE_LOAD, io)) {
break;
}
+ printf("%i\n", errno);
usleep(500000);
}
@@ -1145,7 +1146,7 @@ static int create_crypto_blk_dev(struct crypt_mnt_ftr *crypt_ftr, unsigned char
ioctl_init(io, DM_CRYPT_BUF_SIZE, name, 0);
if (ioctl(fd, DM_DEV_CREATE, io)) {
- printf("Cannot create dm-crypt device\n");
+ printf("Cannot create dm-crypt device %i\n", errno);
goto errout;
}
@@ -2017,3 +2018,45 @@ int cryptfs_get_password_type(void)
return crypt_ftr.crypt_type;
}
+
+/*
+ * Called by vold when it's asked to mount an encrypted external
+ * storage volume. The incoming partition has no crypto header/footer,
+ * as any metadata is been stored in a separate, small partition.
+ *
+ * out_crypto_blkdev must be MAXPATHLEN.
+ */
+int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
+ const unsigned char* key, int keysize, char* out_crypto_blkdev) {
+ int fd = open(real_blkdev, O_RDONLY|O_CLOEXEC);
+ if (fd == -1) {
+ printf("Failed to open %s: %s", real_blkdev, strerror(errno));
+ return -1;
+ }
+
+ unsigned long nr_sec = 0;
+ nr_sec = get_blkdev_size(fd);
+ close(fd);
+
+ if (nr_sec == 0) {
+ printf("Failed to get size of %s: %s", real_blkdev, strerror(errno));
+ return -1;
+ }
+
+ struct crypt_mnt_ftr ext_crypt_ftr;
+ memset(&ext_crypt_ftr, 0, sizeof(ext_crypt_ftr));
+ ext_crypt_ftr.fs_size = nr_sec;
+ ext_crypt_ftr.keysize = keysize;
+ strcpy((char*) ext_crypt_ftr.crypto_type_name, "aes-cbc-essiv:sha256");
+
+ return create_crypto_blk_dev(&ext_crypt_ftr, key, real_blkdev,
+ out_crypto_blkdev, label);
+}
+
+/*
+ * Called by vold when it's asked to unmount an encrypted external
+ * storage volume.
+ */
+int cryptfs_revert_ext_volume(const char* label) {
+ return delete_crypto_blk_dev((char*) label);
+}