diff --git a/firmware/common/file.c b/firmware/common/file.c
index 3477c10..89fbe4c 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -28,6 +28,8 @@
#include "dircache.h"
#include "filefuncs.h"
#include "system.h"
+#define LOGF_ENABLE
+#include "logf.h"
/*
These functions provide a roughly POSIX-compatible file IO API.
@@ -60,6 +62,20 @@ int file_creat(const char *pathname)
return open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
}
+void dbg_print_open_files(void)
+{
+ char path[MAX_PATH];
+ logf("open files: (*dirty)");
+ for(int i = 0; i < MAX_OPEN_FILES; i++)
+ {
+ if(!openfiles[i].busy)
+ continue;
+ if(!fat_get_file_name(&openfiles[i].fatfile, path, MAX_PATH))
+ strcpy(path, "<error>");
+ logf(" %s%s", openfiles[i].dirty ? "*" : "", path);
+ }
+}
+
static int open_internal(const char* pathname, int flags, bool use_cache)
{
DIR_UNCACHED* dir;
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index f055f4b..568692d 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -2556,3 +2556,25 @@ bool fat_ismounted(int volume)
return (volume<NUM_VOLUMES && fat_bpbs[volume].mounted);
}
#endif
+
+bool fat_get_file_name(struct fat_file *file, char *path, long len)
+{
+ static struct fat_dir dir;
+ struct fat_direntry direntry;
+
+ memset(&dir, 0, sizeof(dir));
+ memset(&direntry, 0, sizeof(direntry));
+
+ int rc = fat_opendir(IF_MV2(file->volume,) &dir, file->dircluster, NULL);
+ if(rc < 0)
+ return false;
+ while(fat_getnext(&dir, &direntry) >= 0)
+ {
+ if(direntry.firstcluster == file->firstcluster || direntry.name[0] == 0)
+ break;
+ }
+ if(direntry.name[0] == 0)
+ return false;
+ strlcpy(path, direntry.name, len);
+ return true;
+}
diff --git a/firmware/export/fat.h b/firmware/export/fat.h
index 36beda7..9550045 100644
--- a/firmware/export/fat.h
+++ b/firmware/export/fat.h
@@ -134,4 +134,6 @@ extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry);
extern unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume)); /* public for debug info screen */
extern bool fat_ismounted(int volume);
+extern bool fat_get_file_name(struct fat_file *file, char *path, long len);
+
#endif
diff --git a/firmware/usb.c b/firmware/usb.c
index ebbf080..25cbe24 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -217,6 +217,9 @@ static inline void usb_slave_mode(bool on)
int rc;
if(on)
+ dbg_print_open_files();
+
+ if(on)
{
trigger_cpu_boost();
#ifdef HAVE_PRIORITY_SCHEDULING