Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Rattenking
rt-thread
提交
cd1e0a79
R
rt-thread
项目概览
Rattenking
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
3
Star
1
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,体验更适合开发者的 AI 搜索 >>
提交
cd1e0a79
编写于
3月 29, 2023
作者:
xqyjlj
提交者:
guo
3月 31, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
feat(components): add statfs, statfs64, fstatfs, fstatfs64 support
上级
e4bd8e00
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
184 addition
and
0 deletion
+184
-0
components/dfs/src/dfs_posix.c
components/dfs/src/dfs_posix.c
+26
-0
components/libc/compilers/common/include/sys/statfs.h
components/libc/compilers/common/include/sys/statfs.h
+16
-0
components/lwp/lwp_syscall.c
components/lwp/lwp_syscall.c
+142
-0
未找到文件。
components/dfs/src/dfs_posix.c
浏览文件 @
cd1e0a79
...
...
@@ -520,6 +520,32 @@ int statfs(const char *path, struct statfs *buf)
}
RTM_EXPORT
(
statfs
);
/**
* this function is a POSIX compliant version, which will return the
* information about a mounted file system.
*
* @param fildes the file description.
* @param buf the buffer to save the returned information.
*
* @return 0 on successful, others on failed.
*/
int
fstatfs
(
int
fildes
,
struct
statfs
*
buf
)
{
struct
dfs_fd
*
d
;
/* get the fd */
d
=
fd_get
(
fildes
);
if
(
d
==
NULL
)
{
rt_set_errno
(
-
EBADF
);
return
-
1
;
}
return
statfs
(
d
->
vnode
->
fullpath
,
buf
);
}
RTM_EXPORT
(
fstatfs
);
/**
* this function is a POSIX compliant version, which will make a directory
*
...
...
components/libc/compilers/common/include/sys/statfs.h
浏览文件 @
cd1e0a79
...
...
@@ -5,6 +5,7 @@
*
* Change Logs:
* Date Author Notes
* 2023-03-27 xqyjlj adapt musl
*/
#ifndef __SYS_STATFS_H__
...
...
@@ -16,16 +17,31 @@
extern
"C"
{
#endif
#ifdef RT_USING_MUSLLIBC
/* this is required for musl <sys/statfs.h> */
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
#include_next <sys/statfs.h>
/* limiting influence of _POSIX_SOURCE */
#undef _POSIX_SOURCE
#else
/* def _POSIX_SOURCE */
#include_next <sys/statfs.h>
#endif
#else
struct
statfs
{
size_t
f_bsize
;
/* block size */
size_t
f_blocks
;
/* total data blocks in file system */
size_t
f_bfree
;
/* free blocks in file system */
size_t
f_bavail
;
/* free blocks available to unprivileged user*/
};
int
statfs
(
const
char
*
path
,
struct
statfs
*
buf
);
int
fstatfs
(
int
fd
,
struct
statfs
*
buf
);
#endif
#ifdef __cplusplus
}
#endif
...
...
components/lwp/lwp_syscall.c
浏览文件 @
cd1e0a79
...
...
@@ -4611,6 +4611,144 @@ sysret_t sys_uname(struct utsname *uts)
return
0
;
}
sysret_t
sys_statfs
(
const
char
*
path
,
struct
statfs
*
buf
)
{
int
ret
=
0
;
int
err
;
size_t
len
;
size_t
copy_len
;
char
*
copy_path
;
struct
statfs
statfsbuff
=
{
0
};
if
(
!
lwp_user_accessable
((
void
*
)
buf
,
sizeof
(
struct
statfs
)))
{
return
-
EFAULT
;
}
len
=
lwp_user_strlen
(
path
,
&
err
);
if
(
err
)
{
return
-
EFAULT
;
}
copy_path
=
(
char
*
)
rt_malloc
(
len
+
1
);
if
(
!
copy_path
)
{
return
-
ENOMEM
;
}
copy_len
=
lwp_get_from_user
(
copy_path
,
(
void
*
)
path
,
len
);
if
(
copy_len
==
0
)
{
rt_free
(
copy_path
);
return
-
EFAULT
;
}
copy_path
[
copy_len
]
=
'\0'
;
ret
=
_SYS_WRAP
(
statfs
(
copy_path
,
&
statfsbuff
));
rt_free
(
copy_path
);
if
(
ret
==
0
)
{
lwp_put_to_user
(
buf
,
&
statfsbuff
,
sizeof
statfsbuff
);
}
return
ret
;
}
sysret_t
sys_statfs64
(
const
char
*
path
,
size_t
sz
,
struct
statfs
*
buf
)
{
int
ret
=
0
;
int
err
;
size_t
len
;
size_t
copy_len
;
char
*
copy_path
;
struct
statfs
statfsbuff
=
{
0
};
if
(
!
lwp_user_accessable
((
void
*
)
buf
,
sizeof
(
struct
statfs
)))
{
return
-
EFAULT
;
}
if
(
sz
!=
sizeof
(
struct
statfs
))
{
return
-
EINVAL
;
}
len
=
lwp_user_strlen
(
path
,
&
err
);
if
(
err
)
{
return
-
EFAULT
;
}
copy_path
=
(
char
*
)
rt_malloc
(
len
+
1
);
if
(
!
copy_path
)
{
return
-
ENOMEM
;
}
copy_len
=
lwp_get_from_user
(
copy_path
,
(
void
*
)
path
,
len
);
if
(
copy_len
==
0
)
{
rt_free
(
copy_path
);
return
-
EFAULT
;
}
copy_path
[
copy_len
]
=
'\0'
;
ret
=
_SYS_WRAP
(
statfs
(
copy_path
,
&
statfsbuff
));
rt_free
(
copy_path
);
if
(
ret
==
0
)
{
lwp_put_to_user
(
buf
,
&
statfsbuff
,
sizeof
statfsbuff
);
}
return
ret
;
}
sysret_t
sys_fstatfs
(
int
fd
,
struct
statfs
*
buf
)
{
int
ret
=
0
;
struct
statfs
statfsbuff
=
{
0
};
if
(
!
lwp_user_accessable
((
void
*
)
buf
,
sizeof
(
struct
statfs
)))
{
return
-
EFAULT
;
}
ret
=
_SYS_WRAP
(
fstatfs
(
fd
,
&
statfsbuff
));
if
(
ret
==
0
)
{
lwp_put_to_user
(
buf
,
&
statfsbuff
,
sizeof
statfsbuff
);
}
return
ret
;
}
sysret_t
sys_fstatfs64
(
int
fd
,
size_t
sz
,
struct
statfs
*
buf
)
{
int
ret
=
0
;
struct
statfs
statfsbuff
=
{
0
};
if
(
!
lwp_user_accessable
((
void
*
)
buf
,
sizeof
(
struct
statfs
)))
{
return
-
EFAULT
;
}
if
(
sz
!=
sizeof
(
struct
statfs
))
{
return
-
EINVAL
;
}
ret
=
_SYS_WRAP
(
fstatfs
(
fd
,
&
statfsbuff
));
if
(
ret
==
0
)
{
lwp_put_to_user
(
buf
,
&
statfsbuff
,
sizeof
statfsbuff
);
}
return
ret
;
}
const
static
struct
rt_syscall_def
func_table
[]
=
{
SYSCALL_SIGN
(
sys_exit
),
/* 01 */
...
...
@@ -4822,6 +4960,10 @@ const static struct rt_syscall_def func_table[] =
SYSCALL_SIGN
(
sys_mq_close
),
SYSCALL_SIGN
(
sys_stat
),
//TODO should be replaced by sys_lstat if symbolic link are implemented
SYSCALL_SIGN
(
sys_uname
),
/* 170 */
SYSCALL_SIGN
(
sys_statfs
),
SYSCALL_SIGN
(
sys_statfs64
),
SYSCALL_SIGN
(
sys_fstatfs
),
SYSCALL_SIGN
(
sys_fstatfs64
),
};
const
void
*
lwp_get_sys_api
(
rt_uint32_t
number
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录