参考 http://weharmonyos.com 官方文档完善注解

    百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
    博客输出站点(国内):http://weharmonyos.comhttp://8.134.122.205
    博客输出站点(国外):https://weharmony.github.io
    注解文件系统:https://gitee.com/weharmony/third_party_NuttX
    注解协议栈:https://gitee.com/weharmony/third_party_lwip
上级 f06519be
......@@ -34,6 +34,7 @@
#include "linux/kernel.h"
#include "fs/driver.h"
/*****************************************************************
随机数设备软驱动
/dev/random在类UNIX系统中是一个特殊的设备文件,可以用作随机数发生器或伪随机数发生器。
*****************************************************************/
......
......@@ -36,7 +36,7 @@
#include "fs/driver.h"
/*****************************************************************
硬件随机数发生器,
随机数设备硬驱动.硬件随机数发生器,
/dev/urandom在类UNIX系统中是一个特殊的设备文件,可以用作随机数发生器或伪随机数发生器。
*****************************************************************/
......
......@@ -1084,7 +1084,7 @@ static int fat_bind_check(struct Vnode *blk_driver, los_part **partition)
*partition = part;
return 0;
}
//fat将分区文件系统挂载 举例: mount /dev/mmcblk0p0 /bin1/vs/sd vfat
int fatfs_mount(struct Mount *mnt, struct Vnode *blk_device, const void *data)
{
struct Vnode *vp = NULL;
......@@ -1097,7 +1097,7 @@ int fatfs_mount(struct Mount *mnt, struct Vnode *blk_device, const void *data)
FRESULT result;
int ret;
ret = fat_bind_check(blk_device, &part);
ret = fat_bind_check(blk_device, &part);//通过节点获取分区信息
if (ret != 0) {
goto ERROR_EXIT;
}
......@@ -2129,7 +2129,7 @@ ERROUT:
unlock_fs(fs, res);
return -fatfs_2_vfs(res);
}
//fatfs 实现vnode接口
//fat 文件系统 vnode实现
struct VnodeOps fatfs_vops = {
/* file ops */
.Getattr = fatfs_stat,
......@@ -2152,13 +2152,13 @@ struct VnodeOps fatfs_vops = {
.Symlink = fatfs_symlink,
.Readlink = fatfs_readlink,
};
//fat 文件系统 挂载实现
struct MountOps fatfs_mops = {
.Mount = fatfs_mount,
.Unmount = fatfs_umount,
.Statfs = fatfs_statfs,
};
//fat 文件系统 文件操作实现
struct file_operations_vfs fatfs_fops = {
.open = fatfs_open,
.read = fatfs_read,
......
......@@ -39,29 +39,43 @@
#define MS_NOSYNC 2
struct MountOps;
/* 将一个设备(通常是存储设备)挂接到一个已存在的目录上,操作系统将所有的设备都看作文件,
* 它将整个计算机的资源都整合成一个大的文件目录。我们要访问存储设备中的文件,必须将文件所在的分区挂载到一个已存在的目录上,
* 然后通过访问这个目录来访问存储设备。挂载就是把设备放在一个目录下,让系统知道怎么管理这个设备里的文件,
* 了解这个存储设备的可读写特性之类的过程。
*/
struct Mount {//装载
/******************************************************************
将一个设备(通常是存储设备)挂接到一个已存在的目录上,操作系统将所有的设备都看作文件,
它将整个计算机的资源都整合成一个大的文件目录。我们要访问存储设备中的文件,必须将文件所在的分区挂载到一个已存在的目录上,
然后通过访问这个目录来访问存储设备。挂载就是把设备放在一个目录下,让系统知道怎么管理这个设备里的文件,
了解这个存储设备的可读写特性之类的过程。
linux下面所有的文件、目录、设备都有一个路径,这个路径永远以/开头,用/分隔,如果一个路径是另一个路径的前缀,
则这两个路径有逻辑上的父子关系。但是并不是所有逻辑上的父子关系都必须要是同一个设备,决定不同路径对应到哪个设备的机制就叫做mount(挂载)。
通过mount,可以设置当前的路径与设备的对应关系。每个设备会设置一个挂载点,挂载点是一个空目录。一般来说必须有一个设备挂载在/这个根路径下面,
叫做rootfs。其他挂载点可以是/tmp,/boot,/dev等等,通过在rootfs上面创建一个空目录然后用mount命令就可以将设备挂载到这个目录上。挂载之后,
这个目录下的子路径,就会映射到被挂载的设备里面。当访问一个路径时,会选择一个能最大匹配当前路径前缀的挂载点。
比如说,有/var的挂载点,也有/var/run的挂载点的情况下,访问/var/run/test.pid,就会匹配到/var/run挂载点设备下面的/test.pid。
同一个设备可以有多个挂载点,同一个挂载点同时只能加载一个设备。访问非挂载点的路径的时候,按照前面所说,其实是访问最接近的一个挂载点,
如果没有其他挂载点那么就是rootfs上的目录或者文件了。
https://www.zhihu.com/question/266907637/answer/315386532
*******************************************************************/
//举例: mount /dev/mmcblk0p0 /bin1/vs/sd vfat 将/dev/mmcblk0p0 挂载到/bin1/vs/sd目录
//注意: 同时可以 mount /dev/mmcblk0p0 /home/vs vfat 也就是说一个文件系统可以有多个挂载点
struct Mount {
LIST_ENTRY mountList; /* mount list */ //通过本节点将Mount挂到全局Mount链表上
const struct MountOps *ops; /* operations of mount */ //载操作函数
struct Vnode *vnodeBeCovered; /* vnode we mounted on */ //设备装载
struct Vnode *vnodeCovered; /* syncer vnode */ //暂时不知作何用途
const struct MountOps *ops; /* operations of mount */ //载操作函数
struct Vnode *vnodeBeCovered; /* vnode we mounted on */ //要被挂载的节点 即 /bin1/vs/sd 对应的 vnode节
struct Vnode *vnodeCovered; /* syncer vnode */ //要挂载的节点 即/dev/mmcblk0p0 对应的 vnode节点
LIST_HEAD vnodeList; /* list of vnodes */ //链表表头
int vnodeSize; /* size of vnode list */ //节点数量
LIST_HEAD activeVnodeList; /* list of active vnodes */ //激活的节点链表
int activeVnodeSize; /* szie of active vnodes list *///激活的节点数量
void *data; /* private data */ //私有数据,可使用这个成员作为一个指向它们自己内部数据的指针
uint32_t hashseed; /* Random seed for vfs hash */ //vfs 哈希随机种子
unsigned long mountFlags; /* Flags for mount */ //载标签
char pathName[PATH_MAX]; /* path name of mount point */ //装载点路径名称
char devName[PATH_MAX]; /* path name of dev point */
unsigned long mountFlags; /* Flags for mount */ //载标签
char pathName[PATH_MAX]; /* path name of mount point */ //挂载点路径名称 /bin1/vs/sd
char devName[PATH_MAX]; /* path name of dev point */ //设备名称 /dev/mmcblk0p0
};
//载操作
//载操作
struct MountOps {
int (*Mount)(struct Mount *mount, struct Vnode *vnode, const void *data);//
int (*Mount)(struct Mount *mount, struct Vnode *vnode, const void *data);//
int (*Unmount)(struct Mount *mount, struct Vnode **blkdriver);//卸载
int (*Statfs)(struct Mount *mount, struct statfs *sbp);//统计文件系统的信息,如该文件系统类型、总大小、可用大小等信息
};
......
......@@ -94,12 +94,11 @@ struct ProcDirEntry {//这才是能操作 /proc的 真正结构体
mode_t mode; //模式(读|写...)
int flags; //标签
const struct ProcFileOperations *procFileOps;//驱动程序,每个 /proc 下目录的驱动程序都不一样
struct ProcFile *pf;//文件指针
struct ProcFile *pf;//proc文件指针
struct ProcDirEntry *next, *parent, *subdir;//当前目录项的关系项
void *data;
atomic_t count; /* open file count */ //打开文件的数量
spinlock_t pdeUnloadLock;
int nameLen;
struct ProcDirEntry *pdirCurrent;//当前目录
char name[NAME_MAX];
......
......@@ -65,21 +65,21 @@ static struct ProcDirEntry *VnodeToEntry(struct Vnode *node)
{
return (struct ProcDirEntry *)(node->data);
}
//创建节点,绑定实体对象
//创建节点,通过实体对象转成vnode节点,如此达到统一管理的目的.
static struct Vnode *EntryToVnode(struct ProcDirEntry *entry)
{
struct Vnode *node = NULL;
(void)VnodeAlloc(&g_procfsVops, &node);//申请一个 vnode节点,并设置操作节点的实现函数
(void)VnodeAlloc(&g_procfsVops, &node);//申请一个 vnode节点,并设置节点操作
node->fop = &g_procfsFops;//设置文件操作系列函数
node->data = entry;//绑定实体
node->type = entry->type;//实体类型 (文件|目录)
node->uid = entry->uid;
node->gid = entry->gid;
node->mode = entry->mode;
node->uid = entry->uid; //用户ID
node->gid = entry->gid; //组ID
node->mode = entry->mode;//读/写/执行模式
return node;
}
//实体匹配,通过名称匹配
static int EntryMatch(const char *name, int len, const struct ProcDirEntry *pn)
{
if (len != pn->nameLen) {
......@@ -187,7 +187,7 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
if ((*vpp) == NULL) {
return -ENOMEM;
}
(*vpp)->originMount = parent->originMount;
(*vpp)->originMount = parent->originMount;//继承挂载信息
(*vpp)->parent = parent;
return LOS_OK;
}
......@@ -208,7 +208,7 @@ int VfsProcfsMount(struct Mount *mnt, struct Vnode *device, const void *data)
struct ProcDirEntry *root = GetProcRootEntry();
vp->data = root;
vp->originMount = mnt;//绑定mount
vp->fop = &g_procfsFops;
vp->fop = &g_procfsFops;//指定文件系统
mnt->data = NULL;
mnt->vnodeCovered = vp;
vp->type = root->type;
......@@ -356,7 +356,7 @@ const struct MountOps procfs_operations = {
.Unmount = NULL,
.Statfs = VfsProcfsStatfs,//统计信息
};
// proc 对 VnodeOps 接口实现
// proc 对 VnodeOps 接口实现,暂没有实现创建节点的功能.
static struct VnodeOps g_procfsVops = {
.Lookup = VfsProcfsLookup,
.Getattr = VfsProcfsStat,
......
......@@ -315,18 +315,18 @@ static void ProcDetachNode(struct ProcDirEntry *pn)
}
pn->parent = NULL;
}
//在参数 parent 下创建目录
// /proc文件系统创建目录的方式
static struct ProcDirEntry *ProcCreateDir(struct ProcDirEntry *parent, const char *name,
const struct ProcFileOperations *procFileOps, mode_t mode)
{
struct ProcDirEntry *pn = NULL;
int ret;
pn = ProcAllocNode(&parent, name, S_IFDIR | mode);//分配一个节点
pn = ProcAllocNode(&parent, name, S_IFDIR | mode);//1.先创造一个数据项 ProcDirEntry
if (pn == NULL) {
return pn;
}
pn->procFileOps = procFileOps;
pn->procFileOps = procFileOps;//绑定数据项的文件系统
pn->type = VNODE_TYPE_DIR;
ret = ProcAddNode(parent, pn);
if (ret != 0) {
......
......@@ -164,13 +164,13 @@ struct Vnode {//vnode并不包含文件名,因为 vnode和文件名是 1:N 的
LIST_HEAD parentPathCaches; /* pathCaches point to parents */ //指向父级路径缓存,上面的都是当了爸爸节点
LIST_HEAD childPathCaches; /* pathCaches point to children */ //指向子级路径缓存,上面都是当了别人儿子的节点
struct Vnode *parent; /* parent vnode */ //父节点
struct VnodeOps *vop; /* vnode operations */ //以 Vnode 方式操作数据(接口实现|驱动程序)
struct file_operations_vfs *fop; /* file operations */ //以 file 方式操作数据(接口实现|驱动程序)
struct VnodeOps *vop; /* vnode operations */ //相当于指定操作Vnode方式 (接口实现|驱动程序)
struct file_operations_vfs *fop; /* file operations */ //相当于指定文件系统
void *data; /* private data */ //文件数据block的位置,指向每种具体设备私有的成员,例如 ( drv_data | nfsnode | ....)
uint32_t flag; /* vnode flag */ //节点标签
LIST_ENTRY hashEntry; /* list entry for bucket in hash table */ //通过它挂入哈希表 g_vnodeHashEntrys[i], i:[0,g_vnodeHashMask]
LIST_ENTRY actFreeEntry; /* vnode active/free list entry */ //通过本节点挂到空闲链表和使用链表上
struct Mount *originMount; /* fs info about this vnode */ //关于这个节点的挂载信息
struct Mount *originMount; /* fs info about this vnode */ //节点的挂载信息
struct Mount *newMount; /* fs info about who mount on this vnode */ //挂载在这个节点上的文件系统
};
/*
......
......@@ -36,6 +36,8 @@
#define SYS_CALL_VALUE 0x900001
//加载init进程
#ifdef LOSCFG_QUICK_START
LITE_USER_SEC_RODATA STATIC CHAR *g_initPath = "/dev/shm/init";
#else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册