diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 8b38aa4c822dc09e375bc0518fde01b3923aec03..6957b43bdcab90ddfde116bf0155bb998e502a9f 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -78,6 +78,7 @@ typedef _Bool bool; #define API_FILE_UNLINK 0x4b #define API_FILE_RENAME 0x4c #define API_FILE_MKDIR 0x4d +#define API_FILE_FS_ATTACHED 0x4e #define API_RTC_GET_SECONDS 0x50 #define API_RTC_SCHEDULE_ALARM 0x51 @@ -2064,6 +2065,15 @@ API(API_FILE_RENAME, int epic_file_rename(const char *oldp, const char* newp)); */ API(API_FILE_MKDIR, int epic_file_mkdir(const char *dirname)); +/** + * Check whether the filesystem is currently attached and a call like + * :c:func:`epic_file_open` has a chance to succeed. + * + * :return: ``true`` if the filesystem is attached and ``false`` if the + * filesystem is not attached. + */ +API(API_FILE_FS_ATTACHED, bool epic_fs_is_attached(void)); + /** * RTC * === diff --git a/epicardium/modules/fileops.c b/epicardium/modules/fileops.c index b0be04c5f89db8501756d50113b8025e9c3c7198..2f5e0f0c2d4f35860349e246128e30114a68d1a9 100644 --- a/epicardium/modules/fileops.c +++ b/epicardium/modules/fileops.c @@ -29,6 +29,17 @@ int epic_file_open(const char *filename, const char *mode) return res; } +bool epic_fs_is_attached(void) +{ + EpicFileSystem *fs; + if (efs_lock_global(&fs) == 0) { + efs_unlock_global(fs); + return true; + } else { + return false; + } +} + int epic_file_close(int fd) { EpicFileSystem *fs;