Skip to content

Upgrade ChanFs to R0.13a #5490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions features/filesystem/fat/ChaN/diskio.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
extern "C" {
#endif

#define _USE_WRITE 1 /* 1: Enable disk_write function */
#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */

#include "integer.h"


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

/* ATA/CF specific ioctl command */
#define ATA_GET_REV 20 /* Get F/W revision */
Expand Down
6,883 changes: 4,377 additions & 2,506 deletions features/filesystem/fat/ChaN/ff.cpp

Large diffs are not rendered by default.

332 changes: 173 additions & 159 deletions features/filesystem/fat/ChaN/ff.h

Large diffs are not rendered by default.

277 changes: 142 additions & 135 deletions features/filesystem/fat/ChaN/ffconf.h

Large diffs are not rendered by default.

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions features/filesystem/fat/ChaN/integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
/* Integer type definitions for FatFs module */
/*-------------------------------------------*/

#ifndef _FF_INTEGER
#define _FF_INTEGER
#ifndef FF_INTEGER
#define FF_INTEGER

#ifdef _WIN32 /* Development platform */
#ifdef _WIN32 /* FatFs development platform */

#include <windows.h>
#include <tchar.h>
typedef unsigned __int64 QWORD;


#else /* Embedded platform */

/* These types MUST be 16-bit or 32-bit */
typedef int INT;
typedef unsigned int UINT;

/* This type MUST be 8-bit */
typedef unsigned char BYTE;

Expand All @@ -20,14 +26,13 @@ typedef short SHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;

/* 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 long DWORD;

/* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */
typedef unsigned long long QWORD;

#endif

#endif
48 changes: 21 additions & 27 deletions features/filesystem/fat/FATFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static Deferred<const char*> fat_path_prefix(int id, const char *path)
////// Disk operations //////

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


Expand Down Expand Up @@ -167,7 +167,7 @@ static WORD disk_get_sector_size(BYTE pdrv)
ssize = 512;
}

MBED_ASSERT(ssize >= _MIN_SS && ssize <= _MAX_SS);
MBED_ASSERT(ssize >= FF_MIN_SS && ssize <= FF_MAX_SS);
MBED_ASSERT(_ffs[pdrv]->get_read_size() <= _ffs[pdrv]->get_erase_size());
MBED_ASSERT(_ffs[pdrv]->get_program_size() <= _ffs[pdrv]->get_erase_size());
return ssize;
Expand Down Expand Up @@ -287,7 +287,7 @@ int FATFileSystem::mount(BlockDevice *bd, bool mount) {
return -EINVAL;
}

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

// Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
fs.lock();
FRESULT res = f_mkfs(fs._fsid, 1, cluster_size);
FRESULT res = f_mkfs(fs._fsid, FM_ANY, cluster_size, NULL, 0);
fs.unlock();
if (res != FR_OK) {
return fat_error_remap(res);
Expand Down Expand Up @@ -467,6 +467,7 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
} else {
openmode = FA_READ;
}

if (flags & O_CREAT) {
if (flags & O_TRUNC) {
openmode |= FA_CREATE_ALWAYS;
Expand All @@ -475,6 +476,10 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
}
}

if (flags & O_APPEND) {
openmode |= FA_OPEN_APPEND;
}

lock();
FRESULT res = f_open(fh, fpath, openmode);

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

if (flags & O_APPEND) {
f_lseek(fh, fh->fsize);
}
unlock();

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

lock();
if (whence == SEEK_END) {
offset += fh->fsize;
offset += f_size(fh);
} else if(whence==SEEK_CUR) {
offset += fh->fptr;
offset += f_tell(fh);
}

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

lock();
off_t res = fh->fptr;
off_t res = f_tell(fh);
unlock();

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

lock();
off_t res = fh->fsize;
off_t res = f_size(fh);
unlock();

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

#if _USE_LFN
finfo.lfname = ent->d_name;
finfo.lfsize = NAME_MAX;
#endif // _USE_LFN

lock();
FRESULT res = f_readdir(dh, &finfo);
unlock();
Expand All @@ -644,13 +641,13 @@ ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent) {

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

#if _USE_LFN
#if FF_USE_LFN
if (ent->d_name[0] == 0) {
// No long filename so use short filename.
strncpy(ent->d_name, finfo.fname, NAME_MAX);
strncpy(ent->d_name, finfo.fname, FF_LFN_BUF);
}
#else
strncpy(end->d_name, finfo.fname, len);
strncpy(ent->d_name, finfo.fname, FF_SFN_BUF);
#endif

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

lock();
if (offset < dh->index) {

if (offset < dh->dptr) {
f_rewinddir(dh);
}
while (dh->index < offset) {
while (dh->dptr < offset) {
FILINFO finfo;
FRESULT res;
#if _USE_LFN
char lfname[NAME_MAX];
finfo.lfname = lfname;
finfo.lfsize = NAME_MAX;
#endif // _USE_LFN

res = f_readdir(dh, &finfo);
if (res != FR_OK) {
break;
Expand All @@ -685,7 +679,7 @@ off_t FATFileSystem::dir_tell(fs_dir_t dir) {
FATFS_DIR *dh = static_cast<FATFS_DIR*>(dir);

lock();
off_t offset = dh->index;
off_t offset = dh->dptr;
unlock();

return offset;
Expand Down