keil_examples/USBHostLite/UsbHost/Fat/usbhost_fat.c
/*
**************************************************************************************************************
*                                                 FINDING AN ENTRY
*
* Description: This function searches for a file name in the root directory
*
* Arguments  : ent_name_given    Pointer to the file name to be searched.
*              entry             Pointer to the entry structure. The attributes of the file are stored in this
*                                structure if the file was found in the root directory.
*
* Returns    : MATCH_FOUND       if the file was found in the root directory.
*              MATCH_NOT_FOUND   if the file was not found in the root directory.
*
**************************************************************************************************************
*/
FINDING AN ENTRY
Description: This function searches for a file name in the root directory

Arguments  : ent_name_given    Pointer to the file name to be searched.
entry             Pointer to the entry structure. The attributes of the file are stored in this
structure if the file was found in the root directory.

Returns    : MATCH_FOUND       if the file was found in the root directory.
MATCH_NOT_FOUND   if the file was not found in the root directory.
FINDING AN ENTRY Description : This function searches for a file name in the root directory Arguments : ent_name_given Pointer to the file name to be searched . entry Pointer to the entry structure . The attributes of the file are stored in this structure if the file was found in the root directory . Returns : MATCH_FOUND if the file was found in the root directory . MATCH_NOT_FOUND if the file was not found in the root directory .
int32_t  FAT_FindEntry (uint8_t  *ent_name_given,
                           FILE_ENTRY  *entry)
{
              uint32_t   sec_num;
    volatile  uint8_t  *buf;
              uint8_t   ent_type;
              uint8_t   ent_name_read[13];
    for (sec_num = FAT_BootSec.RootDirStartSec;              
         sec_num < (FAT_BootSec.RootDirStartSec + FAT_BootSec.RootDirSec);
         sec_num++) {
        MS_BulkRecv(sec_num, 1, FATBuffer);                  
        buf = FATBuffer;
        while (buf < (FATBuffer + FAT_BootSec.BytsPerSec)) {
            ent_type = FAT_ChkEntType(buf);                  
            if (ent_type == SFN_ENTRY) {                     
                FAT_GetSFN(buf, ent_name_read);
                if (FAT_StrCaseCmp(ent_name_given, ent_name_read) == MATCH_FOUND) {
                    entry->CurrClus = ReadLE16U(&buf[26]);   
                    entry->FileSize  = ReadLE32U(&buf[28]);  
                    entry->EntrySec = sec_num;           
                    entry->EntrySecOffset = buf - FATBuffer;
                    return (MATCH_FOUND);
                }
            }
            if (ent_type == LAST_ENTRY) {    
                return (MATCH_NOT_FOUND);
            }
            buf = buf + 32;                                  
        }
    }
    return (MATCH_NOT_FOUND);
}
int32_t FAT_FindEntry ( uint8_t * ent_name_given , FILE_ENTRY * entry ) { uint32_t sec_num ; volatile uint8_t * buf ; uint8_t ent_type ; uint8_t ent_name_read [ 13 ] ; for ( sec_num = FAT_BootSec . RootDirStartSec ; sec_num < ( FAT_BootSec . RootDirStartSec + FAT_BootSec . RootDirSec ) ; sec_num ++ ) { MS_BulkRecv ( sec_num , 1 , FATBuffer ) ; buf = FATBuffer ; while ( buf < ( FATBuffer + FAT_BootSec . BytsPerSec ) ) { ent_type = FAT_ChkEntType ( buf ) ; if ( ent_type == SFN_ENTRY ) { FAT_GetSFN ( buf , ent_name_read ) ; if ( FAT_StrCaseCmp ( ent_name_given , ent_name_read ) == MATCH_FOUND ) { entry -> CurrClus = ReadLE16U ( & buf [ 26 ] ) ; entry -> FileSize = ReadLE32U ( & buf [ 28 ] ) ; entry -> EntrySec = sec_num ; entry -> EntrySecOffset = buf - FATBuffer ; return ( MATCH_FOUND ) ; } } if ( ent_type == LAST_ENTRY ) { return ( MATCH_NOT_FOUND ) ; } buf = buf + 32 ; } } return ( MATCH_NOT_FOUND ) ; }
FINDING AN ENTRY
Description: This function searches for a file name in the root directory
FINDING AN ENTRY Description : This function searches for a file name in the root directory
/* For all the sectors in root directory       */ /* Read one sector                             */ /* Check for the entry type                    */ /* If it is short entry get short file name    */ /* Compare given name with this name case insensitively */ /* If they are same, get starting cluster      */ /* Get file size                               */ /* Get sector number where the filename is located */ /* Get offset in this sector where the filename is located */ /* If it is the last entry, no more entries will exist. Return */ /* Move to the next entry                      */