PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
settings_raw_iter.h File Reference
#include <inttypes.h>
#include <stddef.h>
#include <stdbool.h>
#include <system/status_codes.h>
#include <pbl/kernel/compiler.h>

Data Structures

struct  SettingsFileHeader
 Settings file header. More...
 
struct  SettingsRecordHeader
 Record header. More...
 
struct  SettingsRawIter
 Cursor over the records of a settings file. More...
 

Macros

#define SETTINGS_FILE_MAGIC   "set"
 Magic at the start of every settings file.
 
#define SETTINGS_FILE_VERSION   1
 Current settings file format version.
 
#define SETTINGS_FLAG_WRITE_COMPLETE   (1 << 0)
 Record header, key and value are completely written.
 
#define SETTINGS_FLAG_OVERWRITE_STARTED   (1 << 1)
 A newer record for the same key is being written.
 
#define SETTINGS_FLAG_OVERWRITE_COMPLETE   (1 << 2)
 A newer record for the same key is complete; this one is dead.
 
#define SETTINGS_FLAG_SYNCED   (1 << 3)
 Record is in sync with the phone.
 
#define SETTINGS_KEY_MAX_LEN   127
 Maximum key length in bytes.
 
#define SETTINGS_VAL_MAX_LEN   (SETTINGS_EOF_MARKER - 1)
 Maximum value length in bytes.
 
#define KEY_LEN_BITS   7
 Width of the key length field of a record header.
 
#define VAL_LEN_BITS   11
 Width of the value length field of a record header.
 
#define FLAGS_BITS   6
 Width of the flags field of a record header.
 
#define SETTINGS_EOF_MARKER   ((1 << VAL_LEN_BITS) - 1)
 Value length of the all-ones header that marks the end of the records.
 

Functions

void settings_raw_iter_init (SettingsRawIter *iter, int fd, const char *file_name)
 Initialize an iterator and read the file header.
 
void settings_raw_iter_write_file_header (SettingsRawIter *iter, SettingsFileHeader *file_hdr)
 Write the file header, for newly created files.
 
void settings_raw_iter_begin (SettingsRawIter *iter)
 Move to the first record.
 
void settings_raw_iter_resume (SettingsRawIter *iter)
 Start a search from the current record.
 
void settings_raw_iter_next (SettingsRawIter *iter)
 Move to the next record.
 
bool settings_raw_iter_end (SettingsRawIter *iter)
 Check whether the iterator is past the last record.
 
int settings_raw_iter_get_current_record_pos (SettingsRawIter *iter)
 Get the current record position.
 
void settings_raw_iter_set_current_record_pos (SettingsRawIter *iter, int pos)
 Move to a position from settings_raw_iter_get_current_record_pos().
 
int settings_raw_iter_get_resumed_record_pos (SettingsRawIter *iter)
 Get the position the current search started from.
 
void settings_raw_iter_read_key (SettingsRawIter *iter, uint8_t *key)
 Read the key of the current record.
 
void settings_raw_iter_read_val (SettingsRawIter *iter, uint8_t *val, int val_len)
 Read the value of the current record.
 
void settings_raw_iter_read_key_val (SettingsRawIter *iter, uint8_t *key_val_out)
 Read the key and value of the current record in one PFS call.
 
void settings_raw_iter_write_header (SettingsRawIter *iter, SettingsRecordHeader *hdr)
 Write the header of the current record.
 
void settings_raw_iter_write_key (SettingsRawIter *iter, const uint8_t *key)
 Write the key of the current record, using the length from its header.
 
void settings_raw_iter_write_val (SettingsRawIter *iter, const uint8_t *val)
 Write the value of the current record, using the length from its header.
 
void settings_raw_iter_write_key_val (SettingsRawIter *iter, const uint8_t *key_val)
 Write the key and value of the current record in one PFS call.
 
void settings_raw_iter_write_byte (SettingsRawIter *iter, int offset, uint8_t byte)
 Write one byte of the value of the current record in place.
 
void settings_raw_iter_deinit (SettingsRawIter *iter)
 Close the underlying file.