COSA
An Object-Oriented Platform for Arduino Programming
CFFS::File Class Reference

#include <CFFS.hh>

Inheritance diagram for CFFS::File:
Inheritance graph
Collaboration diagram for CFFS::File:
Collaboration graph

Public Member Functions

 File ()
 
int open (const char *filename, uint8_t oflag=O_READ)
 
bool is_open (void) const
 
int remove ()
 
int close ()
 
int seek (uint32_t pos, uint8_t whence=SEEK_SET)
 
uint32_t tell ()
 
int rewind ()
 
uint32_t size ()
 
virtual int write (const void *buf, size_t size)
 
virtual int write_P (const void *buf, size_t size)
 
virtual int getchar ()
 
virtual int read (void *buf, size_t size)
 
void non_blocking ()
 
void blocking ()
 
bool is_blocking () const
 
void eol (Mode mode)
 
Mode eol () const
 
virtual int available ()
 
virtual int room ()
 
virtual int putchar (char c)
 
virtual int puts (const char *s)
 
virtual int puts (str_P s)
 
virtual int write (const iovec_t *vec)
 
virtual int peekchar ()
 
virtual int peekchar (char c)
 
virtual char * gets (char *s, size_t count)
 
virtual int read (iovec_t *vec)
 
virtual int flush ()
 
virtual void empty ()
 

Protected Member Functions

int write (const void *buf, size_t size, bool progmem)
 

Protected Attributes

uint8_t m_flags
 File open flags. More...
 
uint32_t m_entry_addr
 Entry address. More...
 
CFFS::descr_t m_entry
 Cached directory entry. More...
 
CFFS::descr_t m_sector
 Cached sector header. More...
 
uint32_t m_file_size
 File size. More...
 
uint32_t m_current_addr
 Current flash address. More...
 
uint32_t m_current_pos
 Current logical position. More...
 
bool m_blocking
 
Mode m_eol
 

Detailed Description

Flash File access class. Support for directories, hard links, text and binary files. The end of the file is not store in the directory entry, instead it is located when the file is opened. This is done by searching for the first non-0xff value from the end of the last file sector. Text files may not use the value (0xff). Binary files must end each entry with non-0xff entry. Write should always be in append mode as the file cannot be rewritten with any value.

Definition at line 101 of file CFFS.hh.

Constructor & Destructor Documentation

CFFS::File::File ( )
inline

Construct file access instance. Call open() before any read/write operations are possible.

Definition at line 107 of file CFFS.hh.

Member Function Documentation

int IOStream::Device::available ( )
virtualinherited

Number of bytes available (possible to read).

Returns
bytes.

Reimplemented in W5200::Driver, W5500::Driver, W5100::Driver, Soft::UART, UART, IOBuffer< SIZE >, and CC3000::Driver.

Definition at line 24 of file IOStream_Device.cpp.

void IOStream::Device::blocking ( )
inlineinherited

Set blocking mode.

Definition at line 85 of file IOStream.hh.

int CFFS::File::close ( )

Close a file. Return zero(0) if successful otherwise a negative error code (EPREM).

Returns
zero or negative error code.

Definition at line 72 of file CFFS.cpp.

void IOStream::Device::empty ( )
virtualinherited

Empty internal device buffers.

Reimplemented in Soft::UART, UART, and IOBuffer< SIZE >.

Definition at line 175 of file IOStream_Device.cpp.

void IOStream::Device::eol ( Mode  mode)
inlineinherited

Set end of line mode.

Parameters
[in]modefor end of line.

Definition at line 103 of file IOStream.hh.

Mode IOStream::Device::eol ( ) const
inlineinherited

Get end of line mode.

Returns
mode.

Definition at line 112 of file IOStream.hh.

int IOStream::Device::flush ( )
virtualinherited

Flush internal device buffers. Wait for device to become idle.

Returns
zero(0) or negative error code.

Reimplemented in W5200::Driver, W5500::Driver, W5100::Driver, UART, IOBuffer< SIZE >, CC3000::Driver, and WIO.

Definition at line 169 of file IOStream_Device.cpp.

int CFFS::File::getchar ( )
virtual

Read character/byte from the file. If successful returns character read or negative error code (EPREM, EFAULT, ENOSPC, EIO, ENXIO).

Returns
character or negative error code.

Reimplemented from IOStream::Device.

Definition at line 134 of file CFFS.cpp.

char * IOStream::Device::gets ( char *  s,
size_t  count 
)
virtualinherited

Read string terminated by new-line or until size into given string buffer. Returns pointer to string or NULL if empty line.

Parameters
[in]sstring buffer to read into.
[in]countmax number of bytes to read.
Returns
string pointer or NULL.

Definition at line 118 of file IOStream_Device.cpp.

bool IOStream::Device::is_blocking ( ) const
inlineinherited

Is blocking mode?

Returns
bool.

Definition at line 94 of file IOStream.hh.

bool CFFS::File::is_open ( void  ) const
inline

Checks the file's open/closed status. Return true if open otherwise false.

Returns
bool.

Definition at line 124 of file CFFS.hh.

void IOStream::Device::non_blocking ( )
inlineinherited

Set non-blocking mode.

Definition at line 77 of file IOStream.hh.

int CFFS::File::open ( const char *  filename,
uint8_t  oflag = O_READ 
)

Open a file by name and mode flags. Returns zero(0) if successful otherwise a negative error code (EBUSY, EPERM, EINVAL, ENAMETOOLONG, EIO, EEXIST, ENFILE, ENOSPC).

Parameters
[in]filenameof file to open.
[in]oflagmode of file open.
Returns
zero or negative error code.

Definition at line 27 of file CFFS.cpp.

int IOStream::Device::peekchar ( )
virtualinherited

Peek at the next character from device.

Returns
character or EOF(-1).

Reimplemented in Soft::UART, UART, and IOBuffer< SIZE >.

Definition at line 99 of file IOStream_Device.cpp.

int IOStream::Device::peekchar ( char  c)
virtualinherited

Peek for the given character in device buffer. Return number of characters or EOF(-1).

Parameters
[in]ccharacter to peek for.
Returns
available or EOF(-1).

Reimplemented in Soft::UART, UART, and IOBuffer< SIZE >.

Definition at line 105 of file IOStream_Device.cpp.

int IOStream::Device::putchar ( char  c)
virtualinherited

Write character to device.

Parameters
[in]ccharacter to write.
Returns
character written or EOF(-1).

Reimplemented in FAT16::File, HD44780, ST7565, PCD8544, MAX72XX, VLCD, UART, Textbox, IOBuffer< SIZE >, RS485, WIO, and Soft::UAT.

Definition at line 36 of file IOStream_Device.cpp.

int IOStream::Device::puts ( const char *  s)
virtualinherited

Write null terminated string to device. Terminating null is not written.

Parameters
[in]sstring to write.
Returns
zero(0) or negative error code.

Definition at line 43 of file IOStream_Device.cpp.

int IOStream::Device::puts ( str_P  s)
virtualinherited

Write null terminated string from program memory to device. Terminating null is not written.

Parameters
[in]sstring in program memory to write.
Returns
zero(0) or negative error code.

Definition at line 54 of file IOStream_Device.cpp.

int CFFS::File::read ( void *  buf,
size_t  size 
)
virtual

Read data to given buffer with given size from the file. If successful returns number of bytes read or negative error code (EPERM, EIO, ENXIO).

Parameters
[in]bufbuffer to read into.
[in]sizenumber of bytes to read.
Returns
number of bytes read or negative error code.

Reimplemented from IOStream::Device.

Definition at line 142 of file CFFS.cpp.

int IOStream::Device::read ( iovec_t vec)
virtualinherited

Read data to given buffers in null terminated io vector.

Parameters
[in]vecio vector with buffers to read into.
Returns
number of bytes read or EOF(-1).

Definition at line 157 of file IOStream_Device.cpp.

int CFFS::File::remove ( )

Remove a file. The directory entry and all data for the file are deleted. Returns zero(0) if succesful otherwise a negative error code (EPREM, EIO, ENOENT).

Returns
zero or negative error code.

Definition at line 64 of file CFFS.cpp.

int CFFS::File::rewind ( )
inline

Rewind to the start of the file. Return zero(0) if successful otherwise a negative error code (EPERM, EINVAL,EIO, ENXIO).

Returns
zero or negative error code.

Definition at line 168 of file CFFS.hh.

int IOStream::Device::room ( )
virtualinherited

Number of bytes room (write without blocking).

Returns
bytes.

Reimplemented in W5200::Driver, W5500::Driver, W5100::Driver, UART, IOBuffer< SIZE >, CC3000::Driver, and WIO.

Definition at line 30 of file IOStream_Device.cpp.

int CFFS::File::seek ( uint32_t  pos,
uint8_t  whence = SEEK_SET 
)

Sets the file's read position relative to mode. Return zero(0) if successful otherwise a negative error code (EPERM, EINVAL, EIO, ENXIO).

Parameters
[in]posnew position in bytes from given mode.
[in]modeabsolute, relative and from end.
Returns
zero or negative error code.

Definition at line 80 of file CFFS.cpp.

uint32_t CFFS::File::size ( )
inline

Return number of bytes in file.

Returns
size.

Definition at line 177 of file CFFS.hh.

uint32_t CFFS::File::tell ( )
inline

Return current position.

Returns
position.

Definition at line 158 of file CFFS.hh.

int IOStream::Device::write ( const iovec_t vec)
virtualinherited

Write data from buffers in null terminated io vector.

Parameters
[in]vecio vector with buffers to write.
Returns
number of bytes written or EOF(-1).

Definition at line 87 of file IOStream_Device.cpp.

int CFFS::File::write ( const void *  buf,
size_t  size 
)
virtual

Write data from buffer with given size to the file. If successful returns number of bytes written or negative error code (EPREM, EFAULT, ENOSPC, EIO, ENXIO).

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or negative error code.

Reimplemented from IOStream::Device.

Definition at line 122 of file CFFS.cpp.

int CFFS::File::write ( const void *  buf,
size_t  size,
bool  progmem 
)
protected

Write data from buffer in data or program memory with given size to the file. If successful returns number of bytes written or negative error code.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
[in]progmemfrom data(false) or program memory(true).
Returns
number of bytes written or negative error code.

Definition at line 178 of file CFFS.cpp.

int CFFS::File::write_P ( const void *  buf,
size_t  size 
)
virtual

Write data from buffer in program memory with given size to the file. If successful returns number of bytes written or negative error (EPREM, EFAULT, ENOSPC, EIO, ENXIO).

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or negative error code.

Reimplemented from IOStream::Device.

Definition at line 128 of file CFFS.cpp.

Member Data Documentation

bool IOStream::Device::m_blocking
protectedinherited

Blocking state

Definition at line 248 of file IOStream.hh.

uint32_t CFFS::File::m_current_addr
protected

Current flash address.

Definition at line 235 of file CFFS.hh.

uint32_t CFFS::File::m_current_pos
protected

Current logical position.

Definition at line 236 of file CFFS.hh.

CFFS::descr_t CFFS::File::m_entry
protected

Cached directory entry.

Definition at line 232 of file CFFS.hh.

uint32_t CFFS::File::m_entry_addr
protected

Entry address.

Definition at line 231 of file CFFS.hh.

Mode IOStream::Device::m_eol
protectedinherited

End of line mode

Definition at line 251 of file IOStream.hh.

uint32_t CFFS::File::m_file_size
protected

File size.

Definition at line 234 of file CFFS.hh.

uint8_t CFFS::File::m_flags
protected

File open flags.

Definition at line 230 of file CFFS.hh.

CFFS::descr_t CFFS::File::m_sector
protected

Cached sector header.

Definition at line 233 of file CFFS.hh.


The documentation for this class was generated from the following files: