# HG changeset patch # User Jonathan Pevarnek # Date 1302236564 14400 # Node ID b2bb007e5789657da6f0a5960f5bc93d1a955023 # Parent 3acc1f944c7b6c2ec6d144b9d40959c501495723 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... diff -r 3acc1f944c7b -r b2bb007e5789 src/fs.c --- 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");