Skip to content

Commit

Permalink
fix FDB_config and fwrite size check
Browse files Browse the repository at this point in the history
  • Loading branch information
pikasTech committed Dec 7, 2023
1 parent be098b0 commit a6f9a6c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
11 changes: 9 additions & 2 deletions package/flashdb/fdb_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
* @brief configuration file
*/


#ifndef _FDB_CFG_H_
#define _FDB_CFG_H_

#include "PikaObj.h"

/* using KVDB feature */
#define FDB_USING_KVDB

Expand All @@ -33,8 +36,12 @@
/* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */

/* print debug information */
#ifndef PIKA_FDB_DEBUG_ENABLE
#define PIKA_FDB_DEBUG_ENABLE 0
#endif

#if PIKA_FDB_DEBUG_ENABLE
#define FDB_DEBUG_ENABLE
#define FDB_KV_CACHE_TABLE_SIZE 0
#define FDB_SECTOR_CACHE_TABLE_SIZE 0
#endif

#endif /* _FDB_CFG_H_ */
6 changes: 3 additions & 3 deletions package/flashdb/fdb_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ fdb_err_t _fdb_file_erase(fdb_db_t db, uint32_t addr, size_t size) {
pika_platform_fseek(fp, 0, SEEK_SET);
for (i = 0; i * BUF_SIZE < size; i++) {
memset(buf, 0xFF, BUF_SIZE);
size_t sizew = pika_platform_fwrite(buf, BUF_SIZE, 1, fp);
if (sizew != 1) {
size_t sizew = pika_platform_fwrite(buf, 1, BUF_SIZE, fp);
if (sizew != BUF_SIZE) {
FDB_PRINT("Error: write (%s) file failed.\n", db->name);
result = FDB_WRITE_ERR;
break;
}
}
memset(buf, 0xFF, BUF_SIZE);
size_t sizew = pika_platform_fwrite(buf, size - i * BUF_SIZE, 1, fp);
size_t sizew = pika_platform_fwrite(buf, 1, size - i * BUF_SIZE, fp);
if (sizew != size - i * BUF_SIZE) {
FDB_PRINT("Error: write (%s) file failed.\n", db->name);
result = FDB_WRITE_ERR;
Expand Down
11 changes: 9 additions & 2 deletions port/linux/package/pikascript/pikascript-lib/flashdb/fdb_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
* @brief configuration file
*/


#ifndef _FDB_CFG_H_
#define _FDB_CFG_H_

#include "PikaObj.h"

/* using KVDB feature */
#define FDB_USING_KVDB

Expand All @@ -33,8 +36,12 @@
/* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */

/* print debug information */
#ifndef PIKA_FDB_DEBUG_ENABLE
#define PIKA_FDB_DEBUG_ENABLE 0
#endif

#if PIKA_FDB_DEBUG_ENABLE
#define FDB_DEBUG_ENABLE
#define FDB_KV_CACHE_TABLE_SIZE 0
#define FDB_SECTOR_CACHE_TABLE_SIZE 0
#endif

#endif /* _FDB_CFG_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ fdb_err_t _fdb_file_erase(fdb_db_t db, uint32_t addr, size_t size) {
pika_platform_fseek(fp, 0, SEEK_SET);
for (i = 0; i * BUF_SIZE < size; i++) {
memset(buf, 0xFF, BUF_SIZE);
size_t sizew = pika_platform_fwrite(buf, BUF_SIZE, 1, fp);
if (sizew != 1) {
size_t sizew = pika_platform_fwrite(buf, 1, BUF_SIZE, fp);
if (sizew != BUF_SIZE) {
FDB_PRINT("Error: write (%s) file failed.\n", db->name);
result = FDB_WRITE_ERR;
break;
}
}
memset(buf, 0xFF, BUF_SIZE);
size_t sizew = pika_platform_fwrite(buf, size - i * BUF_SIZE, 1, fp);
size_t sizew = pika_platform_fwrite(buf, 1, size - i * BUF_SIZE, fp);
if (sizew != size - i * BUF_SIZE) {
FDB_PRINT("Error: write (%s) file failed.\n", db->name);
result = FDB_WRITE_ERR;
Expand Down

0 comments on commit a6f9a6c

Please sign in to comment.