I have a custom File system implementation for SD card. See p. no 14-16. The file can be read or written by a microcontroller connected through a SPI interface with the SD card.
I am storing a BMP image in this file system. But the application requires lots of random jumps from one location to another.
I learnt through this answer that, I basically need fseek(). Unfortunately fseek() is not provided in this system. The functions which are available are only:
fcreate, fopen, fread, fwrite, feof, fclose:
Is it possible to implement fseek() or a similar functionality using the available functions? If yes how? If not, is writing low level (reading sectors , etc) code the only solution?
fcreate
Description: Creates a new file with the specified name.
Prototype: static BYTE fcreate (find_info* findinfo, char* filename)
Parameters:
1. findinfo-Pointer to a structure with details about the file.
2. filename-Pointer to a memory location that contains the filename.
Return Value: 1, if the file was created successfully. 0, otherwise.
fopen
Description: Opens a file in one of three modes - Read (r), Write (w), Append (a).
In Write/Append modes, if the specified filename does not exist, it is created.
In Write mode, if the specified file exists, it is overwritten.
Prototype: int fopen (FILE* f, char* filename, char* mode)
Parameters:
1. f-Pointer to file structure
2. filename-Pointer to a memory location that contains the filename.
3. mode-Pointer to a memory location that contains the file open mode.
Return Value: 1, if file was opened successfully. 0, otherwise.
fread
Description: Reads the specified number of bytes from a file.
Prototype: unsigned fread (FILE* f, BYTE* buffer, unsigned count)
Parameters:
1. f-Pointer to file structure
2. buffer-Pointer to a memory locationwhere the data will be copied to.
3. count-The maximum number of bytes to read from the file.
Return Value: Number of bytes read from the file.
fwrite
Description: Writes the specified number of bytes to a file.
Prototype: unsigned fwrite (FILE* f, BYTE* buffer, unsigned count)
Parameters:
1. f-Pointer to file structure
2. buffer-Pointer to a memory location where the data will be copied from.
3. count-The number of bytes to write to the file.
Return Value: Number of bytes written to the file.
feof
Description: Checks whether the specified file's current position pointer has reached the end of the file.
Prototype: int feof (FILE* f)
Parameters:
1. f-Pointer to file structure
Return Value: 0, if the file'scurrent position pointer has not reached the end of the file. 1, if the file's current position pointer has reached the end of the file.
fclose
Description: Closes a file.
Prototype: void fclose (FILE* f)
Parameters: 1. f-Pointer to file structure
Return Value: None.