• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * fs/dirent/fs_rewinddir.c
3  *
4  * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved.
5  * Based on NuttX originally from nuttx source (nuttx/fs/ and nuttx/drivers/)
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 
21 /****************************************************************************
22  * Included Files
23  ****************************************************************************/
24 
25 #include "vfs_config.h"
26 #include "dirent.h"
27 #include "errno.h"
28 #include "fs/dirent_fs.h"
29 #include "vnode.h"
30 
31 /****************************************************************************
32  * Public Functions
33  ****************************************************************************/
34 
35 /****************************************************************************
36  * Name: rewinddir
37  *
38  * Description:
39  *   The  rewinddir() function resets the position of the
40  *   directory stream dir to the beginning of the directory.
41  *
42  * Input Parameters:
43  *   dirp -- An instance of type DIR created by a previous
44  *     call to opendir();
45  *
46  * Returned Value:
47  *   None
48  *
49  ****************************************************************************/
50 
rewinddir(DIR * dirp)51 void rewinddir(DIR *dirp)
52 {
53   struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
54   struct Vnode *vnode_ptr = NULL;
55 
56   if (!idir || !idir->fd_root || idir->fd_status != DIRENT_MAGIC)
57     {
58       set_errno(EBADF);
59       return;
60     }
61 
62   /* The way we handle the readdir depends on the type of vnode
63    * that we are dealing with.
64    */
65 
66   vnode_ptr = idir->fd_root;
67   if (vnode_ptr->vop != NULL && vnode_ptr->vop->Rewinddir != NULL)
68     {
69       /* Perform the rewinddir() operation */
70 
71       vnode_ptr->vop->Rewinddir(vnode_ptr, idir);
72     }
73   else
74     {
75       set_errno(ENOSYS);
76     }
77 
78   /* Reset position for telldir() */
79 
80   idir->fd_position = 0;
81 }
82