diff --git a/firmware/common/disk.c b/firmware/common/disk.c index 2908bec..bf004d6 100644 --- a/firmware/common/disk.c +++ b/firmware/common/disk.c @@ -263,6 +263,7 @@ int disk_unmount(int drive) return unmounted; } +#include "splash.h" int disk_unmount_all(void) { int unmounted = 0; @@ -270,15 +271,25 @@ int disk_unmount_all(void) #ifdef HAVE_HOTSWAP mutex_lock(&disk_mutex); #endif + + dbg_print_open_files(); + for (i=0; i= 0) { + int foo; vol_drive[i] = -1; /* mark unused */ unmounted++; - close_files(i); - release_dirs(i); - fat_unmount(i, true); + foo = close_files(i); + if (foo) + splashf(HZ*2, "closed %d files", foo); + foo = release_dirs(i); + if (foo) + splashf(HZ*2, "released %d dirs", foo); + foo = fat_unmount(i, true); + if (foo) + splashf(HZ*2, "umount returns %d", foo); } } #ifdef HAVE_HOTSWAP diff --git a/firmware/common/file.c b/firmware/common/file.c index 447b586..4ff4aa6 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,26 @@ int file_creat(const char *pathname) return open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 0666); } +void dbg_print_open_files(void) +{ + bool logfdump(void); + + static char path[MAX_PATH]; + bool found = false; + 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, ""); + logf(" %s%s", openfiles[i].dirty ? "*" : "", path); + found |= true; + } + if (found) + logfdump(); +} + static int open_internal(const char* pathname, int flags, bool use_cache) { DIR_UNCACHED* dir; @@ -845,6 +867,7 @@ int close_files(int volume) struct filedesc* pfile = openfiles; int fd; int closed = 0; + int dirty = 1; for ( fd=0; fdbusy) { + if (pfile->dirty) + dirty = -1; close(fd); closed++; } } } - return closed; /* return how many we did */ + return dirty * closed; /* return how many we did */ } diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index a4eb24c..40b8c9d 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -2662,3 +2662,25 @@ bool fat_ismounted(int volume) return (volumevolume,) &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 1551107..df6f8a6 100644 --- a/firmware/export/fat.h +++ b/firmware/export/fat.h @@ -137,4 +137,6 @@ extern bool fat_ismounted(int volume); extern void* fat_get_sector_buffer(void); extern void fat_release_sector_buffer(void); +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 aada27d..e5512b3 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -77,7 +77,7 @@ static int usb_mmc_countdown = 0; /* Make sure there's enough stack space for screendump */ #ifdef USB_FULL_INIT -static long usb_stack[(DEFAULT_STACK_SIZE + DUMP_BMP_LINESIZE)/sizeof(long)]; +static long usb_stack[(DEFAULT_STACK_SIZE + DUMP_BMP_LINESIZE + 512)/sizeof(long)]; static const char usb_thread_name[] = "usb"; static unsigned int usb_thread_entry = 0; static bool usb_monitor_enabled = false;