#ifndef STORAGE_H
#define STORAGE_H

#include <stdlib.h>

#include "logger_settings.h"

#include "string.h"
#include "stdio.h"
#include "rprintf.h"
#include "debug.h"

#include "mmc.h"
#include "dosfs.h"
//#include "sensor.h"

#define LOGCACHE_OK 0
#define LOGCACHE_FULL -1
#define LOGCACHE_STRTOOLONG -2
#define LOGCACHE_ERR -3



#define LOGCACHE_FLUSH_FULL	1

#define LOGFILE_PATHLEN 22

	//char filepath[LOGFILE_PATHLEN];
typedef struct FILEWRITE_s {
	FILEINFO fi;
	int id;
} FILEWRITE_t;

typedef struct WRITECACHEBLOCK_s {
	char file_id;
	char data[WRITECACHEDATASIZE];
	int hasdata;
} WRITECACHEBLOCK_t;

FILEWRITE_t filewritearray[MAXSENSORS];
WRITECACHEBLOCK_t filewritecachearray[WRITECACHEBLOCKS];
VOLINFO vi;
uint32_t pstart;
char storageInitialized;
uint8_t fatscratch[SECTOR_SIZE];

char logCacheFlushPolicy;

int mountFatVolume(void);
void listDir(char *dir, char *filter);
uint32_t printFile(char *filepath);
int initStorage(void);
int appendToLog(FILEINFO *fi, char *textdata);
int writeToLog(char *filepath, char *textdata);
int flushCache(char flushpolicy);
void registerLogCache(int entry, char *filepath);
int appendToLogCache(char entry, char *textdata);
void printLogCache(void);
int deleteFile(char *filepath);
void setLogCacheFlushPolicy(char policy);
void initLogCache(void);


#endif
