implement ls, rmdir and mkdir
This commit is contained in:
parent
de5c0d664d
commit
375104536e
@ -1451,4 +1451,5 @@ errors shelly SHELLY_ERR_ {
|
||||
failure WRITE "String write failed",
|
||||
failure SPAWN_RPC "Spawn RPC failed",
|
||||
failure PS_RPC "ps RPC failed",
|
||||
failure FILE_NOT_FOUND "file not found",
|
||||
};
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <fs/fs.h>
|
||||
#include <fs/dirent.h>
|
||||
#include "shelly.h"
|
||||
|
||||
__attribute__((__used__))
|
||||
@ -41,9 +43,36 @@ static errval_t shelly_cmd_help(char * line) {
|
||||
}
|
||||
|
||||
static errval_t shelly_cmd_ls(char * line) {
|
||||
// errval_t err;
|
||||
errval_t err;
|
||||
|
||||
return SYS_ERR_OK;
|
||||
fs_dirhandle_t dh;
|
||||
err = opendir(line, &dh);
|
||||
if (err_is_fail(err)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (dh == NULL) {
|
||||
return SHELLY_ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
char buf[256];
|
||||
|
||||
do {
|
||||
char *name;
|
||||
err = readdir(dh, &name);
|
||||
if (err_no(err) == FS_ERR_INDEX_BOUNDS) {
|
||||
break;
|
||||
} else if (err_is_fail(err)) {
|
||||
goto err_out;
|
||||
}
|
||||
snprintf(buf, 256, "%s\n\r", name);
|
||||
err = shelly_write_str(buf);
|
||||
if (err_is_fail(err)) goto err_out;
|
||||
} while(err_is_ok(err));
|
||||
|
||||
return closedir(dh);
|
||||
err_out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static errval_t shelly_cmd_cat(char * line) {
|
||||
@ -62,15 +91,11 @@ static errval_t shelly_cmd_cat(char * line) {
|
||||
}
|
||||
|
||||
static errval_t shelly_cmd_mkdir(char * line) {
|
||||
// errval_t err;
|
||||
|
||||
return SYS_ERR_OK;
|
||||
return mkdir(line);
|
||||
}
|
||||
|
||||
static errval_t shelly_cmd_rmdir(char * line) {
|
||||
// errval_t err;
|
||||
|
||||
return SYS_ERR_OK;
|
||||
return rmdir(line);
|
||||
}
|
||||
|
||||
static errval_t shelly_cmd_echo(char * line) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user