2008-09-12 16:46:44 +02:00
|
|
|
/****************************************************************************
|
2014-09-28 19:17:36 +02:00
|
|
|
* fs/dirent/fs_rewinddir.c
|
2007-03-14 23:41:09 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-03-14 23:41:09 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-14 23:41:09 +01:00
|
|
|
*
|
2020-03-30 01:36:19 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-03-14 23:41:09 +01:00
|
|
|
*
|
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>
|
2011-03-28 02:05:58 +02:00
|
|
|
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/fs/dirent.h>
|
2009-12-15 01:18:32 +01:00
|
|
|
|
2014-09-29 15:14:38 +02:00
|
|
|
#include "inode/inode.h"
|
2007-03-14 23:41:09 +01:00
|
|
|
|
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
|
|
|
/****************************************************************************
|
2012-08-05 19:44:11 +02:00
|
|
|
* Name: rewindpseudodir
|
2008-09-12 16:46:44 +02:00
|
|
|
****************************************************************************/
|
2007-05-26 21:22:34 +02:00
|
|
|
|
2012-08-05 19:44:11 +02:00
|
|
|
static inline void rewindpseudodir(struct fs_dirent_s *idir)
|
2007-05-26 18:05:59 +02:00
|
|
|
{
|
|
|
|
struct inode *prev;
|
2020-03-30 01:36:19 +02:00
|
|
|
int ret;
|
2007-05-26 18:05:59 +02:00
|
|
|
|
2020-03-30 01:36:19 +02:00
|
|
|
ret = inode_semtake();
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2007-05-26 18:05:59 +02:00
|
|
|
|
|
|
|
/* Reset the position to the beginning */
|
|
|
|
|
2012-08-05 19:44:11 +02:00
|
|
|
prev = idir->u.pseudo.fd_next; /* (Save to delete later) */
|
|
|
|
idir->u.pseudo.fd_next = idir->fd_root; /* The next node to visit */
|
2007-05-26 21:22:34 +02:00
|
|
|
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.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2007-03-14 23:41:09 +01:00
|
|
|
* dirp -- An instance of type DIR created by a previous
|
|
|
|
* call to opendir();
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-03-14 23:41:09 +01:00
|
|
|
* None
|
|
|
|
*
|
2008-09-12 16:46:44 +02:00
|
|
|
****************************************************************************/
|
2007-03-14 23:41:09 +01:00
|
|
|
|
|
|
|
void rewinddir(FAR DIR *dirp)
|
|
|
|
{
|
2011-03-28 02:05:58 +02:00
|
|
|
struct fs_dirent_s *idir = (struct fs_dirent_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
|
|
|
|
2014-02-19 16:21:38 +01:00
|
|
|
/* Verify that we were provided with a valid directory structure,
|
|
|
|
* A special case is when we enumerate an "empty", unused inode (fd_root
|
|
|
|
* == 0). That is an inode in the pseudo-filesystem that has no
|
|
|
|
* operations and no children. This is a "dangling" directory entry that
|
|
|
|
* has lost its children.
|
|
|
|
*/
|
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
|
|
|
{
|
2012-08-05 19:44:11 +02:00
|
|
|
/* The node is part of the root pseudo file system */
|
2007-03-14 23:41:09 +01:00
|
|
|
|
2012-08-05 19:44:11 +02:00
|
|
|
rewindpseudodir(idir);
|
2007-03-14 23:41:09 +01:00
|
|
|
}
|
|
|
|
}
|