summaryrefslogtreecommitdiff
path: root/nuttx/fs
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-12-12 11:08:20 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-12-12 11:08:20 -0600
commitc59dbf885797fd6b4e6c1af4bdbe09148f9a300d (patch)
tree4d0d1e3fe5c85d13b3fd4886c0782d1cf58e1da0 /nuttx/fs
parent6d1a08d951f3142833d30f9835a3889288e5d886 (diff)
downloadnuttx-c59dbf885797fd6b4e6c1af4bdbe09148f9a300d.tar.gz
nuttx-c59dbf885797fd6b4e6c1af4bdbe09148f9a300d.tar.bz2
nuttx-c59dbf885797fd6b4e6c1af4bdbe09148f9a300d.zip
Various fixes to the recent, big procfs checkin
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/procfs/fs_procfs.c12
-rw-r--r--nuttx/fs/procfs/fs_procfsproc.c32
2 files changed, 32 insertions, 12 deletions
diff --git a/nuttx/fs/procfs/fs_procfs.c b/nuttx/fs/procfs/fs_procfs.c
index 2bd091bb6..a44d00f93 100644
--- a/nuttx/fs/procfs/fs_procfs.c
+++ b/nuttx/fs/procfs/fs_procfs.c
@@ -384,6 +384,7 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct fs_dirent_s *dir)
{
FAR struct procfs_level0_s *level0;
+ FAR struct procfs_dir_priv_s *dirpriv;
FAR void *priv = NULL;
irqstate_t flags;
@@ -448,7 +449,10 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
if (match(g_procfsentries[x].pathpattern, relpath))
{
- /* Match found! Call the handler's opendir routine */
+ /* Match found! Call the handler's opendir routine. If successful,
+ * this opendir routine will create an entry derived from struct
+ * procfs_dir_priv_s as dir->u.procfs.
+ */
DEBUGASSERT(g_procfsentries[x].ops && g_procfsentries[x].ops->opendir);
ret = g_procfsentries[x].ops->opendir(relpath, dir);
@@ -459,8 +463,8 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
/* Set the procfs_entry handler */
- level0 = (FAR struct procfs_level0_s *) dir->u.procfs;
- level0->procfsentry = &g_procfsentries[x];
+ dirpriv = (FAR struct procfs_dir_priv_s *)dir->u.procfs;
+ dirpriv->procfsentry = &g_procfsentries[x];
}
return ret;
@@ -684,7 +688,7 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
#endif /* CONFIG_FS_PROCFS_EXCLUDE_PROCESS */
}
- /* Are we reading in intermediate subdirectory? */
+ /* Are we reading an intermediate subdirectory? */
else if (priv->level == 1 && priv->procfsentry == NULL)
{
diff --git a/nuttx/fs/procfs/fs_procfsproc.c b/nuttx/fs/procfs/fs_procfsproc.c
index d646c6758..172a19fb6 100644
--- a/nuttx/fs/procfs/fs_procfsproc.c
+++ b/nuttx/fs/procfs/fs_procfsproc.c
@@ -708,7 +708,6 @@ static int process_dup(FAR const struct file *oldp, FAR struct file *newp)
static int process_opendir(FAR const char *relpath, FAR struct fs_dirent_s *dir)
{
FAR struct tcb_s *tcb;
- FAR void *priv = NULL;
irqstate_t flags;
fvdbg("relpath: \"%s\"\n", relpath ? relpath : "NULL");
@@ -784,14 +783,15 @@ static int process_opendir(FAR const char *relpath, FAR struct fs_dirent_s *dir)
return -ENOMEM;
}
- level1->base.level = 1;
- level1->base.nentries = PROCFS_NATTRS;
- level1->base.index = 0;
- level1->pid = pid;
+ /* Note that the index and procentry pointer were implicitly nullified
+ * by kzalloc(). Only the remaining, non-zero entries need be initialized.
+ */
- priv = (FAR void *)level1;
+ level1->base.level = 1;
+ level1->base.nentries = PROCFS_NATTRS;
+ level1->pid = pid;
- dir->u.procfs = priv;
+ dir->u.procfs = (FAR void *)level1;
return OK;
}
@@ -969,12 +969,28 @@ static int process_stat(const char *relpath, struct stat *buf)
buf->st_mode = S_IFDIR|S_IROTH|S_IRGRP|S_IRUSR;
}
+
+ /* Verify that the process ID is followed by valid path segment delimiter */
+
+ else if (*ptr != '/')
+ {
+ /* We are required to return -ENOENT all all invalid paths */
+
+ fdbg("ERROR: Bad delimiter '%c' in relpath '%s'\n", *ptr, relpath);
+ return -ENOENT;
+ }
else
{
/* Otherwise, the second segment of the relpath should be a well
* known attribute of the task/thread.
*/
+ /* Skip over the path segment delimiter */
+
+ ptr++;
+
+ /* Lookup the well-known attribute string. */
+
ret = process_findattr(ptr);
if (ret < 0)
{
@@ -982,7 +998,7 @@ static int process_stat(const char *relpath, struct stat *buf)
return -ENOENT;
}
- /* It's a read-only file name */
+ /* If the attribute exists, it is the name for a read-only file. */
buf->st_mode = S_IFREG|S_IROTH|S_IRGRP|S_IRUSR;
}