[syslinux] Syslinux 3.81-pre14... hopefully final this time

Thomas Schmitt scdbackup at gmx.net
Wed May 27 05:43:42 PDT 2009


Hi,

> What I'm thinking of doing is to add a piece of C code for this.  If you
> have suggestions as to the interface, that would be appreciated.

The advantage of a C implementation is that one
does not have to look for the Perl interpreter.
One level less of complexity and security risk.

If you give it a permissive license then it
could be included in projects like libisofs.
(I was already decided to change to external
 execution but your recent mails encourage me
 to rethink.)

The MBR generation function should be callable
without the need to have an existing ISO image.
All needed info should be in function parameters.

I believe that program options for blind MBR
generation are desirable, too.

-------------------------------------------------

Proposal of a struct which contains parameters
and results:

  struct isohybrid_par {
      int version;       /* 0 for now */

      /* Input */

      /* Current options */
      int h;
      int s;
      ...
      int partok;

      /* From ISO image or from options */
      char ibsig[4];     /* Bytes 0x40 to 0x43 of isolinux.bin */
      int de_lba;        /* Block address of isolinux.bin */
      int imgsize;       /* Overall size of the ISO image */

      /* MBR code and list of permissible ibsig values. See below. */
      struct isohybrid_mbr *mbr_template;

      /* Output */
      char mbr[512];
      int padding;

      /* (Here be structure members of future versions) */
  };

  int isohybrid_make_mbr(struct isohybrid_par *par);

The member .version will allow future extensions
at the end of the structure member list. This
will eventually keep API and ABI backward
compatible. (Functions may not touch members
which belong to a version higher than the
actually given params.version)

For libisofs it might be useful to update the MBR
code dynamically via some configuration facility,
or to have more than one MBR template at hand.
So i propose this parameter:

  struct isohybrid_mbr {
      int version;
      char mbr_code[512];
      int num_ibsigs;
      char desired_ibsigs[10][4];
  };

It is prepared to cater by a single MBR
for up to 10 different magic numbers
of isolinux.bin. That should suffice for
a while of isohybrid development.
(The fixed size is primitive. But it
 makes life easy and just costs 40 bytes.)

If incompatible families of boot images
and MBRs emerge, this encapsulation will
allow to manage more than one MBR code
template.


A sketch of isohybrid.c:

main(int argc, char **argv)
{
    struct isohybrid_mbr mbr_template;
    struct isohybrid_par params;
    char img_path[4096];
    int blindly = 0;

    /* Load desired magic numbers and MBR code from static char arrays.
       The MBR code was appended to isohybrid.c by the Makefile */
    isohybrid_mbr_template(&mbr_template);

    /* Set default values for options */
    isohybrid_init(&params, &mbr_template);

    /* Parse and check program arguments */
    if (isohybrid_setup(argc, argv, &params, img_path) != 0)
        exit(1);

    /* Make sure to have the necessary info about the ISO image */
    if (params.de_lba != 0 && params.imgsize != 0 && params.ibsig[0] != 0) {
        /* Options for blind MBR generation were given */
        blindly = 1;
    } else if (img_path[0] != 0) {
        /* Read params.ibsig , .de_lba , .imgsize from ISO image */
        if (isohybrid_read_img(img_path, &params) != 0)
            exit(2);
    } else {
        ... complain about missing arguments ...
        exit(1);
    }

    /* Generate the actual MBR */
    if (isohybrid_make_mbr(&params) != 0)
        exit(3);

    if (blindly) {
        /* Write MBR to stdout */
        write(1, params.mbr, 512);

        /* ??? shall we append the number of padding bytes
               to the 512 MBR bytes on stdout ? Big endian ? Decimal ? */

    } else {
        /* Write MBR to image and pad it up */
        if (isohybrid_patch_image(img_path, &params) != 0)
            exit(4);
    }

    exit(0);
}


Sketch of usage in libisofs:

    struct isohybrid_mbr mbr_template;
    struct isohybrid_par params;

    /* Load MBR code from some libisofs specific source */
    iso_load_mbr_template(..., &mbr_template, ...);

    /* Set default values for options */
    isohybrid_init(&params, &mbr_template);

    /* Override by some options from libisofs. Set params.ibsig,
       .de_lba, .imgsize from inner knowledge of libisofs.
    */
    iso_set_mbr_options(..., &params, ...);

    /* Try to generate the actual MBR */
    if (isohybrid_make_mbr(&params) <= 0) {
        ... return failure ...
    }
    /* Return the MBR bytes to be written as first 512 bytes
       of the image stream, and the number of padding bytes. */


We need a replacement for this Makefile gesture:

ISOHDPFX = ../mbr/isohdpfx.bin ../mbr/isohdpfx_f.bin ../mbr/isohdpfx_c.bin \
           ../mbr/isohdppx.bin ../mbr/isohdppx_f.bin ../mbr/isohdppx_c.bin
isohybrid: isohybrid.in $(ISOHDPFX) bin2hex.pl
         cp -f isohybrid.in $@
         for f in $(ISOHDPFX) ; do $(PERL) bin2hex.pl < $$f >> $@ ; done
         chmod a+x $@

Looks like a script bin2c.pl could do the trick.


I volunteer to do those tasks which don't require
deep SYSLINUX knowledge.

Probably i can translate isohybrid 3.81 to
above C sketch. But this translation would have
to be checked by a skilled reviewer. So possibly
it is simpler if that reviewer makes the
translation himself.

Just decide and give me clear orders. :))


-------------------------------------------------


> However, I really don't want to hold the 3.81 release over it.

That's well understandable.


> OK... how about this... we can change the magic number, and then have
> the new isohybrid accept both the old and the new magic number.

Indeed one should change the magic number of
the boot image whenever it becomes incompatible
with older versions of isohybrid.


> The *new* isohybrid can work with *old* isolinux.bin
... one mail later:
> Turns out I can [make work is the other way around],
> after all.

So no new magic number needed for now.

And my 3.72 isohybrid port will work with boot
images of 3.81. I do not have to throw it out
yet. :))


> You need to argue with me more often.  It seems to make me think.

I was already fearing to be too obtrusive.

A good part of the merits belongs to Luciano
Rocha who proposed the options which made me
wake up.


Have a nice day :)

Thomas




More information about the Syslinux mailing list