Skip to content

Commit 55fe30e

Browse files
committed
Ack allocator when freeing a reserved area
1 parent ff1e46b commit 55fe30e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lfs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3705,7 +3705,15 @@ static int lfs_file_rawtruncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) {
37053705

37063706
if (file->flags & LFS_F_FLAT) {
37073707
LFS_ASSERT((file->flags & LFS_F_INLINE) == 0);
3708-
if (size == oldsize) {
3708+
if (size == 0) {
3709+
// just empty the file
3710+
file->ctz.head = 0;
3711+
file->ctz.size = 0;
3712+
file->flags &= ~LFS_F_FLAT;
3713+
file->flags |= LFS_F_INLINE | LFS_F_DIRTY;
3714+
lfs_alloc_ack(lfs);
3715+
return 0;
3716+
} else if (size == oldsize) {
37093717
// noop
37103718
return 0;
37113719
} else {
@@ -3794,6 +3802,7 @@ static int lfs_file_rawreserve(lfs_t *lfs, lfs_file_t *file, lfs_size_t size, in
37943802
if (flags & LFS_R_ERRED) {
37953803
file->flags |= LFS_F_ERRED;
37963804
}
3805+
lfs_alloc_ack(lfs);
37973806
return LFS_ERR_OK;
37983807
}
37993808

0 commit comments

Comments
 (0)