提交 2dc24da8 编写于 作者: Y yinjiaming

fix: 内核告警清理

【背景】
内核代码经代码扫描工具发现存在一些关于代码格式的告警,
现经修改解除掉告警.

【修改方案】
修改了代码中格式不规范的地方,修改的点有:
1.代码中一行过长
2.没有合理的添加空格和空行
3.没有按照规范进行缩进
4.括号的格式没有按照规范
5.注释的格式不对以及存在魔数字
6.函数的声明与定义的格式不一致
并更新了修改文件的版权头时间

【影响】
对现有的产品编译不会有影响。

re #I5H6F5
Signed-off-by: Nyinjiaming <yinjiaming@huawei.com>
Change-Id: Ie46b5b3238fd88c25f99542b8ccd138b956c6458
上级 6302c5f7
...@@ -478,7 +478,6 @@ static int PthreadGetCputime(clockid_t clockID, struct timespec *ats) ...@@ -478,7 +478,6 @@ static int PthreadGetCputime(clockid_t clockID, struct timespec *ats)
uint64_t runtime; uint64_t runtime;
UINT32 intSave; UINT32 intSave;
UINT32 tid = GetTidFromClockID(clockID); UINT32 tid = GetTidFromClockID(clockID);
if (OS_TID_CHECK_INVALID(tid)) { if (OS_TID_CHECK_INVALID(tid)) {
return -EINVAL; return -EINVAL;
} }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C"{ extern "C" {
#endif #endif
#endif /* __cplusplus */ #endif /* __cplusplus */
......
...@@ -343,7 +343,8 @@ static FRESULT init_cluster(DIR_FILE *pdfp, DIR *dp_new, FATFS *fs, int type, co ...@@ -343,7 +343,8 @@ static FRESULT init_cluster(DIR_FILE *pdfp, DIR *dp_new, FATFS *fs, int type, co
return FR_OK; return FR_OK;
} }
static int fatfs_create_obj(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp, BYTE type, const char *target) static int fatfs_create_obj(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp,
BYTE type, const char *target)
{ {
struct Vnode *vp = NULL; struct Vnode *vp = NULL;
FATFS *fs = (FATFS *)parent->originMount->data; FATFS *fs = (FATFS *)parent->originMount->data;
......
/* /*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
...@@ -244,8 +244,9 @@ extern int chattr(const char *pathname, struct IATTR *attr); ...@@ -244,8 +244,9 @@ extern int chattr(const char *pathname, struct IATTR *attr);
* *
* @retval #0 On success. * @retval #0 On success.
* @retval #-1 On failure with errno set. * @retval #-1 On failure with errno set.
* @retval CONTINE_NUTTX_FCNTL doesn't support some cmds in VfsFcntl, needs to continue going through Nuttx vfs operation.</li> * @retval CONTINE_NUTTX_FCNTL doesn't support some cmds in VfsFcntl, needs to continue going through
* * Nuttx vfs operation.</li>
*
* @par Dependency: * @par Dependency:
* <ul><li>fs.h</li></ul> * <ul><li>fs.h</li></ul>
* @see None * @see None
......
/* /*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
...@@ -682,7 +682,6 @@ int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, const ch ...@@ -682,7 +682,6 @@ int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, const ch
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER); LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
ret = jffs2_rmdir(parentInode, targetInode, (const unsigned char *)path); ret = jffs2_rmdir(parentInode, targetInode, (const unsigned char *)path);
if (ret == 0) { if (ret == 0) {
(void)jffs2_iput(targetInode); (void)jffs2_iput(targetInode);
} }
...@@ -809,7 +808,6 @@ int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, const c ...@@ -809,7 +808,6 @@ int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, const c
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER); LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
ret = jffs2_unlink(parentInode, targetInode, (const unsigned char *)path); ret = jffs2_unlink(parentInode, targetInode, (const unsigned char *)path);
if (ret == 0) { if (ret == 0) {
(void)jffs2_iput(targetInode); (void)jffs2_iput(targetInode);
} }
......
/* /*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
...@@ -154,7 +154,8 @@ static int FsCacheInfoFill(struct SeqBuf *buf, void *arg) ...@@ -154,7 +154,8 @@ static int FsCacheInfoFill(struct SeqBuf *buf, void *arg)
VnodeHold(); VnodeHold();
LosBufPrintf(buf, "\n=================================================================\n"); LosBufPrintf(buf, "\n=================================================================\n");
LosBufPrintf(buf, "VnodeAddr ParentAddr DataAddr VnodeOps Hash Ref Type Gid Uid Mode\n"); LosBufPrintf(buf,
"VnodeAddr ParentAddr DataAddr VnodeOps Hash Ref Type Gid Uid Mode\n");
vnodeVirtual = VnodeListProcess(buf, GetVnodeVirtualList()); vnodeVirtual = VnodeListProcess(buf, GetVnodeVirtualList());
vnodeFree = VnodeListProcess(buf, GetVnodeFreeList()); vnodeFree = VnodeListProcess(buf, GetVnodeFreeList());
vnodeActive = VnodeListProcess(buf, GetVnodeActiveList()); vnodeActive = VnodeListProcess(buf, GetVnodeActiveList());
......
...@@ -62,8 +62,8 @@ int OsShellCmdWriteProc(int argc, char **argv) ...@@ -62,8 +62,8 @@ int OsShellCmdWriteProc(int argc, char **argv)
if (argc == WRITEPROC_ARGC) { if (argc == WRITEPROC_ARGC) {
value = argv[0]; value = argv[0];
path = argv[2]; path = argv[2]; // 2: index of path
len = strlen(value) + 1; /* +1:add the \0 */ len = strlen(value) + 1; /* + 1:add the \0 */
if (strncmp(argv[1], ">>", strlen(">>")) == 0) { if (strncmp(argv[1], ">>", strlen(">>")) == 0) {
if ((realpath(path, realPath) == NULL) || (strncmp(realPath, rootProcDir, strlen(rootProcDir)) != 0)) { if ((realpath(path, realPath) == NULL) || (strncmp(realPath, rootProcDir, strlen(rootProcDir)) != 0)) {
PRINT_ERR("No such file or directory\n"); PRINT_ERR("No such file or directory\n");
......
/* /*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
...@@ -304,7 +304,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout ...@@ -304,7 +304,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout
int pollSize; int pollSize;
epHead = EpollGetDataBuff(epfd); epHead = EpollGetDataBuff(epfd);
if (epHead== NULL) { if (epHead == NULL) {
set_errno(EBADF); set_errno(EBADF);
return -1; return -1;
} }
......
...@@ -225,7 +225,6 @@ static char *vfs_normalize_fullpath(const char *directory, const char *filename, ...@@ -225,7 +225,6 @@ static char *vfs_normalize_fullpath(const char *directory, const char *filename,
/* it's a absolute path, use it directly */ /* it's a absolute path, use it directly */
fullpath = strdup(filename); /* copy string */ fullpath = strdup(filename); /* copy string */
if (fullpath == NULL) { if (fullpath == NULL) {
*pathname = NULL; *pathname = NULL;
set_errno(ENOMEM); set_errno(ENOMEM);
...@@ -258,11 +257,10 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn ...@@ -258,11 +257,10 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
} }
#ifdef VFS_USING_WORKDIR #ifdef VFS_USING_WORKDIR
if (directory == NULL) if (directory == NULL) {
{
spin_lock_irqsave(&curr->files->workdir_lock, lock_flags); spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
directory = curr->files->workdir; directory = curr->files->workdir;
} }
#else #else
if ((directory == NULL) && (filename[0] != '/')) { if ((directory == NULL) && (filename[0] != '/')) {
PRINT_ERR("NO_WORKING_DIR\n"); PRINT_ERR("NO_WORKING_DIR\n");
...@@ -275,20 +273,18 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn ...@@ -275,20 +273,18 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
if ((filename[0] != '/') && (strlen(directory) + namelen + 2 > TEMP_PATH_MAX)) { if ((filename[0] != '/') && (strlen(directory) + namelen + 2 > TEMP_PATH_MAX)) {
#ifdef VFS_USING_WORKDIR #ifdef VFS_USING_WORKDIR
if (dir_flags == TRUE) if (dir_flags == TRUE) {
{
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags); spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
} }
#endif #endif
return -ENAMETOOLONG; return -ENAMETOOLONG;
} }
fullpath = vfs_normalize_fullpath(directory, filename, pathname, namelen); fullpath = vfs_normalize_fullpath(directory, filename, pathname, namelen);
#ifdef VFS_USING_WORKDIR #ifdef VFS_USING_WORKDIR
if (dir_flags == TRUE) if (dir_flags == TRUE) {
{
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags); spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
} }
#endif #endif
if (fullpath == NULL) { if (fullpath == NULL) {
return -get_errno(); return -get_errno();
...@@ -308,7 +304,7 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn ...@@ -308,7 +304,7 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
int vfs_normalize_pathat(int dirfd, const char *filename, char **pathname) int vfs_normalize_pathat(int dirfd, const char *filename, char **pathname)
{ {
/* Get path by dirfd*/ /* Get path by dirfd */
char *relativeoldpath = NULL; char *relativeoldpath = NULL;
char *fullpath = NULL; char *fullpath = NULL;
int ret = 0; int ret = 0;
......
...@@ -132,19 +132,19 @@ int VfsPermissionCheck(uint fuid, uint fgid, uint fileMode, int accMode) ...@@ -132,19 +132,19 @@ int VfsPermissionCheck(uint fuid, uint fgid, uint fileMode, int accMode)
#ifdef VFS_USING_WORKDIR #ifdef VFS_USING_WORKDIR
static int SetWorkDir(const char *dir, size_t len) static int SetWorkDir(const char *dir, size_t len)
{ {
errno_t ret; errno_t ret;
uint lock_flags; uint lock_flags;
LosProcessCB *curr = OsCurrProcessGet(); LosProcessCB *curr = OsCurrProcessGet();
spin_lock_irqsave(&curr->files->workdir_lock, lock_flags); spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
ret = strncpy_s(curr->files->workdir, PATH_MAX, dir, len); ret = strncpy_s(curr->files->workdir, PATH_MAX, dir, len);
curr->files->workdir[PATH_MAX - 1] = '\0'; curr->files->workdir[PATH_MAX - 1] = '\0';
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags); spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
if (ret != EOK) { if (ret != EOK) {
return -1; return -1;
} }
return 0; return 0;
} }
#endif #endif
...@@ -155,7 +155,6 @@ int chdir(const char *path) ...@@ -155,7 +155,6 @@ int chdir(const char *path)
char *fullpath_bak = NULL; char *fullpath_bak = NULL;
struct stat statBuff; struct stat statBuff;
if (!path) { if (!path) {
set_errno(EFAULT); set_errno(EFAULT);
return -1; return -1;
......
...@@ -57,7 +57,6 @@ int utime(const char *path, const struct utimbuf *ptimes) ...@@ -57,7 +57,6 @@ int utime(const char *path, const struct utimbuf *ptimes)
/* Sanity checks */ /* Sanity checks */
if (path == NULL) { if (path == NULL) {
ret = -EINVAL; ret = -EINVAL;
goto errout; goto errout;
......
...@@ -53,124 +53,113 @@ ...@@ -53,124 +53,113 @@
#include <ctype.h> #include <ctype.h>
#include "fs/fs_operation.h" #include "fs/fs_operation.h"
typedef enum typedef enum {
{ RM_RECURSIVER,
RM_RECURSIVER, RM_FILE,
RM_FILE, RM_DIR,
RM_DIR, CP_FILE,
CP_FILE, CP_COUNT
CP_COUNT
} wildcard_type; } wildcard_type;
#define ERROR_OUT_IF(condition, message_function, handler) \ #define ERROR_OUT_IF(condition, message_function, handler) \
do \ do { \
{ \ if (condition) { \
if (condition) \ message_function; \
{ \ handler; \
message_function; \
handler; \
} \ } \
} \ } while (0)
while (0)
static inline void set_err(int errcode, const char *err_message) static inline void set_err(int errcode, const char *err_message)
{ {
set_errno(errcode); set_errno(errcode);
perror(err_message); perror(err_message);
} }
int osShellCmdDoChdir(const char *path) int osShellCmdDoChdir(const char *path)
{ {
char *fullpath = NULL; char *fullpath = NULL;
char *fullpath_bak = NULL; char *fullpath_bak = NULL;
int ret; int ret;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
if (path == NULL) if (path == NULL) {
{ LOS_TaskLock();
LOS_TaskLock(); PRINTK("%s\n", shell_working_directory);
PRINTK("%s\n", shell_working_directory); LOS_TaskUnlock();
LOS_TaskUnlock();
return 0; return 0;
} }
ERROR_OUT_IF(strlen(path) > PATH_MAX, set_err(ENOTDIR, "cd error"), return -1); ERROR_OUT_IF(strlen(path) > PATH_MAX, set_err(ENOTDIR, "cd error"), return -1);
ret = vfs_normalize_path(shell_working_directory, path, &fullpath); ret = vfs_normalize_path(shell_working_directory, path, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "cd error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "cd error"), return -1);
fullpath_bak = fullpath; fullpath_bak = fullpath;
ret = chdir(fullpath); ret = chdir(fullpath);
if (ret < 0) if (ret < 0) {
{ free(fullpath_bak);
free(fullpath_bak); perror("cd");
perror("cd"); return -1;
return -1;
} }
/* copy full path to working directory */ /* copy full path to working directory */
LOS_TaskLock(); LOS_TaskLock();
ret = strncpy_s(shell_working_directory, PATH_MAX, fullpath, strlen(fullpath)); ret = strncpy_s(shell_working_directory, PATH_MAX, fullpath, strlen(fullpath));
if (ret != EOK) if (ret != EOK) {
{ free(fullpath_bak);
free(fullpath_bak); LOS_TaskUnlock();
LOS_TaskUnlock(); return -1;
return -1;
} }
LOS_TaskUnlock(); LOS_TaskUnlock();
/* release normalize directory path name */ /* release normalize directory path name */
free(fullpath_bak); free(fullpath_bak);
return 0; return 0;
} }
int osShellCmdLs(int argc, const char **argv) int osShellCmdLs(int argc, const char **argv)
{ {
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
int ret; int ret;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc > 1, PRINTK("ls or ls [DIRECTORY]\n"), return -1); ERROR_OUT_IF(argc > 1, PRINTK("ls or ls [DIRECTORY]\n"), return -1);
if (argc == 0) if (argc == 0) {
{ ls(shell_working_directory);
ls(shell_working_directory); return 0;
return 0;
} }
filename = argv[0]; filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "ls error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "ls error"), return -1);
ls(fullpath); ls(fullpath);
free(fullpath); free(fullpath);
return 0; return 0;
} }
int osShellCmdCd(int argc, const char **argv) int osShellCmdCd(int argc, const char **argv)
{ {
if (argc == 0) if (argc == 0) {
{ (void)osShellCmdDoChdir("/");
(void)osShellCmdDoChdir("/"); return 0;
return 0;
} }
(void)osShellCmdDoChdir(argv[0]); (void)osShellCmdDoChdir(argv[0]);
return 0; return 0;
} }
#define CAT_BUF_SIZE 512 #define CAT_BUF_SIZE 512
...@@ -180,116 +169,104 @@ pthread_mutex_t g_mutex_cat = PTHREAD_MUTEX_INITIALIZER; ...@@ -180,116 +169,104 @@ pthread_mutex_t g_mutex_cat = PTHREAD_MUTEX_INITIALIZER;
int osShellCmdDoCatShow(UINTPTR arg) int osShellCmdDoCatShow(UINTPTR arg)
{ {
int ret = 0; int ret = 0;
char buf[CAT_BUF_SIZE]; char buf[CAT_BUF_SIZE];
size_t size, written, toWrite; size_t size, written, toWrite;
ssize_t cnt; ssize_t cnt;
char *fullpath = (char *)arg; char *fullpath = (char *)arg;
FILE *ini = NULL; FILE *ini = NULL;
(void)pthread_mutex_lock(&g_mutex_cat); (void)pthread_mutex_lock(&g_mutex_cat);
ini = fopen(fullpath, "r"); ini = fopen(fullpath, "r");
if (ini == NULL) if (ini == NULL) {
{ ret = -1;
ret = -1; perror("cat error");
perror("cat error"); goto out;
goto out;
} }
do do {
{ (void)memset_s(buf, sizeof(buf), 0, CAT_BUF_SIZE);
(void)memset_s(buf, sizeof(buf), 0, CAT_BUF_SIZE); size = fread(buf, 1, CAT_BUF_SIZE, ini);
size = fread(buf, 1, CAT_BUF_SIZE, ini); if ((int)size < 0) {
if ((int)size < 0) ret = -1;
{ perror("cat error");
ret = -1; goto out_with_fclose;
perror("cat error");
goto out_with_fclose;
} }
for (toWrite = size, written = 0; toWrite > 0;) for (toWrite = size, written = 0; toWrite > 0;) {
{ cnt = write(1, buf + written, toWrite);
cnt = write(1, buf + written, toWrite); if (cnt == 0) {
if (cnt == 0) /* avoid task-starvation */
{ (void)LOS_TaskDelay(1);
/* avoid task-starvation */ continue;
(void)LOS_TaskDelay(1); } else if (cnt < 0) {
continue; perror("cat write error");
} break;
else if (cnt < 0)
{
perror("cat write error");
break;
} }
written += cnt; written += cnt;
toWrite -= cnt; toWrite -= cnt;
} }
} }
while (size > 0); while (size > 0);
out_with_fclose: out_with_fclose:
(void)fclose(ini); (void)fclose(ini);
out: out:
free(fullpath); free(fullpath);
(void)pthread_mutex_unlock(&g_mutex_cat); (void)pthread_mutex_unlock(&g_mutex_cat);
return ret; return ret;
} }
int osShellCmdCat(int argc, const char **argv) int osShellCmdCat(int argc, const char **argv)
{ {
char *fullpath = NULL; char *fullpath = NULL;
int ret; int ret;
unsigned int ca_task; unsigned int ca_task;
struct Vnode *vnode = NULL; struct Vnode *vnode = NULL;
TSK_INIT_PARAM_S init_param; TSK_INIT_PARAM_S init_param;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc != 1, PRINTK("cat [FILE]\n"), return -1); ERROR_OUT_IF(argc != 1, PRINTK("cat [FILE]\n"), return -1);
ret = vfs_normalize_path(shell_working_directory, argv[0], &fullpath); ret = vfs_normalize_path(shell_working_directory, argv[0], &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "cat error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "cat error"), return -1);
VnodeHold(); VnodeHold();
ret = VnodeLookup(fullpath, &vnode, O_RDONLY); ret = VnodeLookup(fullpath, &vnode, O_RDONLY);
if (ret != LOS_OK) if (ret != LOS_OK) {
{
set_errno(-ret); set_errno(-ret);
perror("cat error"); perror("cat error");
VnodeDrop(); VnodeDrop();
free(fullpath); free(fullpath);
return -1; return -1;
} }
if (vnode->type != VNODE_TYPE_REG) if (vnode->type != VNODE_TYPE_REG) {
{
set_errno(EINVAL); set_errno(EINVAL);
perror("cat error"); perror("cat error");
VnodeDrop(); VnodeDrop();
free(fullpath); free(fullpath);
return -1; return -1;
} }
VnodeDrop(); VnodeDrop();
(void)memset_s(&init_param, sizeof(init_param), 0, sizeof(TSK_INIT_PARAM_S)); (void)memset_s(&init_param, sizeof(init_param), 0, sizeof(TSK_INIT_PARAM_S));
init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)osShellCmdDoCatShow; init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)osShellCmdDoCatShow;
init_param.usTaskPrio = CAT_TASK_PRIORITY; init_param.usTaskPrio = CAT_TASK_PRIORITY;
init_param.auwArgs[0] = (UINTPTR)fullpath; init_param.auwArgs[0] = (UINTPTR)fullpath;
init_param.uwStackSize = CAT_TASK_STACK_SIZE; init_param.uwStackSize = CAT_TASK_STACK_SIZE;
init_param.pcName = "shellcmd_cat"; init_param.pcName = "shellcmd_cat";
init_param.uwResved = LOS_TASK_STATUS_DETACHED | OS_TASK_FLAG_SPECIFIES_PROCESS; init_param.uwResved = LOS_TASK_STATUS_DETACHED | OS_TASK_FLAG_SPECIFIES_PROCESS;
init_param.processID = 2; /* 2: kProcess */ init_param.processID = 2; /* 2: kProcess */
ret = (int)LOS_TaskCreate(&ca_task, &init_param); ret = (int)LOS_TaskCreate(&ca_task, &init_param);
if (ret != LOS_OK) {
if (ret != LOS_OK) free(fullpath);
{
free(fullpath);
} }
return ret; return ret;
} }
static int nfs_mount_ref(const char *server_ip_and_path, const char *mount_path, static int nfs_mount_ref(const char *server_ip_and_path, const char *mount_path,
...@@ -301,7 +278,7 @@ static unsigned long get_mountflags(const char *options) ...@@ -301,7 +278,7 @@ static unsigned long get_mountflags(const char *options)
char *p; char *p;
while ((options != NULL) && (p = strsep((char**)&options, ",")) != NULL) { while ((options != NULL) && (p = strsep((char**)&options, ",")) != NULL) {
if (strncmp(p, "ro", strlen("ro")) == 0) { if (strncmp(p, "ro", strlen("ro")) == 0) {
mountfalgs |= MS_RDONLY; mountfalgs |= MS_RDONLY;
} else if (strncmp(p, "rw", strlen("rw")) == 0) { } else if (strncmp(p, "rw", strlen("rw")) == 0) {
mountfalgs &= ~MS_RDONLY; mountfalgs &= ~MS_RDONLY;
} else if (strncmp(p, "nosuid", strlen("nosuid")) == 0) { } else if (strncmp(p, "nosuid", strlen("nosuid")) == 0) {
...@@ -317,329 +294,288 @@ static unsigned long get_mountflags(const char *options) ...@@ -317,329 +294,288 @@ static unsigned long get_mountflags(const char *options)
} }
static inline void print_mount_usage(void) static inline void print_mount_usage(void)
{ {
PRINTK("mount [DEVICE] [PATH] [NAME]\n"); PRINTK("mount [DEVICE] [PATH] [NAME]\n");
} }
int osShellCmdMount(int argc, const char **argv) int osShellCmdMount(int argc, const char **argv)
{ {
int ret; int ret;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
unsigned int gid, uid; unsigned int gid, uid;
char *data = NULL; char *data = NULL;
char *filessystemtype = NULL; char *filessystemtype = NULL;
unsigned long mountfalgs; unsigned long mountfalgs;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc < 3, print_mount_usage(), return OS_FAIL); ERROR_OUT_IF(argc < 3, print_mount_usage(), return OS_FAIL);
if (strncmp(argv[0], "-t", 2) == 0 || strncmp(argv[0], "-o", 2) == 0) if (strncmp(argv[0], "-t", 2) == 0 || strncmp(argv[0], "-o", 2) == 0) // 2: length of "-t"
{ {
if (argc < 4) if (argc < 4) { // 4: required number of parameters
{ PRINTK("mount -t/-o [DEVICE] [PATH] [NAME]\n");
PRINTK("mount -t/-o [DEVICE] [PATH] [NAME]\n"); return -1;
return -1;
} }
filename = argv[2]; filename = argv[2]; // 2: index of file path
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "mount error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "mount error"), return -1);
if (strncmp(argv[3], "nfs", 3) == 0) if (strncmp(argv[3], "nfs", 3) == 0) { // 3: index of fs type
{ if (argc <= 6) { // 6: arguments include uid or gid
if (argc <= 6) uid = ((argc >= 5) && (argv[4] != NULL)) ? (unsigned int)strtoul(argv[4], (char **)NULL, 0) : 0;
{ gid = ((argc == 6) && (argv[5] != NULL)) ? (unsigned int)strtoul(argv[5], (char **)NULL, 0) : 0;
uid = ((argc >= 5) && (argv[4] != NULL)) ? (unsigned int)strtoul(argv[4], (char **)NULL, 0) : 0;
gid = ((argc == 6) && (argv[5] != NULL)) ? (unsigned int)strtoul(argv[5], (char **)NULL, 0) : 0; if (nfs_mount_ref != NULL) {
ret = nfs_mount_ref(argv[1], fullpath, uid, gid);
if (nfs_mount_ref != NULL) if (ret != LOS_OK) {
{ PRINTK("mount -t [DEVICE] [PATH] [NAME]\n");
ret = nfs_mount_ref(argv[1], fullpath, uid, gid);
if (ret != LOS_OK)
{
PRINTK("mount -t [DEVICE] [PATH] [NAME]\n");
} }
} else {
PRINTK("can't find nfs_mount\n");
} }
else free(fullpath);
{ return 0;
PRINTK("can't find nfs_mount\n");
}
free(fullpath);
return 0;
} }
} }
filessystemtype = (argc >= 4) ? (char *)argv[3] : NULL; /* 3: fs type */ filessystemtype = (argc >= 4) ? (char *)argv[3] : NULL; /* 4: specify fs type, 3: fs type */
mountfalgs = (argc >= 5) ? get_mountflags((const char *)argv[4]) : 0; /* 4: usr option */ mountfalgs = (argc >= 5) ? get_mountflags((const char *)argv[4]) : 0; /* 4: usr option */
data = (argc >= 6) ? (char *)argv[5] : NULL; /* 5: usr option data */ data = (argc >= 6) ? (char *)argv[5] : NULL; /* 5: usr option data */
if (strcmp(argv[1], "0") == 0) if (strcmp(argv[1], "0") == 0) {
{ ret = mount((const char *)NULL, fullpath, filessystemtype, mountfalgs, data);
ret = mount((const char *)NULL, fullpath, filessystemtype, mountfalgs, data); } else {
} ret = mount(argv[1], fullpath, filessystemtype, mountfalgs, data); /* 3: fs type */
else
{
ret = mount(argv[1], fullpath, filessystemtype, mountfalgs, data); /* 3: fs type */
}
if (ret != LOS_OK)
{
perror("mount error");
} }
else if (ret != LOS_OK) {
{ perror("mount error");
PRINTK("mount ok\n"); } else {
PRINTK("mount ok\n");
} }
} } else {
else filename = argv[1];
{ ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
filename = argv[1]; ERROR_OUT_IF(ret < 0, set_err(-ret, "mount error"), return -1);
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "mount error"), return -1); if (strncmp(argv[2], "nfs", 3) == 0) { // 2: index of fs type, 3: length of "nfs"
if (argc <= 5) { // 5: arguments include gid and uid
if (strncmp(argv[2], "nfs", 3) == 0) uid = ((argc >= 4) && (argv[3] != NULL)) ? (unsigned int)strtoul(argv[3], (char **)NULL, 0) : 0;
{ gid = ((argc == 5) && (argv[4] != NULL)) ? (unsigned int)strtoul(argv[4], (char **)NULL, 0) : 0;
if (argc <= 5)
{ if (nfs_mount_ref != NULL) {
uid = ((argc >= 4) && (argv[3] != NULL)) ? (unsigned int)strtoul(argv[3], (char **)NULL, 0) : 0; ret = nfs_mount_ref(argv[0], fullpath, uid, gid);
gid = ((argc == 5) && (argv[4] != NULL)) ? (unsigned int)strtoul(argv[4], (char **)NULL, 0) : 0; if (ret != LOS_OK) {
PRINTK("mount [DEVICE] [PATH] [NAME]\n");
if (nfs_mount_ref != NULL)
{
ret = nfs_mount_ref(argv[0], fullpath, uid, gid);
if (ret != LOS_OK)
{
PRINTK("mount [DEVICE] [PATH] [NAME]\n");
} }
} else {
PRINTK("can't find nfs_mount\n");
} }
else free(fullpath);
{ return 0;
PRINTK("can't find nfs_mount\n");
}
free(fullpath);
return 0;
} }
print_mount_usage(); print_mount_usage();
free(fullpath); free(fullpath);
return 0; return 0;
} }
mountfalgs = (argc >= 4) ? get_mountflags((const char *)argv[3]) : 0; /* 3: usr option */ mountfalgs = (argc >= 4) ? get_mountflags((const char *)argv[3]) : 0; /* 3: usr option */
data = (argc >= 5) ? (char *)argv[4] : NULL; /* 4: usr option data */ data = (argc >= 5) ? (char *)argv[4] : NULL; /* 4: usr option data */
if (strcmp(argv[0], "0") == 0) if (strcmp(argv[0], "0") == 0) {
{ ret = mount((const char *)NULL, fullpath, argv[2], mountfalgs, data);
ret = mount((const char *)NULL, fullpath, argv[2], mountfalgs, data); } else {
} ret = mount(argv[0], fullpath, argv[2], mountfalgs, data); /* 2: fs type */
else
{
ret = mount(argv[0], fullpath, argv[2], mountfalgs, data); /* 2: fs type */
}
if (ret != LOS_OK)
{
perror("mount error");
} }
else if (ret != LOS_OK) {
{ perror("mount error");
PRINTK("mount ok\n"); } else {
PRINTK("mount ok\n");
} }
} }
free(fullpath); free(fullpath);
return 0; return 0;
} }
int osShellCmdUmount(int argc, const char **argv) int osShellCmdUmount(int argc, const char **argv)
{ {
int ret; int ret;
const char *filename = NULL; const char *filename = NULL;
char *fullpath = NULL; char *fullpath = NULL;
char *target_path = NULL; char *target_path = NULL;
int cmp_num; int cmp_num;
char *work_path = NULL; char *work_path = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
work_path = shell_working_directory; work_path = shell_working_directory;
ERROR_OUT_IF(argc == 0, PRINTK("umount [PATH]\n"), return 0); ERROR_OUT_IF(argc == 0, PRINTK("umount [PATH]\n"), return 0);
filename = argv[0]; filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "umount error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "umount error"), return -1);
target_path = fullpath; target_path = fullpath;
cmp_num = strlen(fullpath); cmp_num = strlen(fullpath);
ret = strncmp(work_path, target_path, cmp_num); ret = strncmp(work_path, target_path, cmp_num);
if (ret == 0) if (ret == 0) {
{ work_path += cmp_num;
work_path += cmp_num; if (*work_path == '/' || *work_path == '\0') {
if (*work_path == '/' || *work_path == '\0') set_errno(EBUSY);
{ perror("umount error");
set_errno(EBUSY); free(fullpath);
perror("umount error"); return -1;
free(fullpath);
return -1;
} }
} }
ret = umount(fullpath); ret = umount(fullpath);
free(fullpath); free(fullpath);
if (ret != LOS_OK) if (ret != LOS_OK) {
{ perror("umount error");
perror("umount error"); return 0;
return 0;
} }
PRINTK("umount ok\n"); PRINTK("umount ok\n");
return 0; return 0;
} }
int osShellCmdMkdir(int argc, const char **argv) int osShellCmdMkdir(int argc, const char **argv)
{ {
int ret; int ret;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc != 1, PRINTK("mkdir [DIRECTORY]\n"), return 0); ERROR_OUT_IF(argc != 1, PRINTK("mkdir [DIRECTORY]\n"), return 0);
filename = argv[0]; filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "mkdir error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "mkdir error"), return -1);
ret = mkdir(fullpath, S_IRWXU | S_IRWXG | S_IRWXO); ret = mkdir(fullpath, S_IRWXU | S_IRWXG | S_IRWXO);
if (ret == -1) if (ret == -1) {
{ perror("mkdir error");
perror("mkdir error");
} }
free(fullpath); free(fullpath);
return 0; return 0;
} }
int osShellCmdPwd(int argc, const char **argv) int osShellCmdPwd(int argc, const char **argv)
{ {
char buf[SHOW_MAX_LEN] = {0}; char buf[SHOW_MAX_LEN] = {0};
DIR *dir = NULL; DIR *dir = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: pwd\n"), return -1); ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: pwd\n"), return -1);
dir = opendir(shell_working_directory); dir = opendir(shell_working_directory);
if (dir == NULL) if (dir == NULL) {
{ perror("pwd error");
perror("pwd error"); return -1;
return -1;
} }
LOS_TaskLock(); LOS_TaskLock();
if (strncpy_s(buf, SHOW_MAX_LEN, shell_working_directory, SHOW_MAX_LEN - 1) != EOK) if (strncpy_s(buf, SHOW_MAX_LEN, shell_working_directory, SHOW_MAX_LEN - 1) != EOK) {
{ LOS_TaskUnlock();
LOS_TaskUnlock(); PRINTK("pwd error: strncpy_s error!\n");
PRINTK("pwd error: strncpy_s error!\n"); (void)closedir(dir);
(void)closedir(dir); return -1;
return -1;
} }
LOS_TaskUnlock(); LOS_TaskUnlock();
PRINTK("%s\n", buf); PRINTK("%s\n", buf);
(void)closedir(dir); (void)closedir(dir);
return 0; return 0;
} }
static inline void print_statfs_usage(void) static inline void print_statfs_usage(void)
{ {
PRINTK("Usage :\n"); PRINTK("Usage :\n");
PRINTK(" statfs <path>\n"); PRINTK(" statfs <path>\n");
PRINTK(" path : Mounted file system path that requires query information\n"); PRINTK(" path : Mounted file system path that requires query information\n");
PRINTK("Example:\n"); PRINTK("Example:\n");
PRINTK(" statfs /ramfs\n"); PRINTK(" statfs /ramfs\n");
} }
int osShellCmdStatfs(int argc, const char **argv) int osShellCmdStatfs(int argc, const char **argv)
{ {
struct statfs sfs; struct statfs sfs;
int result; int result;
unsigned long long total_size, free_size; unsigned long long total_size, free_size;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc != 1, PRINTK("statfs failed! Invalid argument!\n"), return -1); ERROR_OUT_IF(argc != 1, PRINTK("statfs failed! Invalid argument!\n"), return -1);
(void)memset_s(&sfs, sizeof(sfs), 0, sizeof(sfs)); (void)memset_s(&sfs, sizeof(sfs), 0, sizeof(sfs));
filename = argv[0]; filename = argv[0];
result = vfs_normalize_path(shell_working_directory, filename, &fullpath); result = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(result < 0, set_err(-result, "statfs error"), return -1); ERROR_OUT_IF(result < 0, set_err(-result, "statfs error"), return -1);
result = statfs(fullpath, &sfs); result = statfs(fullpath, &sfs);
free(fullpath); free(fullpath);
if (result != 0 || sfs.f_type == 0) if (result != 0 || sfs.f_type == 0) {
{ PRINTK("statfs failed! Invalid argument!\n");
PRINTK("statfs failed! Invalid argument!\n"); print_statfs_usage();
print_statfs_usage(); return -1;
return -1;
} }
total_size = (unsigned long long)sfs.f_bsize * sfs.f_blocks; total_size = (unsigned long long)sfs.f_bsize * sfs.f_blocks;
free_size = (unsigned long long)sfs.f_bsize * sfs.f_bfree; free_size = (unsigned long long)sfs.f_bsize * sfs.f_bfree;
PRINTK("statfs got:\n f_type = %d\n cluster_size = %d\n", sfs.f_type, sfs.f_bsize); PRINTK("statfs got:\n f_type = %d\n cluster_size = %d\n", sfs.f_type, sfs.f_bsize);
PRINTK(" total_clusters = %llu\n free_clusters = %llu\n", sfs.f_blocks, sfs.f_bfree); PRINTK(" total_clusters = %llu\n free_clusters = %llu\n", sfs.f_blocks, sfs.f_bfree);
PRINTK(" avail_clusters = %llu\n f_namelen = %d\n", sfs.f_bavail, sfs.f_namelen); PRINTK(" avail_clusters = %llu\n f_namelen = %d\n", sfs.f_bavail, sfs.f_namelen);
PRINTK("\n%s\n total size: %4llu Bytes\n free size: %4llu Bytes\n", argv[0], total_size, free_size); PRINTK("\n%s\n total size: %4llu Bytes\n free size: %4llu Bytes\n", argv[0], total_size, free_size);
return 0; return 0;
} }
int osShellCmdTouch(int argc, const char **argv) int osShellCmdTouch(int argc, const char **argv)
{ {
int ret; int ret;
int fd = -1; int fd = -1;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc != 1, PRINTK("touch [FILE]\n"), return -1); ERROR_OUT_IF(argc != 1, PRINTK("touch [FILE]\n"), return -1);
filename = argv[0]; filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "touch error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "touch error"), return -1);
fd = open(fullpath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); fd = open(fullpath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
free(fullpath); free(fullpath);
if (fd == -1) if (fd == -1) {
{ perror("touch error");
perror("touch error"); return -1;
return -1;
} }
(void)close(fd); (void)close(fd);
return 0; return 0;
} }
#define CP_BUF_SIZE 4096 #define CP_BUF_SIZE 4096
...@@ -647,169 +583,151 @@ pthread_mutex_t g_mutex_cp = PTHREAD_MUTEX_INITIALIZER; ...@@ -647,169 +583,151 @@ pthread_mutex_t g_mutex_cp = PTHREAD_MUTEX_INITIALIZER;
static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename) static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename)
{ {
int ret; int ret;
char *src_fullpath = NULL; char *src_fullpath = NULL;
char *dst_fullpath = NULL; char *dst_fullpath = NULL;
const char *src_filename = NULL; const char *src_filename = NULL;
char *dst_filepath = NULL; char *dst_filepath = NULL;
char *buf = NULL; char *buf = NULL;
const char *filename = NULL; const char *filename = NULL;
ssize_t r_size, w_size; ssize_t r_size, w_size;
int src_fd = -1; int src_fd = -1;
int dst_fd = -1; int dst_fd = -1;
struct stat stat_buf; struct stat stat_buf;
mode_t src_mode; mode_t src_mode;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
buf = (char *)malloc(CP_BUF_SIZE); buf = (char *)malloc(CP_BUF_SIZE);
if (buf == NULL) if (buf == NULL) {
{ PRINTK("cp error: Out of memory!\n");
PRINTK("cp error: Out of memory!\n"); return -1;
return -1;
} }
/* Get source fullpath. */ /* Get source fullpath. */
ret = vfs_normalize_path(shell_working_directory, src_filepath, &src_fullpath); ret = vfs_normalize_path(shell_working_directory, src_filepath, &src_fullpath);
if (ret < 0) if (ret < 0) {
{ set_errno(-ret);
set_errno(-ret); PRINTK("cp error: %s\n", strerror(errno));
PRINTK("cp error: %s\n", strerror(errno)); free(buf);
free(buf); return -1;
return -1;
} }
/* Is source path exist? */ /* Is source path exist? */
ret = stat(src_fullpath, &stat_buf); ret = stat(src_fullpath, &stat_buf);
if (ret == -1) if (ret == -1) {
{ PRINTK("cp %s error: %s\n", src_fullpath, strerror(errno));
PRINTK("cp %s error: %s\n", src_fullpath, strerror(errno)); goto errout_with_srcpath;
goto errout_with_srcpath;
} }
src_mode = stat_buf.st_mode; src_mode = stat_buf.st_mode;
/* Is source path a directory? */ /* Is source path a directory? */
if (S_ISDIR(stat_buf.st_mode)) if (S_ISDIR(stat_buf.st_mode)) {
{ PRINTK("cp %s error: Source file can't be a directory.\n", src_fullpath);
PRINTK("cp %s error: Source file can't be a directory.\n", src_fullpath); goto errout_with_srcpath;
goto errout_with_srcpath;
} }
/* Get dest fullpath. */ /* Get dest fullpath. */
dst_fullpath = strdup(dst_filename); dst_fullpath = strdup(dst_filename);
if (dst_fullpath == NULL) if (dst_fullpath == NULL) {
{ PRINTK("cp error: Out of memory.\n");
PRINTK("cp error: Out of memory.\n"); goto errout_with_srcpath;
goto errout_with_srcpath;
} }
/* Is dest path exist? */ /* Is dest path exist? */
ret = stat(dst_fullpath, &stat_buf); ret = stat(dst_fullpath, &stat_buf);
if (ret == 0) if (ret == 0) {
{ /* Is dest path a directory? */
/* Is dest path a directory? */
if (S_ISDIR(stat_buf.st_mode)) {
if (S_ISDIR(stat_buf.st_mode)) /* Get source file name without '/'. */
{
/* Get source file name without '/'. */ src_filename = src_filepath;
while (1) {
src_filename = src_filepath; filename = strchr(src_filename, '/');
while (1) if (filename == NULL) {
{ break;
filename = strchr(src_filename, '/');
if (filename == NULL)
{
break;
} }
src_filename = filename + 1; src_filename = filename + 1;
} }
/* Add the source file after dest path. */ /* Add the source file after dest path. */
ret = vfs_normalize_path(dst_fullpath, src_filename, &dst_filepath); ret = vfs_normalize_path(dst_fullpath, src_filename, &dst_filepath);
if (ret < 0) if (ret < 0) {
{ set_errno(-ret);
set_errno(-ret); PRINTK("cp error. %s.\n", strerror(errno));
PRINTK("cp error. %s.\n", strerror(errno)); goto errout_with_path;
goto errout_with_path;
} }
free(dst_fullpath); free(dst_fullpath);
dst_fullpath = dst_filepath; dst_fullpath = dst_filepath;
} }
} }
/* Is dest file same as source file? */ /* Is dest file same as source file? */
if (strcmp(src_fullpath, dst_fullpath) == 0) if (strcmp(src_fullpath, dst_fullpath) == 0) {
{ PRINTK("cp error: '%s' and '%s' are the same file\n", src_fullpath, dst_fullpath);
PRINTK("cp error: '%s' and '%s' are the same file\n", src_fullpath, dst_fullpath); goto errout_with_path;
goto errout_with_path;
} }
/* Copy begins. */ /* Copy begins. */
(void)pthread_mutex_lock(&g_mutex_cp); (void)pthread_mutex_lock(&g_mutex_cp);
src_fd = open(src_fullpath, O_RDONLY); src_fd = open(src_fullpath, O_RDONLY);
if (src_fd < 0) if (src_fd < 0) {
{ PRINTK("cp error: can't open %s. %s.\n", src_fullpath, strerror(errno));
PRINTK("cp error: can't open %s. %s.\n", src_fullpath, strerror(errno)); goto errout_with_mutex;
goto errout_with_mutex;
} }
dst_fd = open(dst_fullpath, O_CREAT | O_WRONLY | O_TRUNC, src_mode); dst_fd = open(dst_fullpath, O_CREAT | O_WRONLY | O_TRUNC, src_mode);
if (dst_fd < 0) if (dst_fd < 0) {
{ PRINTK("cp error: can't create %s. %s.\n", dst_fullpath, strerror(errno));
PRINTK("cp error: can't create %s. %s.\n", dst_fullpath, strerror(errno)); goto errout_with_srcfd;
goto errout_with_srcfd;
} }
do do {
{ (void)memset_s(buf, CP_BUF_SIZE, 0, CP_BUF_SIZE);
(void)memset_s(buf, CP_BUF_SIZE, 0, CP_BUF_SIZE); r_size = read(src_fd, buf, CP_BUF_SIZE);
r_size = read(src_fd, buf, CP_BUF_SIZE); if (r_size < 0) {
if (r_size < 0) PRINTK("cp %s %s failed. %s.\n", src_fullpath, dst_fullpath, strerror(errno));
{ goto errout_with_fd;
PRINTK("cp %s %s failed. %s.\n", src_fullpath, dst_fullpath, strerror(errno));
goto errout_with_fd;
} }
w_size = write(dst_fd, buf, r_size); w_size = write(dst_fd, buf, r_size);
if (w_size != r_size) if (w_size != r_size) {
{ PRINTK("cp %s %s failed. %s.\n", src_fullpath, dst_fullpath, strerror(errno));
PRINTK("cp %s %s failed. %s.\n", src_fullpath, dst_fullpath, strerror(errno)); goto errout_with_fd;
goto errout_with_fd;
} }
} } while (r_size == CP_BUF_SIZE);
while (r_size == CP_BUF_SIZE);
/* Release resource. */ /* Release resource. */
free(buf); free(buf);
free(src_fullpath); free(src_fullpath);
free(dst_fullpath); free(dst_fullpath);
(void)close(src_fd); (void)close(src_fd);
(void)close(dst_fd); (void)close(dst_fd);
(void)pthread_mutex_unlock(&g_mutex_cp); (void)pthread_mutex_unlock(&g_mutex_cp);
return LOS_OK; return LOS_OK;
errout_with_fd: errout_with_fd:
(void)close(dst_fd); (void)close(dst_fd);
errout_with_srcfd: errout_with_srcfd:
(void)close(src_fd); (void)close(src_fd);
errout_with_mutex: errout_with_mutex:
(void)pthread_mutex_unlock(&g_mutex_cp); (void)pthread_mutex_unlock(&g_mutex_cp);
errout_with_path: errout_with_path:
free(dst_fullpath); free(dst_fullpath);
errout_with_srcpath: errout_with_srcpath:
free(src_fullpath); free(src_fullpath);
free(buf); free(buf);
return -1; return -1;
} }
/* The separator and EOF for a directory fullpath: '/'and '\0' */ /* The separator and EOF for a directory fullpath: '/'and '\0' */
...@@ -818,751 +736,639 @@ errout_with_srcpath: ...@@ -818,751 +736,639 @@ errout_with_srcpath:
static int os_shell_cmd_do_rmdir(const char *pathname) static int os_shell_cmd_do_rmdir(const char *pathname)
{ {
struct dirent *dirent = NULL; struct dirent *dirent = NULL;
struct stat stat_info; struct stat stat_info;
DIR *d = NULL; DIR *d = NULL;
char *fullpath = NULL; char *fullpath = NULL;
int ret; int ret;
(void)memset_s(&stat_info, sizeof(stat_info), 0, sizeof(struct stat)); (void)memset_s(&stat_info, sizeof(stat_info), 0, sizeof(struct stat));
if (stat(pathname, &stat_info) != 0) if (stat(pathname, &stat_info) != 0) {
{ return -1;
return -1;
} }
if (S_ISREG(stat_info.st_mode) || S_ISLNK(stat_info.st_mode)) if (S_ISREG(stat_info.st_mode) || S_ISLNK(stat_info.st_mode)) {
{ return remove(pathname);
return remove(pathname);
} }
d = opendir(pathname); d = opendir(pathname);
if (d == NULL) if (d == NULL) {
{ return -1;
return -1;
} }
while (1) while (1) {
{ dirent = readdir(d);
dirent = readdir(d); if (dirent == NULL) {
if (dirent == NULL) break;
{
break;
} }
if (strcmp(dirent->d_name, "..") && strcmp(dirent->d_name, ".")) if (strcmp(dirent->d_name, "..") && strcmp(dirent->d_name, ".")) {
{ size_t fullpath_buf_size = strlen(pathname) + strlen(dirent->d_name) + SEPARATOR_EOF_LEN;
size_t fullpath_buf_size = strlen(pathname) + strlen(dirent->d_name) + SEPARATOR_EOF_LEN; if (fullpath_buf_size <= 0) {
if (fullpath_buf_size <= 0) PRINTK("buffer size is invalid!\n");
{ (void)closedir(d);
PRINTK("buffer size is invalid!\n"); return -1;
(void)closedir(d);
return -1;
} }
fullpath = (char *)malloc(fullpath_buf_size); fullpath = (char *)malloc(fullpath_buf_size);
if (fullpath == NULL) if (fullpath == NULL) {
{ PRINTK("malloc failure!\n");
PRINTK("malloc failure!\n"); (void)closedir(d);
(void)closedir(d); return -1;
return -1;
} }
ret = snprintf_s(fullpath, fullpath_buf_size, fullpath_buf_size - 1, "%s/%s", pathname, dirent->d_name); ret = snprintf_s(fullpath, fullpath_buf_size, fullpath_buf_size - 1, "%s/%s", pathname, dirent->d_name);
if (ret < 0) if (ret < 0) {
{ PRINTK("name is too long!\n");
PRINTK("name is too long!\n"); free(fullpath);
free(fullpath); (void)closedir(d);
(void)closedir(d); return -1;
return -1;
} }
(void)os_shell_cmd_do_rmdir(fullpath); (void)os_shell_cmd_do_rmdir(fullpath);
free(fullpath); free(fullpath);
} }
} }
(void)closedir(d); (void)closedir(d);
return rmdir(pathname); return rmdir(pathname);
} }
/* Wildcard matching operations */ /* Wildcard matching operations */
static int os_wildcard_match(const char *src, const char *filename) static int os_wildcard_match(const char *src, const char *filename)
{ {
int ret; int ret;
if (*src != '\0') if (*src != '\0') {
{ if (*filename == '*') {
if (*filename == '*') while ((*filename == '*') || (*filename == '?')) {
{ filename++;
while ((*filename == '*') || (*filename == '?'))
{
filename++;
} }
if (*filename == '\0') if (*filename == '\0') {
{ return 0;
return 0;
} }
while (*src != '\0' && !(*src == *filename)) while (*src != '\0' && !(*src == *filename)) {
{ src++;
src++;
} }
if (*src == '\0') if (*src == '\0') {
{ return -1;
return -1;
} }
ret = os_wildcard_match(src, filename); ret = os_wildcard_match(src, filename);
while ((ret != 0) && (*(++src) != '\0')) while ((ret != 0) && (*(++src) != '\0')) {
{ if (*src == *filename) {
if (*src == *filename) ret = os_wildcard_match(src, filename);
{
ret = os_wildcard_match(src, filename);
} }
} }
return ret; return ret;
} } else {
else if ((*src == *filename) || (*filename == '?')) {
{ return os_wildcard_match(++src, ++filename);
if ((*src == *filename) || (*filename == '?'))
{
return os_wildcard_match(++src, ++filename);
} }
return -1; return -1;
} }
} }
while (*filename != '\0') while (*filename != '\0') {
{ if (*filename != '*') {
if (*filename != '*') return -1;
{
return -1;
} }
filename++; filename++;
} }
return 0; return 0;
} }
/* To determine whether a wildcard character exists in a path */ /* To determine whether a wildcard character exists in a path */
static int os_is_containers_wildcard(const char *filename) static int os_is_containers_wildcard(const char *filename)
{ {
while (*filename != '\0') while (*filename != '\0') {
{ if ((*filename == '*') || (*filename == '?')) {
if ((*filename == '*') || (*filename == '?')) return 1;
{
return 1;
} }
filename++; filename++;
} }
return 0; return 0;
} }
/* Delete a matching file or directory */ /* Delete a matching file or directory */
static int os_wildcard_delete_file_or_dir(const char *fullpath, wildcard_type mark) static int os_wildcard_delete_file_or_dir(const char *fullpath, wildcard_type mark)
{ {
int ret; int ret;
switch (mark) switch (mark) {
{ case RM_RECURSIVER:
case RM_RECURSIVER: ret = os_shell_cmd_do_rmdir(fullpath);
ret = os_shell_cmd_do_rmdir(fullpath); break;
break; case RM_FILE:
case RM_FILE: ret = unlink(fullpath);
ret = unlink(fullpath); break;
break; case RM_DIR:
case RM_DIR: ret = rmdir(fullpath);
ret = rmdir(fullpath); break;
break; default:
default: return VFS_ERROR;
return VFS_ERROR; }
} if (ret == -1) {
if (ret == -1) PRINTK("%s ", fullpath);
{ perror("rm/rmdir error!");
PRINTK("%s ", fullpath); return ret;
perror("rm/rmdir error!"); }
return ret;
} PRINTK("%s match successful!delete!\n", fullpath);
return 0;
PRINTK("%s match successful!delete!\n", fullpath);
return 0;
} }
/* Split the path with wildcard characters */ /* Split the path with wildcard characters */
static char* os_wildcard_split_path(char *fullpath, char **handle, char **wait) static char* os_wildcard_split_path(char *fullpath, char **handle, char **wait)
{ {
int n = 0; int n = 0;
int a = 0; int a = 0;
int b = 0; int b = 0;
int len = strlen(fullpath); int len = strlen(fullpath);
for (n = 0; n < len; n++) for (n = 0; n < len; n++) {
{ if (fullpath[n] == '/') {
if (fullpath[n] == '/') if (b != 0) {
{ fullpath[n] = '\0';
if (b != 0) *wait = fullpath + n + 1;
{ break;
fullpath[n] = '\0';
*wait = fullpath + n + 1;
break;
} }
a = n; a = n;
} } else if (fullpath[n] == '*' || fullpath[n] == '?') {
else if (fullpath[n] == '*' || fullpath[n] == '?') b = n;
{ fullpath[a] = '\0';
b = n; if (a == 0) {
fullpath[a] = '\0'; *handle = fullpath + a + 1;
if (a == 0) continue;
{
*handle = fullpath + a + 1;
continue;
} }
*handle = fullpath + a + 1; *handle = fullpath + a + 1;
} }
} }
return fullpath; return fullpath;
} }
/* Handling entry of the path with wildcard characters */ /* Handling entry of the path with wildcard characters */
static int os_wildcard_extract_directory(char *fullpath, void *dst, wildcard_type mark) static int os_wildcard_extract_directory(char *fullpath, void *dst, wildcard_type mark)
{ {
char separator[] = "/"; char separator[] = "/";
char src[PATH_MAX] = {0}; char src[PATH_MAX] = {0};
struct dirent *dirent = NULL; struct dirent *dirent = NULL;
char *f = NULL; char *f = NULL;
char *s = NULL; char *s = NULL;
char *t = NULL; char *t = NULL;
int ret = 0; int ret = 0;
DIR *d = NULL; DIR *d = NULL;
struct stat stat_buf; struct stat stat_buf;
int deleteFlag = 0; int deleteFlag = 0;
f = os_wildcard_split_path(fullpath, &s, &t); f = os_wildcard_split_path(fullpath, &s, &t);
if (s == NULL) if (s == NULL) {
{ if (mark == CP_FILE) {
if (mark == CP_FILE) ret = os_shell_cmd_do_cp(fullpath, dst);
{ } else if (mark == CP_COUNT) {
ret = os_shell_cmd_do_cp(fullpath, dst); ret = stat(fullpath, &stat_buf);
} if (ret == 0 && (S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode))) {
else if (mark == CP_COUNT) (*(int *)dst)++;
{
ret = stat(fullpath, &stat_buf);
if (ret == 0 && (S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode)))
{
(*(int *)dst)++;
} }
} else {
ret = os_wildcard_delete_file_or_dir(fullpath, mark);
} }
else return ret;
{
ret = os_wildcard_delete_file_or_dir(fullpath, mark);
}
return ret;
} }
d = (*f == '\0') ? opendir("/") : opendir(f); d = (*f == '\0') ? opendir("/") : opendir(f);
if (d == NULL) {
if (d == NULL) perror("opendir error");
{ return VFS_ERROR;
perror("opendir error");
return VFS_ERROR;
} }
while (1) while (1) {
{ dirent = readdir(d);
dirent = readdir(d); if (dirent == NULL) {
if (dirent == NULL) break;
{
break;
} }
ret = strcpy_s(src, PATH_MAX, f); ret = strcpy_s(src, PATH_MAX, f);
if (ret != EOK) if (ret != EOK) {
{ goto closedir_out;
goto closedir_out;
} }
ret = os_wildcard_match(dirent->d_name, s); ret = os_wildcard_match(dirent->d_name, s);
if (ret == 0) if (ret == 0) {
{ ret = strcat_s(src, sizeof(src), separator);
ret = strcat_s(src, sizeof(src), separator); if (ret != EOK) {
if (ret != EOK) goto closedir_out;
{
goto closedir_out;
} }
ret = strcat_s(src, sizeof(src), dirent->d_name); ret = strcat_s(src, sizeof(src), dirent->d_name);
if (ret != EOK) if (ret != EOK) {
{ goto closedir_out;
goto closedir_out;
} }
if (t == NULL) if (t == NULL) {
{ if (mark == CP_FILE) {
if (mark == CP_FILE) ret = os_shell_cmd_do_cp(src, dst);
{ } else if (mark == CP_COUNT) {
ret = os_shell_cmd_do_cp(src, dst); ret = stat(src, &stat_buf);
} if (ret == 0 && (S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode))) {
else if (mark == CP_COUNT) (*(int *)dst)++;
{ if ((*(int *)dst) > 1) {
ret = stat(src, &stat_buf); break;
if (ret == 0 && (S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode)))
{
(*(int *)dst)++;
if ((*(int *)dst) > 1)
{
break;
} }
} }
} } else {
else ret = os_wildcard_delete_file_or_dir(src, mark);
{ if (ret == 0) {
ret = os_wildcard_delete_file_or_dir(src, mark); deleteFlag = 1;
if (ret == 0)
{
deleteFlag = 1;
} }
} }
} } else {
else ret = strcat_s(src, sizeof(src), separator);
{ if (ret != EOK) {
ret = strcat_s(src, sizeof(src), separator); goto closedir_out;
if (ret != EOK)
{
goto closedir_out;
} }
ret = strcat_s(src, sizeof(src), t); ret = strcat_s(src, sizeof(src), t);
if (ret != EOK) if (ret != EOK) {
{ goto closedir_out;
goto closedir_out;
} }
ret = os_wildcard_extract_directory(src, dst, mark); ret = os_wildcard_extract_directory(src, dst, mark);
if (mark == CP_COUNT && (*(int *)dst) > 1) if (mark == CP_COUNT && (*(int *)dst) > 1) {
{ break;
break;
} }
} }
} }
} }
(void)closedir(d); (void)closedir(d);
if (deleteFlag == 1) if (deleteFlag == 1) {
{ ret = 0;
ret = 0;
} }
return ret; return ret;
closedir_out: closedir_out:
(void)closedir(d); (void)closedir(d);
return VFS_ERROR; return VFS_ERROR;
} }
int osShellCmdCp(int argc, const char **argv) int osShellCmdCp(int argc, const char **argv)
{ {
int ret; int ret;
const char *src = NULL; const char *src = NULL;
const char *dst = NULL; const char *dst = NULL;
char *src_fullpath = NULL; char *src_fullpath = NULL;
char *dst_fullpath = NULL; char *dst_fullpath = NULL;
struct stat stat_buf; struct stat stat_buf;
int count = 0; int count = 0;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc < 2, PRINTK("cp [SOURCEFILE] [DESTFILE]\n"), return -1); ERROR_OUT_IF(argc < 2, PRINTK("cp [SOURCEFILE] [DESTFILE]\n"), return -1);
src = argv[0]; src = argv[0];
dst = argv[1]; dst = argv[1];
/* Get source fullpath. */ /* Get source fullpath. */
ret = vfs_normalize_path(shell_working_directory, src, &src_fullpath); ret = vfs_normalize_path(shell_working_directory, src, &src_fullpath);
if (ret < 0) if (ret < 0) {
{ set_errno(-ret);
set_errno(-ret); PRINTK("cp error:%s\n", strerror(errno));
PRINTK("cp error:%s\n", strerror(errno)); return -1;
return -1;
} }
if (src[strlen(src) - 1] == '/') if (src[strlen(src) - 1] == '/') {
{ PRINTK("cp %s error: Source file can't be a directory.\n", src);
PRINTK("cp %s error: Source file can't be a directory.\n", src); goto errout_with_srcpath;
goto errout_with_srcpath;
} }
/* Get dest fullpath. */ /* Get dest fullpath. */
ret = vfs_normalize_path(shell_working_directory, dst, &dst_fullpath); ret = vfs_normalize_path(shell_working_directory, dst, &dst_fullpath);
if (ret < 0) if (ret < 0) {
{ set_errno(-ret);
set_errno(-ret); PRINTK("cp error: can't open %s. %s\n", dst, strerror(errno));
PRINTK("cp error: can't open %s. %s\n", dst, strerror(errno)); goto errout_with_srcpath;
goto errout_with_srcpath;
} }
/* Is dest path exist? */ /* Is dest path exist? */
ret = stat(dst_fullpath, &stat_buf); ret = stat(dst_fullpath, &stat_buf);
if (ret < 0) if (ret < 0) {
{ /* Is dest path a directory? */
/* Is dest path a directory? */
if (dst[strlen(dst) - 1] == '/') if (dst[strlen(dst) - 1] == '/') {
{ PRINTK("cp error: %s, %s.\n", dst_fullpath, strerror(errno));
PRINTK("cp error: %s, %s.\n", dst_fullpath, strerror(errno)); goto errout_with_path;
goto errout_with_path;
} }
} } else {
else if ((S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode)) && dst[strlen(dst) - 1] == '/') {
{ PRINTK("cp error: %s is not a directory.\n", dst_fullpath);
if ((S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode)) && dst[strlen(dst) - 1] == '/') goto errout_with_path;
{
PRINTK("cp error: %s is not a directory.\n", dst_fullpath);
goto errout_with_path;
} }
} }
if (os_is_containers_wildcard(src_fullpath)) if (os_is_containers_wildcard(src_fullpath)) {
{ if (ret < 0 || S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode)) {
if (ret < 0 || S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode)) char *src_copy = strdup(src_fullpath);
{ if (src_copy == NULL) {
char *src_copy = strdup(src_fullpath); PRINTK("cp error : Out of memory.\n");
if (src_copy == NULL) goto errout_with_path;
{
PRINTK("cp error : Out of memory.\n");
goto errout_with_path;
} }
(void)os_wildcard_extract_directory(src_copy, &count, CP_COUNT); (void)os_wildcard_extract_directory(src_copy, &count, CP_COUNT);
free(src_copy); free(src_copy);
if (count > 1) if (count > 1) {
{ PRINTK("cp error : %s is not a directory.\n", dst_fullpath);
PRINTK("cp error : %s is not a directory.\n", dst_fullpath); goto errout_with_path;
goto errout_with_path;
} }
} }
ret = os_wildcard_extract_directory(src_fullpath, dst_fullpath, CP_FILE); ret = os_wildcard_extract_directory(src_fullpath, dst_fullpath, CP_FILE);
} else {
ret = os_shell_cmd_do_cp(src_fullpath, dst_fullpath);
} }
else free(dst_fullpath);
{ free(src_fullpath);
ret = os_shell_cmd_do_cp(src_fullpath, dst_fullpath); return ret;
}
free(dst_fullpath);
free(src_fullpath);
return ret;
errout_with_path: errout_with_path:
free(dst_fullpath); free(dst_fullpath);
errout_with_srcpath: errout_with_srcpath:
free(src_fullpath); free(src_fullpath);
return VFS_ERROR; return VFS_ERROR;
} }
static inline void print_rm_usage(void) static inline void print_rm_usage(void)
{ {
PRINTK("rm [FILE] or rm [-r/-R] [FILE]\n"); PRINTK("rm [FILE] or rm [-r/-R] [FILE]\n");
} }
int osShellCmdRm(int argc, const char **argv) int osShellCmdRm(int argc, const char **argv)
{ {
int ret = 0; int ret = 0;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc != 1 && argc != 2, print_rm_usage(), return -1); ERROR_OUT_IF(argc != 1 && argc != 2, print_rm_usage(), return -1);
if (argc == 2) if (argc == 2) { // 2: arguments include "-r" or "-R"
{ ERROR_OUT_IF(strcmp(argv[0], "-r") != 0 && strcmp(argv[0], "-R") != 0, print_rm_usage(), return -1);
ERROR_OUT_IF(strcmp(argv[0], "-r") != 0 && strcmp(argv[0], "-R") != 0, print_rm_usage(), return -1);
filename = argv[1]; filename = argv[1];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "rm error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "rm error"), return -1);
if (os_is_containers_wildcard(fullpath)) if (os_is_containers_wildcard(fullpath)) {
{ ret = os_wildcard_extract_directory(fullpath, NULL, RM_RECURSIVER);
ret = os_wildcard_extract_directory(fullpath, NULL, RM_RECURSIVER); } else {
} ret = os_shell_cmd_do_rmdir(fullpath);
else
{
ret = os_shell_cmd_do_rmdir(fullpath);
} }
} } else {
else filename = argv[0];
{ ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
filename = argv[0]; ERROR_OUT_IF(ret < 0, set_err(-ret, "rm error"), return -1);
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "rm error"), return -1);
if (os_is_containers_wildcard(fullpath)) if (os_is_containers_wildcard(fullpath)) {
{ ret = os_wildcard_extract_directory(fullpath, NULL, RM_FILE);
ret = os_wildcard_extract_directory(fullpath, NULL, RM_FILE); } else {
} ret = unlink(fullpath);
else
{
ret = unlink(fullpath);
} }
} }
if (ret == -1) if (ret == -1) {
{ perror("rm error");
perror("rm error");
} }
free(fullpath); free(fullpath);
return 0; return 0;
} }
int osShellCmdRmdir(int argc, const char **argv) int osShellCmdRmdir(int argc, const char **argv)
{ {
int ret; int ret;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ERROR_OUT_IF(argc == 0, PRINTK("rmdir [DIRECTORY]\n"), return -1); ERROR_OUT_IF(argc == 0, PRINTK("rmdir [DIRECTORY]\n"), return -1);
filename = argv[0]; filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "rmdir error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "rmdir error"), return -1);
if (os_is_containers_wildcard(fullpath)) if (os_is_containers_wildcard(fullpath)) {
{ ret = os_wildcard_extract_directory(fullpath, NULL, RM_DIR);
ret = os_wildcard_extract_directory(fullpath, NULL, RM_DIR); } else {
} ret = rmdir(fullpath);
else
{
ret = rmdir(fullpath);
} }
if (ret == -1) if (ret == -1) {
{ PRINTK("rmdir %s failed. Error: %s.\n", fullpath, strerror(errno));
PRINTK("rmdir %s failed. Error: %s.\n", fullpath, strerror(errno));
} }
free(fullpath); free(fullpath);
return 0; return 0;
} }
int osShellCmdSync(int argc, const char **argv) int osShellCmdSync(int argc, const char **argv)
{ {
ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: sync\n"), return -1); ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: sync\n"), return -1);
sync(); sync();
return 0; return 0;
} }
int osShellCmdLsfd(int argc, const char **argv) int osShellCmdLsfd(int argc, const char **argv)
{ {
ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: lsfd\n"), return -1); ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: lsfd\n"), return -1);
lsfd(); lsfd();
return 0; return 0;
} }
int checkNum(const char *arg) int checkNum(const char *arg)
{ {
int i = 0; int i = 0;
if (arg == NULL) if (arg == NULL) {
{ return -1;
return -1;
} }
if (arg[0] == '-') if (arg[0] == '-') {
{ /* exclude the '-' */
/* exclude the '-' */
i = 1; i = 1;
} }
for (; arg[i] != 0; i++) for (; arg[i] != 0; i++) {
{ if (!isdigit(arg[i])) {
if (!isdigit(arg[i])) return -1;
{
return -1;
} }
} }
return 0; return 0;
} }
#ifdef LOSCFG_KERNEL_SYSCALL #ifdef LOSCFG_KERNEL_SYSCALL
int osShellCmdSu(int argc, const char **argv) int osShellCmdSu(int argc, const char **argv)
{ {
int su_uid; int su_uid;
int su_gid; int su_gid;
if (argc == 0) if (argc == 0) {
{ /* for su root */
/* for su root */
su_uid = 0; su_uid = 0;
su_gid = 0; su_gid = 0;
} } else {
else ERROR_OUT_IF((argc != 2), PRINTK("su [uid_num] [gid_num]\n"), return -1);
{ ERROR_OUT_IF((checkNum(argv[0]) != 0) || (checkNum(argv[1]) != 0), /* check argv is digit */
ERROR_OUT_IF((argc != 2), PRINTK("su [uid_num] [gid_num]\n"), return -1); PRINTK("check uid_num and gid_num is digit\n"), return -1);
ERROR_OUT_IF((checkNum(argv[0]) != 0) || (checkNum(argv[1]) != 0), /* check argv is digit */
PRINTK("check uid_num and gid_num is digit\n"), return -1);
su_uid = atoi(argv[0]); su_uid = atoi(argv[0]);
su_gid = atoi(argv[1]); su_gid = atoi(argv[1]);
ERROR_OUT_IF((su_uid < 0) || (su_uid > 60000) || (su_gid < 0) || ERROR_OUT_IF((su_uid < 0) || (su_uid > 60000) || (su_gid < 0) ||
(su_gid > 60000), PRINTK("uid_num or gid_num out of range!they should be [0~60000]\n"), return -1); (su_gid > 60000), PRINTK("uid_num or gid_num out of range!they should be [0~60000]\n"), return -1);
} }
SysSetUserID(su_uid); SysSetUserID(su_uid);
SysSetGroupID(su_gid); SysSetGroupID(su_gid);
return 0; return 0;
} }
#endif #endif
int osShellCmdChmod(int argc, const char **argv) int osShellCmdChmod(int argc, const char **argv)
{ {
int i = 0; int i = 0;
int mode = 0; int mode = 0;
int ret; int ret;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
struct IATTR attr = {0}; struct IATTR attr = {0};
char *shell_working_directory = NULL; char *shell_working_directory = NULL;
const char *p = NULL; const char *p = NULL;
#define MODE_BIT 3 /* 3 bits express 1 mode */ #define MODE_BIT 3 /* 3 bits express 1 mode */
ERROR_OUT_IF((argc != 2), PRINTK("Usage: chmod <MODE> [FILE]\n"), return -1); ERROR_OUT_IF((argc != 2), PRINTK("Usage: chmod <MODE> [FILE]\n"), return -1);
p = argv[0]; p = argv[0];
while (p[i]) while (p[i]) {
{ if ((p[i] <= '7') && (p[i] >= '0')) {
if ((p[i] <= '7') && (p[i] >= '0')) mode = ((uint)mode << MODE_BIT) | (uint)(p[i] - '0');
{ } else {
mode = ((uint)mode << MODE_BIT) | (uint)(p[i] - '0'); PRINTK("check the input <MODE>\n");
} return -1;
else
{
PRINTK("check the input <MODE>\n");
return -1;
} }
i++; i++;
} }
filename = argv[1]; filename = argv[1];
shell_working_directory = OsShellGetWorkingDirectory(); shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) if (shell_working_directory == NULL) {
{ return -1;
return -1;
} }
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "chmod error\n"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "chmod error\n"), return -1);
attr.attr_chg_mode = mode; attr.attr_chg_mode = mode;
attr.attr_chg_valid = CHG_MODE; /* change mode */ attr.attr_chg_valid = CHG_MODE; /* change mode */
ret = chattr(fullpath, &attr); ret = chattr(fullpath, &attr);
if (ret < 0) if (ret < 0) {
{ free(fullpath);
free(fullpath); PRINTK("chmod error! %s\n", strerror(errno));
PRINTK("chmod error! %s\n", strerror(errno)); return ret;
return ret;
} }
free(fullpath); free(fullpath);
return 0; return 0;
} }
int osShellCmdChown(int argc, const char **argv) int osShellCmdChown(int argc, const char **argv)
{ {
int ret; int ret;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
struct IATTR attr; struct IATTR attr;
uid_t owner = -1; uid_t owner = -1;
gid_t group = -1; gid_t group = -1;
attr.attr_chg_valid = 0; attr.attr_chg_valid = 0;
ERROR_OUT_IF(((argc != 2) && (argc != 3)), PRINTK("Usage: chown [OWNER] [GROUP] FILE\n"), return -1); ERROR_OUT_IF(((argc != 2) && (argc != 3)), PRINTK("Usage: chown [OWNER] [GROUP] FILE\n"), return -1);
if (argc == 2) if (argc == 2) { // 2: chown owner of file
{ ERROR_OUT_IF((checkNum(argv[0]) != 0), PRINTK("check OWNER is digit\n"), return -1);
ERROR_OUT_IF((checkNum(argv[0]) != 0), PRINTK("check OWNER is digit\n"), return -1); owner = atoi(argv[0]);
owner = atoi(argv[0]); filename = argv[1];
filename = argv[1]; }
} if (argc == 3) { // 3: chown both owner and group
if (argc == 3) ERROR_OUT_IF((checkNum(argv[0]) != 0), PRINTK("check OWNER is digit\n"), return -1);
{ ERROR_OUT_IF((checkNum(argv[1]) != 0), PRINTK("check GROUP is digit\n"), return -1);
ERROR_OUT_IF((checkNum(argv[0]) != 0), PRINTK("check OWNER is digit\n"), return -1); owner = atoi(argv[0]);
ERROR_OUT_IF((checkNum(argv[1]) != 0), PRINTK("check GROUP is digit\n"), return -1); group = atoi(argv[1]);
owner = atoi(argv[0]); filename = argv[2];
group = atoi(argv[1]); }
filename = argv[2];
} if (group != -1) {
attr.attr_chg_gid = group;
if (group != -1) attr.attr_chg_valid |= CHG_GID;
{ }
attr.attr_chg_gid = group; if (owner != -1) {
attr.attr_chg_valid |= CHG_GID; attr.attr_chg_uid = owner;
} attr.attr_chg_valid |= CHG_UID;
if (owner != -1) }
{
attr.attr_chg_uid = owner; char *shell_working_directory = OsShellGetWorkingDirectory();
attr.attr_chg_valid |= CHG_UID; if (shell_working_directory == NULL) {
return -1;
} }
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "chown error\n"), return -1);
char *shell_working_directory = OsShellGetWorkingDirectory(); ret = chattr(fullpath, &attr);
if (shell_working_directory == NULL) if (ret < 0) {
{ free(fullpath);
return -1; PRINTK("chown error! %s\n", strerror(errno));
return ret;
} }
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "chown error\n"), return -1);
ret = chattr(fullpath, &attr); free(fullpath);
if (ret < 0) return 0;
{
free(fullpath);
PRINTK("chown error! %s\n", strerror(errno));
return ret;
}
free(fullpath);
return 0;
} }
int osShellCmdChgrp(int argc, const char **argv) int osShellCmdChgrp(int argc, const char **argv)
{ {
int ret; int ret;
char *fullpath = NULL; char *fullpath = NULL;
const char *filename = NULL; const char *filename = NULL;
struct IATTR attr; struct IATTR attr;
gid_t group; gid_t group;
attr.attr_chg_valid = 0; attr.attr_chg_valid = 0;
ERROR_OUT_IF((argc != 2), PRINTK("Usage: chgrp GROUP FILE\n"), return -1); ERROR_OUT_IF((argc != 2), PRINTK("Usage: chgrp GROUP FILE\n"), return -1);
ERROR_OUT_IF((checkNum(argv[0]) != 0), PRINTK("check GROUP is digit\n"), return -1); ERROR_OUT_IF((checkNum(argv[0]) != 0), PRINTK("check GROUP is digit\n"), return -1);
group = atoi(argv[0]); group = atoi(argv[0]);
filename = argv[1]; filename = argv[1];
if (group != -1) { if (group != -1) {
attr.attr_chg_gid = group; attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID; attr.attr_chg_valid |= CHG_GID;
} }
char *shell_working_directory = OsShellGetWorkingDirectory(); char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) { if (shell_working_directory == NULL) {
return -1; return -1;
} }
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath); ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "chmod error"), return -1); ERROR_OUT_IF(ret < 0, set_err(-ret, "chmod error"), return -1);
ret = chattr(fullpath, &attr); ret = chattr(fullpath, &attr);
if (ret < 0) { if (ret < 0) {
free(fullpath); free(fullpath);
PRINTK("chgrp error! %s\n", strerror(errno)); PRINTK("chgrp error! %s\n", strerror(errno));
return ret; return ret;
} }
free(fullpath); free(fullpath);
return 0; return 0;
} }
#ifdef LOSCFG_SHELL_CMD_DEBUG #ifdef LOSCFG_SHELL_CMD_DEBUG
......
/* /*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
...@@ -239,7 +239,7 @@ BOOL VnodeInUseIter(const struct Mount *mount) ...@@ -239,7 +239,7 @@ BOOL VnodeInUseIter(const struct Mount *mount)
return FALSE; return FALSE;
} }
int VnodeHold() int VnodeHold(void)
{ {
int ret = LOS_MuxLock(&g_vnodeMux, LOS_WAIT_FOREVER); int ret = LOS_MuxLock(&g_vnodeMux, LOS_WAIT_FOREVER);
if (ret != LOS_OK) { if (ret != LOS_OK) {
...@@ -248,7 +248,7 @@ int VnodeHold() ...@@ -248,7 +248,7 @@ int VnodeHold()
return ret; return ret;
} }
int VnodeDrop() int VnodeDrop(void)
{ {
int ret = LOS_MuxUnlock(&g_vnodeMux); int ret = LOS_MuxUnlock(&g_vnodeMux);
if (ret != LOS_OK) { if (ret != LOS_OK) {
...@@ -583,7 +583,7 @@ int VnodeCreate(struct Vnode *parent, const char *name, int mode, struct Vnode * ...@@ -583,7 +583,7 @@ int VnodeCreate(struct Vnode *parent, const char *name, int mode, struct Vnode *
return 0; return 0;
} }
int VnodeDevInit() int VnodeDevInit(void)
{ {
struct Vnode *devNode = NULL; struct Vnode *devNode = NULL;
struct Mount *devMount = NULL; struct Mount *devMount = NULL;
...@@ -616,7 +616,7 @@ int VnodeGetattr(struct Vnode *vnode, struct stat *buf) ...@@ -616,7 +616,7 @@ int VnodeGetattr(struct Vnode *vnode, struct stat *buf)
return LOS_OK; return LOS_OK;
} }
struct Vnode *VnodeGetRoot() struct Vnode *VnodeGetRoot(void)
{ {
return g_rootVnode; return g_rootVnode;
} }
...@@ -697,7 +697,7 @@ LIST_HEAD* GetVnodeActiveList() ...@@ -697,7 +697,7 @@ LIST_HEAD* GetVnodeActiveList()
return &g_vnodeActiveList; return &g_vnodeActiveList;
} }
int VnodeClearCache() int VnodeClearCache(void)
{ {
struct Vnode *item = NULL; struct Vnode *item = NULL;
struct Vnode *nextItem = NULL; struct Vnode *nextItem = NULL;
......
...@@ -50,8 +50,8 @@ extern "C" { ...@@ -50,8 +50,8 @@ extern "C" {
* Rwlock object. * Rwlock object.
*/ */
typedef struct OsRwlock { typedef struct OsRwlock {
INT32 magic:24; /**< Magic number */ INT32 magic : 24; /**< Magic number */
INT32 rwCount:8; /**< Times of locking the rwlock, rwCount > 0 when rwkick is read mode, rwCount < 0 INT32 rwCount : 8; /**< Times of locking the rwlock, rwCount > 0 when rwkick is read mode, rwCount < 0
when the rwlock is write mode, rwCount = 0 when the lock is free. */ when the rwlock is write mode, rwCount = 0 when the lock is free. */
VOID *writeOwner; /**< The current write thread that is locking the rwlock */ VOID *writeOwner; /**< The current write thread that is locking the rwlock */
LOS_DL_LIST readList; /**< Read waiting list */ LOS_DL_LIST readList; /**< Read waiting list */
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
#define ip_addr_set_val(dest, src) do { \ #define ip_addr_set_val(dest, src) do { \
IP_SET_TYPE_VAL(*dest, IP_GET_TYPE(src)); \ IP_SET_TYPE_VAL(*dest, IP_GET_TYPE(src)); \
if(IP_IS_V6_VAL(*(src))) { \ if (IP_IS_V6_VAL(*(src))) { \
ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); \ ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); \
} else { \ } else { \
ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); \ ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); \
......
...@@ -365,19 +365,19 @@ int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len) ...@@ -365,19 +365,19 @@ int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len)
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tRX packets:%u ", ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tRX packets:%u ",
netif->mib2_counters.ifinucastpkts + netif->mib2_counters.ifinnucastpkts); netif->mib2_counters.ifinucastpkts + netif->mib2_counters.ifinnucastpkts);
if ((ret <= 0) || ((unsigned int)ret >= buf_len)) if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out; goto out;
tmp += ret; tmp += ret;
buf_len -= (unsigned int)ret; buf_len -= (unsigned int)ret;
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "errors:%u ", netif->mib2_counters.ifinerrors); ret = snprintf_s(tmp, buf_len, (buf_len - 1), "errors:%u ", netif->mib2_counters.ifinerrors);
if ((ret <= 0) || ((unsigned int)ret >= buf_len)) if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out; goto out;
tmp += ret; tmp += ret;
buf_len -= (unsigned int)ret; buf_len -= (unsigned int)ret;
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "dropped:%u ", netif->mib2_counters.ifindiscards); ret = snprintf_s(tmp, buf_len, (buf_len - 1), "dropped:%u ", netif->mib2_counters.ifindiscards);
if ((ret <= 0) || ((unsigned int)ret >= buf_len)) if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out; goto out;
tmp += ret; tmp += ret;
buf_len -= (unsigned int)ret; buf_len -= (unsigned int)ret;
...@@ -1031,12 +1031,12 @@ u32_t lwip_ifconfig(int argc, const char **argv) ...@@ -1031,12 +1031,12 @@ u32_t lwip_ifconfig(int argc, const char **argv)
#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL #if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) { if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
/* Create the semaphore for ip conflict detection. */ /* Create the semaphore for ip conflict detection. */
if (sys_sem_new(&ip_conflict_detect, 0) != ERR_OK) { if (sys_sem_new(&ip_conflict_detect, 0) != ERR_OK) {
sys_sem_free(&ifconfig_cmd.cb_completed); sys_sem_free(&ifconfig_cmd.cb_completed);
PRINTK("ifconfig: internal error\n"); PRINTK("ifconfig: internal error\n");
return 1; return 1;
} }
is_ip_conflict_signal = 1; is_ip_conflict_signal = 1;
} }
#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */ #endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
...@@ -1057,8 +1057,8 @@ u32_t lwip_ifconfig(int argc, const char **argv) ...@@ -1057,8 +1057,8 @@ u32_t lwip_ifconfig(int argc, const char **argv)
sys_sem_free(&ifconfig_cmd.cb_completed); sys_sem_free(&ifconfig_cmd.cb_completed);
#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL #if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) { if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
is_ip_conflict_signal = 0; is_ip_conflict_signal = 0;
sys_sem_free(&ip_conflict_detect); sys_sem_free(&ip_conflict_detect);
} }
#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */ #endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
...@@ -1076,37 +1076,37 @@ u32_t lwip_ifconfig(int argc, const char **argv) ...@@ -1076,37 +1076,37 @@ u32_t lwip_ifconfig(int argc, const char **argv)
ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0'; ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
PRINTK("%s", ifconfig_cmd.cb_print_buf); PRINTK("%s", ifconfig_cmd.cb_print_buf);
#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL #if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
/* Pend 2 seconds for waiting the arp reply if the ip is already in use.*/ /* Pend 2 seconds for waiting the arp reply if the ip is already in use. */
if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) { if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
err = (err_t)sys_arch_sem_wait(&ip_conflict_detect, DUP_ARP_DETECT_TIME); err = (err_t)sys_arch_sem_wait(&ip_conflict_detect, DUP_ARP_DETECT_TIME);
is_ip_conflict_signal = 0; is_ip_conflict_signal = 0;
sys_sem_free(&ip_conflict_detect); sys_sem_free(&ip_conflict_detect);
if (err < 0) { if (err < 0) {
/* The result neither conflict nor timeout. */ /* The result neither conflict nor timeout. */
PRINT_ERR("ifconfig: internal error\n"); PRINT_ERR("ifconfig: internal error\n");
sys_sem_free(&ifconfig_cmd.cb_completed); sys_sem_free(&ifconfig_cmd.cb_completed);
return 1; return 1;
} else if (err < DUP_ARP_DETECT_TIME) { } else if (err < DUP_ARP_DETECT_TIME) {
/* Duplicate use of new ip, restore it to the old one. */ /* Duplicate use of new ip, restore it to the old one. */
PRINT_ERR("ifconfig: ip conflict!\n"); PRINT_ERR("ifconfig: ip conflict!\n");
ip_addr_set_ip4_u32_val(ifconfig_cmd.ip_addr, old_ip4addr); ip_addr_set_ip4_u32_val(ifconfig_cmd.ip_addr, old_ip4addr);
ret = tcpip_callback(lwip_ifconfig_internal, &ifconfig_cmd); ret = tcpip_callback(lwip_ifconfig_internal, &ifconfig_cmd);
if (ret != ERR_OK) { if (ret != ERR_OK) {
sys_sem_free(&ifconfig_cmd.cb_completed); sys_sem_free(&ifconfig_cmd.cb_completed);
PRINTK("%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret); PRINTK("%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
return 1; return 1;
}
(void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
sys_sem_free(&ifconfig_cmd.cb_completed);
ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
PRINTK("%s", ifconfig_cmd.cb_print_buf);
return 1;
} }
(void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
sys_sem_free(&ifconfig_cmd.cb_completed);
ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
PRINTK("%s", ifconfig_cmd.cb_print_buf);
return 1;
}
} }
#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */ #endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
#if LWIP_IPV6 #if LWIP_IPV6
if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL(ifconfig_cmd.ip_addr)) { if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL(ifconfig_cmd.ip_addr)) {
/* Pend 2 seconds for waiting the arp reply if the ip is already in use.*/ /* Pend 2 seconds for waiting the arp reply if the ip is already in use. */
retval = sys_arch_sem_wait(&dup_addr_detect, DUP_ARP_DETECT_TIME); retval = sys_arch_sem_wait(&dup_addr_detect, DUP_ARP_DETECT_TIME);
is_dup_detect_initialized = 0; is_dup_detect_initialized = 0;
sys_sem_free(&dup_addr_detect); sys_sem_free(&dup_addr_detect);
...@@ -1191,7 +1191,6 @@ void lwip_arp_show_internal(struct netif *netif, char *printf_buf, unsigned int ...@@ -1191,7 +1191,6 @@ void lwip_arp_show_internal(struct netif *netif, char *printf_buf, unsigned int
|| (state == ETHARP_STATE_STATIC) || (state == ETHARP_STATE_STATIC)
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */ #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
) && arp_table[i].netif) { ) && arp_table[i].netif) {
if (strcmp(netif_get_name(netif), netif_get_name(arp_table[i].netif)) != 0) { if (strcmp(netif_get_name(netif), netif_get_name(arp_table[i].netif)) != 0) {
continue; continue;
} }
...@@ -1305,7 +1304,7 @@ void lwip_arp_internal(void *arg) ...@@ -1305,7 +1304,7 @@ void lwip_arp_internal(void *arg)
for (netif = netif_list; netif != NULL; netif = netif->next) { for (netif = netif_list; netif != NULL; netif = netif->next) {
ret = etharp_delete_arp_entry(netif, &ipaddr); ret = etharp_delete_arp_entry(netif, &ipaddr);
if (ret == ERR_OK) { if (ret == ERR_OK) {
/*only can del success one time*/ /* only can del success one time */
break; break;
} }
} }
...@@ -1387,7 +1386,7 @@ u32_t lwip_arp(int argc, const char **argv) ...@@ -1387,7 +1386,7 @@ u32_t lwip_arp(int argc, const char **argv)
goto arp_error; goto arp_error;
} }
i += 2; i += 2;
argc -= 2; argc -= 2; // 2: number of used parameters
} else if (strcmp("-d", argv[i]) == 0 && (argc > 1)) { } else if (strcmp("-d", argv[i]) == 0 && (argc > 1)) {
/* arp delete */ /* arp delete */
arp_cmd.option = ARP_OPTION_DEL; arp_cmd.option = ARP_OPTION_DEL;
...@@ -1399,8 +1398,8 @@ u32_t lwip_arp(int argc, const char **argv) ...@@ -1399,8 +1398,8 @@ u32_t lwip_arp(int argc, const char **argv)
} }
i += 2; i += 2;
argc -= 2; argc -= 2; // 2: number of used parameters
} else if (strcmp("-s", argv[i]) == 0 && (argc > 2)) { } else if (strcmp("-s", argv[i]) == 0 && (argc > 2)) { // 2: require more than 2 parameters
/* arp add */ /* arp add */
char *digit = NULL; char *digit = NULL;
u32_t macaddrlen = strlen(argv[i + 2]) + 1; u32_t macaddrlen = strlen(argv[i + 2]) + 1;
...@@ -1418,7 +1417,7 @@ u32_t lwip_arp(int argc, const char **argv) ...@@ -1418,7 +1417,7 @@ u32_t lwip_arp(int argc, const char **argv)
goto arp_error; goto arp_error;
} }
/*cannot add an arp entry of 127.*.*.* */ /* cannot add an arp entry of 127.*.*.* */
if ((arp_cmd.ipaddr & (u32_t)0x0000007fUL) == (u32_t)0x0000007fUL) { if ((arp_cmd.ipaddr & (u32_t)0x0000007fUL) == (u32_t)0x0000007fUL) {
PRINTK("IP address is not correct!\n"); PRINTK("IP address is not correct!\n");
goto arp_error; goto arp_error;
...@@ -1452,7 +1451,7 @@ u32_t lwip_arp(int argc, const char **argv) ...@@ -1452,7 +1451,7 @@ u32_t lwip_arp(int argc, const char **argv)
} }
i += 3; i += 3;
argc -= 3; argc -= 3; // 3: number of used parameters
} else { } else {
goto arp_error; goto arp_error;
} }
...@@ -1727,7 +1726,7 @@ LWIP_STATIC int osPingFunc(u32_t destip, u32_t cnt, u32_t interval, u32_t data_l ...@@ -1727,7 +1726,7 @@ LWIP_STATIC int osPingFunc(u32_t destip, u32_t cnt, u32_t interval, u32_t data_l
break; break;
} }
intrvl -= 1000; intrvl -= 1000;
sys_msleep(1000); sys_msleep(1000); // 1000: delay 1 s
if (ping_kill == 1) if (ping_kill == 1)
break; break;
} while (intrvl > 0); } while (intrvl > 0);
...@@ -1819,7 +1818,7 @@ u32_t osShellPing(int argc, const char **argv) ...@@ -1819,7 +1818,7 @@ u32_t osShellPing(int argc, const char **argv)
count = ret; count = ret;
count_set = 1; count_set = 1;
i += 2; i += 2;
argc -= 2; argc -= 2; // 2: nuber of arguments that has been checked
} else if (strcmp("-t", argv[i]) == 0) { } else if (strcmp("-t", argv[i]) == 0) {
count = 0; /* ping forerver */ count = 0; /* ping forerver */
count_set = 1; count_set = 1;
...@@ -1834,7 +1833,7 @@ u32_t osShellPing(int argc, const char **argv) ...@@ -1834,7 +1833,7 @@ u32_t osShellPing(int argc, const char **argv)
interval = ret; interval = ret;
i += 2; i += 2;
argc -= 2; argc -= 2; // 2:number of arguments that has been checked
} else if (strcmp("-l", argv[i]) == 0 && (argc > 1)) { } else if (strcmp("-l", argv[i]) == 0 && (argc > 1)) {
ret = atoi(argv[i + 1]); ret = atoi(argv[i + 1]);
if (ret < 0 || ret > (int)(LWIP_MAX_UDP_RAW_SEND_SIZE - sizeof(struct icmp_echo_hdr))) { if (ret < 0 || ret > (int)(LWIP_MAX_UDP_RAW_SEND_SIZE - sizeof(struct icmp_echo_hdr))) {
...@@ -1844,7 +1843,7 @@ u32_t osShellPing(int argc, const char **argv) ...@@ -1844,7 +1843,7 @@ u32_t osShellPing(int argc, const char **argv)
} }
data_len = ret; data_len = ret;
i += 2; i += 2;
argc -= 2; argc -= 2; // 2: number of elements has been checked
} else if (strcmp("-k", argv[i]) == 0) { } else if (strcmp("-k", argv[i]) == 0) {
if (ping_taskid > 0) { if (ping_taskid > 0) {
ping_kill = 1; /* stop the current ping task */ ping_kill = 1; /* stop the current ping task */
...@@ -1896,7 +1895,7 @@ u32_t osShellPing(int argc, const char **argv) ...@@ -1896,7 +1895,7 @@ u32_t osShellPing(int argc, const char **argv)
stPingTask.auwArgs[0] = dst_ipaddr.addr; /* network order */ stPingTask.auwArgs[0] = dst_ipaddr.addr; /* network order */
stPingTask.auwArgs[1] = count; stPingTask.auwArgs[1] = count;
stPingTask.auwArgs[2] = interval; stPingTask.auwArgs[2] = interval;
stPingTask.auwArgs[3] = data_len; stPingTask.auwArgs[3] = data_len; // 3: index of data length
ret = LOS_TaskCreate((UINT32 *)(&ping_taskid), &stPingTask); ret = LOS_TaskCreate((UINT32 *)(&ping_taskid), &stPingTask);
if (ret != LOS_OK) { if (ret != LOS_OK) {
PRINTK("ping_task create failed 0x%08x.\n", ret); PRINTK("ping_task create failed 0x%08x.\n", ret);
...@@ -1923,7 +1922,7 @@ ping_error: ...@@ -1923,7 +1922,7 @@ ping_error:
SHELLCMD_ENTRY(ping_shellcmd, CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)osShellPing); SHELLCMD_ENTRY(ping_shellcmd, CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)osShellPing);
#endif /* LOSCFG_SHELL */ #endif /* LOSCFG_SHELL */
#else /* LWIP_EXT_POLL_SUPPORT*/ #else /* LWIP_EXT_POLL_SUPPORT */
u32_t osShellPing(int argc, const char **argv) u32_t osShellPing(int argc, const char **argv)
{ {
...@@ -2076,7 +2075,7 @@ FAILURE: ...@@ -2076,7 +2075,7 @@ FAILURE:
SHELLCMD_ENTRY(ping_shellcmd, CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)osShellPing); SHELLCMD_ENTRY(ping_shellcmd, CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)osShellPing);
#endif /* LOSCFG_SHELL */ #endif /* LOSCFG_SHELL */
#endif /* LWIP_EXT_POLL_SUPPORT*/ #endif /* LWIP_EXT_POLL_SUPPORT */
#if LWIP_IPV6 #if LWIP_IPV6
u32_t osShellPing6(int argc, const char **argv) u32_t osShellPing6(int argc, const char **argv)
...@@ -2311,6 +2310,7 @@ REDUCE_SELECT_TIME: ...@@ -2311,6 +2310,7 @@ REDUCE_SELECT_TIME:
PRINTK("--- %s ping statistics ---\n", argv[ping6_params.host_index]); PRINTK("--- %s ping statistics ---\n", argv[ping6_params.host_index]);
PRINTK("%d packets transmitted, %d received, %.2f%% packet loss, time %dms\n", PRINTK("%d packets transmitted, %d received, %.2f%% packet loss, time %dms\n",
nsent, nrecieve, (float)(((float)(nsent - nrecieve)) * ((float)(100)) / ((float)(nsent))), nsent, nrecieve, (float)(((float)(nsent - nrecieve)) * ((float)(100)) / ((float)(nsent))),
/* 1000: convert seconds to milliseconds, 1000000: convert nanoseconds to milliseconds */
((last.tv_sec - first.tv_sec) * 1000 + (last.tv_nsec - first.tv_nsec) / 1000000)); ((last.tv_sec - first.tv_sec) * 1000 + (last.tv_nsec - first.tv_nsec) / 1000000));
if (nrecieve) { if (nrecieve) {
/* Display rtt stats only if at least one packet is received */ /* Display rtt stats only if at least one packet is received */
...@@ -2629,7 +2629,7 @@ usage: ...@@ -2629,7 +2629,7 @@ usage:
SHELLCMD_ENTRY(ntpdate_shellcmd, CMD_TYPE_EX, "ntpdate", XARGS, (CmdCallBackFunc)osShellNtpdate); SHELLCMD_ENTRY(ntpdate_shellcmd, CMD_TYPE_EX, "ntpdate", XARGS, (CmdCallBackFunc)osShellNtpdate);
#endif /* LOSCFG_SHELL_CMD_DEBUG */ #endif /* LOSCFG_SHELL_CMD_DEBUG */
#endif /* LWIP_SNTP*/ #endif /* LWIP_SNTP */
#if LWIP_DNS #if LWIP_DNS
u32_t osShellDns(int argc, const char **argv) u32_t osShellDns(int argc, const char **argv)
...@@ -2866,7 +2866,7 @@ int netstat_tcp_recvq(struct tcp_pcb *tpcb) ...@@ -2866,7 +2866,7 @@ int netstat_tcp_recvq(struct tcp_pcb *tpcb)
case NETCONN_UDP_IPV6: case NETCONN_UDP_IPV6:
#endif #endif
case NETCONN_UDP: case NETCONN_UDP:
SYS_ARCH_GET(((unsigned int)conn->recv_avail /*+ conn->lrcv_left*/), retVal); SYS_ARCH_GET(((unsigned int)conn->recv_avail), retVal); // + conn->lrcv_left
break; break;
default: default:
retVal = 0; /* ur... very ugly, damn DHCP DNS and SNTP */ retVal = 0; /* ur... very ugly, damn DHCP DNS and SNTP */
...@@ -2922,7 +2922,7 @@ int netstat_udp_sendq6(struct udp_pcb *upcb) ...@@ -2922,7 +2922,7 @@ int netstat_udp_sendq6(struct udp_pcb *upcb)
#else #else
ret = netstat_get_udp_sendQLen6(upcb, neighbor_cache[idx].q); ret = netstat_get_udp_sendQLen6(upcb, neighbor_cache[idx].q);
if (ret >= 0) { if (ret >= 0) {
retLen += ret; retLen += ret;
} }
#endif #endif
return retLen; return retLen;
...@@ -2966,10 +2966,10 @@ int netstat_udp_sendq(struct udp_pcb *upcb) ...@@ -2966,10 +2966,10 @@ int netstat_udp_sendq(struct udp_pcb *upcb)
#else #else
ret = netstat_get_udp_sendQLen(upcb, arp_table[arpidx].q); ret = netstat_get_udp_sendQLen(upcb, arp_table[arpidx].q);
if (ret > 0) { if (ret > 0) {
retLen += ret; retLen += ret;
if (retLen <= 0) { // overflow, set rteLen = -1 to indicate if (retLen <= 0) { // overflow, set rteLen = -1 to indicate
retLen = -1; retLen = -1;
} }
} }
#endif #endif
} }
...@@ -2992,7 +2992,7 @@ int netstat_netconn_recvq(const struct netconn *conn) ...@@ -2992,7 +2992,7 @@ int netstat_netconn_recvq(const struct netconn *conn)
case NETCONN_PKT_RAW: case NETCONN_PKT_RAW:
#endif #endif
case NETCONN_UDP: case NETCONN_UDP:
SYS_ARCH_GET(((unsigned int)conn->recv_avail /*+ conn->lrcv_left*/), retVal); SYS_ARCH_GET(((unsigned int)conn->recv_avail), retVal); // + conn->lrcv_left
break; break;
default: default:
retVal = 0; /* ur... very ugly, damn DHCP DNS and SNTP */ retVal = 0; /* ur... very ugly, damn DHCP DNS and SNTP */
...@@ -3271,10 +3271,10 @@ void netstat_internal(void *ctx) ...@@ -3271,10 +3271,10 @@ void netstat_internal(void *ctx)
recvQlen = netstat_netconn_recvq(rpcb->recv_arg); recvQlen = netstat_netconn_recvq(rpcb->recv_arg);
sendQlen = netstat_netconn_sendq(rpcb->recv_arg); sendQlen = netstat_netconn_sendq(rpcb->recv_arg);
proto = rpcb->protocol;//raw_proto; proto = rpcb->protocol; // raw_proto;
iRet = snprintf_s((char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1, iRet = snprintf_s((char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
"%-8s%-12d%-12d%-20s%-20s%-16u%-16d\n", "%-8s%-12d%-12d%-20s%-20s%-16u%-16d\n",
"raw", recvQlen, sendQlen, local_ip_port, remote_ip_port, proto, /*rpcb->hdrincl*/0); "raw", recvQlen, sendQlen, local_ip_port, remote_ip_port, proto, 0); // rpcb->hdrincl
if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) { if ((iRet <= 0) || ((u32_t)(iRet) >= entry_buf_len)) {
goto out; goto out;
} }
...@@ -3297,7 +3297,8 @@ void netstat_internal(void *ctx) ...@@ -3297,7 +3297,8 @@ void netstat_internal(void *ctx)
sendQlen = netstat_netconn_sendq(rpcb->recv_arg); sendQlen = netstat_netconn_sendq(rpcb->recv_arg);
for (netif = netif_list; netif != NULL; netif = netif->next) { for (netif = netif_list; netif != NULL; netif = netif->next) {
if (netif_get_index(netif)/*netif->ifindex*/ == rpcb->netif_idx/*index*/) { /* netif->ifindex and index */
if (netif_get_index(netif) == rpcb->netif_idx) {
(void)snprintf_s((char *)netif_name, IFNAMSIZ, IFNAMSIZ - 1, "%s", netif_get_name(netif)); (void)snprintf_s((char *)netif_name, IFNAMSIZ, IFNAMSIZ - 1, "%s", netif_get_name(netif));
break; break;
} }
...@@ -3307,7 +3308,7 @@ void netstat_internal(void *ctx) ...@@ -3307,7 +3308,7 @@ void netstat_internal(void *ctx)
(void)snprintf_s((char *)netif_name, IFNAMSIZ, IFNAMSIZ - 1, "%s", "None"); (void)snprintf_s((char *)netif_name, IFNAMSIZ, IFNAMSIZ - 1, "%s", "None");
} }
proto = rpcb->protocol;//ntohs(rpcb->proto.eth_proto); proto = rpcb->protocol; // ntohs(rpcb->proto.eth_proto);
iRet = snprintf_s((char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1, iRet = snprintf_s((char *)(entry_buf + entry_buf_offset), entry_buf_len, entry_buf_len - 1,
"%-12s%-12d%-12d%-16x%-12s\n", "pkt-raw", recvQlen, sendQlen, proto, netif_name); "%-12s%-12d%-12d%-16x%-12s\n", "pkt-raw", recvQlen, sendQlen, proto, netif_name);
...@@ -3884,4 +3885,4 @@ SHELLCMD_ENTRY(reboot_shellcmd, CMD_TYPE_EX, "reboot", XARGS, (CmdCallBackFunc)o ...@@ -3884,4 +3885,4 @@ SHELLCMD_ENTRY(reboot_shellcmd, CMD_TYPE_EX, "reboot", XARGS, (CmdCallBackFunc)o
#endif /* LOSCFG_SHELL_CMD_DEBUG */ #endif /* LOSCFG_SHELL_CMD_DEBUG */
#endif #endif
#endif //LWIP_ENABLE_LOS_SHELL_CMD #endif // LWIP_ENABLE_LOS_SHELL_CMD
...@@ -435,9 +435,9 @@ LWIP_STATIC void handle_discover(struct netif *netif, struct dhcps *dhcps, ...@@ -435,9 +435,9 @@ LWIP_STATIC void handle_discover(struct netif *netif, struct dhcps *dhcps,
} }
#else #else
else { else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
("handle_discover: sendto(OFFER, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT)\n")); ("handle_discover: sendto(OFFER, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT)\n"));
(void)udp_sendto_if_src(dhcps->pcb, out_msg, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT, netif, &(netif->ip_addr)); (void)udp_sendto_if_src(dhcps->pcb, out_msg, IP_ADDR_BROADCAST, DHCP_CLIENT_PORT, netif, &(netif->ip_addr));
} }
#endif #endif
......
...@@ -412,7 +412,7 @@ int ip6addr_aton(const char *cp, ip6_addr_t *addr) ...@@ -412,7 +412,7 @@ int ip6addr_aton(const char *cp, ip6_addr_t *addr)
int squash_pos = ipv6_blocks; int squash_pos = ipv6_blocks;
int i; int i;
const char *s = cp; const char *s = cp;
const char *ss = cp-1; const char *ss = cp - 1;
for (; ; s++) { for (; ; s++) {
if (current_block_index >= ipv6_blocks) { if (current_block_index >= ipv6_blocks) {
......
...@@ -98,10 +98,10 @@ driverif_output(struct netif *netif, struct pbuf *p) ...@@ -98,10 +98,10 @@ driverif_output(struct netif *netif, struct pbuf *p)
#if PF_PKT_SUPPORT #if PF_PKT_SUPPORT
if (all_pkt_raw_pcbs != NULL) { if (all_pkt_raw_pcbs != NULL) {
p->flags = (u16_t)(p->flags & ~(PBUF_FLAG_LLMCAST | PBUF_FLAG_LLBCAST | PBUF_FLAG_HOST)); p->flags = (u16_t)(p->flags & ~(PBUF_FLAG_LLMCAST | PBUF_FLAG_LLBCAST | PBUF_FLAG_HOST));
p->flags |= PBUF_FLAG_OUTGOING; p->flags |= PBUF_FLAG_OUTGOING;
(void)raw_pkt_input(p, netif, NULL); (void)raw_pkt_input(p, netif, NULL);
} }
#endif #endif
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
......
...@@ -803,12 +803,10 @@ static u8_t lwip_ioctl_internal_SIOCSIFHWADDR(struct ifreq *ifr) ...@@ -803,12 +803,10 @@ static u8_t lwip_ioctl_internal_SIOCSIFHWADDR(struct ifreq *ifr)
} }
#endif #endif
else { else {
/* bring netif down to clear all Neighbor Cache Entry */ /* bring netif down to clear all Neighbor Cache Entry */
(void)netif_set_down(netif); (void)netif_set_down(netif);
ret = netif_set_hwaddr(netif, (const unsigned char *)ifr->ifr_hwaddr.sa_data, netif->hwaddr_len); ret = netif_set_hwaddr(netif, (const unsigned char *)ifr->ifr_hwaddr.sa_data, netif->hwaddr_len);
if (ret != ERR_OK) { if (ret != ERR_OK) {
(void)netif_set_up(netif); (void)netif_set_up(netif);
return err_to_errno(ret); return err_to_errno(ret);
...@@ -979,7 +977,6 @@ static u8_t lwip_ioctl_internal_SIOCGIFFLAGS(struct ifreq *ifr) ...@@ -979,7 +977,6 @@ static u8_t lwip_ioctl_internal_SIOCGIFFLAGS(struct ifreq *ifr)
#endif /* LWIP_IGMP || LWIP_IPV6_MLD */ #endif /* LWIP_IGMP || LWIP_IPV6_MLD */
#if LWIP_DHCP #if LWIP_DHCP
//if ((netif->flags & NETIF_FLAG_DHCP) != 0) {
if (dhcp_supplied_address(netif)) { if (dhcp_supplied_address(netif)) {
ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags | IFF_DYNAMIC); ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags | IFF_DYNAMIC);
} else { } else {
...@@ -1090,7 +1087,6 @@ static u8_t lwip_ioctl_internal_SIOCSIFNAME(struct ifreq *ifr) ...@@ -1090,7 +1087,6 @@ static u8_t lwip_ioctl_internal_SIOCSIFNAME(struct ifreq *ifr)
#endif #endif
netif = netif_find(ifr->ifr_name); netif = netif_find(ifr->ifr_name);
if (netif == NULL) { if (netif == NULL) {
return ENODEV; return ENODEV;
} else if (netif->link_layer_type == LOOPBACK_IF) { } else if (netif->link_layer_type == LOOPBACK_IF) {
...@@ -1165,7 +1161,6 @@ static u8_t lwip_ioctl_internal_SIOCGIFMTU(struct ifreq *ifr) ...@@ -1165,7 +1161,6 @@ static u8_t lwip_ioctl_internal_SIOCGIFMTU(struct ifreq *ifr)
/* get netif hw addr */ /* get netif hw addr */
netif = netif_find(ifr->ifr_name); netif = netif_find(ifr->ifr_name);
if (netif == NULL) { if (netif == NULL) {
return ENODEV; return ENODEV;
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册