summaryrefslogtreecommitdiffstats
path: root/updater/blockimg.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2015-06-24 08:23:33 +0200
committerTao Bao <tbao@google.com>2015-07-14 02:21:31 +0200
commitba9a42aa7e10686de186636fe9fecbf8c4cc7c19 (patch)
tree47a62ed3cf643578280ddb1982599ed8345dd071 /updater/blockimg.cpp
parentMerge "Revert "Zero blocks before BLKDISCARD"" (diff)
downloadandroid_bootable_recovery-ba9a42aa7e10686de186636fe9fecbf8c4cc7c19.tar
android_bootable_recovery-ba9a42aa7e10686de186636fe9fecbf8c4cc7c19.tar.gz
android_bootable_recovery-ba9a42aa7e10686de186636fe9fecbf8c4cc7c19.tar.bz2
android_bootable_recovery-ba9a42aa7e10686de186636fe9fecbf8c4cc7c19.tar.lz
android_bootable_recovery-ba9a42aa7e10686de186636fe9fecbf8c4cc7c19.tar.xz
android_bootable_recovery-ba9a42aa7e10686de186636fe9fecbf8c4cc7c19.tar.zst
android_bootable_recovery-ba9a42aa7e10686de186636fe9fecbf8c4cc7c19.zip
Diffstat (limited to '')
-rw-r--r--updater/blockimg.cpp (renamed from updater/blockimg.c)31
1 files changed, 14 insertions, 17 deletions
diff --git a/updater/blockimg.c b/updater/blockimg.cpp
index a6a389507..258d97552 100644
--- a/updater/blockimg.c
+++ b/updater/blockimg.cpp
@@ -19,6 +19,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <linux/fs.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
@@ -44,10 +45,6 @@
// erase to mean fill the region with zeroes.
#define DEBUG_ERASE 0
-#ifndef BLKDISCARD
-#define BLKDISCARD _IO(0x12,119)
-#endif
-
#define STASH_DIRECTORY_BASE "/cache/recovery"
#define STASH_DIRECTORY_MODE 0700
#define STASH_FILE_MODE 0600
@@ -66,7 +63,7 @@ typedef struct {
static RangeSet* parse_range(char* text) {
char* save;
char* token;
- int i, num;
+ int num;
long int val;
RangeSet* out = NULL;
size_t bufsize;
@@ -92,7 +89,7 @@ static RangeSet* parse_range(char* text) {
num = (int) val;
bufsize = sizeof(RangeSet) + num * sizeof(int);
- out = malloc(bufsize);
+ out = reinterpret_cast<RangeSet*>(malloc(bufsize));
if (!out) {
fprintf(stderr, "failed to allocate range of %zu bytes\n", bufsize);
@@ -102,7 +99,7 @@ static RangeSet* parse_range(char* text) {
out->count = num / 2;
out->size = 0;
- for (i = 0; i < num; ++i) {
+ for (int i = 0; i < num; ++i) {
token = strtok_r(NULL, ",", &save);
if (!token) {
@@ -477,7 +474,7 @@ static char* GetStashFileName(const char* base, const char* id, const char* post
}
len = strlen(STASH_DIRECTORY_BASE) + 1 + strlen(base) + 1 + strlen(id) + strlen(postfix) + 1;
- fn = malloc(len);
+ fn = reinterpret_cast<char*>(malloc(len));
if (fn == NULL) {
fprintf(stderr, "failed to malloc %d bytes for fn\n", len);
@@ -528,7 +525,7 @@ static void EnumerateStash(const char* dirname, StashCallback callback, void* da
}
len = strlen(dirname) + 1 + strlen(item->d_name) + 1;
- fn = malloc(len);
+ fn = reinterpret_cast<char*>(malloc(len));
if (fn == NULL) {
fprintf(stderr, "failed to malloc %d bytes for fn\n", len);
@@ -648,7 +645,8 @@ static int LoadStash(const char* base, const char* id, int verify, int* blocks,
fprintf(stderr, " loading %s\n", fn);
if ((st.st_size % BLOCKSIZE) != 0) {
- fprintf(stderr, "%s size %zd not multiple of block size %d", fn, st.st_size, BLOCKSIZE);
+ fprintf(stderr, "%s size %" PRId64 " not multiple of block size %d",
+ fn, static_cast<int64_t>(st.st_size), BLOCKSIZE);
goto lsout;
}
@@ -856,7 +854,6 @@ csout:
static int SaveStash(const char* base, char** wordsave, uint8_t** buffer, size_t* buffer_alloc,
int fd, int usehash, int* isunresumable) {
char *id = NULL;
- int res = -1;
int blocks = 0;
if (!wordsave || !buffer || !buffer_alloc || !isunresumable) {
@@ -952,7 +949,6 @@ static int LoadSrcTgtVersion2(char** wordsave, RangeSet** tgt, int* src_blocks,
char* word;
char* colonsave;
char* colon;
- int id;
int res;
RangeSet* locs;
size_t stashalloc = 0;
@@ -1068,7 +1064,6 @@ static int LoadSrcTgtVersion3(CommandParameters* params, RangeSet** tgt, int* sr
char* srchash = NULL;
char* tgthash = NULL;
int stash_exists = 0;
- int overlap_blocks = 0;
int rc = -1;
uint8_t* tgtbuffer = NULL;
@@ -1491,7 +1486,7 @@ static int PerformCommandErase(CommandParameters* params) {
range = strtok_r(NULL, " ", &params->cpos);
if (range == NULL) {
- fprintf(stderr, "missing target blocks for zero\n");
+ fprintf(stderr, "missing target blocks for erase\n");
goto pceout;
}
@@ -1666,7 +1661,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state, int argc,
// The data in transfer_list_value is not necessarily null-terminated, so we need
// to copy it to a new buffer and add the null that strtok_r will need.
- transfer_list = malloc(transfer_list_value->size + 1);
+ transfer_list = reinterpret_cast<char*>(malloc(transfer_list_value->size + 1));
if (transfer_list == NULL) {
fprintf(stderr, "failed to allocate %zd bytes for transfer list\n",
@@ -1944,13 +1939,15 @@ Value* RangeSha1Fn(const char* name, State* state, int argc, Expr* argv[]) {
goto done;
}
- int fd = open(blockdev_filename->data, O_RDWR);
+ int fd;
+ fd = open(blockdev_filename->data, O_RDWR);
if (fd < 0) {
ErrorAbort(state, "open \"%s\" failed: %s", blockdev_filename->data, strerror(errno));
goto done;
}
- RangeSet* rs = parse_range(ranges->data);
+ RangeSet* rs;
+ rs = parse_range(ranges->data);
uint8_t buffer[BLOCKSIZE];
SHA_CTX ctx;