Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
e952d55d
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看板
提交
e952d55d
编写于
4月 03, 2013
作者:
P
prife
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #70 from geniusgogo/dfs-fixbug
Dfs clean and optimized code
上级
425d2678
f95cd9a3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
31 deletion
+34
-31
components/dfs/src/dfs.c
components/dfs/src/dfs.c
+8
-8
components/dfs/src/dfs_fs.c
components/dfs/src/dfs_fs.c
+26
-23
未找到文件。
components/dfs/src/dfs.c
浏览文件 @
e952d55d
...
...
@@ -188,11 +188,11 @@ void fd_put(struct dfs_fd *fd)
dfs_unlock
();
};
/**
/**
* @ingroup Fd
*
* This function will return whether this file has been opend.
*
*
* @param pathname the file path name.
*
* @return 0 on file has been open successfully, -1 on open failed.
...
...
@@ -220,7 +220,7 @@ int fd_is_open(const char *pathname)
/* get file path name under mounted file system */
if
(
fs
->
path
[
0
]
==
'/'
&&
fs
->
path
[
1
]
==
'\0'
)
mountpath
=
fullpath
;
else
else
mountpath
=
fullpath
+
strlen
(
fs
->
path
);
dfs_lock
();
...
...
@@ -271,7 +271,7 @@ const char *dfs_subdir(const char *directory, const char *filename)
return
dir
;
}
/**
/**
* this function will normalize a path according to specified parent directory
* and file name.
*
...
...
@@ -308,20 +308,20 @@ char *dfs_normalize_path(const char *directory, const char *filename)
return
RT_NULL
;
/* join path and file name */
rt_snprintf
(
fullpath
,
strlen
(
directory
)
+
strlen
(
filename
)
+
2
,
rt_snprintf
(
fullpath
,
strlen
(
directory
)
+
strlen
(
filename
)
+
2
,
"%s/%s"
,
directory
,
filename
);
}
else
{
fullpath
=
rt_strdup
(
filename
);
/* copy string */
if
(
fullpath
==
RT_NULL
)
return
RT_NULL
;
}
src
=
fullpath
;
dst
=
fullpath
;
dst0
=
dst
;
while
(
1
)
{
...
...
@@ -380,7 +380,7 @@ up_one:
dst
--
;
if
(
dst
<
dst0
)
{
rt_free
(
fullpath
);
rt_free
(
fullpath
);
return
RT_NULL
;
}
while
(
dst0
<
dst
&&
dst
[
-
1
]
!=
'/'
)
...
...
components/dfs/src/dfs_fs.c
浏览文件 @
e952d55d
...
...
@@ -32,8 +32,10 @@
int
dfs_register
(
const
struct
dfs_filesystem_operation
*
ops
)
{
int
index
,
result
;
int
free_index
;
result
=
0
;
free_index
=
DFS_FILESYSTEM_TYPES_MAX
;
/* lock filesystem */
dfs_lock
();
...
...
@@ -41,29 +43,28 @@ int dfs_register(const struct dfs_filesystem_operation *ops)
/* check if this filesystem was already registered */
for
(
index
=
0
;
index
<
DFS_FILESYSTEM_TYPES_MAX
;
index
++
)
{
if
(
filesystem_operation_table
[
index
]
!=
RT_NULL
&&
strcmp
(
filesystem_operation_table
[
index
]
->
name
,
ops
->
name
)
==
0
)
if
(
filesystem_operation_table
[
index
]
==
RT_NULL
)
{
/* 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
;
}
}
/* find out an empty filesystem type entry */
for
(
index
=
0
;
index
<
DFS_FILESYSTEM_TYPES_MAX
&&
filesystem_operation_table
[
index
]
!=
RT_NULL
;
index
++
)
;
/* filesystem type table full */
if
(
index
==
DFS_FILESYSTEM_TYPES_MAX
)
if
(
free_
index
==
DFS_FILESYSTEM_TYPES_MAX
)
{
result
=
-
1
;
goto
err
;
}
/* save the filesystem's operations */
filesystem_operation_table
[
index
]
=
ops
;
filesystem_operation_table
[
free_
index
]
=
ops
;
err:
dfs_unlock
();
...
...
@@ -217,7 +218,7 @@ int dfs_mount(const char *device_name,
struct
dfs_filesystem
*
fs
;
char
*
fullpath
=
RT_NULL
;
rt_device_t
dev_id
;
int
index
;
int
index
,
free_index
;
/* open specific device */
if
(
device_name
!=
RT_NULL
)
...
...
@@ -241,20 +242,22 @@ int dfs_mount(const char *device_name,
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
)
break
;
}
dfs_unlock
();
/* can't find filesystem */
if
(
index
==
DFS_FILESYSTEM_TYPES_MAX
)
{
rt_set_errno
(
-
DFS_STATUS_ENODEV
);
dfs_unlock
();
return
-
1
;
}
ops
=
filesystem_operation_table
[
index
];
dfs_unlock
();
/* make full path for special file */
fullpath
=
dfs_normalize_path
(
RT_NULL
,
path
);
...
...
@@ -280,33 +283,33 @@ int dfs_mount(const char *device_name,
dfs_file_close
(
&
fd
);
}
free_index
=
DFS_FILESYSTEMS_MAX
;
/* check whether the file system mounted or not */
dfs_lock
();
for
(
index
=
0
;
index
<
DFS_FILESYSTEMS_MAX
;
index
++
)
{
if
(
filesystem_table
[
index
].
ops
!=
RT_NULL
&&
strcmp
(
filesystem_table
[
index
].
path
,
path
)
==
0
)
if
(
filesystem_table
[
index
].
ops
==
RT_NULL
)
{
/* find out an empty filesystem table entry */
if
(
free_index
==
DFS_FILESYSTEMS_MAX
)
free_index
=
index
;
}
else
if
(
strcmp
(
filesystem_table
[
index
].
path
,
path
)
==
0
)
{
rt_set_errno
(
-
DFS_STATUS_EINVAL
);
goto
err1
;
}
}
/* find out an empty filesystem table entry */
for
(
index
=
0
;
index
<
DFS_FILESYSTEMS_MAX
&&
filesystem_table
[
index
].
ops
!=
RT_NULL
;
index
++
)
;
/* can't find en empty filesystem table entry */
if
(
index
==
DFS_FILESYSTEMS_MAX
)
if
(
free_
index
==
DFS_FILESYSTEMS_MAX
)
{
rt_set_errno
(
-
DFS_STATUS_ENOSPC
);
goto
err1
;
}
/* register file system */
fs
=
&
(
filesystem_table
[
index
]);
fs
=
&
(
filesystem_table
[
free_
index
]);
fs
->
path
=
fullpath
;
fs
->
ops
=
ops
;
fs
->
dev_id
=
dev_id
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录