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

Patch for mkfs.jffs



Hi,

I just tweaked mkfs.jffs so now it supports device nodes.  The version
from MTD has already been patched but I thought I'd post it here as
well.


-- 
Sébastien Côté
--- /home/scote1/mtd/util/mkfs.jffs.c	Fri Jun 16 10:44:42 2000
+++ mkfs.jffs.c	Mon Jul 10 09:32:21 2000
@@ -24,7 +24,6 @@
 				  % JFFS_ALIGN_SIZE)
 
 
-
 struct jffs_raw_inode
 {
   __u32 magic;    /* A constant magic number.  */
@@ -66,7 +65,7 @@
 static __u32 jffs_checksum(void *data, int size);
 void jffs_print_trace(const char *path, int depth);
 int make_root_dir(FILE *fs, int first_ino, const char *root_dir_path, int depth);
-void write_file(struct jffs_file *f, FILE *fs);
+void write_file(struct jffs_file *f, FILE *fs, struct stat st);
 void read_data(struct jffs_file *f, const char *path, int offset);
 int mkfs(FILE *fs, const char *path, int ino, int parent, int depth);
 
@@ -199,7 +198,7 @@
   f.data = 0;
   f.inode.chksum = jffs_checksum(&f.inode, sizeof(struct jffs_raw_inode));
   f.inode.accurate = 0xff;
-  write_file(&f, fs);
+  write_file(&f, fs, st);
   if (verbose >= 1)
   {
     jffs_print_trace(root_dir_path, depth);
@@ -213,7 +212,7 @@
 
 /* This function writes at least one inode.  */
 void
-write_file(struct jffs_file *f, FILE *fs)
+write_file(struct jffs_file *f, FILE *fs, struct stat st)
 {
   int npad = JFFS_GET_PAD_BYTES(f->inode.nsize);
   int dpad = JFFS_GET_PAD_BYTES(f->inode.dsize);
@@ -228,20 +227,29 @@
   fwrite((void *)&f->inode, sizeof(struct jffs_raw_inode), 1, fs);
   if (f->inode.nsize)
   {
-    fwrite(f->name, 1, f->inode.nsize, fs);
-  }
-  if (npad)
-  {
-    fwrite(ff_data, 1, npad, fs);
+	  fwrite(f->name, 1, f->inode.nsize, fs);
+	  if (npad)
+	  {
+		  fwrite(ff_data, 1, npad, fs);
+	  }
   }
+  
   if (f->inode.dsize)
   {
-    fwrite(f->data, 1, f->inode.dsize, fs);
-  }
-  if (dpad)
-  {
-    fwrite(ff_data, 1, dpad, fs);
+	  if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
+	  {
+		  fwrite((char *)&st.st_rdev, sizeof(st.st_rdev)/4, 1, fs);
+	  }
+	  else
+	  {
+		  fwrite(f->data, 1, f->inode.dsize, fs);
+	  }
+	  if (dpad)
+	  {
+		  fwrite(ff_data, 1, dpad, fs);
+	  }
   }
+
   fs_pos += size;
   /* If the space left on the block is smaller than the size of an
      inode, then skip it.  */
@@ -262,7 +270,7 @@
             (unsigned int)f, path, offset);
     fprintf(stderr, "             file's size: %u\n", f->inode.dsize);
   }
-
+  
   if (!(f->data = (unsigned char *)malloc(f->inode.dsize)))
   {
     fprintf(stderr, "read_data(): malloc() failed! (*data)\n");
@@ -434,18 +442,33 @@
                 f.name);
         exit(1);
       }
+	
       f.inode.dsize = linklen;
       f.data = linkdata;
       f.data[linklen] = '\0';
     }
-
+	 
+	 else if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
+	 {
+	 	 f.inode.dsize = sizeof(st.st_rdev)/4;
+	 }
+	 
 	 f.inode.chksum = 0;
-    f.inode.dchksum = jffs_checksum((void *)f.data, f.inode.dsize);
+	 if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
+		 f.inode.dchksum = jffs_checksum((void *)f.data, f.inode.dsize);
+
+	 else
+	 {
+		 f.inode.dchksum =
+			 jffs_checksum((void *)&st.st_rdev, sizeof(st.st_rdev)/4);
+	 }
+
     f.inode.nchksum = jffs_checksum((void *)f.name, f.inode.nsize);
-    f.inode.chksum = jffs_checksum((void *)&f.inode, sizeof(struct jffs_raw_inode));
+    f.inode.chksum =
+		 jffs_checksum((void *)&f.inode, sizeof(struct jffs_raw_inode));
     f.inode.accurate = 0xff;
-
-    write_file(&f, fs);
+	 
+    write_file(&f, fs, st);
     if (S_ISREG(st.st_mode) && st.st_size)
 	 {
 		 if (pos < st.st_size)
@@ -454,6 +477,7 @@
 			 goto repeat;
 		 }
 	 }
+	
     new_ino++;
 	 pos = 0;
     if (verbose >= 1)