Files
mkrtos-real/mkrtos_user/lib/letter-shell/demo/mkrtos/shell_fs_ext.c

83 lines
1.6 KiB
C
Raw Normal View History

2023-12-03 17:54:26 +08:00
#include "shell.h"
2023-12-03 22:47:29 +08:00
#include "cons_cli.h"
2023-12-10 10:20:05 +08:00
#include "pm_cli.h"
#include <stdlib.h>
2023-12-03 17:54:26 +08:00
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <stddef.h>
#include <string.h>
#include <sys/time.h>
#include <pthread.h>
#include <errno.h>
2023-12-03 17:54:26 +08:00
int ls(int argc, char *agrv[])
{
DIR *dir;
struct dirent *ptr;
int i;
if (argc < 2)
{
return -1;
}
dir = opendir(agrv[1]);
if (!dir)
{
return 0;
}
while ((ptr = readdir(dir)) != NULL)
{
printf("%s \n", ptr->d_name);
}
closedir(dir);
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), ls, ls, ls command);
2023-12-03 22:47:29 +08:00
int cat(int argc, char *argv[])
{
if (argc != 2)
{
return (-1);
}
FILE *fp;
int c;
if ((fp = fopen(argv[1], "r")) == NULL)
{
return errno;
2023-12-03 22:47:29 +08:00
}
while ((c = fgetc(fp)) != EOF)
{
cons_write(&c, 1);
}
fclose(fp);
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), cat, cat, cat command);
2023-12-10 10:20:05 +08:00
int kill(int argc, char *argv[])
{
if (argc < 2)
{
return -1;
}
int pid = atoi(argv[1]);
2023-12-10 23:51:39 +08:00
return pm_kill_task(pid, PM_KILL_TASK_ALL);
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), kill, kill, kill command);
int shell_symlink(int argc, char *argv[])
{
if (argc < 3)
{
return -1;
}
printf("%s %s %s\n", __func__, argv[1], argv[2]);
return symlink(argv[1], argv[2]);
2023-12-10 10:20:05 +08:00
}
2023-12-10 23:51:39 +08:00
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), symlink, shell_symlink, symlink command);