Skip to content

Improvements in littlefs for virtual device #2986

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
Jul 24, 2024
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
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ jobs:
if(
(($files.where{$_.Contains('targets/netcore/nanoFramework.nanoCLR')}).Count -gt 0) -Or
(($files.where{$_.Contains('targets/netcore/nanoCLR.sln')}).Count -gt 0) -Or
(($files.where{$_.Contains('targets/netcore/littlefs')}).Count -gt 0) -Or
(($files.where{$_.Contains('targets/win32')}).Count -gt 0)
)
{
Expand Down
65 changes: 31 additions & 34 deletions targets/netcore/littlefs/hal_littlefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,45 +334,42 @@ int32_t hal_lfs_mount_partition(int32_t index, bool forceFormat)

// mount the file system again
operationResult = lfs_mount(&lfs[index], &lfsConfig[index]);

// create the root directory
lfs_mkdir(&lfs[index], "/");
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// code block to assist testing littlefs
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int32_t lfsIndex = 0;
char writeBuf[] = {
"Hello! if you get this message, congratulations, that's because littlefs is working on your device!!"};
char readBuf[sizeof(writeBuf)];

lfs_file_t file;
lfs_file_open(&lfs[lfsIndex], &file, "file1.txt", LFS_O_RDWR | LFS_O_CREAT);

if (lfs_file_write(&lfs[lfsIndex], &file, writeBuf, sizeof(writeBuf)) != sizeof(writeBuf))
{
// something went wrong
return -1;
}

lfs_file_close(&lfs[lfsIndex], &file);

// reopen the file and read it
lfs_file_open(&lfs[lfsIndex], &file, "file1.txt", LFS_O_RDONLY);
if (lfs_file_read(&lfs[lfsIndex], &file, readBuf, sizeof(readBuf)) != sizeof(writeBuf))
{
// something went wrong
return -1;
}

lfs_file_close(&lfs[lfsIndex], &file);

if (memcmp(writeBuf, readBuf, sizeof(writeBuf)) != 0)
{
// content doesn't match
return -1;
}
// int32_t lfsIndex = 0;
// char writeBuf[] = {
// "Hello! if you get this message, congratulations, that's because littlefs is working on your device!!"};
// char readBuf[sizeof(writeBuf)];

// lfs_file_t file;
// lfs_file_open(&lfs[lfsIndex], &file, "file1.txt", LFS_O_RDWR | LFS_O_CREAT);

// if (lfs_file_write(&lfs[lfsIndex], &file, writeBuf, sizeof(writeBuf)) != sizeof(writeBuf))
//{
// // something went wrong
// return -1;
// }

// lfs_file_close(&lfs[lfsIndex], &file);

//// reopen the file and read it
// lfs_file_open(&lfs[lfsIndex], &file, "file1.txt", LFS_O_RDONLY);
// if (lfs_file_read(&lfs[lfsIndex], &file, readBuf, sizeof(readBuf)) != sizeof(writeBuf))
//{
// // something went wrong
// return -1;
// }

// lfs_file_close(&lfs[lfsIndex], &file);

// if (memcmp(writeBuf, readBuf, sizeof(writeBuf)) != 0)
//{
// // content doesn't match
// return -1;
// }

return operationResult;
}
Expand Down
14 changes: 10 additions & 4 deletions targets/netcore/littlefs/littlefs_FS_Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
lfs_info info;
int32_t result;
char normalizedPath[FS_MAX_DIRECTORY_LENGTH];
// set to empty attributes
uint32_t attributeBuffer = EMPTY_ATTRIBUTE;

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

NANOCLR_SET_AND_LEAVE(S_OK);
}
Expand All @@ -762,7 +764,7 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
fsDrive,
(const char *)normalizedPath,
NANO_LITTLEFS_ATTRIBUTE,
attributes,
&attributeBuffer,
NANO_LITTLEFS_ATTRIBUTE_SIZE);

if (result >= LFS_ERR_OK || result == LFS_ERR_NOATTR)
Expand All @@ -772,7 +774,7 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
if (result == LFS_ERR_NOATTR)
{
// this is a directory, set dir attribute
*attributes = FileAttributes::FileAttributes_Directory;
attributeBuffer = FileAttributes::FileAttributes_Directory;
}
else
{
Expand All @@ -793,7 +795,11 @@ HRESULT LITTLEFS_FS_Driver::GetAttributes(const VOLUME_ID *volume, const char *p
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_DRIVER);
}

NANOCLR_NOCLEANUP();
NANOCLR_CLEANUP();

*attributes = attributeBuffer;

NANOCLR_CLEANUP_END();
}

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