Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
0dc79479
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
460
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0dc79479
编写于
7月 23, 2021
作者:
O
openharmony_ci
提交者:
Gitee
7月 23, 2021
浏览文件
操作
浏览文件
下载
差异文件
!436 toybox升级_内核依赖
Merge pull request !436 from wangchen/toybox
上级
0dfa58ca
2ff44c49
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
336 addition
and
20 deletion
+336
-20
compat/posix/src/misc.c
compat/posix/src/misc.c
+13
-3
syscall/fs_syscall.c
syscall/fs_syscall.c
+242
-16
syscall/los_syscall.c
syscall/los_syscall.c
+0
-1
syscall/los_syscall.h
syscall/los_syscall.h
+5
-0
syscall/syscall_lookup.h
syscall/syscall_lookup.h
+6
-0
syscall/syscall_pub.c
syscall/syscall_pub.c
+65
-0
syscall/syscall_pub.h
syscall/syscall_pub.h
+5
-0
未找到文件。
compat/posix/src/misc.c
浏览文件 @
0dc79479
...
...
@@ -36,7 +36,7 @@
#include "sys/utsname.h"
#include "mqueue.h"
#include "semaphore.h"
#include "los_hw.h"
/*
* Supply some suitable values for constants that may not be present
...
...
@@ -52,17 +52,27 @@
int
uname
(
struct
utsname
*
name
)
{
INT32
ret
;
const
char
*
cpuInfo
=
NULL
;
if
(
name
==
NULL
)
{
return
-
EFAULT
;
}
(
VOID
)
strncpy_s
(
name
->
sysname
,
sizeof
(
name
->
sysname
),
KERNEL_NAME
,
strlen
(
KERNEL_NAME
)
+
1
);
(
VOID
)
strncpy_s
(
name
->
nodename
,
sizeof
(
name
->
nodename
),
"hisilicon"
,
strlen
(
"hisilicon"
)
+
1
);
ret
=
snprintf_s
(
name
->
version
,
sizeof
(
name
->
version
),
sizeof
(
name
->
version
)
-
1
,
"%s %u.%u.%u.%u %s %s
\n
"
,
ret
=
snprintf_s
(
name
->
version
,
sizeof
(
name
->
version
),
sizeof
(
name
->
version
)
-
1
,
"%s %u.%u.%u.%u %s %s"
,
KERNEL_NAME
,
KERNEL_MAJOR
,
KERNEL_MINOR
,
KERNEL_PATCH
,
KERNEL_ITRE
,
__DATE__
,
__TIME__
);
if
(
ret
<
0
)
{
return
-
EIO
;
}
name
->
machine
[
0
]
=
'\0'
;
cpuInfo
=
LOS_CpuInfo
();
(
VOID
)
strncpy_s
(
name
->
machine
,
sizeof
(
name
->
machine
),
cpuInfo
,
sizeof
(
name
->
machine
));
ret
=
snprintf_s
(
name
->
release
,
sizeof
(
name
->
release
),
sizeof
(
name
->
release
)
-
1
,
"%u.%u.%u.%u"
,
KERNEL_MAJOR
,
KERNEL_MINOR
,
KERNEL_PATCH
,
KERNEL_ITRE
);
if
(
ret
<
0
)
{
return
-
EIO
;
}
name
->
domainname
[
0
]
=
'\0'
;
return
0
;
}
...
...
syscall/fs_syscall.c
浏览文件 @
0dc79479
...
...
@@ -29,11 +29,13 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "syscall_pub.h"
#ifdef LOSCFG_FS_VFS
#include "errno.h"
#include "unistd.h"
#include "fs/fd_table.h"
#include "fs/file.h"
#include "fs/fs.h"
#include "fs/fs_operation.h"
#include "sys/mount.h"
#include "los_task_pri.h"
...
...
@@ -56,29 +58,77 @@
#include "sys/statfs.h"
#define HIGH_SHIFT_BIT 32
#define TIMESPEC_TIMES_NUM 2
static
int
UserPathCopy
(
const
char
*
userPath
,
char
**
pathBuf
)
static
int
CheckNewAttrTime
(
struct
IATTR
*
attr
,
struct
timespec
times
[
TIMESPEC_TIMES_NUM
]
)
{
int
ret
;
int
ret
=
ENOERR
;
struct
timespec
stp
=
{
0
};
*
pathBuf
=
(
char
*
)
LOS_MemAlloc
(
OS_SYS_MEM_ADDR
,
PATH_MAX
+
1
);
if
(
*
pathBuf
==
NULL
)
{
return
-
ENOMEM
;
if
(
times
)
{
if
(
times
[
0
].
tv_nsec
==
UTIME_OMIT
)
{
attr
->
attr_chg_valid
&=
~
CHG_ATIME
;
}
else
if
(
times
[
0
].
tv_nsec
==
UTIME_NOW
)
{
ret
=
clock_gettime
(
CLOCK_REALTIME
,
&
stp
);
if
(
ret
<
0
)
{
return
-
get_errno
();
}
attr
->
attr_chg_atime
=
(
unsigned
int
)
stp
.
tv_sec
;
attr
->
attr_chg_valid
|=
CHG_ATIME
;
}
else
{
attr
->
attr_chg_atime
=
(
unsigned
int
)
times
[
0
].
tv_sec
;
attr
->
attr_chg_valid
|=
CHG_ATIME
;
}
if
(
times
[
1
].
tv_nsec
==
UTIME_OMIT
)
{
attr
->
attr_chg_valid
&=
~
CHG_MTIME
;
}
else
if
(
times
[
1
].
tv_nsec
==
UTIME_NOW
)
{
ret
=
clock_gettime
(
CLOCK_REALTIME
,
&
stp
);
if
(
ret
<
0
)
{
return
-
get_errno
();
}
attr
->
attr_chg_mtime
=
(
unsigned
int
)
stp
.
tv_sec
;
attr
->
attr_chg_valid
|=
CHG_MTIME
;
}
else
{
attr
->
attr_chg_mtime
=
(
unsigned
int
)
times
[
1
].
tv_sec
;
attr
->
attr_chg_valid
|=
CHG_MTIME
;
}
}
else
{
ret
=
clock_gettime
(
CLOCK_REALTIME
,
&
stp
);
if
(
ret
<
0
)
{
return
-
get_errno
();
}
attr
->
attr_chg_atime
=
(
unsigned
int
)
stp
.
tv_sec
;
attr
->
attr_chg_mtime
=
(
unsigned
int
)
stp
.
tv_sec
;
attr
->
attr_chg_valid
|=
CHG_ATIME
;
attr
->
attr_chg_valid
|=
CHG_MTIME
;
}
ret
=
LOS_StrncpyFromUser
(
*
pathBuf
,
userPath
,
PATH_MAX
+
1
);
if
(
ret
<
0
)
{
(
void
)
LOS_MemFree
(
OS_SYS_MEM_ADDR
,
*
pathBuf
);
*
pathBuf
=
NULL
;
return
ret
;
}
else
if
(
ret
>
PATH_MAX
)
{
(
void
)
LOS_MemFree
(
OS_SYS_MEM_ADDR
,
*
pathBuf
);
*
pathBuf
=
NULL
;
return
-
ENAMETOOLONG
;
return
ret
;
}
static
int
GetFullpathNull
(
int
fd
,
const
char
*
path
,
char
**
filePath
)
{
int
ret
;
char
*
fullPath
=
NULL
;
struct
file
*
file
=
NULL
;
if
((
fd
!=
AT_FDCWD
)
&&
(
path
==
NULL
))
{
fd
=
GetAssociatedSystemFd
(
fd
);
ret
=
fs_getfilep
(
fd
,
&
file
);
if
(
ret
<
0
)
{
return
-
get_errno
();
}
fullPath
=
file
->
f_path
;
}
else
{
ret
=
GetFullpath
(
fd
,
path
,
&
fullPath
);
if
(
ret
<
0
)
{
return
ret
;
}
}
(
*
pathBuf
)[
ret
]
=
'\0'
;
return
0
;
*
filePath
=
fullPath
;
return
ret
;
}
static
int
UserIovItemCheck
(
const
struct
iovec
*
iov
,
const
int
iovcnt
)
...
...
@@ -2124,6 +2174,37 @@ OUT:
return
result
;
}
int
SysUtimensat
(
int
fd
,
const
char
*
path
,
struct
timespec
times
[
TIMESPEC_TIMES_NUM
],
int
flag
)
{
int
ret
;
int
timeLen
;
struct
IATTR
attr
=
{
0
};
char
*
filePath
=
NULL
;
timeLen
=
TIMESPEC_TIMES_NUM
*
sizeof
(
struct
timespec
);
CHECK_ASPACE
(
times
,
timeLen
);
DUP_FROM_USER
(
times
,
timeLen
);
ret
=
CheckNewAttrTime
(
&
attr
,
times
);
FREE_DUP
(
times
);
if
(
ret
<
0
)
{
goto
OUT
;
}
ret
=
GetFullpathNull
(
fd
,
path
,
&
filePath
);
if
(
ret
<
0
)
{
goto
OUT
;
}
ret
=
chattr
(
filePath
,
&
attr
);
if
(
ret
<
0
)
{
ret
=
-
get_errno
();
}
OUT:
PointerFree
(
filePath
);
return
ret
;
}
int
SysChmod
(
const
char
*
pathname
,
mode_t
mode
)
{
int
ret
;
...
...
@@ -2148,6 +2229,112 @@ OUT:
return
ret
;
}
int
SysFchmodat
(
int
fd
,
const
char
*
path
,
mode_t
mode
,
int
flag
)
{
int
ret
;
char
*
pathRet
=
NULL
;
char
*
fullpath
=
NULL
;
struct
IATTR
attr
=
{
.
attr_chg_mode
=
mode
,
.
attr_chg_valid
=
CHG_MODE
,
};
if
(
path
!=
NULL
)
{
ret
=
UserPathCopy
(
path
,
&
pathRet
);
if
(
ret
!=
0
)
{
goto
OUT
;
}
}
if
(
fd
!=
AT_FDCWD
)
{
/* Process fd convert to system global fd */
fd
=
GetAssociatedSystemFd
(
fd
);
}
ret
=
vfs_normalize_pathat
(
fd
,
pathRet
,
&
fullpath
);
if
(
ret
<
0
)
{
goto
OUT
;
}
ret
=
chattr
(
fullpath
,
&
attr
);
if
(
ret
<
0
)
{
ret
=
-
get_errno
();
}
OUT:
PointerFree
(
pathRet
);
PointerFree
(
fullpath
);
return
ret
;
}
int
SysFchownat
(
int
fd
,
const
char
*
path
,
uid_t
owner
,
gid_t
group
,
int
flag
)
{
int
ret
;
char
*
fullpath
=
NULL
;
struct
IATTR
attr
=
{
.
attr_chg_valid
=
0
,
};
ret
=
GetFullpath
(
fd
,
path
,
&
fullpath
);
if
(
ret
<
0
)
{
goto
OUT
;
}
if
(
owner
!=
(
uid_t
)
-
1
)
{
attr
.
attr_chg_uid
=
owner
;
attr
.
attr_chg_valid
|=
CHG_UID
;
}
if
(
group
!=
(
gid_t
)
-
1
)
{
attr
.
attr_chg_gid
=
group
;
attr
.
attr_chg_valid
|=
CHG_GID
;
}
ret
=
chattr
(
fullpath
,
&
attr
);
if
(
ret
<
0
)
{
ret
=
-
get_errno
();
}
OUT:
PointerFree
(
fullpath
);
return
ret
;
}
int
SysFchown
(
int
fd
,
uid_t
owner
,
gid_t
group
)
{
int
ret
;
int
sysFd
;
struct
IATTR
attr
=
{
0
};
attr
.
attr_chg_valid
=
0
;
struct
file
*
file
=
NULL
;
sysFd
=
GetAssociatedSystemFd
(
fd
);
if
(
sysFd
<
0
)
{
return
-
EBADF
;
}
ret
=
fs_getfilep
(
sysFd
,
&
file
);
if
(
ret
<
0
)
{
return
-
get_errno
();
}
if
(
owner
!=
(
uid_t
)
-
1
)
{
attr
.
attr_chg_uid
=
owner
;
attr
.
attr_chg_valid
|=
CHG_UID
;
}
if
(
group
!=
(
gid_t
)
-
1
)
{
attr
.
attr_chg_gid
=
group
;
attr
.
attr_chg_valid
|=
CHG_GID
;
}
ret
=
chattr
(
file
->
f_path
,
&
attr
);
if
(
ret
<
0
)
{
ret
=
-
get_errno
();
}
return
ret
;
}
int
SysChown
(
const
char
*
pathname
,
uid_t
owner
,
gid_t
group
)
{
int
ret
;
...
...
@@ -2218,4 +2405,43 @@ OUT:
}
return
ret
;
}
int
SysFaccessat
(
int
fd
,
const
char
*
filename
,
int
amode
,
int
flag
)
{
int
ret
;
struct
stat
buf
;
struct
statfs
fsBuf
;
char
*
fullDirectory
=
NULL
;
ret
=
GetFullpath
(
fd
,
filename
,
&
fullDirectory
);
if
(
ret
<
0
)
{
goto
OUT
;
}
ret
=
statfs
(
fullDirectory
,
&
fsBuf
);
if
(
ret
!=
0
)
{
ret
=
-
get_errno
();
goto
OUT
;
}
if
((
fsBuf
.
f_flags
&
MS_RDONLY
)
&&
((
unsigned
int
)
amode
&
W_OK
))
{
ret
=
-
EROFS
;
goto
OUT
;
}
ret
=
stat
(
fullDirectory
,
&
buf
);
if
(
ret
!=
0
)
{
ret
=
-
get_errno
();
goto
OUT
;
}
if
(
VfsPermissionCheck
(
buf
.
st_uid
,
buf
.
st_gid
,
buf
.
st_mode
,
amode
))
{
ret
=
-
EACCES
;
}
OUT:
PointerFree
(
fullDirectory
);
return
ret
;
}
#endif
syscall/los_syscall.c
浏览文件 @
0dc79479
...
...
@@ -32,7 +32,6 @@
#define _GNU_SOURCE
#ifdef LOSCFG_FS_VFS
#include "fs/file.h"
#include "fs/file.h"
#endif
#include "los_init.h"
#include "los_signal.h"
...
...
syscall/los_syscall.h
浏览文件 @
0dc79479
...
...
@@ -231,7 +231,11 @@ extern ssize_t SysReadlinkat(int dirfd, const char *pathname, char *buf, size_t
extern
int
SysUnlink
(
const
char
*
pathname
);
extern
int
SysExecve
(
const
char
*
fileName
,
char
*
const
*
argv
,
char
*
const
*
envp
);
extern
int
SysChdir
(
const
char
*
path
);
extern
int
SysUtimensat
(
int
fd
,
const
char
*
path
,
struct
timespec
times
[
2
],
int
flag
);
extern
int
SysFchmodat
(
int
fd
,
const
char
*
path
,
mode_t
mode
,
int
flag
);
extern
int
SysChmod
(
const
char
*
path
,
mode_t
mode
);
extern
int
SysFchownat
(
int
fd
,
const
char
*
path
,
uid_t
owner
,
gid_t
group
,
int
flag
);
extern
int
SysFchown
(
int
fd
,
uid_t
owner
,
gid_t
group
);
extern
int
SysChown
(
const
char
*
pathname
,
uid_t
owner
,
gid_t
group
);
extern
off_t
SysLseek
(
int
fd
,
off_t
offset
,
int
whence
);
extern
off64_t
SysLseek64
(
int
fd
,
int
offsetHigh
,
int
offsetLow
,
off64_t
*
result
,
int
whence
);
...
...
@@ -239,6 +243,7 @@ extern int SysMount(const char *source, const char *target, const char *filesyst
const
void
*
data
);
extern
int
SysUmount
(
const
char
*
target
);
extern
int
SysAccess
(
const
char
*
path
,
int
amode
);
extern
int
SysFaccessat
(
int
fd
,
const
char
*
filename
,
int
amode
,
int
flag
);
extern
int
SysRename
(
const
char
*
oldpath
,
const
char
*
newpath
);
extern
int
SysMkdir
(
const
char
*
pathname
,
mode_t
mode
);
extern
int
SysRmdir
(
const
char
*
pathname
);
...
...
syscall/syscall_lookup.h
浏览文件 @
0dc79479
...
...
@@ -48,11 +48,15 @@ SYSCALL_HAND_DEF(__NR_execve, SysExecve, int, ARG_NUM_3)
SYSCALL_HAND_DEF
(
__NR_sysinfo
,
SysInfo
,
int
,
ARG_NUM_1
)
SYSCALL_HAND_DEF
(
__NR_chdir
,
SysChdir
,
int
,
ARG_NUM_1
)
SYSCALL_HAND_DEF
(
__NR_utimensat
,
SysUtimensat
,
int
,
ARG_NUM_4
)
SYSCALL_HAND_DEF
(
__NR_fchmodat
,
SysFchmodat
,
int
,
ARG_NUM_4
)
SYSCALL_HAND_DEF
(
__NR_utimensat
,
SysUtimensat
,
int
,
ARG_NUM_4
)
SYSCALL_HAND_DEF
(
__NR_chmod
,
SysChmod
,
int
,
ARG_NUM_2
)
SYSCALL_HAND_DEF
(
__NR_lseek
,
SysLseek
,
off_t
,
ARG_NUM_7
)
/* current only support 32bit max 4G file */
SYSCALL_HAND_DEF
(
__NR_mount
,
SysMount
,
int
,
ARG_NUM_5
)
SYSCALL_HAND_DEF
(
__NR_umount
,
SysUmount
,
int
,
ARG_NUM_1
)
SYSCALL_HAND_DEF
(
__NR_access
,
SysAccess
,
int
,
ARG_NUM_2
)
SYSCALL_HAND_DEF
(
__NR_faccessat
,
SysFaccessat
,
int
,
ARG_NUM_4
)
SYSCALL_HAND_DEF
(
__NR_sync
,
SysSync
,
void
,
ARG_NUM_0
)
SYSCALL_HAND_DEF
(
__NR_rename
,
SysRename
,
int
,
ARG_NUM_2
)
SYSCALL_HAND_DEF
(
__NR_mkdir
,
SysMkdir
,
int
,
ARG_NUM_2
)
...
...
@@ -166,6 +170,8 @@ SYSCALL_HAND_DEF(__NR_rt_sigpending, SysSigPending, int, ARG_NUM_1)
SYSCALL_HAND_DEF
(
__NR_rt_sigtimedwait
,
SysSigTimedWait
,
int
,
ARG_NUM_4
)
SYSCALL_HAND_DEF
(
__NR_rt_sigsuspend
,
SysSigSuspend
,
int
,
ARG_NUM_1
)
SYSCALL_HAND_DEF
(
__NR_fchownat
,
SysFchownat
,
int
,
ARG_NUM_5
)
SYSCALL_HAND_DEF
(
__NR_fchown32
,
SysFchown
,
int
,
ARG_NUM_3
)
SYSCALL_HAND_DEF
(
__NR_chown
,
SysChown
,
int
,
ARG_NUM_3
)
SYSCALL_HAND_DEF
(
__NR_chown32
,
SysChown
,
int
,
ARG_NUM_3
)
#ifdef LOSCFG_SECURITY_CAPABILITY
...
...
syscall/syscall_pub.c
浏览文件 @
0dc79479
...
...
@@ -60,3 +60,68 @@ void *DupUserMem(const void *ptr, size_t len, int needCopy)
return
p
;
}
int
GetFullpath
(
int
fd
,
const
char
*
path
,
char
**
fullpath
)
{
int
ret
=
0
;
char
*
pathRet
=
NULL
;
struct
file
*
file
=
NULL
;
struct
stat
bufRet
=
{
0
};
if
(
path
!=
NULL
)
{
ret
=
UserPathCopy
(
path
,
&
pathRet
);
if
(
ret
!=
0
)
{
goto
OUT
;
}
}
if
((
pathRet
!=
NULL
)
&&
(
*
pathRet
==
'/'
))
{
*
fullpath
=
pathRet
;
pathRet
=
NULL
;
}
else
{
if
(
fd
!=
AT_FDCWD
)
{
/* Process fd convert to system global fd */
fd
=
GetAssociatedSystemFd
(
fd
);
}
ret
=
fs_getfilep
(
fd
,
&
file
);
if
(
file
)
{
ret
=
stat
(
file
->
f_path
,
&
bufRet
);
if
(
!
ret
)
{
if
(
!
S_ISDIR
(
bufRet
.
st_mode
))
{
set_errno
(
ENOTDIR
);
ret
=
-
ENOTDIR
;
goto
OUT
;
}
}
}
ret
=
vfs_normalize_pathat
(
fd
,
pathRet
,
fullpath
);
}
OUT:
PointerFree
(
pathRet
);
return
ret
;
}
int
UserPathCopy
(
const
char
*
userPath
,
char
**
pathBuf
)
{
int
ret
;
*
pathBuf
=
(
char
*
)
LOS_MemAlloc
(
OS_SYS_MEM_ADDR
,
PATH_MAX
+
1
);
if
(
*
pathBuf
==
NULL
)
{
return
-
ENOMEM
;
}
ret
=
LOS_StrncpyFromUser
(
*
pathBuf
,
userPath
,
PATH_MAX
+
1
);
if
(
ret
<
0
)
{
(
void
)
LOS_MemFree
(
OS_SYS_MEM_ADDR
,
*
pathBuf
);
*
pathBuf
=
NULL
;
return
ret
;
}
else
if
(
ret
>
PATH_MAX
)
{
(
void
)
LOS_MemFree
(
OS_SYS_MEM_ADDR
,
*
pathBuf
);
*
pathBuf
=
NULL
;
return
-
ENAMETOOLONG
;
}
(
*
pathBuf
)[
ret
]
=
'\0'
;
return
0
;
}
syscall/syscall_pub.h
浏览文件 @
0dc79479
...
...
@@ -36,9 +36,14 @@
#include "los_vm_lock.h"
#include "los_vm_map.h"
#include "user_copy.h"
#include "fs/fs.h"
#include "fcntl.h"
#include "los_strncpy_from_user.h"
extern
int
CheckRegion
(
const
LosVmSpace
*
space
,
VADDR_T
ptr
,
size_t
len
);
extern
void
*
DupUserMem
(
const
void
*
ptr
,
size_t
len
,
int
needCopy
);
extern
int
GetFullpath
(
int
fd
,
const
char
*
path
,
char
**
fullpath
);
extern
int
UserPathCopy
(
const
char
*
userPath
,
char
**
pathBuf
);
#define CHECK_ASPACE(ptr, len, ...) \
do
{
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录