undo temporary alignment hack
Remove the memory alignment that mysteriously made OTA installs work, in anticipation of a kernel that fixes the actual problem. Handle EINTR properly.
This commit is contained in:
46
minzip/Zip.c
46
minzip/Zip.c
@@ -12,7 +12,6 @@
|
|||||||
#include <stdint.h> // for uintptr_t
|
#include <stdint.h> // for uintptr_t
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h> // for S_ISLNK()
|
#include <sys/stat.h> // for S_ISLNK()
|
||||||
#include <sys/statfs.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define LOG_TAG "minzip"
|
#define LOG_TAG "minzip"
|
||||||
@@ -85,12 +84,6 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* The maximum zipped file write size we will align. */
|
|
||||||
#define WRITE_SIZE 32768
|
|
||||||
/* The boundary on which we will align it. */
|
|
||||||
#define WRITE_ALIGNMENT 32768
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For debugging, dump the contents of a ZipEntry.
|
* For debugging, dump the contents of a ZipEntry.
|
||||||
*/
|
*/
|
||||||
@@ -779,36 +772,18 @@ bool mzReadZipEntry(const ZipArchive* pArchive, const ZipEntry* pEntry,
|
|||||||
static bool writeProcessFunction(const unsigned char *data, int dataLen,
|
static bool writeProcessFunction(const unsigned char *data, int dataLen,
|
||||||
void *cookie)
|
void *cookie)
|
||||||
{
|
{
|
||||||
WriteInfo *wi = (WriteInfo*)cookie;
|
int fd = (int)cookie;
|
||||||
|
|
||||||
if (dataLen <= WRITE_SIZE) {
|
|
||||||
memcpy(wi->aligned_buffer, data, dataLen);
|
|
||||||
data = wi->aligned_buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t soFar = 0;
|
ssize_t soFar = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
ssize_t n = write(wi->fd, data+soFar, dataLen-soFar);
|
ssize_t n = write(fd, data+soFar, dataLen-soFar);
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
LOGE("Error writing %ld bytes from zip file from %p: %s\n",
|
LOGE("Error writing %ld bytes from zip file from %p: %s\n",
|
||||||
dataLen-soFar, data+soFar, strerror(errno));
|
dataLen-soFar, data+soFar, strerror(errno));
|
||||||
if (errno == ENOSPC) {
|
if (errno != EINTR) {
|
||||||
struct statfs sf;
|
return false;
|
||||||
if (statfs("/system", &sf) != 0) {
|
|
||||||
LOGE("failed to statfs /system: %s\n", strerror(errno));
|
|
||||||
} else {
|
|
||||||
LOGE("statfs said: %ld * %ld = %ld\n",
|
|
||||||
(long)sf.f_bsize, (long)sf.f_bfree,
|
|
||||||
(long)sf.f_bsize * (long)sf.f_bfree);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
} else if (n > 0) {
|
} else if (n > 0) {
|
||||||
if (n < dataLen-soFar) {
|
|
||||||
LOGE("short write: %d bytes of %d from %p\n",
|
|
||||||
(int)n, (int)(dataLen-soFar),
|
|
||||||
data+soFar);
|
|
||||||
}
|
|
||||||
soFar += n;
|
soFar += n;
|
||||||
if (soFar == dataLen) return true;
|
if (soFar == dataLen) return true;
|
||||||
if (soFar > dataLen) {
|
if (soFar > dataLen) {
|
||||||
@@ -824,10 +799,10 @@ static bool writeProcessFunction(const unsigned char *data, int dataLen,
|
|||||||
* Uncompress "pEntry" in "pArchive" to "fd" at the current offset.
|
* Uncompress "pEntry" in "pArchive" to "fd" at the current offset.
|
||||||
*/
|
*/
|
||||||
bool mzExtractZipEntryToFile(const ZipArchive *pArchive,
|
bool mzExtractZipEntryToFile(const ZipArchive *pArchive,
|
||||||
const ZipEntry *pEntry, WriteInfo *wi)
|
const ZipEntry *pEntry, int fd)
|
||||||
{
|
{
|
||||||
bool ret = mzProcessZipEntryContents(pArchive, pEntry, writeProcessFunction,
|
bool ret = mzProcessZipEntryContents(pArchive, pEntry, writeProcessFunction,
|
||||||
wi);
|
(void*)fd);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
LOGE("Can't extract entry to file.\n");
|
LOGE("Can't extract entry to file.\n");
|
||||||
return false;
|
return false;
|
||||||
@@ -929,11 +904,6 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* buffer = malloc(WRITE_SIZE+WRITE_ALIGNMENT);
|
|
||||||
WriteInfo wi;
|
|
||||||
wi.aligned_buffer = buffer + WRITE_ALIGNMENT -
|
|
||||||
((long)buffer % WRITE_ALIGNMENT);
|
|
||||||
|
|
||||||
unsigned int zipDirLen;
|
unsigned int zipDirLen;
|
||||||
char *zpath;
|
char *zpath;
|
||||||
|
|
||||||
@@ -1114,8 +1084,7 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wi.fd = fd;
|
bool ok = mzExtractZipEntryToFile(pArchive, pEntry, fd);
|
||||||
bool ok = mzExtractZipEntryToFile(pArchive, pEntry, &wi);
|
|
||||||
close(fd);
|
close(fd);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE("Error extracting \"%s\"\n", targetFile);
|
LOGE("Error extracting \"%s\"\n", targetFile);
|
||||||
@@ -1138,7 +1107,6 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
|
|||||||
|
|
||||||
free(helper.buf);
|
free(helper.buf);
|
||||||
free(zpath);
|
free(zpath);
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|||||||
10
minzip/Zip.h
10
minzip/Zip.h
@@ -55,14 +55,6 @@ typedef struct {
|
|||||||
size_t len;
|
size_t len;
|
||||||
} UnterminatedString;
|
} UnterminatedString;
|
||||||
|
|
||||||
/*
|
|
||||||
* The information we pass down to writeProcessFunction.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
int fd;
|
|
||||||
unsigned char* aligned_buffer;
|
|
||||||
} WriteInfo;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open a Zip archive.
|
* Open a Zip archive.
|
||||||
*
|
*
|
||||||
@@ -174,7 +166,7 @@ bool mzIsZipEntryIntact(const ZipArchive *pArchive, const ZipEntry *pEntry);
|
|||||||
* Inflate and write an entry to a file.
|
* Inflate and write an entry to a file.
|
||||||
*/
|
*/
|
||||||
bool mzExtractZipEntryToFile(const ZipArchive *pArchive,
|
bool mzExtractZipEntryToFile(const ZipArchive *pArchive,
|
||||||
const ZipEntry *pEntry, WriteInfo *wi);
|
const ZipEntry *pEntry, int fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inflate all entries under zipDir to the directory specified by
|
* Inflate all entries under zipDir to the directory specified by
|
||||||
|
|||||||
Reference in New Issue
Block a user