diff options
Diffstat (limited to 'firmware/common/dir.c')
-rw-r--r-- | firmware/common/dir.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/firmware/common/dir.c b/firmware/common/dir.c index 4b4a5fa65d..aa55aeb9e9 100644 --- a/firmware/common/dir.c +++ b/firmware/common/dir.c | |||
@@ -67,6 +67,26 @@ static int strip_volume(const char* name, char* namecopy) | |||
67 | #endif /* #ifdef HAVE_MULTIVOLUME */ | 67 | #endif /* #ifdef HAVE_MULTIVOLUME */ |
68 | 68 | ||
69 | 69 | ||
70 | #ifdef HAVE_HOTSWAP | ||
71 | // release all dir handles on a given volume "by force", to avoid leaks | ||
72 | int release_dirs(int volume) | ||
73 | { | ||
74 | DIR* pdir = opendirs; | ||
75 | int dd; | ||
76 | int closed = 0; | ||
77 | for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++) | ||
78 | { | ||
79 | if (pdir->fatdir.file.volume == volume) | ||
80 | { | ||
81 | pdir->busy = false; /* mark as available, no further action */ | ||
82 | closed++; | ||
83 | } | ||
84 | } | ||
85 | return closed; /* return how many we did */ | ||
86 | } | ||
87 | #endif /* #ifdef HAVE_HOTSWAP */ | ||
88 | |||
89 | |||
70 | DIR* opendir(const char* name) | 90 | DIR* opendir(const char* name) |
71 | { | 91 | { |
72 | char namecopy[MAX_PATH]; | 92 | char namecopy[MAX_PATH]; |
@@ -154,6 +174,10 @@ struct dirent* readdir(DIR* dir) | |||
154 | { | 174 | { |
155 | struct fat_direntry entry; | 175 | struct fat_direntry entry; |
156 | struct dirent* theent = &(dir->theent); | 176 | struct dirent* theent = &(dir->theent); |
177 | |||
178 | if (!dir->busy) | ||
179 | return NULL; | ||
180 | |||
157 | #ifdef HAVE_MULTIVOLUME | 181 | #ifdef HAVE_MULTIVOLUME |
158 | /* Volumes (secondary file systems) get inserted into the root directory | 182 | /* Volumes (secondary file systems) get inserted into the root directory |
159 | of the first volume, since we have no separate top level. */ | 183 | of the first volume, since we have no separate top level. */ |