Loading fuse_sdcard_install.cpp +4 −9 Original line number Diff line number Diff line Loading @@ -20,26 +20,21 @@ #include <unistd.h> #include <functional> #include <memory> #include "fuse_provider.h" #include "fuse_sideload.h" bool start_sdcard_fuse(const char* path) { FuseFileDataProvider file_data_reader(path, 65536); auto file_data_reader = std::make_unique<FuseFileDataProvider>(path, 65536); if (!file_data_reader) { if (!file_data_reader->Valid()) { return false; } provider_vtab vtab; vtab.read_block = std::bind(&FuseFileDataProvider::ReadBlockAlignedData, &file_data_reader, std::placeholders::_2, std::placeholders::_3, std::placeholders::_1); vtab.close = [&file_data_reader]() { file_data_reader.Close(); }; // The installation process expects to find the sdcard unmounted. Unmount it with MNT_DETACH so // that our open file continues to work but new references see it as unmounted. umount2("/sdcard", MNT_DETACH); return run_fuse_sideload(vtab, file_data_reader.file_size(), file_data_reader.fuse_block_size()) == 0; return run_fuse_sideload(std::move(file_data_reader)) == 0; } fuse_sideload/fuse_sideload.cpp +9 −7 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ using SHA256Digest = std::array<uint8_t, SHA256_DIGEST_LENGTH>; struct fuse_data { android::base::unique_fd ffd; // file descriptor for the fuse socket provider_vtab vtab; FuseDataProvider* provider; // Provider of the source data. uint64_t file_size; // bytes Loading Loading @@ -236,7 +236,7 @@ static int fetch_block(fuse_data* fd, uint32_t block) { return 0; } size_t fetch_size = fd->block_size; uint32_t fetch_size = fd->block_size; if (block * fd->block_size + fetch_size > fd->file_size) { // If we're reading the last (partial) block of the file, expect a shorter response from the // host, and pad the rest of the block with zeroes. Loading @@ -244,7 +244,7 @@ static int fetch_block(fuse_data* fd, uint32_t block) { memset(fd->block_data + fetch_size, 0, fd->block_size - fetch_size); } if (!fd->vtab.read_block(block, fd->block_data, fetch_size)) { if (!fd->provider->ReadBlockAlignedData(fd->block_data, fetch_size, block)) { return -EIO; } Loading Loading @@ -341,12 +341,14 @@ static int handle_read(void* data, fuse_data* fd, const fuse_in_header* hdr) { return NO_STATUS; } int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t block_size, const char* mount_point) { int run_fuse_sideload(std::unique_ptr<FuseDataProvider>&& provider, const char* mount_point) { // If something's already mounted on our mountpoint, try to remove it. (Mostly in case of a // previous abnormal exit.) umount2(mount_point, MNT_FORCE); uint64_t file_size = provider->file_size(); uint32_t block_size = provider->fuse_block_size(); // fs/fuse/inode.c in kernel code uses the greater of 4096 and the passed-in max_read. if (block_size < 4096) { fprintf(stderr, "block size (%u) is too small\n", block_size); Loading @@ -358,7 +360,7 @@ int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t bl } fuse_data fd = {}; fd.vtab = vtab; fd.provider = provider.get(); fd.file_size = file_size; fd.block_size = block_size; fd.file_blocks = (file_size == 0) ? 0 : (((file_size - 1) / block_size) + 1); Loading Loading @@ -480,7 +482,7 @@ int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t bl } done: fd.vtab.close(); provider->Close(); if (umount2(mount_point, MNT_DETACH) == -1) { fprintf(stderr, "fuse_sideload umount failed: %s\n", strerror(errno)); Loading fuse_sideload/include/fuse_provider.h +1 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ class FuseDataProvider { return fuse_block_size_; } explicit operator bool() const { bool Valid() const { return fd_ != -1; } Loading fuse_sideload/include/fuse_sideload.h +4 −10 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ #ifndef __FUSE_SIDELOAD_H #define __FUSE_SIDELOAD_H #include <functional> #include <memory> #include "fuse_provider.h" // Define the filenames created by the sideload FUSE filesystem. static constexpr const char* FUSE_SIDELOAD_HOST_MOUNTPOINT = "/sideload"; Loading @@ -26,15 +28,7 @@ static constexpr const char* FUSE_SIDELOAD_HOST_PATHNAME = "/sideload/package.zi static constexpr const char* FUSE_SIDELOAD_HOST_EXIT_FLAG = "exit"; static constexpr const char* FUSE_SIDELOAD_HOST_EXIT_PATHNAME = "/sideload/exit"; struct provider_vtab { // read a block std::function<bool(uint32_t block, uint8_t* buffer, uint32_t fetch_size)> read_block; // close down std::function<void(void)> close; }; int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t block_size, int run_fuse_sideload(std::unique_ptr<FuseDataProvider>&& provider, const char* mount_point = FUSE_SIDELOAD_HOST_MOUNTPOINT); #endif minadbd/fuse_adb_provider.cpp +0 −15 Original line number Diff line number Diff line Loading @@ -18,14 +18,10 @@ #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <functional> #include "adb.h" #include "adb_io.h" #include "fuse_sideload.h" bool FuseAdbDataProvider::ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size, uint32_t start_block) const { Loading @@ -45,14 +41,3 @@ bool FuseAdbDataProvider::ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_s void FuseAdbDataProvider::Close() { WriteFdExactly(fd_, "DONEDONE"); } int run_adb_fuse(android::base::unique_fd&& sfd, uint64_t file_size, uint32_t block_size) { FuseAdbDataProvider adb_data_reader(std::move(sfd), file_size, block_size); provider_vtab vtab; vtab.read_block = std::bind(&FuseAdbDataProvider::ReadBlockAlignedData, &adb_data_reader, std::placeholders::_2, std::placeholders::_3, std::placeholders::_1); vtab.close = [&adb_data_reader]() { adb_data_reader.Close(); }; return run_fuse_sideload(vtab, file_size, block_size); } Loading
fuse_sdcard_install.cpp +4 −9 Original line number Diff line number Diff line Loading @@ -20,26 +20,21 @@ #include <unistd.h> #include <functional> #include <memory> #include "fuse_provider.h" #include "fuse_sideload.h" bool start_sdcard_fuse(const char* path) { FuseFileDataProvider file_data_reader(path, 65536); auto file_data_reader = std::make_unique<FuseFileDataProvider>(path, 65536); if (!file_data_reader) { if (!file_data_reader->Valid()) { return false; } provider_vtab vtab; vtab.read_block = std::bind(&FuseFileDataProvider::ReadBlockAlignedData, &file_data_reader, std::placeholders::_2, std::placeholders::_3, std::placeholders::_1); vtab.close = [&file_data_reader]() { file_data_reader.Close(); }; // The installation process expects to find the sdcard unmounted. Unmount it with MNT_DETACH so // that our open file continues to work but new references see it as unmounted. umount2("/sdcard", MNT_DETACH); return run_fuse_sideload(vtab, file_data_reader.file_size(), file_data_reader.fuse_block_size()) == 0; return run_fuse_sideload(std::move(file_data_reader)) == 0; }
fuse_sideload/fuse_sideload.cpp +9 −7 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ using SHA256Digest = std::array<uint8_t, SHA256_DIGEST_LENGTH>; struct fuse_data { android::base::unique_fd ffd; // file descriptor for the fuse socket provider_vtab vtab; FuseDataProvider* provider; // Provider of the source data. uint64_t file_size; // bytes Loading Loading @@ -236,7 +236,7 @@ static int fetch_block(fuse_data* fd, uint32_t block) { return 0; } size_t fetch_size = fd->block_size; uint32_t fetch_size = fd->block_size; if (block * fd->block_size + fetch_size > fd->file_size) { // If we're reading the last (partial) block of the file, expect a shorter response from the // host, and pad the rest of the block with zeroes. Loading @@ -244,7 +244,7 @@ static int fetch_block(fuse_data* fd, uint32_t block) { memset(fd->block_data + fetch_size, 0, fd->block_size - fetch_size); } if (!fd->vtab.read_block(block, fd->block_data, fetch_size)) { if (!fd->provider->ReadBlockAlignedData(fd->block_data, fetch_size, block)) { return -EIO; } Loading Loading @@ -341,12 +341,14 @@ static int handle_read(void* data, fuse_data* fd, const fuse_in_header* hdr) { return NO_STATUS; } int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t block_size, const char* mount_point) { int run_fuse_sideload(std::unique_ptr<FuseDataProvider>&& provider, const char* mount_point) { // If something's already mounted on our mountpoint, try to remove it. (Mostly in case of a // previous abnormal exit.) umount2(mount_point, MNT_FORCE); uint64_t file_size = provider->file_size(); uint32_t block_size = provider->fuse_block_size(); // fs/fuse/inode.c in kernel code uses the greater of 4096 and the passed-in max_read. if (block_size < 4096) { fprintf(stderr, "block size (%u) is too small\n", block_size); Loading @@ -358,7 +360,7 @@ int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t bl } fuse_data fd = {}; fd.vtab = vtab; fd.provider = provider.get(); fd.file_size = file_size; fd.block_size = block_size; fd.file_blocks = (file_size == 0) ? 0 : (((file_size - 1) / block_size) + 1); Loading Loading @@ -480,7 +482,7 @@ int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t bl } done: fd.vtab.close(); provider->Close(); if (umount2(mount_point, MNT_DETACH) == -1) { fprintf(stderr, "fuse_sideload umount failed: %s\n", strerror(errno)); Loading
fuse_sideload/include/fuse_provider.h +1 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ class FuseDataProvider { return fuse_block_size_; } explicit operator bool() const { bool Valid() const { return fd_ != -1; } Loading
fuse_sideload/include/fuse_sideload.h +4 −10 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ #ifndef __FUSE_SIDELOAD_H #define __FUSE_SIDELOAD_H #include <functional> #include <memory> #include "fuse_provider.h" // Define the filenames created by the sideload FUSE filesystem. static constexpr const char* FUSE_SIDELOAD_HOST_MOUNTPOINT = "/sideload"; Loading @@ -26,15 +28,7 @@ static constexpr const char* FUSE_SIDELOAD_HOST_PATHNAME = "/sideload/package.zi static constexpr const char* FUSE_SIDELOAD_HOST_EXIT_FLAG = "exit"; static constexpr const char* FUSE_SIDELOAD_HOST_EXIT_PATHNAME = "/sideload/exit"; struct provider_vtab { // read a block std::function<bool(uint32_t block, uint8_t* buffer, uint32_t fetch_size)> read_block; // close down std::function<void(void)> close; }; int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t block_size, int run_fuse_sideload(std::unique_ptr<FuseDataProvider>&& provider, const char* mount_point = FUSE_SIDELOAD_HOST_MOUNTPOINT); #endif
minadbd/fuse_adb_provider.cpp +0 −15 Original line number Diff line number Diff line Loading @@ -18,14 +18,10 @@ #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <functional> #include "adb.h" #include "adb_io.h" #include "fuse_sideload.h" bool FuseAdbDataProvider::ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size, uint32_t start_block) const { Loading @@ -45,14 +41,3 @@ bool FuseAdbDataProvider::ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_s void FuseAdbDataProvider::Close() { WriteFdExactly(fd_, "DONEDONE"); } int run_adb_fuse(android::base::unique_fd&& sfd, uint64_t file_size, uint32_t block_size) { FuseAdbDataProvider adb_data_reader(std::move(sfd), file_size, block_size); provider_vtab vtab; vtab.read_block = std::bind(&FuseAdbDataProvider::ReadBlockAlignedData, &adb_data_reader, std::placeholders::_2, std::placeholders::_3, std::placeholders::_1); vtab.close = [&adb_data_reader]() { adb_data_reader.Close(); }; return run_fuse_sideload(vtab, file_size, block_size); }