Skip to content

Commit 76e688e

Browse files
authored
Fix getting file size for NativeFileInfo (#2996)
***NO_CI***
1 parent a2cd773 commit 76e688e

File tree

7 files changed

+30
-4
lines changed

7 files changed

+30
-4
lines changed

src/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_NativeFindFile.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ HRESULT Library_nf_sys_io_filesystem_System_IO_NativeFindFile::GetFileInfo___STA
2525

2626
NANOCLR_CHECK_HRESULT(Library_nf_sys_io_filesystem_System_IO_NativeIO::FindVolume(stack.Arg0(), driver, path));
2727

28+
// zero initialize the fileInfo
29+
memset(&fileInfo, 0, sizeof(FS_FILEINFO));
30+
2831
NANOCLR_CHECK_HRESULT(driver->GetFileInfo(path, &fileInfo, &found));
2932

3033
if (found)
3134
{
3235
// find <NativeFindFile> type definition, don't bother checking the result as it exists for sure
33-
g_CLR_RT_TypeSystem.FindTypeDef("NativeFindFile", "System.IO", nativeFindFileTypeDef);
36+
g_CLR_RT_TypeSystem.FindTypeDef("NativeFileInfo", "System.IO", nativeFindFileTypeDef);
3437

3538
// create an instance of <NativeFindFile>
3639
NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(top, nativeFindFileTypeDef));

targets/ChibiOS/_FatFs/fatfs_FS_Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,9 @@ HRESULT FATFS_FS_Driver::GetFileInfo(const VOLUME_ID *volume, const char *path,
744744
// store the attributes
745745
fileInfo->Attributes = info.fattrib;
746746

747+
// set the file size
748+
fileInfo->Size = info.fsize;
749+
747750
// no need to set the file name details as managed code already has this info
748751
}
749752

targets/ChibiOS/_littlefs/littlefs_FS_Driver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,8 @@ HRESULT LITTLEFS_FS_Driver::GetFileInfo(const VOLUME_ID *volume, const char *pat
733733
&fileInfo->Attributes,
734734
NANO_LITTLEFS_ATTRIBUTE_SIZE);
735735

736+
fileInfo->Size = info.size;
737+
736738
// no need to set the file name details as managed code already has this info
737739
}
738740

@@ -1212,4 +1214,4 @@ FILESYSTEM_DRIVER_INTERFACE g_LITTLEFS_FILE_SYSTEM_DriverInterface = {
12121214

12131215
"LITTLEFS",
12141216
0,
1215-
};
1217+
};

targets/ESP32/_FatFs/fatfs_FS_Driver.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,22 @@ HRESULT FATFS_FS_Driver::GetFileInfo(const VOLUME_ID *volume, const char *path,
642642
// set found flag
643643
*found = true;
644644

645+
// store the attributes
646+
if (S_ISDIR(info.fattrib))
647+
{
648+
fileInfo->Attributes = FileAttributes::FileAttributes_Directory;
649+
}
650+
else
651+
{
652+
fileInfo->Attributes = FileAttributes::FileAttributes_Archive;
653+
}
654+
645655
// store the attributes
646656
fileInfo->Attributes = info.fattrib;
647657

658+
// set the file size
659+
fileInfo->Size = info.fsize;
660+
648661
// no need to set the file name details as managed code already has this info
649662
}
650663

targets/ESP32/_IDF/esp32/app_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ void app_main()
6161
ESP_ERROR_CHECK(nvs_flash_init());
6262

6363
// start receiver task pinned to core 1
64-
xTaskCreatePinnedToCore(&receiver_task, "ReceiverThread", 3072, NULL, 5, NULL, 0);
64+
xTaskCreatePinnedToCore(&receiver_task, "ReceiverThread", 3072, NULL, 5, NULL, 1);
6565

6666
// start the CLR main task pinned to core 0
67-
xTaskCreatePinnedToCore(&main_task, "main_task", 15000, NULL, 5, NULL, 1);
67+
xTaskCreatePinnedToCore(&main_task, "main_task", 15000, NULL, 5, NULL, 0);
6868
}

targets/ESP32/_littlefs/littlefs_FS_Driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@ HRESULT LITTLEFS_FS_Driver::GetFileInfo(const VOLUME_ID *volume, const char *pat
699699
fileInfo->Attributes = FileAttributes::FileAttributes_Archive;
700700
}
701701

702+
// set the file size
703+
fileInfo->Size = info.st_size;
704+
702705
// no need to set the file name details as managed code already has this info
703706
}
704707

targets/netcore/littlefs/littlefs_FS_Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ HRESULT LITTLEFS_FS_Driver::GetFileInfo(const VOLUME_ID *volume, const char *pat
702702
&fileInfo->Attributes,
703703
NANO_LITTLEFS_ATTRIBUTE_SIZE);
704704

705+
fileInfo->Size = info.size;
706+
705707
// no need to set the file name details as managed code already has this info
706708
}
707709

0 commit comments

Comments
 (0)