summaryrefslogtreecommitdiffstats
path: root/libinstaller
diff options
context:
space:
mode:
Diffstat (limited to 'libinstaller')
-rwxr-xr-xlibinstaller/bin2c.pl4
-rw-r--r--libinstaller/setadv.c13
-rw-r--r--libinstaller/syslinux.h16
-rw-r--r--libinstaller/syslxint.h114
-rw-r--r--libinstaller/syslxmod.c302
5 files changed, 264 insertions, 185 deletions
diff --git a/libinstaller/bin2c.pl b/libinstaller/bin2c.pl
index 5a60ca9e..07c11ddb 100755
--- a/libinstaller/bin2c.pl
+++ b/libinstaller/bin2c.pl
@@ -69,10 +69,10 @@ if ($align != 0) {
}
}
-printf "\n};\n\nunsigned int %s_len = %u;\n", $table_name, $total_len;
+printf "\n};\n\nconst unsigned int %s_len = %u;\n", $table_name, $total_len;
@st = stat STDIN;
-printf "\nint %s_mtime = %d;\n", $table_name, $st[9];
+printf "\nconst int %s_mtime = %d;\n", $table_name, $st[9];
exit 0;
diff --git a/libinstaller/setadv.c b/libinstaller/setadv.c
index 32ad1654..d18ac927 100644
--- a/libinstaller/setadv.c
+++ b/libinstaller/setadv.c
@@ -36,14 +36,14 @@ static void cleanup_adv(unsigned char *advbuf)
uint32_t csum;
/* Make sure both copies agree, and update the checksum */
- set_32(advbuf, ADV_MAGIC1);
+ set_32((uint32_t *) advbuf, ADV_MAGIC1);
csum = ADV_MAGIC2;
for (i = 8; i < ADV_SIZE - 4; i += 4)
- csum -= get_32(advbuf + i);
+ csum -= get_32((uint32_t *) (advbuf + i));
- set_32(advbuf + 4, csum);
- set_32(advbuf + ADV_SIZE - 4, ADV_MAGIC3);
+ set_32((uint32_t *) (advbuf + 4), csum);
+ set_32((uint32_t *) (advbuf + ADV_SIZE - 4), ADV_MAGIC3);
memcpy(advbuf + ADV_SIZE, advbuf, ADV_SIZE);
}
@@ -130,12 +130,13 @@ static int adv_consistent(const unsigned char *p)
int i;
uint32_t csum;
- if (get_32(p) != ADV_MAGIC1 || get_32(p + ADV_SIZE - 4) != ADV_MAGIC3)
+ if (get_32((uint32_t *) p) != ADV_MAGIC1 ||
+ get_32((uint32_t *) (p + ADV_SIZE - 4)) != ADV_MAGIC3)
return 0;
csum = 0;
for (i = 4; i < ADV_SIZE - 4; i += 4)
- csum += get_32(p + i);
+ csum += get_32((uint32_t *) (p + i));
return csum == ADV_MAGIC2;
}
diff --git a/libinstaller/syslinux.h b/libinstaller/syslinux.h
index f8f25190..8ed1edbe 100644
--- a/libinstaller/syslinux.h
+++ b/libinstaller/syslinux.h
@@ -18,16 +18,20 @@
/* The standard boot sector and ldlinux image */
extern unsigned char syslinux_bootsect[];
-extern unsigned int syslinux_bootsect_len;
-extern int syslinux_bootsect_mtime;
+extern const unsigned int syslinux_bootsect_len;
+extern const int syslinux_bootsect_mtime;
extern unsigned char syslinux_ldlinux[];
-extern unsigned int syslinux_ldlinux_len;
-extern int syslinux_ldlinux_mtime;
+extern const unsigned int syslinux_ldlinux_len;
+extern const int syslinux_ldlinux_mtime;
extern unsigned char syslinux_mbr[];
-extern unsigned int syslinux_mbr_len;
-extern int syslinux_mbr_mtime;
+extern const unsigned int syslinux_mbr_len;
+extern const int syslinux_mbr_mtime;
+
+/* Sector size assumptions... */
+#define SECTOR_SHIFT 9
+#define SECTOR_SIZE (1 << SECTOR_SHIFT)
/* This takes a boot sector and merges in the syslinux fields */
void syslinux_make_bootsect(void *);
diff --git a/libinstaller/syslxint.h b/libinstaller/syslxint.h
index 208d78ca..e2a80724 100644
--- a/libinstaller/syslxint.h
+++ b/libinstaller/syslxint.h
@@ -18,57 +18,133 @@
/*
* Access functions for littleendian numbers, possibly misaligned.
*/
-static inline uint8_t get_8(const unsigned char *p)
+static inline uint8_t get_8(const uint8_t * p)
{
- return *(const uint8_t *)p;
+ return *p;
}
-static inline uint16_t get_16(const unsigned char *p)
+static inline uint16_t get_16(const uint16_t * p)
{
#if defined(__i386__) || defined(__x86_64__)
/* Littleendian and unaligned-capable */
- return *(const uint16_t *)p;
+ return *p;
#else
- return (uint16_t) p[0] + ((uint16_t) p[1] << 8);
+ const uint8_t *pp = (const uint8_t *)p;
+ return (uint16_t) pp[0] + ((uint16_t) pp[1] << 8);
#endif
}
-static inline uint32_t get_32(const unsigned char *p)
+static inline uint32_t get_32(const uint32_t * p)
{
#if defined(__i386__) || defined(__x86_64__)
/* Littleendian and unaligned-capable */
- return *(const uint32_t *)p;
+ return *p;
#else
- return (uint32_t) p[0] + ((uint32_t) p[1] << 8) +
- ((uint32_t) p[2] << 16) + ((uint32_t) p[3] << 24);
+ const uint8_t *pp = (const uint8_t *)p;
+ return (uint32_t) pp[0] + ((uint32_t) pp[1] << 8) +
+ ((uint32_t) pp[2] << 16) + ((uint32_t) pp[3] << 24);
#endif
}
-static inline void set_16(unsigned char *p, uint16_t v)
+static inline void set_8(uint8_t * p, uint8_t v)
+{
+ *p = v;
+}
+
+static inline void set_16(uint16_t * p, uint16_t v)
{
#if defined(__i386__) || defined(__x86_64__)
/* Littleendian and unaligned-capable */
*(uint16_t *) p = v;
#else
- p[0] = (v & 0xff);
- p[1] = ((v >> 8) & 0xff);
+ uint8_t *pp = (uint8_t *) p;
+ pp[0] = (v & 0xff);
+ pp[1] = ((v >> 8) & 0xff);
#endif
}
-static inline void set_32(unsigned char *p, uint32_t v)
+static inline void set_32(uint32_t * p, uint32_t v)
{
#if defined(__i386__) || defined(__x86_64__)
/* Littleendian and unaligned-capable */
*(uint32_t *) p = v;
#else
- p[0] = (v & 0xff);
- p[1] = ((v >> 8) & 0xff);
- p[2] = ((v >> 16) & 0xff);
- p[3] = ((v >> 24) & 0xff);
+ uint8_t *pp = (uint8_t *) p;
+ pp[0] = (v & 0xff);
+ pp[1] = ((v >> 8) & 0xff);
+ pp[2] = ((v >> 16) & 0xff);
+ pp[3] = ((v >> 24) & 0xff);
#endif
}
-#define SECTOR_SHIFT 9 /* 512-byte sectors */
-#define SECTOR_SIZE (1 << SECTOR_SHIFT)
+#define LDLINUX_MAGIC 0x3eb202fe
+
+/* Patch area for disk-based installers */
+struct patch_area {
+ uint32_t magic; /* LDLINUX_MAGIC */
+ uint32_t instance; /* Per-version value */
+ uint16_t data_sectors;
+ uint16_t adv_sectors;
+ uint32_t dwords;
+ uint32_t checksum;
+ uint32_t currentdir;
+ uint16_t secptroffset;
+ uint16_t secptrcnt;
+};
+
+ /* FAT bootsector format, also used by other disk-based derivatives */
+struct boot_sector {
+ uint8_t bsJump[3];
+ char bsOemName[8];
+ uint16_t bsBytesPerSec;
+ uint8_t bsSecPerClust;
+ uint16_t bsResSectors;
+ uint8_t bsFATs;
+ uint16_t bsRootDirEnts;
+ uint16_t bsSectors;
+ uint8_t bsMedia;
+ uint16_t bsFATsecs;
+ uint16_t bsSecPerTrack;
+ uint16_t bsHeads;
+ uint32_t bsHiddenSecs;
+ uint32_t bsHugeSectors;
+
+ union {
+ struct {
+ uint8_t DriveNumber;
+ uint8_t Reserved1;
+ uint8_t BootSignature;
+ uint32_t VolumeID;
+ char VolumeLabel[11];
+ char FileSysType[8];
+ uint8_t Code[442];
+ } __attribute__ ((packed)) bs16;
+ struct {
+ uint32_t FATSz32;
+ uint16_t ExtFlags;
+ uint16_t FSVer;
+ uint32_t RootClus;
+ uint16_t FSInfo;
+ uint16_t BkBootSec;
+ uint8_t DriveNumber;
+ uint8_t Reserved1;
+ uint8_t BootSignature;
+ uint32_t VolumeID;
+ char VolumeLabel[11];
+ char FileSysType[8];
+ uint8_t Code[414];
+ } __attribute__ ((packed)) bs32;
+ } __attribute__ ((packed));
+
+ uint32_t NextSector; /* Pointer to the first unused sector */
+ uint16_t MaxTransfer; /* Max sectors per transfer */
+ uint16_t bsSignature;
+} __attribute__ ((packed));
+
+#define bsHead bsJump
+#define bsHeadLen offsetof(struct boot_sector, bsOemName)
+#define bsCode bs32.Code /* The common safe choice */
+#define bsCodeLen (offsetof(struct boot_sector, bsSignature) - \
+ offsetof(struct boot_sector, bsCode))
#endif /* SYSLXINT_H */
diff --git a/libinstaller/syslxmod.c b/libinstaller/syslxmod.c
index 8d793a5c..9e1da440 100644
--- a/libinstaller/syslxmod.c
+++ b/libinstaller/syslxmod.c
@@ -1,6 +1,7 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
+ * Copyright 2009 Intel Corporation; author H. Peter Anvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,117 +23,16 @@
#include <stddef.h>
#include "syslinux.h"
+#include "syslxint.h"
-#define LDLINUX_MAGIC 0x3eb202fe
-
-enum bs_offsets {
- bsJump = 0x00,
- bsOemName = 0x03,
- bsBytesPerSec = 0x0b,
- bsSecPerClust = 0x0d,
- bsResSectors = 0x0e,
- bsFATs = 0x10,
- bsRootDirEnts = 0x11,
- bsSectors = 0x13,
- bsMedia = 0x15,
- bsFATsecs = 0x16,
- bsSecPerTrack = 0x18,
- bsHeads = 0x1a,
- bsHiddenSecs = 0x1c,
- bsHugeSectors = 0x20,
-
- /* FAT12/16 only */
- bs16DriveNumber = 0x24,
- bs16Reserved1 = 0x25,
- bs16BootSignature = 0x26,
- bs16VolumeID = 0x27,
- bs16VolumeLabel = 0x2b,
- bs16FileSysType = 0x36,
- bs16Code = 0x3e,
-
- /* FAT32 only */
- bs32FATSz32 = 36,
- bs32ExtFlags = 40,
- bs32FSVer = 42,
- bs32RootClus = 44,
- bs32FSInfo = 48,
- bs32BkBootSec = 50,
- bs32Reserved = 52,
- bs32DriveNumber = 64,
- bs32Reserved1 = 65,
- bs32BootSignature = 66,
- bs32VolumeID = 67,
- bs32VolumeLabel = 71,
- bs32FileSysType = 82,
- bs32Code = 90,
-
- bsSignature = 0x1fe
-};
-
-#define bsHead bsJump
-#define bsHeadLen (bsOemName-bsHead)
-#define bsCode bs32Code /* The common safe choice */
-#define bsCodeLen (bsSignature-bs32Code)
-
-/*
- * Access functions for littleendian numbers, possibly misaligned.
- */
-static inline uint8_t get_8(const unsigned char *p)
-{
- return *(const uint8_t *)p;
-}
-
-static inline uint16_t get_16(const unsigned char *p)
-{
-#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- return *(const uint16_t *)p;
-#else
- return (uint16_t) p[0] + ((uint16_t) p[1] << 8);
-#endif
-}
-
-static inline uint32_t get_32(const unsigned char *p)
-{
-#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- return *(const uint32_t *)p;
-#else
- return (uint32_t) p[0] + ((uint32_t) p[1] << 8) +
- ((uint32_t) p[2] << 16) + ((uint32_t) p[3] << 24);
-#endif
-}
-
-static inline void set_16(unsigned char *p, uint16_t v)
-{
-#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- *(uint16_t *) p = v;
-#else
- p[0] = (v & 0xff);
- p[1] = ((v >> 8) & 0xff);
-#endif
-}
-
-static inline void set_32(unsigned char *p, uint32_t v)
-{
-#if defined(__i386__) || defined(__x86_64__)
- /* Littleendian and unaligned-capable */
- *(uint32_t *) p = v;
-#else
- p[0] = (v & 0xff);
- p[1] = ((v >> 8) & 0xff);
- p[2] = ((v >> 16) & 0xff);
- p[3] = ((v >> 24) & 0xff);
-#endif
-}
+#define sbs ((struct boot_sector *)syslinux_bootsect)
void syslinux_make_bootsect(void *bs)
{
- unsigned char *bootsect = bs;
+ struct boot_sector *bootsect = bs;
- memcpy(bootsect + bsHead, syslinux_bootsect + bsHead, bsHeadLen);
- memcpy(bootsect + bsCode, syslinux_bootsect + bsCode, bsCodeLen);
+ memcpy(&bootsect->bsHead, &sbs->bsHead, bsHeadLen);
+ memcpy(&bootsect->bsCode, &sbs->bsCode, bsCodeLen);
}
/*
@@ -146,36 +46,37 @@ const char *syslinux_check_bootsect(const void *bs)
long long sectors, fatsectors, dsectors;
long long clusters;
int rootdirents, clustersize;
- const unsigned char *sectbuf = bs;
+ const struct boot_sector *sectbuf = bs;
veryold = 0;
/* Must be 0xF0 or 0xF8..0xFF */
- if (get_8(sectbuf + bsMedia) != 0xF0 && get_8(sectbuf + bsMedia) < 0xF8)
+ if (get_8(&sectbuf->bsMedia) != 0xF0 && get_8(&sectbuf->bsMedia) < 0xF8)
goto invalid;
- sectorsize = get_16(sectbuf + bsBytesPerSec);
- if (sectorsize == 512) ; /* ok */
- else if (sectorsize == 1024 || sectorsize == 2048 || sectorsize == 4096)
- return "only 512-byte sectors are supported";
+ sectorsize = get_16(&sectbuf->bsBytesPerSec);
+ if (sectorsize == SECTOR_SIZE) ; /* ok */
+ else if (sectorsize >= 512 && sectorsize <= 4096 &&
+ (sectorsize & (sectorsize - 1)) == 0)
+ return "unsupported sectors size";
else
goto invalid;
- clustersize = get_8(sectbuf + bsSecPerClust);
+ clustersize = get_8(&sectbuf->bsSecPerClust);
if (clustersize == 0 || (clustersize & (clustersize - 1)))
goto invalid; /* Must be nonzero and a power of 2 */
- sectors = get_16(sectbuf + bsSectors);
- sectors = sectors ? sectors : get_32(sectbuf + bsHugeSectors);
+ sectors = get_16(&sectbuf->bsSectors);
+ sectors = sectors ? sectors : get_32(&sectbuf->bsHugeSectors);
- dsectors = sectors - get_16(sectbuf + bsResSectors);
+ dsectors = sectors - get_16(&sectbuf->bsResSectors);
- fatsectors = get_16(sectbuf + bsFATsecs);
- fatsectors = fatsectors ? fatsectors : get_32(sectbuf + bs32FATSz32);
- fatsectors *= get_8(sectbuf + bsFATs);
+ fatsectors = get_16(&sectbuf->bsFATsecs);
+ fatsectors = fatsectors ? fatsectors : get_32(&sectbuf->bs32.FATSz32);
+ fatsectors *= get_8(&sectbuf->bsFATs);
dsectors -= fatsectors;
- rootdirents = get_16(sectbuf + bsRootDirEnts);
+ rootdirents = get_16(&sectbuf->bsRootDirEnts);
dsectors -= (rootdirents + sectorsize / 32 - 1) / sectorsize;
if (dsectors < 0 || fatsectors == 0)
@@ -186,28 +87,28 @@ const char *syslinux_check_bootsect(const void *bs)
if (clusters < 0xFFF5) {
/* FAT12 or FAT16 */
- if (!get_16(sectbuf + bsFATsecs))
+ if (!get_16(&sectbuf->bsFATsecs))
goto invalid;
- if (get_8(sectbuf + bs16BootSignature) == 0x29) {
- if (!memcmp(sectbuf + bs16FileSysType, "FAT12 ", 8)) {
+ if (get_8(&sectbuf->bs16.BootSignature) == 0x29) {
+ if (!memcmp(&sectbuf->bs16.FileSysType, "FAT12 ", 8)) {
if (clusters >= 0xFF5)
return "more than 4084 clusters but claims FAT12";
- } else if (!memcmp(sectbuf + bs16FileSysType, "FAT16 ", 8)) {
+ } else if (!memcmp(&sectbuf->bs16.FileSysType, "FAT16 ", 8)) {
if (clusters < 0xFF5)
return "less than 4084 clusters but claims FAT16";
- } else if (memcmp(sectbuf + bs16FileSysType, "FAT ", 8)) {
+ } else if (memcmp(&sectbuf->bs16.FileSysType, "FAT ", 8)) {
static char fserr[] =
"filesystem type \"????????\" not supported";
- memcpy(fserr + 17, sectbuf + bs16FileSysType, 8);
+ memcpy(fserr + 17, &sectbuf->bs16.FileSysType, 8);
return fserr;
}
}
} else if (clusters < 0x0FFFFFF5) {
/* FAT32 */
/* Moving the FileSysType and BootSignature was a lovely stroke of M$ idiocy */
- if (get_8(sectbuf + bs32BootSignature) != 0x29 ||
- memcmp(sectbuf + bs32FileSysType, "FAT32 ", 8))
+ if (get_8(&sectbuf->bs32.BootSignature) != 0x29 ||
+ memcmp(&sectbuf->bs32.FileSysType, "FAT32 ", 8))
goto invalid;
} else {
goto invalid;
@@ -220,22 +121,112 @@ invalid:
}
/*
- * This patches the boot sector and the first sector of ldlinux.sys
+ * Special handling for the MS-DOS derivative: syslinux_ldlinux
+ * is a "far" object...
+ */
+#ifdef __MSDOS__
+
+#define __noinline __attribute__((noinline))
+
+extern uint16_t ldlinux_seg; /* Defined in dos/syslinux.c */
+
+static inline __attribute__ ((const))
+uint16_t ds(void)
+{
+ uint16_t v;
+asm("movw %%ds,%0":"=rm"(v));
+ return v;
+}
+
+static inline void *set_fs(const void *p)
+{
+ uint16_t seg;
+
+ seg = ldlinux_seg + ((size_t) p >> 4);
+ asm volatile ("movw %0,%%fs"::"rm" (seg));
+ return (void *)((size_t) p & 0xf);
+}
+
+#if 0 /* unused */
+static __noinline uint8_t get_8_sl(const uint8_t * p)
+{
+ uint8_t v;
+
+ p = set_fs(p);
+ asm volatile ("movb %%fs:%1,%0":"=q" (v):"m"(*p));
+ return v;
+}
+#endif
+
+static __noinline uint16_t get_16_sl(const uint16_t * p)
+{
+ uint16_t v;
+
+ p = set_fs(p);
+ asm volatile ("movw %%fs:%1,%0":"=r" (v):"m"(*p));
+ return v;
+}
+
+static __noinline uint32_t get_32_sl(const uint32_t * p)
+{
+ uint32_t v;
+
+ p = set_fs(p);
+ asm volatile ("movl %%fs:%1,%0":"=r" (v):"m"(*p));
+ return v;
+}
+
+#if 0 /* unused */
+static __noinline void set_8_sl(uint8_t * p, uint8_t v)
+{
+ p = set_fs(p);
+ asm volatile ("movb %1,%%fs:%0":"=m" (*p):"qi"(v));
+}
+#endif
+
+static __noinline void set_16_sl(uint16_t * p, uint16_t v)
+{
+ p = set_fs(p);
+ asm volatile ("movw %1,%%fs:%0":"=m" (*p):"ri"(v));
+}
+
+static __noinline void set_32_sl(uint32_t * p, uint32_t v)
+{
+ p = set_fs(p);
+ asm volatile ("movl %1,%%fs:%0":"=m" (*p):"ri"(v));
+}
+
+#else
+
+/* Sane system ... */
+#define get_8_sl(x) get_8(x)
+#define get_16_sl(x) get_16(x)
+#define get_32_sl(x) get_32(x)
+#define set_8_sl(x,y) set_8(x,y)
+#define set_16_sl(x,y) set_16(x,y)
+#define set_32_sl(x,y) set_32(x,y)
+
+#endif
+
+/*
+ * This patches the boot sector and the beginning of ldlinux.sys
* based on an ldlinux.sys sector map passed in. Typically this is
* handled by writing ldlinux.sys, mapping it, and then overwrite it
* with the patched version. If this isn't safe to do because of
* an OS which does block reallocation, then overwrite it with
* direct access since the location is known.
*
- * Return 0 if successful, otherwise -1.
+ * Returns the number of modified bytes in ldlinux.sys if successful,
+ * otherwise -1.
*/
int syslinux_patch(const uint32_t * sectors, int nsectors,
int stupid, int raid_mode)
{
- unsigned char *patcharea, *p;
+ struct patch_area *patcharea;
+ uint32_t *wp;
int nsect = (syslinux_ldlinux_len + 511) >> 9;
uint32_t csum;
- int i, dw;
+ int i, dw, nptrs, rv;
if (nsectors < nsect)
return -1;
@@ -243,44 +234,51 @@ int syslinux_patch(const uint32_t * sectors, int nsectors,
/* Patch in options, as appropriate */
if (stupid) {
/* Access only one sector at a time */
- set_16(syslinux_bootsect + 0x1FC, 1);
+ set_16(&sbs->MaxTransfer, 1);
}
- i = get_16(syslinux_bootsect + 0x1FE);
+ i = get_16(&sbs->bsSignature);
if (raid_mode)
- set_16(syslinux_bootsect + i, 0x18CD); /* INT 18h */
- set_16(syslinux_bootsect + 0x1FE, 0xAA55);
+ set_16((uint16_t *) ((char *)sbs + i), 0x18CD); /* INT 18h */
+ set_16(&sbs->bsSignature, 0xAA55);
/* First sector need pointer in boot sector */
- set_32(syslinux_bootsect + 0x1F8, *sectors++);
- nsect--;
+ set_32(&sbs->NextSector, *sectors++);
/* Search for LDLINUX_MAGIC to find the patch area */
- for (p = syslinux_ldlinux; get_32(p) != LDLINUX_MAGIC; p += 4) ;
- patcharea = p + 8;
+ for (wp = (uint32_t *) syslinux_ldlinux; get_32_sl(wp) != LDLINUX_MAGIC;
+ wp++) ;
+ patcharea = (struct patch_area *)wp;
/* Set up the totals */
- dw = syslinux_ldlinux_len >> 2; /* COMPLETE dwords! */
- set_16(patcharea, dw);
- set_16(patcharea + 2, nsect); /* Does not include the first sector! */
+ dw = syslinux_ldlinux_len >> 2; /* COMPLETE dwords, excluding ADV */
+ set_16_sl(&patcharea->data_sectors, nsect); /* Not including ADVs */
+ set_16_sl(&patcharea->adv_sectors, 0); /* ADVs not supported yet */
+ set_32_sl(&patcharea->dwords, dw);
+ set_32_sl(&patcharea->currentdir, 0);
/* Set the sector pointers */
- p = patcharea + 8;
+ wp = (uint32_t *) ((char *)syslinux_ldlinux +
+ get_16_sl(&patcharea->secptroffset));
+ nptrs = get_16_sl(&patcharea->secptrcnt);
- memset(p, 0, 64 * 4);
while (nsect--) {
- set_32(p, *sectors++);
- p += 4;
+ set_32_sl(wp++, *sectors++);
+ nptrs--;
}
+ while (nptrs--)
+ set_32_sl(wp++, 0);
+
+ rv = (char *)wp - (char *)syslinux_ldlinux;
/* Now produce a checksum */
- set_32(patcharea + 4, 0);
+ set_32_sl(&patcharea->checksum, 0);
csum = LDLINUX_MAGIC;
- for (i = 0, p = syslinux_ldlinux; i < dw; i++, p += 4)
- csum -= get_32(p); /* Negative checksum */
+ for (i = 0, wp = (uint32_t *) syslinux_ldlinux; i < dw; i++, wp++)
+ csum -= get_32_sl(wp); /* Negative checksum */
- set_32(patcharea + 4, csum);
+ set_32_sl(&patcharea->checksum, csum);
- return 0;
+ return rv;
}