From bc113301c744fc311f0cd2f2af102218eac7bb44 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 14 Nov 2017 12:43:44 +0000 Subject: Fixed few bugs, not fully tested yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10996 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/lib/complex/mfs/mfs.c | 13 +++++++------ os/hal/lib/complex/mfs/mfs.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'os') diff --git a/os/hal/lib/complex/mfs/mfs.c b/os/hal/lib/complex/mfs/mfs.c index 11c829eb4..a1decd519 100644 --- a/os/hal/lib/complex/mfs/mfs.c +++ b/os/hal/lib/complex/mfs/mfs.c @@ -442,7 +442,7 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp, hdr_offset = start_offset + (flash_offset_t)sizeof(mfs_bank_header_t); while (hdr_offset < end_offset) { /* Reading the current record header.*/ - RET_ON_ERROR(mfs_flash_read(mfsp, start_offset, + RET_ON_ERROR(mfs_flash_read(mfsp, hdr_offset, sizeof (mfs_data_header_t), (void *)&mfsp->buffer.dhdr)); @@ -632,12 +632,13 @@ static mfs_error_t mfs_garbage_collect(MFSDriver *mfsp) { /* Copying the most recent record instances only.*/ for (i = 0; i < MFS_CFG_MAX_RECORDS; i++) { + uint32_t totsize = mfsp->descriptors[i].size + sizeof (mfs_data_header_t); if (mfsp->descriptors[i].offset != 0) { RET_ON_ERROR(mfs_flash_copy(mfsp, dest_offset, mfsp->descriptors[i].offset, - mfsp->descriptors[i].size)); + totsize)); mfsp->descriptors[i].offset = dest_offset; - dest_offset += mfsp->descriptors[i].size; + dest_offset += totsize; } } @@ -1059,15 +1060,15 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, uint32_t id, /* The size of the old record instance, if present, must be subtracted to the total used size.*/ if (mfsp->descriptors[id - 1U].offset != 0U) { - mfsp->used_space -= sizeof (mfs_data_header_t) + - mfsp->descriptors[id - 1U].size; + mfsp->used_space -= sizeof (mfs_data_header_t) + + mfsp->descriptors[id - 1U].size; } /* Adjusting bank-related metadata.*/ mfsp->descriptors[id - 1U].offset = mfsp->next_offset; mfsp->descriptors[id - 1U].size = (uint32_t)n; mfsp->next_offset += sizeof (mfs_data_header_t) + n; - mfsp->used_space -= sizeof (mfs_data_header_t) + n; + mfsp->used_space += sizeof (mfs_data_header_t) + n; return warning ? MFS_WARN_GC : MFS_NO_ERROR; } diff --git a/os/hal/lib/complex/mfs/mfs.h b/os/hal/lib/complex/mfs/mfs.h index e3504e29a..49b1a342b 100644 --- a/os/hal/lib/complex/mfs/mfs.h +++ b/os/hal/lib/complex/mfs/mfs.h @@ -210,7 +210,7 @@ typedef union { * @brief Type of a data block header. * @details This structure is placed before each written data block. */ -typedef struct { +typedef union { struct { /** * @brief Data header magic. -- cgit v1.2.3