summaryrefslogtreecommitdiff
path: root/fatfs/src
diff options
context:
space:
mode:
authorLeo C2014-11-17 14:47:05 +0100
committerLeo C2014-11-17 14:47:05 +0100
commit7b78a5a287827db9e9b16286f3604aef69b37c5c (patch)
tree6a3788876f5d701f42663f0a498068f18e39df79 /fatfs/src
parent5366852335044c1e68a5c32548d3051cc943552f (diff)
downloadz180-stamp-7b78a5a287827db9e9b16286f3604aef69b37c5c.zip
Import fatfs R0.10cfatfs-0.10c
Diffstat (limited to 'fatfs/src')
-rw-r--r--fatfs/src/00readme.txt7
-rw-r--r--fatfs/src/diskio.c66
-rw-r--r--fatfs/src/diskio.h16
-rw-r--r--fatfs/src/ff.c439
-rw-r--r--fatfs/src/ff.h9
-rw-r--r--fatfs/src/ffconf.h224
-rw-r--r--fatfs/src/option/cc932.c6
-rw-r--r--fatfs/src/option/cc936.c4
-rw-r--r--fatfs/src/option/cc949.c4
-rw-r--r--fatfs/src/option/cc950.c4
-rw-r--r--fatfs/src/option/ccsbcs.c2
-rw-r--r--fatfs/src/option/syscall.c38
12 files changed, 437 insertions, 382 deletions
diff --git a/fatfs/src/00readme.txt b/fatfs/src/00readme.txt
index 7285d33..b30f7d3 100644
--- a/fatfs/src/00readme.txt
+++ b/fatfs/src/00readme.txt
@@ -1,4 +1,4 @@
-FatFs Module Source Files R0.10b (C)ChaN, 2014
+FatFs Module Source Files R0.10c (C)ChaN, 2014
FILES
@@ -156,3 +156,8 @@ REVISION HISTORY
Mar 19,'14 R0.10b Fixed a hard error in the disk I/O layer can collapse the directory entry.
Fixed LFN entry is not deleted on delete/rename an object with lossy converted SFN.
+
+ Nov 09,'14 R0.10c Added a configuration option for the platforms without RTC. (_FS_NORTC)
+ Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel().
+ Fixed a potential problem of FAT access that can appear on disk error.
+ Fixed null pointer dereference on attempting to delete the root direcotry.
diff --git a/fatfs/src/diskio.c b/fatfs/src/diskio.c
index 64194eb..169ae95 100644
--- a/fatfs/src/diskio.c
+++ b/fatfs/src/diskio.c
@@ -1,10 +1,10 @@
/*-----------------------------------------------------------------------*/
-/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2013 */
+/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
/*-----------------------------------------------------------------------*/
/* If a working storage control module is available, it should be */
/* attached to the FatFs via a glue function rather than modifying it. */
/* This is an example of glue functions to attach various exsisting */
-/* storage control module to the FatFs module with a defined API. */
+/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include "diskio.h" /* FatFs lower layer API */
@@ -12,18 +12,18 @@
#include "atadrive.h" /* Example: ATA drive control */
#include "sdcard.h" /* Example: MMC/SDC contorl */
-/* Definitions of physical drive number for each media */
-#define ATA 0
-#define MMC 1
-#define USB 2
+/* Definitions of physical drive number for each drive */
+#define ATA 0 /* Example: Map ATA drive to drive number 0 */
+#define MMC 1 /* Example: Map MMC/SD card to drive number 1 */
+#define USB 2 /* Example: Map USB drive to drive number 2 */
/*-----------------------------------------------------------------------*/
-/* Inidialize a Drive */
+/* Get Drive Status */
/*-----------------------------------------------------------------------*/
-DSTATUS disk_initialize (
- BYTE pdrv /* Physical drive nmuber (0..) */
+DSTATUS disk_status (
+ BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
DSTATUS stat;
@@ -31,21 +31,21 @@ DSTATUS disk_initialize (
switch (pdrv) {
case ATA :
- result = ATA_disk_initialize();
+ result = ATA_disk_status();
// translate the reslut code here
return stat;
case MMC :
- result = MMC_disk_initialize();
+ result = MMC_disk_status();
// translate the reslut code here
return stat;
case USB :
- result = USB_disk_initialize();
+ result = USB_disk_status();
// translate the reslut code here
@@ -57,11 +57,11 @@ DSTATUS disk_initialize (
/*-----------------------------------------------------------------------*/
-/* Get Disk Status */
+/* Inidialize a Drive */
/*-----------------------------------------------------------------------*/
-DSTATUS disk_status (
- BYTE pdrv /* Physical drive nmuber (0..) */
+DSTATUS disk_initialize (
+ BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
DSTATUS stat;
@@ -69,21 +69,21 @@ DSTATUS disk_status (
switch (pdrv) {
case ATA :
- result = ATA_disk_status();
+ result = ATA_disk_initialize();
// translate the reslut code here
return stat;
case MMC :
- result = MMC_disk_status();
+ result = MMC_disk_initialize();
// translate the reslut code here
return stat;
case USB :
- result = USB_disk_status();
+ result = USB_disk_initialize();
// translate the reslut code here
@@ -99,10 +99,10 @@ DSTATUS disk_status (
/*-----------------------------------------------------------------------*/
DRESULT disk_read (
- BYTE pdrv, /* Physical drive nmuber (0..) */
+ BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
- DWORD sector, /* Sector address (LBA) */
- UINT count /* Number of sectors to read (1..128) */
+ DWORD sector, /* Sector address in LBA */
+ UINT count /* Number of sectors to read */
)
{
DRESULT res;
@@ -136,6 +136,7 @@ DRESULT disk_read (
return res;
}
+
return RES_PARERR;
}
@@ -147,10 +148,10 @@ DRESULT disk_read (
#if _USE_WRITE
DRESULT disk_write (
- BYTE pdrv, /* Physical drive nmuber (0..) */
+ BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
- DWORD sector, /* Sector address (LBA) */
- UINT count /* Number of sectors to write (1..128) */
+ DWORD sector, /* Sector address in LBA */
+ UINT count /* Number of sectors to write */
)
{
DRESULT res;
@@ -184,6 +185,7 @@ DRESULT disk_write (
return res;
}
+
return RES_PARERR;
}
#endif
@@ -205,32 +207,24 @@ DRESULT disk_ioctl (
switch (pdrv) {
case ATA :
- // pre-process here
-
- result = ATA_disk_ioctl(cmd, buff);
- // post-process here
+ // Process of the command for the ATA drive
return res;
case MMC :
- // pre-process here
- result = MMC_disk_ioctl(cmd, buff);
-
- // post-process here
+ // Process of the command for the MMC/SD card
return res;
case USB :
- // pre-process here
-
- result = USB_disk_ioctl(cmd, buff);
- // post-process here
+ // Process of the command the USB drive
return res;
}
+
return RES_PARERR;
}
#endif
diff --git a/fatfs/src/diskio.h b/fatfs/src/diskio.h
index 3c2b09d..9650f68 100644
--- a/fatfs/src/diskio.h
+++ b/fatfs/src/diskio.h
@@ -1,5 +1,5 @@
/*-----------------------------------------------------------------------/
-/ Low level disk interface modlue include file (C)ChaN, 2013 /
+/ Low level disk interface modlue include file (C)ChaN, 2014 /
/-----------------------------------------------------------------------*/
#ifndef _DISKIO_DEFINED
@@ -48,14 +48,14 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
/* Command code for disk_ioctrl fucntion */
-/* Generic command (used by FatFs) */
-#define CTRL_SYNC 0 /* Flush disk cache (for write functions) */
-#define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */
-#define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */
-#define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */
-#define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */
+/* Generic command (Used by FatFs) */
+#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
+#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
+#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
+#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
+#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
-/* Generic command (not used by FatFs) */
+/* Generic command (Not used by FatFs) */
#define CTRL_POWER 5 /* Get/Set power status */
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
#define CTRL_EJECT 7 /* Eject media */
diff --git a/fatfs/src/ff.c b/fatfs/src/ff.c
index 2edbe32..9c887c4 100644
--- a/fatfs/src/ff.c
+++ b/fatfs/src/ff.c
@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------/
-/ FatFs - FAT file system module R0.10b (C)ChaN, 2014
+/ FatFs - FAT file system module R0.10c (C)ChaN, 2014
/-----------------------------------------------------------------------------/
/ 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
@@ -113,6 +113,10 @@
/ Fixed creation of an entry with LFN fails on too many SFN collisions.
/ May 19,'14 R0.10b Fixed a hard error in the disk I/O layer can collapse the directory entry.
/ Fixed LFN entry is not deleted on delete/rename an object with lossy converted SFN.
+/ Nov 09,'14 R0.10c Added a configuration option for the platforms without RTC. (_FS_NORTC)
+/ Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel().
+/ Fixed a potential problem of FAT access that can appear on disk error.
+/ Fixed null pointer dereference on attempting to delete the root direcotry.
/---------------------------------------------------------------------------*/
#include "ff.h" /* Declarations of FatFs API */
@@ -127,7 +131,7 @@
---------------------------------------------------------------------------*/
-#if _FATFS != 8051 /* Revision ID */
+#if _FATFS != 80376 /* Revision ID */
#error Wrong include file (ff.h).
#endif
@@ -135,7 +139,7 @@
/* Reentrancy related */
#if _FS_REENTRANT
#if _USE_LFN == 1
-#error Static LFN work area cannot be used at thread-safe configuration.
+#error Static LFN work area cannot be used at thread-safe configuration
#endif
#define ENTER_FF(fs) { if (!lock_fs(fs)) return FR_TIMEOUT; }
#define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; }
@@ -149,7 +153,7 @@
/* Definitions of sector size */
#if (_MAX_SS < _MIN_SS) || (_MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096) || (_MIN_SS != 512 && _MIN_SS != 1024 && _MIN_SS != 2048 && _MIN_SS != 4096)
-#error Wrong sector size configuration.
+#error Wrong sector size configuration
#endif
#if _MAX_SS == _MIN_SS
#define SS(fs) ((UINT)_MAX_SS) /* Fixed sector size */
@@ -158,10 +162,18 @@
#endif
+/* Timestamp feature */
+#if _FS_NORTC
+#define GET_FATTIME() ((DWORD)_NORTC_YEAR << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
+#else
+#define GET_FATTIME() get_fattime()
+#endif
+
+
/* File access control feature */
#if _FS_LOCK
#if _FS_READONLY
-#error _FS_LOCK must be 0 at read-only cfg.
+#error _FS_LOCK must be 0 at read-only configuration
#endif
typedef struct {
FATFS *fs; /* Object ID 1, volume (NULL:blank entry) */
@@ -398,7 +410,7 @@ typedef struct {
/* Name status flags */
-#define NS 11 /* Index of name status byte in fn[] */
+#define NSFLAG 11 /* Index of name status byte in fn[] */
#define NS_LOSS 0x01 /* Out of 8.3 format */
#define NS_LFN 0x02 /* Force to create LFN entry */
#define NS_LAST 0x04 /* Last segment */
@@ -407,16 +419,16 @@ typedef struct {
#define NS_DOT 0x20 /* Dot entry */
-/* FAT sub-type boundaries */
-#define MIN_FAT16 4086U /* Minimum number of clusters for FAT16 */
-#define MIN_FAT32 65526U /* Minimum number of clusters for FAT32 */
+/* FAT sub-type boundaries (Differ from specs but correct for real DOS/Windows) */
+#define MIN_FAT16 4086U /* Minimum number of clusters as FAT16 */
+#define MIN_FAT32 65526U /* Minimum number of clusters as FAT32 */
/* FatFs refers the members in the FAT structures as byte array instead of
/ structure member because the structure is not binary compatible between
/ different platforms */
-#define BS_jmpBoot 0 /* Jump instruction (3) */
+#define BS_jmpBoot 0 /* x86 jump instruction (3) */
#define BS_OEMName 3 /* OEM name (8) */
#define BPB_BytsPerSec 11 /* Sector size [byte] (2) */
#define BPB_SecPerClus 13 /* Cluster size [sector] (1) */
@@ -482,63 +494,53 @@ typedef struct {
/*------------------------------------------------------------*/
/* Module private work area */
/*------------------------------------------------------------*/
-/* Note that uninitialized variables with static duration are
-/ guaranteed zero/null as initial value. If not, either the
-/ linker or start-up routine is out of ANSI-C standard.
+/* Remark: Uninitialized variables with static duration are
+/ guaranteed zero/null at start-up. If not, either the linker
+/ or start-up routine being used is out of ANSI-C standard.
*/
-#if _VOLUMES >= 1 || _VOLUMES <= 10
-static
-FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */
-#else
-#error Number of volumes must be 1 to 10.
+#if _VOLUMES < 1 || _VOLUMES > 9
+#error Wrong _VOLUMES setting
#endif
-
-static
-WORD Fsid; /* File system mount ID */
+static FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */
+static WORD Fsid; /* File system mount ID */
#if _FS_RPATH && _VOLUMES >= 2
-static
-BYTE CurrVol; /* Current drive */
+static BYTE CurrVol; /* Current drive */
#endif
#if _FS_LOCK
-static
-FILESEM Files[_FS_LOCK]; /* Open object lock semaphores */
+static FILESEM Files[_FS_LOCK]; /* Open object lock semaphores */
#endif
-#if _USE_LFN == 0 /* No LFN feature */
+#if _USE_LFN == 0 /* Non LFN feature */
#define DEF_NAMEBUF BYTE sfn[12]
#define INIT_BUF(dobj) (dobj).fn = sfn
#define FREE_BUF()
-
-#elif _USE_LFN == 1 /* LFN feature with static working buffer */
-static
-WCHAR LfnBuf[_MAX_LFN+1];
+#else
+#if _MAX_LFN < 12 || _MAX_LFN > 255
+#error Wrong _MAX_LFN setting
+#endif
+#if _USE_LFN == 1 /* LFN feature with static working buffer */
+static WCHAR LfnBuf[_MAX_LFN+1];
#define DEF_NAMEBUF BYTE sfn[12]
#define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; }
#define FREE_BUF()
-
#elif _USE_LFN == 2 /* LFN feature with dynamic working buffer on the stack */
#define DEF_NAMEBUF BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1]
#define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; }
#define FREE_BUF()
-
#elif _USE_LFN == 3 /* LFN feature with dynamic working buffer on the heap */
#define DEF_NAMEBUF BYTE sfn[12]; WCHAR *lfn
-#define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); \
- if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); \
- (dobj).lfn = lfn; (dobj).fn = sfn; }
+#define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; }
#define FREE_BUF() ff_memfree(lfn)
-
#else
-#error Wrong LFN configuration.
+#error Wrong _USE_LFN setting
+#endif
#endif
-
#ifdef _EXCVT
-static
-const BYTE ExCvt[] = _EXCVT; /* Upper conversion table for extended characters */
+static const BYTE ExCvt[] = _EXCVT; /* Upper conversion table for extended characters */
#endif
@@ -758,21 +760,24 @@ FRESULT sync_window (
{
DWORD wsect;
UINT nf;
+ FRESULT res = FR_OK;
if (fs->wflag) { /* Write back the sector if it is dirty */
wsect = fs->winsect; /* Current sector number */
- if (disk_write(fs->drv, fs->win, wsect, 1))
- return FR_DISK_ERR;
- fs->wflag = 0;
- if (wsect - fs->fatbase < fs->fsize) { /* Is it in the FAT area? */
- for (nf = fs->n_fats; nf >= 2; nf--) { /* Reflect the change to all FAT copies */
- wsect += fs->fsize;
- disk_write(fs->drv, fs->win, wsect, 1);
+ if (disk_write(fs->drv, fs->win, wsect, 1) != RES_OK) {
+ res = FR_DISK_ERR;
+ } else {
+ fs->wflag = 0;
+ if (wsect - fs->fatbase < fs->fsize) { /* Is it in the FAT area? */
+ for (nf = fs->n_fats; nf >= 2; nf--) { /* Reflect the change to all FAT copies */
+ wsect += fs->fsize;
+ disk_write(fs->drv, fs->win, wsect, 1);
+ }
}
}
}
- return FR_OK;
+ return res;
}
#endif
@@ -783,17 +788,22 @@ FRESULT move_window (
DWORD sector /* Sector number to make appearance in the fs->win[] */
)
{
- if (sector != fs->winsect) { /* Changed current window */
+ FRESULT res = FR_OK;
+
+
+ if (sector != fs->winsect) { /* Window offset changed? */
#if !_FS_READONLY
- if (sync_window(fs) != FR_OK)
- return FR_DISK_ERR;
+ res = sync_window(fs); /* Write-back changes */
#endif
- if (disk_read(fs->drv, fs->win, sector, 1))
- return FR_DISK_ERR;
- fs->winsect = sector;
+ if (res == FR_OK) { /* Fill sector window with new data */
+ if (disk_read(fs->drv, fs->win, sector, 1) != RES_OK) {
+ sector = 0xFFFFFFFF; /* Invalidate window if data is not reliable */
+ res = FR_DISK_ERR;
+ }
+ fs->winsect = sector;
+ }
}
-
- return FR_OK;
+ return res;
}
@@ -842,7 +852,7 @@ FRESULT sync_fs ( /* FR_OK: successful, FR_DISK_ERR: failed */
/*-----------------------------------------------------------------------*/
/* Get sector# from cluster# */
/*-----------------------------------------------------------------------*/
-
+/* Hidden API for hacks and disk tools */
DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */
FATFS* fs, /* File system object */
@@ -850,7 +860,7 @@ DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */
)
{
clst -= 2;
- if (clst >= (fs->n_fatent - 2)) return 0; /* Invalid cluster# */
+ if (clst >= fs->n_fatent - 2) return 0; /* Invalid cluster# */
return clst * fs->csize + fs->database;
}
@@ -860,44 +870,52 @@ DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */
/*-----------------------------------------------------------------------*/
/* FAT access - Read value of a FAT entry */
/*-----------------------------------------------------------------------*/
+/* Hidden API for hacks and disk tools */
-
-DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status */
+DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluster status */
FATFS* fs, /* File system object */
- DWORD clst /* Cluster# to get the link information */
+ DWORD clst /* FAT item index (cluster#) to get the value */
)
{
UINT wc, bc;
BYTE *p;
+ DWORD val;
- if (clst < 2 || clst >= fs->n_fatent) /* Check range */
- return 1;
+ if (clst < 2 || clst >= fs->n_fatent) { /* Check range */
+ val = 1; /* Internal error */
- switch (fs->fs_type) {
- case FS_FAT12 :
- bc = (UINT)clst; bc += bc / 2;
- if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break;
- wc = fs->win[bc % SS(fs)]; bc++;
- if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break;
- wc |= fs->win[bc % SS(fs)] << 8;
- return clst & 1 ? wc >> 4 : (wc & 0xFFF);
+ } else {
+ val = 0xFFFFFFFF; /* Default value falls on disk error */
- case FS_FAT16 :
- if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)))) break;
- p = &fs->win[clst * 2 % SS(fs)];
- return LD_WORD(p);
+ switch (fs->fs_type) {
+ case FS_FAT12 :
+ bc = (UINT)clst; bc += bc / 2;
+ if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;
+ wc = fs->win[bc++ % SS(fs)];
+ if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;
+ wc |= fs->win[bc % SS(fs)] << 8;
+ val = clst & 1 ? wc >> 4 : (wc & 0xFFF);
+ break;
+
+ case FS_FAT16 :
+ if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))) != FR_OK) break;
+ p = &fs->win[clst * 2 % SS(fs)];
+ val = LD_WORD(p);
+ break;
- case FS_FAT32 :
- if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)))) break;
- p = &fs->win[clst * 4 % SS(fs)];
- return LD_DWORD(p) & 0x0FFFFFFF;
+ case FS_FAT32 :
+ if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break;
+ p = &fs->win[clst * 4 % SS(fs)];
+ val = LD_DWORD(p) & 0x0FFFFFFF;
+ break;
- default:
- return 1;
+ default:
+ val = 1; /* Internal error */
+ }
}
- return 0xFFFFFFFF; /* An error occurred at the disk I/O layer */
+ return val;
}
@@ -906,11 +924,12 @@ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status
/*-----------------------------------------------------------------------*/
/* FAT access - Change value of a FAT entry */
/*-----------------------------------------------------------------------*/
-#if !_FS_READONLY
+/* Hidden API for hacks and disk tools */
+#if !_FS_READONLY
FRESULT put_fat (
FATFS* fs, /* File system object */
- DWORD clst, /* Cluster# to be changed in range of 2 to fs->n_fatent - 1 */
+ DWORD clst, /* FAT item index (cluster#) to be set */
DWORD val /* New value to mark the cluster */
)
{
@@ -928,14 +947,14 @@ FRESULT put_fat (
bc = (UINT)clst; bc += bc / 2;
res = move_window(fs, fs->fatbase + (bc / SS(fs)));
if (res != FR_OK) break;
- p = &fs->win[bc % SS(fs)];
+ p = &fs->win[bc++ % SS(fs)];
*p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
- bc++;
fs->wflag = 1;
res = move_window(fs, fs->fatbase + (bc / SS(fs)));
if (res != FR_OK) break;
p = &fs->win[bc % SS(fs)];
*p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
+ fs->wflag = 1;
break;
case FS_FAT16 :
@@ -943,6 +962,7 @@ FRESULT put_fat (
if (res != FR_OK) break;
p = &fs->win[clst * 2 % SS(fs)];
ST_WORD(p, (WORD)val);
+ fs->wflag = 1;
break;
case FS_FAT32 :
@@ -951,12 +971,12 @@ FRESULT put_fat (
p = &fs->win[clst * 4 % SS(fs)];
val |= LD_DWORD(p) & 0xF0000000;
ST_DWORD(p, val);
+ fs->wflag = 1;
break;
default :
res = FR_INT_ERR;
}
- fs->wflag = 1;
}
return res;
@@ -978,7 +998,7 @@ FRESULT remove_chain (
{
FRESULT res;
DWORD nxt;
-#if _USE_ERASE
+#if _USE_TRIM
DWORD scl = clst, ecl = clst, rt[2];
#endif
@@ -998,13 +1018,13 @@ FRESULT remove_chain (
fs->free_clust++;
fs->fsi_flag |= 1;
}
-#if _USE_ERASE
+#if _USE_TRIM
if (ecl + 1 == nxt) { /* Is next cluster contiguous? */
ecl = nxt;
} else { /* End of contiguous clusters */
rt[0] = clust2sect(fs, scl); /* Start sector */
rt[1] = clust2sect(fs, ecl) + fs->csize - 1; /* End sector */
- disk_ioctl(fs->drv, CTRL_ERASE_SECTOR, rt); /* Erase the block */
+ disk_ioctl(fs->drv, CTRL_TRIM, rt); /* Erase the block */
scl = ecl = nxt;
}
#endif
@@ -1246,8 +1266,8 @@ FRESULT dir_alloc (
do {
res = move_window(dp->fs, dp->sect);
if (res != FR_OK) break;
- if (dp->dir[0] == DDE || dp->dir[0] == 0) { /* Is it a blank entry? */
- if (++n == nent) break; /* A block of contiguous entries is found */
+ if (dp->dir[0] == DDE || dp->dir[0] == 0) { /* Is it a free entry? */
+ if (++n == nent) break; /* A block of contiguous free entries is found */
} else {
n = 0; /* Not a blank entry. Restart to search */
}
@@ -1526,7 +1546,7 @@ FRESULT dir_find (
}
} else { /* An SFN entry is found */
if (!ord && sum == sum_sfn(dir)) break; /* LFN matched? */
- if (!(dp->fn[NS] & NS_LOSS) && !mem_cmp(dir, dp->fn, 11)) break; /* SFN matched? */
+ if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dir, dp->fn, 11)) break; /* SFN matched? */
ord = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */
}
}
@@ -1568,7 +1588,7 @@ FRESULT dir_read (
if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */
a = dir[DIR_Attr] & AM_MASK;
#if _USE_LFN /* LFN configuration */
- if (c == DDE || (!_FS_RPATH && c == '.') || (int)(a == AM_VOL) != vol) { /* An entry without valid data */
+ if (c == DDE || (!_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */
ord = 0xFF;
} else {
if (a == AM_LFN) { /* An LFN entry is found */
@@ -1586,7 +1606,7 @@ FRESULT dir_read (
}
}
#else /* Non LFN configuration */
- if (c != DDE && (_FS_RPATH || c != '.') && a != AM_LFN && (int)(a == AM_VOL) == vol) /* Is it a valid entry? */
+ if (c != DDE && (_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol) /* Is it a valid entry? */
break;
#endif
res = dir_next(dp, 0); /* Next entry */
@@ -1621,11 +1641,11 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many
fn = dp->fn; lfn = dp->lfn;
mem_cpy(sn, fn, 12);
- if (_FS_RPATH && (sn[NS] & NS_DOT)) /* Cannot create dot entry */
+ if (_FS_RPATH && (sn[NSFLAG] & NS_DOT)) /* Cannot create dot entry */
return FR_INVALID_NAME;
- if (sn[NS] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */
- fn[NS] = 0; dp->lfn = 0; /* Find only SFN */
+ if (sn[NSFLAG] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */
+ fn[NSFLAG] = 0; dp->lfn = 0; /* Find only SFN */
for (n = 1; n < 100; n++) {
gen_numname(fn, sn, lfn, n); /* Generate a numbered name */
res = dir_find(dp); /* Check if the name collides with existing SFN */
@@ -1633,10 +1653,10 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many
}
if (n == 100) return FR_DENIED; /* Abort if too many collisions */
if (res != FR_NO_FILE) return res; /* Abort if the result is other than 'not collided' */
- fn[NS] = sn[NS]; dp->lfn = lfn;
+ fn[NSFLAG] = sn[NSFLAG]; dp->lfn = lfn;
}
- if (sn[NS] & NS_LFN) { /* When LFN is to be created, allocate entries for an SFN + LFNs. */
+ if (sn[NSFLAG] & NS_LFN) { /* When LFN is to be created, allocate entries for an SFN + LFNs. */
for (n = 0; lfn[n]; n++) ;
nent = (n + 25) / 13;
} else { /* Otherwise allocate an entry for an SFN */
@@ -1667,7 +1687,7 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many
mem_set(dp->dir, 0, SZ_DIR); /* Clean the entry */
mem_cpy(dp->dir, dp->fn, 11); /* Put SFN */
#if _USE_LFN
- dp->dir[DIR_NTres] = dp->fn[NS] & (NS_BODY | NS_EXT); /* Put NT flag */
+ dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */
#endif
dp->fs->wflag = 1;
}
@@ -1923,7 +1943,7 @@ FRESULT create_name (
if ((b & 0x0C) == 0x04) cf |= NS_BODY; /* NT flag (Filename has only small capital) */
}
- dp->fn[NS] = cf; /* SFN is created */
+ dp->fn[NSFLAG] = cf; /* SFN is created */
return FR_OK;
@@ -1947,7 +1967,7 @@ FRESULT create_name (
}
if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME;
*path = &p[si]; /* Return pointer to the next segment */
- sfn[NS] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of path */
+ sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of path */
return FR_OK;
}
#endif
@@ -1998,7 +2018,7 @@ FRESULT create_name (
if ((b & 0x03) == 0x01) c |= NS_EXT; /* NT flag (Name extension has only small capital) */
if ((b & 0x0C) == 0x04) c |= NS_BODY; /* NT flag (Name body has only small capital) */
- sfn[NS] = c; /* Store NT flag, File name is created */
+ sfn[NSFLAG] = c; /* Store NT flag, File name is created */
return FR_OK;
#endif
@@ -2041,7 +2061,7 @@ FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
res = create_name(dp, &path); /* Get a segment name of the path */
if (res != FR_OK) break;
res = dir_find(dp); /* Find an object with the sagment name */
- ns = dp->fn[NS];
+ ns = dp->fn[NSFLAG];
if (res != FR_OK) { /* Failed to find the object */
if (res == FR_NO_FILE) { /* Object is not found */
if (_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, */
@@ -2283,7 +2303,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
szbfat = (fmt == FS_FAT16) ? /* (Needed FAT size) */
fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1);
}
- if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than needed) */
+ if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than the size needed) */
return FR_NO_FILESYSTEM;
#if !_FS_READONLY
@@ -2471,7 +2491,7 @@ FRESULT f_open (
}
}
if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate it if overwrite mode */
- dw = get_fattime(); /* Created time */
+ dw = GET_FATTIME(); /* Created time */
ST_DWORD(dir+DIR_CrtTime, dw);
dir[DIR_Attr] = 0; /* Reset attribute */
ST_DWORD(dir+DIR_FileSize, 0); /* size = 0 */
@@ -2597,7 +2617,7 @@ FRESULT f_read (
if (cc) { /* Read maximum contiguous sectors directly */
if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */
cc = fp->fs->csize - csect;
- if (disk_read(fp->fs->drv, rbuff, sect, cc))
+ if (disk_read(fp->fs->drv, rbuff, sect, cc) != RES_OK)
ABORT(fp->fs, FR_DISK_ERR);
#if !_FS_READONLY && _FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */
#if _FS_TINY
@@ -2615,12 +2635,12 @@ FRESULT f_read (
if (fp->dsect != sect) { /* Load data sector if not in cache */
#if !_FS_READONLY
if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
ABORT(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
#endif
- if (disk_read(fp->fs->drv, fp->buf, sect, 1)) /* Fill sector cache */
+ if (disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK) /* Fill sector cache */
ABORT(fp->fs, FR_DISK_ERR);
}
#endif
@@ -2629,7 +2649,7 @@ FRESULT f_read (
rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs)); /* Get partial sector data from sector buffer */
if (rcnt > btr) rcnt = btr;
#if _FS_TINY
- if (move_window(fp->fs, fp->dsect)) /* Move sector window */
+ if (move_window(fp->fs, fp->dsect) != FR_OK) /* Move sector window */
ABORT(fp->fs, FR_DISK_ERR);
mem_cpy(rbuff, &fp->fs->win[fp->fptr % SS(fp->fs)], rcnt); /* Pick partial sector */
#else
@@ -2700,7 +2720,7 @@ FRESULT f_write (
ABORT(fp->fs, FR_DISK_ERR);
#else
if (fp->flag & FA__DIRTY) { /* Write-back sector cache */
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
ABORT(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
@@ -2712,7 +2732,7 @@ FRESULT f_write (
if (cc) { /* Write maximum contiguous sectors directly */
if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */
cc = fp->fs->csize - csect;
- if (disk_write(fp->fs->drv, wbuff, sect, cc))
+ if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK)
ABORT(fp->fs, FR_DISK_ERR);
#if _FS_MINIMIZE <= 2
#if _FS_TINY
@@ -2738,7 +2758,7 @@ FRESULT f_write (
#else
if (fp->dsect != sect) { /* Fill sector cache with file data */
if (fp->fptr < fp->fsize &&
- disk_read(fp->fs->drv, fp->buf, sect, 1))
+ disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK)
ABORT(fp->fs, FR_DISK_ERR);
}
#endif
@@ -2747,7 +2767,7 @@ FRESULT f_write (
wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */
if (wcnt > btw) wcnt = btw;
#if _FS_TINY
- if (move_window(fp->fs, fp->dsect)) /* Move sector window */
+ if (move_window(fp->fs, fp->dsect) != FR_OK) /* Move sector window */
ABORT(fp->fs, FR_DISK_ERR);
mem_cpy(&fp->fs->win[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */
fp->fs->wflag = 1;
@@ -2785,7 +2805,7 @@ FRESULT f_sync (
/* Write-back dirty buffer */
#if !_FS_TINY
if (fp->flag & FA__DIRTY) {
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
LEAVE_FF(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
@@ -2797,7 +2817,7 @@ FRESULT f_sync (
dir[DIR_Attr] |= AM_ARC; /* Set archive bit */
ST_DWORD(dir+DIR_FileSize, fp->fsize); /* Update file size */
st_clust(dir, fp->sclust); /* Update start cluster */
- tm = get_fattime(); /* Update updated time */
+ tm = GET_FATTIME(); /* Update updated time */
ST_DWORD(dir+DIR_WrtTime, tm);
ST_WORD(dir+DIR_LstAccDate, 0);
fp->flag &= ~FA__WRITTEN;
@@ -3046,12 +3066,12 @@ FRESULT f_lseek (
#if !_FS_TINY
#if !_FS_READONLY
if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
ABORT(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
#endif
- if (disk_read(fp->fs->drv, fp->buf, dsc, 1)) /* Load current sector */
+ if (disk_read(fp->fs->drv, fp->buf, dsc, 1) != RES_OK) /* Load current sector */
ABORT(fp->fs, FR_DISK_ERR);
#endif
fp->dsect = dsc;
@@ -3121,12 +3141,12 @@ FRESULT f_lseek (
#if !_FS_TINY
#if !_FS_READONLY
if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
ABORT(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
#endif
- if (disk_read(fp->fs->drv, fp->buf, nsect, 1)) /* Fill sector cache */
+ if (disk_read(fp->fs->drv, fp->buf, nsect, 1) != RES_OK) /* Fill sector cache */
ABORT(fp->fs, FR_DISK_ERR);
#endif
fp->dsect = nsect;
@@ -3417,7 +3437,7 @@ FRESULT f_truncate (
}
#if !_FS_TINY
if (res == FR_OK && (fp->flag & FA__DIRTY)) {
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
res = FR_DISK_ERR;
else
fp->flag &= ~FA__DIRTY;
@@ -3444,7 +3464,7 @@ FRESULT f_unlink (
FRESULT res;
DIR dj, sdj;
BYTE *dir;
- DWORD dclst;
+ DWORD dclst = 0;
DEF_NAMEBUF;
@@ -3453,45 +3473,43 @@ FRESULT f_unlink (
if (res == FR_OK) {
INIT_BUF(dj);
res = follow_path(&dj, path); /* Follow the file path */
- if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
+ if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
res = FR_INVALID_NAME; /* Cannot remove dot entry */
#if _FS_LOCK
- if (res == FR_OK) res = chk_lock(&dj, 2); /* Cannot remove open file */
+ if (res == FR_OK) res = chk_lock(&dj, 2); /* Cannot remove open object */
#endif
if (res == FR_OK) { /* The object is accessible */
dir = dj.dir;
if (!dir) {
- res = FR_INVALID_NAME; /* Cannot remove the start directory */
+ res = FR_INVALID_NAME; /* Cannot remove the origin directory */
} else {
if (dir[DIR_Attr] & AM_RDO)
res = FR_DENIED; /* Cannot remove R/O object */
}
- dclst = ld_clust(dj.fs, dir);
if (res == FR_OK && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-dir? */
- if (dclst < 2) {
+ dclst = ld_clust(dj.fs, dir);
+ if (!dclst) {
res = FR_INT_ERR;
- } else {
- mem_cpy(&sdj, &dj, sizeof (DIR)); /* Check if the sub-directory is empty or not */
+ } else { /* Make sure the sub-directory is empty */
+ mem_cpy(&sdj, &dj, sizeof (DIR));
sdj.sclust = dclst;
res = dir_sdi(&sdj, 2); /* Exclude dot entries */
if (res == FR_OK) {
res = dir_read(&sdj, 0); /* Read an item */
if (res == FR_OK /* Not empty directory */
#if _FS_RPATH
- || dclst == dj.fs->cdir /* Current directory */
+ || dclst == dj.fs->cdir /* or current directory */
#endif
) res = FR_DENIED;
- if (res == FR_NO_FILE) res = FR_OK; /* Empty */
+ if (res == FR_NO_FILE) res = FR_OK; /* It is empty */
}
}
}
if (res == FR_OK) {
res = dir_remove(&dj); /* Remove the directory entry */
- if (res == FR_OK) {
- if (dclst) /* Remove the cluster chain if exist */
- res = remove_chain(dj.fs, dclst);
- if (res == FR_OK) res = sync_fs(dj.fs);
- }
+ if (res == FR_OK && dclst) /* Remove the cluster chain if exist */
+ res = remove_chain(dj.fs, dclst);
+ if (res == FR_OK) res = sync_fs(dj.fs);
}
}
FREE_BUF();
@@ -3514,7 +3532,7 @@ FRESULT f_mkdir (
FRESULT res;
DIR dj;
BYTE *dir, n;
- DWORD dsc, dcl, pcl, tm = get_fattime();
+ DWORD dsc, dcl, pcl, tm = GET_FATTIME();
DEF_NAMEBUF;
@@ -3524,7 +3542,7 @@ FRESULT f_mkdir (
INIT_BUF(dj);
res = follow_path(&dj, path); /* Follow the file path */
if (res == FR_OK) res = FR_EXIST; /* Any object with same name is already existing */
- if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NS] & NS_DOT))
+ if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))
res = FR_INVALID_NAME;
if (res == FR_NO_FILE) { /* Can create a new directory */
dcl = create_chain(dj.fs, 0); /* Allocate a cluster for the new directory table */
@@ -3599,7 +3617,7 @@ FRESULT f_chmod (
INIT_BUF(dj);
res = follow_path(&dj, path); /* Follow the file path */
FREE_BUF();
- if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
+ if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
res = FR_INVALID_NAME;
if (res == FR_OK) {
dir = dj.dir;
@@ -3621,48 +3639,6 @@ FRESULT f_chmod (
/*-----------------------------------------------------------------------*/
-/* Change Timestamp */
-/*-----------------------------------------------------------------------*/
-
-FRESULT f_utime (
- const TCHAR* path, /* Pointer to the file/directory name */
- const FILINFO* fno /* Pointer to the time stamp to be set */
-)
-{
- FRESULT res;
- DIR dj;
- BYTE *dir;
- DEF_NAMEBUF;
-
-
- /* Get logical drive number */
- res = find_volume(&dj.fs, &path, 1);
- if (res == FR_OK) {
- INIT_BUF(dj);
- res = follow_path(&dj, path); /* Follow the file path */
- FREE_BUF();
- if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
- res = FR_INVALID_NAME;
- if (res == FR_OK) {
- dir = dj.dir;
- if (!dir) { /* Root directory */
- res = FR_INVALID_NAME;
- } else { /* File or sub-directory */
- ST_WORD(dir+DIR_WrtTime, fno->ftime);
- ST_WORD(dir+DIR_WrtDate, fno->fdate);
- dj.fs->wflag = 1;
- res = sync_fs(dj.fs);
- }
- }
- }
-
- LEAVE_FF(dj.fs, res);
-}
-
-
-
-
-/*-----------------------------------------------------------------------*/
/* Rename File/Directory */
/*-----------------------------------------------------------------------*/
@@ -3684,7 +3660,7 @@ FRESULT f_rename (
djn.fs = djo.fs;
INIT_BUF(djo);
res = follow_path(&djo, path_old); /* Check old object */
- if (_FS_RPATH && res == FR_OK && (djo.fn[NS] & NS_DOT))
+ if (_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
res = FR_INVALID_NAME;
#if _FS_LOCK
if (res == FR_OK) res = chk_lock(&djo, 2);
@@ -3696,19 +3672,19 @@ FRESULT f_rename (
mem_cpy(buf, djo.dir+DIR_Attr, 21); /* Save the object information except name */
mem_cpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
if (get_ldnumber(&path_new) >= 0) /* Snip drive number off and ignore it */
- res = follow_path(&djn, path_new); /* and check if new object is exist */
+ res = follow_path(&djn, path_new); /* and make sure if new object name is not conflicting */
else
res = FR_INVALID_DRIVE;
if (res == FR_OK) res = FR_EXIST; /* The new object name is already existing */
- if (res == FR_NO_FILE) { /* Is it a valid path and no name collision? */
-/* Start critical section that any interruption can cause a cross-link */
+ if (res == FR_NO_FILE) { /* It is a valid path and no name collision */
+/* Start of critical section that any interruption can cause a cross-link */
res = dir_register(&djn); /* Register the new entry */
if (res == FR_OK) {
dir = djn.dir; /* Copy object information except name */
mem_cpy(dir+13, buf+2, 19);
dir[DIR_Attr] = buf[0] | AM_ARC;
djo.fs->wflag = 1;
- if (djo.sclust != djn.sclust && (dir[DIR_Attr] & AM_DIR)) { /* Update .. entry in the directory if needed */
+ if ((dir[DIR_Attr] & AM_DIR) && djo.sclust != djn.sclust) { /* Update .. entry in the directory if needed */
dw = clust2sect(djo.fs, ld_clust(djo.fs, dir));
if (!dw) {
res = FR_INT_ERR;
@@ -3716,8 +3692,7 @@ FRESULT f_rename (
res = move_window(djo.fs, dw);
dir = djo.fs->win+SZ_DIR; /* .. entry */
if (res == FR_OK && dir[1] == '.') {
- dw = (djo.fs->fs_type == FS_FAT32 && djn.sclust == djo.fs->dirbase) ? 0 : djn.sclust;
- st_clust(dir, dw);
+ st_clust(dir, djn.sclust);
djo.fs->wflag = 1;
}
}
@@ -3728,7 +3703,7 @@ FRESULT f_rename (
res = sync_fs(djo.fs);
}
}
-/* End critical section */
+/* End of critical section */
}
}
}
@@ -3738,6 +3713,48 @@ FRESULT f_rename (
LEAVE_FF(djo.fs, res);
}
+
+
+
+/*-----------------------------------------------------------------------*/
+/* Change Timestamp */
+/*-----------------------------------------------------------------------*/
+
+FRESULT f_utime (
+ const TCHAR* path, /* Pointer to the file/directory name */
+ const FILINFO* fno /* Pointer to the time stamp to be set */
+)
+{
+ FRESULT res;
+ DIR dj;
+ BYTE *dir;
+ DEF_NAMEBUF;
+
+
+ /* Get logical drive number */
+ res = find_volume(&dj.fs, &path, 1);
+ if (res == FR_OK) {
+ INIT_BUF(dj);
+ res = follow_path(&dj, path); /* Follow the file path */
+ FREE_BUF();
+ if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+ res = FR_INVALID_NAME;
+ if (res == FR_OK) {
+ dir = dj.dir;
+ if (!dir) { /* Root directory */
+ res = FR_INVALID_NAME;
+ } else { /* File or sub-directory */
+ ST_WORD(dir+DIR_WrtTime, fno->ftime);
+ ST_WORD(dir+DIR_WrtDate, fno->fdate);
+ dj.fs->wflag = 1;
+ res = sync_fs(dj.fs);
+ }
+ }
+ }
+
+ LEAVE_FF(dj.fs, res);
+}
+
#endif /* !_FS_READONLY */
#endif /* _FS_MINIMIZE == 0 */
#endif /* _FS_MINIMIZE <= 1 */
@@ -3871,7 +3888,7 @@ FRESULT f_setlabel (
if (res == FR_OK) { /* A volume label is found */
if (vn[0]) {
mem_cpy(dj.dir, vn, 11); /* Change the volume label name */
- tm = get_fattime();
+ tm = GET_FATTIME();
ST_DWORD(dj.dir+DIR_WrtTime, tm);
} else {
dj.dir[0] = DDE; /* Remove the volume label */
@@ -3887,7 +3904,7 @@ FRESULT f_setlabel (
mem_set(dj.dir, 0, SZ_DIR); /* Set volume label */
mem_cpy(dj.dir, vn, 11);
dj.dir[DIR_Attr] = AM_VOL;
- tm = get_fattime();
+ tm = GET_FATTIME();
ST_DWORD(dj.dir+DIR_WrtTime, tm);
dj.fs->wflag = 1;
res = sync_fs(dj.fs);
@@ -3950,7 +3967,7 @@ FRESULT f_forward (
sect = clust2sect(fp->fs, fp->clust); /* Get current data sector */
if (!sect) ABORT(fp->fs, FR_INT_ERR);
sect += csect;
- if (move_window(fp->fs, sect)) /* Move sector window */
+ if (move_window(fp->fs, sect) != FR_OK) /* Move sector window */
ABORT(fp->fs, FR_DISK_ERR);
fp->dsect = sect;
rcnt = SS(fp->fs) - (WORD)(fp->fptr % SS(fp->fs)); /* Forward data from sector window */
@@ -3970,13 +3987,13 @@ FRESULT f_forward (
/* Create File System on the Drive */
/*-----------------------------------------------------------------------*/
#define N_ROOTDIR 512 /* Number of root directory entries for FAT12/16 */
-#define N_FATS 1 /* Number of FAT copies (1 or 2) */
+#define N_FATS 1 /* Number of FATs (1 or 2) */
FRESULT f_mkfs (
const TCHAR* path, /* Logical drive number */
BYTE sfd, /* Partitioning rule 0:FDISK, 1:SFD */
- UINT au /* Allocation unit [bytes] */
+ UINT au /* Size of allocation unit in unit of byte or sector */
)
{
static const WORD vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0};
@@ -3992,10 +4009,9 @@ FRESULT f_mkfs (
/* Check mounted drive and clear work area */
+ if (sfd > 1) return FR_INVALID_PARAMETER;
vol = get_ldnumber(&path);
if (vol < 0) return FR_INVALID_DRIVE;
- if (sfd > 1) return FR_INVALID_PARAMETER;
- if (au & (au - 1)) return FR_INVALID_PARAMETER;
fs = FatFs[vol];
if (!fs) return FR_NOT_ENABLED;
fs->fs_type = 0;
@@ -4012,7 +4028,7 @@ FRESULT f_mkfs (
#endif
if (_MULTI_PARTITION && part) {
/* Get partition information from partition table in the MBR */
- if (disk_read(pdrv, fs->win, 0, 1)) return FR_DISK_ERR;
+ if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR;
if (LD_WORD(fs->win+BS_55AA) != 0xAA55) return FR_MKFS_ABORTED;
tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
if (!tbl[4]) return FR_MKFS_ABORTED; /* No partition? */
@@ -4026,13 +4042,14 @@ FRESULT f_mkfs (
n_vol -= b_vol; /* Volume size */
}
- if (!au) { /* AU auto selection */
+ if (au & (au - 1)) au = 0;
+ if (!au) { /* AU auto selection */
vs = n_vol / (2000 / (SS(fs) / 512));
for (i = 0; vs < vst[i]; i++) ;
au = cst[i];
}
- au /= SS(fs); /* Number of sectors per cluster */
- if (au == 0) au = 1;
+ if (au >= _MIN_SS) au /= SS(fs); /* Number of sectors per cluster */
+ if (!au) au = 1;
if (au > 128) au = 128;
/* Pre-compute number of clusters and FAT sub-type */
@@ -4089,7 +4106,7 @@ FRESULT f_mkfs (
/* Update system ID in the partition table */
tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
tbl[4] = sys;
- if (disk_write(pdrv, fs->win, 0, 1)) /* Write it to teh MBR */
+ if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) /* Write it to teh MBR */
return FR_DISK_ERR;
md = 0xF8;
} else {
@@ -4109,7 +4126,7 @@ FRESULT f_mkfs (
ST_DWORD(tbl+8, 63); /* Partition start in LBA */
ST_DWORD(tbl+12, n_vol); /* Partition size in LBA */
ST_WORD(fs->win+BS_55AA, 0xAA55); /* MBR signature */
- if (disk_write(pdrv, fs->win, 0, 1)) /* Write it to the MBR */
+ if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) /* Write it to the MBR */
return FR_DISK_ERR;
md = 0xF8;
}
@@ -4135,7 +4152,7 @@ FRESULT f_mkfs (
ST_WORD(tbl+BPB_SecPerTrk, 63); /* Number of sectors per track */
ST_WORD(tbl+BPB_NumHeads, 255); /* Number of heads */
ST_DWORD(tbl+BPB_HiddSec, b_vol); /* Hidden sectors */
- n = get_fattime(); /* Use current time as VSN */
+ n = GET_FATTIME(); /* Use current time as VSN */
if (fmt == FS_FAT32) {
ST_DWORD(tbl+BS_VolID32, n); /* VSN */
ST_DWORD(tbl+BPB_FATSz32, n_fat); /* Number of sectors per FAT */
@@ -4153,7 +4170,7 @@ FRESULT f_mkfs (
mem_cpy(tbl+BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */
}
ST_WORD(tbl+BS_55AA, 0xAA55); /* Signature (Offset is fixed here regardless of sector size) */
- if (disk_write(pdrv, tbl, b_vol, 1)) /* Write it to the VBR sector */
+ if (disk_write(pdrv, tbl, b_vol, 1) != RES_OK) /* Write it to the VBR sector */
return FR_DISK_ERR;
if (fmt == FS_FAT32) /* Write backup VBR if needed (VBR+6) */
disk_write(pdrv, tbl, b_vol + 6, 1);
@@ -4172,11 +4189,11 @@ FRESULT f_mkfs (
ST_DWORD(tbl+4, 0xFFFFFFFF);
ST_DWORD(tbl+8, 0x0FFFFFFF); /* Reserve cluster #2 for root directory */
}
- if (disk_write(pdrv, tbl, wsect++, 1))
+ if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
return FR_DISK_ERR;
mem_set(tbl, 0, SS(fs)); /* Fill following FAT entries with zero */
for (n = 1; n < n_fat; n++) { /* This loop may take a time on FAT32 volume due to many single sector writes */
- if (disk_write(pdrv, tbl, wsect++, 1))
+ if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
return FR_DISK_ERR;
}
}
@@ -4184,16 +4201,16 @@ FRESULT f_mkfs (
/* Initialize root directory */
i = (fmt == FS_FAT32) ? au : (UINT)n_dir;
do {
- if (disk_write(pdrv, tbl, wsect++, 1))
+ if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
return FR_DISK_ERR;
} while (--i);
-#if _USE_ERASE /* Erase data area if needed */
+#if _USE_TRIM /* Erase data area if needed */
{
DWORD eb[2];
eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1;
- disk_ioctl(pdrv, CTRL_ERASE_SECTOR, eb);
+ disk_ioctl(pdrv, CTRL_TRIM, eb);
}
#endif
@@ -4276,7 +4293,7 @@ FRESULT f_fdisk (
ST_WORD(p, 0xAA55);
/* Write it to the MBR */
- return (disk_write(pdrv, buf, 0, 1) || disk_ioctl(pdrv, CTRL_SYNC, 0)) ? FR_DISK_ERR : FR_OK;
+ return (disk_write(pdrv, buf, 0, 1) != RES_OK || disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) ? FR_DISK_ERR : FR_OK;
}
diff --git a/fatfs/src/ff.h b/fatfs/src/ff.h
index 9894921..5eaad5f 100644
--- a/fatfs/src/ff.h
+++ b/fatfs/src/ff.h
@@ -1,5 +1,5 @@
/*---------------------------------------------------------------------------/
-/ FatFs - FAT file system module include file R0.10b (C)ChaN, 2014
+/ FatFs - FAT file system module include file R0.10c (C)ChaN, 2014
/----------------------------------------------------------------------------/
/ 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
@@ -15,7 +15,7 @@
/----------------------------------------------------------------------------*/
#ifndef _FATFS
-#define _FATFS 8051 /* Revision ID */
+#define _FATFS 80376 /* Revision ID */
#ifdef __cplusplus
extern "C" {
@@ -23,7 +23,6 @@ extern "C" {
#include "integer.h" /* Basic integer types */
#include "ffconf.h" /* FatFs configuration options */
-
#if _FATFS != _FFCONF
#error Wrong configuration file (ffconf.h).
#endif
@@ -236,7 +235,7 @@ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
-#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
+#define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
#define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->fsize)
@@ -252,7 +251,7 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil
/* Additional user defined functions */
/* RTC function */
-#if !_FS_READONLY
+#if !_FS_READONLY && !_FS_NORTC
DWORD get_fattime (void);
#endif
diff --git a/fatfs/src/ffconf.h b/fatfs/src/ffconf.h
index d883c14..f968d7e 100644
--- a/fatfs/src/ffconf.h
+++ b/fatfs/src/ffconf.h
@@ -1,30 +1,30 @@
/*---------------------------------------------------------------------------/
-/ FatFs - FAT file system module configuration file R0.10b (C)ChaN, 2014
+/ FatFs - FAT file system module configuration file R0.10c (C)ChaN, 2014
/---------------------------------------------------------------------------*/
-#ifndef _FFCONF
-#define _FFCONF 8051 /* Revision ID */
-
+#define _FFCONF 80376 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Functions and Buffer Configurations
/---------------------------------------------------------------------------*/
-#define _FS_TINY 0 /* 0:Normal or 1:Tiny */
-/* When _FS_TINY is set to 1, it reduces memory consumption _MAX_SS bytes each
-/ file object. For file data transfer, FatFs uses the common sector buffer in
-/ the file system object (FATFS) instead of private sector buffer eliminated
-/ from the file object (FIL). */
+#define _FS_TINY 0
+/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
+/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS
+/ bytes. Instead of private sector buffer eliminated from the file object,
+/ common sector buffer in the file system object (FATFS) is used for the file
+/ data transfer. */
-#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
-/* Setting _FS_READONLY to 1 defines read only configuration. This removes
-/ writing functions, f_write(), f_sync(), f_unlink(), f_mkdir(), f_chmod(),
-/ f_rename(), f_truncate() and useless f_getfree(). */
+#define _FS_READONLY 0
+/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
+/ Read-only configuration removes basic writing API functions, f_write(),
+/ f_sync(), f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(),
+/ f_getfree() and optional writing functions as well. */
-#define _FS_MINIMIZE 0 /* 0 to 3 */
-/* The _FS_MINIMIZE option defines minimization level to remove API functions.
+#define _FS_MINIMIZE 0
+/* This option defines minimization level to remove some API functions.
/
/ 0: All basic functions are enabled.
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
@@ -33,24 +33,32 @@
/ 3: f_lseek() function is removed in addition to 2. */
-#define _USE_STRFUNC 0 /* 0:Disable or 1-2:Enable */
-/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
+#define _USE_STRFUNC 0
+/* This option switches string functions, f_gets(), f_putc(), f_puts() and
+/ f_printf().
+/
+/ 0: Disable string functions.
+/ 1: Enable without LF-CRLF conversion.
+/ 2: Enable with LF-CRLF conversion. */
-#define _USE_MKFS 0 /* 0:Disable or 1:Enable */
-/* To enable f_mkfs() function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
+#define _USE_MKFS 0
+/* This option switches f_mkfs() function. (0:Disable or 1:Enable)
+/ To enable it, also _FS_READONLY need to be set to 0. */
-#define _USE_FASTSEEK 0 /* 0:Disable or 1:Enable */
-/* To enable fast seek feature, set _USE_FASTSEEK to 1. */
+#define _USE_FASTSEEK 0
+/* This option switches fast seek feature. (0:Disable or 1:Enable) */
-#define _USE_LABEL 0 /* 0:Disable or 1:Enable */
-/* To enable volume label functions, set _USE_LAVEL to 1 */
+#define _USE_LABEL 0
+/* This option switches volume label functions, f_getlabel() and f_setlabel().
+/ (0:Disable or 1:Enable) */
-#define _USE_FORWARD 0 /* 0:Disable or 1:Enable */
-/* To enable f_forward() function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
+#define _USE_FORWARD 0
+/* This option switches f_forward() function. (0:Disable or 1:Enable) */
+/* To enable it, also _FS_TINY need to be set to 1. */
/*---------------------------------------------------------------------------/
@@ -58,7 +66,7 @@
/---------------------------------------------------------------------------*/
#define _CODE_PAGE 932
-/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
+/* This option specifies the OEM code page to be used on the target system.
/ Incorrect setting of the code page can cause a file open failure.
/
/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
@@ -86,11 +94,11 @@
/ 857 - Turkish (OEM)
/ 862 - Hebrew (OEM)
/ 874 - Thai (OEM, Windows)
-/ 1 - ASCII (Valid for only non-LFN configuration) */
+/ 1 - ASCII (No extended character. Valid for only non-LFN configuration.) */
-#define _USE_LFN 0 /* 0 to 3 */
-#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
+#define _USE_LFN 0
+#define _MAX_LFN 255
/* The _USE_LFN option switches the LFN feature.
/
/ 0: Disable LFN feature. _MAX_LFN has no effect.
@@ -98,35 +106,39 @@
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
-/ When enable LFN feature, Unicode handling functions ff_convert() and ff_wtoupper()
-/ function must be added to the project.
-/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When use stack for the
-/ working buffer, take care on stack overflow. When use heap memory for the working
-/ buffer, memory management functions, ff_memalloc() and ff_memfree(), must be added
-/ to the project. */
+/ When enable the LFN feature, Unicode handling functions (option/unicode.c) must
+/ be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes.
+/ When use stack for the working buffer, take care on stack overflow. When use heap
+/ memory for the working buffer, memory management functions, ff_memalloc() and
+/ ff_memfree(), must be added to the project. */
-#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
-/* To switch the character encoding on the FatFs API (TCHAR) to Unicode, enable LFN
-/ feature and set _LFN_UNICODE to 1. This option affects behavior of string I/O
-/ functions. This option must be 0 when LFN feature is not enabled. */
+#define _LFN_UNICODE 0
+/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
+/ To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE
+/ to 1. This option also affects behavior of string I/O functions. */
-#define _STRF_ENCODE 3 /* 0:ANSI/OEM, 1:UTF-16LE, 2:UTF-16BE, 3:UTF-8 */
-/* When Unicode API is enabled by _LFN_UNICODE option, this option selects the character
-/ encoding on the file to be read/written via string I/O functions, f_gets(), f_putc(),
-/ f_puts and f_printf(). This option has no effect when _LFN_UNICODE == 0. Note that
-/ FatFs supports only BMP. */
+#define _STRF_ENCODE 3
+/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
+/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
+/
+/ 0: ANSI/OEM
+/ 1: UTF-16LE
+/ 2: UTF-16BE
+/ 3: UTF-8
+/
+/ When _LFN_UNICODE is 0, this option has no effect. */
-#define _FS_RPATH 0 /* 0 to 2 */
-/* The _FS_RPATH option configures relative path feature.
+#define _FS_RPATH 0
+/* This option configures relative path feature.
/
/ 0: Disable relative path feature and remove related functions.
-/ 1: Enable relative path. f_chdrive() and f_chdir() function are available.
+/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available.
/ 2: f_getcwd() function is available in addition to 1.
/
-/ Note that output of the f_readdir() fnction is affected by this option. */
+/ Note that directory items read via f_readdir() are affected by this option. */
/*---------------------------------------------------------------------------/
@@ -137,39 +149,43 @@
/* Number of volumes (logical drives) to be used. */
-#define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
+#define _STR_VOLUME_ID 0
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
-/* When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
-/ number in the path name. _VOLUME_STRS defines the drive ID strings for each logical
-/ drives. Number of items must be equal to _VOLUMES. Valid characters for the drive ID
-/ strings are: 0-9 and A-Z. */
+/* _STR_VOLUME_ID option switches string volume ID feature.
+/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
+/ number in the path name. _VOLUME_STRS defines the drive ID strings for each
+/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for
+/ the drive ID strings are: A-Z and 0-9. */
-#define _MULTI_PARTITION 0 /* 0:Single partition, 1:Enable multiple partition */
-/* By default(0), each logical drive number is bound to the same physical drive number
-/ and only a FAT volume found on the physical drive is mounted. When it is set to 1,
-/ each logical drive number is bound to arbitrary drive/partition listed in VolToPart[].
-*/
+#define _MULTI_PARTITION 0
+/* This option switches multi-partition feature. By default (0), each logical drive
+/ number is bound to the same physical drive number and only an FAT volume found on
+/ the physical drive will be mounted. When multi-partition feature is enabled (1),
+/ each logical drive number is bound to arbitrary physical drive and partition
+/ listed in the VolToPart[]. Also f_fdisk() funciton will be enabled. */
#define _MIN_SS 512
#define _MAX_SS 512
-/* These options configure the range of sector size to be supported. (512, 1024, 2048 or
-/ 4096) Always set both 512 for most systems, all memory card and harddisk. But a larger
-/ value may be required for on-board flash memory and some type of optical media.
-/ When _MAX_SS is larger than _MIN_SS, FatFs is configured to variable sector size and
-/ GET_SECTOR_SIZE command must be implemented to the disk_ioctl() function. */
+/* These options configure the range of sector size to be supported. (512, 1024,
+/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
+/ harddisk. But a larger value may be required for on-board flash memory and some
+/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
+/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the
+/ disk_ioctl() function. */
-#define _USE_ERASE 0 /* 0:Disable or 1:Enable */
-/* To enable sector erase feature, set _USE_ERASE to 1. Also CTRL_ERASE_SECTOR command
-/ should be added to the disk_ioctl() function. */
+#define _USE_TRIM 0
+/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
+/ To enable Trim feature, also CTRL_TRIM command should be implemented to the
+/ disk_ioctl() function. */
-#define _FS_NOFSINFO 0 /* 0 to 3 */
-/* If you need to know correct free space on the FAT32 volume, set bit 0 of this option
-/ and f_getfree() function at first time after volume mount will force a full FAT scan.
-/ Bit 1 controls the last allocated cluster number as bit 0.
+#define _FS_NOFSINFO 0
+/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
+/ option, and f_getfree() function at first time after volume mount will force
+/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
/
/ bit0=0: Use free cluster count in the FSINFO if available.
/ bit0=1: Do not trust free cluster count in the FSINFO.
@@ -183,46 +199,72 @@
/ System Configurations
/---------------------------------------------------------------------------*/
-#define _FS_LOCK 0 /* 0:Disable or >=1:Enable */
-/* To enable file lock control feature, set _FS_LOCK to non-zero value.
-/ The value defines how many files/sub-directories can be opened simultaneously
-/ with file lock control. This feature uses bss _FS_LOCK * 12 bytes. */
-
-
-#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
-#define _FS_TIMEOUT 1000 /* Timeout period in unit of time tick */
-#define _SYNC_t HANDLE /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID, SemaphoreHandle_t and etc.. */
-/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
+#define _FS_NORTC 0
+#define _NORTC_MON 11
+#define _NORTC_MDAY 9
+#define _NORTC_YEAR 2014
+/* The _FS_NORTC option switches timestamp feature. If the system does not have
+/ an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
+/ the timestamp feature. All objects modified by FatFs will have a fixed timestamp
+/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR.
+/ When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need
+/ to be added to the project to read current time form RTC. _NORTC_MON,
+/ _NORTC_MDAY and _NORTC_YEAR have no effect.
+/ These options have no effect at read-only configuration (_FS_READONLY == 1). */
+
+
+#define _FS_LOCK 0
+/* The _FS_LOCK option switches file lock feature to control duplicated file open
+/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
+/ is 1.
+/
+/ 0: Disable file lock feature. To avoid volume corruption, application program
+/ should avoid illegal open, remove and rename to the open objects.
+/ >0: Enable file lock feature. The value defines how many files/sub-directories
+/ can be opened simultaneously under file lock control. Note that the file
+/ lock feature is independent of re-entrancy. */
+
+
+#define _FS_REENTRANT 0
+#define _FS_TIMEOUT 1000
+#define _SYNC_t HANDLE
+/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
+/ module itself. Note that regardless of this option, file access to different
+/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
+/ and f_fdisk() function, are always not re-entrant. Only file/directory access
+/ to the same volume is under control of this feature.
/
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
-/ function must be added to the project.
-*/
+/ function, must be added to the project. Samples are available in
+/ option/syscall.c.
+/
+/ The _FS_TIMEOUT defines timeout period in unit of time tick.
+/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
+/ SemaphoreHandle_t and etc.. */
-#define _WORD_ACCESS 0 /* 0 or 1 */
+#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.
+/ * Address misaligned memory access is always allowed to 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.
+/ If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
+/ Following table shows allowable settings 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
+/ Cortex-M0 0 x86 0/1 TLCS-870 0/1
+/ AVR 0/1 RX600(LE) 0/1 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
+/ PIC32 0 H8/300H 0 8051 0/1
*/
-
-#endif /* _FFCONF */
diff --git a/fatfs/src/option/cc932.c b/fatfs/src/option/cc932.c
index 26ac70f..36db384 100644
--- a/fatfs/src/option/cc932.c
+++ b/fatfs/src/option/cc932.c
@@ -3739,10 +3739,10 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
#if !_TINY_TABLE
if (dir) { /* OEMCP to unicode */
p = sjis2uni;
- hi = sizeof(sjis2uni) / 4 - 1;
+ hi = sizeof sjis2uni / 4 - 1;
} else { /* Unicode to OEMCP */
p = uni2sjis;
- hi = sizeof(uni2sjis) / 4 - 1;
+ hi = sizeof uni2sjis / 4 - 1;
}
li = 0;
for (n = 16; n; n--) {
@@ -3764,7 +3764,7 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
p -= 3;
c = *p;
} else { /* Unicode to OEMCP */
- li = 0; hi = sizeof(uni2sjis) / 4 - 1;
+ li = 0; hi = sizeof uni2sjis / 4 - 1;
for (n = 16; n; n--) {
i = li + (hi - li) / 2;
if (chr == uni2sjis[i * 2]) break;
diff --git a/fatfs/src/option/cc936.c b/fatfs/src/option/cc936.c
index 07a7c1c..84bc329 100644
--- a/fatfs/src/option/cc936.c
+++ b/fatfs/src/option/cc936.c
@@ -10936,10 +10936,10 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
} else {
if (dir) { /* OEMCP to unicode */
p = oem2uni;
- hi = sizeof(oem2uni) / 4 - 1;
+ hi = sizeof oem2uni / 4 - 1;
} else { /* Unicode to OEMCP */
p = uni2oem;
- hi = sizeof(uni2oem) / 4 - 1;
+ hi = sizeof uni2oem / 4 - 1;
}
li = 0;
for (n = 16; n; n--) {
diff --git a/fatfs/src/option/cc949.c b/fatfs/src/option/cc949.c
index 1fd075d..0abda85 100644
--- a/fatfs/src/option/cc949.c
+++ b/fatfs/src/option/cc949.c
@@ -8565,10 +8565,10 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
} else {
if (dir) { /* OEMCP to unicode */
p = oem2uni;
- hi = sizeof(oem2uni) / 4 - 1;
+ hi = sizeof oem2uni / 4 - 1;
} else { /* Unicode to OEMCP */
p = uni2oem;
- hi = sizeof(uni2oem) / 4 - 1;
+ hi = sizeof uni2oem / 4 - 1;
}
li = 0;
for (n = 16; n; n--) {
diff --git a/fatfs/src/option/cc950.c b/fatfs/src/option/cc950.c
index a3c9c44..d914b6d 100644
--- a/fatfs/src/option/cc950.c
+++ b/fatfs/src/option/cc950.c
@@ -6791,10 +6791,10 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
} else {
if (dir) { /* OEMCP to unicode */
p = oem2uni;
- hi = sizeof(oem2uni) / 4 - 1;
+ hi = sizeof oem2uni / 4 - 1;
} else { /* Unicode to OEMCP */
p = uni2oem;
- hi = sizeof(uni2oem) / 4 - 1;
+ hi = sizeof uni2oem / 4 - 1;
}
li = 0;
for (n = 16; n; n--) {
diff --git a/fatfs/src/option/ccsbcs.c b/fatfs/src/option/ccsbcs.c
index d6897bc..b16db30 100644
--- a/fatfs/src/option/ccsbcs.c
+++ b/fatfs/src/option/ccsbcs.c
@@ -444,7 +444,7 @@ const WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2
-}
+};
#elif _CODE_PAGE == 1257
#define _TBLDEF 1
diff --git a/fatfs/src/option/syscall.c b/fatfs/src/option/syscall.c
index ccfd47e..2036cb7 100644
--- a/fatfs/src/option/syscall.c
+++ b/fatfs/src/option/syscall.c
@@ -1,10 +1,8 @@
/*------------------------------------------------------------------------*/
/* Sample code of OS dependent controls for FatFs */
-/* (C)ChaN, 2012 */
+/* (C)ChaN, 2014 */
/*------------------------------------------------------------------------*/
-#include <stdlib.h> /* ANSI memory controls */
-#include <malloc.h> /* ANSI memory controls */
#include "../ff.h"
@@ -13,14 +11,14 @@
/*------------------------------------------------------------------------*/
/* Create a Synchronization Object
/*------------------------------------------------------------------------*/
-/* This function is called by f_mount() function to create a new
-/ synchronization object, such as semaphore and mutex. When a 0 is
-/ returned, the f_mount() function fails with FR_INT_ERR.
+/* This function is called in f_mount() function to create a new
+/ synchronization object, such as semaphore and mutex. When a 0 is returned,
+/ the f_mount() function fails with FR_INT_ERR.
*/
-int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any error */
+int ff_cre_syncobj ( /* !=0:Function succeeded, ==0:Could not create due to any error */
BYTE vol, /* Corresponding logical drive being processed */
- _SYNC_t* sobj /* Pointer to return the created sync object */
+ _SYNC_t *sobj /* Pointer to return the created sync object */
)
{
int ret;
@@ -29,13 +27,13 @@ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any erro
*sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */
ret = (int)(*sobj != INVALID_HANDLE_VALUE);
-// *sobj = SyncObjects[vol]; /* uITRON (give a static created semaphore) */
-// ret = 1;
+// *sobj = SyncObjects[vol]; /* uITRON (give a static created sync object) */
+// ret = 1; /* The initial value of the semaphore must be 1. */
-// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
+// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
// ret = (int)(err == OS_NO_ERR);
-// *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
+// *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
// ret = (int)(*sobj != NULL);
return ret;
@@ -47,11 +45,11 @@ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create due to any erro
/* Delete a Synchronization Object */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount() function to delete a synchronization
-/ object that created with ff_cre_syncobj() function. When a 0 is
-/ returned, the f_mount() function fails with FR_INT_ERR.
+/ object that created with ff_cre_syncobj function. When a 0 is returned,
+/ the f_mount() function fails with FR_INT_ERR.
*/
-int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */
+int ff_del_syncobj ( /* !=0:Function succeeded, ==0:Could not delete due to any error */
_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
)
{
@@ -65,7 +63,7 @@ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any erro
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
// ret = (int)(err == OS_NO_ERR);
-// xSemaphoreDelete(sobj); /* FreeRTOS */
+// vSemaphoreDelete(sobj); /* FreeRTOS */
// ret = 1;
return ret;
@@ -77,10 +75,10 @@ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any erro
/* Request Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on entering file functions to lock the volume.
-/ When a FALSE is returned, the file function fails with FR_TIMEOUT.
+/ When a 0 is returned, the file function fails with FR_TIMEOUT.
*/
-int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
+int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
_SYNC_t sobj /* Sync object to wait */
)
{
@@ -135,7 +133,7 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block */
UINT msize /* Number of bytes to allocate */
)
{
- return malloc(msize);
+ return malloc(msize); /* Allocate a new memory block with POSIX API */
}
@@ -147,7 +145,7 @@ void ff_memfree (
void* mblock /* Pointer to the memory block to free */
)
{
- free(mblock);
+ free(mblock); /* Discard the memory block with POSIX API */
}
#endif