view src/testFS.c @ 61:5e1d4b26c2ef

Added the ability to write an arbitrary block of data to some file First, I also fixed some memory leaks with the file reading function Second, there seems to be a lot of code duplication at the moment, taking care of it is now my next priority I removed the blankFile function, it was absolutely useless (and unless I am mistaken, it can now be duplicated with setFileData(fid, NULL, 0); I added the setFileSize function, it will set the size of a file to be equal to some specified amount. It will not alter the data in any blocks so if downsizing everything under that point will be the same. If increasing the size, everything over that point will most likely be garbage. The function setFileData will now set the data stored in some file to be equal to data passed by the user. TODO: fix duplication, add creating files
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sat, 16 Apr 2011 20:17:51 -0400
parents 25be3895c62a
children 72d87920de94
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) {
		//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
		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);
	}
}