1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-02 19:29:15 +01:00
gussy 26410ad8de Back to where we were with r133, but now with proper SD Card code.
Additions to note; PIOS_SPI, DosFS and PIOS_SDCARD.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@136 ebee16cc-31ac-478f-84a7-5cbb03baadba
2010-01-23 17:31:14 +00:00

127 lines
2.6 KiB
C

#include "dosfs.h"
#include "pios.h"
#include "minGlue.h"
/* TODO: Use global filesystem mounting */
/* TODO: Implement error handling properly */
static uint8_t Sector[SECTOR_SIZE];
static VOLINFO vi;
static uint32_t pstart, psize;
static uint8_t pactive, ptype;
static uint32_t successcount;
int dosfs_ini_openread(const char *filename, PFILEINFO file)
{
pstart = DFS_GetPtnStart(0, Sector, 0, &pactive, &ptype, &psize);
if (pstart == 0xffffffff) {
/* Cannot find first partition */
return 0;
}
if(DFS_GetVolInfo(0, Sector, pstart, &vi) != DFS_OK) {
/* No volume information */
return 0;
}
if(DFS_OpenFile(&vi, (uint8_t *)filename, DFS_READ, Sector, file)) {
/* Error opening file */
return 0;
}
/* No errors */
return 1;
}
int dosfs_ini_openwrite(const char *filename, PFILEINFO file)
{
pstart = DFS_GetPtnStart(0, Sector, 0, &pactive, &ptype, &psize);
if (pstart == 0xffffffff) {
/* Cannot find first partition */
return 0;
}
if(DFS_GetVolInfo(0, Sector, pstart, &vi) != DFS_OK) {
/* No volume information */
return 0;
}
if(DFS_OpenFile(&vi, (uint8_t *)filename, DFS_WRITE, Sector, file)) {
/* 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)
{
DFS_ReadFile(file, Sector, (uint8_t *)buffer, &successcount, size);
if(successcount == size) {
/* No errors */
return 1;
} else {
/* Reached EOF */
return 0;
}
}
int dosfs_ini_write(char *buffer, PFILEINFO file)
{
/* TODO: Check this works */
DFS_WriteFile(file, Sector, (uint8_t *)buffer, &successcount, sizeof(buffer));
/* No errors */
return 1;
}
int dosfs_ini_rename(const char *source, const char *dest)
{
/* TODO: Implement, or just don't, since we aren't planning on using renaming */
/* No errors */
return 1;
}
int dosfs_ini_remove(const char *filename)
{
VOLINFO vi;
uint32_t pstart, psize;
uint8_t pactive, ptype;
pstart = DFS_GetPtnStart(0, Sector, 0, &pactive, &ptype, &psize);
if (pstart == 0xffffffff) {
/* Cannot find first partition */
return 0;
}
if(DFS_GetVolInfo(0, Sector, pstart, &vi) != DFS_OK) {
/* No volume information */
return 0;
}
/* Remove the file */
DFS_UnlinkFile(&vi, (uint8_t *)filename, Sector);
/* No errors */
return 1;
}
int dosfs_ini_rewind(PFILEINFO file)
{
DFS_Seek(file, 0, Sector);
/* No errors */
return 1;
}