mtd/util mkfs.jffs2.c,1.42,1.43

havasi at infradead.org havasi at infradead.org
Fri Nov 26 09:29:50 EST 2004


Update of /home/cvs/mtd/util
In directory phoenix.infradead.org:/tmp/cvs-serv7615

Modified Files:
	mkfs.jffs2.c 
Log Message:
Incremental file system image generation support.



Index: mkfs.jffs2.c
===================================================================
RCS file: /home/cvs/mtd/util/mkfs.jffs2.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- mkfs.jffs2.c	25 May 2004 11:20:45 -0000	1.42
+++ mkfs.jffs2.c	26 Nov 2004 14:29:47 -0000	1.43
@@ -6,6 +6,7 @@
  *           2001 David A. Schleef <ds at lineo.com>
  *           2002 Axis Communications AB
  *           2001, 2002 Erik Andersen <andersen at codepoet.org>
+ *           2004 University of Szeged, Hungary
  *
  * 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
@@ -76,6 +77,8 @@
 #define mkfs_debug_msg(a...)	{ }
 #define min(x,y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_y:_x; })
 
+#define PAD(x) (((x)+3)&~3)
+
 struct filesystem_entry {
 	char *name;					/* Name of this directory (think basename) */
 	char *path;					/* Path of this directory (think dirname) */
@@ -91,6 +94,7 @@
 
 
 static int out_fd = -1;
+static int in_fd = -1;
 static char default_rootdir[] = ".";
 static char *rootdir = default_rootdir;
 static int verbose = 0;
@@ -650,7 +654,8 @@
 #define JFFS2_MAX_SYMLINK_LEN 254
 #endif
 
-static uint32_t ino;
+static uint32_t ino = 0;
+static uint8_t *file_buffer = NULL;		/* file buffer contains the actual erase block*/
 static int out_ofs = 0;
 static int erase_block_size = 65536;
 static int pad_fs_size = 0;
@@ -1112,7 +1117,10 @@
 	cleanmarker.totlen   = cpu_to_je32(cleanmarker_size);
 	cleanmarker.hdr_crc  = cpu_to_je32(crc32(0, &cleanmarker, sizeof(struct jffs2_unknown_node)-4));
 
-	ino = root->sb.st_ino = 1;
+	if (ino == 0)
+		ino = 1;
+	
+	root->sb.st_ino = 1;
 	recursive_populate_directory(root);
 
 	if (pad_fs_size == -1) {
@@ -1156,6 +1164,7 @@
 	{"disable-compressor", 1, NULL, 'x'},
 	{"test-compression", 0, NULL, 't'},
 	{"compressor-priority", 1, NULL, 'y'},
+	{"input", 1, NULL, 'i'},
 	{NULL, 0, NULL, 0}
 };
 
@@ -1190,11 +1199,147 @@
 	"  -P, --squash-perms      Squash permissions on all files\n"
 	"  -h, --help              Display this help text\n"
 	"  -v, --verbose           Verbose operation\n"
-	"  -V, --version           Display version information\n\n";
-
+	"  -V, --version           Display version information\n"
+	"  -i, --incremental=FILE  Parse FILE and generate appendage output for it\n\n";
 
 static char *revtext = "$Revision$";
 
+int load_next_block() {
+	
+	int ret;
+	ret = read(in_fd, file_buffer, erase_block_size);
+		
+	if(verbose)
+		printf("Load next block : %d bytes read\n",ret);
+	
+	return ret;
+}
+
+void process_buffer(int inp_size) {
+	uint8_t		*p = file_buffer;
+	union jffs2_node_union 	*node;
+	uint16_t	type;
+	int		bitchbitmask = 0;
+	int		obsolete;
+	
+	char	name[256];
+	
+	while ( p < (file_buffer + inp_size)) {
+		
+		node = (union jffs2_node_union *) p;
+		
+		/* Skip empty space */
+		if (je16_to_cpu (node->u.magic) == 0xFFFF && je16_to_cpu (node->u.nodetype) == 0xFFFF) {
+			p += 4;
+			continue;
+		}
+		
+		if (je16_to_cpu (node->u.magic) != JFFS2_MAGIC_BITMASK)	{
+			if (!bitchbitmask++)
+    			    printf ("Wrong bitmask  at  0x%08x, 0x%04x\n", p - file_buffer, je16_to_cpu (node->u.magic));
+			p += 4;
+			continue;
+		}
+		
+		bitchbitmask = 0;
+		
+		type = je16_to_cpu(node->u.nodetype);
+		if ((type & JFFS2_NODE_ACCURATE) != JFFS2_NODE_ACCURATE) {
+			obsolete = 1;
+			type |= JFFS2_NODE_ACCURATE;
+		} else
+			obsolete = 0;
+		
+		node->u.nodetype = cpu_to_je16(type);
+		
+		switch(je16_to_cpu(node->u.nodetype)) {
+		
+			case JFFS2_NODETYPE_INODE:
+				if(verbose)
+					printf ("%8s Inode      node at 0x%08x, totlen 0x%08x, #ino  %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n",
+						obsolete ? "Obsolete" : "",
+						p - file_buffer, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino),
+						je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize), 
+						je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
+				
+				if ( je32_to_cpu (node->i.ino) > ino )
+					ino = je32_to_cpu (node->i.ino);
+				
+				p += PAD(je32_to_cpu (node->i.totlen));
+				break;
+				
+			case JFFS2_NODETYPE_DIRENT:
+				memcpy (name, node->d.name, node->d.nsize);
+				name [node->d.nsize] = 0x0;
+			
+				if(verbose)
+					printf ("%8s Dirent     node at 0x%08x, totlen 0x%08x, #pino %5d, version %5d, #ino  %8d, nsize %8d, name %s\n",
+						obsolete ? "Obsolete" : "",
+						p - file_buffer, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino),
+						je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino), 
+						node->d.nsize, name);
+				
+				p += PAD(je32_to_cpu (node->d.totlen));						
+				break;
+		
+			case JFFS2_NODETYPE_CLEANMARKER:
+				if (verbose) {
+					printf ("%8s Cleanmarker     at 0x%08x, totlen 0x%08x\n", 
+						obsolete ? "Obsolete" : "",
+						p - file_buffer, je32_to_cpu (node->u.totlen));
+				}
+				
+				p += PAD(je32_to_cpu (node->u.totlen));						
+				break;
+		
+			case JFFS2_NODETYPE_PADDING:
+				if (verbose) {
+					printf ("%8s Padding    node at 0x%08x, totlen 0x%08x\n", 
+						obsolete ? "Obsolete" : "",
+						p - file_buffer, je32_to_cpu (node->u.totlen));
+				}
+				
+				p += PAD(je32_to_cpu (node->u.totlen));						
+				break;
+				
+			case 0xffff:
+				p += 4;
+				break;
+				
+			default:	
+				if (verbose) {
+					printf ("%8s Unknown    node at 0x%08x, totlen 0x%08x\n", 
+						obsolete ? "Obsolete" : "",
+						p - file_buffer, je32_to_cpu (node->u.totlen));
+				}
+				
+				p += PAD(je32_to_cpu (node->u.totlen));						
+		}	
+	}
+}
+
+void parse_image(){
+	int ret;
+	
+	file_buffer = malloc(erase_block_size);
+	
+	if (!file_buffer) {
+		perror("out of memory");
+		close (in_fd);
+		close (out_fd);
+		exit(1);
+	}
+	
+	while ((ret = load_next_block())) {
+		process_buffer(ret);	
+	}
+	
+	if (file_buffer)
+		free(file_buffer);
+	
+	close(in_fd);
+}
+
 int main(int argc, char **argv)
 {
 	int c, opt;
@@ -1208,7 +1353,7 @@
         jffs2_compressors_init();
 
 	while ((opt = getopt_long(argc, argv, 
-					"D:d:r:s:o:qUPfh?vVe:lbp::nc:m:x:X:Lty:", long_options, &c)) >= 0) 
+					"D:d:r:s:o:qUPfh?vVe:lbp::nc:m:x:X:Lty:i:", long_options, &c)) >= 0) 
 	{
 		switch (opt) {
 			case 'D':
@@ -1361,6 +1506,15 @@
                                 }
                                 free(compr_name);
                                 break;
+			case 'i':
+				if (in_fd != -1) {
+					error_msg_and_die("(incremental) filename specified more than once");
+				}
+				in_fd = open(optarg, O_RDONLY);
+				if (in_fd == -1) {
+					perror_msg_and_die("cannot open (incremental) file");
+				}
+				break;
 		}
 	}
 	if (out_fd == -1) {
@@ -1378,6 +1532,9 @@
 	if (!(cwd = getcwd(0, GETCWD_SIZE)))
 		perror_msg_and_die("getcwd failed");
 
+	if(in_fd != -1)
+		parse_image();
+	
 	root = recursive_add_host_directory(NULL, "/", cwd);
 
 	if (devtable)





More information about the linux-mtd-cvs mailing list