[syslinux] port syslinux isohybrid perl script to C
Geert Stappers
stappers at stappers.nl
Fri Apr 30 13:54:29 PDT 2010
Op 20100430 om 13:14 schreef P J P:
> Hi,
>
> Please see -> http://pjp.dgplug.org/tools/syslinux-3.86-isohybrid.patch.5
+++ syslinux-3.86.1/utils/bin2Carray.pl 2010-04-30 11:12:52.492689084
@@ -0,0 +1,50 @@
+#!/usr/bin/env perl
<snip/>
+##
+# main ()
+{
+ my ($len, $ch) = (0, 0);
+ binmode(STDIN);
+ while (read(STDIN, $ch, 1))
+ {
+ printf(" ") if (!($len % 12));
+ printf(" 0x%02X,", ord($ch));
+ $len++;
+ printf("\n") if (!($len % 12));
+ }
+ exit 0;
+}
+++ syslinux-3.86.1/utils/isohybrid.c 2010-04-30 12:43:49.644890414 +0530
@@ -0,0 +1,576 @@
+/*
+ * isohybrid.c: Post process an ISO 9660 image generated with mkisofs or
+ * genisoimage to allow - hybrid booting - as a CD-ROM or as a hard
+ * disk.
+ *
+ * This is based on the original Perl script written by H. Peter Anvin.
The rewrite in C is
to avoid dependency on Perl on a system under installation
+ *
+ * Copyright (C) 2010 P J P <pj.pandit at yahoo.co.in>
+ *
<snip/>
+
+#define VERSION "0.6"
+#define BUFSIZE 2048
+#define MBRSIZE 432
+
<snip/>
+size_t
+get_hex_data(uint8_t *mbr)
+{
+ static int i = 0;
+ extern unsigned char hexdata[];
+
+ while (i < MBRSIZE)
+ {
+ mbr[i] = hexdata[i];
+ i++;
+ }
+
+ return i++;
+}
+
+
+int
+initialise_mbr(uint8_t *mbr)
+{
+ int i = 0;
+ uint32_t psize = 0, tmp = 0;
+ uint8_t ptype = 0, *rbm = mbr;
+ uint8_t bhead = 0, bsect = 0, bcyle = 0;
+ uint8_t ehead = 0, esect = 0, ecyle = 0;
+
+ for (i = 0; i <= (hd0 + 3 * partok); i++)
+ if ((tmp = get_hex_data(mbr)) > MBRSIZE)
+ errx(1, "bad MBR code: %d", tmp);
+ mbr += MBRSIZE; /* offset 432 */
+
<snip/>
+int
+main(int argc, char *argv[])
+{
<snip/>
+ free(buf);
+ fclose(fp);
+
+ return 0;
+}
>
> Major changes:
>
> - bin2Carray changed to remove '*' character from C array.
> - asterisk('*') character removed from the hexdata.c, so get_hex_data()
> changed to only check length, and not '*' delimiter.
The function get_hex_data() will ALLWAYS return MBRSIZE,
there will be NEVER 'errx(1, "bad MBR code: %d", tmp);'
Geert Stappers
More information about the Syslinux
mailing list