*** empty log message ***
[yaffs/.git] / utils / mkyaffsimage.c
index 87fc7dab837c2e40d4976c4ed3457db1b339a857..814e2af779224bf73afc1017f05ab13cf1ae1342 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.6 2002-12-13 00:13:06 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;
@@ -57,7 +59,7 @@ static int outFile;
 static int error;
 
 
-int obj_compare(const void *a, const void * b)
+static int obj_compare(const void *a, const void * b)
 {
   objItem *oa, *ob;
   
@@ -73,7 +75,7 @@ int obj_compare(const void *a, const void * b)
 }
 
 
-void add_obj_to_list(dev_t dev, ino_t ino, int obj)
+static void add_obj_to_list(dev_t dev, ino_t ino, int obj)
 {
        if(n_obj < MAX_OBJECTS)
        {
@@ -93,11 +95,11 @@ void add_obj_to_list(dev_t dev, ino_t ino, int obj)
 }
 
 
-int find_obj_in_list(dev_t dev, ino_t ino)
+static int find_obj_in_list(dev_t dev, ino_t ino)
 {
        objItem *i = NULL;
        objItem test;
-       
+
        test.dev = dev;
        test.ino = ino;
        
@@ -113,15 +115,31 @@ 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)
+static void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare)
 {
        nand_calculate_ecc (data , spare->ecc1);
        nand_calculate_ecc (&data[256] , spare->ecc2);
 }
 
-void yaffs_CalcTagsECC(yaffs_Tags *tags)
+static void yaffs_CalcTagsECC(yaffs_Tags *tags)
 {
        // Todo don't do anything yet. Need to calculate ecc
        unsigned char *b = ((yaffs_TagsUnion *)tags)->asBytes;
@@ -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)
@@ -151,7 +170,7 @@ static void yaffs_LoadTagsIntoSpare(yaffs_Spare *sparePtr, yaffs_Tags *tagsPtr)
 {
        yaffs_TagsUnion *tu = (yaffs_TagsUnion *)tagsPtr;
        
-       yaffs_CalcTagsECC(tagsPtr);
+       //yaffs_CalcTagsECC(tagsPtr);
        
        sparePtr->tagByte0 = tu->asBytes[0];
        sparePtr->tagByte1 = tu->asBytes[1];
@@ -165,15 +184,16 @@ static void yaffs_LoadTagsIntoSpare(yaffs_Spare *sparePtr, yaffs_Tags *tagsPtr)
 
 
 
-int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)
+static int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)
 {
        yaffs_Tags t;
        yaffs_Spare s;
-       
+
        error = write(outFile,data,512);
        if(error < 0) return error;
-       
+
        memset(&t,0xff,sizeof (yaffs_Tags));
+       memset(&s,0xff,sizeof (yaffs_Spare));
        
        t.chunkId = chunkId;
        t.serialNumber = 0;
@@ -190,7 +210,7 @@ int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)
        
 }
 
-int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int parent, const char *name, int equivalentObj, const char * alias)
+static int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int parent, const char *name, int equivalentObj, const char * alias)
 {
        __u8 bytes[512];
        
@@ -205,11 +225,13 @@ int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int paren
        
        strncpy(oh->name,name,YAFFS_MAX_NAME_LENGTH);
        
+       
        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;
@@ -236,13 +258,13 @@ int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int paren
 }
 
 
-int process_directory(int parent, const char *path)
+static int process_directory(int parent, const char *path)
 {
 
        DIR *dir;
        struct dirent *entry;
 
-       nDirectories++; 
+       nDirectories++;
        
        dir = opendir(path);
        
@@ -295,9 +317,9 @@ int process_directory(int parent, const char *path)
                                        
                                                        char symname[500];
                                                
-                                                       memset(symname,0,500);
+                                                       memset(symname,0, sizeof(symname));
                                        
-                                                       readlink(full_name,symname,499);
+                                                       readlink(full_name,symname,sizeof(symname) -1);
                                                
                                                        printf("symlink to \"%s\"\n",symname);
                                                        error =  write_object_header(newObj, YAFFS_OBJECT_TYPE_SYMLINK, &stats, parent, entry->d_name, -1, symname);
@@ -363,7 +385,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);
                                                }
                                        }
                                }
@@ -390,7 +413,7 @@ int main(int argc, char *argv[])
        {
                printf("usage: mkyaffsimage dir image_file\n");
                printf("           dir        the directory tree to be converted\n");
-               printf("           image_file the ouput file to hold the image\n");
+               printf("           image_file the output file to hold the image\n");
                exit(1);
        }
 
@@ -416,7 +439,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);