2008-09-12 16:46:44 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* fs/fs_rewinddir.c
|
2007-03-14 23:41:09 +01:00
|
|
|
*
|
2009-12-15 01:18:32 +01:00
|
|
|
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
2007-03-14 23:41:09 +01:00
|
|
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2008-09-12 16:46:44 +02:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-03-14 23:41:09 +01:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-09-12 16:46:44 +02:00
|
|
|
****************************************************************************/
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2008-09-12 16:46:44 +02:00
|
|
|
/****************************************************************************
|
2007-03-14 23:41:09 +01:00
|
|
|
* Included Files
|
2008-09-12 16:46:44 +02:00
|
|
|
****************************************************************************/
|
2007-03-14 23:41:09 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-15 01:18:32 +01:00
|
|
|
|
2007-03-14 23:41:09 +01:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <nuttx/fs.h>
|
2009-12-15 01:18:32 +01:00
|
|
|
|
2007-03-14 23:41:09 +01:00
|
|
|
#include "fs_internal.h"
|
|
|
|
|
2008-09-12 16:46:44 +02:00
|
|
|
/****************************************************************************
|
2007-03-14 23:41:09 +01:00
|
|
|
* Private Functions
|
2008-09-12 16:46:44 +02:00
|
|
|
****************************************************************************/
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2008-09-12 16:46:44 +02:00
|
|
|
/****************************************************************************
|
2007-05-26 21:22:34 +02:00
|
|
|
* Name: rewindpsuedodir
|
2008-09-12 16:46:44 +02:00
|
|
|
****************************************************************************/
|
2007-05-26 21:22:34 +02:00
|
|
|
|
2007-05-26 18:05:59 +02:00
|
|
|
static inline void rewindpsuedodir(struct internal_dir_s *idir)
|
|
|
|
{
|
|
|
|
struct inode *prev;
|
|
|
|
|
|
|
|
inode_semtake();
|
|
|
|
|
|
|
|
/* Reset the position to the beginning */
|
|
|
|
|
2007-05-26 21:22:34 +02:00
|
|
|
prev = idir->u.psuedo.fd_next; /* (Save to delete later) */
|
|
|
|
idir->u.psuedo.fd_next = idir->fd_root; /* The next node to visit */
|
|
|
|
idir->fd_position = 0; /* Reset position */
|
2007-05-26 18:05:59 +02:00
|
|
|
|
|
|
|
/* Increment the reference count on the root=next node. We
|
|
|
|
* should now have two references on the inode.
|
|
|
|
*/
|
|
|
|
|
2007-05-26 21:22:34 +02:00
|
|
|
idir->fd_root->i_crefs++;
|
2007-05-26 18:05:59 +02:00
|
|
|
inode_semgive();
|
|
|
|
|
|
|
|
/* Then release the reference to the old next inode */
|
|
|
|
|
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
inode_release(prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 16:46:44 +02:00
|
|
|
/****************************************************************************
|
2007-03-14 23:41:09 +01:00
|
|
|
* Public Functions
|
2008-09-12 16:46:44 +02:00
|
|
|
****************************************************************************/
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2008-09-12 16:46:44 +02:00
|
|
|
/****************************************************************************
|
2007-03-14 23:41:09 +01:00
|
|
|
* Name: rewinddir
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The rewinddir() function resets the position of the
|
|
|
|
* directory stream dir to the beginning of the directory.
|
|
|
|
*
|
|
|
|
* Inputs:
|
|
|
|
* dirp -- An instance of type DIR created by a previous
|
|
|
|
* call to opendir();
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* None
|
|
|
|
*
|
2008-09-12 16:46:44 +02:00
|
|
|
****************************************************************************/
|
2007-03-14 23:41:09 +01:00
|
|
|
|
|
|
|
void rewinddir(FAR DIR *dirp)
|
|
|
|
{
|
|
|
|
struct internal_dir_s *idir = (struct internal_dir_s *)dirp;
|
2007-06-09 21:11:00 +02:00
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
2007-05-26 21:22:34 +02:00
|
|
|
struct inode *inode;
|
|
|
|
#endif
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2007-05-26 18:05:59 +02:00
|
|
|
/* Sanity checks */
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2007-05-26 21:22:34 +02:00
|
|
|
if (!idir || !idir->fd_root)
|
2007-05-26 18:05:59 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2007-05-26 18:05:59 +02:00
|
|
|
/* The way we handle the readdir depends on the type of inode
|
|
|
|
* that we are dealing with.
|
|
|
|
*/
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2007-06-09 21:11:00 +02:00
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
2007-05-26 21:22:34 +02:00
|
|
|
inode = idir->fd_root;
|
|
|
|
if (INODE_IS_MOUNTPT(inode))
|
2007-05-26 18:05:59 +02:00
|
|
|
{
|
2007-05-26 21:22:34 +02:00
|
|
|
/* The node is a file system mointpoint. Verify that the mountpoint
|
|
|
|
* supports the rewinddir() method
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (inode->u.i_mops && inode->u.i_mops->rewinddir)
|
|
|
|
{
|
|
|
|
/* Perform the rewinddir() operation */
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2007-05-26 21:22:34 +02:00
|
|
|
inode->u.i_mops->rewinddir(inode, idir);
|
|
|
|
}
|
2007-05-26 18:05:59 +02:00
|
|
|
}
|
|
|
|
else
|
2007-05-26 21:22:34 +02:00
|
|
|
#endif
|
2007-05-26 18:05:59 +02:00
|
|
|
{
|
|
|
|
/* The node is part of the root psuedo file system */
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2007-05-26 18:05:59 +02:00
|
|
|
rewindpsuedodir(idir);
|
2007-03-14 23:41:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|