AOSP10 TWRP Merge: fix conflicts and update libraries needed
This allows flame to boot TWRP. Still will need to work on
super partition for vendor and system access.
The plan will be to cherry-pick any updates to android-9.0
through gerrit.twrp.me to this branch as a WIP.
diff --git a/fuse_sideload/fuse_sideload.cpp b/fuse_sideload/fuse_sideload.cpp
index 8fa8ad4..3d94803 100644
--- a/fuse_sideload/fuse_sideload.cpp
+++ b/fuse_sideload/fuse_sideload.cpp
@@ -45,9 +45,8 @@
#include <errno.h>
#include <fcntl.h>
-#include <limits.h>
-#include "fuse.h"
-#include <pthread.h>
+#include <limits.h> // PATH_MAX
+#include <linux/fuse.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -58,19 +57,13 @@
#include <sys/uio.h>
#include <unistd.h>
-#ifdef USE_MINCRYPT
-#include "mincrypt/sha256.h"
-#define SHA256_DIGEST_LENGTH SHA256_DIGEST_SIZE
-#else
-#include <openssl/sha.h>
-#endif
-
#include <array>
#include <string>
#include <vector>
-//#include <android-base/stringprintf.h>
-//#include <android-base/unique_fd.h>
+#include <android-base/stringprintf.h>
+#include <android-base/unique_fd.h>
+#include <openssl/sha.h>
static constexpr uint64_t PACKAGE_FILE_ID = FUSE_ROOT_ID + 1;
static constexpr uint64_t EXIT_FLAG_ID = FUSE_ROOT_ID + 2;
@@ -80,12 +73,8 @@
using SHA256Digest = std::array<uint8_t, SHA256_DIGEST_LENGTH>;
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-
struct fuse_data {
- int ffd; // file descriptor for the fuse socket
+ android::base::unique_fd ffd; // file descriptor for the fuse socket
FuseDataProvider* provider; // Provider of the source data.
@@ -102,8 +91,8 @@
uint8_t* extra_block; // another block of storage for reads that span two blocks
- uint8_t* hashes; // SHA-256 hash of each block (all zeros
- // if block hasn't been read yet)
+ std::vector<SHA256Digest>
+ hashes; // SHA-256 hash of each block (all zeros if block hasn't been read yet)
};
static void fuse_reply(const fuse_data* fd, uint64_t unique, const void* data, size_t len) {
@@ -162,7 +151,7 @@
static void fill_attr(fuse_attr* attr, const fuse_data* fd, uint64_t nodeid, uint64_t size,
uint32_t mode) {
- memset(attr, 0, sizeof(*attr));
+ *attr = {};
attr->nlink = 1;
attr->uid = fd->uid;
attr->gid = fd->gid;
@@ -175,8 +164,7 @@
}
static int handle_getattr(void* /* data */, const fuse_data* fd, const fuse_in_header* hdr) {
- struct fuse_attr_out out;
- memset(&out, 0, sizeof(out));
+ fuse_attr_out out = {};
out.attr_valid = 10;
if (hdr->nodeid == FUSE_ROOT_ID) {
@@ -196,8 +184,7 @@
static int handle_lookup(void* data, const fuse_data* fd, const fuse_in_header* hdr) {
if (data == nullptr) return -ENOENT;
- struct fuse_entry_out out;
- memset(&out, 0, sizeof(out));
+ fuse_entry_out out = {};
out.entry_valid = 10;
out.attr_valid = 10;
@@ -222,8 +209,7 @@
if (hdr->nodeid == EXIT_FLAG_ID) return -EPERM;
if (hdr->nodeid != PACKAGE_FILE_ID) return -ENOENT;
- struct fuse_open_out out;
- memset(&out, 0, sizeof(out));
+ fuse_open_out out = {};
out.fh = 10; // an arbitrary number; we always use the same handle
fuse_reply(fd, hdr->unique, &out, sizeof(out));
return NO_STATUS;
@@ -271,26 +257,22 @@
// time we've read this block).
// - Otherwise, return -EINVAL for the read.
- uint8_t hash[SHA256_DIGEST_LENGTH];
-#ifdef USE_MINCRYPT
- SHA256_hash(fd->block_data, fd->block_size, hash);
-#else
- SHA256(fd->block_data, fd->block_size, hash);
-#endif
- uint8_t* blockhash = fd->hashes + block * SHA256_DIGEST_LENGTH;
- if (memcmp(hash, blockhash, SHA256_DIGEST_LENGTH) == 0) {
+ SHA256Digest hash;
+ SHA256(fd->block_data, fd->block_size, hash.data());
+
+ const SHA256Digest& blockhash = fd->hashes[block];
+ if (hash == blockhash) {
return 0;
}
- int i;
- for (i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
- if (blockhash[i] != 0) {
+ for (uint8_t i : blockhash) {
+ if (i != 0) {
fd->curr_block = -1;
return -EIO;
}
}
- memcpy(blockhash, hash, SHA256_DIGEST_LENGTH);
+ fd->hashes[block] = hash;
return 0;
}
@@ -377,14 +359,8 @@
return -1;
}
-<<<<<<< HEAD:fuse_sideload.cpp
- fuse_data fd;
- memset(&fd, 0, sizeof(fd));
- fd.vtab = vtab;
-=======
fuse_data fd = {};
fd.provider = provider.get();
->>>>>>> android-10.0.0_r25:fuse_sideload/fuse_sideload.cpp
fd.file_size = file_size;
fd.block_size = block_size;
fd.file_blocks = (file_size == 0) ? 0 : (((file_size - 1) / block_size) + 1);
@@ -396,14 +372,8 @@
goto done;
}
- fd.hashes = (uint8_t*)calloc(fd.file_blocks, SHA256_DIGEST_LENGTH);
- if (fd.hashes == NULL) {
- fprintf(stderr, "failed to allocate %d bites for hashes\n",
- fd.file_blocks * SHA256_DIGEST_LENGTH);
- result = -1;
- goto done;
- }
-
+ // All hashes will be zero-initialized.
+ fd.hashes.resize(fd.file_blocks);
fd.uid = getuid();
fd.gid = getgid();
@@ -421,28 +391,21 @@
goto done;
}
-<<<<<<< HEAD:fuse_sideload.cpp
- fd.ffd = open("/dev/fuse", O_RDWR);
- if (!fd.ffd) {
-=======
fd.ffd.reset(open("/dev/fuse", O_RDWR));
if (fd.ffd == -1) {
->>>>>>> android-10.0.0_r25:fuse_sideload/fuse_sideload.cpp
perror("open /dev/fuse");
result = -1;
goto done;
}
{
- char opts[256];
- snprintf(opts, sizeof(opts),
- ("fd=%d,user_id=%d,group_id=%d,max_read=%u,"
- "allow_other,rootmode=040000"),
- fd.ffd, fd.uid, fd.gid, block_size);
+ std::string opts = android::base::StringPrintf(
+ "fd=%d,user_id=%d,group_id=%d,max_read=%u,allow_other,rootmode=040000", fd.ffd.get(),
+ fd.uid, fd.gid, block_size);
- result = mount("/dev/fuse", FUSE_SIDELOAD_HOST_MOUNTPOINT, "fuse",
- MS_NOSUID | MS_NODEV | MS_RDONLY | MS_NOEXEC, opts);
- if (result < 0) {
+ result = mount("/dev/fuse", mount_point, "fuse", MS_NOSUID | MS_NODEV | MS_RDONLY | MS_NOEXEC,
+ opts.c_str());
+ if (result == -1) {
perror("mount");
goto done;
}
@@ -530,9 +493,3 @@
return result;
}
-
-extern "C" int run_old_fuse_sideload(const struct provider_vtab& vtab, void* cookie __unused,
- uint64_t file_size, uint32_t block_size)
-{
- return run_fuse_sideload(vtab, file_size, block_size, FUSE_SIDELOAD_HOST_MOUNTPOINT);
-}