1. diff --git a/firmware/common/file.c b/firmware/common/file.c
  2. index 3477c10..89fbe4c 100644
  3. --- a/firmware/common/file.c
  4. +++ b/firmware/common/file.c
  5. @@ -28,6 +28,8 @@
  6.  #include "dircache.h"
  7.  #include "filefuncs.h"
  8.  #include "system.h"
  9. +#define LOGF_ENABLE
  10. +#include "logf.h"
  11.  
  12.  /*
  13.    These functions provide a roughly POSIX-compatible file IO API.
  14. @@ -60,6 +62,20 @@ int file_creat(const char *pathname)
  15.      return open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
  16.  }
  17.  
  18. +void dbg_print_open_files(void)
  19. +{
  20. +    char path[MAX_PATH];
  21. +    logf("open files: (*dirty)");
  22. +    for(int  i = 0; i < MAX_OPEN_FILES; i++)
  23. +    {
  24. +        if(!openfiles[i].busy)
  25. +            continue;
  26. +        if(!fat_get_file_name(&openfiles[i].fatfile, path, MAX_PATH))
  27. +            strcpy(path, "<error>");
  28. +        logf("  %s%s", openfiles[i].dirty ? "*" : "", path);
  29. +    }
  30. +}
  31. +
  32.  static int open_internal(const char* pathname, int flags, bool use_cache)
  33.  {
  34.      DIR_UNCACHED* dir;
  35. diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
  36. index f055f4b..568692d 100644
  37. --- a/firmware/drivers/fat.c
  38. +++ b/firmware/drivers/fat.c
  39. @@ -2556,3 +2556,25 @@ bool fat_ismounted(int volume)
  40.      return (volume<NUM_VOLUMES && fat_bpbs[volume].mounted);
  41.  }
  42.  #endif
  43. +
  44. +bool fat_get_file_name(struct fat_file *file, char *path, long len)
  45. +{
  46. +    static struct fat_dir dir;
  47. +    struct fat_direntry direntry;
  48. +
  49. +    memset(&dir, 0, sizeof(dir));
  50. +    memset(&direntry, 0, sizeof(direntry));
  51. +
  52. +    int rc = fat_opendir(IF_MV2(file->volume,) &dir, file->dircluster, NULL);
  53. +    if(rc < 0)
  54. +        return false;
  55. +    while(fat_getnext(&dir, &direntry) >= 0)
  56. +    {
  57. +        if(direntry.firstcluster == file->firstcluster || direntry.name[0] == 0)
  58. +            break;
  59. +    }
  60. +    if(direntry.name[0] == 0)
  61. +        return false;
  62. +    strlcpy(path, direntry.name, len);
  63. +    return true;
  64. +}
  65. diff --git a/firmware/export/fat.h b/firmware/export/fat.h
  66. index 36beda7..9550045 100644
  67. --- a/firmware/export/fat.h
  68. +++ b/firmware/export/fat.h
  69. @@ -134,4 +134,6 @@ extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry);
  70.  extern unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume)); /* public for debug info screen */
  71.  extern bool fat_ismounted(int volume);
  72.  
  73. +extern bool fat_get_file_name(struct fat_file *file, char *path, long len);
  74. +
  75.  #endif
  76. diff --git a/firmware/usb.c b/firmware/usb.c
  77. index ebbf080..25cbe24 100644
  78. --- a/firmware/usb.c
  79. +++ b/firmware/usb.c
  80. @@ -217,6 +217,9 @@ static inline void usb_slave_mode(bool on)
  81.      int rc;
  82.  
  83.      if(on)
  84. +        dbg_print_open_files();
  85. +
  86. +    if(on)
  87.      {
  88.          trigger_cpu_boost();
  89.  #ifdef HAVE_PRIORITY_SCHEDULING