Skip to content

Commit 8a39773

Browse files
authored
Merge pull request #5490 from deepikabhavnani/fat_upgrade
Upgrade ChanFs to R0.13a
2 parents e413350 + a2a7c28 commit 8a39773

File tree

7 files changed

+5015
-2975
lines changed

7 files changed

+5015
-2975
lines changed

features/filesystem/fat/ChaN/diskio.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
extern "C" {
1010
#endif
1111

12-
#define _USE_WRITE 1 /* 1: Enable disk_write function */
13-
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
14-
1512
#include "integer.h"
1613

1714

@@ -67,6 +64,9 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
6764
#define MMC_GET_CID 12 /* Get CID */
6865
#define MMC_GET_OCR 13 /* Get OCR */
6966
#define MMC_GET_SDSTAT 14 /* Get SD status */
67+
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
68+
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
69+
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
7070

7171
/* ATA/CF specific ioctl command */
7272
#define ATA_GET_REV 20 /* Get F/W revision */

features/filesystem/fat/ChaN/ff.cpp

Lines changed: 4377 additions & 2506 deletions
Large diffs are not rendered by default.

features/filesystem/fat/ChaN/ff.h

Lines changed: 173 additions & 159 deletions
Large diffs are not rendered by default.

features/filesystem/fat/ChaN/ffconf.h

Lines changed: 142 additions & 135 deletions
Large diffs are not rendered by default.

features/filesystem/fat/ChaN/ccsbcs.cpp renamed to features/filesystem/fat/ChaN/ffunicode.cpp

Lines changed: 287 additions & 138 deletions
Large diffs are not rendered by default.

features/filesystem/fat/ChaN/integer.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
/* Integer type definitions for FatFs module */
33
/*-------------------------------------------*/
44

5-
#ifndef _FF_INTEGER
6-
#define _FF_INTEGER
5+
#ifndef FF_INTEGER
6+
#define FF_INTEGER
77

8-
#ifdef _WIN32 /* Development platform */
8+
#ifdef _WIN32 /* FatFs development platform */
99

1010
#include <windows.h>
1111
#include <tchar.h>
12+
typedef unsigned __int64 QWORD;
13+
1214

1315
#else /* Embedded platform */
1416

17+
/* These types MUST be 16-bit or 32-bit */
18+
typedef int INT;
19+
typedef unsigned int UINT;
20+
1521
/* This type MUST be 8-bit */
1622
typedef unsigned char BYTE;
1723

@@ -20,14 +26,13 @@ typedef short SHORT;
2026
typedef unsigned short WORD;
2127
typedef unsigned short WCHAR;
2228

23-
/* These types MUST be 16-bit or 32-bit */
24-
typedef int INT;
25-
typedef unsigned int UINT;
26-
2729
/* These types MUST be 32-bit */
2830
typedef long LONG;
2931
typedef unsigned long DWORD;
3032

33+
/* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */
34+
typedef unsigned long long QWORD;
35+
3136
#endif
3237

3338
#endif

features/filesystem/fat/FATFileSystem.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static Deferred<const char*> fat_path_prefix(int id, const char *path)
131131
////// Disk operations //////
132132

133133
// Global access to block device from FAT driver
134-
static BlockDevice *_ffs[_VOLUMES] = {0};
134+
static BlockDevice *_ffs[FF_VOLUMES] = {0};
135135
static SingletonPtr<PlatformMutex> _ffs_mutex;
136136

137137

@@ -167,7 +167,7 @@ static WORD disk_get_sector_size(BYTE pdrv)
167167
ssize = 512;
168168
}
169169

170-
MBED_ASSERT(ssize >= _MIN_SS && ssize <= _MAX_SS);
170+
MBED_ASSERT(ssize >= FF_MIN_SS && ssize <= FF_MAX_SS);
171171
MBED_ASSERT(_ffs[pdrv]->get_read_size() <= _ffs[pdrv]->get_erase_size());
172172
MBED_ASSERT(_ffs[pdrv]->get_program_size() <= _ffs[pdrv]->get_erase_size());
173173
return ssize;
@@ -287,7 +287,7 @@ int FATFileSystem::mount(BlockDevice *bd, bool mount) {
287287
return -EINVAL;
288288
}
289289

290-
for (int i = 0; i < _VOLUMES; i++) {
290+
for (int i = 0; i < FF_VOLUMES; i++) {
291291
if (!_ffs[i]) {
292292
_id = i;
293293
_ffs[_id] = bd;
@@ -331,7 +331,7 @@ int FATFileSystem::format(BlockDevice *bd, bd_size_t cluster_size) {
331331

332332
// Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
333333
fs.lock();
334-
FRESULT res = f_mkfs(fs._fsid, 1, cluster_size);
334+
FRESULT res = f_mkfs(fs._fsid, FM_ANY, cluster_size, NULL, 0);
335335
fs.unlock();
336336
if (res != FR_OK) {
337337
return fat_error_remap(res);
@@ -467,6 +467,7 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
467467
} else {
468468
openmode = FA_READ;
469469
}
470+
470471
if (flags & O_CREAT) {
471472
if (flags & O_TRUNC) {
472473
openmode |= FA_CREATE_ALWAYS;
@@ -475,6 +476,10 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
475476
}
476477
}
477478

479+
if (flags & O_APPEND) {
480+
openmode |= FA_OPEN_APPEND;
481+
}
482+
478483
lock();
479484
FRESULT res = f_open(fh, fpath, openmode);
480485

@@ -485,9 +490,6 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
485490
return fat_error_remap(res);
486491
}
487492

488-
if (flags & O_APPEND) {
489-
f_lseek(fh, fh->fsize);
490-
}
491493
unlock();
492494

493495
*file = fh;
@@ -555,9 +557,9 @@ off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence) {
555557

556558
lock();
557559
if (whence == SEEK_END) {
558-
offset += fh->fsize;
560+
offset += f_size(fh);
559561
} else if(whence==SEEK_CUR) {
560-
offset += fh->fptr;
562+
offset += f_tell(fh);
561563
}
562564

563565
FRESULT res = f_lseek(fh, offset);
@@ -576,7 +578,7 @@ off_t FATFileSystem::file_tell(fs_file_t file) {
576578
FIL *fh = static_cast<FIL*>(file);
577579

578580
lock();
579-
off_t res = fh->fptr;
581+
off_t res = f_tell(fh);
580582
unlock();
581583

582584
return res;
@@ -586,7 +588,7 @@ off_t FATFileSystem::file_size(fs_file_t file) {
586588
FIL *fh = static_cast<FIL*>(file);
587589

588590
lock();
589-
off_t res = fh->fsize;
591+
off_t res = f_size(fh);
590592
unlock();
591593

592594
return res;
@@ -627,11 +629,6 @@ ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent) {
627629
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
628630
FILINFO finfo;
629631

630-
#if _USE_LFN
631-
finfo.lfname = ent->d_name;
632-
finfo.lfsize = NAME_MAX;
633-
#endif // _USE_LFN
634-
635632
lock();
636633
FRESULT res = f_readdir(dh, &finfo);
637634
unlock();
@@ -644,13 +641,13 @@ ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent) {
644641

645642
ent->d_type = (finfo.fattrib & AM_DIR) ? DT_DIR : DT_REG;
646643

647-
#if _USE_LFN
644+
#if FF_USE_LFN
648645
if (ent->d_name[0] == 0) {
649646
// No long filename so use short filename.
650-
strncpy(ent->d_name, finfo.fname, NAME_MAX);
647+
strncpy(ent->d_name, finfo.fname, FF_LFN_BUF);
651648
}
652649
#else
653-
strncpy(end->d_name, finfo.fname, len);
650+
strncpy(ent->d_name, finfo.fname, FF_SFN_BUF);
654651
#endif
655652

656653
return 1;
@@ -660,17 +657,14 @@ void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset) {
660657
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
661658

662659
lock();
663-
if (offset < dh->index) {
660+
661+
if (offset < dh->dptr) {
664662
f_rewinddir(dh);
665663
}
666-
while (dh->index < offset) {
664+
while (dh->dptr < offset) {
667665
FILINFO finfo;
668666
FRESULT res;
669-
#if _USE_LFN
670-
char lfname[NAME_MAX];
671-
finfo.lfname = lfname;
672-
finfo.lfsize = NAME_MAX;
673-
#endif // _USE_LFN
667+
674668
res = f_readdir(dh, &finfo);
675669
if (res != FR_OK) {
676670
break;
@@ -685,7 +679,7 @@ off_t FATFileSystem::dir_tell(fs_dir_t dir) {
685679
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);
686680

687681
lock();
688-
off_t offset = dh->index;
682+
off_t offset = dh->dptr;
689683
unlock();
690684

691685
return offset;

0 commit comments

Comments
 (0)