From 8da59161e4e4954868bf60cf267e5dd427957ee0 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Sun, 20 Apr 2025 17:58:43 -0400 Subject: [PATCH] filesystem: prevent lockup when flash is nearly full --- filesystem/filesystem.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index 741430ec..e67cb8cc 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -252,6 +252,11 @@ static void filesystem_cat(char *filename) { } bool filesystem_write_file(char *filename, char *text, int32_t length) { + if (filesystem_get_free_space() <= 256) { + printf("No free space!\n"); + return false; + } + int err = lfs_file_open(&eeprom_filesystem, &file, filename, LFS_O_RDWR | LFS_O_CREAT | LFS_O_TRUNC); if (err < 0) return false; err = lfs_file_write(&eeprom_filesystem, &file, text, length); @@ -260,6 +265,11 @@ bool filesystem_write_file(char *filename, char *text, int32_t length) { } bool filesystem_append_file(char *filename, char *text, int32_t length) { + if (filesystem_get_free_space() <= 256) { + printf("No free space!\n"); + return false; + } + int err = lfs_file_open(&eeprom_filesystem, &file, filename, LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND); if (err < 0) return false; err = lfs_file_write(&eeprom_filesystem, &file, text, length);