diff --git a/ce/.gitignore b/ce/.gitignore index 1444bed..c3e5675 100644 --- a/ce/.gitignore +++ b/ce/.gitignore @@ -2,4 +2,5 @@ *.json docs/ .cache/ +*.map ce diff --git a/ce/Makefile b/ce/Makefile index 2bfeba8..bc091b1 100644 --- a/ce/Makefile +++ b/ce/Makefile @@ -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)) diff --git a/ce/interp.c b/ce/interp.c index 85b874b..096207d 100644 --- a/ce/interp.c +++ b/ce/interp.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -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 \n"); - cprintf (context, "format \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; diff --git a/init/.gitignore b/init/.gitignore index 5fcba09..84a8769 100644 --- a/init/.gitignore +++ b/init/.gitignore @@ -2,4 +2,5 @@ *.json docs/ .cache/ +*.map init diff --git a/libfat/Makefile b/libfat/Makefile index 4624931..05d93fa 100644 --- a/libfat/Makefile +++ b/libfat/Makefile @@ -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)" diff --git a/libfat/libfat.c b/libfat/libfat.c index 22c73cc..0f3656b 100644 --- a/libfat/libfat.c +++ b/libfat/libfat.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/make/user.mk b/make/user.mk index 2227024..a9d4cde 100644 --- a/make/user.mk +++ b/make/user.mk @@ -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) $< diff --git a/sdutil/.gitignore b/sdutil/.gitignore index 5efb1aa..68f3a9a 100644 --- a/sdutil/.gitignore +++ b/sdutil/.gitignore @@ -2,4 +2,5 @@ *.json docs/ .cache/ +*.map sdutil diff --git a/sdutil/Makefile b/sdutil/Makefile index cef092c..8306802 100644 --- a/sdutil/Makefile +++ b/sdutil/Makefile @@ -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 diff --git a/sdutil/sdutil.c b/sdutil/sdutil.c index ccc46bc..94d0fb0 100644 --- a/sdutil/sdutil.c +++ b/sdutil/sdutil.c @@ -1,5 +1,7 @@ #include +#include #include +#include #include #include #include @@ -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); } diff --git a/spin/.gitignore b/spin/.gitignore index 5ae9319..fb19b40 100644 --- a/spin/.gitignore +++ b/spin/.gitignore @@ -2,4 +2,5 @@ *.json docs/ .cache/ +*.map spin