On Tue, 11 Aug 2009 03:18:58 +0200
Felix Fietkau <n...@openwrt.org> wrote:

> Daniel Dickinson wrote:
> > Ticket #5652 now contains a patch, attached here, to fix the
> > following:

The updated patch is below.

> The patch looks wrong to me. sizeof on a constant string should return
> its length + 1 (for the null byte). In your patch however you use a
> length value of 3, which doesn't make any sense.
> Are you really sure that in your case it substitutes the sizeof
> expression with a value of 1 or is this a guess?

I misunderstood my C.  sizeof a constant array works and I thought it
didn't for some reason.  

Since it turns out I was wrong about sizeof, perhaps the problem was
the following line

if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF)) == 0) {

That would compare 5 bytes because of the null.


Index: package/mtd/src/mtd.c
===================================================================
--- package/mtd/src/mtd.c       (revision 17207)
+++ package/mtd/src/mtd.c       (working copy)
@@ -42,6 +42,7 @@
 #include <sys/stat.h>
 #include <sys/reboot.h>
 #include <linux/reboot.h>
+#include <arpa/inet.h>
 #include "mtd-api.h"
 #include "mtd.h"
 
@@ -248,6 +249,7 @@
 {
        int fd, result;
        ssize_t r, w, e;
+       uint32_t jffs2_eof_magic = htonl(JFFS2_EOF);
 
        fd = mtd_check_open(mtd);
        if(fd < 0) {
@@ -285,11 +287,11 @@
                        break;
 
                if (jffs2file) {
-                       if (memcmp(buf, JFFS2_EOF, sizeof(JFFS2_EOF))
== 0) {
+                       if (memcmp(buf, &jffs2_eof_magic,
sizeof(jffs2_eof_magic)) == 0) { if (!quiet)
                                        fprintf(stderr, "\b\b\b   ");
                                if (quiet < 2)
-                                       fprintf(stderr, "\nAppending
jffs2 data to from %s to %s...", jffs2file, mtd);
+                                       fprintf(stderr, "\nAppending
jffs2 data from %s to %s...", jffs2file, mtd); /* got an EOF marker -
this is the place to add some jffs2 data */ mtd_replace_jffs2(mtd, fd,
e, jffs2file); goto done;
Index: package/mtd/src/mtd.h
===================================================================
--- package/mtd/src/mtd.h       (revision 17207)
+++ package/mtd/src/mtd.h       (working copy)
@@ -7,7 +7,7 @@
 #define target_brcm 1
 #endif
 
-#define JFFS2_EOF "\xde\xad\xc0\xde"
+#define JFFS2_EOF  0xDEADC0DE
 
 extern int quiet;
 extern int mtdsize;
Index: package/mtd/src/jffs2.c
===================================================================
--- package/mtd/src/jffs2.c     (revision 17207)
+++ package/mtd/src/jffs2.c     (working copy)
@@ -8,6 +8,7 @@
 #include <dirent.h>
 #include <unistd.h>
 #include <endian.h>
+#include <arpa/inet.h>
 #include "jffs2.h"
 #include "crc32.h"
 #include "mtd.h"
@@ -211,6 +212,7 @@
 
 int mtd_replace_jffs2(const char *mtd, int fd, int ofs, const char
*filename) {
+       const uint32_t jffs2_eof_magic = htonl(JFFS2_EOF);
        outfd = fd;
        mtdofs = ofs;
 
@@ -222,7 +224,7 @@
        pad(erasesize);
 
        /* add eof marker, pad to eraseblock size and write the data */
-       add_data(JFFS2_EOF, sizeof(JFFS2_EOF) - 1);
+       add_data(&jffs2_eof_magic, sizeof(jffs2_eof_magic));
        pad(erasesize);
        free(buf);
 
@@ -262,6 +264,7 @@
 int mtd_write_jffs2(const char *mtd, const char *filename, const char
*dir) {
        int err = -1, fdeof = 0;
+       const uint32_t jffs2_eof_magic = htonl(JFFS2_EOF);
 
        outfd = mtd_check_open(mtd);
        if (!outfd)
@@ -324,7 +327,7 @@
        pad(erasesize);
 
        /* add eof marker, pad to eraseblock size and write the data */
-       add_data(JFFS2_EOF, sizeof(JFFS2_EOF) - 1);
+       add_data(&jffs2_eof_magic, sizeof(jffs2_eof_magic));
        pad(erasesize);
 
        err = 0;


-- 
And that's my crabbing done for the day.  Got it out of the way early, 
now I have the rest of the afternoon to sniff fragrant tea-roses or 
strangle cute bunnies or something.   -- Michael Devore
GnuPG Key Fingerprint 86 F5 81 A5 D4 2E 1F 1C      http://gnupg.org
The C Shore (Daniel Dickinson's Website) http://www.bmts.com/~cshore

Attachment: signature.asc
Description: PGP signature

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to