Hi,
the mbed class FileSystem (mbed-os/FileSystem.h at master · ARMmbed/mbed-os · GitHub )
is defining opaque pointers (l. 34 ff.):
// Opaque pointer representing files and directories.
typedef void *fs_file_t;
typedef void *fs_dir_t;
What types are compatible with these and, out of personal interest, why was it chosen to use opaque pointers for this, after all?
reneg973
(Rene G.)
April 19, 2021, 12:29pm
2
You should check the design first. There are different classes deriving from FileSystem. All of them can return a different type for this pointer. You shouldn’t take care about it.
ladislas
(Ladislas de Toldi)
April 20, 2021, 1:16pm
3
if you use FAT, it will be a FIL *
, see FatFs - FIL
if (res != FR_OK) {
debug_if(FFS_DBG, "f_read() failed: %d\n", res);
return fat_error_remap(res);
} else {
return n;
}
}
ssize_t FATFileSystem::file_write(fs_file_t file, const void *buffer, size_t len)
{
FIL *fh = static_cast<FIL *>(file);
lock();
UINT n;
FRESULT res = f_write(fh, buffer, len, &n);
unlock();
for LittleFs it will be a lfs_file_t *
ssize_t LittleFileSystem::file_write(fs_file_t file, const void *buffer, size_t len)
{
lfs_file_t *f = (lfs_file_t *)file;
_mutex.lock();
LFS_INFO("file_write(%p, %p, %d)", file, buffer, len);
lfs_ssize_t res = lfs_file_write(&_lfs, f, buffer, len);
LFS_INFO("file_write -> %d", lfs_toerror(res));
_mutex.unlock();
return lfs_toerror(res);
}