Skip to content

Commit 56a5d3d

Browse files
committed
working on IMFS_initialize
1 parent 4db6b26 commit 56a5d3d

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

cpukit/include/rtems/imfs.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ struct IMFS_jnode_tt
150150
const IMFS_node_control *control;
151151
};
152152

153+
typedef struct
154+
{
155+
const IMFS_mknod_control *directory;
156+
const IMFS_mknod_control *device;
157+
const IMFS_mknod_control *file;
158+
const IMFS_mknod_control *fifo;
159+
} IMFS_mknod_controls;
160+
161+
typedef struct
162+
{
163+
IMFS_directory_t Root_directory;
164+
const IMFS_mknod_controls *mknod_controls;
165+
} IMFS_fs_info_t;
166+
167+
typedef struct
168+
{
169+
IMFS_fs_info_t *fs_info;
170+
const rtems_filesystem_operations_table *ops;
171+
const IMFS_mknod_controls *mknod_controls;
172+
} IMFS_mount_data;
173+
153174
/*
154175
* Routines
155176
*/

cpukit/libfs/src/imfs/imfs_init.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
static const rtems_filesystem_operations_table IMFS_ops = {
2+
.lock_h = rtems_filesystem_default_lock,
3+
.unlock_h = rtems_filesystem_default_unlock,
4+
.eval_path_h = IMFS_eval_path,
5+
.link_h = IMFS_link,
6+
.are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal,
7+
.mknod_h = IMFS_mknod,
8+
.rmnod_h = IMFS_rmnod,
9+
.fchmod_h = IMFS_fchmod,
10+
.chown_h = IMFS_chown,
11+
.clonenod_h = IMFS_node_clone,
12+
.freenod_h = IMFS_node_free,
13+
.mount_h = IMFS_mount,
14+
.unmount_h = IMFS_unmount,
15+
.fsunmount_me_h = IMFS_fsunmount,
16+
.utimens_h = IMFS_utimens,
17+
.symlink_h = IMFS_symlink,
18+
.readlink_h = IMFS_readlink,
19+
.rename_h = IMFS_rename,
20+
.statvfs_h = rtems_filesystem_default_statvfs};
21+
22+
// 初始化 IMFS 文件系统并挂载到指定挂载点。成功返回 0,失败返回 -1 并设置 errno。
23+
int IMFS_initialize(
24+
rtems_filesystem_mount_table_entry_t *mt_entry, // 挂载点表项,描述挂载目标。
25+
const void *data // 可选的初始化数据(未使用)。
26+
)
27+
{
28+
// 为 IMFS 文件系统信息结构分配并清零内存。
29+
IMFS_fs_info_t *fs_info = calloc(1, sizeof(*fs_info));
30+
31+
// 构造挂载所需的初始化数据结构,包括操作集和创建节点控制表。
32+
IMFS_mount_data mount_data = {
33+
.fs_info = fs_info, // 文件系统内部信息。
34+
.ops = &IMFS_ops, // 文件系统操作函数集合。
35+
.mknod_controls = &IMFS_default_mknod_controls // 创建节点控制信息。
36+
};
37+
38+
// 内存分配失败,返回 ENOMEM。
39+
if (fs_info == NULL)
40+
{
41+
rtems_set_errno_and_return_minus_one(ENOMEM);
42+
}
43+
44+
// 调用实际支持函数完成文件系统的初始化和挂载。
45+
return IMFS_initialize_support(mt_entry, &mount_data);
46+
}

0 commit comments

Comments
 (0)