diff options
author | Ethan Yonker <dees_troy@teamw.in> | 2015-10-09 18:15:26 +0200 |
---|---|---|
committer | Ethan Yonker <dees_troy@teamw.in> | 2015-10-09 18:15:29 +0200 |
commit | c798c9cd2486e0ff83776002c74f113677b10a84 (patch) | |
tree | d128a80cbc58e63a622fda2774e727611f9d2cd4 /applypatch | |
parent | Add TW_IGNORE_ABS_MT_TRACKING_ID (diff) | |
parent | merge in mnc-release history after reset to mnc-dev (diff) | |
download | android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.gz android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.bz2 android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.lz android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.xz android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.tar.zst android_bootable_recovery-c798c9cd2486e0ff83776002c74f113677b10a84.zip |
Diffstat (limited to 'applypatch')
-rw-r--r-- | applypatch/applypatch.c | 53 | ||||
-rw-r--r-- | applypatch/bspatch.c | 1 | ||||
-rw-r--r-- | applypatch/imgdiff.c | 9 | ||||
-rw-r--r-- | applypatch/imgpatch.c | 1 |
4 files changed, 39 insertions, 25 deletions
diff --git a/applypatch/applypatch.c b/applypatch/applypatch.c index 73195d96a..bc45e3c45 100644 --- a/applypatch/applypatch.c +++ b/applypatch/applypatch.c @@ -453,20 +453,19 @@ int WriteToPartition(unsigned char* data, size_t len, int attempt; for (attempt = 0; attempt < 2; ++attempt) { - lseek(fd, start, SEEK_SET); + if (TEMP_FAILURE_RETRY(lseek(fd, start, SEEK_SET)) == -1) { + printf("failed seek on %s: %s\n", + partition, strerror(errno)); + return -1; + } while (start < len) { size_t to_write = len - start; if (to_write > 1<<20) to_write = 1<<20; - ssize_t written = write(fd, data+start, to_write); - if (written < 0) { - if (errno == EINTR) { - written = 0; - } else { - printf("failed write writing to %s (%s)\n", - partition, strerror(errno)); - return -1; - } + ssize_t written = TEMP_FAILURE_RETRY(write(fd, data+start, to_write)); + if (written == -1) { + printf("failed write writing to %s: %s\n", partition, strerror(errno)); + return -1; } start += written; } @@ -491,13 +490,20 @@ int WriteToPartition(unsigned char* data, size_t len, // won't just be reading the cache. sync(); int dc = open("/proc/sys/vm/drop_caches", O_WRONLY); - write(dc, "3\n", 2); + if (TEMP_FAILURE_RETRY(write(dc, "3\n", 2)) == -1) { + printf("write to /proc/sys/vm/drop_caches failed: %s\n", strerror(errno)); + } else { + printf(" caches dropped\n"); + } close(dc); sleep(1); - printf(" caches dropped\n"); // verify - lseek(fd, 0, SEEK_SET); + if (TEMP_FAILURE_RETRY(lseek(fd, 0, SEEK_SET)) == -1) { + printf("failed to seek back to beginning of %s: %s\n", + partition, strerror(errno)); + return -1; + } unsigned char buffer[4096]; start = len; size_t p; @@ -507,15 +513,12 @@ int WriteToPartition(unsigned char* data, size_t len, size_t so_far = 0; while (so_far < to_read) { - ssize_t read_count = read(fd, buffer+so_far, to_read-so_far); - if (read_count < 0) { - if (errno == EINTR) { - read_count = 0; - } else { - printf("verify read error %s at %zu: %s\n", - partition, p, strerror(errno)); - return -1; - } + ssize_t read_count = + TEMP_FAILURE_RETRY(read(fd, buffer+so_far, to_read-so_far)); + if (read_count == -1) { + printf("verify read error %s at %zu: %s\n", + partition, p, strerror(errno)); + return -1; } if ((size_t)read_count < to_read) { printf("short verify read %s at %zu: %zd %zu %s\n", @@ -656,8 +659,8 @@ ssize_t FileSink(const unsigned char* data, ssize_t len, void* token) { ssize_t done = 0; ssize_t wrote; while (done < (ssize_t) len) { - wrote = write(fd, data+done, len-done); - if (wrote <= 0) { + wrote = TEMP_FAILURE_RETRY(write(fd, data+done, len-done)); + if (wrote == -1) { printf("error writing %d bytes: %s\n", (int)(len-done), strerror(errno)); return done; } @@ -690,7 +693,7 @@ size_t FreeSpaceForFile(const char* filename) { printf("failed to statfs %s: %s\n", filename, strerror(errno)); return -1; } - return sf.f_bsize * sf.f_bfree; + return sf.f_bsize * sf.f_bavail; } int CacheSizeCheck(size_t bytes) { diff --git a/applypatch/bspatch.c b/applypatch/bspatch.c index b34ec2a88..b57760eda 100644 --- a/applypatch/bspatch.c +++ b/applypatch/bspatch.c @@ -23,6 +23,7 @@ #include <stdio.h> #include <sys/stat.h> #include <errno.h> +#include <malloc.h> #include <unistd.h> #include <string.h> diff --git a/applypatch/imgdiff.c b/applypatch/imgdiff.c index 05c4f250f..3bac8be91 100644 --- a/applypatch/imgdiff.c +++ b/applypatch/imgdiff.c @@ -408,6 +408,7 @@ unsigned char* ReadImage(const char* filename, p[2] == 0x08 && // deflate compression p[3] == 0x00) { // no header flags // 'pos' is the offset of the start of a gzip chunk. + size_t chunk_offset = pos; *num_chunks += 3; *chunks = realloc(*chunks, *num_chunks * sizeof(ImageChunk)); @@ -453,6 +454,14 @@ unsigned char* ReadImage(const char* filename, strm.avail_out = allocated - curr->len; strm.next_out = curr->data + curr->len; ret = inflate(&strm, Z_NO_FLUSH); + if (ret < 0) { + printf("Error: inflate failed [%s] at file offset [%zu]\n" + "imgdiff only supports gzip kernel compression," + " did you try CONFIG_KERNEL_LZO?\n", + strm.msg, chunk_offset); + free(img); + return NULL; + } curr->len = allocated - strm.avail_out; if (strm.avail_out == 0) { allocated *= 2; diff --git a/applypatch/imgpatch.c b/applypatch/imgpatch.c index 33c448762..09b0a7397 100644 --- a/applypatch/imgpatch.c +++ b/applypatch/imgpatch.c @@ -21,6 +21,7 @@ #include <sys/cdefs.h> #include <sys/stat.h> #include <errno.h> +#include <malloc.h> #include <unistd.h> #include <string.h> |