sdutil FAT formatting, libfat fix memcpy overflow, generate linker .map files for user apps
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m46s

This commit is contained in:
2026-03-21 00:08:19 +01:00
parent 7fa37ad6d7
commit 3a48856ee4
11 changed files with 41 additions and 34 deletions

1
ce/.gitignore vendored
View File

@@ -2,4 +2,5 @@
*.json
docs/
.cache/
*.map
ce

View File

@@ -6,7 +6,6 @@ $(eval $(call add_lib,libaux))
$(eval $(call add_lib,libarena))
$(eval $(call add_lib,libioutil))
$(eval $(call add_lib,libterminal))
$(eval $(call add_lib,libfat))
$(eval $(call add_lib,libmalloc))
$(eval $(call add_lib,libdebugconsole))
$(eval $(call add_lib,libinput))

View File

@@ -9,7 +9,6 @@
#include <filewriter.h>
#include <fs_types.h>
#include <kb.h>
#include <libfat.h>
#include <malloc.h>
#include <mprintf.h>
#include <path.h>
@@ -299,30 +298,6 @@ 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");
@@ -336,7 +311,6 @@ static void help (struct context* context) {
cprintf (context, "terminfo\n");
cprintf (context, "cls\n");
cprintf (context, "mkvol <volume> <filesystem> <device>\n");
cprintf (context, "format <device> <filesystem>\n");
cprintf (context, "quit\n");
}
@@ -410,11 +384,6 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
mkvol (context, cmd->args[0], cmd->args[1], cmd->args[2]);
else
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;

1
init/.gitignore vendored
View File

@@ -2,4 +2,5 @@
*.json
docs/
.cache/
*.map
init

View File

@@ -2,6 +2,7 @@ include ../make/ufuncs.mk
$(eval $(call add_include,libsystem))
$(eval $(call add_include,libstring))
$(eval $(call add_include,libaux))
cflags += -D"FAT_PRINTF(a)"

View File

@@ -1,6 +1,7 @@
#include <devices.h>
#include <fs_types.h>
#include <libfat.h>
#include <minmax.h>
#include <status.h>
#include <stddef.h>
#include <stdint.h>
@@ -69,7 +70,7 @@ static int fat_diskio_write (struct fatfs_ctx* ctx, uint32_t sector, uint8_t* bu
int fat_format_drive (struct fatfs_ctx* ctx, const char* device_key, int fs_type) {
memset (ctx, 0, sizeof (*ctx));
memcpy (ctx->device_name, device_key, sizeof (ctx->device_name) - 1);
memcpy (ctx->device_name, device_key, min (sizeof (ctx->device_name) - 1, strlen (device_key)));
size_t total_size = 0;
device_do (device_key, XDRV_GET_SIZE, &total_size, NULL, NULL, NULL);

View File

@@ -28,7 +28,7 @@ DOCS ?= \
all: $(app)
$(app): $(extra_deps) $(o)
$(ld) -o $@ $(ldflags) -T ../$(platform)/link.ld $(o)
$(ld) -o $@ $(ldflags) --Map=$(app).map -T ../$(platform)/link.ld $(o)
%.o: %.c
$(cc) -c -o $@ $(cflags) $<

1
sdutil/.gitignore vendored
View File

@@ -2,4 +2,5 @@
*.json
docs/
.cache/
*.map
sdutil

View File

@@ -7,6 +7,7 @@ $(eval $(call add_lib,libmalloc))
$(eval $(call add_lib,libdebugconsole))
$(eval $(call add_lib,libmalloc))
$(eval $(call add_lib,libinput))
$(eval $(call add_lib,libfat))
cflags += -DPRINTF_INCLUDE_CONFIG_H=1

View File

@@ -1,5 +1,7 @@
#include <devices.h>
#include <fs_types.h>
#include <in_input.h>
#include <libfat.h>
#include <mprintf.h>
#include <process_self.h>
#include <status.h>
@@ -120,6 +122,22 @@ static void list_part_dos (const char* dev_name) {
/* clang-format on */
}
static void format_fat32 (const char* dev_name) {
struct fatfs_ctx ctx;
int r = fat_format_drive (&ctx, dev_name, FS_FAT32);
mprintf ("\nFormatting done: %s (%d)\n", str_status[r < 0 ? -r : r], r);
}
static void format_fat16 (const char* dev_name) {
struct fatfs_ctx ctx;
int r = fat_format_drive (&ctx, dev_name, FS_FAT16);
mprintf ("\nFormatting done: %s (%d)\n", str_status[r < 0 ? -r : r], r);
}
void app_main (void) {
libprocess_self_init ();
@@ -142,6 +160,20 @@ void app_main (void) {
}
list_part_dos (devnamebuf);
} else if (strcmp (commandbuf, "format_fat32") == 0) {
if (env_get (process_get_pgid (), "dev", (void*)devnamebuf, sizeof (devnamebuf)) != ST_OK) {
mprintf ("ERROR dev=???. No device name provided for format_fat32\n");
return;
}
format_fat32 (devnamebuf);
} else if (strcmp (commandbuf, "format_fat16") == 0) {
if (env_get (process_get_pgid (), "dev", (void*)devnamebuf, sizeof (devnamebuf)) != ST_OK) {
mprintf ("ERROR dev=???. No device name provided for format_fat16\n");
return;
}
format_fat16 (devnamebuf);
} else {
mprintf ("ERROR C=%s. Unknown command\n", commandbuf);
}

1
spin/.gitignore vendored
View File

@@ -2,4 +2,5 @@
*.json
docs/
.cache/
*.map
spin