summaryrefslogtreecommitdiffstats
path: root/updater/blockimg.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-03-28 21:31:31 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-03-28 21:31:31 +0200
commitc1966bd6b9609ed14b91dd96e00d20e222595ccf (patch)
tree4795145050d9337cb240ce05f3cbae88783d51f9 /updater/blockimg.cpp
parentMerge "updater: Clean up LoadSrcTgtVersion2()." am: f037b7b535 am: 51159a069d am: 21b5268fbd (diff)
parentapplypatch: Change the ssize_t length parameters to size_t. am: f7eb760fe7 am: d4d9ef3941 (diff)
downloadandroid_bootable_recovery-c1966bd6b9609ed14b91dd96e00d20e222595ccf.tar
android_bootable_recovery-c1966bd6b9609ed14b91dd96e00d20e222595ccf.tar.gz
android_bootable_recovery-c1966bd6b9609ed14b91dd96e00d20e222595ccf.tar.bz2
android_bootable_recovery-c1966bd6b9609ed14b91dd96e00d20e222595ccf.tar.lz
android_bootable_recovery-c1966bd6b9609ed14b91dd96e00d20e222595ccf.tar.xz
android_bootable_recovery-c1966bd6b9609ed14b91dd96e00d20e222595ccf.tar.zst
android_bootable_recovery-c1966bd6b9609ed14b91dd96e00d20e222595ccf.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;