更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
mount.h 文件参考

浏览源代码.

结构体

struct  Mount
 举例: mount /dev/mmcblk0p0 /bin1/vs/sd vfat 将/dev/mmcblk0p0 挂载到/bin1/vs/sd目录 更多...
 
struct  MountOps
 挂载操作 更多...
 

类型定义

typedef int(* foreach_mountpoint_t) (const char *devpoint, const char *mountpoint, struct statfs *statbuf, void *arg)
 

函数

struct MountMountAlloc (struct Vnode *vnode, struct MountOps *mop)
 
LIST_HEADGetMountList (void)
 获取装载链表,并初始化 更多...
 
int foreach_mountpoint (foreach_mountpoint_t handler, void *arg)
 
int ForceUmountDev (struct Vnode *dev)
 

类型定义说明

◆ foreach_mountpoint_t

typedef int(* foreach_mountpoint_t) (const char *devpoint, const char *mountpoint, struct statfs *statbuf, void *arg)

在文件 mount.h96 行定义.

函数说明

◆ ForceUmountDev()

int ForceUmountDev ( struct Vnode dev)

在文件 vfs_force_umount.c451 行定义.

452{
453 int ret;
454 struct Vnode *origin = NULL;
455 struct filelist *flist = &tg_filelist;
456 if (dev == NULL) {
457 return -EINVAL;
458 }
459
460 (void)sem_wait(&flist->fl_sem);
461 VnodeHold();
462
463 struct Mount *mnt = GetDevMountPoint(dev);
464 if (mnt == NULL) {
465 VnodeDrop();
466 (void)sem_post(&flist->fl_sem);
467 return -ENXIO;
468 }
469 origin = mnt->vnodeBeCovered;
470
472 VnodeTryFreeAll(mnt);
473 ret = mnt->ops->Unmount(mnt, &dev);
474 if (ret != OK) {
475 PRINT_ERR("unmount in fs failed, ret = %d, errno = %d\n", ret, errno);
476 }
477
479 free(mnt);
480 origin->newMount = NULL;
481 origin->flag &= ~(VNODE_FLAG_MOUNT_ORIGIN);
482
483 VnodeDrop();
484 (void)sem_post(&flist->fl_sem);
485
486 return OK;
487}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
Definition: los_list.h:292
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
int sem_post(sem_t *sem)
增加信号量计数
Definition: semaphore.c:139
int sem_wait(sem_t *sem)
获取信号量
Definition: semaphore.c:77
举例: mount /dev/mmcblk0p0 /bin1/vs/sd vfat 将/dev/mmcblk0p0 挂载到/bin1/vs/sd目录
Definition: mount.h:68
LIST_ENTRY mountList
Definition: mount.h:69
struct Vnode * vnodeBeCovered
Definition: mount.h:71
const struct MountOps * ops
Definition: mount.h:70
int(* Unmount)(struct Mount *mount, struct Vnode **blkdriver)
卸载分区
Definition: mount.h:91
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
struct Mount * newMount
Definition: vnode.h:181
uint32_t flag
Definition: vnode.h:177
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
int VnodeDrop(void)
归还锁
Definition: vnode.c:292
int VnodeHold(void)
拿锁,封装互斥量
Definition: vnode.c:283
static void FileDisableAndClean(struct Mount *mnt)
static struct Mount * GetDevMountPoint(struct Vnode *dev)
static void VnodeTryFreeAll(struct Mount *mount)
函数调用图:
这是这个函数的调用关系图:

◆ foreach_mountpoint()

int foreach_mountpoint ( foreach_mountpoint_t  handler,
void arg 
)
这是这个函数的调用关系图:

◆ GetMountList()

LIST_HEAD * GetMountList ( void  )

获取装载链表,并初始化

在文件 mount.c71 行定义.

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
函数调用图:
这是这个函数的调用关系图:

◆ MountAlloc()

struct Mount * MountAlloc ( struct Vnode vnode,
struct MountOps mop 
)

在文件 mount.c48 行定义.

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}
LIST_HEAD vnodeList
Definition: mount.h:74
LIST_HEAD activeVnodeList
Definition: mount.h:76
uint32_t hashseed
Definition: mount.h:79
函数调用图:
这是这个函数的调用关系图: