summaryrefslogtreecommitdiffstats
path: root/fastboot
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-03-18 23:12:44 -0700
committerElliott Hughes <enh@google.com>2015-03-18 23:23:11 -0700
commitd30ad8a2eeefc382e898f2130d0be9461eed0bd9 (patch)
tree0461b35509b5422c3a1aec46b43db7ac167da27a /fastboot
parent253c18d2fbab6c16886af8bdfd528df3ebf82b93 (diff)
downloadsystem_core-d30ad8a2eeefc382e898f2130d0be9461eed0bd9.zip
system_core-d30ad8a2eeefc382e898f2130d0be9461eed0bd9.tar.gz
system_core-d30ad8a2eeefc382e898f2130d0be9461eed0bd9.tar.bz2
Switch fastboot to libziparchive.
Bug: 19765860 Change-Id: I83ea56e3b317893995d7106852b65584f99c0e64
Diffstat (limited to 'fastboot')
-rw-r--r--fastboot/Android.mk6
-rw-r--r--fastboot/fastboot.cpp42
2 files changed, 22 insertions, 26 deletions
diff --git a/fastboot/Android.mk b/fastboot/Android.mk
index 9cb002f..b9e957f 100644
--- a/fastboot/Android.mk
+++ b/fastboot/Android.mk
@@ -23,7 +23,7 @@ LOCAL_SRC_FILES := protocol.c engine.c bootimg_utils.cpp fastboot.cpp util.c fs.
LOCAL_MODULE := fastboot
LOCAL_MODULE_TAGS := debug
LOCAL_CONLYFLAGS += -std=gnu99
-LOCAL_CFLAGS += -Wall -Werror
+LOCAL_CFLAGS += -Wall -Wextra -Werror
ifeq ($(HOST_OS),linux)
LOCAL_SRC_FILES += usb_linux.c util_linux.c
@@ -53,9 +53,11 @@ endif
LOCAL_STATIC_LIBRARIES := \
$(EXTRA_STATIC_LIBS) \
- libzipfile \
+ libziparchive-host \
libext4_utils_host \
libsparse_host \
+ libutils \
+ liblog \
libz
ifneq ($(HOST_OS),windows)
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 04f3166..2c28139 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -45,7 +45,7 @@
#include <unistd.h>
#include <sparse/sparse.h>
-#include <zipfile/zipfile.h>
+#include <ziparchive/zip_archive.h>
#include "bootimg_utils.h"
#include "fastboot.h"
@@ -379,29 +379,24 @@ void *load_bootable_image(const char *kernel, const char *ramdisk,
return bdata;
}
-static void *unzip_file(zipfile_t zip, const char *name, unsigned *sz)
+static void *unzip_file(ZipArchiveHandle zip, const char *name, unsigned *sz)
{
- void *data;
- zipentry_t entry;
- unsigned datasz;
-
- entry = lookup_zipentry(zip, name);
- if (entry == NULL) {
+ ZipEntryName zip_entry_name(name);
+ ZipEntry zip_entry;
+ if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
fprintf(stderr, "archive does not contain '%s'\n", name);
return 0;
}
- *sz = get_zipentry_size(entry);
+ *sz = zip_entry.uncompressed_length;
- datasz = *sz * 1.001;
- data = malloc(datasz);
-
- if(data == 0) {
+ uint8_t* data = reinterpret_cast<uint8_t*>(malloc(zip_entry.uncompressed_length));
+ if (data == NULL) {
fprintf(stderr, "failed to allocate %d bytes\n", *sz);
return 0;
}
- if (decompress_zipentry(entry, data, datasz)) {
+ if (ExtractToMemory(zip, &zip_entry, data, zip_entry.uncompressed_length) != 0) {
fprintf(stderr, "failed to unzip '%s' from archive\n", name);
free(data);
return 0;
@@ -410,7 +405,7 @@ static void *unzip_file(zipfile_t zip, const char *name, unsigned *sz)
return data;
}
-static int unzip_to_file(zipfile_t zip, char *name)
+static int unzip_to_file(ZipArchiveHandle zip, char *name)
{
int fd = fileno(tmpfile());
if (fd < 0) {
@@ -693,11 +688,10 @@ void do_flash(usb_handle *usb, const char *pname, const char *fname)
flash_buf(pname, &buf);
}
-void do_update_signature(zipfile_t zip, char *fn)
+void do_update_signature(ZipArchiveHandle zip, char *fn)
{
- void *data;
unsigned sz;
- data = unzip_file(zip, fn, &sz);
+ void* data = unzip_file(zip, fn, &sz);
if (data == 0) return;
fb_queue_download("signature", data, sz);
fb_queue_command("signature", "installing signature");
@@ -709,12 +703,10 @@ void do_update(usb_handle *usb, const char *filename, int erase_first)
fb_queue_query_save("product", cur_product, sizeof(cur_product));
- unsigned zsize;
- void* zdata = load_file(filename, &zsize);
- if (zdata == 0) die("failed to load '%s': %s", filename, strerror(errno));
-
- zipfile_t zip = init_zipfile(zdata, zsize);
- if (zip == 0) die("failed to access zipdata in '%s'");
+ ZipArchiveHandle zip;
+ if (OpenArchive(filename, &zip) != 0) {
+ die("failed to open zip file '%s': %s", filename, strerror(errno));
+ }
unsigned sz;
void* data = unzip_file(zip, "android-info.txt", &sz);
@@ -750,6 +742,8 @@ void do_update(usb_handle *usb, const char *filename, int erase_first)
* program exits.
*/
}
+
+ CloseArchive(zip);
}
void do_send_signature(char *fn)