Line 389... |
Line 389... |
|
|
static int FileFind(OS_FILE *directory, char *name, OS_FileEntry_t *fileEntry)
|
static int FileFind(OS_FILE *directory, char *name, OS_FileEntry_t *fileEntry)
|
{
|
{
|
int count, rc = -1;
|
int count, rc = -1;
|
uint32 blockIndex, blockOffset;
|
uint32 blockIndex, blockOffset;
|
uint32 blockIndexEmpty=BLOCK_EOF, blockOffsetEmpty=0;
|
uint32 blockIndexEmpty=BLOCK_EOF, blockOffsetEmpty=0, fileOffsetEmpty=0;
|
|
|
// Loop through files in directory
|
// Loop through files in directory
|
for(;;)
|
for(;;)
|
{
|
{
|
blockIndex = directory->blockIndex;
|
blockIndex = directory->blockIndex;
|
Line 408... |
Line 408... |
}
|
}
|
if(fileEntry->valid != 1 && blockIndexEmpty == BLOCK_EOF)
|
if(fileEntry->valid != 1 && blockIndexEmpty == BLOCK_EOF)
|
{
|
{
|
blockIndexEmpty = blockIndex;
|
blockIndexEmpty = blockIndex;
|
blockOffsetEmpty = blockOffset;
|
blockOffsetEmpty = blockOffset;
|
|
fileOffsetEmpty = directory->fileOffset - sizeof(OS_FileEntry_t);
|
}
|
}
|
}
|
}
|
if(rc == 0 || directory->fileEntry.mediaType == FILE_MEDIA_FLASH ||
|
if(rc == 0 || directory->fileEntry.mediaType == FILE_MEDIA_FLASH ||
|
blockIndexEmpty == BLOCK_EOF)
|
blockIndexEmpty == BLOCK_EOF)
|
{
|
{
|
// Backup to start of fileEntry or last entry in directory
|
// Backup to start of fileEntry or last entry in directory
|
if(directory->blockIndex != blockIndex)
|
if(directory->blockIndex != blockIndex)
|
BlockRead(directory, blockIndex);
|
BlockRead(directory, blockIndex);
|
directory->blockOffset = blockOffset;
|
directory->blockOffset = blockOffset;
|
}
|
}
|
else
|
else if(blockIndexEmpty != BLOCK_EOF)
|
{
|
{
|
// Backup to empty slot
|
// Backup to empty slot
|
if(directory->blockIndex != blockIndexEmpty)
|
if(directory->blockIndex != blockIndexEmpty)
|
BlockRead(directory, blockIndexEmpty);
|
BlockRead(directory, blockIndexEmpty);
|
directory->blockOffset = blockOffsetEmpty;
|
directory->blockOffset = blockOffsetEmpty;
|
|
directory->fileOffset = fileOffsetEmpty;
|
}
|
}
|
return rc;
|
return rc;
|
}
|
}
|
|
|
|
|