未验证 提交 ba23a26f 编写于 作者: O openharmony_ci 提交者: Gitee

!928 Fix : 内核告警清理

Merge pull request !928 from yinjiaming/fix
......@@ -478,7 +478,6 @@ static int PthreadGetCputime(clockid_t clockID, struct timespec *ats)
uint64_t runtime;
UINT32 intSave;
UINT32 tid = GetTidFromClockID(clockID);
if (OS_TID_CHECK_INVALID(tid)) {
return -EINVAL;
}
......
......@@ -42,7 +42,7 @@
#ifdef __cplusplus
#if __cplusplus
extern "C"{
extern "C" {
#endif
#endif /* __cplusplus */
......
......@@ -343,7 +343,8 @@ static FRESULT init_cluster(DIR_FILE *pdfp, DIR *dp_new, FATFS *fs, int type, co
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;
FATFS *fs = (FATFS *)parent->originMount->data;
......
/*
* 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,
* are permitted provided that the following conditions are met:
......@@ -244,7 +244,8 @@ extern int chattr(const char *pathname, struct IATTR *attr);
*
* @retval #0 On success.
* @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:
* <ul><li>fs.h</li></ul>
......
/*
* 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,
* are permitted provided that the following conditions are met:
......@@ -682,7 +682,6 @@ int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, const ch
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
ret = jffs2_rmdir(parentInode, targetInode, (const unsigned char *)path);
if (ret == 0) {
(void)jffs2_iput(targetInode);
}
......@@ -809,7 +808,6 @@ int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, const c
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
ret = jffs2_unlink(parentInode, targetInode, (const unsigned char *)path);
if (ret == 0) {
(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,
* are permitted provided that the following conditions are met:
......@@ -154,7 +154,8 @@ static int FsCacheInfoFill(struct SeqBuf *buf, void *arg)
VnodeHold();
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());
vnodeFree = VnodeListProcess(buf, GetVnodeFreeList());
vnodeActive = VnodeListProcess(buf, GetVnodeActiveList());
......
......@@ -62,8 +62,8 @@ int OsShellCmdWriteProc(int argc, char **argv)
if (argc == WRITEPROC_ARGC) {
value = argv[0];
path = argv[2];
len = strlen(value) + 1; /* +1:add the \0 */
path = argv[2]; // 2: index of path
len = strlen(value) + 1; /* + 1:add the \0 */
if (strncmp(argv[1], ">>", strlen(">>")) == 0) {
if ((realpath(path, realPath) == NULL) || (strncmp(realPath, rootProcDir, strlen(rootProcDir)) != 0)) {
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,
* 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
int pollSize;
epHead = EpollGetDataBuff(epfd);
if (epHead== NULL) {
if (epHead == NULL) {
set_errno(EBADF);
return -1;
}
......
......@@ -225,7 +225,6 @@ static char *vfs_normalize_fullpath(const char *directory, const char *filename,
/* it's a absolute path, use it directly */
fullpath = strdup(filename); /* copy string */
if (fullpath == NULL) {
*pathname = NULL;
set_errno(ENOMEM);
......@@ -258,8 +257,7 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
}
#ifdef VFS_USING_WORKDIR
if (directory == NULL)
{
if (directory == NULL) {
spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
directory = curr->files->workdir;
}
......@@ -275,8 +273,7 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
if ((filename[0] != '/') && (strlen(directory) + namelen + 2 > TEMP_PATH_MAX)) {
#ifdef VFS_USING_WORKDIR
if (dir_flags == TRUE)
{
if (dir_flags == TRUE) {
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
}
#endif
......@@ -285,8 +282,7 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
fullpath = vfs_normalize_fullpath(directory, filename, pathname, namelen);
#ifdef VFS_USING_WORKDIR
if (dir_flags == TRUE)
{
if (dir_flags == TRUE) {
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
}
#endif
......@@ -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)
{
/* Get path by dirfd*/
/* Get path by dirfd */
char *relativeoldpath = NULL;
char *fullpath = NULL;
int ret = 0;
......
......@@ -155,7 +155,6 @@ int chdir(const char *path)
char *fullpath_bak = NULL;
struct stat statBuff;
if (!path) {
set_errno(EFAULT);
return -1;
......
......@@ -57,7 +57,6 @@ int utime(const char *path, const struct utimbuf *ptimes)
/* Sanity checks */
if (path == NULL) {
ret = -EINVAL;
goto errout;
......
......@@ -53,8 +53,7 @@
#include <ctype.h>
#include "fs/fs_operation.h"
typedef enum
{
typedef enum {
RM_RECURSIVER,
RM_FILE,
RM_DIR,
......@@ -63,15 +62,12 @@ typedef enum
} wildcard_type;
#define ERROR_OUT_IF(condition, message_function, handler) \
do \
{ \
if (condition) \
{ \
do { \
if (condition) { \
message_function; \
handler; \
} \
} \
while (0)
} while (0)
static inline void set_err(int errcode, const char *err_message)
{
......@@ -85,13 +81,11 @@ int osShellCmdDoChdir(const char *path)
char *fullpath_bak = NULL;
int ret;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
if (path == NULL)
{
if (path == NULL) {
LOS_TaskLock();
PRINTK("%s\n", shell_working_directory);
LOS_TaskUnlock();
......@@ -106,8 +100,7 @@ int osShellCmdDoChdir(const char *path)
fullpath_bak = fullpath;
ret = chdir(fullpath);
if (ret < 0)
{
if (ret < 0) {
free(fullpath_bak);
perror("cd");
return -1;
......@@ -117,8 +110,7 @@ int osShellCmdDoChdir(const char *path)
LOS_TaskLock();
ret = strncpy_s(shell_working_directory, PATH_MAX, fullpath, strlen(fullpath));
if (ret != EOK)
{
if (ret != EOK) {
free(fullpath_bak);
LOS_TaskUnlock();
return -1;
......@@ -137,15 +129,13 @@ int osShellCmdLs(int argc, const char **argv)
const char *filename = NULL;
int ret;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
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);
return 0;
}
......@@ -162,8 +152,7 @@ int osShellCmdLs(int argc, const char **argv)
int osShellCmdCd(int argc, const char **argv)
{
if (argc == 0)
{
if (argc == 0) {
(void)osShellCmdDoChdir("/");
return 0;
}
......@@ -189,35 +178,28 @@ int osShellCmdDoCatShow(UINTPTR arg)
(void)pthread_mutex_lock(&g_mutex_cat);
ini = fopen(fullpath, "r");
if (ini == NULL)
{
if (ini == NULL) {
ret = -1;
perror("cat error");
goto out;
}
do
{
do {
(void)memset_s(buf, sizeof(buf), 0, CAT_BUF_SIZE);
size = fread(buf, 1, CAT_BUF_SIZE, ini);
if ((int)size < 0)
{
if ((int)size < 0) {
ret = -1;
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);
if (cnt == 0)
{
if (cnt == 0) {
/* avoid task-starvation */
(void)LOS_TaskDelay(1);
continue;
}
else if (cnt < 0)
{
} else if (cnt < 0) {
perror("cat write error");
break;
}
......@@ -244,8 +226,7 @@ int osShellCmdCat(int argc, const char **argv)
struct Vnode *vnode = NULL;
TSK_INIT_PARAM_S init_param;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
......@@ -256,16 +237,14 @@ int osShellCmdCat(int argc, const char **argv)
VnodeHold();
ret = VnodeLookup(fullpath, &vnode, O_RDONLY);
if (ret != LOS_OK)
{
if (ret != LOS_OK) {
set_errno(-ret);
perror("cat error");
VnodeDrop();
free(fullpath);
return -1;
}
if (vnode->type != VNODE_TYPE_REG)
{
if (vnode->type != VNODE_TYPE_REG) {
set_errno(EINVAL);
perror("cat error");
VnodeDrop();
......@@ -283,9 +262,7 @@ int osShellCmdCat(int argc, const char **argv)
init_param.processID = 2; /* 2: kProcess */
ret = (int)LOS_TaskCreate(&ca_task, &init_param);
if (ret != LOS_OK)
{
if (ret != LOS_OK) {
free(fullpath);
}
......@@ -330,42 +307,34 @@ int osShellCmdMount(int argc, const char **argv)
char *filessystemtype = NULL;
unsigned long mountfalgs;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
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 (argc < 4)
if (strncmp(argv[0], "-t", 2) == 0 || strncmp(argv[0], "-o", 2) == 0) // 2: length of "-t"
{
if (argc < 4) { // 4: required number of parameters
PRINTK("mount -t/-o [DEVICE] [PATH] [NAME]\n");
return -1;
}
filename = argv[2];
filename = argv[2]; // 2: index of file path
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "mount error"), return -1);
if (strncmp(argv[3], "nfs", 3) == 0)
{
if (argc <= 6)
{
if (strncmp(argv[3], "nfs", 3) == 0) { // 3: index of fs type
if (argc <= 6) { // 6: arguments include uid or gid
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)
{
if (nfs_mount_ref != NULL) {
ret = nfs_mount_ref(argv[1], fullpath, uid, gid);
if (ret != LOS_OK)
{
if (ret != LOS_OK) {
PRINTK("mount -t [DEVICE] [PATH] [NAME]\n");
}
}
else
{
} else {
PRINTK("can't find nfs_mount\n");
}
free(fullpath);
......@@ -373,50 +342,36 @@ int osShellCmdMount(int argc, const char **argv)
}
}
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 */
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);
}
else
{
} else {
ret = mount(argv[1], fullpath, filessystemtype, mountfalgs, data); /* 3: fs type */
}
if (ret != LOS_OK)
{
if (ret != LOS_OK) {
perror("mount error");
}
else
{
} else {
PRINTK("mount ok\n");
}
}
else
{
} else {
filename = argv[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)
{
if (argc <= 5)
{
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
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 (nfs_mount_ref != NULL)
{
if (nfs_mount_ref != NULL) {
ret = nfs_mount_ref(argv[0], fullpath, uid, gid);
if (ret != LOS_OK)
{
if (ret != LOS_OK) {
PRINTK("mount [DEVICE] [PATH] [NAME]\n");
}
}
else
{
} else {
PRINTK("can't find nfs_mount\n");
}
free(fullpath);
......@@ -431,20 +386,14 @@ int osShellCmdMount(int argc, const char **argv)
mountfalgs = (argc >= 4) ? get_mountflags((const char *)argv[3]) : 0; /* 3: usr option */
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);
}
else
{
} else {
ret = mount(argv[0], fullpath, argv[2], mountfalgs, data); /* 2: fs type */
}
if (ret != LOS_OK)
{
if (ret != LOS_OK) {
perror("mount error");
}
else
{
} else {
PRINTK("mount ok\n");
}
}
......@@ -462,8 +411,7 @@ int osShellCmdUmount(int argc, const char **argv)
int cmp_num;
char *work_path = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
work_path = shell_working_directory;
......@@ -477,11 +425,9 @@ int osShellCmdUmount(int argc, const char **argv)
target_path = fullpath;
cmp_num = strlen(fullpath);
ret = strncmp(work_path, target_path, cmp_num);
if (ret == 0)
{
if (ret == 0) {
work_path += cmp_num;
if (*work_path == '/' || *work_path == '\0')
{
if (*work_path == '/' || *work_path == '\0') {
set_errno(EBUSY);
perror("umount error");
free(fullpath);
......@@ -491,8 +437,7 @@ int osShellCmdUmount(int argc, const char **argv)
ret = umount(fullpath);
free(fullpath);
if (ret != LOS_OK)
{
if (ret != LOS_OK) {
perror("umount error");
return 0;
}
......@@ -507,8 +452,7 @@ int osShellCmdMkdir(int argc, const char **argv)
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
......@@ -519,8 +463,7 @@ int osShellCmdMkdir(int argc, const char **argv)
ERROR_OUT_IF(ret < 0, set_err(-ret, "mkdir error"), return -1);
ret = mkdir(fullpath, S_IRWXU | S_IRWXG | S_IRWXO);
if (ret == -1)
{
if (ret == -1) {
perror("mkdir error");
}
free(fullpath);
......@@ -532,23 +475,20 @@ int osShellCmdPwd(int argc, const char **argv)
char buf[SHOW_MAX_LEN] = {0};
DIR *dir = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: pwd\n"), return -1);
dir = opendir(shell_working_directory);
if (dir == NULL)
{
if (dir == NULL) {
perror("pwd error");
return -1;
}
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();
PRINTK("pwd error: strncpy_s error!\n");
(void)closedir(dir);
......@@ -578,8 +518,7 @@ int osShellCmdStatfs(int argc, const char **argv)
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
......@@ -594,8 +533,7 @@ int osShellCmdStatfs(int argc, const char **argv)
result = statfs(fullpath, &sfs);
free(fullpath);
if (result != 0 || sfs.f_type == 0)
{
if (result != 0 || sfs.f_type == 0) {
PRINTK("statfs failed! Invalid argument!\n");
print_statfs_usage();
return -1;
......@@ -619,8 +557,7 @@ int osShellCmdTouch(int argc, const char **argv)
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
......@@ -632,8 +569,7 @@ int osShellCmdTouch(int argc, const char **argv)
fd = open(fullpath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
free(fullpath);
if (fd == -1)
{
if (fd == -1) {
perror("touch error");
return -1;
}
......@@ -660,14 +596,12 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
struct stat stat_buf;
mode_t src_mode;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
buf = (char *)malloc(CP_BUF_SIZE);
if (buf == NULL)
{
if (buf == NULL) {
PRINTK("cp error: Out of memory!\n");
return -1;
}
......@@ -675,8 +609,7 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
/* Get source fullpath. */
ret = vfs_normalize_path(shell_working_directory, src_filepath, &src_fullpath);
if (ret < 0)
{
if (ret < 0) {
set_errno(-ret);
PRINTK("cp error: %s\n", strerror(errno));
free(buf);
......@@ -686,16 +619,14 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
/* Is source path exist? */
ret = stat(src_fullpath, &stat_buf);
if (ret == -1)
{
if (ret == -1) {
PRINTK("cp %s error: %s\n", src_fullpath, strerror(errno));
goto errout_with_srcpath;
}
src_mode = stat_buf.st_mode;
/* 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);
goto errout_with_srcpath;
}
......@@ -703,8 +634,7 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
/* Get dest fullpath. */
dst_fullpath = strdup(dst_filename);
if (dst_fullpath == NULL)
{
if (dst_fullpath == NULL) {
PRINTK("cp error: Out of memory.\n");
goto errout_with_srcpath;
}
......@@ -712,20 +642,16 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
/* Is dest path exist? */
ret = stat(dst_fullpath, &stat_buf);
if (ret == 0)
{
if (ret == 0) {
/* Is dest path a directory? */
if (S_ISDIR(stat_buf.st_mode))
{
if (S_ISDIR(stat_buf.st_mode)) {
/* Get source file name without '/'. */
src_filename = src_filepath;
while (1)
{
while (1) {
filename = strchr(src_filename, '/');
if (filename == NULL)
{
if (filename == NULL) {
break;
}
src_filename = filename + 1;
......@@ -734,8 +660,7 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
/* Add the source file after dest path. */
ret = vfs_normalize_path(dst_fullpath, src_filename, &dst_filepath);
if (ret < 0)
{
if (ret < 0) {
set_errno(-ret);
PRINTK("cp error. %s.\n", strerror(errno));
goto errout_with_path;
......@@ -747,8 +672,7 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
/* 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);
goto errout_with_path;
}
......@@ -757,36 +681,30 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
(void)pthread_mutex_lock(&g_mutex_cp);
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));
goto errout_with_mutex;
}
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));
goto errout_with_srcfd;
}
do
{
do {
(void)memset_s(buf, CP_BUF_SIZE, 0, 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;
}
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));
goto errout_with_fd;
}
}
while (r_size == CP_BUF_SIZE);
} while (r_size == CP_BUF_SIZE);
/* Release resource. */
......@@ -825,46 +743,37 @@ static int os_shell_cmd_do_rmdir(const char *pathname)
int ret;
(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;
}
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);
}
d = opendir(pathname);
if (d == NULL)
{
if (d == NULL) {
return -1;
}
while (1)
{
while (1) {
dirent = readdir(d);
if (dirent == NULL)
{
if (dirent == NULL) {
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;
if (fullpath_buf_size <= 0)
{
if (fullpath_buf_size <= 0) {
PRINTK("buffer size is invalid!\n");
(void)closedir(d);
return -1;
}
fullpath = (char *)malloc(fullpath_buf_size);
if (fullpath == NULL)
{
if (fullpath == NULL) {
PRINTK("malloc failure!\n");
(void)closedir(d);
return -1;
}
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");
free(fullpath);
(void)closedir(d);
......@@ -884,55 +793,42 @@ static int os_wildcard_match(const char *src, const char *filename)
{
int ret;
if (*src != '\0')
{
if (*filename == '*')
{
while ((*filename == '*') || (*filename == '?'))
{
if (*src != '\0') {
if (*filename == '*') {
while ((*filename == '*') || (*filename == '?')) {
filename++;
}
if (*filename == '\0')
{
if (*filename == '\0') {
return 0;
}
while (*src != '\0' && !(*src == *filename))
{
while (*src != '\0' && !(*src == *filename)) {
src++;
}
if (*src == '\0')
{
if (*src == '\0') {
return -1;
}
ret = os_wildcard_match(src, filename);
while ((ret != 0) && (*(++src) != '\0'))
{
if (*src == *filename)
{
while ((ret != 0) && (*(++src) != '\0')) {
if (*src == *filename) {
ret = os_wildcard_match(src, filename);
}
}
return ret;
}
else
{
if ((*src == *filename) || (*filename == '?'))
{
} else {
if ((*src == *filename) || (*filename == '?')) {
return os_wildcard_match(++src, ++filename);
}
return -1;
}
}
while (*filename != '\0')
{
if (*filename != '*')
{
while (*filename != '\0') {
if (*filename != '*') {
return -1;
}
filename++;
......@@ -944,10 +840,8 @@ static int os_wildcard_match(const char *src, const char *filename)
static int os_is_containers_wildcard(const char *filename)
{
while (*filename != '\0')
{
if ((*filename == '*') || (*filename == '?'))
{
while (*filename != '\0') {
if ((*filename == '*') || (*filename == '?')) {
return 1;
}
filename++;
......@@ -961,8 +855,7 @@ static int os_wildcard_delete_file_or_dir(const char *fullpath, wildcard_type ma
{
int ret;
switch (mark)
{
switch (mark) {
case RM_RECURSIVER:
ret = os_shell_cmd_do_rmdir(fullpath);
break;
......@@ -975,8 +868,7 @@ static int os_wildcard_delete_file_or_dir(const char *fullpath, wildcard_type ma
default:
return VFS_ERROR;
}
if (ret == -1)
{
if (ret == -1) {
PRINTK("%s ", fullpath);
perror("rm/rmdir error!");
return ret;
......@@ -995,24 +887,18 @@ static char* os_wildcard_split_path(char *fullpath, char **handle, char **wait)
int b = 0;
int len = strlen(fullpath);
for (n = 0; n < len; n++)
{
if (fullpath[n] == '/')
{
if (b != 0)
{
for (n = 0; n < len; n++) {
if (fullpath[n] == '/') {
if (b != 0) {
fullpath[n] = '\0';
*wait = fullpath + n + 1;
break;
}
a = n;
}
else if (fullpath[n] == '*' || fullpath[n] == '?')
{
} else if (fullpath[n] == '*' || fullpath[n] == '?') {
b = n;
fullpath[a] = '\0';
if (a == 0)
{
if (a == 0) {
*handle = fullpath + a + 1;
continue;
}
......@@ -1039,112 +925,82 @@ static int os_wildcard_extract_directory(char *fullpath, void *dst, wildcard_typ
f = os_wildcard_split_path(fullpath, &s, &t);
if (s == NULL)
{
if (mark == CP_FILE)
{
if (s == NULL) {
if (mark == CP_FILE) {
ret = os_shell_cmd_do_cp(fullpath, dst);
}
else if (mark == CP_COUNT)
{
} else if (mark == CP_COUNT) {
ret = stat(fullpath, &stat_buf);
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))) {
(*(int *)dst)++;
}
}
else
{
} else {
ret = os_wildcard_delete_file_or_dir(fullpath, mark);
}
return ret;
}
d = (*f == '\0') ? opendir("/") : opendir(f);
if (d == NULL)
{
if (d == NULL) {
perror("opendir error");
return VFS_ERROR;
}
while (1)
{
while (1) {
dirent = readdir(d);
if (dirent == NULL)
{
if (dirent == NULL) {
break;
}
ret = strcpy_s(src, PATH_MAX, f);
if (ret != EOK)
{
if (ret != EOK) {
goto closedir_out;
}
ret = os_wildcard_match(dirent->d_name, s);
if (ret == 0)
{
if (ret == 0) {
ret = strcat_s(src, sizeof(src), separator);
if (ret != EOK)
{
if (ret != EOK) {
goto closedir_out;
}
ret = strcat_s(src, sizeof(src), dirent->d_name);
if (ret != EOK)
{
if (ret != EOK) {
goto closedir_out;
}
if (t == NULL)
{
if (mark == CP_FILE)
{
if (t == NULL) {
if (mark == CP_FILE) {
ret = os_shell_cmd_do_cp(src, dst);
}
else if (mark == CP_COUNT)
{
} else if (mark == CP_COUNT) {
ret = stat(src, &stat_buf);
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))) {
(*(int *)dst)++;
if ((*(int *)dst) > 1)
{
if ((*(int *)dst) > 1) {
break;
}
}
}
else
{
} else {
ret = os_wildcard_delete_file_or_dir(src, mark);
if (ret == 0)
{
if (ret == 0) {
deleteFlag = 1;
}
}
}
else
{
} else {
ret = strcat_s(src, sizeof(src), separator);
if (ret != EOK)
{
if (ret != EOK) {
goto closedir_out;
}
ret = strcat_s(src, sizeof(src), t);
if (ret != EOK)
{
if (ret != EOK) {
goto closedir_out;
}
ret = os_wildcard_extract_directory(src, dst, mark);
if (mark == CP_COUNT && (*(int *)dst) > 1)
{
if (mark == CP_COUNT && (*(int *)dst) > 1) {
break;
}
}
}
}
(void)closedir(d);
if (deleteFlag == 1)
{
if (deleteFlag == 1) {
ret = 0;
}
return ret;
......@@ -1163,8 +1019,7 @@ int osShellCmdCp(int argc, const char **argv)
struct stat stat_buf;
int count = 0;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
......@@ -1176,15 +1031,13 @@ int osShellCmdCp(int argc, const char **argv)
/* Get source fullpath. */
ret = vfs_normalize_path(shell_working_directory, src, &src_fullpath);
if (ret < 0)
{
if (ret < 0) {
set_errno(-ret);
PRINTK("cp error:%s\n", strerror(errno));
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);
goto errout_with_srcpath;
}
......@@ -1192,8 +1045,7 @@ int osShellCmdCp(int argc, const char **argv)
/* Get dest fullpath. */
ret = vfs_normalize_path(shell_working_directory, dst, &dst_fullpath);
if (ret < 0)
{
if (ret < 0) {
set_errno(-ret);
PRINTK("cp error: can't open %s. %s\n", dst, strerror(errno));
goto errout_with_srcpath;
......@@ -1202,47 +1054,36 @@ int osShellCmdCp(int argc, const char **argv)
/* Is dest path exist? */
ret = stat(dst_fullpath, &stat_buf);
if (ret < 0)
{
if (ret < 0) {
/* 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));
goto errout_with_path;
}
}
else
{
if ((S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode)) && dst[strlen(dst) - 1] == '/')
{
} 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);
goto errout_with_path;
}
}
if (os_is_containers_wildcard(src_fullpath))
{
if (ret < 0 || S_ISREG(stat_buf.st_mode) || S_ISLNK(stat_buf.st_mode))
{
if (os_is_containers_wildcard(src_fullpath)) {
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)
{
if (src_copy == NULL) {
PRINTK("cp error : Out of memory.\n");
goto errout_with_path;
}
(void)os_wildcard_extract_directory(src_copy, &count, CP_COUNT);
free(src_copy);
if (count > 1)
{
if (count > 1) {
PRINTK("cp error : %s is not a directory.\n", dst_fullpath);
goto errout_with_path;
}
}
ret = os_wildcard_extract_directory(src_fullpath, dst_fullpath, CP_FILE);
}
else
{
} else {
ret = os_shell_cmd_do_cp(src_fullpath, dst_fullpath);
}
free(dst_fullpath);
......@@ -1267,47 +1108,36 @@ int osShellCmdRm(int argc, const char **argv)
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
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);
filename = argv[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_RECURSIVER);
}
else
{
} else {
ret = os_shell_cmd_do_rmdir(fullpath);
}
}
else
{
} else {
filename = argv[0];
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);
}
else
{
} else {
ret = unlink(fullpath);
}
}
if (ret == -1)
{
if (ret == -1) {
perror("rm error");
}
free(fullpath);
......@@ -1320,8 +1150,7 @@ int osShellCmdRmdir(int argc, const char **argv)
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
......@@ -1331,16 +1160,12 @@ int osShellCmdRmdir(int argc, const char **argv)
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
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);
}
else
{
} else {
ret = rmdir(fullpath);
}
if (ret == -1)
{
if (ret == -1) {
PRINTK("rmdir %s failed. Error: %s.\n", fullpath, strerror(errno));
}
free(fullpath);
......@@ -1368,20 +1193,16 @@ int osShellCmdLsfd(int argc, const char **argv)
int checkNum(const char *arg)
{
int i = 0;
if (arg == NULL)
{
if (arg == NULL) {
return -1;
}
if (arg[0] == '-')
{
if (arg[0] == '-') {
/* exclude the '-' */
i = 1;
}
for (; arg[i] != 0; i++)
{
if (!isdigit(arg[i]))
{
for (; arg[i] != 0; i++) {
if (!isdigit(arg[i])) {
return -1;
}
}
......@@ -1394,15 +1215,12 @@ int osShellCmdSu(int argc, const char **argv)
int su_uid;
int su_gid;
if (argc == 0)
{
if (argc == 0) {
/* for su root */
su_uid = 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 */
PRINTK("check uid_num and gid_num is digit\n"), return -1);
......@@ -1435,14 +1253,10 @@ int osShellCmdChmod(int argc, const char **argv)
ERROR_OUT_IF((argc != 2), PRINTK("Usage: chmod <MODE> [FILE]\n"), return -1);
p = argv[0];
while (p[i])
{
if ((p[i] <= '7') && (p[i] >= '0'))
{
while (p[i]) {
if ((p[i] <= '7') && (p[i] >= '0')) {
mode = ((uint)mode << MODE_BIT) | (uint)(p[i] - '0');
}
else
{
} else {
PRINTK("check the input <MODE>\n");
return -1;
}
......@@ -1451,8 +1265,7 @@ int osShellCmdChmod(int argc, const char **argv)
filename = argv[1];
shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
if (shell_working_directory == NULL) {
return -1;
}
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
......@@ -1461,8 +1274,7 @@ int osShellCmdChmod(int argc, const char **argv)
attr.attr_chg_mode = mode;
attr.attr_chg_valid = CHG_MODE; /* change mode */
ret = chattr(fullpath, &attr);
if (ret < 0)
{
if (ret < 0) {
free(fullpath);
PRINTK("chmod error! %s\n", strerror(errno));
return ret;
......@@ -1483,14 +1295,12 @@ int osShellCmdChown(int argc, const char **argv)
attr.attr_chg_valid = 0;
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);
owner = atoi(argv[0]);
filename = argv[1];
}
if (argc == 3)
{
if (argc == 3) { // 3: chown both owner and group
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);
owner = atoi(argv[0]);
......@@ -1498,28 +1308,24 @@ int osShellCmdChown(int argc, const char **argv)
filename = argv[2];
}
if (group != -1)
{
if (group != -1) {
attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID;
}
if (owner != -1)
{
if (owner != -1) {
attr.attr_chg_uid = owner;
attr.attr_chg_valid |= CHG_UID;
}
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
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);
ret = chattr(fullpath, &attr);
if (ret < 0)
{
if (ret < 0) {
free(fullpath);
PRINTK("chown error! %s\n", strerror(errno));
return ret;
......
/*
* 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,
* are permitted provided that the following conditions are met:
......@@ -239,7 +239,7 @@ BOOL VnodeInUseIter(const struct Mount *mount)
return FALSE;
}
int VnodeHold()
int VnodeHold(void)
{
int ret = LOS_MuxLock(&g_vnodeMux, LOS_WAIT_FOREVER);
if (ret != LOS_OK) {
......@@ -248,7 +248,7 @@ int VnodeHold()
return ret;
}
int VnodeDrop()
int VnodeDrop(void)
{
int ret = LOS_MuxUnlock(&g_vnodeMux);
if (ret != LOS_OK) {
......@@ -583,7 +583,7 @@ int VnodeCreate(struct Vnode *parent, const char *name, int mode, struct Vnode *
return 0;
}
int VnodeDevInit()
int VnodeDevInit(void)
{
struct Vnode *devNode = NULL;
struct Mount *devMount = NULL;
......@@ -616,7 +616,7 @@ int VnodeGetattr(struct Vnode *vnode, struct stat *buf)
return LOS_OK;
}
struct Vnode *VnodeGetRoot()
struct Vnode *VnodeGetRoot(void)
{
return g_rootVnode;
}
......@@ -697,7 +697,7 @@ LIST_HEAD* GetVnodeActiveList()
return &g_vnodeActiveList;
}
int VnodeClearCache()
int VnodeClearCache(void)
{
struct Vnode *item = NULL;
struct Vnode *nextItem = NULL;
......
......@@ -50,8 +50,8 @@ extern "C" {
* Rwlock object.
*/
typedef struct OsRwlock {
INT32 magic:24; /**< Magic number */
INT32 rwCount:8; /**< Times of locking the rwlock, rwCount > 0 when rwkick is read mode, rwCount < 0
INT32 magic : 24; /**< Magic number */
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. */
VOID *writeOwner; /**< The current write thread that is locking the rwlock */
LOS_DL_LIST readList; /**< Read waiting list */
......
......@@ -58,7 +58,7 @@
#define ip_addr_set_val(dest, src) do { \
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)); \
} else { \
ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); \
......
......@@ -1076,7 +1076,7 @@ u32_t lwip_ifconfig(int argc, const char **argv)
ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
PRINTK("%s", ifconfig_cmd.cb_print_buf);
#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))) {
err = (err_t)sys_arch_sem_wait(&ip_conflict_detect, DUP_ARP_DETECT_TIME);
is_ip_conflict_signal = 0;
......@@ -1106,7 +1106,7 @@ u32_t lwip_ifconfig(int argc, const char **argv)
#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
#if LWIP_IPV6
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);
is_dup_detect_initialized = 0;
sys_sem_free(&dup_addr_detect);
......@@ -1191,7 +1191,6 @@ void lwip_arp_show_internal(struct netif *netif, char *printf_buf, unsigned int
|| (state == ETHARP_STATE_STATIC)
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
) && arp_table[i].netif) {
if (strcmp(netif_get_name(netif), netif_get_name(arp_table[i].netif)) != 0) {
continue;
}
......@@ -1305,7 +1304,7 @@ void lwip_arp_internal(void *arg)
for (netif = netif_list; netif != NULL; netif = netif->next) {
ret = etharp_delete_arp_entry(netif, &ipaddr);
if (ret == ERR_OK) {
/*only can del success one time*/
/* only can del success one time */
break;
}
}
......@@ -1387,7 +1386,7 @@ u32_t lwip_arp(int argc, const char **argv)
goto arp_error;
}
i += 2;
argc -= 2;
argc -= 2; // 2: number of used parameters
} else if (strcmp("-d", argv[i]) == 0 && (argc > 1)) {
/* arp delete */
arp_cmd.option = ARP_OPTION_DEL;
......@@ -1399,8 +1398,8 @@ u32_t lwip_arp(int argc, const char **argv)
}
i += 2;
argc -= 2;
} else if (strcmp("-s", argv[i]) == 0 && (argc > 2)) {
argc -= 2; // 2: number of used parameters
} else if (strcmp("-s", argv[i]) == 0 && (argc > 2)) { // 2: require more than 2 parameters
/* arp add */
char *digit = NULL;
u32_t macaddrlen = strlen(argv[i + 2]) + 1;
......@@ -1418,7 +1417,7 @@ u32_t lwip_arp(int argc, const char **argv)
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) {
PRINTK("IP address is not correct!\n");
goto arp_error;
......@@ -1452,7 +1451,7 @@ u32_t lwip_arp(int argc, const char **argv)
}
i += 3;
argc -= 3;
argc -= 3; // 3: number of used parameters
} else {
goto arp_error;
}
......@@ -1727,7 +1726,7 @@ LWIP_STATIC int osPingFunc(u32_t destip, u32_t cnt, u32_t interval, u32_t data_l
break;
}
intrvl -= 1000;
sys_msleep(1000);
sys_msleep(1000); // 1000: delay 1 s
if (ping_kill == 1)
break;
} while (intrvl > 0);
......@@ -1819,7 +1818,7 @@ u32_t osShellPing(int argc, const char **argv)
count = ret;
count_set = 1;
i += 2;
argc -= 2;
argc -= 2; // 2: nuber of arguments that has been checked
} else if (strcmp("-t", argv[i]) == 0) {
count = 0; /* ping forerver */
count_set = 1;
......@@ -1834,7 +1833,7 @@ u32_t osShellPing(int argc, const char **argv)
interval = ret;
i += 2;
argc -= 2;
argc -= 2; // 2:number of arguments that has been checked
} else if (strcmp("-l", argv[i]) == 0 && (argc > 1)) {
ret = atoi(argv[i + 1]);
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)
}
data_len = ret;
i += 2;
argc -= 2;
argc -= 2; // 2: number of elements has been checked
} else if (strcmp("-k", argv[i]) == 0) {
if (ping_taskid > 0) {
ping_kill = 1; /* stop the current ping task */
......@@ -1896,7 +1895,7 @@ u32_t osShellPing(int argc, const char **argv)
stPingTask.auwArgs[0] = dst_ipaddr.addr; /* network order */
stPingTask.auwArgs[1] = count;
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);
if (ret != LOS_OK) {
PRINTK("ping_task create failed 0x%08x.\n", ret);
......@@ -1923,7 +1922,7 @@ ping_error:
SHELLCMD_ENTRY(ping_shellcmd, CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)osShellPing);
#endif /* LOSCFG_SHELL */
#else /* LWIP_EXT_POLL_SUPPORT*/
#else /* LWIP_EXT_POLL_SUPPORT */
u32_t osShellPing(int argc, const char **argv)
{
......@@ -2076,7 +2075,7 @@ FAILURE:
SHELLCMD_ENTRY(ping_shellcmd, CMD_TYPE_EX, "ping", XARGS, (CmdCallBackFunc)osShellPing);
#endif /* LOSCFG_SHELL */
#endif /* LWIP_EXT_POLL_SUPPORT*/
#endif /* LWIP_EXT_POLL_SUPPORT */
#if LWIP_IPV6
u32_t osShellPing6(int argc, const char **argv)
......@@ -2311,6 +2310,7 @@ REDUCE_SELECT_TIME:
PRINTK("--- %s ping statistics ---\n", argv[ping6_params.host_index]);
PRINTK("%d packets transmitted, %d received, %.2f%% packet loss, time %dms\n",
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));
if (nrecieve) {
/* Display rtt stats only if at least one packet is received */
......@@ -2629,7 +2629,7 @@ usage:
SHELLCMD_ENTRY(ntpdate_shellcmd, CMD_TYPE_EX, "ntpdate", XARGS, (CmdCallBackFunc)osShellNtpdate);
#endif /* LOSCFG_SHELL_CMD_DEBUG */
#endif /* LWIP_SNTP*/
#endif /* LWIP_SNTP */
#if LWIP_DNS
u32_t osShellDns(int argc, const char **argv)
......@@ -2866,7 +2866,7 @@ int netstat_tcp_recvq(struct tcp_pcb *tpcb)
case NETCONN_UDP_IPV6:
#endif
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;
default:
retVal = 0; /* ur... very ugly, damn DHCP DNS and SNTP */
......@@ -2992,7 +2992,7 @@ int netstat_netconn_recvq(const struct netconn *conn)
case NETCONN_PKT_RAW:
#endif
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;
default:
retVal = 0; /* ur... very ugly, damn DHCP DNS and SNTP */
......@@ -3271,10 +3271,10 @@ void netstat_internal(void *ctx)
recvQlen = netstat_netconn_recvq(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,
"%-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)) {
goto out;
}
......@@ -3297,7 +3297,8 @@ void netstat_internal(void *ctx)
sendQlen = netstat_netconn_sendq(rpcb->recv_arg);
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));
break;
}
......@@ -3307,7 +3308,7 @@ void netstat_internal(void *ctx)
(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,
"%-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
#endif /* LOSCFG_SHELL_CMD_DEBUG */
#endif
#endif //LWIP_ENABLE_LOS_SHELL_CMD
#endif // LWIP_ENABLE_LOS_SHELL_CMD
......@@ -412,7 +412,7 @@ int ip6addr_aton(const char *cp, ip6_addr_t *addr)
int squash_pos = ipv6_blocks;
int i;
const char *s = cp;
const char *ss = cp-1;
const char *ss = cp - 1;
for (; ; s++) {
if (current_block_index >= ipv6_blocks) {
......
......@@ -803,12 +803,10 @@ static u8_t lwip_ioctl_internal_SIOCSIFHWADDR(struct ifreq *ifr)
}
#endif
else {
/* bring netif down to clear all Neighbor Cache Entry */
(void)netif_set_down(netif);
ret = netif_set_hwaddr(netif, (const unsigned char *)ifr->ifr_hwaddr.sa_data, netif->hwaddr_len);
if (ret != ERR_OK) {
(void)netif_set_up(netif);
return err_to_errno(ret);
......@@ -979,7 +977,6 @@ static u8_t lwip_ioctl_internal_SIOCGIFFLAGS(struct ifreq *ifr)
#endif /* LWIP_IGMP || LWIP_IPV6_MLD */
#if LWIP_DHCP
//if ((netif->flags & NETIF_FLAG_DHCP) != 0) {
if (dhcp_supplied_address(netif)) {
ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags | IFF_DYNAMIC);
} else {
......@@ -1090,7 +1087,6 @@ static u8_t lwip_ioctl_internal_SIOCSIFNAME(struct ifreq *ifr)
#endif
netif = netif_find(ifr->ifr_name);
if (netif == NULL) {
return ENODEV;
} else if (netif->link_layer_type == LOOPBACK_IF) {
......@@ -1165,7 +1161,6 @@ static u8_t lwip_ioctl_internal_SIOCGIFMTU(struct ifreq *ifr)
/* get netif hw addr */
netif = netif_find(ifr->ifr_name);
if (netif == NULL) {
return ENODEV;
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册