From a9ac73d0f76c25565a73569f8bbaff277b15267a Mon Sep 17 00:00:00 2001 From: David Quintana Date: Wed, 9 Sep 2015 03:01:14 +0000 Subject: [PATCH] [FATTEN] * Allow customizing the 8-letter volume label from the FAT header. * Make the efisys.bin have EFIBOOT as a label. * Improve a bit the help text. svn path=/trunk/; revision=69140 --- reactos/boot/CMakeLists.txt | 2 +- reactos/tools/fatten/fatten.c | 110 +++++++++++++++++++++++++++++----- 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/reactos/boot/CMakeLists.txt b/reactos/boot/CMakeLists.txt index dd6f3c14c14..6f5b5836f9f 100644 --- a/reactos/boot/CMakeLists.txt +++ b/reactos/boot/CMakeLists.txt @@ -16,7 +16,7 @@ else() endif() add_custom_target(efisys - COMMAND native-fatten ${CMAKE_CURRENT_BINARY_DIR}/efisys.bin -format 2880 -boot ${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/fat.bin -mkdir EFI -mkdir EFI/BOOT -add $ EFI/BOOT/boot${EFI_PLATFORM_ID}.efi + COMMAND native-fatten ${CMAKE_CURRENT_BINARY_DIR}/efisys.bin -format 2880 EFIBOOT -boot ${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/fat.bin -mkdir EFI -mkdir EFI/BOOT -add $ EFI/BOOT/boot${EFI_PLATFORM_ID}.efi DEPENDS native-fatten bootmgfw fat VERBATIM) diff --git a/reactos/tools/fatten/fatten.c b/reactos/tools/fatten/fatten.c index 476d4697504..a64c5f96285 100644 --- a/reactos/tools/fatten/fatten.c +++ b/reactos/tools/fatten/fatten.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "fatfs/ff.h" #include "fatfs/diskio.h" @@ -93,19 +94,30 @@ int need_mount() void print_help(char const * const name) { printf("Syntax: %s image_file [list of commands]\n\n", name); - printf("Commands: [Note: both '/' and '-' are accepted as command prefixes.] \n"); - printf(" /format [] Formats the disk image.\n"); - printf(" /boot Writes a new boot sector.\n"); - printf(" /add Copies an external file or directory\n" - " into the image.\n"); - printf(" /extract Copies a file or directory from the image\n" - " into an external file or directory.\n"); - printf(" /move Moves/renames a file or directory.\n"); - printf(" /copy Copies a file or directory.\n"); - printf(" /mkdir Creates a directory.\n"); - printf(" /rmdir Creates a directory.\n"); - printf(" /list [] Lists files a directory (defaults to root).\n"); - //printf(" /recursive Enables recursive processing for directories.\n"); +#if _WIN32 + printf("Commands: [Note: both '/' and '-' are accepted as command prefixes.]\n"); +#else + printf("Commands:\n"); +#endif + printf(" -format []\n" + " Formats the disk image.\n"); + printf(" -boot []\n" + " Writes a new boot sector.\n"); + printf(" -add \n" + " Copies an external file or directory into the image.\n"); + printf(" -extract \n" + " Copies a file or directory from the image into an external file\n" + " or directory.\n"); + printf(" -move \n" + " Moves/renames a file or directory.\n"); + printf(" -copy \n" + " Copies a file or directory.\n"); + printf(" -mkdir \n" + " Creates a directory.\n"); + printf(" -rmdir \n" + " Creates a directory.\n"); + printf(" -list []\n" + " Lists files a directory (defaults to root).\n"); } #define PRINT_HELP_AND_QUIT() \ @@ -167,7 +179,7 @@ int main(int oargc, char* oargv[]) // NOTE: The fs driver detects which FAT format fits best based on size int sectors; - NEED_PARAMS(1, 1); + NEED_PARAMS(1, 2); // Arg 1: number of sectors sectors = atoi(argv[0]); @@ -189,6 +201,76 @@ int main(int oargc, char* oargv[]) printf("ERROR: Formatting drive: %d.\n", ret); PRINT_HELP_AND_QUIT(); } + + // Arg 2: custom header label (optional) + if (nargs > 1) + { + char label[8]; + + int i, invalid=0; + int len = strlen(argv[1]); + + if (len <= 8) + { + // Copy and verify each character + for (i = 0; i < len; i++) + { + char ch = argv[1][i]; + label[i] = ch; + + if (!isupper(ch) && !isspace(ch)) + { + invalid =1; + break; + } + } + + if (!invalid) + { + // Pad the label with spaces + while (len < 8) + { + label[len++] = ' '; + } + } + } + else + { + invalid = 1; + } + + if (invalid) + { + printf("Error: header label is limited to 8 uppercase letters and spaces."); + ret = 1; + goto exit; + } + + if (disk_read(0, buff, 0, 1)) + { + printf("Error: unable to read existing boot sector from image."); + ret = 1; + goto exit; + } + + + if (g_Filesystem.fs_type == FS_FAT32) + { + memcpy(buff + 71, label, 8); + } + else + { + memcpy(buff + 43, label, 8); + } + + if (disk_write(0, buff, 0, 1)) + { + printf("Error: unable to write new boot sector to image."); + ret = 1; + goto exit; + } + + } } else if (strcmp(parg, "boot") == 0) {