summaryrefslogtreecommitdiffstats
path: root/minadbd/fuse_adb_provider.cpp
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2019-03-19 21:56:19 +0100
committerandroid-build-merger <android-build-merger@google.com>2019-03-19 21:56:19 +0100
commit77a2ff12d7365c7c1f31e1f7943018404ad728ae (patch)
tree874f99533dc317f106ba4da4e955713c5ff46051 /minadbd/fuse_adb_provider.cpp
parentMerge "Skip calling verify_package_compatibility when resuming." am: 98beb6414b (diff)
parentMerge "Create a FuseDataProvider base class" (diff)
downloadandroid_bootable_recovery-77a2ff12d7365c7c1f31e1f7943018404ad728ae.tar
android_bootable_recovery-77a2ff12d7365c7c1f31e1f7943018404ad728ae.tar.gz
android_bootable_recovery-77a2ff12d7365c7c1f31e1f7943018404ad728ae.tar.bz2
android_bootable_recovery-77a2ff12d7365c7c1f31e1f7943018404ad728ae.tar.lz
android_bootable_recovery-77a2ff12d7365c7c1f31e1f7943018404ad728ae.tar.xz
android_bootable_recovery-77a2ff12d7365c7c1f31e1f7943018404ad728ae.tar.zst
android_bootable_recovery-77a2ff12d7365c7c1f31e1f7943018404ad728ae.zip
Diffstat (limited to 'minadbd/fuse_adb_provider.cpp')
-rw-r--r--minadbd/fuse_adb_provider.cpp30
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);
}