Skip to content

Commit

Permalink
Improved ls command, added rm command.
Browse files Browse the repository at this point in the history
  • Loading branch information
pradosh-arduino committed Jan 24, 2025
1 parent bb5cc28 commit 6157bcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions source/kernel/C/filesystems/fwrfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ int is_validfilename(char c) {
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
(c == '.')) {
return 1; // Character is alphanumeric
return 1;
} else {
return 0; // Character is not alphanumeric
return 0;
}
}

Expand Down Expand Up @@ -94,6 +94,8 @@ int delete_file(struct fwrfs* fs, const char* filename) {
return 0;
}
}

printf("rm: cannot remove \'%s\': No such file or directory", filename);
return -1;
}

Expand Down Expand Up @@ -145,9 +147,11 @@ size_t calculate_memory_usage(struct fwrfs* fs) {
}

void list_contents(struct fwrfs* fs) {
size_t total_memory = calculate_memory_usage(fs);

printf("%sTotal Memory Used: %u bytes%s", "\x1b[38;2;128;128;128m", total_memory, reset_color);

if(fs->nfolders != 0 || fs->nfiles != 0){
size_t total_memory = calculate_memory_usage(fs);
printf("%sTotal Memory Used: %u bytes%s", "\x1b[38;2;128;128;128m", total_memory, reset_color);
}

for (int i = 0; i < fs->nfolders; i++) {
printf("%s%s%s", yellow_color, fs->folders[i].name, reset_color);
Expand Down
5 changes: 5 additions & 0 deletions source/kernel/C/shell/sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ void execute(const char* buffer, int argc, char** argv)
create_file(fs, arg, "");
} else if (strcmp(buffer, "touch") == 0) {
printf("touch: missing file operand");
} else if (strncmp(buffer, "rm ", 3) == 0) {
char* arg = buffer + 3;
delete_file(fs, arg);
} else if (strcmp(buffer, "rm") == 0) {
printf("rm: missing file operand");
} else if (strncmp(buffer, "mkdir ", 6) == 0) {
char* arg = buffer + 6;
create_folder(fs, arg);
Expand Down

0 comments on commit 6157bcd

Please sign in to comment.