From 5e6832a24d39f15261be0cad19708274db57a126 Mon Sep 17 00:00:00 2001 From: xunchang Date: Fri, 15 Mar 2019 16:04:32 -0700 Subject: Remove the provider_vtab It's no longer needed with the newly added FuseDataProvider class. Also cleans up the parameters for run_fuse_sideload. Bug: 127071893 Test: unit tests pass, run a sideload Change-Id: I1ccd6798d187cfc6ac9f559ffb3f3edf08dad55c --- fuse_sideload/fuse_sideload.cpp | 16 +++++++++------- fuse_sideload/include/fuse_provider.h | 2 +- fuse_sideload/include/fuse_sideload.h | 14 ++++---------- 3 files changed, 14 insertions(+), 18 deletions(-) (limited to 'fuse_sideload') diff --git a/fuse_sideload/fuse_sideload.cpp b/fuse_sideload/fuse_sideload.cpp index e812486f8..b5b6ac15e 100644 --- a/fuse_sideload/fuse_sideload.cpp +++ b/fuse_sideload/fuse_sideload.cpp @@ -76,7 +76,7 @@ using SHA256Digest = std::array; 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 @@ -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. @@ -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; } @@ -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&& 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); @@ -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); @@ -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)); diff --git a/fuse_sideload/include/fuse_provider.h b/fuse_sideload/include/fuse_provider.h index 672af0577..499d57aa0 100644 --- a/fuse_sideload/include/fuse_provider.h +++ b/fuse_sideload/include/fuse_provider.h @@ -37,7 +37,7 @@ class FuseDataProvider { return fuse_block_size_; } - explicit operator bool() const { + bool Valid() const { return fd_ != -1; } diff --git a/fuse_sideload/include/fuse_sideload.h b/fuse_sideload/include/fuse_sideload.h index 821c7c808..1b7759a7f 100644 --- a/fuse_sideload/include/fuse_sideload.h +++ b/fuse_sideload/include/fuse_sideload.h @@ -17,7 +17,9 @@ #ifndef __FUSE_SIDELOAD_H #define __FUSE_SIDELOAD_H -#include +#include + +#include "fuse_provider.h" // Define the filenames created by the sideload FUSE filesystem. static constexpr const char* FUSE_SIDELOAD_HOST_MOUNTPOINT = "/sideload"; @@ -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 read_block; - - // close down - std::function close; -}; - -int run_fuse_sideload(const provider_vtab& vtab, uint64_t file_size, uint32_t block_size, +int run_fuse_sideload(std::unique_ptr&& provider, const char* mount_point = FUSE_SIDELOAD_HOST_MOUNTPOINT); #endif -- cgit v1.2.3