STORAGE: change FATFileSystem::format() to include allocation_unit argument, to facilitate fixing of inconsistent file systems.

Conflicts:
	features/filesystem/fat/FATFileSystem.cpp
	features/filesystem/fat/FATFileSystem.h
pull/3762/head
Simon Hughes 2017-02-03 11:40:08 +00:00
parent 26141f0f5d
commit 01baa72ab9
3 changed files with 48 additions and 0 deletions

View File

@ -1231,6 +1231,24 @@ control_t fsfat_fopen_test_21(const size_t call_count)
return CaseNext;
}
/** @brief test for operation of SDFileSystem::format()
*
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
*/
control_t fsfat_fopen_test_22(const size_t call_count)
{
FSFAT_FENTRYLOG("%s:entered\n", __func__);
(void) call_count;
int32_t ret = -1;
/* the allocation_unit of 0 means chanFS will use the default for the card (varies according to capacity). */
ret = sd.format(0);
FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE, "%s:Error: failed to format sdcard (ret=%d)\n", __func__, (int) ret);
TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g);
return CaseNext;
}
@ -1319,6 +1337,7 @@ Case cases[] = {
#ifdef FOPEN_NOT_IMPLEMENTED
Case("FSFAT_FOPEN_TEST_21: todo.", FSFAT_FOPEN_TEST_21),
#endif /* FOPEN_NOT_IMPLEMENTED */
Case("FSFAT_FOPEN_TEST_22: format() test.", FSFAT_FOPEN_TEST_22),
};

View File

@ -323,6 +323,23 @@ int FATFileSystem::rename(const char *oldname, const char *newname) {
return 0;
}
<<<<<<< HEAD
=======
/* See http://elm-chan.org/fsw/ff/en/mkfs.html for details of f_mkfs() and
* associated arguments. */
int FATFileSystem::format(int allocation_unit) {
lock();
FRESULT res = f_mkfs(_fsid, 0, allocation_unit); // Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
if (res) {
debug_if(FFS_DBG, "f_mkfs() failed: %d\n", res);
unlock();
return -1;
}
unlock();
return 0;
}
>>>>>>> b86fe65... STORAGE: change FATFileSystem::format() to include allocation_unit argument, to facilitate fixing of inconsistent file systems.
DirHandle *FATFileSystem::opendir(const char *name) {
lock();
FATFS_DIR dir;

View File

@ -74,6 +74,18 @@ public:
*/
virtual int rename(const char *oldname, const char *newname);
/**
* Formats a logical drive, FDISK partitioning rule.
*
* @param allocation_unit
* This is the number of bytes per cluster size. The valid value is N
* times the sector size. N is a power of 2 from 1 to 128 for FAT
* volume and upto 16MiB for exFAT volume. If zero is given,
* the default allocation unit size is selected depending on the volume
* size.
*/
virtual int format(int allocation_unit = 0);
/**
* Opens a directory on the filesystem
*/