未验证 提交 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,8 +244,9 @@ 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>
* @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,
* 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,11 +257,10 @@ 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;
}
}
#else
if ((directory == NULL) && (filename[0] != '/')) {
PRINT_ERR("NO_WORKING_DIR\n");
......@@ -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)) {
#ifdef VFS_USING_WORKDIR
if (dir_flags == TRUE)
{
if (dir_flags == TRUE) {
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
}
}
#endif
return -ENAMETOOLONG;
}
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
if (fullpath == NULL) {
return -get_errno();
......@@ -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;
......
......@@ -132,19 +132,19 @@ int VfsPermissionCheck(uint fuid, uint fgid, uint fileMode, int accMode)
#ifdef VFS_USING_WORKDIR
static int SetWorkDir(const char *dir, size_t len)
{
errno_t ret;
uint lock_flags;
LosProcessCB *curr = OsCurrProcessGet();
spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
ret = strncpy_s(curr->files->workdir, PATH_MAX, dir, len);
curr->files->workdir[PATH_MAX - 1] = '\0';
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
if (ret != EOK) {
return -1;
}
return 0;
errno_t ret;
uint lock_flags;
LosProcessCB *curr = OsCurrProcessGet();
spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
ret = strncpy_s(curr->files->workdir, PATH_MAX, dir, len);
curr->files->workdir[PATH_MAX - 1] = '\0';
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
if (ret != EOK) {
return -1;
}
return 0;
}
#endif
......@@ -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,124 +53,113 @@
#include <ctype.h>
#include "fs/fs_operation.h"
typedef enum
{
RM_RECURSIVER,
RM_FILE,
RM_DIR,
CP_FILE,
CP_COUNT
typedef enum {
RM_RECURSIVER,
RM_FILE,
RM_DIR,
CP_FILE,
CP_COUNT
} wildcard_type;
#define ERROR_OUT_IF(condition, message_function, handler) \
do \
{ \
if (condition) \
{ \
message_function; \
handler; \
do { \
if (condition) { \
message_function; \
handler; \
} \
} \
while (0)
} while (0)
static inline void set_err(int errcode, const char *err_message)
{
set_errno(errcode);
perror(err_message);
set_errno(errcode);
perror(err_message);
}
int osShellCmdDoChdir(const char *path)
{
char *fullpath = NULL;
char *fullpath_bak = NULL;
int ret;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
char *fullpath = NULL;
char *fullpath_bak = NULL;
int ret;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
return -1;
}
if (path == NULL)
{
LOS_TaskLock();
PRINTK("%s\n", shell_working_directory);
LOS_TaskUnlock();
if (path == NULL) {
LOS_TaskLock();
PRINTK("%s\n", shell_working_directory);
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);
ERROR_OUT_IF(ret < 0, set_err(-ret, "cd error"), return -1);
ret = vfs_normalize_path(shell_working_directory, path, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "cd error"), return -1);
fullpath_bak = fullpath;
ret = chdir(fullpath);
if (ret < 0)
{
free(fullpath_bak);
perror("cd");
return -1;
fullpath_bak = fullpath;
ret = chdir(fullpath);
if (ret < 0) {
free(fullpath_bak);
perror("cd");
return -1;
}
/* copy full path to working directory */
/* copy full path to working directory */
LOS_TaskLock();
ret = strncpy_s(shell_working_directory, PATH_MAX, fullpath, strlen(fullpath));
if (ret != EOK)
{
free(fullpath_bak);
LOS_TaskUnlock();
return -1;
LOS_TaskLock();
ret = strncpy_s(shell_working_directory, PATH_MAX, fullpath, strlen(fullpath));
if (ret != EOK) {
free(fullpath_bak);
LOS_TaskUnlock();
return -1;
}
LOS_TaskUnlock();
/* release normalize directory path name */
LOS_TaskUnlock();
/* release normalize directory path name */
free(fullpath_bak);
free(fullpath_bak);
return 0;
return 0;
}
int osShellCmdLs(int argc, const char **argv)
{
char *fullpath = NULL;
const char *filename = NULL;
int ret;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
char *fullpath = NULL;
const char *filename = NULL;
int ret;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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)
{
ls(shell_working_directory);
return 0;
if (argc == 0) {
ls(shell_working_directory);
return 0;
}
filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "ls error"), return -1);
filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "ls error"), return -1);
ls(fullpath);
free(fullpath);
ls(fullpath);
free(fullpath);
return 0;
return 0;
}
int osShellCmdCd(int argc, const char **argv)
{
if (argc == 0)
{
(void)osShellCmdDoChdir("/");
return 0;
if (argc == 0) {
(void)osShellCmdDoChdir("/");
return 0;
}
(void)osShellCmdDoChdir(argv[0]);
(void)osShellCmdDoChdir(argv[0]);
return 0;
return 0;
}
#define CAT_BUF_SIZE 512
......@@ -180,116 +169,104 @@ pthread_mutex_t g_mutex_cat = PTHREAD_MUTEX_INITIALIZER;
int osShellCmdDoCatShow(UINTPTR arg)
{
int ret = 0;
char buf[CAT_BUF_SIZE];
size_t size, written, toWrite;
ssize_t cnt;
char *fullpath = (char *)arg;
FILE *ini = NULL;
(void)pthread_mutex_lock(&g_mutex_cat);
ini = fopen(fullpath, "r");
if (ini == NULL)
{
ret = -1;
perror("cat error");
goto out;
int ret = 0;
char buf[CAT_BUF_SIZE];
size_t size, written, toWrite;
ssize_t cnt;
char *fullpath = (char *)arg;
FILE *ini = NULL;
(void)pthread_mutex_lock(&g_mutex_cat);
ini = fopen(fullpath, "r");
if (ini == NULL) {
ret = -1;
perror("cat error");
goto out;
}
do
{
(void)memset_s(buf, sizeof(buf), 0, CAT_BUF_SIZE);
size = fread(buf, 1, CAT_BUF_SIZE, ini);
if ((int)size < 0)
{
ret = -1;
perror("cat error");
goto out_with_fclose;
do {
(void)memset_s(buf, sizeof(buf), 0, CAT_BUF_SIZE);
size = fread(buf, 1, CAT_BUF_SIZE, ini);
if ((int)size < 0) {
ret = -1;
perror("cat error");
goto out_with_fclose;
}
for (toWrite = size, written = 0; toWrite > 0;)
{
cnt = write(1, buf + written, toWrite);
if (cnt == 0)
{
/* avoid task-starvation */
(void)LOS_TaskDelay(1);
continue;
}
else if (cnt < 0)
{
perror("cat write error");
break;
for (toWrite = size, written = 0; toWrite > 0;) {
cnt = write(1, buf + written, toWrite);
if (cnt == 0) {
/* avoid task-starvation */
(void)LOS_TaskDelay(1);
continue;
} else if (cnt < 0) {
perror("cat write error");
break;
}
written += cnt;
toWrite -= cnt;
written += cnt;
toWrite -= cnt;
}
}
while (size > 0);
while (size > 0);
out_with_fclose:
(void)fclose(ini);
(void)fclose(ini);
out:
free(fullpath);
(void)pthread_mutex_unlock(&g_mutex_cat);
return ret;
free(fullpath);
(void)pthread_mutex_unlock(&g_mutex_cat);
return ret;
}
int osShellCmdCat(int argc, const char **argv)
{
char *fullpath = NULL;
int ret;
unsigned int ca_task;
struct Vnode *vnode = NULL;
TSK_INIT_PARAM_S init_param;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
char *fullpath = NULL;
int ret;
unsigned int ca_task;
struct Vnode *vnode = NULL;
TSK_INIT_PARAM_S init_param;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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);
ERROR_OUT_IF(ret < 0, set_err(-ret, "cat error"), return -1);
ret = vfs_normalize_path(shell_working_directory, argv[0], &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "cat error"), return -1);
VnodeHold();
ret = VnodeLookup(fullpath, &vnode, O_RDONLY);
if (ret != LOS_OK)
{
VnodeHold();
ret = VnodeLookup(fullpath, &vnode, O_RDONLY);
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();
free(fullpath);
return -1;
}
VnodeDrop();
(void)memset_s(&init_param, sizeof(init_param), 0, sizeof(TSK_INIT_PARAM_S));
init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)osShellCmdDoCatShow;
init_param.usTaskPrio = CAT_TASK_PRIORITY;
init_param.auwArgs[0] = (UINTPTR)fullpath;
init_param.uwStackSize = CAT_TASK_STACK_SIZE;
init_param.pcName = "shellcmd_cat";
init_param.uwResved = LOS_TASK_STATUS_DETACHED | OS_TASK_FLAG_SPECIFIES_PROCESS;
init_param.processID = 2; /* 2: kProcess */
ret = (int)LOS_TaskCreate(&ca_task, &init_param);
if (ret != LOS_OK)
{
free(fullpath);
}
VnodeDrop();
(void)memset_s(&init_param, sizeof(init_param), 0, sizeof(TSK_INIT_PARAM_S));
init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)osShellCmdDoCatShow;
init_param.usTaskPrio = CAT_TASK_PRIORITY;
init_param.auwArgs[0] = (UINTPTR)fullpath;
init_param.uwStackSize = CAT_TASK_STACK_SIZE;
init_param.pcName = "shellcmd_cat";
init_param.uwResved = LOS_TASK_STATUS_DETACHED | OS_TASK_FLAG_SPECIFIES_PROCESS;
init_param.processID = 2; /* 2: kProcess */
ret = (int)LOS_TaskCreate(&ca_task, &init_param);
if (ret != LOS_OK) {
free(fullpath);
}
return ret;
return ret;
}
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)
char *p;
while ((options != NULL) && (p = strsep((char**)&options, ",")) != NULL) {
if (strncmp(p, "ro", strlen("ro")) == 0) {
mountfalgs |= MS_RDONLY;
mountfalgs |= MS_RDONLY;
} else if (strncmp(p, "rw", strlen("rw")) == 0) {
mountfalgs &= ~MS_RDONLY;
} else if (strncmp(p, "nosuid", strlen("nosuid")) == 0) {
......@@ -317,329 +294,288 @@ static unsigned long get_mountflags(const char *options)
}
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 ret;
char *fullpath = NULL;
const char *filename = NULL;
unsigned int gid, uid;
char *data = NULL;
char *filessystemtype = NULL;
unsigned long mountfalgs;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
int ret;
char *fullpath = NULL;
const char *filename = NULL;
unsigned int gid, uid;
char *data = NULL;
char *filessystemtype = NULL;
unsigned long mountfalgs;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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)
{
PRINTK("mount -t/-o [DEVICE] [PATH] [NAME]\n");
return -1;
if (argc < 4) { // 4: required number of parameters
PRINTK("mount -t/-o [DEVICE] [PATH] [NAME]\n");
return -1;
}
filename = argv[2];
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)
{
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 (ret != LOS_OK)
{
PRINTK("mount -t [DEVICE] [PATH] [NAME]\n");
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) { // 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) {
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
{
PRINTK("can't find nfs_mount\n");
}
free(fullpath);
return 0;
free(fullpath);
return 0;
}
}
filessystemtype = (argc >= 4) ? (char *)argv[3] : NULL; /* 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 */
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)
{
ret = mount((const char *)NULL, fullpath, filessystemtype, mountfalgs, data);
}
else
{
ret = mount(argv[1], fullpath, filessystemtype, mountfalgs, data); /* 3: fs type */
}
if (ret != LOS_OK)
{
perror("mount error");
if (strcmp(argv[1], "0") == 0) {
ret = mount((const char *)NULL, fullpath, filessystemtype, mountfalgs, data);
} else {
ret = mount(argv[1], fullpath, filessystemtype, mountfalgs, data); /* 3: fs type */
}
else
{
PRINTK("mount ok\n");
if (ret != LOS_OK) {
perror("mount error");
} else {
PRINTK("mount ok\n");
}
}
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)
{
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)
{
ret = nfs_mount_ref(argv[0], fullpath, uid, gid);
if (ret != LOS_OK)
{
PRINTK("mount [DEVICE] [PATH] [NAME]\n");
} 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) { // 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) {
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
{
PRINTK("can't find nfs_mount\n");
}
free(fullpath);
return 0;
free(fullpath);
return 0;
}
print_mount_usage();
free(fullpath);
return 0;
print_mount_usage();
free(fullpath);
return 0;
}
mountfalgs = (argc >= 4) ? get_mountflags((const char *)argv[3]) : 0; /* 3: usr option */
data = (argc >= 5) ? (char *)argv[4] : NULL; /* 4: usr option data */
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)
{
ret = mount((const char *)NULL, fullpath, argv[2], mountfalgs, data);
}
else
{
ret = mount(argv[0], fullpath, argv[2], mountfalgs, data); /* 2: fs type */
}
if (ret != LOS_OK)
{
perror("mount error");
if (strcmp(argv[0], "0") == 0) {
ret = mount((const char *)NULL, fullpath, argv[2], mountfalgs, data);
} else {
ret = mount(argv[0], fullpath, argv[2], mountfalgs, data); /* 2: fs type */
}
else
{
PRINTK("mount ok\n");
if (ret != LOS_OK) {
perror("mount error");
} else {
PRINTK("mount ok\n");
}
}
free(fullpath);
return 0;
free(fullpath);
return 0;
}
int osShellCmdUmount(int argc, const char **argv)
{
int ret;
const char *filename = NULL;
char *fullpath = NULL;
char *target_path = NULL;
int cmp_num;
char *work_path = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
int ret;
const char *filename = NULL;
char *fullpath = NULL;
char *target_path = NULL;
int cmp_num;
char *work_path = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "umount error"), return -1);
filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "umount error"), return -1);
target_path = fullpath;
cmp_num = strlen(fullpath);
ret = strncmp(work_path, target_path, cmp_num);
if (ret == 0)
{
work_path += cmp_num;
if (*work_path == '/' || *work_path == '\0')
{
set_errno(EBUSY);
perror("umount error");
free(fullpath);
return -1;
target_path = fullpath;
cmp_num = strlen(fullpath);
ret = strncmp(work_path, target_path, cmp_num);
if (ret == 0) {
work_path += cmp_num;
if (*work_path == '/' || *work_path == '\0') {
set_errno(EBUSY);
perror("umount error");
free(fullpath);
return -1;
}
}
ret = umount(fullpath);
free(fullpath);
if (ret != LOS_OK)
{
perror("umount error");
return 0;
ret = umount(fullpath);
free(fullpath);
if (ret != LOS_OK) {
perror("umount error");
return 0;
}
PRINTK("umount ok\n");
return 0;
PRINTK("umount ok\n");
return 0;
}
int osShellCmdMkdir(int argc, const char **argv)
{
int ret;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
int ret;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "mkdir error"), return -1);
filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "mkdir error"), return -1);
ret = mkdir(fullpath, S_IRWXU | S_IRWXG | S_IRWXO);
if (ret == -1)
{
perror("mkdir error");
ret = mkdir(fullpath, S_IRWXU | S_IRWXG | S_IRWXO);
if (ret == -1) {
perror("mkdir error");
}
free(fullpath);
return 0;
free(fullpath);
return 0;
}
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)
{
return -1;
char buf[SHOW_MAX_LEN] = {0};
DIR *dir = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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);
if (dir == NULL)
{
perror("pwd error");
return -1;
dir = opendir(shell_working_directory);
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)
{
LOS_TaskUnlock();
PRINTK("pwd error: strncpy_s error!\n");
(void)closedir(dir);
return -1;
LOS_TaskLock();
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);
return -1;
}
LOS_TaskUnlock();
LOS_TaskUnlock();
PRINTK("%s\n", buf);
(void)closedir(dir);
return 0;
PRINTK("%s\n", buf);
(void)closedir(dir);
return 0;
}
static inline void print_statfs_usage(void)
{
PRINTK("Usage :\n");
PRINTK(" statfs <path>\n");
PRINTK(" path : Mounted file system path that requires query information\n");
PRINTK("Example:\n");
PRINTK(" statfs /ramfs\n");
PRINTK("Usage :\n");
PRINTK(" statfs <path>\n");
PRINTK(" path : Mounted file system path that requires query information\n");
PRINTK("Example:\n");
PRINTK(" statfs /ramfs\n");
}
int osShellCmdStatfs(int argc, const char **argv)
{
struct statfs sfs;
int result;
unsigned long long total_size, free_size;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
struct statfs sfs;
int result;
unsigned long long total_size, free_size;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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];
result = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(result < 0, set_err(-result, "statfs error"), return -1);
filename = argv[0];
result = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(result < 0, set_err(-result, "statfs error"), return -1);
result = statfs(fullpath, &sfs);
free(fullpath);
result = statfs(fullpath, &sfs);
free(fullpath);
if (result != 0 || sfs.f_type == 0)
{
PRINTK("statfs failed! Invalid argument!\n");
print_statfs_usage();
return -1;
if (result != 0 || sfs.f_type == 0) {
PRINTK("statfs failed! Invalid argument!\n");
print_statfs_usage();
return -1;
}
total_size = (unsigned long long)sfs.f_bsize * sfs.f_blocks;
free_size = (unsigned long long)sfs.f_bsize * sfs.f_bfree;
total_size = (unsigned long long)sfs.f_bsize * sfs.f_blocks;
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(" 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("\n%s\n total size: %4llu Bytes\n free size: %4llu Bytes\n", argv[0], total_size, free_size);
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(" 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);
return 0;
return 0;
}
int osShellCmdTouch(int argc, const char **argv)
{
int ret;
int fd = -1;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
int ret;
int fd = -1;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "touch error"), return -1);
filename = argv[0];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
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);
free(fullpath);
if (fd == -1)
{
perror("touch error");
return -1;
fd = open(fullpath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
free(fullpath);
if (fd == -1) {
perror("touch error");
return -1;
}
(void)close(fd);
return 0;
(void)close(fd);
return 0;
}
#define CP_BUF_SIZE 4096
......@@ -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)
{
int ret;
char *src_fullpath = NULL;
char *dst_fullpath = NULL;
const char *src_filename = NULL;
char *dst_filepath = NULL;
char *buf = NULL;
const char *filename = NULL;
ssize_t r_size, w_size;
int src_fd = -1;
int dst_fd = -1;
struct stat stat_buf;
mode_t src_mode;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
int ret;
char *src_fullpath = NULL;
char *dst_fullpath = NULL;
const char *src_filename = NULL;
char *dst_filepath = NULL;
char *buf = NULL;
const char *filename = NULL;
ssize_t r_size, w_size;
int src_fd = -1;
int dst_fd = -1;
struct stat stat_buf;
mode_t src_mode;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
return -1;
}
buf = (char *)malloc(CP_BUF_SIZE);
if (buf == NULL)
{
PRINTK("cp error: Out of memory!\n");
return -1;
buf = (char *)malloc(CP_BUF_SIZE);
if (buf == NULL) {
PRINTK("cp error: Out of memory!\n");
return -1;
}
/* Get source fullpath. */
/* Get source fullpath. */
ret = vfs_normalize_path(shell_working_directory, src_filepath, &src_fullpath);
if (ret < 0)
{
set_errno(-ret);
PRINTK("cp error: %s\n", strerror(errno));
free(buf);
return -1;
ret = vfs_normalize_path(shell_working_directory, src_filepath, &src_fullpath);
if (ret < 0) {
set_errno(-ret);
PRINTK("cp error: %s\n", strerror(errno));
free(buf);
return -1;
}
/* Is source path exist? */
/* Is source path exist? */
ret = stat(src_fullpath, &stat_buf);
if (ret == -1)
{
PRINTK("cp %s error: %s\n", src_fullpath, strerror(errno));
goto errout_with_srcpath;
ret = stat(src_fullpath, &stat_buf);
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? */
src_mode = stat_buf.st_mode;
/* Is source path a directory? */
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;
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;
}
/* Get dest fullpath. */
/* Get dest fullpath. */
dst_fullpath = strdup(dst_filename);
if (dst_fullpath == NULL)
{
PRINTK("cp error: Out of memory.\n");
goto errout_with_srcpath;
dst_fullpath = strdup(dst_filename);
if (dst_fullpath == NULL) {
PRINTK("cp error: Out of memory.\n");
goto errout_with_srcpath;
}
/* Is dest path exist? */
/* Is dest path exist? */
ret = stat(dst_fullpath, &stat_buf);
if (ret == 0)
{
/* Is dest path a directory? */
if (S_ISDIR(stat_buf.st_mode))
{
/* Get source file name without '/'. */
src_filename = src_filepath;
while (1)
{
filename = strchr(src_filename, '/');
if (filename == NULL)
{
break;
ret = stat(dst_fullpath, &stat_buf);
if (ret == 0) {
/* Is dest path a directory? */
if (S_ISDIR(stat_buf.st_mode)) {
/* Get source file name without '/'. */
src_filename = src_filepath;
while (1) {
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);
if (ret < 0)
{
set_errno(-ret);
PRINTK("cp error. %s.\n", strerror(errno));
goto errout_with_path;
ret = vfs_normalize_path(dst_fullpath, src_filename, &dst_filepath);
if (ret < 0) {
set_errno(-ret);
PRINTK("cp error. %s.\n", strerror(errno));
goto errout_with_path;
}
free(dst_fullpath);
dst_fullpath = dst_filepath;
free(dst_fullpath);
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)
{
PRINTK("cp error: '%s' and '%s' are the same file\n", src_fullpath, dst_fullpath);
goto errout_with_path;
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;
}
/* Copy begins. */
/* Copy begins. */
(void)pthread_mutex_lock(&g_mutex_cp);
src_fd = open(src_fullpath, O_RDONLY);
if (src_fd < 0)
{
PRINTK("cp error: can't open %s. %s.\n", src_fullpath, strerror(errno));
goto errout_with_mutex;
(void)pthread_mutex_lock(&g_mutex_cp);
src_fd = open(src_fullpath, O_RDONLY);
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)
{
PRINTK("cp error: can't create %s. %s.\n", dst_fullpath, strerror(errno));
goto errout_with_srcfd;
dst_fd = open(dst_fullpath, O_CREAT | O_WRONLY | O_TRUNC, src_mode);
if (dst_fd < 0) {
PRINTK("cp error: can't create %s. %s.\n", dst_fullpath, strerror(errno));
goto errout_with_srcfd;
}
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)
{
PRINTK("cp %s %s failed. %s.\n", src_fullpath, dst_fullpath, strerror(errno));
goto errout_with_fd;
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) {
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)
{
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) {
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. */
/* Release resource. */
free(buf);
free(src_fullpath);
free(dst_fullpath);
(void)close(src_fd);
(void)close(dst_fd);
(void)pthread_mutex_unlock(&g_mutex_cp);
return LOS_OK;
free(buf);
free(src_fullpath);
free(dst_fullpath);
(void)close(src_fd);
(void)close(dst_fd);
(void)pthread_mutex_unlock(&g_mutex_cp);
return LOS_OK;
errout_with_fd:
(void)close(dst_fd);
(void)close(dst_fd);
errout_with_srcfd:
(void)close(src_fd);
(void)close(src_fd);
errout_with_mutex:
(void)pthread_mutex_unlock(&g_mutex_cp);
(void)pthread_mutex_unlock(&g_mutex_cp);
errout_with_path:
free(dst_fullpath);
free(dst_fullpath);
errout_with_srcpath:
free(src_fullpath);
free(buf);
return -1;
free(src_fullpath);
free(buf);
return -1;
}
/* The separator and EOF for a directory fullpath: '/'and '\0' */
......@@ -818,751 +736,639 @@ errout_with_srcpath:
static int os_shell_cmd_do_rmdir(const char *pathname)
{
struct dirent *dirent = NULL;
struct stat stat_info;
DIR *d = NULL;
char *fullpath = NULL;
int ret;
(void)memset_s(&stat_info, sizeof(stat_info), 0, sizeof(struct stat));
if (stat(pathname, &stat_info) != 0)
{
return -1;
struct dirent *dirent = NULL;
struct stat stat_info;
DIR *d = NULL;
char *fullpath = NULL;
int ret;
(void)memset_s(&stat_info, sizeof(stat_info), 0, sizeof(struct stat));
if (stat(pathname, &stat_info) != 0) {
return -1;
}
if (S_ISREG(stat_info.st_mode) || S_ISLNK(stat_info.st_mode))
{
return remove(pathname);
if (S_ISREG(stat_info.st_mode) || S_ISLNK(stat_info.st_mode)) {
return remove(pathname);
}
d = opendir(pathname);
if (d == NULL)
{
return -1;
d = opendir(pathname);
if (d == NULL) {
return -1;
}
while (1)
{
dirent = readdir(d);
if (dirent == NULL)
{
break;
while (1) {
dirent = readdir(d);
if (dirent == NULL) {
break;
}
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)
{
PRINTK("buffer size is invalid!\n");
(void)closedir(d);
return -1;
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) {
PRINTK("buffer size is invalid!\n");
(void)closedir(d);
return -1;
}
fullpath = (char *)malloc(fullpath_buf_size);
if (fullpath == NULL)
{
PRINTK("malloc failure!\n");
(void)closedir(d);
return -1;
fullpath = (char *)malloc(fullpath_buf_size);
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)
{
PRINTK("name is too long!\n");
free(fullpath);
(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) {
PRINTK("name is too long!\n");
free(fullpath);
(void)closedir(d);
return -1;
}
(void)os_shell_cmd_do_rmdir(fullpath);
free(fullpath);
(void)os_shell_cmd_do_rmdir(fullpath);
free(fullpath);
}
}
(void)closedir(d);
return rmdir(pathname);
(void)closedir(d);
return rmdir(pathname);
}
/* Wildcard matching operations */
static int os_wildcard_match(const char *src, const char *filename)
{
int ret;
int ret;
if (*src != '\0')
{
if (*filename == '*')
{
while ((*filename == '*') || (*filename == '?'))
{
filename++;
if (*src != '\0') {
if (*filename == '*') {
while ((*filename == '*') || (*filename == '?')) {
filename++;
}
if (*filename == '\0')
{
return 0;
if (*filename == '\0') {
return 0;
}
while (*src != '\0' && !(*src == *filename))
{
src++;
while (*src != '\0' && !(*src == *filename)) {
src++;
}
if (*src == '\0')
{
return -1;
if (*src == '\0') {
return -1;
}
ret = os_wildcard_match(src, filename);
ret = os_wildcard_match(src, filename);
while ((ret != 0) && (*(++src) != '\0'))
{
if (*src == *filename)
{
ret = os_wildcard_match(src, filename);
while ((ret != 0) && (*(++src) != '\0')) {
if (*src == *filename) {
ret = os_wildcard_match(src, filename);
}
}
return ret;
}
else
{
if ((*src == *filename) || (*filename == '?'))
{
return os_wildcard_match(++src, ++filename);
return ret;
} else {
if ((*src == *filename) || (*filename == '?')) {
return os_wildcard_match(++src, ++filename);
}
return -1;
return -1;
}
}
while (*filename != '\0')
{
if (*filename != '*')
{
return -1;
while (*filename != '\0') {
if (*filename != '*') {
return -1;
}
filename++;
filename++;
}
return 0;
return 0;
}
/* To determine whether a wildcard character exists in a path */
static int os_is_containers_wildcard(const char *filename)
{
while (*filename != '\0')
{
if ((*filename == '*') || (*filename == '?'))
{
return 1;
while (*filename != '\0') {
if ((*filename == '*') || (*filename == '?')) {
return 1;
}
filename++;
filename++;
}
return 0;
return 0;
}
/* Delete a matching file or directory */
static int os_wildcard_delete_file_or_dir(const char *fullpath, wildcard_type mark)
{
int ret;
switch (mark)
{
case RM_RECURSIVER:
ret = os_shell_cmd_do_rmdir(fullpath);
break;
case RM_FILE:
ret = unlink(fullpath);
break;
case RM_DIR:
ret = rmdir(fullpath);
break;
default:
return VFS_ERROR;
}
if (ret == -1)
{
PRINTK("%s ", fullpath);
perror("rm/rmdir error!");
return ret;
}
PRINTK("%s match successful!delete!\n", fullpath);
return 0;
int ret;
switch (mark) {
case RM_RECURSIVER:
ret = os_shell_cmd_do_rmdir(fullpath);
break;
case RM_FILE:
ret = unlink(fullpath);
break;
case RM_DIR:
ret = rmdir(fullpath);
break;
default:
return VFS_ERROR;
}
if (ret == -1) {
PRINTK("%s ", fullpath);
perror("rm/rmdir error!");
return ret;
}
PRINTK("%s match successful!delete!\n", fullpath);
return 0;
}
/* Split the path with wildcard characters */
static char* os_wildcard_split_path(char *fullpath, char **handle, char **wait)
{
int n = 0;
int a = 0;
int b = 0;
int len = strlen(fullpath);
for (n = 0; n < len; n++)
{
if (fullpath[n] == '/')
{
if (b != 0)
{
fullpath[n] = '\0';
*wait = fullpath + n + 1;
break;
int n = 0;
int a = 0;
int b = 0;
int len = strlen(fullpath);
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] == '?')
{
b = n;
fullpath[a] = '\0';
if (a == 0)
{
*handle = fullpath + a + 1;
continue;
a = n;
} else if (fullpath[n] == '*' || fullpath[n] == '?') {
b = n;
fullpath[a] = '\0';
if (a == 0) {
*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 */
static int os_wildcard_extract_directory(char *fullpath, void *dst, wildcard_type mark)
{
char separator[] = "/";
char src[PATH_MAX] = {0};
struct dirent *dirent = NULL;
char *f = NULL;
char *s = NULL;
char *t = NULL;
int ret = 0;
DIR *d = NULL;
struct stat stat_buf;
int deleteFlag = 0;
f = os_wildcard_split_path(fullpath, &s, &t);
if (s == NULL)
{
if (mark == CP_FILE)
{
ret = os_shell_cmd_do_cp(fullpath, dst);
}
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)))
{
(*(int *)dst)++;
char separator[] = "/";
char src[PATH_MAX] = {0};
struct dirent *dirent = NULL;
char *f = NULL;
char *s = NULL;
char *t = NULL;
int ret = 0;
DIR *d = NULL;
struct stat stat_buf;
int deleteFlag = 0;
f = os_wildcard_split_path(fullpath, &s, &t);
if (s == NULL) {
if (mark == CP_FILE) {
ret = os_shell_cmd_do_cp(fullpath, dst);
} 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))) {
(*(int *)dst)++;
}
} else {
ret = os_wildcard_delete_file_or_dir(fullpath, mark);
}
else
{
ret = os_wildcard_delete_file_or_dir(fullpath, mark);
}
return ret;
return ret;
}
d = (*f == '\0') ? opendir("/") : opendir(f);
if (d == NULL)
{
perror("opendir error");
return VFS_ERROR;
d = (*f == '\0') ? opendir("/") : opendir(f);
if (d == NULL) {
perror("opendir error");
return VFS_ERROR;
}
while (1)
{
dirent = readdir(d);
if (dirent == NULL)
{
break;
while (1) {
dirent = readdir(d);
if (dirent == NULL) {
break;
}
ret = strcpy_s(src, PATH_MAX, f);
if (ret != EOK)
{
goto closedir_out;
ret = strcpy_s(src, PATH_MAX, f);
if (ret != EOK) {
goto closedir_out;
}
ret = os_wildcard_match(dirent->d_name, s);
if (ret == 0)
{
ret = strcat_s(src, sizeof(src), separator);
if (ret != EOK)
{
goto closedir_out;
ret = os_wildcard_match(dirent->d_name, s);
if (ret == 0) {
ret = strcat_s(src, sizeof(src), separator);
if (ret != EOK) {
goto closedir_out;
}
ret = strcat_s(src, sizeof(src), dirent->d_name);
if (ret != EOK)
{
goto closedir_out;
ret = strcat_s(src, sizeof(src), dirent->d_name);
if (ret != EOK) {
goto closedir_out;
}
if (t == NULL)
{
if (mark == CP_FILE)
{
ret = os_shell_cmd_do_cp(src, dst);
}
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)))
{
(*(int *)dst)++;
if ((*(int *)dst) > 1)
{
break;
if (t == NULL) {
if (mark == CP_FILE) {
ret = os_shell_cmd_do_cp(src, dst);
} 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))) {
(*(int *)dst)++;
if ((*(int *)dst) > 1) {
break;
}
}
}
else
{
ret = os_wildcard_delete_file_or_dir(src, mark);
if (ret == 0)
{
deleteFlag = 1;
} else {
ret = os_wildcard_delete_file_or_dir(src, mark);
if (ret == 0) {
deleteFlag = 1;
}
}
}
else
{
ret = strcat_s(src, sizeof(src), separator);
if (ret != EOK)
{
goto closedir_out;
} else {
ret = strcat_s(src, sizeof(src), separator);
if (ret != EOK) {
goto closedir_out;
}
ret = strcat_s(src, sizeof(src), t);
if (ret != EOK)
{
goto closedir_out;
ret = strcat_s(src, sizeof(src), t);
if (ret != EOK) {
goto closedir_out;
}
ret = os_wildcard_extract_directory(src, dst, mark);
if (mark == CP_COUNT && (*(int *)dst) > 1)
{
break;
ret = os_wildcard_extract_directory(src, dst, mark);
if (mark == CP_COUNT && (*(int *)dst) > 1) {
break;
}
}
}
}
(void)closedir(d);
if (deleteFlag == 1)
{
ret = 0;
(void)closedir(d);
if (deleteFlag == 1) {
ret = 0;
}
return ret;
return ret;
closedir_out:
(void)closedir(d);
return VFS_ERROR;
(void)closedir(d);
return VFS_ERROR;
}
int osShellCmdCp(int argc, const char **argv)
{
int ret;
const char *src = NULL;
const char *dst = NULL;
char *src_fullpath = NULL;
char *dst_fullpath = NULL;
struct stat stat_buf;
int count = 0;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
int ret;
const char *src = NULL;
const char *dst = NULL;
char *src_fullpath = NULL;
char *dst_fullpath = NULL;
struct stat stat_buf;
int count = 0;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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];
dst = argv[1];
src = argv[0];
dst = argv[1];
/* Get source fullpath. */
/* Get source fullpath. */
ret = vfs_normalize_path(shell_working_directory, src, &src_fullpath);
if (ret < 0)
{
set_errno(-ret);
PRINTK("cp error:%s\n", strerror(errno));
return -1;
ret = vfs_normalize_path(shell_working_directory, src, &src_fullpath);
if (ret < 0) {
set_errno(-ret);
PRINTK("cp error:%s\n", strerror(errno));
return -1;
}
if (src[strlen(src) - 1] == '/')
{
PRINTK("cp %s error: Source file can't be a directory.\n", src);
goto errout_with_srcpath;
if (src[strlen(src) - 1] == '/') {
PRINTK("cp %s error: Source file can't be a directory.\n", src);
goto errout_with_srcpath;
}
/* Get dest fullpath. */
/* Get dest fullpath. */
ret = vfs_normalize_path(shell_working_directory, dst, &dst_fullpath);
if (ret < 0)
{
set_errno(-ret);
PRINTK("cp error: can't open %s. %s\n", dst, strerror(errno));
goto errout_with_srcpath;
ret = vfs_normalize_path(shell_working_directory, dst, &dst_fullpath);
if (ret < 0) {
set_errno(-ret);
PRINTK("cp error: can't open %s. %s\n", dst, strerror(errno));
goto errout_with_srcpath;
}
/* Is dest path exist? */
/* Is dest path exist? */
ret = stat(dst_fullpath, &stat_buf);
if (ret < 0)
{
/* Is dest path a directory? */
ret = stat(dst_fullpath, &stat_buf);
if (ret < 0) {
/* Is dest path a directory? */
if (dst[strlen(dst) - 1] == '/')
{
PRINTK("cp error: %s, %s.\n", dst_fullpath, strerror(errno));
goto errout_with_path;
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] == '/')
{
PRINTK("cp error: %s is not a directory.\n", dst_fullpath);
goto errout_with_path;
} 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))
{
char *src_copy = strdup(src_fullpath);
if (src_copy == NULL)
{
PRINTK("cp error : Out of memory.\n");
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)) {
char *src_copy = strdup(src_fullpath);
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)
{
PRINTK("cp error : %s is not a directory.\n", dst_fullpath);
goto errout_with_path;
(void)os_wildcard_extract_directory(src_copy, &count, CP_COUNT);
free(src_copy);
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);
ret = os_wildcard_extract_directory(src_fullpath, dst_fullpath, CP_FILE);
} else {
ret = os_shell_cmd_do_cp(src_fullpath, dst_fullpath);
}
else
{
ret = os_shell_cmd_do_cp(src_fullpath, dst_fullpath);
}
free(dst_fullpath);
free(src_fullpath);
return ret;
free(dst_fullpath);
free(src_fullpath);
return ret;
errout_with_path:
free(dst_fullpath);
free(dst_fullpath);
errout_with_srcpath:
free(src_fullpath);
return VFS_ERROR;
free(src_fullpath);
return VFS_ERROR;
}
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 ret = 0;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
int ret = 0;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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)
{
ERROR_OUT_IF(strcmp(argv[0], "-r") != 0 && strcmp(argv[0], "-R") != 0, print_rm_usage(), return -1);
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);
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))
{
ret = os_wildcard_extract_directory(fullpath, NULL, RM_RECURSIVER);
}
else
{
ret = os_shell_cmd_do_rmdir(fullpath);
if (os_is_containers_wildcard(fullpath)) {
ret = os_wildcard_extract_directory(fullpath, NULL, RM_RECURSIVER);
} else {
ret = os_shell_cmd_do_rmdir(fullpath);
}
}
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);
} 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))
{
ret = os_wildcard_extract_directory(fullpath, NULL, RM_FILE);
}
else
{
ret = unlink(fullpath);
if (os_is_containers_wildcard(fullpath)) {
ret = os_wildcard_extract_directory(fullpath, NULL, RM_FILE);
} else {
ret = unlink(fullpath);
}
}
if (ret == -1)
{
perror("rm error");
if (ret == -1) {
perror("rm error");
}
free(fullpath);
return 0;
free(fullpath);
return 0;
}
int osShellCmdRmdir(int argc, const char **argv)
{
int ret;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
int ret;
char *fullpath = NULL;
const char *filename = NULL;
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
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];
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "rmdir error"), return -1);
filename = argv[0];
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))
{
ret = os_wildcard_extract_directory(fullpath, NULL, RM_DIR);
}
else
{
ret = rmdir(fullpath);
if (os_is_containers_wildcard(fullpath)) {
ret = os_wildcard_extract_directory(fullpath, NULL, RM_DIR);
} else {
ret = rmdir(fullpath);
}
if (ret == -1)
{
PRINTK("rmdir %s failed. Error: %s.\n", fullpath, strerror(errno));
if (ret == -1) {
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)
{
ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: sync\n"), return -1);
ERROR_OUT_IF(argc > 0, PRINTK("\nUsage: sync\n"), return -1);
sync();
return 0;
sync();
return 0;
}
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 i = 0;
if (arg == NULL)
{
return -1;
int i = 0;
if (arg == NULL) {
return -1;
}
if (arg[0] == '-')
{
/* exclude the '-' */
if (arg[0] == '-') {
/* exclude the '-' */
i = 1;
i = 1;
}
for (; arg[i] != 0; i++)
{
if (!isdigit(arg[i]))
{
return -1;
for (; arg[i] != 0; i++) {
if (!isdigit(arg[i])) {
return -1;
}
}
return 0;
return 0;
}
#ifdef LOSCFG_KERNEL_SYSCALL
int osShellCmdSu(int argc, const char **argv)
{
int su_uid;
int su_gid;
int su_uid;
int su_gid;
if (argc == 0)
{
/* for su root */
if (argc == 0) {
/* for su root */
su_uid = 0;
su_gid = 0;
}
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);
su_uid = 0;
su_gid = 0;
} 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);
su_uid = atoi(argv[0]);
su_gid = atoi(argv[1]);
su_uid = atoi(argv[0]);
su_gid = atoi(argv[1]);
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);
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);
}
SysSetUserID(su_uid);
SysSetGroupID(su_gid);
return 0;
SysSetUserID(su_uid);
SysSetGroupID(su_gid);
return 0;
}
#endif
int osShellCmdChmod(int argc, const char **argv)
{
int i = 0;
int mode = 0;
int ret;
char *fullpath = NULL;
const char *filename = NULL;
struct IATTR attr = {0};
char *shell_working_directory = NULL;
const char *p = NULL;
int i = 0;
int mode = 0;
int ret;
char *fullpath = NULL;
const char *filename = NULL;
struct IATTR attr = {0};
char *shell_working_directory = NULL;
const char *p = NULL;
#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];
while (p[i])
{
if ((p[i] <= '7') && (p[i] >= '0'))
{
mode = ((uint)mode << MODE_BIT) | (uint)(p[i] - '0');
}
else
{
PRINTK("check the input <MODE>\n");
return -1;
p = argv[0];
while (p[i]) {
if ((p[i] <= '7') && (p[i] >= '0')) {
mode = ((uint)mode << MODE_BIT) | (uint)(p[i] - '0');
} else {
PRINTK("check the input <MODE>\n");
return -1;
}
i++;
i++;
}
filename = argv[1];
filename = argv[1];
shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL)
{
return -1;
shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
return -1;
}
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "chmod error\n"), return -1);
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "chmod error\n"), return -1);
attr.attr_chg_mode = mode;
attr.attr_chg_valid = CHG_MODE; /* change mode */
ret = chattr(fullpath, &attr);
if (ret < 0)
{
free(fullpath);
PRINTK("chmod error! %s\n", strerror(errno));
return ret;
attr.attr_chg_mode = mode;
attr.attr_chg_valid = CHG_MODE; /* change mode */
ret = chattr(fullpath, &attr);
if (ret < 0) {
free(fullpath);
PRINTK("chmod error! %s\n", strerror(errno));
return ret;
}
free(fullpath);
return 0;
free(fullpath);
return 0;
}
int osShellCmdChown(int argc, const char **argv)
{
int ret;
char *fullpath = NULL;
const char *filename = NULL;
struct IATTR attr;
uid_t owner = -1;
gid_t group = -1;
attr.attr_chg_valid = 0;
ERROR_OUT_IF(((argc != 2) && (argc != 3)), PRINTK("Usage: chown [OWNER] [GROUP] FILE\n"), return -1);
if (argc == 2)
{
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)
{
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]);
group = atoi(argv[1]);
filename = argv[2];
}
if (group != -1)
{
attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID;
}
if (owner != -1)
{
attr.attr_chg_uid = owner;
attr.attr_chg_valid |= CHG_UID;
int ret;
char *fullpath = NULL;
const char *filename = NULL;
struct IATTR attr;
uid_t owner = -1;
gid_t group = -1;
attr.attr_chg_valid = 0;
ERROR_OUT_IF(((argc != 2) && (argc != 3)), PRINTK("Usage: chown [OWNER] [GROUP] FILE\n"), return -1);
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) { // 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]);
group = atoi(argv[1]);
filename = argv[2];
}
if (group != -1) {
attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID;
}
if (owner != -1) {
attr.attr_chg_uid = owner;
attr.attr_chg_valid |= CHG_UID;
}
char *shell_working_directory = OsShellGetWorkingDirectory();
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();
if (shell_working_directory == NULL)
{
return -1;
ret = chattr(fullpath, &attr);
if (ret < 0) {
free(fullpath);
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);
if (ret < 0)
{
free(fullpath);
PRINTK("chown error! %s\n", strerror(errno));
return ret;
}
free(fullpath);
return 0;
free(fullpath);
return 0;
}
int osShellCmdChgrp(int argc, const char **argv)
{
int ret;
char *fullpath = NULL;
const char *filename = NULL;
struct IATTR attr;
gid_t group;
attr.attr_chg_valid = 0;
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);
group = atoi(argv[0]);
filename = argv[1];
if (group != -1) {
attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID;
}
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
return -1;
}
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "chmod error"), return -1);
int ret;
char *fullpath = NULL;
const char *filename = NULL;
struct IATTR attr;
gid_t group;
attr.attr_chg_valid = 0;
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);
group = atoi(argv[0]);
filename = argv[1];
if (group != -1) {
attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID;
}
char *shell_working_directory = OsShellGetWorkingDirectory();
if (shell_working_directory == NULL) {
return -1;
}
ret = vfs_normalize_path(shell_working_directory, filename, &fullpath);
ERROR_OUT_IF(ret < 0, set_err(-ret, "chmod error"), return -1);
ret = chattr(fullpath, &attr);
if (ret < 0) {
free(fullpath);
PRINTK("chgrp error! %s\n", strerror(errno));
return ret;
}
ret = chattr(fullpath, &attr);
if (ret < 0) {
free(fullpath);
PRINTK("chgrp error! %s\n", strerror(errno));
return ret;
}
free(fullpath);
return 0;
free(fullpath);
return 0;
}
#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,
* 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)); \
......
......@@ -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 ",
netif->mib2_counters.ifinucastpkts + netif->mib2_counters.ifinnucastpkts);
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "errors:%u ", netif->mib2_counters.ifinerrors);
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
ret = snprintf_s(tmp, buf_len, (buf_len - 1), "dropped:%u ", netif->mib2_counters.ifindiscards);
if ((ret <= 0) || ((unsigned int)ret >= buf_len))
goto out;
goto out;
tmp += ret;
buf_len -= (unsigned int)ret;
......@@ -1031,12 +1031,12 @@ u32_t lwip_ifconfig(int argc, const char **argv)
#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
/* Create the semaphore for ip conflict detection. */
if (sys_sem_new(&ip_conflict_detect, 0) != ERR_OK) {
sys_sem_free(&ifconfig_cmd.cb_completed);
PRINTK("ifconfig: internal error\n");
return 1;
}
is_ip_conflict_signal = 1;
if (sys_sem_new(&ip_conflict_detect, 0) != ERR_OK) {
sys_sem_free(&ifconfig_cmd.cb_completed);
PRINTK("ifconfig: internal error\n");
return 1;
}
is_ip_conflict_signal = 1;
}
#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
......@@ -1057,8 +1057,8 @@ u32_t lwip_ifconfig(int argc, const char **argv)
sys_sem_free(&ifconfig_cmd.cb_completed);
#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
is_ip_conflict_signal = 0;
sys_sem_free(&ip_conflict_detect);
is_ip_conflict_signal = 0;
sys_sem_free(&ip_conflict_detect);
}
#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
......@@ -1076,37 +1076,37 @@ 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;
sys_sem_free(&ip_conflict_detect);
if (err < 0) {
/* The result neither conflict nor timeout. */
PRINT_ERR("ifconfig: internal error\n");
sys_sem_free(&ifconfig_cmd.cb_completed);
return 1;
} else if (err < DUP_ARP_DETECT_TIME) {
/* Duplicate use of new ip, restore it to the old one. */
PRINT_ERR("ifconfig: ip conflict!\n");
ip_addr_set_ip4_u32_val(ifconfig_cmd.ip_addr, old_ip4addr);
ret = tcpip_callback(lwip_ifconfig_internal, &ifconfig_cmd);
if (ret != ERR_OK) {
sys_sem_free(&ifconfig_cmd.cb_completed);
PRINTK("%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
return 1;
err = (err_t)sys_arch_sem_wait(&ip_conflict_detect, DUP_ARP_DETECT_TIME);
is_ip_conflict_signal = 0;
sys_sem_free(&ip_conflict_detect);
if (err < 0) {
/* The result neither conflict nor timeout. */
PRINT_ERR("ifconfig: internal error\n");
sys_sem_free(&ifconfig_cmd.cb_completed);
return 1;
} else if (err < DUP_ARP_DETECT_TIME) {
/* Duplicate use of new ip, restore it to the old one. */
PRINT_ERR("ifconfig: ip conflict!\n");
ip_addr_set_ip4_u32_val(ifconfig_cmd.ip_addr, old_ip4addr);
ret = tcpip_callback(lwip_ifconfig_internal, &ifconfig_cmd);
if (ret != ERR_OK) {
sys_sem_free(&ifconfig_cmd.cb_completed);
PRINTK("%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
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 */
#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 */
......@@ -2922,7 +2922,7 @@ int netstat_udp_sendq6(struct udp_pcb *upcb)
#else
ret = netstat_get_udp_sendQLen6(upcb, neighbor_cache[idx].q);
if (ret >= 0) {
retLen += ret;
retLen += ret;
}
#endif
return retLen;
......@@ -2966,10 +2966,10 @@ int netstat_udp_sendq(struct udp_pcb *upcb)
#else
ret = netstat_get_udp_sendQLen(upcb, arp_table[arpidx].q);
if (ret > 0) {
retLen += ret;
if (retLen <= 0) { // overflow, set rteLen = -1 to indicate
retLen = -1;
}
retLen += ret;
if (retLen <= 0) { // overflow, set rteLen = -1 to indicate
retLen = -1;
}
}
#endif
}
......@@ -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
......@@ -435,9 +435,9 @@ LWIP_STATIC void handle_discover(struct netif *netif, struct dhcps *dhcps,
}
#else
else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
("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));
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
("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));
}
#endif
......
......@@ -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) {
......
......@@ -98,10 +98,10 @@ driverif_output(struct netif *netif, struct pbuf *p)
#if PF_PKT_SUPPORT
if (all_pkt_raw_pcbs != NULL) {
p->flags = (u16_t)(p->flags & ~(PBUF_FLAG_LLMCAST | PBUF_FLAG_LLBCAST | PBUF_FLAG_HOST));
p->flags |= PBUF_FLAG_OUTGOING;
(void)raw_pkt_input(p, netif, NULL);
}
p->flags = (u16_t)(p->flags & ~(PBUF_FLAG_LLMCAST | PBUF_FLAG_LLBCAST | PBUF_FLAG_HOST));
p->flags |= PBUF_FLAG_OUTGOING;
(void)raw_pkt_input(p, netif, NULL);
}
#endif
#if ETH_PAD_SIZE
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册