--- src/mkdosfs.c.bootcode 2011-10-01 08:11:39.728024787 +0400 +++ src/mkdosfs.c 2011-10-01 08:13:15.412024824 +0400 @@ -280,6 +280,7 @@ static char *program_name = "mkdosfs"; /* Name of the program */ static char *device_name = NULL; /* Name of the device on which to create the filesystem */ static int atari_format = 0; /* Use Atari variation of MS-DOS FS format */ +static const char *bootcode_srcimage = NULL; /* Source file/device from which read bootloader code */ static int check = FALSE; /* Default to no readablity checking */ static int verbose = 0; /* Default to verbose mode off */ static long volume_id; /* Volume ID number */ @@ -794,6 +795,24 @@ return sectors; } +static void +apply_external_bootcode(void) +{ + if ( !bootcode_srcimage ) + return; + char *bootcodeptr = ( size_fat == 32 ) ? + ( (char*) &bs.fat32.boot_code ) : ( (char*) &bs.oldfat.boot_code ); + int offset = ( int )( bootcodeptr - (char*)&bs ); + int nbytes = ( size_fat == 32 ) ? BOOTCODE_FAT32_SIZE : BOOTCODE_SIZE; + int srcfile = open( bootcode_srcimage, O_RDONLY ); + if ( srcfile < 0 ) + die("Cannot open device/file for reading source bootloader code"); + if ( lseek( srcfile, offset, SEEK_SET ) < 0) + die("Cannot seek to begin of source bootloader code"); + if ( read( srcfile, bootcodeptr, nbytes ) != nbytes ) + die("Cannot read source bootloader code"); +} + /* Create the filesystem data tables */ static void @@ -842,6 +861,9 @@ (char *)&bs.oldfat.boot_code) - (char *)&bs) - 2; + if (bootcode_srcimage) { + apply_external_bootcode(); + } else if (size_fat == 32) { int offset = (char *)&bs.fat32.boot_code - (char *)&bs + MESSAGE_OFFSET + 0x7c00; @@ -1423,7 +1445,7 @@ { fatal_error("\ Usage: mkdosfs [-a][-A][-c][-C][-v][-I][-l bad-block-file][-b backup-boot-sector]\n\ - [-m boot-msg-file][-n volume-name][-i volume-id]\n\ + [-m boot-msg-file][-n volume-name][-i volume-id] [-B bootcode-image ]\n\ [-s sectors-per-cluster][-S logical-sector-size][-f number-of-FATs]\n\ [-h hidden-sectors][-F fat-size][-r root-dir-entries][-R reserved-sectors]\n\ /dev/name [blocks]\n"); @@ -1488,7 +1510,7 @@ printf ("%s " VERSION " (" VERSION_DATE ")\n", program_name); - while ((c = getopt (argc, argv, "aAb:cCf:F:Ii:l:m:n:r:R:s:S:h:v")) != EOF) + while ((c = getopt (argc, argv, "aAB:b:cCf:F:Ii:l:m:n:r:R:s:S:h:v")) != EOF) /* Scan the command line for options */ switch (c) { @@ -1500,6 +1522,10 @@ align_structures = FALSE; break; + case 'B': + bootcode_srcimage = optarg; + break; + case 'b': /* b : location of backup boot sector */ backup_boot = (int) strtol (optarg, &tmp, 0); if (*tmp || backup_boot < 2 || backup_boot > 0xffff) --- man/mkdosfs.8.bootcode 2011-10-01 08:14:09.000000000 +0400 +++ man/mkdosfs.8 2011-10-01 08:15:04.192024792 +0400 @@ -12,6 +12,10 @@ .B \-A ] [ +.B \-B +.I source-bootcode-container +] +[ .B \-b .I sector-of-backup ] @@ -109,6 +113,15 @@ option. Some PC-specific boot sector fields aren't written, and a boot message (option \fB\-m\fP) is ignored. .TP +.BI \-B " source-bootcode-container " +By default \fBmkdosfs\fP writes bootsector containing dummy code +that does nothing except displays stupid message. If you want to create +bootable DOS diskette and are ABSOULTELY sure that it has the same format +as another already existing diskette (most important is difference +between FAT and FAT32), you can extract boot loader from it. +\fIsource-container\fP should be device file like /dev/fd0, +as well as regular file like /mnt/windows/bootcode.dos +.TP .BI \-b " sector-of-backup " Selects the location of the backup boot sector for FAT32. Default depends on number of reserved sectors, but usually is sector 6. The