23 #define debug_printf(x, ...)
39 extern const uint32_t RFS_fileCount;
40 extern const uint8_t *RFS_fileNames[];
41 extern const uint32_t RFS_fileLength[];
42 extern const uint8_t *RFS_fileData[];
61 uint32_t RFS_getFileCount(
void )
79 int32_t RFS_getFileLengthByIndex( uint32_t index )
82 if( index >= RFS_fileCount ) {
87 return RFS_fileLength[index];
102 int32_t RFS_getFileLength( RFS_FileHandle *fileHandle )
105 return RFS_getFileLengthByIndex( fileHandle->fileIndex );
121 uint8_t *RFS_getFileNameByIndex( uint32_t index )
124 if( index >= RFS_fileCount ) {
128 return (uint8_t *) RFS_fileNames[index];
144 uint8_t *RFS_getFileName( RFS_FileHandle *fileHandle )
147 return RFS_getFileNameByIndex( fileHandle->fileIndex );
162 int16_t RFS_getFileIndex( uint8_t name[] )
169 for( i = 0; i < RFS_getFileCount(); i++ ) {
172 if( strncmp( (
char const*) name, (
char const *) RFS_getFileNameByIndex( i ), RFS_MAX_FILE_NAME_SIZE ) == 0 ) {
197 int32_t RFS_fileOpen( RFS_FileHandle *fileHandle, uint8_t name[] )
202 index = RFS_getFileIndex( name );
206 fileHandle->fileIndex = index;
207 fileHandle->currentIndex = 0;
234 int32_t RFS_fileSeek( RFS_FileHandle *fileHandle, int32_t offset, uint32_t whence )
241 if( whence == RFS_SEEK_SET ) {
242 fileHandle->currentIndex = offset;
245 else if( whence == RFS_SEEK_CUR ) {
246 fileHandle->currentIndex += offset;
249 else if( whence == RFS_SEEK_END ) {
250 fileHandle->currentIndex = ( RFS_getFileLengthByIndex( fileHandle->fileIndex ) + offset );
259 return fileHandle->currentIndex;
282 int32_t RFS_fileRead( uint8_t *buf, uint32_t size, uint32_t nmemb, RFS_FileHandle *fileHandle )
286 int32_t fileIndex = -1;
288 uint32_t totalByteCount;
289 uint8_t *src = (uint8_t *) -1, *dst = (uint8_t *) -1, *end = (uint8_t *) -1;
292 fileIndex = fileHandle->fileIndex;
293 debug_printf(
"RFS_fileRead(): fileIndex = %d \n", fileIndex );
295 if( fileIndex < 0 ) {
299 if( fileIndex >= RFS_getFileCount() ) {
304 byteIndex = fileHandle->currentIndex;
306 src = (
unsigned char *) RFS_fileData[fileIndex];
309 debug_printf(
" endindex = %d\n", RFS_getFileLengthByIndex(fileIndex) );
311 end = (
unsigned char *) RFS_fileData[fileIndex];
312 end += RFS_getFileLengthByIndex( fileIndex ) - 1;
314 dst = (uint8_t *) buf;
315 debug_printf(
"RFS_fileRead(): byteIndex = %d src = %08Xh end = %08Xh dst = %08Xh \n",
316 byteIndex, src, end, dst );
318 totalByteCount = size * nmemb;
320 for( i = 0; ( i < totalByteCount ) && ( src <= end ); i++ )
323 debug_printf(
"RFS_fileRead(): Bytes copied: %d [%d]\n", i, totalByteCount );
325 fileHandle->currentIndex += i;
342 uint8_t *RFS_fileGetRawData( RFS_FileHandle *fileHandle )
345 int32_t fileIndex = -1;
348 fileIndex = fileHandle->fileIndex;
351 if( fileIndex >= RFS_getFileCount() )
354 return (
unsigned char *) RFS_fileData[fileIndex];