2010-01-23 18:31:14 +01:00
|
|
|
#include "dosfs.h"
|
|
|
|
#include "pios.h"
|
|
|
|
#include "minGlue.h"
|
|
|
|
|
2010-01-24 09:13:48 +01:00
|
|
|
/* Global Variables */
|
2010-01-25 17:30:31 +01:00
|
|
|
extern uint8_t PIOS_SDCARD_Sector[SECTOR_SIZE];
|
|
|
|
extern VOLINFO PIOS_SDCARD_VolInfo;
|
2010-01-24 09:13:48 +01:00
|
|
|
|
|
|
|
/* Local Variables */
|
|
|
|
static uint32_t SuccessCount;
|
2010-01-23 18:31:14 +01:00
|
|
|
|
|
|
|
int dosfs_ini_openread(const char *filename, PFILEINFO file)
|
|
|
|
{
|
2010-01-25 17:30:31 +01:00
|
|
|
if(DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)filename, DFS_READ, PIOS_SDCARD_Sector, file)) {
|
2010-01-23 18:31:14 +01:00
|
|
|
/* Error opening file */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No errors */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dosfs_ini_openwrite(const char *filename, PFILEINFO file)
|
|
|
|
{
|
2010-01-24 09:13:48 +01:00
|
|
|
/* TODO: Check this works */
|
2010-01-25 17:30:31 +01:00
|
|
|
if(DFS_OpenFile(&PIOS_SDCARD_VolInfo, (uint8_t *)filename, DFS_WRITE, PIOS_SDCARD_Sector, file)) {
|
2010-01-23 18:31:14 +01:00
|
|
|
/* Error opening file */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No errors */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dosfs_ini_close(PFILEINFO file)
|
|
|
|
{
|
|
|
|
/* This doesn't actually do anything */
|
|
|
|
DFS_Close(file);
|
|
|
|
|
|
|
|
/* No errors */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dosfs_ini_read(char *buffer, int size, PFILEINFO file)
|
|
|
|
{
|
2010-01-24 14:03:13 +01:00
|
|
|
if(PIOS_SDCARD_ReadLine(file, (uint8_t *)buffer, size) < 0)
|
|
|
|
{
|
|
|
|
/* Error reading line */
|
2010-01-23 18:31:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2010-01-24 14:03:13 +01:00
|
|
|
|
|
|
|
/* No errors */
|
|
|
|
return 1;
|
2010-01-23 18:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int dosfs_ini_write(char *buffer, PFILEINFO file)
|
|
|
|
{
|
|
|
|
/* TODO: Check this works */
|
2010-01-25 17:30:31 +01:00
|
|
|
DFS_WriteFile(file, PIOS_SDCARD_Sector, (uint8_t *)buffer, &SuccessCount, sizeof(buffer));
|
2010-01-23 18:31:14 +01:00
|
|
|
|
|
|
|
/* No errors */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dosfs_ini_rename(const char *source, const char *dest)
|
|
|
|
{
|
2010-01-24 14:03:13 +01:00
|
|
|
if(PIOS_SDCARD_FileCopy((char *)source, (char *)dest)) {
|
|
|
|
/* Error renaming file */
|
|
|
|
return 0;
|
2010-01-24 09:13:48 +01:00
|
|
|
}
|
|
|
|
|
2010-01-23 18:31:14 +01:00
|
|
|
/* No errors */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dosfs_ini_remove(const char *filename)
|
|
|
|
{
|
2010-01-24 14:03:13 +01:00
|
|
|
/* Remove the file */
|
|
|
|
if(PIOS_SDCARD_FileDelete((char *)filename)) {
|
|
|
|
/* Error deleting file */
|
2010-01-23 18:31:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No errors */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dosfs_ini_rewind(PFILEINFO file)
|
|
|
|
{
|
2010-01-24 09:13:48 +01:00
|
|
|
/* TODO: Check this works */
|
2010-01-25 17:30:31 +01:00
|
|
|
DFS_Seek(file, 0, PIOS_SDCARD_Sector);
|
2010-01-23 18:31:14 +01:00
|
|
|
/* No errors */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|