mirror of https://github.com/ARMmbed/mbed-os.git
STORAGE: fixes for merging in format test with new block device implementation of format.
parent
01baa72ab9
commit
0b7a2ca030
|
@ -29,10 +29,27 @@ using namespace utest::v1;
|
||||||
HeapBlockDevice bd(128*BLOCK_SIZE, BLOCK_SIZE);
|
HeapBlockDevice bd(128*BLOCK_SIZE, BLOCK_SIZE);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void test_format() {
|
void test_format() {
|
||||||
int err = FATFileSystem::format(&bd);
|
int err = FATFileSystem::format(&bd);
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void test_format() {
|
||||||
|
int err = -1;
|
||||||
|
FATFileSystem fs("");
|
||||||
|
|
||||||
|
err = fs.mount(&bd, false);
|
||||||
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
|
err = fs.format(&bd);
|
||||||
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
||||||
|
err = fs.unmount();
|
||||||
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Simple test for reading/writing files
|
// Simple test for reading/writing files
|
||||||
template <ssize_t TEST_SIZE>
|
template <ssize_t TEST_SIZE>
|
||||||
|
|
|
@ -816,7 +816,7 @@ control_t fsfat_fopen_test_07(const size_t call_count)
|
||||||
FILE *f = NULL;
|
FILE *f = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int errno_val = 0;
|
int errno_val = 0;
|
||||||
char *filename = "/sd/badfile.txt";
|
char *filename = (char*) "/sd/badfile.txt";
|
||||||
|
|
||||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||||
(void) call_count;
|
(void) call_count;
|
||||||
|
@ -872,7 +872,7 @@ control_t fsfat_fopen_test_08(const size_t call_count)
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int ret_ferror = -1;
|
int ret_ferror = -1;
|
||||||
char *filename = "/sd/test.txt";
|
char *filename = (char*) "/sd/test.txt";
|
||||||
int errno_val = 0;
|
int errno_val = 0;
|
||||||
|
|
||||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||||
|
@ -971,7 +971,7 @@ control_t fsfat_fopen_test_08(const size_t call_count)
|
||||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g);
|
TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g);
|
||||||
return CaseNext;
|
return CaseNext;
|
||||||
}
|
}
|
||||||
#endif NO_SYMBOL
|
#endif //NO_SYMBOL
|
||||||
|
|
||||||
/** @brief test for operation of ftell()
|
/** @brief test for operation of ftell()
|
||||||
*
|
*
|
||||||
|
@ -1243,7 +1243,7 @@ control_t fsfat_fopen_test_22(const size_t call_count)
|
||||||
int32_t ret = -1;
|
int32_t ret = -1;
|
||||||
|
|
||||||
/* the allocation_unit of 0 means chanFS will use the default for the card (varies according to capacity). */
|
/* the allocation_unit of 0 means chanFS will use the default for the card (varies according to capacity). */
|
||||||
ret = sd.format(0);
|
ret = fs.format(&sd, 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);
|
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);
|
TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g);
|
||||||
return CaseNext;
|
return CaseNext;
|
||||||
|
|
|
@ -187,10 +187,6 @@ FATFileSystem::~FATFileSystem() {
|
||||||
unmount();
|
unmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
int FATFileSystem::mount(BlockDevice *bd) {
|
|
||||||
return mount(bd, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FATFileSystem::mount(BlockDevice *bd, bool force) {
|
int FATFileSystem::mount(BlockDevice *bd, bool force) {
|
||||||
lock();
|
lock();
|
||||||
if (_id != -1) {
|
if (_id != -1) {
|
||||||
|
@ -241,7 +237,21 @@ int FATFileSystem::sync() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FATFileSystem::format(BlockDevice *bd) {
|
/* 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;
|
||||||
|
}
|
||||||
|
int FATFileSystem::format(BlockDevice *bd, int allocation_unit) {
|
||||||
FATFileSystem fs("");
|
FATFileSystem fs("");
|
||||||
int err = fs.mount(bd, false);
|
int err = fs.mount(bd, false);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -250,7 +260,7 @@ int FATFileSystem::format(BlockDevice *bd) {
|
||||||
|
|
||||||
// Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
|
// Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
|
||||||
fs.lock();
|
fs.lock();
|
||||||
FRESULT res = f_mkfs(fs._fsid, 0, 512);
|
FRESULT res = f_mkfs(fs._fsid, 0, int allocation_unit);
|
||||||
fs.unlock();
|
fs.unlock();
|
||||||
|
|
||||||
err = fs.unmount();
|
err = fs.unmount();
|
||||||
|
@ -260,6 +270,33 @@ int FATFileSystem::format(BlockDevice *bd) {
|
||||||
|
|
||||||
return res == 0 ? 0 : -1;
|
return res == 0 ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* See http://elm-chan.org/fsw/ff/en/mkfs.html for details of f_mkfs() and
|
||||||
|
* associated arguments. */
|
||||||
|
int FATFileSystem::format(BlockDevice *bd, int allocation_unit) {
|
||||||
|
//FATFileSystem fs("");
|
||||||
|
//int err = fs.mount(bd, false);
|
||||||
|
//if (err) {
|
||||||
|
// return -1;
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
|
||||||
|
//fs.lock();
|
||||||
|
lock();
|
||||||
|
//FRESULT res = f_mkfs(fs._fsid, 0, allocation_unit);
|
||||||
|
FRESULT res = f_mkfs(_fsid, 0, allocation_unit);
|
||||||
|
//fs.unlock();
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
//err = fs.unmount();
|
||||||
|
//if (err) {
|
||||||
|
// return -1;
|
||||||
|
//}
|
||||||
|
|
||||||
|
return res == 0 ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FileHandle *FATFileSystem::open(const char* name, int flags) {
|
FileHandle *FATFileSystem::open(const char* name, int flags) {
|
||||||
lock();
|
lock();
|
||||||
|
@ -323,23 +360,7 @@ int FATFileSystem::rename(const char *oldname, const char *newname) {
|
||||||
return 0;
|
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) {
|
DirHandle *FATFileSystem::opendir(const char *name) {
|
||||||
lock();
|
lock();
|
||||||
FATFS_DIR dir;
|
FATFS_DIR dir;
|
||||||
|
|
|
@ -40,9 +40,15 @@ public:
|
||||||
virtual ~FATFileSystem();
|
virtual ~FATFileSystem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mounts the filesystem
|
* @brief Mounts the filesystem
|
||||||
|
*
|
||||||
|
* @param bd
|
||||||
|
* This is the block device that will be formated.
|
||||||
|
*
|
||||||
|
* @param force
|
||||||
|
* Flag to underlying filesystem to force the mounting of the filesystem.
|
||||||
*/
|
*/
|
||||||
virtual int mount(BlockDevice *bd);
|
virtual int mount(BlockDevice *bd, bool force = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unmounts the filesystem
|
* Unmounts the filesystem
|
||||||
|
@ -55,9 +61,21 @@ public:
|
||||||
virtual int sync();
|
virtual int sync();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a logical drive, FDISK partitioning rule, 512 bytes per cluster
|
* @brief Formats a logical drive, FDISK partitioning rule.
|
||||||
|
*
|
||||||
|
* The block device to format should be mounted when this function is called.
|
||||||
|
*
|
||||||
|
* @param bd
|
||||||
|
* This is the block device that will be formated.
|
||||||
|
*
|
||||||
|
* @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 by the underlying
|
||||||
|
* filesystem, which depends on the volume size.
|
||||||
*/
|
*/
|
||||||
static int format(BlockDevice *bd);
|
int format(BlockDevice *bd, int allocation_unit = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file on the filesystem
|
* Opens a file on the filesystem
|
||||||
|
@ -74,18 +92,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int rename(const char *oldname, const char *newname);
|
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
|
* Opens a directory on the filesystem
|
||||||
*/
|
*/
|
||||||
|
@ -106,8 +112,6 @@ protected:
|
||||||
char _fsid[2];
|
char _fsid[2];
|
||||||
int _id;
|
int _id;
|
||||||
|
|
||||||
virtual int mount(BlockDevice *bd, bool force);
|
|
||||||
|
|
||||||
virtual void lock();
|
virtual void lock();
|
||||||
virtual void unlock();
|
virtual void unlock();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue