Implement read_dir_entry () VFS op, CE add ls command
This commit is contained in:
49
ce/ce.c
49
ce/ce.c
@@ -108,13 +108,54 @@ static void cmd_cat (struct list_node_link* tokens) {
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_ls (struct list_node_link* tokens) {
|
||||
if (tokens == NULL) {
|
||||
printf ("ERROR no directory path provided\n");
|
||||
return;
|
||||
}
|
||||
|
||||
struct token* token = list_entry (tokens, struct token, tokens_link);
|
||||
struct desc desc;
|
||||
char volume[VOLUME_MAX];
|
||||
const char* path;
|
||||
int ret;
|
||||
struct dir_entry entry;
|
||||
|
||||
if (!path_parse (token->buffer, volume, &path)) {
|
||||
printf ("ERROR bad path '%s'\n", token->buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ret = volume_open (volume)) < 0) {
|
||||
printf ("ERROR could not open volume '%s': %s\n", volume, str_status[-ret]);
|
||||
return;
|
||||
}
|
||||
|
||||
describe (path, &desc);
|
||||
|
||||
if (desc.type != FS_DIR) {
|
||||
volume_close ();
|
||||
}
|
||||
|
||||
size_t entries = desc.size;
|
||||
for (size_t entry_num = 0; entry_num < entries; entry_num++) {
|
||||
read_dir_entry (path, &entry, entry_num);
|
||||
describe (entry.path, &desc);
|
||||
|
||||
printf ("%-40s%c %-40zu\n", entry.path, (desc.type == FS_DIR ? '*' : ' '), desc.size);
|
||||
}
|
||||
|
||||
volume_close ();
|
||||
}
|
||||
|
||||
static void cmd_help (struct list_node_link* tokens) {
|
||||
(void)tokens;
|
||||
|
||||
printf ("Available commands:\n");
|
||||
printf ("\techo <word1> <word2> <word3> ...\n");
|
||||
printf ("\thelp\n");
|
||||
printf ("\tcat <file path>\n");
|
||||
printf ("echo <word1> <word2> <word3> ...\n");
|
||||
printf ("help\n");
|
||||
printf ("cat <file path>\n");
|
||||
printf ("ls <directory path>\n");
|
||||
}
|
||||
|
||||
static void exec_tokens (struct list_node_link* tokens) {
|
||||
@@ -126,6 +167,8 @@ static void exec_tokens (struct list_node_link* tokens) {
|
||||
cmd_help (tokens->next);
|
||||
} else if (strcmp (cmd_token->buffer, "cat") == 0) {
|
||||
cmd_cat (tokens->next);
|
||||
} else if (strcmp (cmd_token->buffer, "ls") == 0) {
|
||||
cmd_ls (tokens->next);
|
||||
} else {
|
||||
printf ("ERROR: unknown command '%s'\n", cmd_token->buffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user