diff options
author | Tao Bao <tbao@google.com> | 2017-03-28 21:11:06 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-03-28 21:11:06 +0200 |
commit | d4d9ef3941b074d1adb21b98b330991d40fc4cca (patch) | |
tree | 5f80e6c423b0206e0fceace93827191c965348d9 /updater/blockimg.cpp | |
parent | Merge "updater: Clean up LoadSrcTgtVersion2()." (diff) | |
parent | applypatch: Change the ssize_t length parameters to size_t. (diff) | |
download | android_bootable_recovery-d4d9ef3941b074d1adb21b98b330991d40fc4cca.tar android_bootable_recovery-d4d9ef3941b074d1adb21b98b330991d40fc4cca.tar.gz android_bootable_recovery-d4d9ef3941b074d1adb21b98b330991d40fc4cca.tar.bz2 android_bootable_recovery-d4d9ef3941b074d1adb21b98b330991d40fc4cca.tar.lz android_bootable_recovery-d4d9ef3941b074d1adb21b98b330991d40fc4cca.tar.xz android_bootable_recovery-d4d9ef3941b074d1adb21b98b330991d40fc4cca.tar.zst android_bootable_recovery-d4d9ef3941b074d1adb21b98b330991d40fc4cca.zip |
Diffstat (limited to '')
-rw-r--r-- | updater/blockimg.cpp | 81 |
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; |