ringfs
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Data Structures | Functions
RingFS API

Data Structures

struct  ringfs_flash_partition
 Flash memory+parition descriptor. More...
 
struct  ringfs
 RingFS instance. More...
 

Functions

int ringfs_init (struct ringfs *fs, const struct ringfs_flash_partition *flash, uint32_t version, int object_size)
 Initialize a RingFS instance. More...
 
int ringfs_format (struct ringfs *fs)
 Format the flash memory. More...
 
int ringfs_scan (struct ringfs *fs)
 Scan the flash memory for a valid filesystem. More...
 
int ringfs_capacity (struct ringfs *fs)
 Calculate maximum RingFS capacity. More...
 
int ringfs_count_estimate (struct ringfs *fs)
 Calculate approximate object count. More...
 
int ringfs_count_exact (struct ringfs *fs)
 Calculate exact object count. More...
 
int ringfs_append (struct ringfs *fs, const void *object)
 Append an object at the end of the ring. More...
 
int ringfs_fetch (struct ringfs *fs, void *object)
 Fetch next object from the ring, oldest-first. More...
 
int ringfs_discard (struct ringfs *fs)
 Discard all fetched objects up to the read cursor. More...
 
int ringfs_rewind (struct ringfs *fs)
 Rewind the read cursor back to the oldest object. More...
 

Detailed Description


Data Structure Documentation

struct ringfs

RingFS instance.

Should be initialized with ringfs_init() befure use. Structure fields should not be accessed directly.

Definition at line 63 of file ringfs.h.

Data Fields
struct ringfs_loc cursor
const struct
ringfs_flash_partition *
flash
int object_size
struct ringfs_loc read
int slots_per_sector
uint32_t version
struct ringfs_loc write

Function Documentation

int ringfs_append ( struct ringfs fs,
const void *  object 
)

Append an object at the end of the ring.

Deletes oldest objects as needed.

Parameters
fsInitialized RingFS instance.
objectObject to be stored.
Returns
Zero on success, -1 on failure.

Definition at line 310 of file ringfs.c.

int ringfs_capacity ( struct ringfs fs)

Calculate maximum RingFS capacity.

Parameters
fsInitialized RingFS instance.
Returns
Maximum capacity on success, -1 on failure.

Definition at line 278 of file ringfs.c.

int ringfs_count_estimate ( struct ringfs fs)

Calculate approximate object count.

Runs in O(1).

Parameters
fsInitialized RingFS instance.
Returns
Estimated object count on success, -1 on failure.

Definition at line 283 of file ringfs.c.

int ringfs_count_exact ( struct ringfs fs)

Calculate exact object count.

Runs in O(n).

Parameters
fsInitialized RingFS instance.
Returns
Exact object count on success, -1 on failure.

Definition at line 291 of file ringfs.c.

int ringfs_discard ( struct ringfs fs)

Discard all fetched objects up to the read cursor.

Parameters
fsInitialized RingFS instance.
Returns
Zero on success, -1 on failure.

Definition at line 384 of file ringfs.c.

int ringfs_fetch ( struct ringfs fs,
void *  object 
)

Fetch next object from the ring, oldest-first.

Advances read cursor.

Parameters
fsInitialized RingFS instance.
objectBuffer to store retrieved object.
Returns
Zero on success, -1 on failure.

Definition at line 363 of file ringfs.c.

int ringfs_format ( struct ringfs fs)

Format the flash memory.

Parameters
fsInitialized RingFS instance.
Returns
Zero on success, -1 on failure.

Definition at line 153 of file ringfs.c.

int ringfs_init ( struct ringfs fs,
const struct ringfs_flash_partition flash,
uint32_t  version,
int  object_size 
)

Initialize a RingFS instance.

Must be called before the instance can be used with the other ringfs_* functions.

Parameters
fsRingFS instance to be initialized.
flashFlash memory interface. Must be implemented externally.
versionObject version. Should be incremented whenever the object's semantics or size change in a backwards-incompatible way.
object_sizeSize of one stored object, in bytes.
Returns
Zero on success, -1 on failure.

Definition at line 139 of file ringfs.c.

int ringfs_rewind ( struct ringfs fs)

Rewind the read cursor back to the oldest object.

Parameters
fsInitialized RingFS instance.
Returns
Zero on success, -1 on failure.

Definition at line 394 of file ringfs.c.

int ringfs_scan ( struct ringfs fs)

Scan the flash memory for a valid filesystem.

Parameters
fsInitialized RingFS instance.
Returns
Zero on success, -1 on failure.

Definition at line 174 of file ringfs.c.