X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/663888501e27e6bfcd01bd0f43620b9d08cd2b7b..7bfbd75115d54d77df68ff865162f69283e7c7fe:/package/openwrt/jffs2root.c?ds=sidebyside diff --git a/package/openwrt/jffs2root.c b/package/openwrt/jffs2root.c index e74c89a9b..140c8a6e0 100644 --- a/package/openwrt/jffs2root.c +++ b/package/openwrt/jffs2root.c @@ -3,8 +3,6 @@ * * Copyright (C) 2005 Mike Baker * - * $Id$ - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 @@ -19,6 +17,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * $Id$ + * */ #include @@ -48,7 +48,10 @@ void init_crc32() unsigned long crc; unsigned long poly = 0xEDB88320L; int n, bit; - crc32 = (unsigned long *) malloc(256 * sizeof(unsigned long)); + if ((crc32 = (unsigned long *) malloc(256 * sizeof(unsigned long))) == (void *)-1) { + perror("malloc"); + exit(1); + } for (n = 0; n < 256; n++) { crc = (unsigned long) n; for (bit = 0; bit < 8; bit++) @@ -70,6 +73,8 @@ int main(int argc, char **argv) int fd; unsigned long len; struct trx_header *ptr; + unsigned offset; + if (((fd = open(FILENAME, O_RDWR)) < 0) || ((len = lseek(fd, 0, SEEK_END)) < 0) || ((ptr = (struct trx_header *) mmap(0, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1)) @@ -78,17 +83,22 @@ int main(int argc, char **argv) exit(-1); } + /* treat last partition as rootfs offset */ + offset = ptr->offsets[2] ? : ptr->offsets[1]; + if (argc > 1 && !strcmp(argv[1],"--move")) { - if (ptr->offsets[1] >= ptr->len) { + if (offset >= ptr->len) { printf("Partition already moved outside trx\n"); - } else if (ptr->offsets[1] & 0x0001ffff) { +#if 0 + } else if (offset & 0x0001ffff) { printf("Partition does not start on a block boundary\n"); +#endif } else { init_crc32(); - bzero((void *)((int)ptr + ptr->len), (size_t)(len - ptr->len)); - ptr->len = ptr->offsets[1]; + //bzero((void *)((int)ptr + ptr->len), (size_t)(len - ptr->len)); + ptr->len = offset; ptr->crc32 = crc32buf((void *) &(ptr->flag_version), ptr->len - offsetof(struct trx_header, flag_version)); - msync(ptr,len,MS_SYNC|MS_INVALIDATE); + msync(ptr,sizeof(struct trx_header),MS_SYNC|MS_INVALIDATE); printf("Partition moved; please reboot\n"); } } else { @@ -103,6 +113,7 @@ int main(int argc, char **argv) } - munmap((void *) ptr, sizeof(struct trx_header)); + munmap((void *) ptr, len); + close (fd); return 0; }