aboutsummaryrefslogtreecommitdiff
path: root/nuttx/fs
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-14 15:42:03 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-14 15:42:03 +0000
commit930f9a13511a6d9bc2e44fadef42f6345d921667 (patch)
treebc136f7b1fa5989900d1b0e856571e51d96998dc /nuttx/fs
parentb3f3dd123c181fe851f0a9756bed7acd4ba4ef7d (diff)
downloadpx4-firmware-930f9a13511a6d9bc2e44fadef42f6345d921667.tar.gz
px4-firmware-930f9a13511a6d9bc2e44fadef42f6345d921667.tar.bz2
px4-firmware-930f9a13511a6d9bc2e44fadef42f6345d921667.zip
Add support for dup2'ing files. Infrastructure and ROMFS done. Still need FAT, BINFS, NXFFS, and NFS
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5516 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/fat/fs_fat32.c46
-rw-r--r--nuttx/fs/fs_files.c18
-rw-r--r--nuttx/fs/nfs/nfs_vfsops.c2
-rw-r--r--nuttx/fs/nxffs/nxffs_initialize.c2
-rw-r--r--nuttx/fs/romfs/fs_romfs.c245
-rw-r--r--nuttx/fs/romfs/fs_romfs.h1
-rw-r--r--nuttx/fs/romfs/fs_romfsutil.c12
7 files changed, 209 insertions, 117 deletions
diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c
index 0c28cea67..788e6bebc 100644
--- a/nuttx/fs/fat/fs_fat32.c
+++ b/nuttx/fs/fat/fs_fat32.c
@@ -121,28 +121,30 @@ static int fat_stat(struct inode *mountpt, const char *relpath, struct stat
const struct mountpt_operations fat_operations =
{
- fat_open,
- fat_close,
- fat_read,
- fat_write,
- fat_seek,
- fat_ioctl,
- fat_sync,
-
- fat_opendir,
- NULL,
- fat_readdir,
- fat_rewinddir,
-
- fat_bind,
- fat_unbind,
- fat_statfs,
-
- fat_unlink,
- fat_mkdir,
- fat_rmdir,
- fat_rename,
- fat_stat
+ fat_open, /* open */
+ fat_close, /* close */
+ fat_read, /* read */
+ fat_write, /* write */
+ fat_seek, /* seek */
+ fat_ioctl, /* ioctl */
+
+ fat_sync, /* sync */
+ NULL, /* dup */
+
+ fat_opendir, /* opendir */
+ NULL, /* closedir */
+ fat_readdir, /* readdir */
+ fat_rewinddir, /* rewinddir */
+
+ fat_bind, /* bind */
+ fat_unbind, /* unbind */
+ fat_statfs, /* statfs */
+
+ fat_unlink, /* unlinke */
+ fat_mkdir, /* mkdir */
+ fat_rmdir, /* rmdir */
+ fat_rename, /* rename */
+ fat_stat /* stat */
};
/****************************************************************************
diff --git a/nuttx/fs/fs_files.c b/nuttx/fs/fs_files.c
index 4da2d28a5..06addb1ef 100644
--- a/nuttx/fs/fs_files.c
+++ b/nuttx/fs/fs_files.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/fs_files.c
*
- * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -284,14 +284,6 @@ int files_dup(FAR struct file *filep1, FAR struct file *filep2)
goto errout;
}
-#ifndef CONFIG_DISABLE_MOUNTPOINT
- if (INODE_IS_MOUNTPT(filep1->f_inode))
- {
- err = ENOSYS; /* Not yet supported */
- goto errout;
- }
-#endif
-
list = sched_getfiles();
if (!list)
{
@@ -331,18 +323,16 @@ int files_dup(FAR struct file *filep1, FAR struct file *filep2)
if (inode->u.i_ops && inode->u.i_ops->open)
{
#ifndef CONFIG_DISABLE_MOUNTPOINT
-#if 0 /* Not implemented */
if (INODE_IS_MOUNTPT(inode))
{
- /* Open a file on the mountpoint */
+ /* Dup the open file on the in the new file structure */
- ret = inode->u.i_mops->open(filep2, ?, filep2->f_oflags, ?);
+ ret = inode->u.i_mops->dup(filep1, filep2);
}
else
#endif
-#endif
{
- /* Open the pseudo file or device driver */
+ /* (Re-)open the pseudo file or device driver */
ret = inode->u.i_ops->open(filep2);
}
diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c
index 3cd5a47dc..efb026c7f 100644
--- a/nuttx/fs/nfs/nfs_vfsops.c
+++ b/nuttx/fs/nfs/nfs_vfsops.c
@@ -166,7 +166,9 @@ const struct mountpt_operations nfs_operations =
nfs_write, /* write */
NULL, /* seek */
NULL, /* ioctl */
+
NULL, /* sync */
+ NULL, /* dup */
nfs_opendir, /* opendir */
NULL, /* closedir */
diff --git a/nuttx/fs/nxffs/nxffs_initialize.c b/nuttx/fs/nxffs/nxffs_initialize.c
index 6d93a318a..0aa424869 100644
--- a/nuttx/fs/nxffs/nxffs_initialize.c
+++ b/nuttx/fs/nxffs/nxffs_initialize.c
@@ -82,7 +82,9 @@ const struct mountpt_operations nxffs_operations =
nxffs_write, /* write */
NULL, /* seek -- Use f_pos in struct file */
nxffs_ioctl, /* ioctl */
+
NULL, /* sync -- No buffered data */
+ NULL, /* dup -- not implemented */
nxffs_opendir, /* opendir */
NULL, /* closedir */
diff --git a/nuttx/fs/romfs/fs_romfs.c b/nuttx/fs/romfs/fs_romfs.c
index b95619d75..de87c7fec 100644
--- a/nuttx/fs/romfs/fs_romfs.c
+++ b/nuttx/fs/romfs/fs_romfs.c
@@ -70,24 +70,33 @@
* Private Function Prototypes
****************************************************************************/
-static int romfs_open(FAR struct file *filep, const char *relpath,
+static int romfs_open(FAR struct file *filep, FAR const char *relpath,
int oflags, mode_t mode);
static int romfs_close(FAR struct file *filep);
-static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen);
+static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
+ size_t buflen);
static off_t romfs_seek(FAR struct file *filep, off_t offset, int whence);
-static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int romfs_ioctl(FAR struct file *filep, int cmd,
+ unsigned long arg);
-static int romfs_opendir(struct inode *mountpt, const char *relpath,
- struct fs_dirent_s *dir);
-static int romfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir);
-static int romfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir);
+static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp);
-static int romfs_bind(FAR struct inode *blkdriver, const void *data,
- void **handle);
-static int romfs_unbind(void *handle, FAR struct inode **blkdriver);
-static int romfs_statfs(struct inode *mountpt, struct statfs *buf);
+static int romfs_opendir(FAR struct inode *mountpt,
+ FAR const char *relpath,
+ FAR struct fs_dirent_s *dir);
+static int romfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir);
+static int romfs_rewinddir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir);
-static int romfs_stat(struct inode *mountpt, const char *relpath, struct stat *buf);
+static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
+ FAR void **handle);
+static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver);
+static int romfs_statfs(FAR struct inode *mountpt,
+ FAR struct statfs *buf);
+
+static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct stat *buf);
/****************************************************************************
* Private Variables
@@ -110,7 +119,9 @@ const struct mountpt_operations romfs_operations =
NULL, /* write */
romfs_seek, /* seek */
romfs_ioctl, /* ioctl */
+
NULL, /* sync */
+ romfs_dup, /* dup */
romfs_opendir, /* opendir */
NULL, /* closedir */
@@ -136,13 +147,13 @@ const struct mountpt_operations romfs_operations =
* Name: romfs_open
****************************************************************************/
-static int romfs_open(FAR struct file *filep, const char *relpath,
- int oflags, mode_t mode)
+static int romfs_open(FAR struct file *filep, FAR const char *relpath,
+ int oflags, mode_t mode)
{
- struct romfs_dirinfo_s dirinfo;
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- int ret;
+ struct romfs_dirinfo_s dirinfo;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ int ret;
fvdbg("Open '%s'\n", relpath);
@@ -150,11 +161,11 @@ static int romfs_open(FAR struct file *filep, const char *relpath,
DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL);
- /* mountpoint private data from the inode reference from the file
+ /* Get mountpoint private data from the inode reference from the file
* structure
*/
- rm = (struct romfs_mountpt_s*)filep->f_inode->i_private;
+ rm = (FAR struct romfs_mountpt_s*)filep->f_inode->i_private;
DEBUGASSERT(rm != NULL);
@@ -214,7 +225,7 @@ static int romfs_open(FAR struct file *filep, const char *relpath,
* file.
*/
- rf = (struct romfs_file_s *)zalloc(sizeof(struct romfs_file_s));
+ rf = (FAR struct romfs_file_s *)zalloc(sizeof(struct romfs_file_s));
if (!rf)
{
fdbg("Failed to allocate private data\n", ret);
@@ -226,8 +237,7 @@ static int romfs_open(FAR struct file *filep, const char *relpath,
* non-zero elements)
*/
- rf->rf_open = true;
- rf->rf_size = dirinfo.rd_size;
+ rf->rf_size = dirinfo.rd_size;
/* Get the start of the file data */
@@ -277,9 +287,9 @@ errout_with_semaphore:
static int romfs_close(FAR struct file *filep)
{
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- int ret = OK;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ int ret = OK;
fvdbg("Closing\n");
@@ -321,19 +331,20 @@ static int romfs_close(FAR struct file *filep)
* Name: romfs_read
****************************************************************************/
-static ssize_t romfs_read(FAR struct file *filep, char *buffer, size_t buflen)
+static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
+ size_t buflen)
{
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- unsigned int bytesread;
- unsigned int readsize;
- unsigned int nsectors;
- uint32_t offset;
- size_t bytesleft;
- off_t sector;
- uint8_t *userbuffer = (uint8_t*)buffer;
- int sectorndx;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ unsigned int bytesread;
+ unsigned int readsize;
+ unsigned int nsectors;
+ uint32_t offset;
+ size_t bytesleft;
+ off_t sector;
+ FAR uint8_t *userbuffer = (FAR uint8_t*)buffer;
+ int sectorndx;
+ int ret;
fvdbg("Read %d bytes from offset %d\n", buflen, filep->f_pos);
@@ -467,10 +478,10 @@ errout_with_semaphore:
static off_t romfs_seek(FAR struct file *filep, off_t offset, int whence)
{
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- off_t position;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ off_t position;
+ int ret;
fvdbg("Seek to offset: %d whence: %d\n", offset, whence);
@@ -548,9 +559,9 @@ errout_with_semaphore:
static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
- struct romfs_mountpt_s *rm;
- struct romfs_file_s *rf;
- FAR void **ppv = (FAR void**)arg;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *rf;
+ FAR void **ppv = (FAR void**)arg;
fvdbg("cmd: %d arg: %08lx\n", cmd, arg);
@@ -582,6 +593,95 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
}
/****************************************************************************
+ * Name: romfs_dup
+ ****************************************************************************/
+
+static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp)
+{
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_file_s *oldrf;
+ FAR struct romfs_file_s *newrf;
+ int ret;
+
+ fvdbg("Dup %p->%p\n", oldp, newp);
+
+ /* Sanity checks */
+
+ DEBUGASSERT(oldp->f_priv != NULL &&
+ newp->f_priv == NULL &&
+ newp->f_inode != NULL);
+
+ /* Get mountpoint private data from the inode reference from the file
+ * structure
+ */
+
+ rm = (FAR struct romfs_mountpt_s*)newp->f_inode->i_private;
+ DEBUGASSERT(rm != NULL);
+
+ /* Check if the mount is still healthy */
+
+ romfs_semtake(rm);
+ ret = romfs_checkmount(rm);
+ if (ret != OK)
+ {
+ fdbg("romfs_checkmount failed: %d\n", ret);
+ goto errout_with_semaphore;
+ }
+
+ /* Recover the old private data from the old struct file instance */
+
+ oldrf = oldp->f_priv;
+
+ /* Create an new instance of the file private data to describe the new
+ * dup'ed file.
+ */
+
+ newrf = (FAR struct romfs_file_s *)malloc(sizeof(struct romfs_file_s));
+ if (!newrf)
+ {
+ fdbg("Failed to allocate private data\n", ret);
+ ret = -ENOMEM;
+ goto errout_with_semaphore;
+ }
+
+ /* Copy all file private data (except for the buffer) */
+
+ newrf->rf_startoffset = oldrf->rf_startoffset;
+ newrf->rf_size = oldrf->rf_size;
+
+ /* Configure buffering to support access to this file */
+
+ ret = romfs_fileconfigure(rm, newrf);
+ if (ret < 0)
+ {
+ fdbg("Failed configure buffering: %d\n", ret);
+ goto errout_with_semaphore;
+ }
+
+ /* Attach the new private date to the new struct file instance */
+
+ newp->f_priv = newrf;
+
+ /* Then insert the new instance into the mountpoint structure.
+ * It needs to be there (1) to handle error conditions that effect
+ * all files, and (2) to inform the umount logic that we are busy
+ * (but a simple reference count could have done that).
+ */
+
+ newrf->rf_next = rm->rm_head;
+ rm->rm_head = newrf->rf_next;
+
+ romfs_semgive(rm);
+ return OK;
+
+ /* Error exits */
+
+errout_with_semaphore:
+ romfs_semgive(rm);
+ return ret;
+}
+
+/****************************************************************************
* Name: romfs_opendir
*
* Description:
@@ -589,12 +689,12 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
*
****************************************************************************/
-static int romfs_opendir(struct inode *mountpt, const char *relpath,
- struct fs_dirent_s *dir)
+static int romfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct fs_dirent_s *dir)
{
- struct romfs_mountpt_s *rm;
- struct romfs_dirinfo_s dirinfo;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_dirinfo_s dirinfo;
+ int ret;
fvdbg("relpath: '%s'\n", relpath);
@@ -654,14 +754,15 @@ errout_with_semaphore:
*
****************************************************************************/
-static int romfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int romfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir)
{
- struct romfs_mountpt_s *rm;
- uint32_t linkoffset;
- uint32_t next;
- uint32_t info;
- uint32_t size;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ uint32_t linkoffset;
+ uint32_t next;
+ uint32_t info;
+ uint32_t size;
+ int ret;
fvdbg("Entry\n");
@@ -749,9 +850,10 @@ errout_with_semaphore:
*
****************************************************************************/
-static int romfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int romfs_rewinddir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir)
{
- struct romfs_mountpt_s *rm;
+ FAR struct romfs_mountpt_s *rm;
int ret;
fvdbg("Entry\n");
@@ -788,8 +890,8 @@ static int romfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir)
*
****************************************************************************/
-static int romfs_bind(FAR struct inode *blkdriver, const void *data,
- void **handle)
+static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
+ FAR void **handle)
{
struct romfs_mountpt_s *rm;
int ret;
@@ -813,7 +915,7 @@ static int romfs_bind(FAR struct inode *blkdriver, const void *data,
/* Create an instance of the mountpt state structure */
- rm = (struct romfs_mountpt_s *)zalloc(sizeof(struct romfs_mountpt_s));
+ rm = (FAR struct romfs_mountpt_s *)zalloc(sizeof(struct romfs_mountpt_s));
if (!rm)
{
fdbg("Failed to allocate mountpoint structure\n");
@@ -874,9 +976,9 @@ errout_with_sem:
*
****************************************************************************/
-static int romfs_unbind(void *handle, FAR struct inode **blkdriver)
+static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver)
{
- struct romfs_mountpt_s *rm = (struct romfs_mountpt_s*)handle;
+ FAR struct romfs_mountpt_s *rm = (FAR struct romfs_mountpt_s*)handle;
int ret;
fvdbg("Entry\n");
@@ -948,10 +1050,10 @@ static int romfs_unbind(void *handle, FAR struct inode **blkdriver)
*
****************************************************************************/
-static int romfs_statfs(struct inode *mountpt, struct statfs *buf)
+static int romfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
{
- struct romfs_mountpt_s *rm;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ int ret;
fvdbg("Entry\n");
@@ -1004,11 +1106,12 @@ errout_with_semaphore:
*
****************************************************************************/
-static int romfs_stat(struct inode *mountpt, const char *relpath, struct stat *buf)
+static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
+ FAR struct stat *buf)
{
- struct romfs_mountpt_s *rm;
- struct romfs_dirinfo_s dirinfo;
- int ret;
+ FAR struct romfs_mountpt_s *rm;
+ FAR struct romfs_dirinfo_s dirinfo;
+ int ret;
fvdbg("Entry\n");
diff --git a/nuttx/fs/romfs/fs_romfs.h b/nuttx/fs/romfs/fs_romfs.h
index 4081517fb..6a337d2c5 100644
--- a/nuttx/fs/romfs/fs_romfs.h
+++ b/nuttx/fs/romfs/fs_romfs.h
@@ -159,7 +159,6 @@ struct romfs_mountpt_s
struct romfs_file_s
{
struct romfs_file_s *rf_next; /* Retained in a singly linked list */
- bool rf_open; /* true: The file is (still) open */
uint32_t rf_startoffset; /* Offset to the start of the file data */
uint32_t rf_size; /* Size of the file in bytes */
uint32_t rf_cachesector; /* Current sector in the rf_buffer */
diff --git a/nuttx/fs/romfs/fs_romfsutil.c b/nuttx/fs/romfs/fs_romfsutil.c
index 6ea114b5e..4857fb6d3 100644
--- a/nuttx/fs/romfs/fs_romfsutil.c
+++ b/nuttx/fs/romfs/fs_romfsutil.c
@@ -613,7 +613,7 @@ int romfs_fsconfigure(struct romfs_mountpt_s *rm)
}
/****************************************************************************
- * Name: romfs_ffileconfigure
+ * Name: romfs_fileconfigure
*
* Desciption:
* This function is called as part of the ROMFS file open operation It
@@ -649,6 +649,7 @@ int romfs_fileconfigure(struct romfs_mountpt_s *rm, struct romfs_file_s *rf)
return -ENOMEM;
}
}
+
return OK;
}
@@ -663,7 +664,6 @@ int romfs_fileconfigure(struct romfs_mountpt_s *rm, struct romfs_file_s *rf)
int romfs_checkmount(struct romfs_mountpt_s *rm)
{
- struct romfs_file_s *file;
struct inode *inode;
struct geometry geo;
int ret;
@@ -692,14 +692,8 @@ int romfs_checkmount(struct romfs_mountpt_s *rm)
/* If we get here, the mount is NOT healthy */
rm->rm_mounted = false;
-
- /* Make sure that this is flagged in every opened file */
-
- for (file = rm->rm_head; file; file = file->rf_next)
- {
- file->rf_open = false;
- }
}
+
return -ENODEV;
}