view src/testFS.c @ 64:72d87920de94

Direntries are no longer cached separately from everything else Main thing: direntries are no longer cached separately from everything else, this was done to make future changes with creating/deleting a file much easier There is currently a TON of code duplication in listFiles() and lookupFile(fname), I am still trying to think of a better way to do this...
author Jonathan Pevarnek <pevarnj@gmail.com>
date Thu, 21 Apr 2011 21:59:51 -0400
parents 5e1d4b26c2ef
children b30006e3fb42
line wrap: on
line source

#include <std.h>
#include <fs.h>

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)
{
	init_all(__memsize);
	char buffer[256];
	if(init_fs(0x100, __memsize)) goto END;

	while(1) {
		if(listFiles()) sPrint("WARNING: ERROR IN READING FILE NAMES\n");
		char fname[28];
		sPrint("Please enter the file to read: ");
		getFname(fname);
		u32 fid = lookupFile(fname);
		if(!fid) continue; //if fid is 0, the file was not found
		u32 fileSize;
		if(getFileSize(fid, &fileSize)) continue;
		char *text = malloc(fileSize);
		if(getFileData(fid, text)) continue;
		dumpText(text, fileSize);
		free(text);
	}

	/*
	while(1) {
		//Prints off the name of each file
		listFiles();
		char fname[28];
		sPrint("Please enter the file to read: ");
		getFname(fname);
		u32 fid = lookupFile(fname);
		if(!fid) continue; //if fid is 0, the file was not found
		sPrint("Please enter the file to copy to: ");
		getFname(fname);
		u32 fid2 = lookupFile(fname);
		if(!fid2) continue;
		u32 fileSize;
		if(getFileSize(fid, &fileSize)) continue;
		char *text = malloc(fileSize);
		if(!text) continue;
		if(getFileData(fid, text)) {
			free(text);
			continue;
		}
		setFileData(fid2, text, fileSize);
		free(text);
		
		if(getFileSize(fid2, &fileSize)) continue;
		text = malloc(fileSize);
		if(getFileData(fid2, text)) continue;
		dumpText(text, fileSize);
		free(text);
	}
	*/

END:
	sPrint("DONE\n");
	for(;;) {
		sGet(buffer, 0);
	}
}