summaryrefslogtreecommitdiff
path: root/ext4_utils
diff options
context:
space:
mode:
Diffstat (limited to 'ext4_utils')
-rw-r--r--ext4_utils/allocate.c6
-rw-r--r--ext4_utils/ext4_crypt_init_extensions.cpp18
-rw-r--r--ext4_utils/make_ext4fs.c7
-rwxr-xr-xext4_utils/mkuserimg_mke2fs.sh35
4 files changed, 59 insertions, 7 deletions
diff --git a/ext4_utils/allocate.c b/ext4_utils/allocate.c
index e0f662c8..d3a77b0a 100644
--- a/ext4_utils/allocate.c
+++ b/ext4_utils/allocate.c
@@ -231,16 +231,20 @@ static int reserve_blocks(struct block_group_info *bg, u32 bg_num, u32 start, u3
static void free_blocks(struct block_group_info *bg, u32 block, u32 num_blocks)
{
unsigned int i;
+
+ if (num_blocks == 0)
+ return;
for (i = 0; i < num_blocks; i++, block--)
bg->block_bitmap[block / 8] &= ~(1 << (block % 8));
bg->free_blocks += num_blocks;
+ block++;
for (i = bg->chunk_count; i > 0 ;) {
--i;
if (bg->chunks[i].len >= num_blocks && bg->chunks[i].block <= block) {
if (bg->chunks[i].block == block) {
bg->chunks[i].block += num_blocks;
bg->chunks[i].len -= num_blocks;
- } else if (bg->chunks[i].block + bg->chunks[i].len - 1 == block + num_blocks) {
+ } else if (bg->chunks[i].block + bg->chunks[i].len == block + num_blocks) {
bg->chunks[i].len -= num_blocks;
}
break;
diff --git a/ext4_utils/ext4_crypt_init_extensions.cpp b/ext4_utils/ext4_crypt_init_extensions.cpp
index 2bf88012..35a1c219 100644
--- a/ext4_utils/ext4_crypt_init_extensions.cpp
+++ b/ext4_utils/ext4_crypt_init_extensions.cpp
@@ -41,6 +41,8 @@
static const std::string arbitrary_sequence_number = "42";
static const int vold_command_timeout_ms = 60 * 1000;
+static int set_system_de_policy_on(char const* dir);
+
int e4crypt_install_keyring()
{
key_serial_t device_keyring = add_key("keyring", "e4crypt", 0, 0,
@@ -58,11 +60,22 @@ int e4crypt_install_keyring()
int e4crypt_set_directory_policy(const char* dir)
{
+ if (!dir || strncmp(dir, "/data/", 6)) {
+ return 0;
+ }
+
+ // Special-case /data/media/obb per b/64566063
+ if (strcmp(dir, "/data/media/obb") == 0) {
+ // Try to set policy on this directory, but if it is non-empty this may fail.
+ set_system_de_policy_on(dir);
+ return 0;
+ }
+
// Only set policy on first level /data directories
// To make this less restrictive, consider using a policy file.
// However this is overkill for as long as the policy is simply
// to apply a global policy to all /data folders created via makedir
- if (!dir || strncmp(dir, "/data/", 6) || strchr(dir + 6, '/')) {
+ if (strchr(dir + 6, '/')) {
return 0;
}
@@ -83,7 +96,10 @@ int e4crypt_set_directory_policy(const char* dir)
return 0;
}
}
+ return set_system_de_policy_on(dir);
+}
+static int set_system_de_policy_on(char const* dir) {
std::string ref_filename = std::string("/data") + e4crypt_key_ref;
std::string policy;
if (!android::base::ReadFileToString(ref_filename, &policy)) {
diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c
index 077899a4..cadf55c1 100644
--- a/ext4_utils/make_ext4fs.c
+++ b/ext4_utils/make_ext4fs.c
@@ -630,6 +630,13 @@ static void extract_base_fs_allocations(const char *directory, const char *mount
int start_block, end_block;
u32 block_file_size;
u32 real_file_block_size;
+ struct stat buf;
+
+ if (lstat(real_file_name, &buf) == -1)
+ critical_error(err_msg);
+
+ if (!S_ISREG(buf.st_mode))
+ continue;
real_file_fd = open(real_file_name, O_RDONLY);
if (real_file_fd == -1) {
diff --git a/ext4_utils/mkuserimg_mke2fs.sh b/ext4_utils/mkuserimg_mke2fs.sh
index 64b1fe3f..ea73ff70 100755
--- a/ext4_utils/mkuserimg_mke2fs.sh
+++ b/ext4_utils/mkuserimg_mke2fs.sh
@@ -8,7 +8,8 @@ Usage:
mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE [-j <journal_size>]
[-T TIMESTAMP] [-C FS_CONFIG] [-D PRODUCT_OUT] [-B BLOCK_LIST_FILE]
[-d BASE_ALLOC_FILE_IN ] [-A BASE_ALLOC_FILE_OUT ] [-L LABEL]
- [-i INODES ] [-e ERASE_BLOCK_SIZE] [-o FLASH_BLOCK_SIZE] [FILE_CONTEXTS]
+ [-i INODES ] [-e ERASE_BLOCK_SIZE] [-o FLASH_BLOCK_SIZE]
+ [-U MKE2FS_UUID] [-S MKE2FS_HASH_SEED] [FILE_CONTEXTS]
EOT
}
@@ -17,6 +18,7 @@ BLOCKSIZE=4096
MKE2FS_OPTS=""
MKE2FS_EXTENDED_OPTS=""
E2FSDROID_OPTS=""
+E2FSPROGS_FAKE_TIME=""
if [ "$1" = "-s" ]; then
MKE2FS_EXTENDED_OPTS+="android_sparse"
@@ -53,6 +55,7 @@ fi
if [[ "$1" == "-T" ]]; then
E2FSDROID_OPTS+=" -T $2"
+ E2FSPROGS_FAKE_TIME=$2
shift; shift
fi
@@ -108,6 +111,19 @@ if [[ "$1" == "-o" ]]; then
shift; shift
fi
+if [[ "$1" == "-U" ]]; then
+ MKE2FS_OPTS+=" -U $2"
+ shift; shift
+fi
+
+if [[ "$1" == "-S" ]]; then
+ if [[ $MKE2FS_EXTENDED_OPTS ]]; then
+ MKE2FS_EXTENDED_OPTS+=","
+ fi
+ MKE2FS_EXTENDED_OPTS+="hash_seed=$2"
+ shift; shift
+fi
+
if [[ $MKE2FS_EXTENDED_OPTS ]]; then
MKE2FS_OPTS+=" -E $MKE2FS_EXTENDED_OPTS"
fi
@@ -141,16 +157,25 @@ SIZE=$((SIZE / BLOCKSIZE))
# truncate output file since mke2fs will keep verity section in existing file
cat /dev/null >$OUTPUT_FILE
+MAKE_EXT4FS_ENV="MKE2FS_CONFIG=./system/extras/ext4_utils/mke2fs.conf"
+if [[ $E2FSPROGS_FAKE_TIME ]]; then
+ MAKE_EXT4FS_ENV+=" E2FSPROGS_FAKE_TIME=$E2FSPROGS_FAKE_TIME"
+fi
+
MAKE_EXT4FS_CMD="mke2fs $MKE2FS_OPTS -t $EXT_VARIANT -b $BLOCKSIZE $OUTPUT_FILE $SIZE"
-echo $MAKE_EXT4FS_CMD
-MKE2FS_CONFIG=./system/extras/ext4_utils/mke2fs.conf $MAKE_EXT4FS_CMD
+echo $MAKE_EXT4FS_ENV $MAKE_EXT4FS_CMD
+env $MAKE_EXT4FS_ENV $MAKE_EXT4FS_CMD
if [ $? -ne 0 ]; then
exit 4
fi
+if [[ $E2FSPROGS_FAKE_TIME ]]; then
+ E2FSDROID_ENV="E2FSPROGS_FAKE_TIME=$E2FSPROGS_FAKE_TIME"
+fi
+
E2FSDROID_CMD="e2fsdroid $E2FSDROID_OPTS -f $SRC_DIR -a $MOUNT_POINT $OUTPUT_FILE"
-echo $E2FSDROID_CMD
-$E2FSDROID_CMD
+echo $E2FSDROID_ENV $E2FSDROID_CMD
+env $E2FSDROID_ENV $E2FSDROID_CMD
if [ $? -ne 0 ]; then
rm -f $OUTPUT_FILE
exit 4