changeset 52:2de1c2597a60

Modified getFSize so it now returns a value indicating success/failure Also modified the lookup function so it does not load the file into the cache
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sat, 09 Apr 2011 01:28:06 -0400
parents eda059d74100
children b22b6a83cf04
files include/fs.h src/fs.c src/testFS.c
diffstat 3 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/include/fs.h	Fri Apr 08 13:41:58 2011 -0400
+++ b/include/fs.h	Sat Apr 09 01:28:06 2011 -0400
@@ -30,7 +30,7 @@
 int fsInit(u32 devnum);
 void listFiles();
 u32 lookupFile(char *fname);
-u32 getFSize(u32 fid);
+int getFSize(u32 fid, u32 *size);
 int getFData(u32 fid, void *ptr);
 void printFname(char *name);
 void getFname(char *fname);
--- a/src/fs.c	Fri Apr 08 13:41:58 2011 -0400
+++ b/src/fs.c	Sat Apr 09 01:28:06 2011 -0400
@@ -41,7 +41,6 @@
 	Direntry *dp;
 	for(dp = Direntries; dp - Direntries < NFiles; dp++) {
 		if(!fnameCmp(fname, dp->fname)) {
-			if(loadToCache(dp->inode)) return 0;
 			return dp->inode;
 		}
 	}
@@ -49,14 +48,16 @@
 }
 
 //REQUIRES:   Valid loadable fid
-u32 getFSize(u32 fid)
+//This sets *size equal to the size of the file.  Will return 0 an success
+int getFSize(u32 fid, u32 *size)
 {
-	loadToCache(fid);
-	return Cached.size;
+	if(loadToCache(fid)) return -1;
+	*size = Cached.size;
+	return 0;
 }
 
 
-//REQUIRES:   point is large enough to hold everything
+//REQUIRES:   ptr is large enough to hold everything
 int getFData(u32 fid, void *ptr)
 {
 	int i;
--- a/src/testFS.c	Fri Apr 08 13:41:58 2011 -0400
+++ b/src/testFS.c	Sat Apr 09 01:28:06 2011 -0400
@@ -19,7 +19,6 @@
 	if(fsInit(0x100)) goto END;
 
 	while(1) {
-		
 		//Prints off the name of each file
 		listFiles();
 		char fname[28];
@@ -27,11 +26,10 @@
 		getFname(fname);
 		u32 fid = lookupFile(fname);
 		if(!fid) continue; //if fid is 0, the file was not found
-
-		u32 fileSize = getFSize(fid);
+		u32 fileSize;
+		if(getFSize(fid, &fileSize)) continue;
 		char *text = malloc(fileSize);
-		text = text;
-		getFData(fid, text);
+		if(getFData(fid, text)) continue;
 		dumpText(text, fileSize);
 		free(text);
 	}