diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-10-04 22:07:45 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-10-04 22:07:45 +0000 |
commit | 3a98bf08829c7e986161db7968b6e98fbabdac16 (patch) | |
tree | 9449582c85031b81f0e98355fe0ddbd420e581a0 /nuttx | |
parent | 68c47baf9fce581d0078384ef0fcdb6436292fcb (diff) | |
download | px4-nuttx-3a98bf08829c7e986161db7968b6e98fbabdac16.tar.gz px4-nuttx-3a98bf08829c7e986161db7968b6e98fbabdac16.tar.bz2 px4-nuttx-3a98bf08829c7e986161db7968b6e98fbabdac16.zip |
Fix check for open files when overwriting an existing file
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4019 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/fs/nxffs/nxffs_open.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/nuttx/fs/nxffs/nxffs_open.c b/nuttx/fs/nxffs/nxffs_open.c index 99998350b..c00e2ea6d 100644 --- a/nuttx/fs/nxffs/nxffs_open.c +++ b/nuttx/fs/nxffs/nxffs_open.c @@ -423,11 +423,27 @@ static inline int nxffs_wropen(FAR struct nxffs_volume_s *volume, ret = nxffs_findinode(volume, name, &entry); if (ret == OK) { - /* It exists. It would be an error if we are asked to create it + FAR struct nxffs_ofile_s *ofile; + + /* It exists. Is the file already open for reading? */ + + ofile = nxffs_findofile(volume, name); + if (ofile) + { + /* The file is already open. + * Limitation: Files cannot be open both for reading and writing. + */ + + fdbg("File is open for reading\n"); + ret = -ENOSYS; + goto errout_with_exclsem; + } + + /* It would be an error if we are asked to create the file * exclusively. */ - if ((oflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) + else if ((oflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) { fdbg("File exists, can't create O_EXCL\n"); ret = -EEXIST; |