Skip to content

Commit

Permalink
fixed #3, added FS detection
Browse files Browse the repository at this point in the history
  • Loading branch information
NullExceptionTSB committed Jan 6, 2023
1 parent 02a6c02 commit 73f00e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:\
Expand Down
1 change: 1 addition & 0 deletions src/fat/fat12.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 28 additions & 2 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

}

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 73f00e3

Please sign in to comment.