[syslinux] isohybrid and ISO images whose size is not a multiple of 2048 bytes vs. VirtualBox
Ady
ady-sf at hotmail.com
Thu Feb 19 16:21:04 PST 2015
> Hi,
>
> > Hopefully I am explaining it better this time.
>
> Our ideas of implementation are supposed to yield the
> same result.
>
Hmm, I am not sure. Or perhaps I am misunderstanding your code.
Let me try with an example (or two). For this example, let's assume:
-h 255
-s 63
ISO size: 1'085'736'960 bytes ( > 1GiB)
This size happens to be a multiple of:
63, 255 and 2048
So, using these values in my suggested loop.
1_ Calculate a potential Cylinders (amount) value;
Cylinders=
trunc(roundup( ISO_size / (Heads * Sectors_per_track * 512))
Cylinders (1st attempt)=
trunc(roundup(1085736960/(255*63*512))
Cylinders (1st attempt)=
trunc(roundup(132))
Cylinders (1st attempt)=132
2_ Calculate 'Cylinders * Heads * Sectors_per_track';
132 * 255 * 63 = 2120580
3._ Is the result of the calculation (as explained in the previous step
#2) a multiple of '4'?
2120580 / 4 = 530145, so the answer is "yes".
3.a_ If it is, continue (to step #4).
Since the answer was "yes", we end the loop and we have found the
minimal Cylinders amount that achieves our conditions.
Now, if I take your code:
if (Heads * Sectors_per_track) is divisible by 4
# Pad up to next full cylinder
align_factor = 1
else if (Heads * Sectors_per_track) is divisible by 2
# Pad up to next full double cylinder
align_factor = 2
else
# Pad up to next full quatruple cylinder (nearly 32 MB)
align_factor = 4
For the example I am presenting here, "Heads*Sectors_per_track" is
255*63, so it is not a multiple of 4 nor of 2. Would you add anyway
nearly 32MiB? I assume you wouldn't. Instead, I guess you would first
evaluate whether it is already a full "valid" cylinder and that no
additional zero-padding would be required.
When comparing your code with my suggested calculation, I see that your
conditionals do not account for the ISO image size, but only for
"Heads" and "Sectors_per_track".
So let's assume a new example. Let's add a few bytes to the size of the
ISO image:
-h 255
-s 63
ISO size: 1'085'736'960 bytes+2048 bytes
ISO size: 1'085'739'008 bytes ( > 1GiB)
Now let's perform the calculations for this new example:
Cylinders (1st attempt)=
trunc(roundup(1085739008/(255*63*512))
Cylinders (1st attempt)=
trunc(roundup(132.0002489884842826...)
Cylinders (1st attempt)=133
133 * 255 * 63 = 2136645
Is it multiple of '4'?
2136645 / 4 = 534161.25, so the answer is "no".
3.b_ If it is not, then add '+1' to the attempted Cylinders (amount)
value and loop.
134 * 255 * 63 = 2152710
Is it multiple of '4'?
2152710 / 4 = 538177.5 so the answer is "no".
135 * 255 * 63 = 2168775
Is it multiple of '4'?
2168775 / 4 = 542193.75 so the answer is "no".
136 * 255 * 63 = 2184840
2184840 / 4 = 546210 so the answer is "yes".
Since the answer was "yes", we end the loop and we have found the
minimal Cylinders amount that achieves our conditions.
In this second example, we have started with a first attempt of 133 for
the amount of complete Cylinders, and we would had to add 3 more, up to
136.
Other values of "ISO_size", "Heads" and "Sectors_per_track" might lead
my suggested loop to add either 0, 1, 2, or 3 complete Cylinders. The
zero-padding could be between 0 bytes and "almost 4 complete Cylinders"
(4 complete Cylinders minus 2048 bytes).
Now, considering our mutual slight misunderstandings throughout this
email thread, I have to wonder whether the wording you (Thomas) used
for your 3 variants of zero-padding, together with the 3 conditionals,
are equivalent to the 4 possible loops I am suggesting.
Although the size of the input image doesn't seem to be considered in
the conditionals you (Thomas) presented, I could assume that this is
just "implied" in the pseudo-code, similarly to what happens in my
suggested loop (the size of the image is used in the calculations
before the loop, not part of it). If it is not, then we have a first
difference in our approach.
The second difference could be the 3 conditionals vs the 4 loops. As
seen in my second example above, depending on the size of the input
image the required padding varies, even with a "fixed" pair of "Heads"
and "Sectors_per_track" values. Although I have not tried to find
specific examples for having to add between 1 and 2 complete Cylinders
(of zero-padding bytes), the second example above should show that the
possibility indeed exists.
So, unless I am misinterpreting the wording in your code:
"# Pad up to next full ... cylinder" ,
my second example suggests that having 4 ranges (coded as 4 loops or
using conditionals or however it could be done) might be able to
achieve better optimal values (less zero-padding) at least for some
cases.
I must apologize for the long emails. Certainly if I would know how to
code it myself it would be shorter to explain.
Thank you for your attention.
Regards,
Ady.
More information about the Syslinux
mailing list