diff options
author | Tianjie Xu <xunchang@google.com> | 2019-03-19 21:52:17 +0100 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-03-19 21:52:17 +0100 |
commit | 4aa4bf5e196602c2a852b813f02637b98362f1ba (patch) | |
tree | 874f99533dc317f106ba4da4e955713c5ff46051 /minadbd/fuse_adb_provider.cpp | |
parent | Merge "Skip calling verify_package_compatibility when resuming." (diff) | |
parent | Merge "Create a FuseDataProvider base class" (diff) | |
download | android_bootable_recovery-4aa4bf5e196602c2a852b813f02637b98362f1ba.tar android_bootable_recovery-4aa4bf5e196602c2a852b813f02637b98362f1ba.tar.gz android_bootable_recovery-4aa4bf5e196602c2a852b813f02637b98362f1ba.tar.bz2 android_bootable_recovery-4aa4bf5e196602c2a852b813f02637b98362f1ba.tar.lz android_bootable_recovery-4aa4bf5e196602c2a852b813f02637b98362f1ba.tar.xz android_bootable_recovery-4aa4bf5e196602c2a852b813f02637b98362f1ba.tar.zst android_bootable_recovery-4aa4bf5e196602c2a852b813f02637b98362f1ba.zip |
Diffstat (limited to 'minadbd/fuse_adb_provider.cpp')
-rw-r--r-- | minadbd/fuse_adb_provider.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/minadbd/fuse_adb_provider.cpp b/minadbd/fuse_adb_provider.cpp index 9bd3f2392..cada4bd2a 100644 --- a/minadbd/fuse_adb_provider.cpp +++ b/minadbd/fuse_adb_provider.cpp @@ -27,30 +27,32 @@ #include "adb_io.h" #include "fuse_sideload.h" -int read_block_adb(const adb_data& ad, uint32_t block, uint8_t* buffer, uint32_t fetch_size) { - if (!WriteFdFmt(ad.sfd, "%08u", block)) { +bool FuseAdbDataProvider::ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size, + uint32_t start_block) const { + if (!WriteFdFmt(fd_, "%08u", start_block)) { fprintf(stderr, "failed to write to adb host: %s\n", strerror(errno)); - return -EIO; + return false; } - if (!ReadFdExactly(ad.sfd, buffer, fetch_size)) { + if (!ReadFdExactly(fd_, buffer, fetch_size)) { fprintf(stderr, "failed to read from adb host: %s\n", strerror(errno)); - return -EIO; + return false; } - return 0; + return true; } -int run_adb_fuse(int sfd, uint64_t file_size, uint32_t block_size) { - adb_data ad; - ad.sfd = sfd; - ad.file_size = file_size; - ad.block_size = block_size; +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(read_block_adb, ad, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3); - vtab.close = [&ad]() { WriteFdExactly(ad.sfd, "DONEDONE"); }; + 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); } |