9 #include "fstk_malloc.h"
13 #include <readline/readline.h>
14 #include <readline/history.h>
20 static inline void fstk_shell_help(void)
22 printf("fs --open a new file sytem\n"
23 "help --print this information\n"
24 "print [fs] --print the current fs information\n"
25 "quit, q --quit the program\n"
26 "cat [file]... --show the file content\n"
27 "check_fat --check the vfat FAT table\n"
28 "ls [file|dir]... --list the file or diectory\n"
29 "dir [file|dir}... --the same with 'ls'\n"
30 "block [file|dir]. --show the file block address\n"
31 "sector [file|dir] --show the file sector address\n"
32 "stat [file|dir].. --show the detail information\n");
35 static int parse_shell(char *shell
, char *argv
[])
44 while((p
= strchr(shell
, ' '))) {
58 static inline int is_cmd(char *cmd
, char *input
)
60 return !strcmp(cmd
, input
);
66 int fstk_shell(const char *prompt
, struct fstk
*fs
)
69 char **argv
= malloc(MAX_ARGC
* sizeof(char *));
75 printf("\tfstk shell, V%s (Copyright) Liu Aleaxander\n"
76 "\ttype 'quit' or 'q' to quit, 'help' for more information\n",
80 line
= readline(prompt
);
86 argc
= parse_shell(line
, argv
);
91 } else if (is_cmd(cmd
, "quit") || is_cmd(cmd
, "q")) {
94 } else if (is_cmd(cmd
, "print")) {
95 if (is_cmd(argv
[1], "fs"))
96 fs
->ops
->print_fs_info(fs
);
97 } else if (is_cmd(cmd
, "help")) {
99 } else if (is_cmd(cmd
, "fs")) {
102 } else if (is_cmd(cmd
, "cat")) {
104 fstk_cat(fs
, argc
, argv
);
106 printf("USAGE: cat file\n");
107 } else if (is_cmd(cmd
, "ls")) {
108 fstk_ls(fs
, argc
, argv
);
109 } else if (is_cmd(cmd
, "cd")) {
110 fstk_cd(fs
, argv
[1]);
111 } else if (is_cmd(cmd
, "check_fat")) {
113 } else if (is_cmd(cmd
, "block")) {
115 fstk_block(fs
, argc
, argv
);
117 printf("USAGE: block file | dir\n");
118 } else if (is_cmd(cmd
, "sector")) {
120 fstk_sector(fs
, argc
, argv
);
122 printf("USAGE: sector file | dir\n");
123 } else if (is_cmd(cmd
, "stat")) {
125 fstk_stat(fs
, argc
, argv
);
127 printf("USAGE: stat file | dir\n");
129 printf("Unknow command! type 'help' for more info.\n");