fix FDB_config and fwrite size check

This commit is contained in:
lyon1998 2023-12-07 23:30:54 +08:00
parent be098b033c
commit a6f9a6c893
4 changed files with 24 additions and 10 deletions

View File

@ -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
@ -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_ */

View File

@ -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;

View File

@ -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
@ -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_ */

View File

@ -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;