diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-03-20 15:26:50 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-03-20 15:26:50 +0000 |
commit | 3d7ed16eabcbea16723b66df2cd2a7d10ba22474 (patch) | |
tree | db1cebf1b882206a0c01eb0e8fee552b6667443b /nuttx/fs/fat/fs_fat32.c | |
parent | 14a689eafb060d06234357c70a29630d9bfd502f (diff) | |
download | px4-nuttx-3d7ed16eabcbea16723b66df2cd2a7d10ba22474.tar.gz px4-nuttx-3d7ed16eabcbea16723b66df2cd2a7d10ba22474.tar.bz2 px4-nuttx-3d7ed16eabcbea16723b66df2cd2a7d10ba22474.zip |
Fix a FAT error when trying to create file in a non-existent directory. Reported by Andrew Tridgell.
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5764 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs/fat/fs_fat32.c')
-rw-r--r-- | nuttx/fs/fat/fs_fat32.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c index 7202bb63d..c9167b3b4 100644 --- a/nuttx/fs/fat/fs_fat32.c +++ b/nuttx/fs/fat/fs_fat32.c @@ -260,6 +260,12 @@ static int fat_open(FAR struct file *filep, const char *relpath, /* fall through to finish the file open operations */ } + + /* ENOENT would be returned by fat_finddirentry() if the full + * directory path was found, but the file was not found in the + * final directory. + */ + else if (ret == -ENOENT) { /* The file does not exist. Were we asked to create it? */ @@ -284,6 +290,9 @@ static int fat_open(FAR struct file *filep, const char *relpath, direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset]; } + + /* No other error is handled */ + else { /* An error occurred while checking for file existence -- @@ -1406,6 +1415,7 @@ static int fat_opendir(struct inode *mountpt, const char *relpath, struct fs_dir { goto errout_with_semaphore; } + direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset]; /* Check if this is the root directory */ @@ -1942,11 +1952,20 @@ static int fat_mkdir(struct inode *mountpt, const char *relpath, mode_t mode) ret = fat_finddirentry(fs, &dirinfo, relpath); - /* If anything exists at this location, then we fail with EEXIST */ + /* Or if any error occurs other -ENOENT, then return the error. For + * example, if one of the earlier directory path segments was not found + * then ENOTDIR will be returned. + */ - if (ret == OK) + if (ret != -ENOENT) { - ret = -EEXIST; + /* If anything exists at this location, then we fail with EEXIST */ + + if (ret == OK) + { + ret = -EEXIST; + } + goto errout_with_semaphore; } @@ -2224,13 +2243,6 @@ int fat_rename(struct inode *mountpt, const char *oldrelpath, /* Now find the directory where we should create the newpath object */ ret = fat_finddirentry(fs, &dirinfo, newrelpath); - if (ret == OK) - { - /* It is an error if the object at newrelpath already exists */ - - ret = -EEXIST; - goto errout_with_semaphore; - } /* What we expect is -ENOENT mean that the full directory path was * followed but that the object does not exists in the terminal directory. @@ -2238,6 +2250,13 @@ int fat_rename(struct inode *mountpt, const char *oldrelpath, if (ret != -ENOENT) { + if (ret == OK) + { + /* It is an error if the object at newrelpath already exists */ + + ret = -EEXIST; + } + goto errout_with_semaphore; } |