mFS file system library for EEPROM memory chips.

Embed: (wiki syntax)

« Back to documentation index

file Class Reference

file Class Reference

mFS File handle class More...

#include <mfs.h>

Public Member Functions

 file (mfs *fs_ref, char filename[20], FileOpenMode operation)
 Create file handle.
 ~file ()
 Close file handle.
void rewind ()
 Rewind to the start postion of the file.
char rewind (uint32_t n)
 Reverse n bytes back.
char forward ()
 Forward one byte.
char forward (uint32_t n)
 Forward n bytes.
char seek (uint32_t byte)
 Seek to byte given.
void read (char *data, uint32_t n)
 Reads a string of bytes.
void readBin (char *data, uint32_t n)
 Reads a binary array of bytes.
char write (char *data, uint32_t n)
 Write byte array to a file (buffer)
char flush ()
 Flush file buffer Writes buffer to the EEPROM chip in use.

Detailed Description

mFS File handle class

This class provides a file handle and data manipulation methods to be used for files stored in mFS files system.

Definition at line 223 of file mfs.h.


Constructor & Destructor Documentation

file ( mfs fs_ref,
char  filename[20],
FileOpenMode  operation 
)

Create file handle.

Warning:
File must be created before it can be opened! Opening non-existing file will trip the system to error(); If read only file is opened in rw mode system will trip to error().

AWRITE is a file access mode where cursor can be moved along the file and write can be started at any point. write() function will overwrite only as many bytes as you chosen to write.

DWRITE is a file access mode similiar to AWRITE but when you start writing all the data after cursor will be removed permanently and flush() will set a new EOF marker.

Parameters:
filename[20]Filename input.
operationRO = Read only, AWRITE = read and write, DWRITE = read + destructive write.

Definition at line 289 of file mfs.cpp.

~file (  )

Close file handle.

Flushes the file and closes the handle.

Definition at line 320 of file mfs.cpp.


Member Function Documentation

char flush (  )

Flush file buffer Writes buffer to the EEPROM chip in use.

Returns:
Error code: 0 = OK, 1 = Out of free space, 2 = Destructive operation failed (fs is corrupted).

Definition at line 567 of file mfs.cpp.

char forward (  )

Forward one byte.

Returns:
Error code: 0 = OK, 1 = End of file.

Definition at line 418 of file mfs.cpp.

char forward ( uint32_t  n )

Forward n bytes.

Parameters:
nNumber of blocks.
Returns:
Error code: 0 = OK, 1 = End of file.

Definition at line 423 of file mfs.cpp.

void read ( char *  data,
uint32_t  n 
)

Reads a string of bytes.

Always places '\0' at the end of string.

Parameters:
dataOutput buffer.
nNumber of bytes to be read.
Returns:
Error code. 0 = OK, 1 = Last block of the file

Definition at line 478 of file mfs.cpp.

void readBin ( char *  data,
uint32_t  n 
)

Reads a binary array of bytes.

Doesn't add '\0' at the end of data array and doesn't respect mEOF byte.

Parameters:
dataOutput buffer.
nNumber of bytes to be read.

Definition at line 517 of file mfs.cpp.

char rewind ( uint32_t  n )

Reverse n bytes back.

Parameters:
nNumber of bytes.
Returns:
Error code: 0 = OK, 1 = First byte of file.

Definition at line 382 of file mfs.cpp.

void rewind (  )

Rewind to the start postion of the file.

Definition at line 374 of file mfs.cpp.

char seek ( uint32_t  byte )

Seek to byte given.

Parameters:
byteByte number where to seek.
Returns:
Error code: 0 = OK, 1 = End of file or already at first byte.

Definition at line 468 of file mfs.cpp.

char write ( char *  data,
uint32_t  n 
)

Write byte array to a file (buffer)

Parameters:
dataInput data.
nNumber of bytes to be read.
Returns:
Error code: 0 = OK, 1 = Flush failed.

Definition at line 546 of file mfs.cpp.