changeset 37:b2bb007e5789

The filesytem stuff actually does something now The code is still messy but for now, I shall focus on laundry (and after that, sleep) Once the user enters the filename, this now dumps the entire contents of the file to the screen. It would be nice to have this wait for the user to push enter or something, not sure how possible that is though...
author Jonathan Pevarnek <pevarnj@gmail.com>
date Fri, 08 Apr 2011 00:22:44 -0400
parents 3acc1f944c7b
children 4f8e3bb19646
files src/fs.c
diffstat 1 files changed, 44 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/fs.c	Thu Apr 07 23:45:03 2011 -0400
+++ b/src/fs.c	Fri Apr 08 00:22:44 2011 -0400
@@ -69,10 +69,20 @@
 	return last;
 }
 
+void dumpText(char *text, int size)
+{
+	do {
+		putline(text, (size > CON_LEN)?CON_LEN:size);
+		size -= CON_LEN;
+		text += CON_LEN;
+	} while(size > 0);
+}
+
 void start(u64 __memsize)
 {
 	sPrint(""); //I have no idea why I would possibly need this...
 	char buffer[256];
+	int i;
 	
 	u32 dev = find_dev(0x100);
 	Superblock sb;
@@ -93,17 +103,41 @@
 		sPrint("ERROR\n");
 		goto END;
 	}
-	
-	//Prints off the name of each file
-	Direntry *dp;
-	for(dp = direntries; dp - direntries < nFiles; dp++) {
-		printFname(dp->fname), sPrint("\n");
+
+	while(1) {
+		
+		//Prints off the name of each file
+		Direntry *dp;
+		for(dp = direntries; dp - direntries < nFiles; dp++) {
+			printFname(dp->fname), sPrint("\n");
+		}
+		char fname[28];
+		sPrint("Please enter the file to read: ");
+		getFname(fname);
+		int file = fnameLookup(fname, direntries, nFiles);
+
+		u32 fileLoc = direntries[file].inode;
+
+		Inode fileToRead;
+		if(readFSBlock(dev, fileLoc, &fileToRead)) {
+			sPrint("ERROR\n");
+			goto END;
+		}
+
+		u32 fileSize = fileToRead.size;
+		const u32 origFileSize = fileSize;
+
+		for(i = 0; i < fileToRead.nblocks; i++) {
+			char text[1024];
+			if(readFSBlock(dev, fileToRead.blocks[i], text)) {
+				sPrint("ERROR\n");
+				goto END;
+			}
+			dumpText(text, (fileSize > 1024)?1024:fileSize);
+			fileSize -= 1024;
+		}
 	}
-	char fname[28];
-	sPrint("Please enter the file to read: ");
-	getFname(fname);
-	printFname(fname), sPrint("\n");
-	sPrint(itoa(fnameLookup(fname, direntries, nFiles), buffer, 10)), sPrint("\n");
+
 
 END:
 	sPrint("DONE\n");