changeset 54:39fcefab46ed

Modified the init_fs function to take advantage of dynamic memory init_fs (renamed) now takes advantage of dynamic memory and allocates space for exactly as many direntries as it needs to keep track of TODO redo caching to Jeff's far superior idea
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sat, 09 Apr 2011 21:55:59 -0400
parents b22b6a83cf04
children 25be3895c62a
files include/fs.h include/std.h src/fs.c src/std.c src/testFS.c
diffstat 5 files changed, 21 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/include/fs.h	Sat Apr 09 11:18:57 2011 -0400
+++ b/include/fs.h	Sat Apr 09 21:55:59 2011 -0400
@@ -27,7 +27,7 @@
 };
 typedef struct DIRENTRY Direntry;
 
-int fsInit(u32 devnum);
+int init_fs(u32 devnum);
 void listFiles();
 u32 lookupFile(char *fname);
 int getFSize(u32 fid, u32 *size);
--- a/include/std.h	Sat Apr 09 11:18:57 2011 -0400
+++ b/include/std.h	Sat Apr 09 21:55:59 2011 -0400
@@ -1,6 +1,12 @@
+#include <die.h>
+
 #ifndef __STD_H
 #define __STD_H
 
+#define assert(x) do { if(!(x)) die(); } while (0)
+
+void init_all(u64 __memsize);
+
 double abs(double num);
 
 char* ftoa(double x, char *a, unsigned int prec);
--- a/src/fs.c	Sat Apr 09 11:18:57 2011 -0400
+++ b/src/fs.c	Sat Apr 09 21:55:59 2011 -0400
@@ -5,14 +5,13 @@
 static int readFSBlock(u32 dev, u32 blkno, void *fsBlock);
 
 static u32 DevID;
-//static Superblock sb; //the superblock
-static Direntry Direntries[32];
+static Direntry *Direntries = NULL;
 static int NFiles;
 
 static u32 CacheID = 0;
 static Inode Cached;
 
-int fsInit(u32 devnum)
+int init_fs(u32 devnum)
 {
 	DevID = find_dev(0x100);
 	Superblock sb; //the superblock
@@ -20,12 +19,8 @@
 	Inode rootINode;
 	if(readFSBlock(DevID, sb.root_inode, &rootINode)) return -1;
 	NFiles = rootINode.size/sizeof(Direntry);
-	if(NFiles > 32) return -1; //for the moment, I do not feel like having support
-	                           //for this.  TODO add support
-	int i;
-	for(i = 0; i*32 < NFiles; i++) { //this will only run once...  It is useless
-		if(readFSBlock(DevID, rootINode.blocks[i], Direntries)) return -1;
-	}
+	Direntries = malloc(rootINode.size);
+	if(getFData(sb.root_inode, Direntries)) return -1;
 	return 0;
 }
 
@@ -128,6 +123,7 @@
 //EFFECTS:    Sets fsBlock to be equal
 static int readFSBlock(u32 dev, u32 blkno, void *fsBlock)
 {
+	//assert(isBlockAt(blkno)); //DO NOT UNCOMMENT
 	if(fba_read_blk(dev, blkno*2, fsBlock)) return 1;
 	if(fba_read_blk(dev, blkno*2 + 1, fsBlock + 512)) return 1;
 	return 0;
--- a/src/std.c	Sat Apr 09 11:18:57 2011 -0400
+++ b/src/std.c	Sat Apr 09 21:55:59 2011 -0400
@@ -1,5 +1,12 @@
 #include <std.h>
 
+void init_all(u64 __memsize)
+{
+	init_io_int();
+	init_console();
+	malloc_init(__memsize - HEAP_START);
+}
+
 double abs(double num)
 {
 	if(num < 0) return num*-1;
--- a/src/testFS.c	Sat Apr 09 11:18:57 2011 -0400
+++ b/src/testFS.c	Sat Apr 09 21:55:59 2011 -0400
@@ -12,11 +12,9 @@
 
 void start(u64 __memsize)
 {
-	init_io_int();
-	init_console();
-	malloc_init(__memsize - HEAP_START);
+	init_all(__memsize);
 	char buffer[256];
-	if(fsInit(0x100)) goto END;
+	if(init_fs(0x100)) goto END;
 
 	while(1) {
 		//Prints off the name of each file