*** empty log message ***
[yaffs/.git] / utils / mkyaffsimage.c
index 797bc0f0f1192d32cb495afb83c36fdfe5e69ee1..0b6d4094060982b51994b28b2e83de16468f6ac6 100644 (file)
@@ -14,6 +14,9 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  *
+ *
+ * Nick Bane modifications flagged NCB
+ *
  */
  
 #include <stdlib.h>
 
 #define MAX_OBJECTS 10000
 
+const char * mkyaffsimage_c_version = "$Id: mkyaffsimage.c,v 1.4 2002-10-02 00:10:17 charles Exp $";
+
 // External functions for ECC on data
 void nand_calculate_ecc (const u_char *dat, u_char *ecc_code);
 int nand_correct_data (u_char *dat, u_char *read_ecc, u_char *calc_ecc);
 
 
-
-
-
 typedef struct
 {
        dev_t dev;
@@ -113,6 +115,22 @@ int find_obj_in_list(dev_t dev, ino_t ino)
        return -1;
 }
 
+// NCB added 10/9/2002
+static __u16 yaffs_CalcNameSum(const char *name)
+{
+       __u16 sum = 0;
+       __u16 i = 1;
+       
+       __u8 *bname = (__u8 *)name;
+       
+       while (*bname)
+       {
+               sum += (*bname) * i;
+               i++;
+               bname++;
+       }
+       return sum;
+}
 
 
 void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare)
@@ -133,7 +151,8 @@ void yaffs_CalcTagsECC(yaffs_Tags *tags)
        
        for(i = 0; i < 8; i++)
        {
-               for(j = 1; j &0x7f; j<<=1)
+// NCB modified 20-9-02                for(j = 1; j &0x7f; j<<=1)
+               for(j = 1; j &0xff; j<<=1)
                {
                        bit++;
                        if(b[i] & j)
@@ -206,11 +225,15 @@ int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int paren
        
        strncpy(oh->name,name,YAFFS_MAX_NAME_LENGTH);
        
+       // NCB added 10/9/2001
+       oh->sum = yaffs_CalcNameSum(oh->name);
+       
        if(t != YAFFS_OBJECT_TYPE_HARDLINK)
        {
                oh->st_mode = s->st_mode;
                oh->st_uid = s->st_uid;
-               oh->st_gid = s->st_uid;
+// NCB 12/9/02         oh->st_gid = s->st_uid;
+               oh->st_gid = s->st_gid;
                oh->st_atime = s->st_atime;
                oh->st_mtime = s->st_mtime;
                oh->st_ctime = s->st_ctime;
@@ -364,7 +387,8 @@ int process_directory(int parent, const char *path)
                                                {
                                                        printf("directory\n");
                                                        error =  write_object_header(newObj, YAFFS_OBJECT_TYPE_DIRECTORY, &stats, parent, entry->d_name, -1, NULL);
-                                                       process_directory(1,full_name);
+// NCB modified 10/9/2001                              process_directory(1,full_name);
+                                                       process_directory(newObj,full_name);
                                                }
                                        }
                                }
@@ -417,7 +441,8 @@ int main(int argc, char *argv[])
        }
        
        printf("Processing directory %s into image file %s\n",argv[1],argv[2]);
-
+       error =  write_object_header(1, YAFFS_OBJECT_TYPE_DIRECTORY, &stats, 1,"", -1, NULL);
+       if(error)
        error = process_directory(YAFFS_OBJECTID_ROOT,argv[1]);
        
        close(outFile);