#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[] = {
	{ "dummy", NULL, NULL, NULL, 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();
}

