mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-19 12:58:55 +00:00
128 lines
2.3 KiB
C
128 lines
2.3 KiB
C
|
|
/*
|
||
|
|
* Copyright (c) 2023, ArtInChip Technology Co., Ltd
|
||
|
|
*
|
||
|
|
* SPDX-License-Identifier: Apache-2.0
|
||
|
|
*
|
||
|
|
* matteo <duanmt@artinchip.com>
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
#include <console.h>
|
||
|
|
#include <aic_core.h>
|
||
|
|
#include <aic_common.h>
|
||
|
|
#include <aic_errno.h>
|
||
|
|
|
||
|
|
#include <dfs_bare.h>
|
||
|
|
#include <dfs.h>
|
||
|
|
#include <dfs_file.h>
|
||
|
|
|
||
|
|
static int cmd_ls(int argc, char **argv)
|
||
|
|
{
|
||
|
|
extern void ls(const char *pathname);
|
||
|
|
|
||
|
|
if (argc == 1)
|
||
|
|
{
|
||
|
|
#ifdef DFS_USING_WORKDIR
|
||
|
|
ls(working_directory);
|
||
|
|
#else
|
||
|
|
ls("/");
|
||
|
|
#endif
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ls(argv[1]);
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
CONSOLE_CMD(ls, cmd_ls, "List information about the FILEs.");
|
||
|
|
|
||
|
|
static int cmd_cp(int argc, char **argv)
|
||
|
|
{
|
||
|
|
void copy(const char *src, const char *dst);
|
||
|
|
|
||
|
|
if (argc != 3)
|
||
|
|
{
|
||
|
|
rt_kprintf("Usage: cp SOURCE DEST\n");
|
||
|
|
rt_kprintf("Copy SOURCE to DEST.\n");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
copy(argv[1], argv[2]);
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
CONSOLE_CMD(cp, cmd_cp, "Copy SOURCE to DEST.");
|
||
|
|
|
||
|
|
static int cmd_mkdir(int argc, char **argv)
|
||
|
|
{
|
||
|
|
if (argc == 1)
|
||
|
|
{
|
||
|
|
rt_kprintf("Usage: mkdir [OPTION] DIRECTORY\n");
|
||
|
|
rt_kprintf("Create the DIRECTORY, if they do not already exist.\n");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
mkdir(argv[1], 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
CONSOLE_CMD(mkdir, cmd_mkdir, "Create the DIRECTORY.");
|
||
|
|
|
||
|
|
static int cmd_echo(int argc, char **argv)
|
||
|
|
{
|
||
|
|
if (argc == 2)
|
||
|
|
{
|
||
|
|
rt_kprintf("%s\n", argv[1]);
|
||
|
|
}
|
||
|
|
else if (argc == 3)
|
||
|
|
{
|
||
|
|
int fd;
|
||
|
|
|
||
|
|
fd = open(argv[2], O_RDWR | O_APPEND | O_CREAT, 0);
|
||
|
|
if (fd >= 0)
|
||
|
|
{
|
||
|
|
write(fd, argv[1], strlen(argv[1]));
|
||
|
|
close(fd);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
rt_kprintf("open file:%s failed!\n", argv[2]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
rt_kprintf("Usage: echo \"string\" / + [filename]\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
CONSOLE_CMD(echo, cmd_echo, "echo string to file");
|
||
|
|
|
||
|
|
static int cmd_cat(int argc, char **argv)
|
||
|
|
{
|
||
|
|
int index;
|
||
|
|
extern void cat(const char *filename);
|
||
|
|
|
||
|
|
if (argc == 1)
|
||
|
|
{
|
||
|
|
rt_kprintf("Usage: cat / + [FILE]...\n");
|
||
|
|
rt_kprintf("Concatenate FILE(s)\n");
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (index = 1; index < argc; index ++)
|
||
|
|
{
|
||
|
|
cat(argv[index]);
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
CONSOLE_CMD(cat, cmd_cat, "Concatenate FILE(s)");
|