Item #1.
Well, if the C snippet results gives the same result, then the information about h/s geometry is either incorrect or interpreted incorrectly.
As said, not only the result posted by OP is not compatible with any "known" geometry, but it cannot result from *any* geometry.
Item #3
Your reply does not (again) take into consideration the data in the BPB.
Again, that data NEEDS to be accurate AND the geometry of the original image can be gathered by these data without any calculation, it is just a matter of reading two values.
Again, with all due respect
you are going down EXACTLY the SAME path that Gilles Vollant went (with - unfortunately - not very good results
) when he extended Winimage from being able to manage ONLY floppy and superfloppy to being able to manage hard disk images.
The "export image with MBR" in Winimage produces - just like IMDISK corresponding feature has been reported to behave in this thread - something almost, but not quite, entirely UNlike a valid partition table entry.
Expecially nowadays assuming that a volume will go in a hard-disk image respecting cylinder boundary is "wrong" as "current" NT based systems, i.e. Vista
and later do default to 4 Kb alignment, or, if you prefer, first partition will start at 0/32/33 LBA 2048 instead of 0/1/1 LBA 63 (still in the default 255/63 H/S geometry).
As I see it, if you want to extend IMDISK to manage "properly" disk images, you will need to go into the pain of - besides "fixing" the currently botched CHS generated entry - providing a new set of "user-selectable" choices.
As you know I am not a programmer, but I really see nothing particularly difficult in doing the above.
Basically (and IMNSHO
):
- IF the loaded volume inside a disk image is NOT resized, allow for an option to use the already existing MBR "as is" (dd or rawcopy style) including it's CODE (besides the DATA)
- IF the loaded volume is a "superfloppy" or is created within IMDISK, allow for an option to create MBR DATA (with correct values ) AND at least a switch between THREE "modes":
- Cylinder boundary aligned (old approach) with 63 "Sectors before"
- 4K aligned (new approach) with 2048 "Sectors before"
- User manual input
the above three are "LBA based" (and you have to manage it anyway in the BPB of the volume @offset 0x1C), then you can convert the values to CHS (for the MBR entry) AND use for it the SAME H/S geometry you need to manage anyway in the BPB @offset 0x18 and 0x1A.
This geometry should also be changeable by the user, as it is "vital" for bootability on a number of VBR code (notwithstanding that NT will use LBA addressing for accessing the filesystem).
See:
http://www.911cd.net...showtopic=23408and links therein.
To become "complete" you would also need to provide a way to write to the newly created MBR at least the MBR CODE of the OS where IMDISK is used.
The alternative, as I see it, is removing the current "export with MBR" and leave IMDISK be a Volume/Partition/Filesystem related tool and NOT a DISK one....
Wonko