From 991c25dd5d4a0edde574865215d0742e1e5b1cdd Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Sat, 30 Jan 2021 16:31:03 +0800 Subject: [finsh] add mount/umount cmd --- components/finsh/msh_file.c | 106 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 13 deletions(-) (limited to 'components') diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c index 1368838b94..aa182ff9b3 100644 --- a/components/finsh/msh_file.c +++ b/components/finsh/msh_file.c @@ -101,7 +101,7 @@ int msh_exec_script(const char *cmd_line, int size) int length; line_buf = (char *) rt_malloc(RT_CONSOLEBUF_SIZE); - if (line_buf == RT_NULL) + if (line_buf == RT_NULL) { close(fd); return -RT_ENOMEM; @@ -295,7 +295,7 @@ static void directory_delete_for_msh(const char *pathname, char f, char v) if (dirent == RT_NULL) break; if (rt_strcmp(".", dirent->d_name) != 0 && - rt_strcmp("..", dirent->d_name) != 0) + rt_strcmp("..", dirent->d_name) != 0) { rt_sprintf(full_path, "%s/%s", pathname, dirent->d_name); if (dirent->d_type == DT_REG) @@ -347,13 +347,20 @@ int cmd_rm(int argc, char **argv) { switch (argv[1][n]) { - case 'f': f = 1; break; - case 'r': r = 1; break; - case 'v': v = 1; break; - case '-': break; - default: - rt_kprintf("Error: Bad option: %c\n", argv[1][n]); - return 0; + case 'f': + f = 1; + break; + case 'r': + r = 1; + break; + case 'v': + v = 1; + break; + case '-': + break; + default: + rt_kprintf("Error: Bad option: %c\n", argv[1][n]); + return 0; } } argc -= 1; @@ -363,7 +370,7 @@ int cmd_rm(int argc, char **argv) for (index = 1; index < argc; index ++) { struct stat s; - if (stat (argv[index], &s) == 0) + if (stat(argv[index], &s) == 0) { if (s.st_mode & S_IFDIR) { @@ -469,8 +476,81 @@ int cmd_mkfs(int argc, char **argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkfs, __cmd_mkfs, format disk with file system); +extern struct dfs_filesystem filesystem_table[]; +int cmd_mount(int argc, char *argv[]) +{ + if (argc == 1) + { + struct dfs_filesystem *iter; + + /* display the mount history */ + rt_kprintf("filesystem device mountpoint\n"); + rt_kprintf("---------- ------ ----------\n"); + for (iter = &filesystem_table[0]; + iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++) + { + if ((iter != NULL) && (iter->path != NULL)) + { + rt_kprintf("%-10s %-6s %-s\n", + iter->ops->name, iter->dev_id->parent.name, iter->path); + } + } + return 0; + } + else if (argc == 4) + { + char *device = argv[1]; + char *path = argv[2]; + char *fstype = argv[3]; + + /* mount a filesystem to the specified directory */ + rt_kprintf("mount device %s(%s) onto %s ... ", device, fstype, path); + if (dfs_mount(device, path, fstype, 0, 0) == 0) + { + rt_kprintf("succeed!\n"); + return 0; + } + else + { + rt_kprintf("failed!\n"); + return -1; + } + } + else + { + rt_kprintf("Usage: mount .\n"); + return -1; + } +} +FINSH_FUNCTION_EXPORT_ALIAS(cmd_mount, __cmd_mount, mount ); + +/* unmount the filesystem from the specified mountpoint */ +int cmd_umount(int argc, char *argv[]) +{ + char *path = argv[1]; + + if (argc != 2) + { + rt_kprintf("Usage: unmount .\n"); + return -1; + } + + rt_kprintf("unmount %s ... ", path); + if (dfs_unmount(path) < 0) + { + rt_kprintf("failed!\n"); + return -1; + } + else + { + rt_kprintf("succeed!\n"); + return 0; + } +} +FINSH_FUNCTION_EXPORT_ALIAS(cmd_umount, __cmd_umount, Unmount device from file system); + extern int df(const char *path); -int cmd_df(int argc, char** argv) +int cmd_df(int argc, char **argv) { if (argc != 2) { @@ -492,7 +572,7 @@ int cmd_df(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_df, __cmd_df, disk free); -int cmd_echo(int argc, char** argv) +int cmd_echo(int argc, char **argv) { if (argc == 2) { @@ -505,7 +585,7 @@ int cmd_echo(int argc, char** argv) fd = open(argv[2], O_RDWR | O_APPEND | O_CREAT, 0); if (fd >= 0) { - write (fd, argv[1], strlen(argv[1])); + write(fd, argv[1], strlen(argv[1])); close(fd); } else -- cgit v1.3.1 From 32533127584b6bf98754591a168b5f2962d02ee1 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 5 Mar 2021 23:09:00 +0800 Subject: remove difftime() --- components/libc/compilers/common/time.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index c2fbd6f333..cc135bcfc9 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -12,7 +12,6 @@ * 2021-02-08 Meco Man add settimeofday() stime() * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() * 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes - * add difftime() * 2021-02-12 Meco Man add errno * 2012-12-08 Bernard fix the issue of _timevalue.tv_usec initialization, * which found by Rob @@ -177,12 +176,6 @@ char* ctime(const time_t *tim_p) } RTM_EXPORT(ctime); -double difftime (time_t tim1, time_t tim2) -{ - return (double)(tim1 - tim2); -} -RTM_EXPORT(difftime); - /** * Returns the current time. * @@ -372,6 +365,9 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) } RTM_EXPORT(settimeofday); +RTM_EXPORT(difftime); /* inherent in libc */ +RTM_EXPORT(strftime); /* inherent in libc*/ + #ifdef RT_USING_POSIX static struct timeval _timevalue; static int clock_time_system_init() -- cgit v1.3.1 From ff9210a84d39be7a6860d3fbf89a0a8837a9aba0 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 5 Mar 2021 23:13:57 +0800 Subject: revise comment --- components/libc/compilers/common/time.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index cc135bcfc9..ed72cc1f3f 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -365,8 +365,9 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) } RTM_EXPORT(settimeofday); -RTM_EXPORT(difftime); /* inherent in libc */ -RTM_EXPORT(strftime); /* inherent in libc*/ +/* inherent in the toolchain */ +RTM_EXPORT(difftime); +RTM_EXPORT(strftime); #ifdef RT_USING_POSIX static struct timeval _timevalue; -- cgit v1.3.1