summaryrefslogtreecommitdiffstats
path: root/uncrypt
diff options
context:
space:
mode:
Diffstat (limited to 'uncrypt')
-rw-r--r--uncrypt/Android.bp39
-rw-r--r--uncrypt/Android.mk32
-rw-r--r--uncrypt/uncrypt.cpp40
3 files changed, 68 insertions, 43 deletions
diff --git a/uncrypt/Android.bp b/uncrypt/Android.bp
new file mode 100644
index 000000000..aa56d2f74
--- /dev/null
+++ b/uncrypt/Android.bp
@@ -0,0 +1,39 @@
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_binary {
+ name: "uncrypt",
+
+ srcs: [
+ "uncrypt.cpp",
+ ],
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+
+ static_libs: [
+ "libbootloader_message",
+ "libotautil",
+ "libfs_mgr",
+ "libbase",
+ "libcutils",
+ "liblog",
+ ],
+
+ init_rc: [
+ "uncrypt.rc",
+ ],
+}
diff --git a/uncrypt/Android.mk b/uncrypt/Android.mk
deleted file mode 100644
index 59084b0bb..000000000
--- a/uncrypt/Android.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_CLANG := true
-LOCAL_SRC_FILES := uncrypt.cpp
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/..
-LOCAL_MODULE := uncrypt
-LOCAL_STATIC_LIBRARIES := \
- libbootloader_message \
- libbase \
- liblog \
- libfs_mgr \
- libcutils
-LOCAL_CFLAGS := -Werror
-LOCAL_INIT_RC := uncrypt.rc
-
-include $(BUILD_EXECUTABLE)
diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp
index ad3bdce7a..bb43c2c4a 100644
--- a/uncrypt/uncrypt.cpp
+++ b/uncrypt/uncrypt.cpp
@@ -116,7 +116,7 @@
#include <cutils/sockets.h>
#include <fs_mgr.h>
-#include "error_code.h"
+#include "otautil/error_code.h"
static constexpr int WINDOW_SIZE = 5;
static constexpr int FIBMAP_RETRY_LIMIT = 3;
@@ -172,10 +172,14 @@ static struct fstab* read_fstab() {
return fstab;
}
-static const char* find_block_device(const char* path, bool* encryptable, bool* encrypted) {
+static const char* find_block_device(const char* path, bool* encryptable, bool* encrypted, bool *f2fs_fs) {
// Look for a volume whose mount point is the prefix of path and
// return its block device. Set encrypted if it's currently
// encrypted.
+
+ // ensure f2fs_fs is set to 0 first.
+ if (f2fs_fs)
+ *f2fs_fs = false;
for (int i = 0; i < fstab->num_entries; ++i) {
struct fstab_rec* v = &fstab->recs[i];
if (!v->mount_point) {
@@ -192,6 +196,8 @@ static const char* find_block_device(const char* path, bool* encryptable, bool*
*encrypted = true;
}
}
+ if (f2fs_fs && strcmp(v->fs_type, "f2fs") == 0)
+ *f2fs_fs = true;
return v->blk_device;
}
}
@@ -244,7 +250,7 @@ static int retry_fibmap(const int fd, const char* name, int* block, const int he
}
static int produce_block_map(const char* path, const char* map_file, const char* blk_dev,
- bool encrypted, int socket) {
+ bool encrypted, bool f2fs_fs, int socket) {
std::string err;
if (!android::base::RemoveFileIfExists(map_file, &err)) {
LOG(ERROR) << "failed to remove the existing map file " << map_file << ": " << err;
@@ -307,6 +313,17 @@ static int produce_block_map(const char* path, const char* map_file, const char*
}
}
+#ifndef F2FS_IOC_SET_DONTMOVE
+#ifndef F2FS_IOCTL_MAGIC
+#define F2FS_IOCTL_MAGIC 0xf5
+#endif
+#define F2FS_IOC_SET_DONTMOVE _IO(F2FS_IOCTL_MAGIC, 13)
+#endif
+ if (f2fs_fs && ioctl(fd, F2FS_IOC_SET_DONTMOVE) < 0) {
+ PLOG(ERROR) << "Failed to set non-movable file for f2fs: " << path << " on " << blk_dev;
+ return kUncryptIoctlError;
+ }
+
off64_t pos = 0;
int last_progress = 0;
while (pos < sb.st_size) {
@@ -448,20 +465,21 @@ static int produce_block_map(const char* path, const char* map_file, const char*
static int uncrypt(const char* input_path, const char* map_file, const int socket) {
LOG(INFO) << "update package is \"" << input_path << "\"";
- // Turn the name of the file we're supposed to convert into an
- // absolute path, so we can find what filesystem it's on.
+ // Turn the name of the file we're supposed to convert into an absolute path, so we can find
+ // what filesystem it's on.
char path[PATH_MAX+1];
- if (realpath(input_path, path) == NULL) {
+ if (realpath(input_path, path) == nullptr) {
PLOG(ERROR) << "failed to convert \"" << input_path << "\" to absolute path";
- return 1;
+ return kUncryptRealpathFindError;
}
bool encryptable;
bool encrypted;
- const char* blk_dev = find_block_device(path, &encryptable, &encrypted);
- if (blk_dev == NULL) {
+ bool f2fs_fs;
+ const char* blk_dev = find_block_device(path, &encryptable, &encrypted, &f2fs_fs);
+ if (blk_dev == nullptr) {
LOG(ERROR) << "failed to find block device for " << path;
- return 1;
+ return kUncryptBlockDeviceFindError;
}
// If the filesystem it's on isn't encrypted, we only produce the
@@ -479,7 +497,7 @@ static int uncrypt(const char* input_path, const char* map_file, const int socke
// and /sdcard we leave the file alone.
if (strncmp(path, "/data/", 6) == 0) {
LOG(INFO) << "writing block map " << map_file;
- return produce_block_map(path, map_file, blk_dev, encrypted, socket);
+ return produce_block_map(path, map_file, blk_dev, encrypted, f2fs_fs, socket);
}
return 0;