diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-03-14 17:33:48 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-03-14 17:33:48 -0600 |
commit | 1f5472e87e21553426ededbd28d1759440b8eedf (patch) | |
tree | 4fd1e3268c11dfe6ff9d08af0f2bbe7c1fae3c68 /nuttx/fs | |
parent | 3a81a51177d8aa06ffb2065d997220c076c916de (diff) | |
download | px4-nuttx-1f5472e87e21553426ededbd28d1759440b8eedf.tar.gz px4-nuttx-1f5472e87e21553426ededbd28d1759440b8eedf.tar.bz2 px4-nuttx-1f5472e87e21553426ededbd28d1759440b8eedf.zip |
Fix a bug in the FAT unbind() logic. There were problems with the way certain internal list handling was implemented. The end result is that newly opened or cloned file structures were never being added to the list of open files. So when the unmount() happens, it always looked like there were not open files and a crash could ensue.
Diffstat (limited to 'nuttx/fs')
-rw-r--r-- | nuttx/fs/fat/fs_fat32.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c index 7dd24c733..eb64e83ee 100644 --- a/nuttx/fs/fat/fs_fat32.c +++ b/nuttx/fs/fat/fs_fat32.c @@ -353,7 +353,7 @@ static int fat_open(FAR struct file *filep, const char *relpath, */ ff->ff_next = fs->fs_head; - fs->fs_head = ff->ff_next; + fs->fs_head = ff; fat_semgive(fs); @@ -391,6 +391,8 @@ static int fat_close(FAR struct file *filep) { struct inode *inode; struct fat_file_s *ff; + struct fat_file_s *currff; + struct fat_file_s *prevff; struct fat_mountpt_s *fs; int ret; @@ -412,6 +414,26 @@ static int fat_close(FAR struct file *filep) ret = fat_sync(filep); + /* Remove the file structure from the list of open files in the mountpoint + * structure. + */ + + for (prevff = NULL, currff = fs->fs_head; + currff && currff != ff; + prevff = currff, currff = currff->ff_next); + + if (currff) + { + if (prevff) + { + prevff->ff_next = ff->ff_next; + } + else + { + fs->fs_head = ff->ff_next; + } + } + /* Then deallocate the memory structures created when the open method * was called. * @@ -1408,7 +1430,7 @@ static int fat_dup(FAR const struct file *oldp, FAR struct file *newp) */ newff->ff_next = fs->fs_head; - fs->fs_head = newff->ff_next; + fs->fs_head = newff; fat_semgive(fs); return OK; |