Project

General

Profile

« Previous | Next » 

Revision 191

Added by markw almost 11 years ago

Upgraded to v3 of petit fat fs. Should fix 64k file size limit.

View differences:

firmware/common/integer.h
#ifndef _INTEGER
#define _INTEGER
/* These types must be 16-bit, 32-bit or larger integer */
typedef int INT;
typedef unsigned int UINT;
/* These types must be 8-bit integer */
typedef char CHAR;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
typedef unsigned char u08;
typedef unsigned char uint8_t;
/* These types must be 16-bit integer */
typedef short SHORT;
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
typedef unsigned short u16;
/* These types must be 32-bit integer */
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
typedef unsigned int u32;
#define EEMEM
#endif
/*-------------------------------------------*/
/* Integer type definitions for FatFs module */
/*-------------------------------------------*/
#ifndef _FF_INTEGER
#define _FF_INTEGER
#ifdef _WIN32 /* FatFs development platform */
#include <windows.h>
#include <tchar.h>
#else /* Embedded platform */
/* This type MUST be 8 bit */
typedef unsigned char BYTE;
typedef unsigned char u08;
typedef unsigned char uint8_t;
/* These types MUST be 16 bit */
typedef short SHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
typedef unsigned short u16;
/* These types MUST be 16 bit or 32 bit */
typedef int INT;
typedef unsigned int UINT;
/* These types MUST be 32 bit */
typedef long LONG;
typedef unsigned int DWORD;
typedef unsigned int u32;
#endif
#endif
firmware/fat/pff.c
/*----------------------------------------------------------------------------/
/ Petit FatFs - FAT file system module R0.02a (C)ChaN, 2010
/ Petit FatFs - FAT file system module R0.03 (C)ChaN, 2014
/-----------------------------------------------------------------------------/
/ Petit FatFs module is an open source software to implement FAT file system to
/ small embedded systems. This is a free software and is opened for education,
/ research and commercial developments under license policy of following trems.
/ Petit FatFs module is a generic FAT file system module for small embedded
/ systems. This is a free software that opened for education, research and
/ commercial developments under license policy of following trems.
/
/ Copyright (C) 2010, ChaN, all right reserved.
/ Copyright (C) 2014, ChaN, all right reserved.
/
/ * The Petit FatFs module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
/ personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
/ personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
/ * Redistributions of source code must retain the above copyright notice.
/
/-----------------------------------------------------------------------------/
/ Jun 15,'09 R0.01a First release. (Branched from FatFs R0.07b.)
/ Jun 15,'09 R0.01a First release.
/
/ Dec 14,'09 R0.02 Added multiple code page support.
/ Added write funciton.
/ Changed stream read mode interface.
/ Dec 07,'10 R0.02a Added some configuration options.
/ Fixed fails to open objects with DBCS character.
/ Jun 10,'14 R0.03 Separated out configuration options to pffconf.h.
/ Added _USE_LCC option.
/ Added _FS_FAT16 option.
/----------------------------------------------------------------------------*/
#include "pff.h" /* Petit FatFs configurations and declarations */
......
---------------------------------------------------------------------------*/
#if _PFATFS != 4004 /* Revision ID */
#error Wrong include file (pff.h).
#endif
#if _FS_FAT32
#define LD_CLUST(dir) (((DWORD)LD_WORD(dir+DIR_FstClusHI)<<16) | LD_WORD(dir+DIR_FstClusLO))
#if !_FS_FAT16 && !_FS_FAT12
#define _FS_32ONLY 1
#else
#define LD_CLUST(dir) LD_WORD(dir+DIR_FstClusLO)
#define _FS_32ONLY 0
#endif
#else
#if !_FS_FAT16 && !_FS_FAT12
#error Wrong _FS_FATxx setting.
#endif
#define _FS_32ONLY 0
#endif
#define ABORT(err) {fs->flag = 0; return err;}
/*--------------------------------------------------------*/
/* DBCS code ranges and SBCS extend char conversion table */
/*--------------------------------------------------------*/
#if _CODE_PAGE == 932 /* Japanese Shift-JIS */
#define _DF1S 0x81 /* DBC 1st byte range 1 start */
......
#define _DS2E 0xFE
#elif _CODE_PAGE == 437 /* U.S. (OEM) */
#define _DF1S 0
#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F,0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0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xDF, \
0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
#elif _CODE_PAGE == 737 /* Greek (OEM) */
#define _DF1S 0
#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \
0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xE7,0xE8,0xF1,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
#elif _CODE_PAGE == 775 /* Baltic (OEM) */
#define _DF1S 0
#define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F,0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
0xA0,0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0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
#elif _CODE_PAGE == 874 /* Thai (OEM, Windows) */
#define _DF1S 0
#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
#elif _CODE_PAGE == 1250 /* Central Europe (Windows) */
#define _DF1S 0
#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x8D,0x8E,0x8F, \
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8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xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF}
#elif _CODE_PAGE == 1252 /* Latin 1 (Windows) */
#define _DF1S 0
#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0xAd,0x9B,0x8C,0x9D,0xAE,0x9F, \
0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F}
#elif _CODE_PAGE == 1253 /* Greek (Windows) */
#define _DF1S 0
#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0x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D1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x9F}
#elif _CODE_PAGE == 1255 /* Hebrew (Windows) */
#define _DF1S 0
#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
#elif _CODE_PAGE == 1256 /* Arabic (Windows) */
#define _DF1S 0
#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x8C,0x9D,0x9E,0x9F, \
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0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xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xFF}
#elif _CODE_PAGE == 1258 /* Vietnam (OEM, Windows) */
#define _DF1S 0
#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0xAC,0x9D,0x9E,0x9F, \
0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xEC,0xCD,0xCE,0xCF,0xD0,0xD1,0xF2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xFE,0x9F}
#elif _CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */
#define _DF1S 0
#else
#error Unknown code page
#error Unknown code page.
#endif
......
#define IsUpper(c) (((c)>='A')&&((c)<='Z'))
#define IsLower(c) (((c)>='a')&&((c)<='z'))
#if _DF1S /* DBCS configuration */
#ifndef _EXCVT /* DBCS configuration */
#ifdef _DF2S /* Two 1st byte areas */
#define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))
......
#define IsDBCS1(c) 0
#define IsDBCS2(c) 0
#endif /* _DF1S */
#endif /* _EXCVT */
/* FatFs refers the members in the FAT structures with byte offset instead
......
CLUST clst /* Cluster# to get the link information */
)
{
WORD wc, bc, ofs;
BYTE buf[4];
FATFS *fs = FatFs;
if (clst < 2 || clst >= fs->n_fatent) /* Range check */
return 1;
switch (fs->fs_type) {
#if _FS_FAT12
case FS_FAT12 :
bc = (WORD)clst; bc += bc / 2;
case FS_FAT12 : {
UINT wc, bc, ofs;
bc = (UINT)clst; bc += bc / 2;
ofs = bc % 512; bc /= 512;
if (ofs != 511) {
if (disk_readp(buf, fs->fatbase + bc, ofs, 2)) break;
......
}
wc = LD_WORD(buf);
return (clst & 1) ? (wc >> 4) : (wc & 0xFFF);
}
#endif
#if _FS_FAT16
case FS_FAT16 :
if (disk_readp(buf, fs->fatbase + clst / 256, (WORD)(((WORD)clst % 256) * 2), 2)) break;
if (disk_readp(buf, fs->fatbase + clst / 256, ((UINT)clst % 256) * 2, 2)) break;
return LD_WORD(buf);
#endif
#if _FS_FAT32
case FS_FAT32 :
if (disk_readp(buf, fs->fatbase + clst / 128, (WORD)(((WORD)clst % 128) * 4), 4)) break;
if (disk_readp(buf, fs->fatbase + clst / 128, ((UINT)clst % 128) * 4, 4)) break;
return LD_DWORD(buf) & 0x0FFFFFFF;
#endif
}
......
/*-----------------------------------------------------------------------*/
/* Get sector# from cluster# */
/* Get sector# from cluster# / Get cluster field from directory entry */
/*-----------------------------------------------------------------------*/
static
......
}
static
CLUST get_clust (
BYTE* dir /* Pointer to directory entry */
)
{
FATFS *fs = FatFs;
CLUST clst = 0;
if (_FS_32ONLY || (_FS_FAT32 && fs->fs_type == FS_FAT32)) {
clst = LD_WORD(dir+DIR_FstClusHI);
clst <<= 16;
}
clst |= LD_WORD(dir+DIR_FstClusLO);
return clst;
}
/*-----------------------------------------------------------------------*/
/* Directory handling - Rewind directory index */
/*-----------------------------------------------------------------------*/
......
clst = dj->sclust;
if (clst == 1 || clst >= fs->n_fatent) /* Check start cluster range */
return FR_DISK_ERR;
if (_FS_FAT32 && !clst && fs->fs_type == FS_FAT32) /* Replace cluster# 0 with root cluster# if in FAT32 */
if (_FS_FAT32 && !clst && (_FS_32ONLY || fs->fs_type == FS_FAT32)) /* Replace cluster# 0 with root cluster# if in FAT32 */
clst = (CLUST)fs->dirbase;
dj->clust = clst; /* Current cluster */
dj->sect = clst ? clust2sect(clst) : fs->dirbase; /* Current sector */
dj->sect = (_FS_32ONLY || clst) ? clust2sect(clst) : fs->dirbase; /* Current sector */
return FR_OK; /* Seek succeeded */
}
......
return FR_NO_FILE;
}
else { /* Dynamic table */
if (((i / 16) & (fs->csize-1)) == 0) { /* Cluster changed? */
if (((i / 16) & (fs->csize - 1)) == 0) { /* Cluster changed? */
clst = get_fat(dj->clust); /* Get next cluster */
if (clst <= 1) return FR_DISK_ERR;
if (clst >= fs->n_fatent) /* When it reached end of dynamic table */
......
if (res != FR_OK) return res;
do {
res = disk_readp(dir, dj->sect, (WORD)((dj->index % 16) * 32), 32) /* Read an entry */
res = disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32) /* Read an entry */
? FR_DISK_ERR : FR_OK;
if (res != FR_OK) break;
c = dir[DIR_Name]; /* First character */
......
FRESULT dir_read (
DIR *dj, /* Pointer to the directory object to store read object name */
BYTE *dir, /* 32-byte working buffer */
BYTE *lfn_buffer /* 256-byte lfn buffer */
char *lfn_buffer /* 256-byte lfn buffer */
)
{
FRESULT res;
BYTE a, c;
int lfn = 0;
char *lfn_pos = &lfn_buffer[255];
lfn_buffer[255] = '\0';
res = FR_NO_FILE;
while (dj->sect) {
res = disk_readp(dir, dj->sect, (WORD)((dj->index % 16) * 32), 32) /* Read an entry */
res = disk_readp(dir, dj->sect, (dj->index % 16) * 32, 32) /* Read an entry */
? FR_DISK_ERR : FR_OK;
if (res != FR_OK) break;
c = dir[DIR_Name];
if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */
......
lfn = 1;
}
if (c != 0xE5 && c != '.' && !(a & AM_VOL)) /* Is it a valid entry? */
break;
res = dir_next2(dj); /* Next entry */
......
/* Pick a segment and create the object name in directory form */
/*-----------------------------------------------------------------------*/
#ifdef _EXCVT
static const BYTE cvt[] = _EXCVT;
#endif
static
FRESULT create_name (
......
const char **path /* Pointer to pointer to the segment in the path string */
)
{
BYTE c, d, ni, si, i, *sfn;
BYTE c, ni, si, i, *sfn;
const char *p;
#if _USE_LCC
#ifdef _EXCVT
static const BYTE cvt[] = _EXCVT;
#endif
#endif
/* Create file name in directory form */
sfn = dj->fn;
......
i = 8; ni = 11;
continue;
}
#if _USE_LCC
#ifdef _EXCVT
if (c >= 0x80) /* To upper extended char (SBCS) */
c = cvt[c - 0x80];
#endif
if (IsDBCS1(c) && i < ni - 1) { /* DBC 1st byte? */
d = p[si++]; /* Get 2nd byte */
BYTE d = p[si++]; /* Get 2nd byte */
sfn[i++] = c;
sfn[i++] = d;
} else { /* Single byte code */
if (IsLower(c)) c -= 0x20; /* toupper */
} else
#endif
{ /* Single byte code */
if (_USE_LCC && IsLower(c)) c -= 0x20; /* toupper */
sfn[i++] = c;
}
}
......
FRESULT res;
while (*path == ' ') path++; /* Skip leading spaces */
if (*path == '/') path++; /* Strip heading separator */
while (*path == ' ') path++; /* Strip leading spaces */
if (*path == '/') path++; /* Strip heading separator if exist */
dj->sclust = 0; /* Set start directory (always root dir) */
if ((BYTE)*path <= ' ') { /* Null path means the root directory */
if ((BYTE)*path < ' ') { /* Null path means the root directory */
res = dir_rewind(dj);
dir[0] = 0;
......
res = create_name(dj, &path); /* Get a segment */
if (res != FR_OK) break;
res = dir_find(dj, dir); /* Find it */
if (res != FR_OK) { /* Could not find the object */
if (res == FR_NO_FILE && !*(dj->fn+11))
res = FR_NO_PATH;
break;
if (res != FR_OK) break; /* Could not find the object */
if (dj->fn[11]) break; /* Last segment match. Function completed. */
if (!(dir[DIR_Attr] & AM_DIR)) { /* Cannot follow path because it is a file */
res = FR_NO_FILE; break;
}
if (*(dj->fn+11)) break; /* Last segment match. Function completed. */
if (!(dir[DIR_Attr] & AM_DIR)) { /* Cannot follow because it is a file */
res = FR_NO_PATH; break;
}
dj->sclust = LD_CLUST(dir);
dj->sclust = get_clust(dir); /* Follow next */
}
}
......
DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */
)
{
if (disk_readp(buf, sect, 510, 2)) /* Read the boot sector */
if (disk_readp(buf, sect, 510, 2)) /* Read the boot record */
return 3;
if (LD_WORD(buf) != 0xAA55) /* Check record signature */
return 2;
if (!disk_readp(buf, sect, BS_FilSysType, 2) && LD_WORD(buf) == 0x4146) /* Check FAT12/16 */
if (!_FS_32ONLY && !disk_readp(buf, sect, BS_FilSysType, 2) && LD_WORD(buf) == 0x4146) /* Check FAT12/16 */
return 0;
if (_FS_FAT32 && !disk_readp(buf, sect, BS_FilSysType32, 2) && LD_WORD(buf) == 0x4146) /* Check FAT32 */
return 0;
......
/*-----------------------------------------------------------------------*/
FRESULT pf_mount (
FATFS *fs /* Pointer to new file system object (NULL: Unmount) */
FATFS *fs /* Pointer to new file system object */
)
{
BYTE fmt, buf[36];
......
FatFs = 0;
if (!fs) return FR_OK; /* Unregister fs object */
if (disk_initialize() & STA_NOINIT) /* Check if the drive is ready or not */
return FR_NOT_READY;
......
if (fmt) return FR_NO_FILESYSTEM; /* No valid FAT patition is found */
/* Initialize the file system object */
if (disk_readp(buf, bsect, 13, sizeof(buf))) return FR_DISK_ERR;
if (disk_readp(buf, bsect, 13, sizeof (buf))) return FR_DISK_ERR;
fsize = LD_WORD(buf+BPB_FATSz16-13); /* Number of sectors per FAT */
if (!fsize) fsize = LD_DWORD(buf+BPB_FATSz32-13);
......
) / fs->csize + 2;
fs->n_fatent = (CLUST)mclst;
fmt = FS_FAT16; /* Determine the FAT sub type */
if (mclst < 0xFF7) /* Number of clusters < 0xFF5 */
#if _FS_FAT12
fmt = 0; /* Determine the FAT sub type */
if (_FS_FAT12 && mclst < 0xFF7)
fmt = FS_FAT12;
#else
return FR_NO_FILESYSTEM;
#endif
if (mclst >= 0xFFF7) /* Number of clusters >= 0xFFF5 */
#if _FS_FAT32
if (_FS_FAT16 && mclst >= 0xFF8 && mclst < 0xFFF7)
fmt = FS_FAT16;
if (_FS_FAT32 && mclst >= 0xFFF7)
fmt = FS_FAT32;
#else
return FR_NO_FILESYSTEM;
#endif
if (!fmt) return FR_NO_FILESYSTEM;
fs->fs_type = fmt;
fs->fs_type = fmt; /* FAT sub-type */
if (_FS_FAT32 && fmt == FS_FAT32)
if (_FS_32ONLY || (_FS_FAT32 && fmt == FS_FAT32))
fs->dirbase = LD_DWORD(buf+(BPB_RootClus-13)); /* Root directory start cluster */
else
fs->dirbase = fs->fatbase + fsize; /* Root directory start sector (lba) */
......
FATFS *fs = FatFs;
if (!fs) /* Check file system */
return FR_NOT_ENABLED;
if (!fs) return FR_NOT_ENABLED; /* Check file system */
fs->flag = 0;
dj.fn = sp;
......
if (!dir[0] || (dir[DIR_Attr] & AM_DIR)) /* It is a directory */
return FR_NO_FILE;
fs->org_clust = LD_CLUST(dir); /* File start cluster */
fs->org_clust = get_clust(dir); /* File start cluster */
fs->fsize = LD_DWORD(dir+DIR_FileSize); /* File size */
fs->fptr = 0; /* File pointer */
fs->flag = FA_OPENED;
......
FRESULT pf_read (
void* buff, /* Pointer to the read buffer (NULL:Forward data to the stream)*/
WORD btr, /* Number of bytes to read */
WORD* br /* Pointer to number of bytes read */
UINT btr, /* Number of bytes to read */
UINT* br /* Pointer to number of bytes read */
)
{
DRESULT dr;
CLUST clst;
DWORD sect, remain;
WORD rcnt;
UINT rcnt;
BYTE cs, *rbuff = (BYTE *)buff;
FATFS *fs = FatFs;
......
return FR_NOT_OPENED;
remain = fs->fsize - fs->fptr;
if (btr > remain) btr = (WORD)remain; /* Truncate btr by remaining bytes */
if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */
while (btr) { /* Repeat until all data transferred */
if ((fs->fptr % 512) == 0) { /* On the sector boundary? */
cs = (BYTE)(fs->fptr / 512 & (fs->csize - 1)); /* Sector offset in the cluster */
if (!cs) { /* On the cluster boundary? */
clst = (fs->fptr == 0) ? /* On the top of the file? */
fs->org_clust : get_fat(fs->curr_clust);
if (clst <= 1) goto fr_abort;
if (fs->fptr == 0) /* On the top of the file? */
clst = fs->org_clust;
else
clst = get_fat(fs->curr_clust);
if (clst <= 1) ABORT(FR_DISK_ERR);
fs->curr_clust = clst; /* Update current cluster */
}
sect = clust2sect(fs->curr_clust); /* Get current sector */
if (!sect) goto fr_abort;
if (!sect) ABORT(FR_DISK_ERR);
fs->dsect = sect + cs;
}
rcnt = (WORD)(512 - (fs->fptr % 512)); /* Get partial sector data from sector buffer */
rcnt = 512 - (UINT)fs->fptr % 512; /* Get partial sector data from sector buffer */
if (rcnt > btr) rcnt = btr;
dr = disk_readp(!buff ? 0 : rbuff, fs->dsect, (WORD)(fs->fptr % 512), rcnt);
if (dr) goto fr_abort;
dr = disk_readp(!buff ? 0 : rbuff, fs->dsect, (UINT)fs->fptr % 512, rcnt);
if (dr) ABORT(FR_DISK_ERR);
fs->fptr += rcnt; rbuff += rcnt; /* Update pointers and counters */
btr -= rcnt; *br += rcnt;
}
return FR_OK;
fr_abort:
fs->flag = 0;
return FR_DISK_ERR;
}
#endif
......
FRESULT pf_write (
const void* buff, /* Pointer to the data to be written */
WORD btw, /* Number of bytes to write (0:Finalize the current write operation) */
WORD* bw /* Pointer to number of bytes written */
UINT btw, /* Number of bytes to write (0:Finalize the current write operation) */
UINT* bw /* Pointer to number of bytes written */
)
{
CLUST clst;
DWORD sect, remain;
const BYTE *p = buff;
BYTE cs;
WORD wcnt;
UINT wcnt;
FATFS *fs = FatFs;
......
return FR_NOT_OPENED;
if (!btw) { /* Finalize request */
if ((fs->flag & FA__WIP) && disk_writep(0, 0)) goto fw_abort;
if ((fs->flag & FA__WIP) && disk_writep(0, 0)) ABORT(FR_DISK_ERR);
fs->flag &= ~FA__WIP;
return FR_OK;
} else { /* Write data request */
......
fs->fptr &= 0xFFFFFE00;
}
remain = fs->fsize - fs->fptr;
if (btw > remain) btw = (WORD)remain; /* Truncate btw by remaining bytes */
if (btw > remain) btw = (UINT)remain; /* Truncate btw by remaining bytes */
while (btw) { /* Repeat until all data transferred */
if (((WORD)fs->fptr % 512) == 0) { /* On the sector boundary? */
if ((UINT)fs->fptr % 512 == 0) { /* On the sector boundary? */
cs = (BYTE)(fs->fptr / 512 & (fs->csize - 1)); /* Sector offset in the cluster */
if (!cs) { /* On the cluster boundary? */
clst = (fs->fptr == 0) ? /* On the top of the file? */
fs->org_clust : get_fat(fs->curr_clust);
if (clst <= 1) goto fw_abort;
if (fs->fptr == 0) /* On the top of the file? */
clst = fs->org_clust;
else
clst = get_fat(fs->curr_clust);
if (clst <= 1) ABORT(FR_DISK_ERR);
fs->curr_clust = clst; /* Update current cluster */
}
sect = clust2sect(fs->curr_clust); /* Get current sector */
if (!sect) goto fw_abort;
if (!sect) ABORT(FR_DISK_ERR);
fs->dsect = sect + cs;
if (disk_writep(0, fs->dsect)) goto fw_abort; /* Initiate a sector write operation */
if (disk_writep(0, fs->dsect)) ABORT(FR_DISK_ERR); /* Initiate a sector write operation */
fs->flag |= FA__WIP;
}
wcnt = 512 - ((WORD)fs->fptr % 512); /* Number of bytes to write to the sector */
wcnt = 512 - (UINT)fs->fptr % 512; /* Number of bytes to write to the sector */
if (wcnt > btw) wcnt = btw;
if (disk_writep(p, wcnt)) goto fw_abort; /* Send data to the sector */
if (disk_writep(p, wcnt)) ABORT(FR_DISK_ERR); /* Send data to the sector */
fs->fptr += wcnt; p += wcnt; /* Update pointers and counters */
btw -= wcnt; *bw += wcnt;
if (((WORD)fs->fptr % 512) == 0) {
if (disk_writep(0, 0)) goto fw_abort; /* Finalize the currtent secter write operation */
if ((UINT)fs->fptr % 512 == 0) {
if (disk_writep(0, 0)) ABORT(FR_DISK_ERR); /* Finalize the currtent secter write operation */
fs->flag &= ~FA__WIP;
}
}
return FR_OK;
fw_abort:
fs->flag = 0;
return FR_DISK_ERR;
}
#endif
......
}
while (ofs > bcs) { /* Cluster following loop */
clst = get_fat(clst); /* Follow cluster chain */
if (clst <= 1 || clst >= fs->n_fatent) goto fe_abort;
if (clst <= 1 || clst >= fs->n_fatent) ABORT(FR_DISK_ERR);
fs->curr_clust = clst;
fs->fptr += bcs;
ofs -= bcs;
}
fs->fptr += ofs;
sect = clust2sect(clst); /* Current sector */
if (!sect) goto fe_abort;
if (!sect) ABORT(FR_DISK_ERR);
fs->dsect = sect + (fs->fptr / 512 & (fs->csize - 1));
}
return FR_OK;
fe_abort:
fs->flag = 0;
return FR_DISK_ERR;
}
#endif
......
if (res == FR_OK) { /* Follow completed */
if (dir[0]) { /* It is not the root dir */
if (dir[DIR_Attr] & AM_DIR) /* The object is a directory */
dj->sclust = LD_CLUST(dir);
dj->sclust = get_clust(dir);
else /* The object is not a directory */
res = FR_NO_PATH;
res = FR_NO_FILE;
}
if (res == FR_OK)
res = dir_rewind(dj); /* Rewind dir */
}
if (res == FR_NO_FILE) res = FR_NO_PATH;
}
return res;
......
res = dir_rewind(dj);
} else {
res = dir_read(dj, dir, &fno->lfname[0]);
if (res == FR_NO_FILE) {
dj->sect = 0;
res = FR_OK;
}
if (res == FR_NO_FILE) res = FR_OK;
if (res == FR_OK) { /* A valid entry is found */
get_fileinfo(dj, dir, fno); /* Get the object information */
res = dir_next2(dj); /* Increment index for next */
if (res == FR_NO_FILE) {
dj->sect = 0;
res = FR_OK;
}
if (res == FR_NO_FILE) res = FR_OK;
}
}
}
firmware/fat/pff.h
/*---------------------------------------------------------------------------/
/ Petit FatFs - FAT file system module include file R0.02a (C)ChaN, 2010
/ Petit FatFs - FAT file system module include file R0.03 (C)ChaN, 2014
/----------------------------------------------------------------------------/
/ Petit FatFs module is an open source software to implement FAT file system to
/ small embedded systems. This is a free software and is opened for education,
/ research and commercial developments under license policy of following trems.
/
/ Copyright (C) 2010, ChaN, all right reserved.
/ Copyright (C) 2014, ChaN, all right reserved.
/
/ * The Petit FatFs module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
......
/
/----------------------------------------------------------------------------*/
#include "integer.h"
#ifndef _PFATFS
#define _PFATFS 4004 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Petit FatFs Configuration Options
/
/ CAUTION! Do not forget to make clean the project after any changes to
/ the configuration options.
/
/----------------------------------------------------------------------------*/
#ifndef _FATFS
#define _FATFS
#ifdef __cplusplus
extern "C" {
#endif
#define _USE_READ 1 /* 1:Enable pf_read() */
#include "integer.h"
#include "pffconf.h"
#define _USE_DIR 1 /* 1:Enable pf_opendir() and pf_readdir() */
#if _PFATFS != _PFFCONF
#error Wrong configuration file (pffconf.h).
#endif
#define _USE_LSEEK 1 /* 1:Enable pf_lseek() */
#define _USE_WRITE 0 /* 1:Enable pf_write() */
#define _FS_FAT12 1 /* 1:Enable FAT12 support */
#define _FS_FAT32 1 /* 1:Enable FAT32 support */
#define _CODE_PAGE 1
/* Defines which code page is used for path name. Supported code pages are:
/ 932, 936, 949, 950, 437, 720, 737, 775, 850, 852, 855, 857, 858, 862, 866,
/ 874, 1250, 1251, 1252, 1253, 1254, 1255, 1257, 1258 and 1 (ASCII only).
/ SBCS code pages except for 1 requiers a case conversion table. This
/ might occupy 128 bytes on the RAM on some platforms, e.g. avr-gcc. */
#define _WORD_ACCESS 0
/* The _WORD_ACCESS option defines which access method is used to the word
/ data in the FAT structure.
/
/ 0: Byte-by-byte access. Always compatible with all platforms.
/ 1: Word access. Do not choose this unless following condition is met.
/
/ When the byte order on the memory is big-endian or address miss-aligned
/ word access results incorrect behavior, the _WORD_ACCESS must be set to 0.
/ If it is not the case, the value can also be set to 1 to improve the
/ performance and code efficiency. */
/* End of configuration options. Do not change followings without care. */
/*--------------------------------------------------------------------------*/
#if _FS_FAT32
#define CLUST DWORD
#else
......
FR_DISK_ERR, /* 1 */
FR_NOT_READY, /* 2 */
FR_NO_FILE, /* 3 */
FR_NO_PATH, /* 4 */
FR_NOT_OPENED, /* 5 */
FR_NOT_ENABLED, /* 6 */
FR_NO_FILESYSTEM /* 7 */
FR_NOT_OPENED, /* 4 */
FR_NOT_ENABLED, /* 5 */
FR_NO_FILESYSTEM /* 6 */
} FRESULT;
......
/*--------------------------------------------------------------*/
/* Petit FatFs module application interface */
FRESULT pf_mount (FATFS*); /* Mount/Unmount a logical drive */
FRESULT pf_open (const char*); /* Open a file */
FRESULT pf_read (void*, WORD, WORD*); /* Read data from the open file */
FRESULT pf_write (const void*, WORD, WORD*); /* Write data to the open file */
FRESULT pf_lseek (DWORD); /* Move file pointer of the open file */
FRESULT pf_opendir (DIR*, const char*); /* Open a directory */
FRESULT pf_readdir (DIR*, FILINFO*); /* Read a directory item from the open directory */
FRESULT pf_mount (FATFS* fs); /* Mount/Unmount a logical drive */
FRESULT pf_open (const char* path); /* Open a file */
FRESULT pf_read (void* buff, UINT btr, UINT* br); /* Read data from the open file */
FRESULT pf_write (const void* buff, UINT btw, UINT* bw); /* Write data to the open file */
FRESULT pf_lseek (DWORD ofs); /* Move file pointer of the open file */
FRESULT pf_opendir (DIR* dj, const char* path); /* Open a directory */
FRESULT pf_readdir (DIR* dj, FILINFO* fno); /* Read a directory item from the open directory */
......
#endif
#endif /* _FATFS */
#ifdef __cplusplus
}
#endif
#endif /* _PFATFS */
firmware/fat/pff_file.c
enum SimpleFileStatus file_read(struct SimpleFile * file, void * buffer, int bytes, int * bytesread)
{
WORD bytesread_word;
UINT bytesread_word;
FRESULT res;
file_write_flush();
......
enum SimpleFileStatus file_write(struct SimpleFile * file, void * buffer, int bytes, int * byteswritten)
{
WORD byteswritten_word;
UINT byteswritten_word;
FRESULT res;
//printf("went\n");
firmware/fat/pffconf.h
/*---------------------------------------------------------------------------/
/ Petit FatFs - Configuration file R0.03 (C)ChaN, 2014
/---------------------------------------------------------------------------*/
#ifndef _PFFCONF
#define _PFFCONF 4004 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Function Configurations
/---------------------------------------------------------------------------*/
#define _USE_READ 1 /* Enable pf_read() function */
#define _USE_DIR 1 /* Enable pf_opendir() and pf_readdir() function */
#define _USE_LSEEK 1 /* Enable pf_lseek() function */
#define _USE_WRITE 0 /* Enable pf_write() function */
#define _FS_FAT12 0 /* Enable FAT12 */
#define _FS_FAT16 1 /* Enable FAT16 */
#define _FS_FAT32 1 /* Enable FAT32 */
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/---------------------------------------------------------------------------*/
#define _USE_LCC 1 /* Allow lower case characters for path name */
#define _CODE_PAGE 437
/* The _CODE_PAGE specifies the code page to be used on the target system.
/ SBCS code pages with _USE_LCC == 1 requiers a 128 byte of case conversion
/ table. This might occupy RAM on some platforms, e.g. avr-gcc.
/ When _USE_LCC == 0, _CODE_PAGE has no effect.
/
/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
/ 949 - Korean (DBCS, OEM, Windows)
/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
/ 1250 - Central Europe (Windows)
/ 1251 - Cyrillic (Windows)
/ 1252 - Latin 1 (Windows)
/ 1253 - Greek (Windows)
/ 1254 - Turkish (Windows)
/ 1255 - Hebrew (Windows)
/ 1256 - Arabic (Windows)
/ 1257 - Baltic (Windows)
/ 1258 - Vietnam (OEM, Windows)
/ 437 - U.S. (OEM)
/ 720 - Arabic (OEM)
/ 737 - Greek (OEM)
/ 775 - Baltic (OEM)
/ 850 - Multilingual Latin 1 (OEM)
/ 858 - Multilingual Latin 1 + Euro (OEM)
/ 852 - Latin 2 (OEM)
/ 855 - Cyrillic (OEM)
/ 866 - Russian (OEM)
/ 857 - Turkish (OEM)
/ 862 - Hebrew (OEM)
/ 874 - Thai (OEM, Windows)
*/
/*---------------------------------------------------------------------------/
/ System Configurations
/---------------------------------------------------------------------------*/
#define _WORD_ACCESS 0
/* The _WORD_ACCESS option is an only platform dependent option. It defines
/ which access method is used to the word data on the FAT volume.
/
/ 0: Byte-by-byte access. Always compatible with all platforms.
/ 1: Word access. Do not choose this unless under both the following conditions.
/
/ * Address misaligned memory access is always allowed for ALL instructions.
/ * Byte order on the memory is little-endian.
/
/ If it is the case, _WORD_ACCESS can also be set to 1 to improve performance and
/ reduce code size. Following table shows an example of some processor types.
/
/ ARM7TDMI 0 ColdFire 0 V850E 0
/ Cortex-M3 0 Z80 0/1 V850ES 0/1
/ Cortex-M0 0 RX600(LE) 0/1 TLCS-870 0/1
/ AVR 0/1 RX600(BE) 0 TLCS-900 0/1
/ AVR32 0 RL78 0 R32C 0
/ PIC18 0/1 SH-2 0 M16C 0/1
/ PIC24 0 H8S 0 MSP430 0
/ PIC32 0 H8/300H 0 x86 0/1
*/
#endif /* _PFFCONF */

Also available in: Unified diff