Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
60f2ae4d
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,发现更多精彩内容 >>
提交
60f2ae4d
编写于
9月 26, 2019
作者:
z13955633063
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[components][dfs]添加ftruncate接口
上级
2a39e590
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
105 addition
and
0 deletion
+105
-0
components/dfs/filesystems/elmfat/dfs_elm.c
components/dfs/filesystems/elmfat/dfs_elm.c
+25
-0
components/dfs/include/dfs_file.h
components/dfs/include/dfs_file.h
+4
-0
components/dfs/include/dfs_posix.h
components/dfs/include/dfs_posix.h
+1
-0
components/dfs/src/dfs_file.c
components/dfs/src/dfs_file.c
+29
-0
components/dfs/src/dfs_posix.c
components/dfs/src/dfs_posix.c
+46
-0
未找到文件。
components/dfs/filesystems/elmfat/dfs_elm.c
浏览文件 @
60f2ae4d
...
...
@@ -478,6 +478,31 @@ int dfs_elm_close(struct dfs_fd *file)
int
dfs_elm_ioctl
(
struct
dfs_fd
*
file
,
int
cmd
,
void
*
args
)
{
switch
(
cmd
)
{
case
RT_FIOFTRUNCATE
:
{
FIL
*
fd
;
FSIZE_t
fptr
,
length
;
FRESULT
result
=
FR_OK
;
fd
=
(
FIL
*
)(
file
->
data
);
RT_ASSERT
(
fd
!=
RT_NULL
);
/* save file read/write point */
fptr
=
fd
->
fptr
;
length
=
*
(
off_t
*
)
args
;
if
(
length
<=
fd
->
obj
.
objsize
)
{
fd
->
fptr
=
length
;
result
=
f_truncate
(
fd
);
}
else
{
result
=
f_lseek
(
fd
,
length
);
}
/* restore file read/write point */
fd
->
fptr
=
fptr
;
return
elm_result_to_dfs
(
result
);
}
}
return
-
ENOSYS
;
}
...
...
components/dfs/include/dfs_file.h
浏览文件 @
60f2ae4d
...
...
@@ -66,6 +66,10 @@ int dfs_file_lseek(struct dfs_fd *fd, off_t offset);
int
dfs_file_stat
(
const
char
*
path
,
struct
stat
*
buf
);
int
dfs_file_rename
(
const
char
*
oldpath
,
const
char
*
newpath
);
int
dfs_file_ftruncate
(
struct
dfs_fd
*
fd
,
off_t
length
);
/* 0x5254 is just a magic number to make these relatively unique ("RT") */
#define RT_FIOFTRUNCATE 0x52540000U
#ifdef __cplusplus
}
...
...
components/dfs/include/dfs_posix.h
浏览文件 @
60f2ae4d
...
...
@@ -58,6 +58,7 @@ int fstat(int fildes, struct stat *buf);
int
fsync
(
int
fildes
);
int
fcntl
(
int
fildes
,
int
cmd
,
...);
int
ioctl
(
int
fildes
,
int
cmd
,
...);
int
ftruncate
(
int
fd
,
off_t
length
);
/* directory api*/
int
rmdir
(
const
char
*
path
);
...
...
components/dfs/src/dfs_file.c
浏览文件 @
60f2ae4d
...
...
@@ -482,6 +482,35 @@ __exit:
return
result
;
}
/**
* this function is will cause the regular file referenced by fd
* to be truncated to a size of precisely length bytes.
*
* @param fd the file descriptor.
* @param length the length to be truncated.
*
* @return the status of truncated.
*/
int
dfs_file_ftruncate
(
struct
dfs_fd
*
fd
,
off_t
length
)
{
int
result
;
/* fd is null or not a regular file system fd, or length is invalid */
if
(
fd
==
NULL
||
fd
->
type
!=
FT_REGULAR
||
length
<
0
)
return
-
EINVAL
;
if
(
fd
->
fops
->
ioctl
==
NULL
)
return
-
ENOSYS
;
result
=
fd
->
fops
->
ioctl
(
fd
,
RT_FIOFTRUNCATE
,
(
void
*
)
&
length
);
/* update current size */
if
(
result
==
0
)
fd
->
size
=
length
;
return
result
;
}
#ifdef RT_USING_FINSH
#include <finsh.h>
...
...
components/dfs/src/dfs_posix.c
浏览文件 @
60f2ae4d
...
...
@@ -471,6 +471,52 @@ int ioctl(int fildes, int cmd, ...)
}
RTM_EXPORT
(
ioctl
);
/**
*
* this function is a POSIX compliant version, which cause the regular file
* referenced by fd to be truncated to a size of precisely length bytes.
* @param fd the file descriptor.
* @param length the length to be truncated.
*
* @return Upon successful completion, ftruncate() shall return 0;
* otherwise, -1 shall be returned and errno set to indicate the error.
*/
int
ftruncate
(
int
fd
,
off_t
length
)
{
int
result
;
struct
dfs_fd
*
d
;
d
=
fd_get
(
fd
);
if
(
d
==
NULL
)
{
rt_set_errno
(
-
EBADF
);
return
-
1
;
}
if
(
length
<
0
)
{
fd_put
(
d
);
rt_set_errno
(
-
EINVAL
);
return
-
1
;
}
result
=
dfs_file_ftruncate
(
d
,
length
);
if
(
result
<
0
)
{
fd_put
(
d
);
rt_set_errno
(
result
);
return
-
1
;
}
/* release the ref-count of fd */
fd_put
(
d
);
return
0
;
}
RTM_EXPORT
(
ftruncate
);
/**
* this function is a POSIX compliant version, which will return the
* information about a mounted file system.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录