Misc util patch
Hi,
Please find attached a patch against mtd-snapshot-20030325.
Fixes:
* typo in eraseall.c, enable short option 'j', make cleanmarker to work:
this was obviously NOT tested. Now, it's okay.
* potential bug fix in mkfs.jffs2.c, because cpu_to_je32 can be a macro. BTW, this cleans a warning under ppcboot about unexpected node version.
* undefined prototypes in compr_rtime.c
* gcc-3.x warning cleanups in mtd_debug.c
* getopt'ified fcp.c, fixes a bug with "fcp -h"
Test(basic):
* Image generated using mkfs.jffs2 on x86-linux is written to NOR flash and mounted okay on ppc_4xx-ppcboot/linux.
* eraseall -j /dev/mtd2 && mount: fs space readily available.
Thanks for the excellent work.
Cheers,
Stephane
fs/jffs2/compr_rtime.c +3 -0
@@ -25,6 +25,9 @@#include <linux/types.h> #include <linux/errno.h> #include <linux/string.h> +#ifndef __KERNEL__ +#include <string.h> +#endif /* _compress returns the compressed size, -1 if bigger */ int jffs2_rtime_compress(unsigned char *data_in, unsigned char *cpage_out,
util/eraseall.c +8 -6
@@ -45,7 +45,7 @@#include "linux/jffs2.h" #define PROGRAM "eraseall" -#define VERSION "0.1.1" +#define VERSION "0.1.2"static const char *exe_name;static const char *mtd_device;
@@ -119,18 +119,20 @@continue ; } }else { -if (lseek (fd, erase.start,SEEK_SET ) !=0 ) { +if (lseek (fd, erase.start,SEEK_SET ) <0 ) {fprintf (stderr,"\n%s: %s: MTD lseek failure: %s\n" , exe_name, mtd_device,strerror (errno));continue ; } -if (write (fd , &cleanmarker,sizeof (cleanmarker)) !=0 ) { +if (write (fd , &cleanmarker,sizeof (cleanmarker)) !=sizeof (cleanmarker)) {fprintf (stderr,"\n%s: %s: MTD write failure: %s\n" , exe_name, mtd_device,strerror (errno));continue ; } }if (!quiet) -printf ("\rCleanmarker written at %x\n" , erase.start); +printf (" Cleanmarker written at %x." , erase.start); } +if (!quiet) +printf ("\n" );return 0 ; }
@@ -144,7 +146,7 @@for (;;) {int option_index =0 ; -static const char *short_options ="q" ; +static const char *short_options ="jq" ;static const struct option long_options[] = { {"help" , no_argument,0 ,0 }, {"version" , no_argument,0 ,0 },
@@ -202,7 +204,7 @@printf ("Usage: %s [OPTION] MTD_DEVICE\n" "Erases all of the specified MTD device.\n" "\n" -" -j, --jffs2 format the device for jffs2" +" -j, --jffs2 format the device for jffs2\n" " -q, --quiet don't display progress messages\n" " --silent same as --quiet\n" " --help display this help and exit\n"
util/fcp.c +43 -33
89 lines not on this page · raw message
util/mkfs.jffs2.c +6 -3
@@ -785,7 +785,8 @@ rd.hdr_crc =cpu_to_je32 (crc32 (0 , &rd,sizeof (struct jffs2_unknown_node ) -4 )); rd.pino =cpu_to_je32 ((e->parent) ? e->parent->sb.st_ino :1 ); - rd.version =cpu_to_je32 (version++); + rd.version =cpu_to_je32 (version); + version++; rd.ino =cpu_to_je32 (statbuf->st_ino); rd.mctime =cpu_to_je32 (statbuf->st_mtime); rd.nsize =strlen (name);
@@ -877,7 +878,8 @@ ri.hdr_crc =cpu_to_je32 (crc32 (0 , &ri,sizeof (struct jffs2_unknown_node ) -4 )); - ri.version =cpu_to_je32 (++ver); + ++ver; + ri.version =cpu_to_je32 (ver); ri.offset =cpu_to_je32 (offset); ri.csize =cpu_to_je32 (space); ri.dsize =cpu_to_je32 (dsize);
@@ -895,7 +897,8 @@ }if (!je32_to_cpu (ri.version)) {/* Was empty file */ - ri.version =cpu_to_je32 (++ver); + ++ver; + ri.version =cpu_to_je32 (ver); ri.totlen =cpu_to_je32 (sizeof (ri)); ri.hdr_crc =cpu_to_je32 (crc32 (0 , &ri,sizeof (struct jffs2_unknown_node ) -4 ));
util/mtd_debug.c +9 -9
@@ -124,10 +124,10 @@if ((buf = (u_int8_t *)malloc (size)) ==NULL ) {#define BUF_SIZE (64 * 1024 * sizeof (u_int8_t)) -fprintf (stderr, __FUNCTION__": malloc(%#x)\n" , size); +fprintf (stderr,"%s: malloc(%#x)\n" , __FUNCTION__, size);if (size !=BUF_SIZE ) { size =BUF_SIZE ; -fprintf (stderr, __FUNCTION__": trying buffer size %#x\n" , size); +fprintf (stderr,"%s: trying buffer size %#x\n" , __FUNCTION__, size); goto retry; }perror ("malloc()" );
@@ -139,14 +139,14 @@ err =read (fd,buf,size);if (err <0 ) { -fprintf (stderr, __FUNCTION__": read, size %#x, n %#x\n" , size, n); +fprintf (stderr,"%s: read, size %#x, n %#x\n" , __FUNCTION__, size, n);perror ("read()" ); goto err2; } err =write (outfd,buf,size);if (err <0 ) { -fprintf (stderr, __FUNCTION__": write, size %#x, n %#x\n" , size, n); +fprintf (stderr,"%s: write, size %#x, n %#x\n" , __FUNCTION__, size, n);perror ("write()" ); goto err2; }
@@ -194,10 +194,10 @@ retry:if ((buf = (u_int8_t *)malloc (size)) ==NULL ) { -fprintf (stderr, __FUNCTION__": malloc(%#x) failed\n" , size); +fprintf (stderr,"%s: malloc(%#x) failed\n" , __FUNCTION__, size);if (size !=BUF_SIZE ) { size =BUF_SIZE ; -fprintf (stderr, __FUNCTION__": trying buffer size %#x\n" , size); +fprintf (stderr,"%s: trying buffer size %#x\n" , __FUNCTION__, size); goto retry; }perror ("malloc()" );
@@ -209,7 +209,7 @@ size = n;if (fread (buf,size,1 ,fp) !=1 ||ferror (fp)) { -fprintf (stderr, __FUNCTION__": fread, size %#x, n %#x\n" , size, n); +fprintf (stderr,"%s: fread, size %#x, n %#x\n" , __FUNCTION__, size, n);perror ("fread()" );free (buf);fclose (fp);
@@ -218,7 +218,7 @@ err =write (fd,buf,size);if (err <0 ) { -fprintf (stderr, __FUNCTION__": write, size %#x, n %#x\n" , size, n); +fprintf (stderr,"%s: write, size %#x, n %#x\n" , __FUNCTION__, size, n);perror ("write()" );free (buf);fclose (fp);
@@ -298,7 +298,7 @@printf ("MTD_WRITEABLE" ); else { -int i,first =1 ; +int first =1 ; static struct { const char *name;
Quoted 7 lines · Stephane Fillod
Hi,
Please find attached a patch against mtd-snapshot-20030325.
Fixes:
* typo ineraseall.c, enable short option 'j', make cleanmarker to work:
this was obviously NOT tested. Now, it's okay.
Applied.
Quoted 2 lines
* potential bug fix in
mkfs.jffs2.c, becausecpu_to_je32can be a macro. BTW, this cleans a warning under ppcboot about unexpected node version.
I think the warning's bogus -- what precisely does it complain about? Incrementing version more than once is a bug but a harmless one.
I think I'd rather fix the macro instead so it doesn't evaluate 'x' more than once...
#define t16(x) ({ uint16_t b = x; (target_endian==__BYTE_ORDER)?x:bswap_16(b); }) #define t32(x) ({ uint32_t b = x; (target_endian==__BYTE_ORDER)?x:bswap_32(b); })
Quoted 1 line
* undefined prototypes in
compr_rtime.c
No Likee Ifdefs.
I think it's probably time to stop mkfs.jffs2 from using kernel code at all. If this is just a warning, let it stay. It's ugly but the fact we're using kernel files at all is ugly anyway :)
Quoted 2 lines
* gcc-3.x warning cleanups in
mtd_debug.c
* getopt'ifiedfcp.c, fixes a bug with "fcp -h"
Applied.
Thanks for the fixes.
Signature · 1 line
dwmw2