更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
mount.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "fs/mount.h"
32#include "path_cache.h"
33#include "vnode.h"
34#ifdef LOSCFG_DRIVERS_RANDOM
35#include "hisoc/random.h"
36#else
37#include "stdlib.h"
38#endif
39
40static LIST_HEAD *g_mountList = NULL;//挂载点链表,上面挂的是系统所有挂载点
41/* 在内核MountAlloc只被VnodeDevInit调用,但真实情况下它还将被系统调用 mount()调用
42* int mount(const char *source, const char *target,
43 const char *filesystemtype, unsigned long mountflags,
44 const void *data)
45 mount见于..\code-2.0-canary\third_party\NuttX\fs\mount\fs_mount.c
46 vnodeBeCovered: /dev/mmcblk0
47*/
48struct Mount* MountAlloc(struct Vnode* vnodeBeCovered, struct MountOps* fsop)
49{
50 struct Mount* mnt = (struct Mount*)zalloc(sizeof(struct Mount));//申请一个mount结构体内存,小内存分配用 zalloc
51 if (mnt == NULL) {
52 PRINT_ERR("MountAlloc failed no memory!\n");
53 return NULL;
54 }
55
56 LOS_ListInit(&mnt->activeVnodeList);//初始化激活索引节点链表
57 LOS_ListInit(&mnt->vnodeList);//初始化索引节点链表
58
59 mnt->vnodeBeCovered = vnodeBeCovered;//设备将装载到vnodeBeCovered节点上
60 vnodeBeCovered->newMount = mnt;//该节点不再是虚拟节点,而作为 设备结点
61#ifdef LOSCFG_DRIVERS_RANDOM //随机值 驱动模块
62 HiRandomHwInit();//随机值初始化
63 (VOID)HiRandomHwGetInteger(&mnt->hashseed);//用于生成哈希种子
64 HiRandomHwDeinit();//随机值反初始化
65#else
66 mnt->hashseed = (uint32_t)random(); //随机生成哈子种子
67#endif
68 return mnt;
69}
70///获取装载链表,并初始化
72{
73 if (g_mountList == NULL) {
74 g_mountList = zalloc(sizeof(LIST_HEAD));//分配内存, 小内存分配用 zalloc
75 if (g_mountList == NULL) {
76 PRINT_ERR("init mount list failed, no memory.");
77 return NULL;
78 }
79 LOS_ListInit(g_mountList);//初始化全局链表
80 }
81 return g_mountList;//所有文件系统的挂载信息
82}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
Definition: los_list.h:104
void * zalloc(size_t size)
Definition: malloc.c:91
static LIST_HEAD * g_mountList
Definition: mount.c:40
LIST_HEAD * GetMountList()
获取装载链表,并初始化
Definition: mount.c:71
struct Mount * MountAlloc(struct Vnode *vnodeBeCovered, struct MountOps *fsop)
Definition: mount.c:48
举例: mount /dev/mmcblk0p0 /bin1/vs/sd vfat 将/dev/mmcblk0p0 挂载到/bin1/vs/sd目录
Definition: mount.h:68
LIST_HEAD vnodeList
Definition: mount.h:74
LIST_HEAD activeVnodeList
Definition: mount.h:76
struct Vnode * vnodeBeCovered
Definition: mount.h:71
uint32_t hashseed
Definition: mount.h:79
挂载操作
Definition: mount.h:89
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
struct Mount * newMount
Definition: vnode.h:181