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

#include <CFFS.hh>

Collaboration diagram for CFFS:
Collaboration graph

Classes

struct  descr_t
 
class  File
 

Static Public Member Functions

static bool begin (Flash::Device *flash)
 
static int ls (IOStream &outs)
 
static int rm (const char *filename)
 
static int cd (const char *filename)
 
static int mkdir (const char *filename)
 
static int rmdir (const char *filename)
 
static int format (Flash::Device *flash, const char *name)
 

Static Public Attributes

static const size_t FILENAME_MAX = 22
 

Protected Types

enum  {
  CFFS_TYPE = 0xf5cf, FILE_ENTRY_TYPE = 0x8001, FILE_BLOCK_TYPE = 0x8002, DIR_ENTRY_TYPE = 0x8003,
  DIR_BLOCK_TYPE = 0x8004, FREE_TYPE = 0xffff, ALLOC_MASK = 0x8000, TYPE_MASK = 0x7fff
}
 

Static Protected Member Functions

static int read (void *dest, uint32_t src, size_t size)
 
static int write (uint32_t dest, const void *src, size_t size)
 
static int write_P (uint32_t dest, const void *src, size_t size)
 
static int lookup (const char *filename, descr_t &entry, uint32_t &addr)
 
static int create (const char *filename, uint16_t type, uint8_t flags, descr_t &entry, uint32_t &addr)
 
static int remove (uint32_t addr, uint16_t type)
 
static uint32_t next_free_sector ()
 
static uint32_t next_free_directory ()
 
static int find_end_of_file (uint32_t sector, uint32_t &pos, uint32_t &size)
 

Static Protected Attributes

static const uint32_t NULL_REF = 0xffffffffL
 
static const size_t DIR_MAX = 16
 
static Flash::Devicedevice = NULL
 
static uint32_t current_dir_addr = 0L
 

Friends

class File
 

Detailed Description

Cosa Flash File System for Flash Memory.

Limitations

Directory entries are not reclaimed (directory block is not erased and rewritten when full).

Definition at line 35 of file CFFS.hh.

Member Enumeration Documentation

anonymous enum
protected

CFFS object types:

CFFS_TYPE is the file system master block on the device. It is the first object on the flash; size is the size of the header, ref is the address of the root directory (the next object), and the name of the device.

FILE_ENTRY_TYPE is a file descriptor; size is not used, ref is the address of the first file block, name is the name of the file.

FILE_BLOCK_TYPE is a file block; size is the block size (typically sector size), ref is the address of the next block, name is not used (filled with zero).

DIR_ENTRY_TYPE is a directory reference; size is not used, ref is the address of the directory block, name is the name of the directory.

DIR_BLOCK_TYPE is directory block header; size is the directory sector, ref is the address to the next directory block (NULL is encoded as 0xffffffffL, NULL_REF)

Enumerator
CFFS_TYPE 

File System Master header.

FILE_ENTRY_TYPE 

File descriptor entry.

FILE_BLOCK_TYPE 

File data block.

DIR_ENTRY_TYPE 

Directory reference entry.

DIR_BLOCK_TYPE 

Directory block.

FREE_TYPE 

Free descriptor.

ALLOC_MASK 

Allocated mask.

TYPE_MASK 

Type mask.

Definition at line 74 of file CFFS.hh.

Member Function Documentation

bool CFFS::begin ( Flash::Device flash)
static

Mount a CFFS volume on the given flash device. Return true if successful otherwise false.

Parameters
[in]flashdevice to mount.
Returns
bool.

Definition at line 228 of file CFFS.cpp.

int CFFS::cd ( const char *  filename)
static

Change current directory to the given filename in the current directory. Return zero(0) if successful otherwise a negative error code (EPREM, EIO, ENOENT, ENOTDIR).

Parameters
[in]filenamedirectory to change to.
Returns
zero or negative error code.

Definition at line 293 of file CFFS.cpp.

int CFFS::create ( const char *  filename,
uint16_t  type,
uint8_t  flags,
descr_t entry,
uint32_t &  addr 
)
staticprotected

Create directory entry with given file name and type. The flags (O_EXCL) may be used to fail if the file already exists. The type must be DIR_TYPE or FILE_TYPE. Returns zero and entry otherwise negative error code.

Parameters
[in]filenameto create.
[in]typeof entry to create.
[in]flagsopen flags to check.
[out]entrysetting.
[out]addraddress of entry.
Returns
zero and entry otherwise negative error code.

Definition at line 391 of file CFFS.cpp.

int CFFS::find_end_of_file ( uint32_t  sector,
uint32_t &  pos,
uint32_t &  size 
)
staticprotected

Find address and size of file that starts with the given sector. Return zero(0) if successful otherwise a negative error code.

Parameters
[in]sectoraddress of sector.
[out]posaddress of end of file.
[out]sizeof file.
Returns
zero or negative error code.

Definition at line 570 of file CFFS.cpp.

int CFFS::format ( Flash::Device flash,
const char *  name 
)
static

Format the flash. Create a CFFS volume with root directory. Returns zero(0) if successful otherwise a negative error code (EPERM, ENAMETOOLONG, EIO).

Parameters
[in]flashdevice to mount.
[in]nameof file system.
Returns
zero or negative error code.

Definition at line 322 of file CFFS.cpp.

int CFFS::lookup ( const char *  filename,
descr_t entry,
uint32_t &  addr 
)
staticprotected

Lookup directory entry with the given file name. Return zero and entry if found otherwise negative error code.

Parameters
[in]filenameto lookup.
[out]entrysetting.
[out]addrentry address.
Returns
zero and entry setting otherwise negative error code.

Definition at line 366 of file CFFS.cpp.

int CFFS::ls ( IOStream outs)
static

List directory contents to given iostream. Return zero(0) if successful otherwise a negative error code (EPERM, EIO).

Parameters
[in]outsoutput stream.
Returns
zero or negative error code.

Definition at line 253 of file CFFS.cpp.

int CFFS::mkdir ( const char *  filename)
static

Create a directory with the given filename in the current directory. Return zero(0) if successful otherwise a negative error code (EPERM, EIO, EEXIST).

Parameters
[in]filenamedirectory to create.
Returns
zero or negative error code.

Definition at line 307 of file CFFS.cpp.

uint32_t CFFS::next_free_directory ( )
staticprotected

Allocate next free directory. Returns directory address or zero.

Returns
directory address or zero.

Definition at line 531 of file CFFS.cpp.

uint32_t CFFS::next_free_sector ( )
staticprotected

Allocate next free sector. Returns sector address or zero.

Returns
sector address or zero.

Definition at line 502 of file CFFS.cpp.

int CFFS::read ( void *  dest,
uint32_t  src,
size_t  size 
)
staticprotected

Read flash block with the given size into the buffer from the source address. Return number of bytes read or negative error code.

Parameters
[in]destbuffer to read from flash into.
[in]srcaddress in flash to read from.
[in]sizenumber of bytes to read.
Returns
number of bytes or negative error code.

Definition at line 475 of file CFFS.cpp.

int CFFS::remove ( uint32_t  addr,
uint16_t  type 
)
staticprotected

Remove directory entry. Returns zero(0) if successful otherwise a negative error code.

Parameters
[in]addrentry address.
[in]typeentry type.
Returns
zero or negative error code.

Definition at line 444 of file CFFS.cpp.

int CFFS::rm ( const char *  filename)
static

Remove a file. The directory entry and all data for the file is deleted. Return zero(0) if successful otherwise a negative error code (EPREM, EIO, ENOENT, ENFILE, EINVAL).

Parameters
[in]filenameto remove.
Returns
zero or negative error code.

Definition at line 285 of file CFFS.cpp.

int CFFS::rmdir ( const char *  filename)
static

Remove directory with the given filename in the current directory. Return zero(0) if successful otherwise a negative error code (ENOSYS).

Parameters
[in]filenamedirectory to remove.
Returns
zero or negative error code.

Definition at line 315 of file CFFS.cpp.

int CFFS::write ( uint32_t  dest,
const void *  src,
size_t  size 
)
staticprotected

Write flash block at given destination address with the contents of the source buffer. Return number of bytes written or negative error code.

Parameters
[in]destaddress in flash to write to.
[in]srcbuffer to write to flash.
[in]sizenumber of bytes to write.
Returns
number of bytes or negative error code.

Definition at line 484 of file CFFS.cpp.

int CFFS::write_P ( uint32_t  dest,
const void *  src,
size_t  size 
)
staticprotected

Write flash block at given destination address with contents of the source buffer in program memory. Return number of bytes written or negative error code.

Parameters
[in]destaddress in flash to write to.
[in]srcbuffer in program memory to write to flash.
[in]sizenumber of bytes to write.
Returns
number of bytes written or EOF(-1).

Definition at line 493 of file CFFS.cpp.

Friends And Related Function Documentation

friend class File
friend

Definition at line 313 of file CFFS.hh.

Member Data Documentation

uint32_t CFFS::current_dir_addr = 0L
staticprotected

Current directory address.

Definition at line 323 of file CFFS.hh.

Flash::Device * CFFS::device = NULL
staticprotected

Current flash device (singleton).

Definition at line 320 of file CFFS.hh.

const size_t CFFS::DIR_MAX = 16
staticprotected

Number of directory sectors.

Definition at line 317 of file CFFS.hh.

const size_t CFFS::FILENAME_MAX = 22
static

Max size of file/drive name.

Definition at line 38 of file CFFS.hh.

const uint32_t CFFS::NULL_REF = 0xffffffffL
staticprotected

CFFS null address in flash data structures.

Definition at line 88 of file CFFS.hh.


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