[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] --cleanmarkers option in mkfs.jffs2



The following patch adds --cleanmarkers (-c) option to mkfs.jffs2
that adds cleanmarkers to each erase block when padding.

/Johan Adolfsson - Axis Communications AB
diff -u -p -r1.27 mkfs.jffs2.c
--- mkfs.jffs2.c	5 Sep 2002 15:21:03 -0000	1.27
+++ mkfs.jffs2.c	10 Sep 2002 19:59:41 -0000
@@ -106,6 +106,7 @@ extern unsigned char jffs2_compress(unsi
 
 static int erase_block_size = 65536;
 static int pad_fs_size = 0;
+static int add_clean_markers = 0;
 static int page_size = 4096;
 static int out_fd = 1;
 static int out_ofs = 0;
@@ -1099,6 +1100,7 @@ static int go(char *dname, FILE * devtab
 
 static struct option long_options[] = {
 	{"pad", 2, NULL, 'p'},
+	{"cleanmarkers", 0, NULL, 'c'},
 	{"root", 1, NULL, 'r'},
 	{"pagesize", 1, NULL, 's'},
 	{"eraseblock", 1, NULL, 'e'},
@@ -1122,6 +1124,7 @@ static char *helptext =
 	"  -p, --pad[=SIZE]       Pad output to SIZE bytes with 0xFF. If SIZE is\n"
 	"                         not specified, the output is padded to the end of\n"
 	"                         the final erase block\n"
+	"  -c, --cleanmarkers     Add a cleanmarker to every eraseblock when padding\n"
 	"  -r, -d, --root=DIR     Build filesystem from directory DIR (default: cwd)\n"
 	"  -s, --pagesize=SIZE    Use page size (max data node size) SIZE (default: 4KiB)\n"
 	"  -e, --eraseblock=SIZE  Use erase block size SIZE (default: 64KiB)\n"
@@ -1162,7 +1165,9 @@ int main(int argc, char **argv)
 			else
 				pad_fs_size = -1;
 			break;
-
+		case 'c':
+			add_clean_markers = 1;
+			break;
 		case 'r':
 		case 'd':				/* for compatibility with mkfs.jffs, genext2fs, etc... */
 			if (rootdir != default_rootdir) {
@@ -1238,8 +1243,23 @@ int main(int argc, char **argv)
 	if (pad_fs_size == -1) {
 		padblock();
 	} else {
-		while (out_ofs < pad_fs_size) {
-			full_write(out_fd, ffbuf, min(16, pad_fs_size - out_ofs));
+		struct jffs2_unknown_node cleanmarker = {
+		  .magic =    cpu_to_target16(JFFS2_MAGIC_BITMASK),
+		  .nodetype = cpu_to_target16(JFFS2_NODETYPE_CLEANMARKER),
+		  .totlen =   cpu_to_target32(sizeof(cleanmarker))
+		};
+
+		if (add_clean_markers){
+			padblock();
+			while (out_ofs < pad_fs_size) {
+				full_write(out_fd, &cleanmarker, sizeof(cleanmarker));
+				padblock();
+			}
+		} else {
+			while (out_ofs < pad_fs_size) {
+				full_write(out_fd, ffbuf, min(16, pad_fs_size - out_ofs));
+			}
+
 		}
 	}