keil_examples/USBHostLite/UsbHost/Fat/usbhost_fat.c
/*
**************************************************************************************************************
*                                                OPENING A FILE
*
* Description: This function stores the attributes of a file, such as starting cluster, file size, 
*              sector where the file entry is stored and offset of the entry in that sector
*
* Arguments  : file_name    Name of the file. The file must be in root directory.
*
* Returns    : pointer to the entry    On Success
*              NULL                    On Failure
* 
* Modifed 6/9/08 WCB returns a file descriptor which is the INDEX+1 to the entry.
* returning the entry address itself could be interpreted as a negative number --
* and thus an error -- for memory locations of 0x80000000 and above.  We return
* INDEX+1 instead of just the index to avoid returning a file descriptor of zero,
* which could be potentially confused with an error.
*
**************************************************************************************************************
*/
OPENING A FILE
Description: This function stores the attributes of a file, such as starting cluster, file size,
sector where the file entry is stored and offset of the entry in that sector

Arguments  : file_name    Name of the file. The file must be in root directory.

Returns    : pointer to the entry    On Success
NULL                    On Failure

Modifed 6/9/08 WCB returns a file descriptor which is the INDEX+1 to the entry.
returning the entry address itself could be interpreted as a negative number
and thus an error -- for memory locations of 0x80000000 and above.  We return
INDEX+1 instead of just the index to avoid returning a file descriptor of zero,
which could be potentially confused with an error.
OPENING A FILE Description : This function stores the attributes of a file such as starting cluster file size sector where the file entry is stored and offset of the entry in that sector Arguments : file_name Name of the file . The file must be in root directory . Returns : pointer to the entry On Success NULL On Failure Modifed 6 / 9 / 08 WCB returns a file descriptor which is the INDEX + 1 to the entry . returning the entry address itself could be interpreted as a negative number and thus an error -- for memory locations of 0x80000000 and above . We return INDEX + 1 instead of just the index to avoid returning a file descriptor of zero which could be potentially confused with an error .
int32_t  FILE_Open (uint8_t  *file_name,
                       uint8_t   flags)
{
    int32_t   rc;
    FILE_ENTRY  *entry = 0;
    int32_t  fd = -1;
    do {
    	if (FAT_FileEntry[++fd].FileStatus == 0)
    		entry = &FAT_FileEntry[fd];
    } while ((entry == 0) && (fd < MAX_FILE_DESCRIPTORS-1));
    if (entry == 0) {
        return (ERR_OPEN_LIMIT_REACHED);
    }
    if (flags == RDONLY) {                       
        rc = FAT_FindEntry(file_name, entry);
        if (rc == MATCH_FOUND) {
            entry->FileStatus = 1;
            rc = fd+1;
        }
    } else {                                     
        rc = FAT_CreateEntry(file_name, entry);
        if (rc == MATCH_FOUND) {
            entry->FileStatus = 1;
            rc = fd+1;
        }
    }
    return (rc);
}
int32_t FILE_Open ( uint8_t * file_name , uint8_t flags ) { int32_t rc ; FILE_ENTRY * entry = 0 ; int32_t fd = -1 ; do { if ( FAT_FileEntry [ ++ fd ] . FileStatus == 0 ) entry = & FAT_FileEntry [ fd ] ; } while ( ( entry == 0 ) && ( fd < MAX_FILE_DESCRIPTORS - 1 ) ) ; if ( entry == 0 ) { return ( ERR_OPEN_LIMIT_REACHED ) ; } if ( flags == RDONLY ) { rc = FAT_FindEntry ( file_name , entry ) ; if ( rc == MATCH_FOUND ) { entry -> FileStatus = 1 ; rc = fd + 1 ; } } else { rc = FAT_CreateEntry ( file_name , entry ) ; if ( rc == MATCH_FOUND ) { entry -> FileStatus = 1 ; rc = fd + 1 ; } } return ( rc ) ; }
OPENING A FILE
Description: This function stores the attributes of a file, such as starting cluster, file size,
sector where the file entry is stored and offset of the entry in that sector
OPENING A FILE Description : This function stores the attributes of a file such as starting cluster file size sector where the file entry is stored and offset of the entry in that sector
/* Search for a file. If it doesn't exist, don't create it */ /* Search for a file. If it doesn't exist, create it       */