Well, /dev/zero cannot be used like that...

This commit is contained in:
topjohnwu
2017-03-13 05:05:51 +08:00
parent 1442e29d0e
commit 7877ac0c3b
3 changed files with 11 additions and 13 deletions

View File

@@ -21,9 +21,6 @@ static void restore_buf(int fd, const void *buf, size_t size) {
}
void repack(const char* orig_image, const char* out_image) {
zero = open("/dev/zero", O_RDONLY);
if (zero < 0) error(1, "Cannot open /dev/zero");
size_t size;
unsigned char *orig;
char name[PATH_MAX];
@@ -51,12 +48,12 @@ void repack(const char* orig_image, const char* out_image) {
hdr.dt_size = 0;
// Skip a page for header
sendfile(fd, zero, NULL, hdr.page_size);
write_zero(fd, hdr.page_size);
// Restore kernel
if (mtk_kernel) {
mtk_kernel_off = lseek(fd, 0, SEEK_CUR);
sendfile(fd, zero, NULL, 512);
write_zero(fd, 512);
memcpy(&mtk_kernel_hdr, kernel, sizeof(mtk_kernel_hdr));
}
hdr.kernel_size = restore(KERNEL_FILE, fd);
@@ -65,7 +62,7 @@ void repack(const char* orig_image, const char* out_image) {
// Restore ramdisk
if (mtk_ramdisk) {
mtk_ramdisk_off = lseek(fd, 0, SEEK_CUR);
sendfile(fd, zero, NULL, 512);
write_zero(fd, 512);
memcpy(&mtk_ramdisk_hdr, ramdisk, sizeof(mtk_ramdisk_hdr));
}
if (access(RAMDISK_FILE, R_OK) == 0) {