#include <stdio.h>
#include <string.h>

#include "vfs.h"
#include "blockdev.h"

struct fsys_entry {
	char *name;
	int (*mount_func) (void);
	int (*read_func) (char *buf, int len);
	int (*dir_func) (char *dirname);
	int (*close_func) (void);
} static const fsys_table[] = {
	{ "ext2", ext2fs_mount, ext2fs_read, ext2fs_dir, NULL },
};

static const size_t fsys_table_length = sizeof(fsys_table) / sizeof(fsys_table[0]);

const struct fsys_entry *fsys = NULL;
int filemax;
int filepos;

int mount_fs(char *fs_name)
{
	for (size_t i = 0; i < fsys_table_length; i++) {
		if ((!fs_name || !strcmp(fsys_table[i].name, fs_name)) && fsys_table[i].mount_func()) {
			fsys = &fsys_table[i];
			return 1;
		}
	}

	if (fs_name)
		fprintf(stderr, "mount_fs: Faild to mount filesystem: %s.\n", fs_name);
	else
		fprintf(stderr, "mount_fs: No matching filesystem found.\n");
	return 0;
}




int file_open(const char *filename)
{
	if (filename && filename[0] != '/') {
		fprintf(stderr, "file_open: filename musst start with '/',"
			"no support for device identifier");
		return 0;
	}
	
	if (!fsys) {
		fprintf(stderr, "file_open: no open filesystem.\n");
		return 0;
	}
	char *path = strdup(filename);
	if (!fsys->dir_func(path)) {
		fprintf(stderr, "file_open: file not found '%s'.\n", filename);
		return 0;
	}
	filepos = 0;
	return 1;
}

int file_read(void *buf, unsigned long len)
{
	if (filepos < 0 || filepos > filemax)
		filepos = filemax;

	if (len < 0 || len > filemax - filepos)
		len = filemax - filepos;
	return fsys->read_func(buf, len);
}

unsigned long file_seek(unsigned long offset)
{
	if (offset <= filemax)
		filepos = offset;
	else
		filepos = filemax;
	return filepos;
}

unsigned long file_size(void)
{
	return filemax;
}

void file_close(void)
{
	// In contrast to filo the device is not closed here
	// devclose();
}

