Skip to content

Commit 3bcb976

Browse files
committed
sys/log, fs/fcb: Address some review comments
1 parent 142177c commit 3bcb976

File tree

6 files changed

+56
-64
lines changed

6 files changed

+56
-64
lines changed

fs/fcb/include/fcb/fcb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,16 @@ int fcb_getnext(struct fcb *, struct fcb_entry *loc);
172172
* Get first entry in the provided flash area
173173
*
174174
* @param fcb Pointer to FCB
175-
* @param fa Optional pointer to flash area
175+
* @param fap Optional pointer to flash area
176176
* @param loc Pointer to first FCB entry in the provided flash area
177177
*
178178
* @return 0 on success, non-zero on failure
179179
*/
180-
int fcb_getnext_in_area(struct fcb *fcb, struct flash_area *fa,
180+
int fcb_getnext_in_area(struct fcb *fcb, struct flash_area *fap,
181181
struct fcb_entry *loc);
182182

183183
/**
184-
* Get next area pointer from the FCB pointer to by fcb pointer
184+
* Get next area pointer from the FCB pointer
185185
*
186186
* @param fcb Pointer to the FCB
187187
* @param fap Pointer to the flash_area

fs/fcb/src/fcb_getnext.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ fcb_start_offset(struct fcb *fcb)
6363
}
6464

6565
int
66-
fcb_getnext_in_area(struct fcb *fcb, struct flash_area *fa,
66+
fcb_getnext_in_area(struct fcb *fcb, struct flash_area *fap,
6767
struct fcb_entry *loc)
6868
{
6969
int rc;
7070

7171
/* If a flash area is specified, find first entry in that area */
72-
if (fa) {
73-
loc->fe_area = fa;
72+
if (fap) {
73+
loc->fe_area = fap;
7474
loc->fe_elem_off = fcb_len_in_flash(fcb, sizeof(struct fcb_disk_area));
7575
loc->fe_elem_ix = 0;
7676
loc->fe_data_len = 0;

sys/log/full/include/log/log_fcb.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,27 @@ struct log_fcb_bmark {
3939
#endif
4040
/* The index of the log entry that the FCB entry contains. */
4141
uint32_t lfb_index;
42-
/* Is this a sector boundary bookmark */
43-
bool lfb_sect_bmark;
4442
};
4543

4644
/** A set of fcb log bookmarks. */
4745
struct log_fcb_bset {
4846
/** Array of bookmarks. */
4947
struct log_fcb_bmark *lfs_bmarks;
5048

49+
/** Enable sector bookmarks */
5150
bool lfs_en_sect_bmarks;
5251

5352
/** The maximum number of bookmarks. */
5453
int lfs_cap;
5554

5655
/** The number of currently used non-sector bookmarks. */
57-
int lfs_non_s_size;
56+
int lfs_non_sect_size;
5857

5958
/** The number of currently usable bookmarks. */
6059
int lfs_size;
6160

62-
/** The index where the next bookmark will get written. */
63-
uint32_t lfs_next;
64-
6561
/** The index where the next non-sector bmark will get written */
66-
uint32_t lfs_next_non_s;
62+
uint32_t lfs_next_non_sect;
6763
};
6864

6965
/**

sys/log/full/src/log_fcb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ fcb_walk_back_find_start(struct fcb *fcb, struct log *log,
113113
* If bmark is found, fill up min_diff.
114114
*
115115
* The "index" field corresponds to a log entry index.
116+
* For min_diff, if bookmark was found, fill it up with the difference
117+
* else it will return -1.
116118
*
117119
* If bookmarks are enabled, this function uses them in the search.
118120
*

sys/log/full/src/log_fcb2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ static int log_fcb2_rtr_erase(struct log *log);
4747
* The "index" field corresponds to a log entry index.
4848
*
4949
* If bookmarks are enabled, this function uses them in the search.
50+
* For min_diff, if bookmark was found, fill it up with the difference
51+
* else it will return -1.
5052
*
5153
* @return 0 if an entry was found
5254
* SYS_ENOENT if there are no suitable entries.
@@ -185,7 +187,7 @@ log_fcb2_start_append(struct log *log, int len, struct fcb2_entry *loc)
185187
* bookmarks
186188
*/
187189
log_fcb_init_bmarks(fcb_log, fcb_log->fl_bset.lfs_bmarks,
188-
fcb_log->fl_bset.lfs_cap);
190+
fcb_log->fl_bset.lfs_cap, true);
189191
#endif
190192

191193
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)

sys/log/full/src/log_fcb_bmark.c

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ log_fcb_clear_bmarks(struct fcb_log *fcb_log)
121121
{
122122
fcb_log->fl_bset.lfs_size = 0;
123123
fcb_log->fl_bset.lfs_next = 0;
124-
fcb_log->fl_bset.lfs_next_non_s = 0;
125-
fcb_log->fl_bset.lfs_non_s_size = 0;
124+
fcb_log->fl_bset.lfs_next_non_sect = 0;
125+
fcb_log->fl_bset.lfs_non_sect_size = 0;
126126
memset(fcb_log->fl_bset.lfs_bmarks, 0,
127127
sizeof(struct log_fcb_bmark) *
128128
fcb_log->fl_bset.lfs_cap);
@@ -172,9 +172,9 @@ log_fcb_closest_bmark(struct fcb_log *fcb_log, uint32_t index,
172172
if (diff < *min_diff) {
173173
*min_diff = diff;
174174
closest = bmark;
175-
MODLOG_INFO(LOG_MODULE_DEFAULT, "index: %u, closest bmark idx: %u, \n",
176-
(unsigned int)index,
177-
(unsigned int)bmark->lfb_index);
175+
MODLOG_DEBUG(LOG_MODULE_DEFAULT, "index: %u, closest bmark idx: %u, \n",
176+
(unsigned int)index,
177+
(unsigned int)bmark->lfb_index);
178178
/* We found the exact match, no need to keep searching for a
179179
* better match
180180
*/
@@ -191,57 +191,49 @@ log_fcb_closest_bmark(struct fcb_log *fcb_log, uint32_t index,
191191
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
192192
#if MYNEWT_VAL(LOG_FCB)
193193
static void
194-
log_fcb_insert_bmark(struct fcb_log *fcb_log, struct fcb_entry *entry,
195-
uint32_t index, bool sect_bmark, int pos)
194+
log_fcb_insert_sect_bmark(struct fcb_log *fcb_log, struct fcb_entry *entry,
195+
uint32_t index, int pos)
196196
#elif MYNEWT_VAL(LOG_FCB2)
197197
static void
198-
log_fcb_insert_bmark(struct fcb_log *fcb_log, fcb2_entry *entry,
199-
uint32_t index, bool sect_bmark, int pos)
198+
log_fcb_insert_sect_bmark(struct fcb_log *fcb_log, fcb2_entry *entry,
199+
uint32_t index, int pos)
200200
#endif
201201
{
202202
struct log_fcb_bset *bset;
203203

204204
bset = &fcb_log->fl_bset;
205205

206-
if (pos == bset->lfs_cap - 1) {
207-
goto add;
206+
if (pos != bset->lfs_cap - 1) {
207+
memmove(&bset->lfs_bmarks[pos + 1], &bset->lfs_bmarks[pos],
208+
sizeof(bset->lfs_bmarks[0]) * (bset->lfs_size - pos - 1));
208209
}
209210

210-
memcpy(&bset->lfs_bmarks[pos + 1], &bset->lfs_bmarks[pos],
211-
sizeof(bset->lfs_bmarks[0]) * bset->lfs_size - pos - 1);
212-
213-
add:
214211
bset->lfs_bmarks[pos] = (struct log_fcb_bmark) {
215212
.lfb_entry = *entry,
216213
.lfb_index = index,
217-
.lfb_sect_bmark = sect_bmark
218214
};
219215

220216
if (bset->lfs_size < bset->lfs_cap) {
221217
bset->lfs_size++;
222218
}
223-
224-
bset->lfs_next++;
225-
bset->lfs_next %= bset->lfs_cap;
226219
}
227220
#endif
228221

229222
#if MYNEWT_VAL(LOG_FCB)
230223
static void
231-
log_fcb_replace_bmark(struct fcb_log *fcb_log, struct fcb_entry *entry,
232-
uint32_t index, bool sect_bmark, int pos)
224+
log_fcb_replace_non_sect_bmark(struct fcb_log *fcb_log, struct fcb_entry *entry,
225+
uint32_t index, int pos)
233226
#elif MYNEWT_VAL(LOG_FCB2)
234227
static void
235-
log_fcb_replace_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
236-
uint32_t index, bool sect_bmark, int pos)
228+
log_fcb_replace_non_sect_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
229+
uint32_t index, int pos)
237230
#endif
238231
{
239232
int i = 0;
240233
struct log_fcb_bset *bset = &fcb_log->fl_bset;
241-
bool en_sect_bmark = sect_bmark & bset->lfs_en_sect_bmarks;
242234

243235
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
244-
if (en_sect_bmark) {
236+
if (bset->lfs_en_sect_bmarks) {
245237
for (i = fcb_log->fl_fcb.f_sector_cnt;
246238
i < (bset->lfs_non_s_size + fcb_log->fl_fcb.f_sector_cnt);
247239
i++) {
@@ -252,8 +244,8 @@ log_fcb_replace_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
252244
}
253245
} else
254246
#endif
255-
if (!en_sect_bmark) {
256-
for (i = 0; i < bset->lfs_non_s_size; i++) {
247+
{
248+
for (i = 0; i < bset->lfs_non_sect_size; i++) {
257249
if (index == bset->lfs_bmarks[i].lfb_index) {
258250
/* If index matches, no need to replace */
259251
return;
@@ -264,7 +256,6 @@ log_fcb_replace_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
264256
bset->lfs_bmarks[pos] = (struct log_fcb_bmark) {
265257
.lfb_entry = *entry,
266258
.lfb_index = index,
267-
.lfb_sect_bmark = sect_bmark
268259
};
269260
}
270261

@@ -300,7 +291,7 @@ log_fcb_add_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
300291
pos = i + 1;
301292
}
302293
}
303-
log_fcb_insert_bmark(fcb_log, entry, index, sect_bmark, pos);
294+
log_fcb_insert_sect_bmark(fcb_log, entry, index, pos);
304295
if (pos >= fcb_log->fl_fcb.f_sector_cnt - 1) {
305296
/* Make sure inserts do not trickle into the non-sector
306297
* bookmarks
@@ -313,48 +304,49 @@ log_fcb_add_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
313304
}
314305
} else {
315306
/* Replace oldest non-sector bmark */
316-
log_fcb_replace_bmark(fcb_log, entry, index, sect_bmark,
317-
bset->lfs_next_non_s +
318-
bset->lfs_en_sect_bmarks ? fcb_log->fl_fcb.f_sector_cnt
319-
: 0);
307+
log_fcb_replace_non_sect_bmark(fcb_log, entry, index,
308+
bset->lfs_next_non_sect +
309+
(bset->lfs_en_sect_bmarks ?
310+
fcb_log->fl_fcb.f_sector_cnt : 0));
320311
MODLOG_DEBUG(LOG_MODULE_DEFAULT, "replace bmark index: %u, pos: %u, \n",
321312
(unsigned int)index,
322-
(unsigned int)bset->lfs_next_non_s + bset->lfs_en_sect_bmarks ?
323-
fcb_log->fl_fcb.f_sector_cnt : 0);
324-
if (bset->lfs_non_s_size >= MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS)) {
325-
bset->lfs_next_non_s = (bset->lfs_next_non_s + 1) %
326-
MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS);
313+
(unsigned int)bset->lfs_next_non_sect +
314+
(bset->lfs_en_sect_bmarks ?
315+
fcb_log->fl_fcb.f_sector_cnt : 0));
316+
if (bset->lfs_non_sect_size >= MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS)) {
317+
bset->lfs_next_non_sect = (bset->lfs_next_non_sect + 1) %
318+
MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS);
327319
} else {
328-
if (!bset->lfs_non_s_size) {
320+
if (!bset->lfs_non_sect_size) {
329321
/* First non-sector bmark position */
330-
bset->lfs_next_non_s = pos;
322+
bset->lfs_next_non_sect = pos;
331323
}
332-
bset->lfs_non_s_size++;
324+
bset->lfs_non_sect_size++;
333325
bset->lfs_size++;
334326
}
335327

336-
assert(bset->lfs_non_s_size <= MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS));
328+
assert(bset->lfs_non_sect_size <= MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS));
337329
}
338330
#else
339331
if (!sect_bmark) {
340332
if (bset->lfs_size >= MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS)) {
341333
/* Replace oldest non-sector bmark */
342-
log_fcb_replace_bmark(fcb_log, entry, index, sect_bmark,
343-
bset->lfs_next_non_s);
334+
log_fcb_replace_non_sect_bmark(fcb_log, entry, index,
335+
bset->lfs_next_non_sect);
344336
MODLOG_DEBUG(LOG_MODULE_DEFAULT, "replace bmark index: %u, pos: %u, \n",
345337
(unsigned int)index,
346-
(unsigned int)bset->lfs_next_non_s);
347-
bset->lfs_next_non_s = (bset->lfs_next_non_s + 1) %
348-
MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS);
338+
(unsigned int)bset->lfs_next_non_sect);
339+
bset->lfs_next_non_sect = (bset->lfs_next_non_sect + 1) %
340+
MYNEWT_VAL(LOG_FCB_NUM_ABS_BMARKS);
349341
} else {
350-
log_fcb_replace_bmark(fcb_log, entry, index, sect_bmark,
351-
bset->lfs_size);
342+
log_fcb_replace_non_sect_bmark(fcb_log, entry, index,
343+
bset->lfs_size);
352344
MODLOG_DEBUG(LOG_MODULE_DEFAULT, "replace bmark index: %u, pos: %u, \n",
353345
(unsigned int)index,
354346
bset->lfs_size);
355347
if (!bset->lfs_size) {
356348
/* First non-sector bmark position */
357-
bset->lfs_next_non_s = pos;
349+
bset->lfs_next_non_sect = pos;
358350
}
359351
bset->lfs_size++;
360352
}

0 commit comments

Comments
 (0)