libjf API reference guide

Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

jf_cache_file.c File Reference

#include <jf/jf_config.h>
#include <jf/jf_errors.h>
#include <jf/jf_utils.h>
#include <jf/jf_cache_file.h>
#include <jf/jf_trace.h>

Go to the source code of this file.

Defines

#define JF_TRACE_MODULE   JF_TRACE_MOD_LIB_CACHE_FILE

Functions

int jf_cache_file_check_bytes (const jf_cache_file_t *cf)
int jf_cache_file_chunk_prepare (jf_cache_file_t *cf, const struct jf_cache_file_range_s *range)
int jf_cache_file_chunk_set_content (jf_cache_file_t *cf, jf_offset_t chunk, size_t size, size_t offset, const byte_t *content)
int jf_cache_file_clear (jf_cache_file_t *cf)
void jf_cache_file_destroy (jf_cache_file_t *cf)
int jf_cache_file_get_free_ranges (const jf_cache_file_t *cf, const struct jf_cache_file_range_s *range, size_t *size, struct jf_cache_file_range_s **array)
int jf_cache_file_get_used_ranges (const jf_cache_file_t *cf, const struct jf_cache_file_range_s *range, size_t *size, struct jf_cache_file_range_s **array)
int jf_cache_file_init (jf_cache_file_t *cf, jf_offset_t last_pos, jf_offset_t limit)
int jf_cache_file_merge (jf_cache_file_t *cf, jf_offset_t first, jf_offset_t last)
int jf_cache_file_resize (jf_cache_file_t *cf, jf_offset_t new_last_pos)
int jf_cache_file_search_hint (const jf_cache_file_t *cf, jf_offset_t value, jf_offset_t *pos, jf_offset_t hint)
int jf_cache_file_set_content (jf_cache_file_t *cf, jf_offset_t pos, size_t size, const byte_t *content)
int jf_cache_file_split (jf_cache_file_t *cf, jf_offset_t pos, const struct jf_cache_file_range_s *range)
int jf_cache_file_trace (const jf_cache_file_t *cf, FILE *out_stream)


Define Documentation

#define JF_TRACE_MODULE   JF_TRACE_MOD_LIB_CACHE_FILE
 

Definition at line 42 of file jf_cache_file.c.


Function Documentation

int jf_cache_file_check_bytes const jf_cache_file_t cf  ) 
 

Check the value of the "bytes" property against real allocated bytes; this is a _DEBUG method should be used only when checking code

Parameters:
cf IN cache file object
Returns:
a boolean value: TRUE if "bytes" is OK, FALSE if "bytes" is not aligned to cache file object content
Definition at line 1250 of file jf_cache_file.c.

References TRUE.

int jf_cache_file_chunk_prepare jf_cache_file_t cf,
const struct jf_cache_file_range_s range
 

Prepare a logical chunk for usage: this is a mix of jf_cache_file_merge and jf_cache_file_split; it MUST be used BEFORE every cache file update (see jf_cache_file_chunk_set_content)

Parameters:
cf IN/OUT cache file object
range IN range of (cache) file positions are going to be updated
Returns:
a reason code
Definition at line 851 of file jf_cache_file.c.

References jf_cache_file_t::array, jf_cache_file_t::bytes, CATCH, jf_cache_file_elem_s::data, FALSE, jf_cache_file_range_s::first, jf_cache_file_is_empty(), jf_cache_file_is_safe(), jf_cache_file_merge(), jf_cache_file_search(), jf_cache_file_search_hint(), jf_cache_file_split(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_MALLOC_ERROR, JF_RC_OBJ_CORRUPTED, JF_RC_OBJ_NOT_INITIALIZED, JF_RC_OK, JF_RC_OUT_OF_RANGE, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, jf_cache_file_t::size, THROW, and TRUE.

Referenced by jf_cache_file_set_content().

int jf_cache_file_chunk_set_content jf_cache_file_t cf,
jf_offset_t  chunk,
size_t  size,
size_t  offset,
const byte_t content
 

Set the content of a chunk

Parameters:
cf IN/OUT cache file object
chunk IN chunk cache position as returned by jf_cache_file_search
size IN number of bytes must be stored in chunk
offset IN storage displacement (0 if the content must be filled in starting at first byte)
content IN data must be copied in chunk
Returns:
a reason code
Definition at line 1191 of file jf_cache_file.c.

References jf_cache_file_t::array, byte_t, jf_cache_file_t::bytes, CATCH, jf_cache_file_elem_s::data, jf_cache_file_range_s::first, jf_offset_t, JF_RC_DESTINATION_TOO_SMALL, JF_RC_INTERNAL_ERROR, JF_RC_MALLOC_ERROR, JF_RC_OK, JF_RC_OUT_OF_RANGE, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, jf_cache_file_t::size, and THROW.

Referenced by jf_cache_file_set_content().

int jf_cache_file_clear jf_cache_file_t cf  ) 
 

Clear and re-init a cache file: every allocated chunk is released and the cache file become a single chunk empty cache file

Parameters:
cf IN/OUT cache file object
Returns:
a reason code
Definition at line 124 of file jf_cache_file.c.

References CATCH, jf_cache_file_destroy(), jf_cache_file_get_last_pos(), jf_cache_file_get_limit(), jf_cache_file_init(), jf_cache_file_is_empty(), jf_cache_file_is_safe(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_OBJ_CORRUPTED, JF_RC_OK, JF_TRACE, and THROW.

Referenced by jf_journal_rollback_int(), and jf_journal_write_records().

void jf_cache_file_destroy jf_cache_file_t cf  ) 
 

Destroy a cache file object. Every created object (jf_cache_file_create) must be destroyed to avoid memory leaks.

Parameters:
cf IN/OUT cache file object
Definition at line 46 of file jf_cache_file.c.

References jf_cache_file_t::array, jf_cache_file_elem_s::data, jf_cache_file_is_safe(), jf_cache_file_reset(), jf_offset_t, JF_TRACE, and jf_cache_file_t::size.

Referenced by jf_cache_file_clear(), and jf_journal_file_destroy().

int jf_cache_file_get_free_ranges const jf_cache_file_t cf,
const struct jf_cache_file_range_s range,
size_t *  size,
struct jf_cache_file_range_s **  array
 

Retrieve a list of free (non allocated) ranges between a specified range; every range is a set of (cache) file bytes

Parameters:
cf IN cache file object
range IN first and last byte of the (cache) file range must be inspected
size OUT number of free ranges found between "range.first" and "range.last" (cache) file position
array OUT a pointer to an array storing all free ranges; NOTE: the array MUST be released with function "free()" by caller to avoid memory leaks
Returns:
a reason code
Definition at line 646 of file jf_cache_file.c.

References jf_cache_file_t::array, CATCH, jf_cache_file_elem_s::data, jf_cache_file_range_s::first, jf_cache_file_is_empty(), jf_cache_file_is_safe(), jf_cache_file_search(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_INVALID_OPTION, JF_RC_OBJ_CORRUPTED, JF_RC_OBJ_NOT_INITIALIZED, JF_RC_OK, JF_RC_REALLOC_ERROR, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, and THROW.

int jf_cache_file_get_used_ranges const jf_cache_file_t cf,
const struct jf_cache_file_range_s range,
size_t *  size,
struct jf_cache_file_range_s **  array
 

Retrieve a list of used (allocated) ranges between a specified range; every range is a set of (cache) file bytes

Parameters:
cf IN cache file object
range IN first and last byte of the (cache) file range must be inspected
size OUT number of used ranges found between "range.first" and "range.last" (cache) file position
array OUT a pointer to an array storing all used ranges; NOTE: the array MUST be released with function "free()" by caller to avoid memory leaks
Returns:
a reason code
Definition at line 749 of file jf_cache_file.c.

References jf_cache_file_t::array, CATCH, jf_cache_file_elem_s::data, jf_cache_file_range_s::first, jf_cache_file_is_empty(), jf_cache_file_is_safe(), jf_cache_file_search(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_INVALID_OPTION, JF_RC_OBJ_CORRUPTED, JF_RC_OBJ_NOT_INITIALIZED, JF_RC_OK, JF_RC_REALLOC_ERROR, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, and THROW.

int jf_cache_file_init jf_cache_file_t cf,
jf_offset_t  last_pos,
jf_offset_t  limit
 

Initialize a cache file object: this method MUST be invoked after jf_cache_file_create and before every "useful" method

Parameters:
cf IN/OUT cache file object
last_pos IN last valid filepos should be cached
limit IN desired max size amount; see jf_cache_file_set_limit for more details about special values
Returns:
a reason code
Definition at line 64 of file jf_cache_file.c.

References jf_cache_file_t::array, jf_cache_file_t::bytes, CATCH, jf_cache_file_elem_s::data, jf_cache_file_range_s::first, jf_cache_file_is_empty(), jf_cache_file_set_limit(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_MALLOC_ERROR, JF_RC_OBJ_NOT_VOID, JF_RC_OK, JF_RC_OUT_OF_RANGE, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, jf_cache_file_t::size, and THROW.

Referenced by jf_cache_file_clear(), jf_cache_file_resize(), and jf_journal_file_init().

int jf_cache_file_merge jf_cache_file_t cf,
jf_offset_t  first,
jf_offset_t  last
 

Merge some consecutive chunk in a single one

Parameters:
cf IN/OUT cache file object
first IN first chunk must be merged (NOTE: the chunk value IS not the byte position, see jf_cache_file_search)
last IN last chunk must be merged
Returns:
a reason code
Definition at line 1038 of file jf_cache_file.c.

References jf_cache_file_t::array, byte_t, jf_cache_file_t::bytes, CATCH, jf_cache_file_elem_s::data, FALSE, jf_cache_file_range_s::first, jf_cache_file_is_empty(), jf_cache_file_is_safe(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_INVALID_OPTION, JF_RC_MALLOC_ERROR, JF_RC_OBJ_CORRUPTED, JF_RC_OBJ_NOT_INITIALIZED, JF_RC_OK, JF_RC_OUT_OF_RANGE, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, jf_cache_file_t::size, THROW, and TRUE.

Referenced by jf_cache_file_chunk_prepare().

int jf_cache_file_resize jf_cache_file_t cf,
jf_offset_t  new_last_pos
 

Resize an already initialized (see jf_cache_file_init) object

Parameters:
cf IN/OUT cache file object
new_last_pos IN new last valid filepos must be cached
Returns:
a reason code
Definition at line 173 of file jf_cache_file.c.

References jf_cache_file_t::array, byte_t, jf_cache_file_t::bytes, CATCH, jf_cache_file_elem_s::data, jf_cache_file_range_s::first, JF_CACHE_FILE_DEFAULT_LIMIT, jf_cache_file_init(), jf_cache_file_is_empty(), jf_cache_file_is_safe(), jf_cache_file_search(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_OBJ_CORRUPTED, JF_RC_OK, JF_RC_REALLOC_ERROR, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, jf_cache_file_t::size, and THROW.

Referenced by jf_journal_add_byte_data(), and jf_journal_open_attach_file().

int jf_cache_file_search_hint const jf_cache_file_t cf,
jf_offset_t  value,
jf_offset_t pos,
jf_offset_t  hint
 

Search a value in cache array and return the position of the interval containing the value; a hint is accepted to cut down search time (if hint is right, computation time become T(n)=O(1) )

Parameters:
cf IN cache file object
value IN searched value
pos OUT interval (chunk) containing the searched value
hint IN initial search position; a negative value is used for "no available hint" condition
Returns:
a reason code (JF_RC_OBJ_NOT_FOUND if data was not found)
Definition at line 303 of file jf_cache_file.c.

References jf_cache_file_t::array, CATCH, FALSE, jf_cache_file_range_s::first, jf_cache_file_is_empty(), jf_cache_file_is_safe(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_OBJ_CORRUPTED, JF_RC_OBJ_NOT_FOUND, JF_RC_OBJ_NOT_INITIALIZED, JF_RC_OK, JF_RC_OUT_OF_RANGE, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, jf_cache_file_t::size, THROW, and TRUE.

Referenced by jf_cache_file_chunk_prepare(), and jf_cache_file_search().

int jf_cache_file_set_content jf_cache_file_t cf,
jf_offset_t  pos,
size_t  size,
const byte_t content
 

Set the content of a piece of (cache) file: this is the "high" level method should normally be used to update cache content

Parameters:
cf IN/OUT cache file content
pos IN cache file starting position
size IN number of bytes must be updated in cache file starting at "pos" position (first position is "0")
content IN data should be copied into cache file
Returns:
a reason code
Definition at line 571 of file jf_cache_file.c.

References jf_cache_file_t::array, byte_t, CATCH, jf_cache_file_range_s::first, jf_cache_file_chunk_prepare(), jf_cache_file_chunk_set_content(), jf_cache_file_search(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_INVALID_STATUS, JF_RC_OK, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, and THROW.

Referenced by jf_journal_add_byte_data().

int jf_cache_file_split jf_cache_file_t cf,
jf_offset_t  pos,
const struct jf_cache_file_range_s range
 

Split a record in cache file object

Parameters:
cf IN/OUT cache file object
pos IN position of the record must be splitted
range IN range (lowest and highest values) for new record
Returns:
a reason code
Definition at line 400 of file jf_cache_file.c.

References jf_cache_file_t::array, byte_t, jf_cache_file_t::bytes, CATCH, jf_cache_file_elem_s::data, jf_cache_file_range_s::first, jf_cache_file_is_empty(), jf_cache_file_is_safe(), jf_offset_t, JF_RC_INTERNAL_ERROR, JF_RC_INVALID_OPTION, JF_RC_MALLOC_ERROR, JF_RC_OBJ_CORRUPTED, JF_RC_OBJ_NOT_INITIALIZED, JF_RC_OK, JF_RC_OUT_OF_RANGE, JF_RC_REALLOC_ERROR, JF_TRACE, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, jf_cache_file_t::size, and THROW.

Referenced by jf_cache_file_chunk_prepare().

int jf_cache_file_trace const jf_cache_file_t cf,
FILE *  out_stream
 

Trace the content of a cache file object

Parameters:
cf IN cache file object
out_stream IN/OUT output stream used for trace
Returns:
a reason code
Definition at line 1279 of file jf_cache_file.c.

References jf_cache_file_t::array, jf_cache_file_t::bytes, CATCH, jf_cache_file_elem_s::data, jf_cache_file_range_s::first, jf_cache_file_is_safe(), jf_offset_t, JF_OFFSET_T_FORMAT, JF_RC_INTERNAL_ERROR, JF_RC_OBJ_CORRUPTED, JF_RC_OK, JF_TRACE, jf_trace_hex_data(), jf_trace_text_data(), jf_word_t, jf_cache_file_range_s::last, jf_cache_file_elem_s::range, jf_cache_file_t::size, and THROW.


Copyright 2005 © Tiian