• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * fs/mount/fs_foreachmountpoint.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 #include "vfs_config.h"
25 #include "fs/mount.h"
26 #include "vnode.h"
27 
28 /****************************************************************************
29  * Public Functions
30  ****************************************************************************/
31 
32 /****************************************************************************
33  * Name: foreach_mountpoint
34  *
35  * Description:
36  *   Visit each mountpoint in the pseudo-file system.  The traversal is
37  *   terminated when the callback 'handler' returns a non-zero value, or when
38  *   all of the mountpoints have been visited.
39  *
40  *   This is just a front end "filter" to foreach_vnode() that forwards only
41  *   mountpoint vnodes.  It is intended to support the mount() command to
42  *   when the mount command is used to enumerate mounts.
43  *
44  *   NOTE 1: Use with caution... The pseudo-file system is locked throughout
45  *   the traversal.
46  *   NOTE 2: The search algorithm is recursive and could, in principle, use
47  *   an indeterminant amount of stack space.  This will not usually be a
48  *   real work issue.
49  *
50  ****************************************************************************/
51 
foreach_mountpoint(foreach_mountpoint_t handler,void * arg)52 int foreach_mountpoint(foreach_mountpoint_t handler, void *arg)
53 {
54   int ret;
55   struct Mount *mnt = NULL;
56   struct statfs statBuf = {0};
57   LIST_HEAD *mntList = GetMountList();
58   LOS_DL_LIST_FOR_EACH_ENTRY(mnt, mntList, struct Mount, mountList)
59     {
60       if (mnt->ops->Statfs != NULL)
61         {
62            ret = mnt->ops->Statfs(mnt, &statBuf);
63            if (ret == OK)
64              {
65                 (void)handler(mnt->devName, mnt->pathName, &statBuf, arg);
66              }
67         }
68     }
69   return 0;
70 }
71