diff --git a/README.md b/README.md index 224f399..1321874 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ This is a list for current templates supported by the `-t/--template` option: ### Usage example To create a 1.44MiB 3.5' Floppy Disk image named `FloppyImageFile.img`:\ `mkimg -c -t 1 -o FloppyImageFile.img`\ -**NOTE: THIS COMMAND WILL NOT CURRENTLY WORK AS FS DETECTION IS NOT CURRENTLY IMPLEMENTED**\ To add file `main.c` to image `FloppyImageFile.img` which is unpartitioned:\ `mkimg -a -i main.c -o FloppyImageFile.img -u`\ To add file `main.c` to image `FloppyImageFile.img` which is a 1.44MiB 3.5' Floppy Disk:\ diff --git a/src/fat/fat12.c b/src/fat/fat12.c index 529f245..e0f3ecd 100644 --- a/src/fat/fat12.c +++ b/src/fat/fat12.c @@ -40,6 +40,7 @@ bpb16* fat12_write_bpb_direct(image* img) { bpb->bytesPerSector = 512; memset(bpb->oem, ' ', 8); + memcpy(bpb->oem, "mkimg", 5); bpb->sectorsPerCluster = 1; //forced for fat12 bpb->reservedSectors = 1; bpb->numFats = 2; diff --git a/src/image.c b/src/image.c index 1333f63..598ead9 100644 --- a/src/image.c +++ b/src/image.c @@ -46,6 +46,29 @@ void image_detect_partition_table(image* img) { } +//todo: change image to partition +mkimg_filesystem image_autodetect_fat(image* img) { + uint16_t rsectors = *((uint16_t*)(img->image_buffer+11+3)), + bps = *((uint16_t*)(img->image_buffer+11)); + char* fatptr = img->image_buffer + rsectors*bps; + if (fatptr > (img->image_buffer + img->image_size)) + return 0; + uint32_t* rclusters = (uint32_t*)fatptr; + + int may_16 = 1, may_32 = 1; + //detecting FAT type using file allocation table reserved clusters + if (rclusters[0] == 0xFFFFF8) + return FSFAT12; + if (rclusters[0] == 0xFFFFFFF8) + return FSFAT16; + if (rclusters[0] == 0x0FFFFFF8 && + rclusters[1] == 0x0FFFFFFF && + rclusters[2] == 0x0FFFFFF8) + return FSFAT32; + + return 0; +} + void image_detect_filesystem_nopart(image* img) { char magic_number_buff[8]; //detect NTFS @@ -60,9 +83,11 @@ void image_detect_filesystem_nopart(image* img) { img->image_file_system = FSExFAT; return; } - return; - //WARNING! THIS DETECTION IS TECHNICALLY INCORRECT! + //detect other FATs + mkimg_filesystem fatfs = image_autodetect_fat(img); + if (fatfs) + img->image_file_system = fatfs; } @@ -95,6 +120,7 @@ void image_detect_ex(image* img, int force_unpart, int force_nofs) { img->image_partition_table = PARTTYPE_NONE; else image_detect_partition_table(img); + if (force_nofs) img->image_partition_table = FSNone; else diff --git a/src/main.c b/src/main.c index 3794061..43fbdc4 100644 --- a/src/main.c +++ b/src/main.c @@ -95,6 +95,7 @@ void mode_add(mkimg_args* args) { int main(int argc, char* argv[]) { mkimg_args* args = arg_parse(argc, argv); + switch (args->mode) { case create: mode_create(args);