summaryrefslogtreecommitdiff
path: root/nuttx/fs/fs_readdir.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-26 16:05:59 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-26 16:05:59 +0000
commit2a3e5f6cd969f93fbb56d7ba2b63d7d8da11e756 (patch)
tree6ecb4e1b2918a65b64e0d3daef3723d5da1344d1 /nuttx/fs/fs_readdir.c
parentd88d061f01f4238008e4f24910820b63e5bd7c82 (diff)
downloadpx4-nuttx-2a3e5f6cd969f93fbb56d7ba2b63d7d8da11e756.tar.gz
px4-nuttx-2a3e5f6cd969f93fbb56d7ba2b63d7d8da11e756.tar.bz2
px4-nuttx-2a3e5f6cd969f93fbb56d7ba2b63d7d8da11e756.zip
Setting up for mountpoint support
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@250 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs/fs_readdir.c')
-rw-r--r--nuttx/fs/fs_readdir.c112
1 files changed, 71 insertions, 41 deletions
diff --git a/nuttx/fs/fs_readdir.c b/nuttx/fs/fs_readdir.c
index 54a880328..4c2d79227 100644
--- a/nuttx/fs/fs_readdir.c
+++ b/nuttx/fs/fs_readdir.c
@@ -50,61 +50,30 @@
************************************************************/
/************************************************************
- * Public Functions
- ************************************************************/
-
-/************************************************************
- * Name: readdir
- *
- * Description:
- * The readdir() function returns a pointer to a dirent
- * structure representing the next directory entry in the
- * directory stream pointed to by dir. It returns NULL on
- * reaching the end-of-file or if an error occurred.
- *
- * Inputs:
- * dirp -- An instance of type DIR created by a previous
- * call to opendir();
- *
- * Return:
- * The readdir() function returns a pointer to a dirent
- * structure, or NULL if an error occurs or end-of-file
- * is reached. On error, errno is set appropriately.
- *
- * EBADF - Invalid directory stream descriptor dir
- *
+ * Name: readpsuedodir
************************************************************/
-#if CONFIG_NFILE_DESCRIPTORS > 0
-
-FAR struct dirent *readdir(DIR *dirp)
+static inline FAR struct dirent *readpsuedodir(struct internal_dir_s *idir)
{
- FAR struct internal_dir_s *idir = (struct internal_dir_s *)dirp;
FAR struct inode *prev;
- if (!idir)
- {
- *get_errno_ptr() = EBADF;
- return NULL;
- }
-
/* Check if we are at the end of the list */
- if (!idir->next)
+ if (!idir->u.psuedo.next)
{
return NULL;
}
/* Copy the inode name into the dirent structure */
- strncpy(idir->dir.d_name, idir->next->i_name, NAME_MAX+1);
+ strncpy(idir->dir.d_name, idir->u.psuedo.next->i_name, NAME_MAX+1);
/* If the node has file operations, we will say that it is
* a file.
*/
idir->dir.d_type = 0;
- if (idir->next->u.i_ops)
+ if (idir->u.psuedo.next->u.i_ops)
{
idir->dir.d_type |= DTYPE_FILE;
}
@@ -113,7 +82,7 @@ FAR struct dirent *readdir(DIR *dirp)
* is a directory. NOTE: that the node can be both!
*/
- if (idir->next->i_child || !idir->next->u.i_ops)
+ if (idir->u.psuedo.next->i_child || !idir->u.psuedo.next->u.i_ops)
{
idir->dir.d_type |= DTYPE_DIRECTORY;
}
@@ -122,14 +91,14 @@ FAR struct dirent *readdir(DIR *dirp)
inode_semtake();
- prev = idir->next;
- idir->next = prev->i_peer; /* The next node to visit */
+ prev = idir->u.psuedo.next;
+ idir->u.psuedo.next = prev->i_peer; /* The next node to visit */
- if (idir->next)
+ if (idir->u.psuedo.next)
{
/* Increment the reference count on this next node */
- idir->next->i_crefs++;
+ idir->u.psuedo.next->i_crefs++;
}
inode_semgive();
@@ -142,4 +111,65 @@ FAR struct dirent *readdir(DIR *dirp)
return &idir->dir;
}
+/************************************************************
+ * Public Functions
+ ************************************************************/
+
+/************************************************************
+ * Name: readdir
+ *
+ * Description:
+ * The readdir() function returns a pointer to a dirent
+ * structure representing the next directory entry in the
+ * directory stream pointed to by dir. It returns NULL on
+ * reaching the end-of-file or if an error occurred.
+ *
+ * Inputs:
+ * dirp -- An instance of type DIR created by a previous
+ * call to opendir();
+ *
+ * Return:
+ * The readdir() function returns a pointer to a dirent
+ * structure, or NULL if an error occurs or end-of-file
+ * is reached. On error, errno is set appropriately.
+ *
+ * EBADF - Invalid directory stream descriptor dir
+ *
+ ************************************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+
+FAR struct dirent *readdir(DIR *dirp)
+{
+ FAR struct internal_dir_s *idir = (struct internal_dir_s *)dirp;
+
+ /* Sanity checks */
+
+ if (!idir || !idir->root)
+ {
+ *get_errno_ptr() = EBADF;
+ return NULL;
+ }
+
+ /* The way we handle the readdir depends on the type of inode
+ * that we are dealing with.
+ */
+
+ if (INODE_IS_MOUNTPT(idir->root))
+ {
+ /* The node is a file system mointpoint */
+
+#warning "Mountpoint support not implemented"
+ *get_errno_ptr() = ENOSYS;
+ return NULL;
+ }
+ else
+ {
+ /* The node is part of the root psuedo file system, release
+ * our contained reference to the 'next' inode.
+ */
+ return readpsuedodir(idir);
+ }
+}
+
#endif /* CONFIG_NFILE_DESCRIPTORS */