Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
c6f88ef7
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c6f88ef7
编写于
2月 02, 2015
作者:
P
prife
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dfs_win32: add seekdir support
上级
0f9139ec
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
82 addition
and
65 deletion
+82
-65
bsp/simulator/drivers/dfs_win32.c
bsp/simulator/drivers/dfs_win32.c
+82
-65
未找到文件。
bsp/simulator/drivers/dfs_win32.c
浏览文件 @
c6f88ef7
...
@@ -50,6 +50,14 @@
...
@@ -50,6 +50,14 @@
#define WIN32_DIRDISK_ROOT "."
/* "F:\\Project\\svn\\rtt\\trunk\\bsp\\simulator_test" */
#define WIN32_DIRDISK_ROOT "."
/* "F:\\Project\\svn\\rtt\\trunk\\bsp\\simulator_test" */
typedef
struct
{
HANDLE
handle
;
char
*
start
;
char
*
end
;
char
*
curr
;
struct
_finddata_t
finddata
;
}
WINDIR
;
/* There are so many error codes in windows, you'd better google for details.
/* There are so many error codes in windows, you'd better google for details.
* google "System Error Codes (Windows)"
* google "System Error Codes (Windows)"
* http://msdn.microsoft.com/ZH-CN/library/windows/desktop/ms681381(v=vs.85).aspx
* http://msdn.microsoft.com/ZH-CN/library/windows/desktop/ms681381(v=vs.85).aspx
...
@@ -166,8 +174,8 @@ static int dfs_win32_open(struct dfs_fd *file)
...
@@ -166,8 +174,8 @@ static int dfs_win32_open(struct dfs_fd *file)
oflag
=
file
->
flags
;
oflag
=
file
->
flags
;
if
(
oflag
&
DFS_O_DIRECTORY
)
/* operations about dir */
if
(
oflag
&
DFS_O_DIRECTORY
)
/* operations about dir */
{
{
struct
_finddata_t
dir
;
WINDIR
*
wdirp
;
int
handle
;
HANDLE
handle
;
int
len
;
int
len
;
file_path
=
winpath_dirdup
(
WIN32_DIRDISK_ROOT
,
file
->
path
);
file_path
=
winpath_dirdup
(
WIN32_DIRDISK_ROOT
,
file
->
path
);
...
@@ -191,14 +199,24 @@ static int dfs_win32_open(struct dfs_fd *file)
...
@@ -191,14 +199,24 @@ static int dfs_win32_open(struct dfs_fd *file)
strcat
(
file_path
,
"*.*"
);
strcat
(
file_path
,
"*.*"
);
/* _findfirst will get '.' */
/* _findfirst will get '.' */
if
((
handle
=
_findfirst
(
file_path
,
&
dir
))
==
-
1
)
/* save this pointer,will used by dfs_win32_getdents*/
wdirp
=
rt_malloc
(
sizeof
(
WINDIR
));
RT_ASSERT
(
wdirp
!=
NULL
);
if
((
handle
=
_findfirst
(
file_path
,
&
wdirp
->
finddata
))
==
-
1
)
{
{
rt_free
(
wdirp
);
rt_free
(
file_path
);
rt_free
(
file_path
);
goto
__err
;
goto
__err
;
}
}
len
=
strlen
(
wdirp
->
finddata
.
name
)
+
1
;
/* save this pointer,will used by dfs_win32_getdents*/
wdirp
->
handle
=
handle
;
file
->
data
=
(
void
*
)
handle
;
//wdirp->nfiles = 1;
wdirp
->
start
=
malloc
(
len
);
//not rt_malloc!
wdirp
->
end
=
wdirp
->
curr
=
wdirp
->
start
;
wdirp
->
end
+=
len
;
strncpy
(
wdirp
->
curr
,
wdirp
->
finddata
.
name
,
len
);
file
->
data
=
(
void
*
)
wdirp
;
rt_free
(
file_path
);
rt_free
(
file_path
);
return
DFS_STATUS_OK
;
return
DFS_STATUS_OK
;
}
}
...
@@ -243,25 +261,22 @@ __err:
...
@@ -243,25 +261,22 @@ __err:
static
int
dfs_win32_close
(
struct
dfs_fd
*
file
)
static
int
dfs_win32_close
(
struct
dfs_fd
*
file
)
{
{
int
oflag
;
if
(
file
->
flags
&
DFS_O_DIRECTORY
)
oflag
=
file
->
flags
;
if
(
oflag
&
DFS_O_DIRECTORY
)
{
{
/* operations about dir */
WINDIR
*
wdirp
=
(
WINDIR
*
)(
file
->
data
);
if
(
_findclose
((
intptr_t
)
file
->
data
)
<
0
)
RT_ASSERT
(
wdirp
!=
RT_NULL
);
goto
__err
;
if
(
_findclose
((
intptr_t
)
wdirp
->
handle
)
==
0
)
{
free
(
wdirp
->
start
);
//NOTE: here we don't use rt_free!
rt_free
(
wdirp
);
return
0
;
return
0
;
}
}
}
/* regular file operations */
else
/* regular file operations */
if
(
_close
((
int
)(
file
->
data
))
<
0
)
{
goto
__err
;
if
(
_close
((
int
)(
file
->
data
))
==
0
)
return
0
;
return
0
;
}
__err:
return
win32_result_to_dfs
(
GetLastError
());
return
win32_result_to_dfs
(
GetLastError
());
}
}
...
@@ -316,16 +331,19 @@ static int dfs_win32_seek(struct dfs_fd *file,
...
@@ -316,16 +331,19 @@ static int dfs_win32_seek(struct dfs_fd *file,
/* set offset as current offset */
/* set offset as current offset */
if
(
file
->
type
==
FT_DIRECTORY
)
if
(
file
->
type
==
FT_DIRECTORY
)
{
{
return
-
DFS_STATUS_ENOSYS
;
WINDIR
*
wdirp
=
(
WINDIR
*
)(
file
->
data
);
RT_ASSERT
(
wdirp
!=
RT_NULL
);
wdirp
->
curr
=
wdirp
->
start
+
offset
;
return
offset
;
}
}
else
if
(
file
->
type
==
FT_REGULAR
)
else
//
file->type == FT_REGULAR)
{
{
result
=
_lseek
((
int
)(
file
->
data
),
offset
,
SEEK_SET
);
result
=
_lseek
((
int
)(
file
->
data
),
offset
,
SEEK_SET
);
if
(
result
>=
0
)
if
(
result
>=
0
)
return
offset
;
return
offset
;
}
else
return
win32_result_to_dfs
(
GetLastError
());
return
win32_result_to_dfs
(
GetLastError
());
}
}
}
/* return the size of struct dirent*/
/* return the size of struct dirent*/
...
@@ -334,53 +352,52 @@ static int dfs_win32_getdents(
...
@@ -334,53 +352,52 @@ static int dfs_win32_getdents(
struct
dirent
*
dirp
,
struct
dirent
*
dirp
,
rt_uint32_t
count
)
rt_uint32_t
count
)
{
{
rt_uint32_t
index
;
WINDIR
*
wdirp
;
struct
dirent
*
d
;
struct
dirent
*
d
=
dirp
;
struct
_finddata_t
fileinfo
;
int
handle
;
int
result
;
int
result
;
handle
=
(
int
)(
file
->
data
);
/* make integer count */
RT_ASSERT
(
handle
!=
RT_NULL
);
if
(
count
/
sizeof
(
struct
dirent
)
!=
1
)
return
-
DFS_STATUS_EINVAL
;
/* round count, count is always 1 */
count
=
(
count
/
sizeof
(
struct
dirent
))
*
sizeof
(
struct
dirent
);
if
(
count
==
0
)
return
-
DFS_STATUS_EINVAL
;
index
=
0
;
wdirp
=
(
WINDIR
*
)(
file
->
data
);
/* usually, the while loop should only be looped only once! */
RT_ASSERT
(
wdirp
!=
RT_NULL
);
while
(
1
)
if
(
wdirp
->
curr
==
NULL
)
//no more entries in this directory
{
return
0
;
d
=
dirp
+
index
;
if
(
_findnext
(
handle
,
&
fileinfo
)
!=
0
)
//-1 failed
goto
__err
;
if
(
fileinfo
.
attrib
&
_A_SUBDIR
)
/* get the current entry */
d
->
d_type
=
DFS_DT_DIR
;
/* directory */
if
(
wdirp
->
finddata
.
attrib
&
_A_SUBDIR
)
d
->
d_type
=
DFS_DT_DIR
;
else
else
d
->
d_type
=
DFS_DT_REG
;
d
->
d_type
=
DFS_DT_REG
;
d
->
d_namlen
=
strlen
(
wdirp
->
curr
);
/* write the rest arguments of struct dirent* dirp */
strncpy
(
d
->
d_name
,
wdirp
->
curr
,
DFS_PATH_MAX
);
d
->
d_namlen
=
strlen
(
fileinfo
.
name
);
d
->
d_reclen
=
(
rt_uint16_t
)
sizeof
(
struct
dirent
);
d
->
d_reclen
=
(
rt_uint16_t
)
sizeof
(
struct
dirent
);
strcpy
(
d
->
d_name
,
fileinfo
.
name
);
wdirp
->
curr
+=
(
strlen
(
wdirp
->
curr
)
+
1
);
file
->
pos
=
wdirp
->
curr
-
wdirp
->
start
+
sizeof
(
struct
dirent
);
//NOTE!
index
++
;
/* now set up for the next call to readdir */
if
(
index
*
sizeof
(
struct
dirent
)
>=
count
)
if
(
wdirp
->
curr
>=
wdirp
->
end
)
break
;
{
if
(
_findnext
(
wdirp
->
handle
,
&
wdirp
->
finddata
)
==
0
)
{
char
*
old_start
=
wdirp
->
start
;
long
name_len
=
strlen
(
wdirp
->
finddata
.
name
)
+
1
;
wdirp
->
start
=
realloc
(
wdirp
->
start
,
wdirp
->
end
-
wdirp
->
start
+
name_len
);
wdirp
->
curr
=
wdirp
->
start
+
(
wdirp
->
curr
-
old_start
);
wdirp
->
end
=
wdirp
->
curr
+
name_len
;
strcpy
(
wdirp
->
curr
,
wdirp
->
finddata
.
name
);
}
}
if
(
index
==
0
)
else
return
0
;
{
file
->
pos
+=
index
*
sizeof
(
struct
dirent
);
return
index
*
sizeof
(
struct
dirent
);
__err:
if
((
result
=
GetLastError
())
==
ERROR_NO_MORE_FILES
)
if
((
result
=
GetLastError
())
==
ERROR_NO_MORE_FILES
)
return
0
;
wdirp
->
curr
=
NULL
;
else
else
return
win32_result_to_dfs
(
result
);
return
win32_result_to_dfs
(
result
);
}
}
return
sizeof
(
struct
dirent
);
}
}
static
int
dfs_win32_unlink
(
struct
dfs_filesystem
*
fs
,
const
char
*
path
)
static
int
dfs_win32_unlink
(
struct
dfs_filesystem
*
fs
,
const
char
*
path
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录