Skip to content

Commit cf57071

Browse files
committed
deeper understanding of rtems_filesystem_register
1 parent f674348 commit cf57071

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

为了工作/Linux/内核层/Rtems Source Code.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ categories:
55
- 内核层
66
abbrlink: 4936fe45
77
date: 2025-05-19 12:50:00
8-
updated: 2025-06-04 17:25:00
8+
updated: 2025-06-18 17:20:00
99
---
1010

1111
<meta name="referrer" content="no-referrer"/>
@@ -579,6 +579,26 @@ flowchart TD
579579
O --> P[设置 errno 等于 EINVAL 并返回 -1]
580580
```
581581

582+
在 rtems_filesystem_register() 的源码中,有几行比较细节的地方。在 Rtems 中,文件系统的注册全局表有两个,一个是静态表 rtems_filesystem_table,一个是动态表 filesystem_chain。静态表是 Rtems 预先定义好的常量,提供了 Rtems 内置的文件系统。动态表用于用户动态注册文件系统,在下面的函数实现中,如果发现全局表没有注册该文件系统,Rtems 会将该文件系统挂到 filesystem_chain 上。
583+
584+
好,问题来了,表里面除了 type 成员,更重要的是挂载函数 rtems_filesystem_fsmount_me_t。这个函数是需要我们自己写的,也就是说 Rtems 在注册文件系统的时候,除了记录到注册全局表以后,就没有其他架构上的操作了。后面的操作都需要我们自己做,Rtems 的文件系统虚拟层目前看起来几乎没有。
585+
586+
```c
587+
rtems_chain_control *chain = &filesystem_chain;
588+
589+
...
590+
591+
if (rtems_filesystem_get_mount_handler(type) == NULL)
592+
{
593+
rtems_chain_initialize_node(&fsn->node);
594+
rtems_chain_append_unprotected(chain, &fsn->node);
595+
}
596+
else
597+
{
598+
...
599+
}
600+
```
601+
582602
#### struct filesystem_node
583603

584604
struct filesystem_node 结构体的作用是将一个文件系统的描述信息封装为链表中的一个节点,使得多个文件系统表项可以通过链表的形式组织和管理。它结合了 Rtems 的链表节点结构 rtems_chain_node 与文件系统表项 rtems_filesystem_table_t,方便在系统中动态维护、查找和操作支持的文件系统。该结构体通常用于构建一个文件系统注册表,实现对多个文件系统的统一管理和遍历。

0 commit comments

Comments
 (0)