diff --git a/inc/fdb_def.h b/inc/fdb_def.h index 4fd1733..2d505af 100644 --- a/inc/fdb_def.h +++ b/inc/fdb_def.h @@ -69,24 +69,24 @@ if (!(EXPR)) \ while (1); \ } -#define FDB_KVDB_CTRL_SET_SEC_SIZE 0x00 /**< set sector size control command */ +#define FDB_KVDB_CTRL_SET_SEC_SIZE 0x00 /**< set sector size control command, this change MUST before database initialization */ #define FDB_KVDB_CTRL_GET_SEC_SIZE 0x01 /**< get sector size control command */ #define FDB_KVDB_CTRL_SET_LOCK 0x02 /**< set lock function control command */ #define FDB_KVDB_CTRL_SET_UNLOCK 0x03 /**< set unlock function control command */ -#define FDB_KVDB_CTRL_SET_FILE_MODE 0x09 /**< set file mode control command */ -#define FDB_KVDB_CTRL_SET_MAX_SIZE 0x0A /**< set database max size in file mode control command */ -#define FDB_KVDB_CTRL_SET_NOT_FORMAT 0x0B /**< set database NOT format mode control command */ +#define FDB_KVDB_CTRL_SET_FILE_MODE 0x09 /**< set file mode control command, this change MUST before database initialization */ +#define FDB_KVDB_CTRL_SET_MAX_SIZE 0x0A /**< set database max size in file mode control command, this change MUST before database initialization */ +#define FDB_KVDB_CTRL_SET_NOT_FORMAT 0x0B /**< set database NOT format mode control command, this change MUST before database initialization */ -#define FDB_TSDB_CTRL_SET_SEC_SIZE 0x00 /**< set sector size control command */ +#define FDB_TSDB_CTRL_SET_SEC_SIZE 0x00 /**< set sector size control command, this change MUST before database initialization */ #define FDB_TSDB_CTRL_GET_SEC_SIZE 0x01 /**< get sector size control command */ #define FDB_TSDB_CTRL_SET_LOCK 0x02 /**< set lock function control command */ #define FDB_TSDB_CTRL_SET_UNLOCK 0x03 /**< set unlock function control command */ -#define FDB_TSDB_CTRL_SET_ROLLOVER 0x04 /**< set rollover control command */ +#define FDB_TSDB_CTRL_SET_ROLLOVER 0x04 /**< set rollover control command, this change MUST before database initialization */ #define FDB_TSDB_CTRL_GET_ROLLOVER 0x05 /**< get rollover control command */ #define FDB_TSDB_CTRL_GET_LAST_TIME 0x06 /**< get last save time control command */ -#define FDB_TSDB_CTRL_SET_FILE_MODE 0x09 /**< set file mode control command */ -#define FDB_TSDB_CTRL_SET_MAX_SIZE 0x0A /**< set database max size in file mode control command */ -#define FDB_TSDB_CTRL_SET_NOT_FORMAT 0x0B /**< set database NOT formatable mode control command */ +#define FDB_TSDB_CTRL_SET_FILE_MODE 0x09 /**< set file mode control command, this change MUST before database initialization */ +#define FDB_TSDB_CTRL_SET_MAX_SIZE 0x0A /**< set database max size in file mode control command, this change MUST before database initialization */ +#define FDB_TSDB_CTRL_SET_NOT_FORMAT 0x0B /**< set database NOT formatable mode control command, this change MUST before database initialization */ #ifdef FDB_USING_TIMESTAMP_64BIT typedef int64_t fdb_time_t; diff --git a/inc/flashdb.h b/inc/flashdb.h index 6168e51..e64fd8f 100644 --- a/inc/flashdb.h +++ b/inc/flashdb.h @@ -31,11 +31,11 @@ extern "C" { #endif /* FlashDB database API */ -fdb_err_t fdb_kvdb_init (fdb_kvdb_t db, const char *name, const char *part_name, struct fdb_default_kv *default_kv, +fdb_err_t fdb_kvdb_init (fdb_kvdb_t db, const char *name, const char *path, struct fdb_default_kv *default_kv, void *user_data); void fdb_kvdb_control(fdb_kvdb_t db, int cmd, void *arg); fdb_err_t fdb_kvdb_deinit(fdb_kvdb_t db); -fdb_err_t fdb_tsdb_init (fdb_tsdb_t db, const char *name, const char *part_name, fdb_get_time get_time, size_t max_len, +fdb_err_t fdb_tsdb_init (fdb_tsdb_t db, const char *name, const char *path, fdb_get_time get_time, size_t max_len, void *user_data); void fdb_tsdb_control(fdb_tsdb_t db, int cmd, void *arg); fdb_err_t fdb_tsdb_deinit(fdb_tsdb_t db); diff --git a/src/fdb.c b/src/fdb.c index 4349ff6..f220827 100644 --- a/src/fdb.c +++ b/src/fdb.c @@ -21,11 +21,11 @@ #error "Please defined the FDB_USING_FAL_MODE or FDB_USING_FILE_MODE macro" #endif -fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *part_name, fdb_db_type type, void *user_data) +fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *path, fdb_db_type type, void *user_data) { FDB_ASSERT(db); FDB_ASSERT(name); - FDB_ASSERT(part_name); + FDB_ASSERT(path); if (db->init_ok) { return FDB_NO_ERR; @@ -45,8 +45,8 @@ fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *part_name, fdb #else db->cur_file = 0; #endif - db->storage.dir = part_name; - FDB_ASSERT(strlen(part_name) != 0) + db->storage.dir = path; + FDB_ASSERT(strlen(path) != 0) #endif } else { #ifdef FDB_USING_FAL_MODE @@ -55,8 +55,8 @@ fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *part_name, fdb /* FAL (Flash Abstraction Layer) initialization */ fal_init(); /* check the flash partition */ - if ((db->storage.part = fal_partition_find(part_name)) == NULL) { - FDB_INFO("Error: Partition (%s) not found.\n", part_name); + if ((db->storage.part = fal_partition_find(path)) == NULL) { + FDB_INFO("Error: Partition (%s) not found.\n", path); return FDB_PART_NOT_FOUND; } diff --git a/src/fdb_kvdb.c b/src/fdb_kvdb.c index 59ed9f1..3d764e8 100644 --- a/src/fdb_kvdb.c +++ b/src/fdb_kvdb.c @@ -452,7 +452,7 @@ static uint32_t get_next_sector_addr(fdb_kvdb_t db, kv_sec_info_t pre_sec) uint32_t next_addr; if (pre_sec->addr == FAILED_ADDR) { - /* the next sector is on the top of the partition */ + /* the next sector is on the top of the database */ return 0; } else { /* check KV sector combined */ @@ -1586,13 +1586,13 @@ void fdb_kvdb_control(fdb_kvdb_t db, int cmd, void *arg) * * @param db database object * @param name database name - * @param part_name partition name + * @param path FAL mode: partition name, file mode: database saved directory path * @param default_kv the default KV set @see fdb_default_kv * @param user_data user data * * @return result */ -fdb_err_t fdb_kvdb_init(fdb_kvdb_t db, const char *name, const char *part_name, struct fdb_default_kv *default_kv, +fdb_err_t fdb_kvdb_init(fdb_kvdb_t db, const char *name, const char *path, struct fdb_default_kv *default_kv, void *user_data) { fdb_err_t result = FDB_NO_ERR; @@ -1604,7 +1604,7 @@ fdb_err_t fdb_kvdb_init(fdb_kvdb_t db, const char *name, const char *part_name, /* must be aligned with write granularity */ FDB_ASSERT((FDB_STR_KV_VALUE_MAX_SIZE * 8) % FDB_WRITE_GRAN == 0); - result = _fdb_init_ex((fdb_db_t)db, name, part_name, FDB_DB_TYPE_KV, user_data); + result = _fdb_init_ex((fdb_db_t)db, name, path, FDB_DB_TYPE_KV, user_data); if (result != FDB_NO_ERR) { goto __exit; } diff --git a/src/fdb_tsdb.c b/src/fdb_tsdb.c index ff80d90..e000191 100644 --- a/src/fdb_tsdb.c +++ b/src/fdb_tsdb.c @@ -131,7 +131,7 @@ static uint32_t get_next_sector_addr(fdb_tsdb_t db, tsdb_sec_info_t pre_sec, uin if (pre_sec->addr + db_sec_size(db) < db_max_size(db)) { return pre_sec->addr + db_sec_size(db); } else { - /* the next sector is on the top of the partition */ + /* the next sector is on the top of the database */ return 0; } } else { @@ -726,14 +726,14 @@ void fdb_tsdb_control(fdb_tsdb_t db, int cmd, void *arg) * * @param db database object * @param name database name - * @param part_name partition name + * @param path FAL mode: partition name, file mode: database saved directory path * @param get_time get current time function * @param max_len maximum length of each log * @param user_data user data * * @return result */ -fdb_err_t fdb_tsdb_init(fdb_tsdb_t db, const char *name, const char *part_name, fdb_get_time get_time, size_t max_len, void *user_data) +fdb_err_t fdb_tsdb_init(fdb_tsdb_t db, const char *name, const char *path, fdb_get_time get_time, size_t max_len, void *user_data) { fdb_err_t result = FDB_NO_ERR; struct tsdb_sec_info sector; @@ -741,7 +741,7 @@ fdb_err_t fdb_tsdb_init(fdb_tsdb_t db, const char *name, const char *part_name, FDB_ASSERT(get_time); - result = _fdb_init_ex((fdb_db_t)db, name, part_name, FDB_DB_TYPE_TS, user_data); + result = _fdb_init_ex((fdb_db_t)db, name, path, FDB_DB_TYPE_TS, user_data); if (result != FDB_NO_ERR) { goto __exit; } @@ -775,7 +775,7 @@ fdb_err_t fdb_tsdb_init(fdb_tsdb_t db, const char *name, const char *part_name, } /* db->cur_sec is the latest sector, and the next is the oldest sector */ if (latest_addr + db_sec_size(db) >= db_max_size(db)) { - /* db->cur_sec is the the bottom of the partition */ + /* db->cur_sec is the the bottom of the database */ db->oldest_addr = 0; } else { db->oldest_addr = latest_addr + db_sec_size(db);