summaryrefslogtreecommitdiffstats
path: root/minadbd/fuse_adb_provider.cpp
diff options
context:
space:
mode:
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);
}