From 8381112442c165b29ef9bcb5f88c3d0c761e2373 Mon Sep 17 00:00:00 2001 From: Frapples Date: Wed, 21 Dec 2016 23:12:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E4=BA=86=E6=96=B9=E4=BE=BF=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=EF=BC=8C=E5=AE=9E=E7=8E=B0=E5=87=A0=E4=B8=AA=E5=B0=8F?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell_command.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/shell_command.c b/shell_command.c index 14a6693..ba918b8 100644 --- a/shell_command.c +++ b/shell_command.c @@ -10,22 +10,61 @@ int cmd_pwd(int argc, char* argv[]) int cmd_cd(int argc, char* argv[]) { - printf("%d\n", argc); + if (argc <= 0) { + printf("命令有误\n"); + return -1; + } - for (int i = 0; i < argc; i++) { - printf("[%s]\n", argv[i]); + if (fs_chdir(argv[0]) == FS_SUCCESS) { + return 0; + } else { + printf("改变失败,可能目录不存在\n"); + return -1; } - return 0; + } int cmd_ls(int argc, char* argv[]) { + const char* path; + char wd[FS_MAX_FILE_PATH]; + if (argc <= 0) { + fs_getcwd(wd, FS_MAX_FILE_PATH); + path = wd; + } else { + path = argv[0]; + } + + FS_DIR* dir = fs_opendir(path); + if (dir == NULL) { + printf("列出目录信息失败\n"); + } + + char name[32]; + do { + fs_readdir(dir, name); + printf("%s ", name); + } while(name[0] != '\0'); + printf("\n"); + + fs_closedir(dir); + return 0; } int cmd_mkdir(int argc, char* argv[]) { - return 0; + if (argc <= 0) { + printf("命令有误\n"); + return -1; + } + + if (fs_mkdir(argv[0]) == FS_SUCCESS) { + return 0; + } else { + printf("建立失败\n"); + return -1; + } } int cmd_rmdir(int argc, char* argv[])