The problem is there are only index.html and test.jpg files on the card. Funny is that it occurs for jpg but not for html. The card has been formated before the test. Can anyone confirm this?
Funny. I saw this bug for the first time when i was. using name image.jpg. I renamed it to test to be sure there was never such file on the card (and the gz version). I have my boards at work, can you check image.jpg Jay Jay?
Retested on Spider: if a file named “filename.xxx” exist on SD card already, File.Exist will return “TRUE” if file need to check that has pattern like: “filename.xxxyyyy…”.
Only happen on files have extension 3 characters
I think i found there reason for this problem. I have browsed .NET MF source code starting from File.Exists method and came across this file
\client_v4_1\DeviceCode\Drivers\FS\FAT\FAT_FS.cpp
Inside there is a method that essentialy is responsible for deciding whether the file exists or not. Here is the code:
BOOL FAT_Directory::IsName( LPCWSTR name, UINT32 nameLen )
{
char c;
int j;
// Compare the base name
for(j = 0; j < SHORTNAME_SIZE && nameLen > 0; j++)
{
c = (char)(*name);
name++;
nameLen--;
// stop if we see the "."
if(c == '.') break;
if(c >= 'a' && c <= 'z') c -= 'a' - 'A';
else if(j == 0 && c == 0xE5) c = 0x05;
if(DIR_Name[j] != c) return FALSE;
}
// the rest of the base name has to be blanks
for(; j < 8; j++)
{
if(DIR_Name[j] != WHITESPACE_CHAR) return FALSE;
}
// Only compare the extension if there is one
if(nameLen > 0)
{
// skip the '.' if we haven't already
if(*name == '.')
{
name++;
nameLen--;
}
// Compare the extension
for(; j < SHORTNAME_FULL_SIZE && nameLen > 0; j++)
{
c = (char)(*name);
name++;
nameLen--;
if(c >= 'a' && c <= 'z') c -= 'a' - 'A';
if(DIR_Name[j] != c) return FALSE;
}
}
// the rest of the extension has to be blanks
for(; j < 11; j++)
{
if(DIR_Name[j] != WHITESPACE_CHAR) return FALSE;
}
return TRUE;
}
Correct me if I’m wrong. In FAT when a filename is <= 11 characters (1-8 for name and 1-3 for extension) it will be stored as short entry. Let’s use this filename as an example:
index.htm
. The problem is that when we call
File.Exists("index.html")
we will get true. This is because the file we are trying to find has <= 11 characters and when we run the above method it will compare only first three characters of the extension. This problem should only occure for files that have 3 letter extensions and qualify for short entry in FAT. I think a simple fix at the end of that method could work to fix this problem:
return nameLen == 0;
Could GHI or anyone compile NET MF with this fix and check it ?