文件系统几个关键结构体注释

    百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
    博客输出站点(国内):http://weharmonyos.com
    博客输出站点(国外):https://weharmony.github.io
    注解文件系统:https://gitee.com/weharmony/third_party_NuttX
    注解协议栈:https://gitee.com/weharmony/third_party_lwip
    注解编译子系统:https://gitee.com/weharmony/build_lite
上级 20a8f18d
[OpenHarmony | 鸿蒙研究站 | WeHarmony](http://weharmonyos.com/) **[ < 国内](http://weharmonyos.com/)[ | 国外 >](http://weharmonyos.com/)**
[![在这里插入图片描述](https://gitee.com/weharmony/docs/raw/master/pic/other/io.png)](http://weharmonyos.com/)
百篇博客系列篇.本篇为:
......@@ -8,7 +6,7 @@
### **同步官方源码历史**
* 每月至少同步一次
* `2021/7/15` -- 本次官方改动不大,新增 `blackbox`,`hidumper`,对一些宏(`LOSCFG_KERNEL_SMP` ..)规范化使用
* `2021/7/15` -- 本次官方改动不大,新增blackbox,hidumper,对一些宏(LOSCFG_KERNEL_SMP ..)规范化使用
* `2021/6/27` -- 本次官方对文件系统/设备驱动改动较大,目录结构进行了重新整理.
* `2021/6/08` -- 本次官方对编译构建,任务,信号模块有较大的改动.
* `2021/5/28` -- 本次官方改动不大,主要针对一些错误单词拼写纠正.
......@@ -22,11 +20,11 @@
* 百篇博客分析地址:
* 国内: [ http://weharmonyos.com/weharmony](http://weharmonyos.com/weharmony)
* 国外: [ http://weharmonyos.com/weharmony](http://weharmonyos.com/weharmony)
* 国外: [ https://weharmony.github.io/weharmony](http://weharmonyos.com/weharmony)
* [OpenHarmony开发者文档](http://weharmonyos.com/openharmony) 是对官方文档 [docs](https://gitee.com/openharmony/docs) 做的非常炫酷的静态站点,支持侧边栏/面包屑/搜索/中英文,非常方便的查看官方文档,大大提高学习和开发效率.
* 国内: [http://weharmonyos.com/openharmony](http://weharmonyos.com/openharmony)
* 国外: [http://weharmonyos.com/openharmony](http://weharmonyos.com/openharmony)
* 国外: [https://weharmony.github.io/openharmony](http://weharmonyos.com/openharmony)
* [下载.鸿蒙源码分析.离线文档 < 国内](http://weharmonyos.com/history.html)[ | 国外 > ](http://weharmonyos.com/history.html)
......@@ -77,13 +75,15 @@
与代码有bug需不断debug一样,文章和注解内容会存在不少错漏之处,请多包涵,但会反复修正,持续更新,`.xx`代表修改的次数,精雕细琢,言简意赅,力求打造精品内容。
* [v61.xx 鸿蒙内核源码分析(ninja应用篇) | 简单而快速的构建系统 ](https://my.oschina.net/weharmony/blog/5139034) **[ | 51](https://harmonyos.51cto.com/posts/7328)[ .c](https://blog.csdn.net/kuangyufei/article/details/118970589)[ .h](http://weharmonyos.com/blog/60_ninja应用篇.html)[ .o](https://my.oschina.net/weharmony)**
* [v62.xx 鸿蒙内核源码分析(文件概念篇) | 为什么说一切皆是文件 ](https://my.oschina.net/weharmony/blog/5152858) **[ | 51](https://harmonyos.51cto.com/posts/7460)[ .c](https://blog.csdn.net/kuangyufei/article/details/119217155)[ .h](http://weharmonyos.com/blog/62_文件概念篇.html)[ .o](https://my.oschina.net/weharmony)**
* [v61.xx 鸿蒙内核源码分析(忍者ninja篇) | 都忍者了能不快吗 ](https://my.oschina.net/weharmony/blog/5139034) **[ | 51](https://harmonyos.51cto.com/posts/7328)[ .c](https://blog.csdn.net/kuangyufei/article/details/118970589)[ .h](http://weharmonyos.com/blog/61_忍者ninja篇.html)[ .o](https://my.oschina.net/weharmony)**
* [v60.xx 鸿蒙内核源码分析(gn应用篇) | gn语法及在鸿蒙的使用 ](https://my.oschina.net/weharmony/blog/5137565) **[ | 51](https://harmonyos.51cto.com/posts/7310)[ .c](https://blog.csdn.net/kuangyufei/article/details/118932416)[ .h](http://weharmonyos.com/blog/60_gn应用篇.html)[ .o](https://my.oschina.net/weharmony)**
* [v59.xx 鸿蒙内核源码分析(构建工具篇) | 顺瓜摸藤调试鸿蒙构建过程 ](https://my.oschina.net/weharmony/blog/5135157) **[ | 51](https://harmonyos.51cto.com/posts/7287)[ .c](https://blog.csdn.net/kuangyufei/article/details/118878233)[ .h](http://weharmonyos.com/blog/59_构建工具篇.html)[ .o](https://my.oschina.net/weharmony)**
* [v58.xx 鸿蒙内核源码分析(环境脚本篇) | 有了它编译鸿蒙好简单 ](https://my.oschina.net/weharmony/blog/5132725) **[ | 51](https://harmonyos.51cto.com/posts/7248)[ .c](https://blog.csdn.net/kuangyufei/article/details/118765692)[ .h](http://weharmonyos.com/blog/58_编译脚本篇.html)[ .o](https://my.oschina.net/weharmony)**
* [v58.xx 鸿蒙内核源码分析(环境脚本篇) | 编译鸿蒙原来如此简单 ](https://my.oschina.net/weharmony/blog/5132725) **[ | 51](https://harmonyos.51cto.com/posts/7248)[ .c](https://blog.csdn.net/kuangyufei/article/details/118765692)[ .h](http://weharmonyos.com/blog/58_编译脚本篇.html)[ .o](https://my.oschina.net/weharmony)**
* [v57.xx 鸿蒙内核源码分析(编译过程篇) | 简单案例窥视GCC编译全过程 ](https://my.oschina.net/weharmony/blog/5064209) **[ | 51](https://harmonyos.51cto.com/posts/5032)[ .c](https://blog.csdn.net/kuangyufei/article/details/117419679)[ .h](http://weharmonyos.com/blog/57_编译过程篇.html)[ .o](https://my.oschina.net/weharmony)**
......
......@@ -46,16 +46,35 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/****************************************************************
geometry应该翻译为几何数据,其实就是指的CHS(Cylinder、Head、Sector/Track)
C-Cylinder柱面数表示硬盘每面盘片上有几条磁道,编号从0开始,最大为1023,表示有1024个磁道(用10个二进制位存储)
H-Head磁头数表示硬盘总共有几个磁头,也就是几面盘片,编号从0开始,最大为255,表示有256个磁头(用8个二进制位存储);
S-Sector/Track扇区数表示每条磁道上有几个扇区,编号从1开始,最大为63,表示63个扇区(用6个二进制位存储),
每个扇区512字节,它是硬盘的最小存储单位。
我们可以算一下:1024个柱面×63个扇区×256个磁头×512byte=8455716864byte。即通常的8.4GB(实际上应该是7.8GB左右)限制。
实际上磁头数通常只用到255个(由汇编语言的寻址寄存器决定),即使把这3个字节按线性寻址,依然力不从心。
当然现在的硬盘早就超过8.4GB了。
从大到小
H-Head(磁头)---》C-Cylinder(柱面数或者磁道数,即每个磁头的磁道数)------》S-Sector/Track(扇区,也就是每个磁道有多少扇区)--------》扇区大小(512bit)磁盘空间
Geometry:
Cylinder Number - 1020 (0-1024)
Head Number - 16 (0-256)
Sector Number - 63 (1-64)
*****************************************************************/
/* This structure provides information about the state of a block driver */
struct geometry
{
bool geo_available; /* true: The device is available */
bool geo_mediachanged; /* true: The media has changed since last query */
bool geo_writeenabled; /* true: It is okay to write to this device */
unsigned long long geo_nsectors; /* Number of sectors on the device */
size_t geo_sectorsize; /* Size of one sector */
bool geo_available; /* true: The device is available *///设备是否有效
bool geo_mediachanged; /* true: The media has changed since last query *///自上次查询以来媒体已更改
bool geo_writeenabled; /* true: It is okay to write to this device *///是否可写
unsigned long long geo_nsectors; /* Number of sectors on the device *///扇区的数量
size_t geo_sectorsize; /* Size of one sector *///扇区的大小
};
/* This structure is provided by block devices when they register with the
......@@ -64,7 +83,8 @@ struct geometry
* that it deals in struct Vnode vs. struct filep.
*/
struct block_operations
//块驱动操作方式,以 vnode方式操作
struct block_operations //块操作接口类,块是文件系统层面的概念,块(Block)是文件系统存取数据的最小单位,一般大小是4KB
{
int (*open)(struct Vnode *vnode);
int (*close)(struct Vnode *vnode);
......@@ -77,11 +97,13 @@ struct block_operations
int (*unlink)(struct Vnode *vnode);
};
//该结构由文件系统提供,用于描述挂载点。请注意,此结构与 file_operations 的不同之处仅在于 open 方法的形式。
//打开文件后,它可以作为 struct file_operations 或 struct mountpt_operations 访问
struct drv_data
{
const void *ops;
mode_t mode;
void *priv;
const void *ops; //驱动程序 ( block_operations | file_operations_vfs | ... )
mode_t mode; //RWE_RW_RW 0755
void *priv; //私有数据域 (struct file)
};
/****************************************************************************
......
......@@ -99,39 +99,41 @@ struct filelist
extern struct filelist tg_filelist;
#endif
/* This structure is provided by devices when they are registered with the
* system. It is used to call back to perform device specific operations.
*/
struct file_operations_vfs
{
/* The device driver open method differs from the mountpoint open method */
int (*open)(struct file *filep);
/* This structure is provided by devices when they are registered with the
* system. It is used to call back to perform device specific operations.
*/
//该结构由设备在向系统注册时提供,它用于回调以执行特定于设备的操作。
struct file_operations_vfs //vfs 文件操作接口,字符操作数据,各文件系统/设备需要实现这些接口
{
/* The device driver open method differs from the mountpoint open method */
//设备驱动打开方式与挂载点打开方式不同
int (*open)(struct file *filep); //打开文件
//通过文件名打开文件,实际上是分成三步实现:首先,操作系统找到这个文件名对应的inode号码;
//其次,通过inode号码,获取inode信息;最后,根据inode信息,找到文件数据所在的block,读出数据。
/* The following methods must be identical in signature and position because
* the struct file_operations and struct mountp_operations are treated like
* unions.
*///@note_thinking 没明白
//以下方法的签名和位置必须相同,因为 struct file_operations 和 struct mountp_operations 被视为联合
int (*close)(struct file *filep); //关闭文件
ssize_t (*read)(struct file *filep, char *buffer, size_t buflen); //读文件
ssize_t (*write)(struct file *filep, const char *buffer, size_t buflen);//写文件
off_t (*seek)(struct file *filep, off_t offset, int whence);//寻找,检索 文件
int (*ioctl)(struct file *filep, int cmd, unsigned long arg);//对文件的控制命令
int (*mmap)(struct file* filep, struct VmMapRegion *region);//内存映射实现<文件/设备 - 线性区的映射>
/* The two structures need not be common after this point */
#ifndef CONFIG_DISABLE_POLL
int (*poll)(struct file *filep, poll_table *fds); //轮询接口
#endif
int (*stat)(struct file *filep, struct stat* st); //统计接口
int (*fallocate)(struct file* filep, int mode, off_t offset, off_t len);
int (*fallocate64)(struct file *filep, int mode, off64_t offset, off64_t len);
int (*fsync)(struct file *filep);
ssize_t (*readpage)(struct file *filep, char *buffer, size_t buflen);
int (*unlink)(struct Vnode *vnode);
};
/* The following methods must be identical in signature and position because
* the struct file_operations and struct mountp_operations are treated like
* unions.
*/
int (*close)(struct file *filep);
ssize_t (*read)(struct file *filep, char *buffer, size_t buflen);
ssize_t (*write)(struct file *filep, const char *buffer, size_t buflen);
off_t (*seek)(struct file *filep, off_t offset, int whence);
int (*ioctl)(struct file *filep, int cmd, unsigned long arg);
int (*mmap)(struct file* filep, struct VmMapRegion *region);
/* The two structures need not be common after this point */
#ifndef CONFIG_DISABLE_POLL
int (*poll)(struct file *filep, poll_table *fds);
#endif
int (*stat)(struct file *filep, struct stat* st);
int (*fallocate)(struct file* filep, int mode, off_t offset, off_t len);
int (*fallocate64)(struct file *filep, int mode, off64_t offset, off64_t len);
int (*fsync)(struct file *filep);
ssize_t (*readpage)(struct file *filep, char *buffer, size_t buflen);
int (*unlink)(struct Vnode *vnode);
};
/* file mapped in VMM pages */
struct page_mapping {
......
../../../../../third_party/NuttX/include/nuttx/fs/fs.h
\ No newline at end of file
../../../../../third_party/NuttX/include/nuttx/fs/fs.h
......@@ -239,12 +239,12 @@ LITE_OS_SEC_TEXT_INIT INT32 OsMain(VOID)
return ret;
}
ret = OsSystemProcessCreate();
ret = OsSystemProcessCreate();//创建系统进程
if (ret != LOS_OK) {
return ret;
}
ret = ArchInit();
ret = ArchInit(); //MMU架构初始化
if (ret != LOS_OK) {
return ret;
}
......
git add -A
git commit -m ' 注解根文件系统制作过程
git commit -m ' 文件系统几个关键结构体注释
百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
博客输出站点(国内):http://weharmonyos.com
博客输出站点(国外):https://weharmony.github.io
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册