add mkdir
This commit is contained in:
		| @@ -39,11 +39,11 @@ | ||||
| //--------------------------------------------------------------------+ | ||||
|  | ||||
| //------------- embedded-cli -------------// | ||||
| #define CLI_BUFFER_SIZE     256 | ||||
| #define CLI_BUFFER_SIZE     512 | ||||
| #define CLI_RX_BUFFER_SIZE  16 | ||||
| #define CLI_CMD_BUFFER_SIZE 32 | ||||
| #define CLI_HISTORY_SIZE    32 | ||||
| #define CLI_BINDING_COUNT   3 | ||||
| #define CLI_BINDING_COUNT   8 | ||||
|  | ||||
| static EmbeddedCli *_cli; | ||||
| static CLI_UINT cli_buffer[BYTES_TO_CLI_UINTS(CLI_BUFFER_SIZE)]; | ||||
| @@ -58,9 +58,10 @@ static scsi_inquiry_resp_t inquiry_resp; | ||||
| // | ||||
| //--------------------------------------------------------------------+ | ||||
|  | ||||
| void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context); | ||||
| void cli_cmd_cd(EmbeddedCli *cli, char *args, void *context); | ||||
| void cli_cmd_cat(EmbeddedCli *cli, char *args, void *context); | ||||
| void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context); | ||||
| void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context); | ||||
|  | ||||
| void cli_write_char(EmbeddedCli *cli, char c) | ||||
| { | ||||
| @@ -89,6 +90,8 @@ bool msc_app_init(void) | ||||
|   config->historyBufferSize = CLI_HISTORY_SIZE; | ||||
|   config->maxBindingCount   = CLI_BINDING_COUNT; | ||||
|  | ||||
|   TU_ASSERT(embeddedCliRequiredSize(config) <= CLI_BUFFER_SIZE); | ||||
|  | ||||
|   _cli = embeddedCliNew(config); | ||||
|   TU_ASSERT(_cli != NULL); | ||||
|  | ||||
| @@ -118,6 +121,13 @@ bool msc_app_init(void) | ||||
|     cli_cmd_ls | ||||
|   }); | ||||
|  | ||||
|   embeddedCliAddBinding(_cli, (CliCommandBinding) { | ||||
|     "mkdir", | ||||
|     "Usage: mkdir [DIR]...\r\n\tCreate the DIRECTORY(ies), if they do not already exist..", | ||||
|     true, | ||||
|     NULL, | ||||
|     cli_cmd_mkdir | ||||
|   }); | ||||
|  | ||||
|   return true; | ||||
| } | ||||
| @@ -320,72 +330,6 @@ DRESULT disk_ioctl ( | ||||
| // CLI Commands | ||||
| //--------------------------------------------------------------------+ | ||||
|  | ||||
| void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context) | ||||
| { | ||||
|   (void) cli; (void) context; | ||||
|  | ||||
|   uint16_t argc = embeddedCliGetTokenCount(args); | ||||
|  | ||||
|   // only support 1 argument | ||||
|   if ( argc > 1 ) | ||||
|   { | ||||
|     printf("invalid arguments\r\n"); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   // default is current directory | ||||
|   const char* dpath = "."; | ||||
|   if (argc) dpath = args; | ||||
|  | ||||
|   DIR dir; | ||||
|   if ( FR_OK != f_opendir(&dir, dpath) ) | ||||
|   { | ||||
|     printf("cannot access '%s': No such file or directory\r\n", dpath); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   FILINFO fno; | ||||
|   while( (f_readdir(&dir, &fno) == FR_OK) && (fno.fname[0] != 0) ) | ||||
|   { | ||||
|     if ( fno.fname[0] != '.' ) // ignore . and .. entry | ||||
|     { | ||||
|       if ( fno.fattrib & AM_DIR ) | ||||
|       { | ||||
|         // directory | ||||
|         printf("/%s\r\n", fno.fname); | ||||
|       }else | ||||
|       { | ||||
|         printf("%-40s%lu KB\r\n", fno.fname, fno.fsize / 1000); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   f_closedir(&dir); | ||||
| } | ||||
|  | ||||
| void cli_cmd_cd(EmbeddedCli *cli, char *args, void *context) | ||||
| { | ||||
|   (void) cli; (void) context; | ||||
|  | ||||
|   uint16_t argc = embeddedCliGetTokenCount(args); | ||||
|  | ||||
|   // only support 1 argument | ||||
|   if ( argc != 1 ) | ||||
|   { | ||||
|     printf("invalid arguments\r\n"); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   // default is current directory | ||||
|   const char* dpath = args; | ||||
|  | ||||
|   if ( FR_OK != f_chdir(dpath) ) | ||||
|   { | ||||
|     printf("%s: No such file or directory\r\n", dpath); | ||||
|     return; | ||||
|   } | ||||
| } | ||||
|  | ||||
| void cli_cmd_cat(EmbeddedCli *cli, char *args, void *context) | ||||
| { | ||||
|   (void) cli; (void) context; | ||||
| @@ -430,3 +374,92 @@ void cli_cmd_cat(EmbeddedCli *cli, char *args, void *context) | ||||
|     f_close(&fi); | ||||
|   } | ||||
| } | ||||
|  | ||||
| void cli_cmd_cd(EmbeddedCli *cli, char *args, void *context) | ||||
| { | ||||
|   (void) cli; (void) context; | ||||
|  | ||||
|   uint16_t argc = embeddedCliGetTokenCount(args); | ||||
|  | ||||
|   // only support 1 argument | ||||
|   if ( argc != 1 ) | ||||
|   { | ||||
|     printf("invalid arguments\r\n"); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   // default is current directory | ||||
|   const char* dpath = args; | ||||
|  | ||||
|   if ( FR_OK != f_chdir(dpath) ) | ||||
|   { | ||||
|     printf("%s: No such file or directory\r\n", dpath); | ||||
|     return; | ||||
|   } | ||||
| } | ||||
|  | ||||
| void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context) | ||||
| { | ||||
|   (void) cli; (void) context; | ||||
|  | ||||
|   uint16_t argc = embeddedCliGetTokenCount(args); | ||||
|  | ||||
|   // only support 1 argument | ||||
|   if ( argc > 1 ) | ||||
|   { | ||||
|     printf("invalid arguments\r\n"); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   // default is current directory | ||||
|   const char* dpath = "."; | ||||
|   if (argc) dpath = args; | ||||
|  | ||||
|   DIR dir; | ||||
|   if ( FR_OK != f_opendir(&dir, dpath) ) | ||||
|   { | ||||
|     printf("cannot access '%s': No such file or directory\r\n", dpath); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   FILINFO fno; | ||||
|   while( (f_readdir(&dir, &fno) == FR_OK) && (fno.fname[0] != 0) ) | ||||
|   { | ||||
|     if ( fno.fname[0] != '.' ) // ignore . and .. entry | ||||
|     { | ||||
|       if ( fno.fattrib & AM_DIR ) | ||||
|       { | ||||
|         // directory | ||||
|         printf("/%s\r\n", fno.fname); | ||||
|       }else | ||||
|       { | ||||
|         printf("%-40s%lu KB\r\n", fno.fname, fno.fsize / 1000); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   f_closedir(&dir); | ||||
| } | ||||
|  | ||||
| void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context) | ||||
| { | ||||
|   (void) cli; (void) context; | ||||
|  | ||||
|   uint16_t argc = embeddedCliGetTokenCount(args); | ||||
|  | ||||
|   // only support 1 argument | ||||
|   if ( argc != 1 ) | ||||
|   { | ||||
|     printf("invalid arguments\r\n"); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   // default is current directory | ||||
|   const char* dpath = args; | ||||
|  | ||||
|   if ( FR_OK != f_mkdir(dpath) ) | ||||
|   { | ||||
|     printf("%s: cannot create this directory\r\n", dpath); | ||||
|     return; | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach