Finish dup logic for open files; fix bug in sigtimedwait(), would return wrong signo value if the signal was already pending

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5517 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2013-01-14 19:22:32 +00:00
parent 555e3fe1f5
commit 5a2eda210b
17 changed files with 333 additions and 102 deletions
+21 -20
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nxffs/nxffs.h
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References: Linux/Documentation/filesystems/romfs.txt
@@ -1044,6 +1044,7 @@ extern int nxffs_pack(FAR struct nxffs_volume_s *volume);
* - nxffs_read() is defined in nxffs_read.c
* - nxffs_write() is defined in nxffs_write.c
* - nxffs_ioctl() is defined in nxffs_ioctl.c
* - nxffs_dup() is defined in nxffs_open.c
* - nxffs_opendir(), nxffs_readdir(), and nxffs_rewindir() are defined in
* nxffs_dirent.c
* - nxffs_bind() and nxffs_unbind() are defined in nxffs_initialize.c
@@ -1058,25 +1059,25 @@ struct fs_dirent_s;
struct statfs;
struct stat;
extern int nxffs_open(FAR struct file *filep, FAR const char *relpath,
int oflags, mode_t mode);
extern int nxffs_close(FAR struct file *filep);
extern ssize_t nxffs_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
extern ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
extern int nxffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
extern int nxffs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct fs_dirent_s *dir);
extern int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
extern int nxffs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
extern int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
FAR void **handle);
extern int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver);
extern int nxffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf);
extern int nxffs_stat(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct stat *buf);
extern int nxffs_unlink(FAR struct inode *mountpt, FAR const char *relpath);
int nxffs_open(FAR struct file *filep, FAR const char *relpath, int oflags,
mode_t mode);
int nxffs_close(FAR struct file *filep);
ssize_t nxffs_read(FAR struct file *filep, FAR char *buffer, size_t buflen);
ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
int nxffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
int nxffs_dup(FAR const struct file *oldp, FAR struct file *newp);
int nxffs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct fs_dirent_s *dir);
int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
int nxffs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
FAR void **handle);
int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver);
int nxffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf);
int nxffs_stat(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct stat *buf);
int nxffs_unlink(FAR struct inode *mountpt, FAR const char *relpath);
#endif /* __FS_NXFFS_NXFFS_H */
+2 -2
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nxffs/nxffs_initialize.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References: Linux/Documentation/filesystems/romfs.txt
@@ -84,7 +84,7 @@ const struct mountpt_operations nxffs_operations =
nxffs_ioctl, /* ioctl */
NULL, /* sync -- No buffered data */
NULL, /* dup -- not implemented */
nxffs_dup, /* dup */
nxffs_opendir, /* opendir */
NULL, /* closedir */
+60 -2
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/nxffs/nxffs_open.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References: Linux/Documentation/filesystems/romfs.txt
@@ -1023,7 +1023,7 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath,
#endif
/* Limitation: A file must be opened for reading or writing, but not both.
* There is no general for extending the size of of a file. Extending the
* There is no general way of extending the size of a file. Extending the
* file size of possible if the file to be extended is the last in the
* sequence on FLASH, but since that case is not the general case, no file
* extension is supported.
@@ -1058,6 +1058,64 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath,
return ret;
}
/****************************************************************************
* Name: binfs_dup
*
* Description:
* Duplicate open file data in the new file structure.
*
****************************************************************************/
int nxffs_dup(FAR const struct file *oldp, FAR struct file *newp)
{
#ifdef CONFIG_DEBUG
FAR struct nxffs_volume_s *volume;
#endif
FAR struct nxffs_ofile_s *ofile;
fvdbg("Dup %p->%p\n", oldp, newp);
/* Sanity checks */
#ifdef CONFIG_DEBUG
DEBUGASSERT(oldp->f_priv == NULL && oldp->f_inode != NULL);
/* Get the mountpoint private data from the NuttX inode reference in the
* file structure
*/
volume = (FAR struct nxffs_volume_s*)oldp->f_inode->i_private;
DEBUGASSERT(volume != NULL);
#endif
/* Recover the open file state from the struct file instance */
ofile = (FAR struct nxffs_ofile_s *)oldp->f_priv;
/* I do not think we need exclusive access to the volume to do this.
* The volume exclsem protects the open file list and, hence, would
* assure that the ofile is stable. However, it is assumed that the
* caller holds a value file descriptor associated with this ofile,
* so it should be stable throughout the life of this function.
*/
/* Limitations: I do not think we have to be concerned about the
* usual NXFFS file limitations here: dup'ing cannot resulting
* in mixed reading and writing to the same file, or multiple
* writer to different file.
*
* I notice that nxffs_wropen will prohibit multiple opens for
* writing. But I do not thing that dup'ing a file already opened
* for writing suffers from any of these issues.
*/
/* Just increment the reference count on the ofile */
ofile->crefs++;
newp->f_priv = (FAR void *)ofile;
return OK;
}
/****************************************************************************
* Name: nxffs_close
*