summaryrefslogtreecommitdiffstats
path: root/updater/blockimg.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-03-28 00:12:48 +0200
committerTao Bao <tbao@google.com>2017-03-28 19:13:38 +0200
commitf7eb760fe76cb66c5d5341b03d6a66cc1f06d795 (patch)
tree150376048a310df4ac1f873bdf487ad9edf15e2d /updater/blockimg.cpp
parentMerge "updater: Clean up LoadSrcTgtVersion2()." (diff)
downloadandroid_bootable_recovery-f7eb760fe76cb66c5d5341b03d6a66cc1f06d795.tar
android_bootable_recovery-f7eb760fe76cb66c5d5341b03d6a66cc1f06d795.tar.gz
android_bootable_recovery-f7eb760fe76cb66c5d5341b03d6a66cc1f06d795.tar.bz2
android_bootable_recovery-f7eb760fe76cb66c5d5341b03d6a66cc1f06d795.tar.lz
android_bootable_recovery-f7eb760fe76cb66c5d5341b03d6a66cc1f06d795.tar.xz
android_bootable_recovery-f7eb760fe76cb66c5d5341b03d6a66cc1f06d795.tar.zst
android_bootable_recovery-f7eb760fe76cb66c5d5341b03d6a66cc1f06d795.zip
Diffstat (limited to 'updater/blockimg.cpp')
-rw-r--r--updater/blockimg.cpp81
1 files changed, 40 insertions, 41 deletions
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index 1cad6da92..5a27ff41a 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -240,57 +240,56 @@ struct RangeSinkState {
size_t p_remain;
};
-static ssize_t RangeSinkWrite(const uint8_t* data, ssize_t size, void* token) {
- RangeSinkState* rss = reinterpret_cast<RangeSinkState*>(token);
+static size_t RangeSinkWrite(const uint8_t* data, size_t size, void* token) {
+ RangeSinkState* rss = static_cast<RangeSinkState*>(token);
- if (rss->p_remain == 0) {
- LOG(ERROR) << "range sink write overrun";
- return 0;
- }
-
- ssize_t written = 0;
- while (size > 0) {
- size_t write_now = size;
-
- if (rss->p_remain < write_now) {
- write_now = rss->p_remain;
- }
+ if (rss->p_remain == 0) {
+ LOG(ERROR) << "range sink write overrun";
+ return 0;
+ }
- if (write_all(rss->fd, data, write_now) == -1) {
- break;
- }
+ size_t written = 0;
+ while (size > 0) {
+ size_t write_now = size;
- data += write_now;
- size -= write_now;
+ if (rss->p_remain < write_now) {
+ write_now = rss->p_remain;
+ }
- rss->p_remain -= write_now;
- written += write_now;
+ if (write_all(rss->fd, data, write_now) == -1) {
+ break;
+ }
- if (rss->p_remain == 0) {
- // move to the next block
- ++rss->p_block;
- if (rss->p_block < rss->tgt.count) {
- rss->p_remain = (rss->tgt.pos[rss->p_block * 2 + 1] -
- rss->tgt.pos[rss->p_block * 2]) * BLOCKSIZE;
+ data += write_now;
+ size -= write_now;
- off64_t offset = static_cast<off64_t>(rss->tgt.pos[rss->p_block*2]) * BLOCKSIZE;
- if (!discard_blocks(rss->fd, offset, rss->p_remain)) {
- break;
- }
+ rss->p_remain -= write_now;
+ written += write_now;
- if (!check_lseek(rss->fd, offset, SEEK_SET)) {
- break;
- }
+ if (rss->p_remain == 0) {
+ // Move to the next block.
+ ++rss->p_block;
+ if (rss->p_block < rss->tgt.count) {
+ rss->p_remain =
+ (rss->tgt.pos[rss->p_block * 2 + 1] - rss->tgt.pos[rss->p_block * 2]) * BLOCKSIZE;
+
+ off64_t offset = static_cast<off64_t>(rss->tgt.pos[rss->p_block * 2]) * BLOCKSIZE;
+ if (!discard_blocks(rss->fd, offset, rss->p_remain)) {
+ break;
+ }
- } else {
- // we can't write any more; return how many bytes have
- // been written so far.
- break;
- }
+ if (!check_lseek(rss->fd, offset, SEEK_SET)) {
+ break;
}
+
+ } else {
+ // We can't write any more; return how many bytes have been written so far.
+ break;
+ }
}
+ }
- return written;
+ return written;
}
// All of the data for all the 'new' transfers is contained in one
@@ -338,7 +337,7 @@ static bool receive_new_data(const uint8_t* data, size_t size, void* cookie) {
// At this point nti->rss is set, and we own it. The main
// thread is waiting for it to disappear from nti.
- ssize_t written = RangeSinkWrite(data, size, nti->rss);
+ size_t written = RangeSinkWrite(data, size, nti->rss);
data += written;
size -= written;