文件系统支持完善

This commit is contained in:
zhangzheng
2023-12-02 23:15:33 +08:00
parent 2d68c1b480
commit 50e54e7662
15 changed files with 212 additions and 45 deletions

View File

@@ -10,10 +10,25 @@
*/
#include "shell.h"
#include "shell_ext.h"
#include "shell_fs.h"
#include "shell_passthrough.h"
#include "shell_secure_user.h"
#include "log.h"
// #include "telnetd.h"
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <stddef.h>
#include <string.h>
#include <sys/time.h>
#include <pthread.h>
#include "cons_cli.h"
#include "u_sleep.h"
Shell shell;
char shellBuffer[512];
static Shell shell;
static ShellFs shellFs;
static char shellBuffer[256];
static char shellPathBuffer[128] = "/mnt/";
/**
* @brief 用户shell写
@@ -43,16 +58,53 @@ signed short userShellRead(char *data, unsigned short len)
u_sleep_ms(5);
}
}
/**
* @brief 列出文件
*
* @param path 路径
* @param buffer 结果缓冲
* @param maxLen 最大缓冲长度
* @return size_t 0
*/
size_t userShellListDir(char *path, char *buffer, size_t maxLen)
{
DIR *dir;
struct dirent *ptr;
int i;
if (!path)
{
return 0;
}
dir = opendir(path);
if (!dir)
{
return 0;
}
memset(buffer, 0, maxLen);
while ((ptr = readdir(dir)) != NULL)
{
strcat(buffer, ptr->d_name);
strcat(buffer, "\t");
}
closedir(dir);
return 0;
}
/**
* @brief 用户shell初始化
*
*/
void userShellInit(void)
{
shellFs.getcwd = getcwd;
shellFs.chdir = chdir;
shellFs.listdir = userShellListDir;
shellFsInit(&shellFs, shellPathBuffer, sizeof(shellPathBuffer));
shell.write = userShellWrite;
shell.read = userShellRead;
shellInit(&shell, shellBuffer, 512);
shellSetPath(&shell, shellPathBuffer);
shellInit(&shell, shellBuffer, sizeof(shellBuffer));
shellCompanionAdd(&shell, SHELL_COMPANION_ID_FS, &shellFs);
while (1)
{