[Yaffs] patch: mkyaffsimage error handling

Frank Rowand frowand@mvista.com
Mon, 22 Nov 2004 16:05:33 -0800


This is a multi-part message in MIME format.
--------------010509010807050701080206
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

The attached patch cleans up the error handling in mkyaffsimage a
little bit.

Some functions return an error value, others directly set the
global variable "error".  The patch converts all usage to the
function error return model.

In process_directory(), added a printf() of the name of the
unhandled object to the "we don't handle this type" error
message.

In process_directory(), stop scanning as soon as an error
occurs.  (This may be a controversial change, but it seemed
good to me to make the failure obvious, and not hidden in
the output of files that were properly processed.)

-Frank
-- 
Frank Rowand <frank_rowand@mvista.com>
MontaVista Software, Inc

--------------010509010807050701080206
Content-Type: text/plain;
 name="yaffs_userland_07_mkyaffsimage_error_handling.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="yaffs_userland_07_mkyaffsimage_error_handling.patch"

Index: yaffs/utils/mkyaffsimage.c
===================================================================
--- yaffs.orig/utils/mkyaffsimage.c
+++ yaffs/utils/mkyaffsimage.c
@@ -30,6 +30,7 @@
 #include <dirent.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "yaffs_guts.h"
 #include "nand_ecc.h"
@@ -56,8 +57,6 @@
 
 static int outFile;
 
-static int error;
-
 static int convert_endian = 0;
 
 static int obj_compare(const void *a, const void * b)
@@ -236,6 +235,7 @@
 
 static int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)
 {
+	int error;
 	yaffs_Tags t;
 	yaffs_Spare s;
 
@@ -386,7 +386,7 @@
 
 static int process_directory(int parent, const char *path)
 {
-
+	int error = 0;
 	DIR *dir;
 	struct dirent *entry;
 
@@ -396,7 +396,7 @@
 	
 	if(dir)
 	{
-		while((entry = readdir(dir)) != NULL)
+		while(((entry = readdir(dir)) != NULL) && (error >= 0))
 		{
 		
 			/* Ignore . and .. */
@@ -518,19 +518,23 @@
 				}
 				else
 				{
+					printf("%s",full_name);
 					printf(" we don't handle this type\n");
+					error = -1;
+					errno = EINVAL;
 				}
 			}
 		}
 	}
 	
-	return 0;
+	return error;
 
 }
 
 
 int main(int argc, char *argv[])
 {
+	int error;
 	struct stat stats;
 	
 	printf("mkyaffsimage: image building tool for YAFFS built "__DATE__"\n");
@@ -572,8 +576,8 @@
 	
 	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]);
+	if (error >= 0)
+		error = process_directory(YAFFS_OBJECTID_ROOT,argv[1]);
 	
 	close(outFile);
 	

--------------010509010807050701080206--