]> www.infradead.org Git - mtd-utils.git/commitdiff
mtd: tests: Fix endian issue with CRC generation algorithm
authorPaul McGougan <PMcGougan@topcon.com>
Thu, 17 Apr 2014 05:09:26 +0000 (05:09 +0000)
committerBrian Norris <computersforpeace@gmail.com>
Tue, 29 Sep 2015 22:48:32 +0000 (15:48 -0700)
The calculation of the CRC in /tests/checkfs/makefiles.c was writing the CRC
Into the produced files in host byte-order which would cause CRC validation
to fail on big-endian systems as the validation is performed bytewise.

Signed-off-by: Paul McGougan <pmcgougan AT topcon.com>
[Brian: add endian.h]
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
tests/checkfs/makefiles.c

index 589280b4e48d64cddb5249c21e9a4cf13ba0e317..52fea5467fa3be7f06f9ba60670f2726f7e52295 100644 (file)
@@ -26,6 +26,7 @@ The files are opened in the current dir.
 */
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <endian.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -170,6 +171,7 @@ void checksum(char *filename){
     printf("Error! Cannot open filename to update checksum: %s\n",filename);
     exit(1);
   }
+  crc = htole16(crc);
   if(fwrite(&crc, sizeof(crc), 1, fp) != 1){
     printf("error! unable to update the file for checksum.\n");
     fclose(fp);