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

Commit 66a1949d authored by Ethan Yonker's avatar Ethan Yonker Committed by Dees Troy
Browse files

Adopted Storage support

 -Detects, decrypts, and mounts an adopted SD card if a
  secondary block device is defined (usually mmcblk1)
 -Handles unified storage
 -Displays the adopted storage in MTP along with internal
 -Factory Reset - wiped just like a data media device, we
  retain the keys folder and the storage.xml during a
  factory reset
 -Backup / Restore
 -Disable mass storage when adopted storage is present
 -Read storage nickname from storage.xml and apply it to
  display names in the GUI
 -Read storage.xml and determine what storage location is in
  use for /sdcard and remap accordingly

libgpt_twrp is source code mostly kanged from an efimanager
project. It is GPL v2 or higher, so we will opt for GPL v3.

Change-Id: Ieda0030bec5155ba8d2b9167dc0016cebbf39d55
parent 56a7a99d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ ifeq ($(TW_INCLUDE_L_CRYPTO), true)
endif
ifeq ($(TW_INCLUDE_CRYPTO), true)
    LOCAL_CFLAGS += -DTW_INCLUDE_CRYPTO
    LOCAL_SHARED_LIBRARIES += libcryptfslollipop
    LOCAL_SHARED_LIBRARIES += libcryptfslollipop libgpt_twrp
    LOCAL_C_INCLUDES += external/boringssl/src/include
endif
ifeq ($(TW_USE_MODEL_HARDWARE_ID_FOR_DEVICE_ID), true)
@@ -592,6 +592,7 @@ include $(commands_recovery_local_path)/injecttwrp/Android.mk \
ifeq ($(TW_INCLUDE_CRYPTO), true)
    include $(commands_recovery_local_path)/crypto/lollipop/Android.mk
    include $(commands_recovery_local_path)/crypto/scrypt/Android.mk
    include $(commands_recovery_local_path)/gpt/Android.mk
endif
ifeq ($(BUILD_ID), GINGERBREAD)
    TW_NO_EXFAT := true
+44 −1
Original line number Diff line number Diff line
@@ -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);
}
+3 −0
Original line number Diff line number Diff line
@@ -221,6 +221,9 @@ extern "C" {
  int cryptfs_verify_passwd(char *newpw);
  int cryptfs_get_password_type(void);
  int delete_crypto_blk_dev(char *name);
  int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
          const unsigned char* key, int keysize, char* out_crypto_blkdev);
  int cryptfs_revert_ext_volume(const char* label);
#ifdef __cplusplus
}
#endif
+3 −1
Original line number Diff line number Diff line
@@ -744,7 +744,7 @@ void DataManager::SetDefaultValues()
		mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "0"));
	} else {
		LOGINFO("Lun file '%s'\n", Lun_File_str.c_str());
		mConstValues.insert(make_pair(TW_HAS_USB_STORAGE, "1"));
		mValues.insert(make_pair(TW_HAS_USB_STORAGE, make_pair("1", 0)));
	}
#endif
#ifdef TW_INCLUDE_INJECTTWRP
@@ -923,6 +923,8 @@ void DataManager::SetDefaultValues()
	mValues.insert(make_pair("tw_language", make_pair(EXPAND(TW_DEFAULT_LANGUAGE), 1)));
	LOGINFO("LANG: %s\n", EXPAND(TW_DEFAULT_LANGUAGE));

	mValues.insert(make_pair("tw_has_adopted_storage", make_pair("0", 0)));

	pthread_mutex_unlock(&m_valuesLock);
}

gpt/Android.mk

0 → 100755
+15 −0
Original line number Diff line number Diff line
LOCAL_PATH := $(call my-dir)

# Build libgpt_twrp library

include $(CLEAR_VARS)
LOCAL_CLANG := false
LOCAL_MODULE := libgpt_twrp
LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES = \
    gpt.c \
    gptcrc32.c

LOCAL_SHARED_LIBRARIES := libc
include $(BUILD_SHARED_LIBRARY)
Loading