# HG changeset patch # User Jonathan Pevarnek # Date 1302326886 14400 # Node ID 2de1c2597a609fb670a6dfbf1fd88b4e04790bf8 # Parent eda059d7410024e786b0a8c37fdcca2d62b098e6 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 diff -r eda059d74100 -r 2de1c2597a60 include/fs.h --- 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); diff -r eda059d74100 -r 2de1c2597a60 src/fs.c --- 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; diff -r eda059d74100 -r 2de1c2597a60 src/testFS.c --- 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); }