Ejemplo n.º 1
0
// File Access
FAT_FILE_HANDLE Fat_FileOpen(FAT_HANDLE Fat, const char *pFilename){
    bool bFind = FALSE;
    FAT_BROWSE_HANDLE hBrowse;     
    FILE_CONTEXT FileContext;
    FAT_FILE_INFO *pFile = 0;
    
    if (Fat_FileBrowseBegin(Fat, &hBrowse)){
        while (!bFind && Fat_FileBrowseNext(&hBrowse, &FileContext)){
            if (FileContext.bLongFilename){
                bFind = fatSameLongFilename((alt_u16 *)FileContext.szName, (alt_u16 *)pFilename);
            }else{
                if (strcmpi(FileContext.szName, pFilename) == 0)
                    bFind = TRUE;
            }    
        } // while 
        
        if (bFind){
            pFile = malloc(sizeof(FAT_FILE_INFO));
            if (pFile){
                pFile->OpenAttribute = FILE_OPEN_READ; 
                pFile->SeekPos = 0;
                pFile->Directory = FileContext;
                pFile->IsOpened = TRUE;
                pFile->Cluster = FileContext.FirstLogicalCluster;
                pFile->ClusterSeq = 0;
                pFile->Fat = Fat;
            }    
        }    
    }  

    
    return (FAT_FILE_HANDLE)pFile;  
}
Ejemplo n.º 2
0
bool Fat_FileExist(FAT_HANDLE Fat, const char *pFilename){
    bool bFind = FALSE;
    FAT_BROWSE_HANDLE hBrowse;     
    FILE_CONTEXT FileContext;
    if (Fat_FileBrowseBegin(Fat, &hBrowse)){
        while (!bFind && Fat_FileBrowseNext(&hBrowse, &FileContext)){
            if (FileContext.bLongFilename){
                bFind = fatSameLongFilename((alt_u16 *)FileContext.szName, (alt_u16 *)pFilename);
            }else{
                if (strcmpi(FileContext.szName, pFilename) == 0)
                    bFind = TRUE;
            }    
        } // while 
        Fat_FileClose(Fat); 
    }
    return bFind;            
}