Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1235f52

Browse files
committedMar 13, 2025·
fs/fcb: Address review comments
1 parent 640691c commit 1235f52

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed
 

‎fs/fcb/include/fcb/fcb.h

+8
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,19 @@ int fcb_append_to_scratch(struct fcb *);
194194

195195
/**
196196
* How many sectors are unused.
197+
*
198+
* @param fcb - fcb to check
199+
* @return number of free sectors if successful,
200+
* negative value on error
197201
*/
198202
int fcb_free_sector_cnt(struct fcb *fcb);
199203

200204
/**
201205
* Whether FCB has any data.
206+
*
207+
* @param fcb - fcb to check
208+
* @return 1 if FCB is empty, 0 if FCB has data,
209+
* negative value on error
202210
*/
203211
int fcb_is_empty(struct fcb *fcb);
204212

‎fs/fcb/src/fcb.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ fcb_free_sector_cnt(struct fcb *fcb)
130130
return i;
131131
}
132132

133+
int
134+
fcb_is_empty_nolock(struct fcb *fcb)
135+
{
136+
bool ret = false;
137+
138+
ret = (fcb->f_active.fe_area == fcb->f_oldest &&
139+
fcb->f_active.fe_elem_off == sizeof(struct fcb_disk_area));
140+
141+
return ret;
142+
}
143+
133144
int
134145
fcb_is_empty(struct fcb *fcb)
135146
{
@@ -262,13 +273,13 @@ fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
262273

263274
i = 0;
264275
memset(&loc, 0, sizeof(loc));
265-
while (!fcb_getnext(fcb, &loc)) {
276+
while (!fcb_getnext_nolock(fcb, &loc)) {
266277
if (i == 0) {
267278
/* Start from the beginning of fcb entries */
268279
*last_n_entry = loc;
269280
} else if (i > (entries - 1)) {
270281
/* Update last_n_entry after n entries and keep updating */
271-
fcb_getnext(fcb, last_n_entry);
282+
fcb_getnext_nolock(fcb, last_n_entry);
272283
}
273284
i++;
274285
}
@@ -293,7 +304,7 @@ fcb_clear(struct fcb *fcb)
293304
return FCB_ERR_ARGS;
294305
}
295306

296-
while (!fcb_is_empty(fcb)) {
307+
while (!fcb_is_empty_nolock(fcb)) {
297308
rc = fcb_rotate(fcb);
298309
if (rc) {
299310
break;

0 commit comments

Comments
 (0)
Please sign in to comment.