Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
f4e8820b
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f4e8820b
编写于
12月 19, 2013
作者:
P
prife
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dfs: refine more code
clean code with pointer rather than index
上级
7fd6d17d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
67 deletion
+49
-67
components/dfs/src/dfs_fs.c
components/dfs/src/dfs_fs.c
+49
-67
未找到文件。
components/dfs/src/dfs_fs.c
浏览文件 @
f4e8820b
...
...
@@ -37,48 +37,36 @@
*
* @param ops the file system instance to be registered.
*
* @return
0 on successful, -1
on failed.
* @return
RT_EOK on successful, -RT_ERROR
on failed.
*/
int
dfs_register
(
const
struct
dfs_filesystem_operation
*
ops
)
{
int
index
,
result
;
int
free_index
;
result
=
0
;
free_index
=
DFS_FILESYSTEM_TYPES_MAX
;
int
ret
=
RT_EOK
;
const
struct
dfs_filesystem_operation
**
empty
=
RT_NULL
;
const
struct
dfs_filesystem_operation
**
iter
;
/* lock filesystem */
dfs_lock
();
/* check if this filesystem was already registered */
for
(
index
=
0
;
index
<
DFS_FILESYSTEM_TYPES_MAX
;
index
++
)
for
(
iter
=
&
filesystem_operation_table
[
0
];
iter
<
&
filesystem_operation_table
[
DFS_FILESYSTEM_TYPES_MAX
];
iter
++
)
{
if
(
filesystem_operation_table
[
index
]
==
RT_NULL
)
/* find out an empty filesystem type entry */
if
(
*
iter
==
RT_NULL
)
(
empty
==
RT_NULL
)
?
(
empty
=
iter
)
:
0
;
else
if
(
strcmp
((
*
iter
)
->
name
,
ops
->
name
)
==
0
)
{
/* find out an empty filesystem type entry */
if
(
free_index
==
DFS_FILESYSTEM_TYPES_MAX
)
free_index
=
index
;
}
else
if
(
strcmp
(
filesystem_operation_table
[
index
]
->
name
,
ops
->
name
)
==
0
)
{
result
=
-
1
;
goto
err
;
ret
=
-
1
;
break
;
}
}
/* filesystem type table full */
if
(
free_index
==
DFS_FILESYSTEM_TYPES_MAX
)
{
result
=
-
1
;
goto
err
;
}
/* save the filesystem's operations */
filesystem_operation_table
[
free_index
]
=
ops
;
if
((
ret
==
RT_EOK
)
&&
(
empty
!=
RT_NULL
))
*
empty
=
ops
;
err:
dfs_unlock
();
return
re
sul
t
;
return
ret
;
}
/**
...
...
@@ -91,38 +79,38 @@ err:
*/
struct
dfs_filesystem
*
dfs_filesystem_lookup
(
const
char
*
path
)
{
struct
dfs_filesystem
*
fs
;
rt_uint32_t
index
,
fspath
,
prefixlen
;
struct
dfs_filesystem
*
iter
;
struct
dfs_filesystem
*
empty
=
RT_NULL
;
rt_uint32_t
fspath
,
prefixlen
;
fs
=
RT_NULL
;
prefixlen
=
0
;
/* lock filesystem */
dfs_lock
();
/* lookup it in the filesystem table */
for
(
index
=
0
;
index
<
DFS_FILESYSTEMS_MAX
;
index
++
)
for
(
iter
=
&
filesystem_table
[
0
];
iter
<
&
filesystem_table
[
DFS_FILESYSTEMS_MAX
];
iter
++
)
{
if
((
filesystem_table
[
index
].
path
==
RT_NULL
)
||
(
filesystem_table
[
index
].
ops
==
RT_NULL
))
if
((
iter
->
path
==
RT_NULL
)
||
(
iter
->
ops
==
RT_NULL
))
continue
;
fspath
=
strlen
(
filesystem_table
[
index
].
path
);
fspath
=
strlen
(
iter
->
path
);
if
((
fspath
<
prefixlen
)
||
(
strncmp
(
filesystem_table
[
index
].
path
,
path
,
fspath
)
!=
0
))
||
(
strncmp
(
iter
->
path
,
path
,
fspath
)
!=
0
))
continue
;
/* check next path separator */
if
(
fspath
>
1
&&
(
strlen
(
path
)
>
fspath
)
&&
(
path
[
fspath
]
!=
'/'
))
continue
;
fs
=
&
filesystem_table
[
index
]
;
empty
=
iter
;
prefixlen
=
fspath
;
}
dfs_unlock
();
return
fs
;
return
empty
;
}
/**
...
...
@@ -198,11 +186,11 @@ int dfs_mount(const char *device_name,
unsigned
long
rwflag
,
const
void
*
data
)
{
const
struct
dfs_filesystem_operation
*
ops
;
struct
dfs_filesystem
*
fs
;
char
*
fullpath
=
RT_NULL
;
const
struct
dfs_filesystem_operation
**
ops
;
struct
dfs_filesystem
*
iter
;
struct
dfs_filesystem
*
fs
=
RT_NULL
;
char
*
fullpath
=
RT_NULL
;
rt_device_t
dev_id
;
int
index
,
free_index
;
/* open specific device */
if
(
device_name
==
RT_NULL
)
...
...
@@ -217,28 +205,25 @@ int dfs_mount(const char *device_name,
return
-
1
;
}
/* find out specific filesystem */
/* find out
the
specific filesystem */
dfs_lock
();
for
(
index
=
0
;
index
<
DFS_FILESYSTEM_TYPES_MAX
;
index
++
)
{
if
(
filesystem_operation_table
[
index
]
==
RT_NULL
)
continue
;
if
(
strcmp
(
filesystem_operation_table
[
index
]
->
name
,
filesystemtype
)
==
0
)
for
(
ops
=
&
filesystem_operation_table
[
0
];
ops
<
&
filesystem_operation_table
[
DFS_FILESYSTEM_TYPES_MAX
];
ops
++
)
if
((
ops
!=
RT_NULL
)
&&
(
strcmp
((
*
ops
)
->
name
,
filesystemtype
)
==
0
))
break
;
}
dfs_unlock
();
/* can't find filesystem */
if
(
index
==
DFS_FILESYSTEM_TYPES_MAX
)
if
(
ops
==
&
filesystem_operation_table
[
DFS_FILESYSTEM_TYPES_MAX
])
{
/* can't find filesystem */
rt_set_errno
(
-
DFS_STATUS_ENODEV
);
return
-
1
;
}
/* check if there is mount implementation */
ops
=
filesystem_operation_table
[
index
];
if
((
ops
==
NULL
)
||
(
ops
->
mount
==
NULL
))
if
((
*
ops
==
NULL
)
||
((
*
ops
)
->
mount
==
NULL
))
{
rt_set_errno
(
-
DFS_STATUS_ENOSYS
);
return
-
1
;
...
...
@@ -267,36 +252,33 @@ int dfs_mount(const char *device_name,
dfs_file_close
(
&
fd
);
}
/* check whether the file system mounted or not
*/
free_index
=
DFS_FILESYSTEMS_MAX
;
/* check whether the file system mounted or not
in the filesystem table
* if it is unmounted yet, find out an empty entry */
dfs_lock
();
for
(
index
=
0
;
index
<
DFS_FILESYSTEMS_MAX
;
index
++
)
for
(
iter
=
&
filesystem_table
[
0
];
iter
<
&
filesystem_table
[
DFS_FILESYSTEMS_MAX
];
iter
++
)
{
if
(
filesystem_table
[
index
].
ops
==
RT_NULL
)
{
/* find out an empty filesystem table entry */
if
(
free_index
==
DFS_FILESYSTEMS_MAX
)
free_index
=
index
;
}
/* check if it is an empty filesystem table entry? if it is, save fs */
if
(
iter
->
ops
==
RT_NULL
)
(
fs
==
RT_NULL
)
?
(
fs
=
iter
)
:
0
;
/* check if the PATH is mounted */
else
if
(
strcmp
(
filesystem_table
[
index
].
path
,
path
)
==
0
)
else
if
(
strcmp
(
iter
->
path
,
path
)
==
0
)
{
rt_set_errno
(
-
DFS_STATUS_EINVAL
);
goto
err1
;
}
}
/* can't find en empty filesystem table entry */
if
(
free_index
==
DFS_FILESYSTEMS_MAX
)
if
((
fs
==
RT_NULL
)
&&
(
iter
==
&
filesystem_table
[
DFS_FILESYSTEMS_MAX
]))
{
rt_set_errno
(
-
DFS_STATUS_ENOSPC
);
goto
err1
;
}
/* register file system */
fs
=
&
(
filesystem_table
[
free_index
]);
fs
->
path
=
fullpath
;
fs
->
ops
=
ops
;
fs
->
ops
=
*
ops
;
fs
->
dev_id
=
dev_id
;
/* release filesystem_table lock */
dfs_unlock
();
...
...
@@ -306,7 +288,7 @@ int dfs_mount(const char *device_name,
rt_device_open
(
fs
->
dev_id
,
RT_DEVICE_OFLAG_RDWR
);
/* call mount of this filesystem */
if
(
ops
->
mount
(
fs
,
rwflag
,
data
)
<
0
)
if
(
(
*
ops
)
->
mount
(
fs
,
rwflag
,
data
)
<
0
)
{
/* close device */
if
(
dev_id
!=
RT_NULL
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录