Skip to content

Commit b31d308

Browse files
committed
Improvements in littlefs for virtual device
- Improvements in GetAttributes. - Add extra test code. - Comment test code.
1 parent eeacb90 commit b31d308

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

targets/netcore/littlefs/hal_littlefs.c

+31-34
Original file line numberDiff line numberDiff line change
@@ -334,45 +334,42 @@ int32_t hal_lfs_mount_partition(int32_t index, bool forceFormat)
334334

335335
// mount the file system again
336336
operationResult = lfs_mount(&lfs[index], &lfsConfig[index]);
337-
338-
// create the root directory
339-
lfs_mkdir(&lfs[index], "/");
340337
}
341338

342339
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
343340
// code block to assist testing littlefs
344341
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
345-
int32_t lfsIndex = 0;
346-
char writeBuf[] = {
347-
"Hello! if you get this message, congratulations, that's because littlefs is working on your device!!"};
348-
char readBuf[sizeof(writeBuf)];
349-
350-
lfs_file_t file;
351-
lfs_file_open(&lfs[lfsIndex], &file, "file1.txt", LFS_O_RDWR | LFS_O_CREAT);
352-
353-
if (lfs_file_write(&lfs[lfsIndex], &file, writeBuf, sizeof(writeBuf)) != sizeof(writeBuf))
354-
{
355-
// something went wrong
356-
return -1;
357-
}
358-
359-
lfs_file_close(&lfs[lfsIndex], &file);
360-
361-
// reopen the file and read it
362-
lfs_file_open(&lfs[lfsIndex], &file, "file1.txt", LFS_O_RDONLY);
363-
if (lfs_file_read(&lfs[lfsIndex], &file, readBuf, sizeof(readBuf)) != sizeof(writeBuf))
364-
{
365-
// something went wrong
366-
return -1;
367-
}
368-
369-
lfs_file_close(&lfs[lfsIndex], &file);
370-
371-
if (memcmp(writeBuf, readBuf, sizeof(writeBuf)) != 0)
372-
{
373-
// content doesn't match
374-
return -1;
375-
}
342+
// int32_t lfsIndex = 0;
343+
// char writeBuf[] = {
344+
// "Hello! if you get this message, congratulations, that's because littlefs is working on your device!!"};
345+
// char readBuf[sizeof(writeBuf)];
346+
347+
// lfs_file_t file;
348+
// lfs_file_open(&lfs[lfsIndex], &file, "file1.txt", LFS_O_RDWR | LFS_O_CREAT);
349+
350+
// if (lfs_file_write(&lfs[lfsIndex], &file, writeBuf, sizeof(writeBuf)) != sizeof(writeBuf))
351+
//{
352+
// // something went wrong
353+
// return -1;
354+
// }
355+
356+
// lfs_file_close(&lfs[lfsIndex], &file);
357+
358+
//// reopen the file and read it
359+
// lfs_file_open(&lfs[lfsIndex], &file, "file1.txt", LFS_O_RDONLY);
360+
// if (lfs_file_read(&lfs[lfsIndex], &file, readBuf, sizeof(readBuf)) != sizeof(writeBuf))
361+
//{
362+
// // something went wrong
363+
// return -1;
364+
// }
365+
366+
// lfs_file_close(&lfs[lfsIndex], &file);
367+
368+
// if (memcmp(writeBuf, readBuf, sizeof(writeBuf)) != 0)
369+
//{
370+
// // content doesn't match
371+
// return -1;
372+
// }
376373

377374
return operationResult;
378375
}

targets/netcore/littlefs/littlefs_FS_Driver.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
719719
lfs_info info;
720720
int32_t result;
721721
char normalizedPath[FS_MAX_DIRECTORY_LENGTH];
722+
// set to empty attributes
723+
uint32_t attributeBuffer = EMPTY_ATTRIBUTE;
722724

723725
// set to empty attributes
724726
*attributes = EMPTY_ATTRIBUTE;
@@ -751,7 +753,7 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
751753
// if this is home directory
752754
if (info.type == LFS_TYPE_DIR && *normalizedPath == '\0')
753755
{
754-
*attributes = FileAttributes::FileAttributes_Directory;
756+
attributeBuffer = FileAttributes::FileAttributes_Directory;
755757

756758
NANOCLR_SET_AND_LEAVE(S_OK);
757759
}
@@ -762,7 +764,7 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
762764
fsDrive,
763765
(const char *)normalizedPath,
764766
NANO_LITTLEFS_ATTRIBUTE,
765-
attributes,
767+
&attributeBuffer,
766768
NANO_LITTLEFS_ATTRIBUTE_SIZE);
767769

768770
if (result >= LFS_ERR_OK || result == LFS_ERR_NOATTR)
@@ -772,7 +774,7 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
772774
if (result == LFS_ERR_NOATTR)
773775
{
774776
// this is a directory, set dir attribute
775-
*attributes = FileAttributes::FileAttributes_Directory;
777+
attributeBuffer = FileAttributes::FileAttributes_Directory;
776778
}
777779
else
778780
{
@@ -793,7 +795,11 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
793795
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_DRIVER);
794796
}
795797

796-
NANOCLR_NOCLEANUP();
798+
NANOCLR_CLEANUP();
799+
800+
*attributes = attributeBuffer;
801+
802+
NANOCLR_CLEANUP_END();
797803
}
798804

799805
HRESULT LITTLEFS_FS_Driver::SetAttributes(const VOLUME_ID *volume, const char *path, uint32_t attributes)

0 commit comments

Comments
 (0)