CE add format command, implement libfat
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m57s

This commit is contained in:
2026-03-10 21:38:51 +01:00
parent be8d1e4596
commit 3d9503260e
6 changed files with 142 additions and 5 deletions

View File

@@ -11,6 +11,7 @@
#include <fs_types.h>
#include <kb.h>
#include <liballoc.h>
#include <libfat.h>
#include <path.h>
#include <printf.h>
#include <process.h>
@@ -296,6 +297,30 @@ static void mkvol (struct context* context, const char* volume, const char* str_
cprintf (context, "ERROR Could not create volume: %s\n", str_status[-ret]);
}
static void format (struct context* context, const char* device, const char* str_fs_type) {
int fs_type;
if (strcmp (str_fs_type, "tar") == 0) {
fs_type = FS_TARFS;
} else if (strcmp (str_fs_type, "fat16") == 0) {
fs_type = FS_FAT16;
} else if (strcmp (str_fs_type, "fat32") == 0) {
fs_type = FS_FAT32;
} else {
cprintf (context, "ERROR Unknown filesystem '%s'\n", str_fs_type);
return;
}
struct fatfs_ctx ctx;
int ret = fat_format_drive (&ctx, device, fs_type);
if (ret < 0)
cprintf (context, "ERROR Could not format drive: %s\n", str_status[-ret]);
else
cprintf (context, "OK\n");
}
static void help (struct context* context) {
cprintf (context, "Available commands:\n");
cprintf (context, "help\n");
@@ -337,7 +362,7 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
if (cmd->args[0] != NULL)
ls (context, cmd->args[0]);
else
cprintf (context, "No directory path provided\n");
cprintf (context, "ERROR No directory path provided\n");
} else if (strcmp (cmd->name, "quit") == 0) {
quit1 (context);
} else if (strcmp (cmd->name, "mkfile") == 0) {
@@ -350,7 +375,7 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
if (cmd->args[0] != NULL)
edit (context, cmd->args[0]);
else
cprintf (context, "No file path provided\n");
cprintf (context, "ERROR No file path provided\n");
} else if (strcmp (cmd->name, "terminfo") == 0) {
terminfo (context);
} else if (strcmp (cmd->name, "cls") == 0) {
@@ -359,7 +384,12 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
if ((cmd->args[0] != NULL) && (cmd->args[1] != NULL) && (cmd->args[2] != NULL))
mkvol (context, cmd->args[0], cmd->args[1], cmd->args[2]);
else
cprintf (context, "No volume key, filesystem type or device key provided\n");
cprintf (context, "ERROR No volume key, filesystem type or device key provided\n");
} else if (strcmp (cmd->name, "format") == 0) {
if ((cmd->args[0] != NULL) && (cmd->args[1] != NULL))
format (context, cmd->args[0], cmd->args[1]);
else
cprintf (context, "ERROR No device key or filesystem type provided\n");
} else {
char volume[VOLUME_MAX];
const char* path;