aboutsummaryrefslogtreecommitdiffstats
path: root/libinstaller/setadv.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-05-29 15:16:22 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-05-29 15:16:22 -0700
commit5e6aef0b866b1e5c1c458cc8ca2a52092928fb0d (patch)
treed88795d0d3aba72776a20bf8ee4c8778815df3d0 /libinstaller/setadv.c
parentdcd9ae222c665a56a57a560be62b407a04573e13 (diff)
parent8833b1c37f7ecfa41e0e2c26e72c2913d5eba969 (diff)
downloadsyslinux-5e6aef0b866b1e5c1c458cc8ca2a52092928fb0d.tar.gz
syslinux-5e6aef0b866b1e5c1c458cc8ca2a52092928fb0d.tar.xz
syslinux-5e6aef0b866b1e5c1c458cc8ca2a52092928fb0d.zip
Merge branch 'master' into core32
Conflicts: com32/include/netinet/in.h com32/include/sys/cpu.h dos/argv.c dos/malloc.c dos/syslinux.c extlinux/main.c libinstaller/setadv.c libinstaller/syslinux.h libinstaller/syslxint.h libinstaller/syslxmod.c linux/syslinux.c mtools/syslinux.c win32/syslinux.c Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'libinstaller/setadv.c')
-rw-r--r--libinstaller/setadv.c180
1 files changed, 90 insertions, 90 deletions
diff --git a/libinstaller/setadv.c b/libinstaller/setadv.c
index c57f0974..d18ac927 100644
--- a/libinstaller/setadv.c
+++ b/libinstaller/setadv.c
@@ -24,7 +24,7 @@
#include <errno.h>
#include "syslxint.h"
-unsigned char syslinux_adv[2*ADV_SIZE];
+unsigned char syslinux_adv[2 * ADV_SIZE];
#define ADV_MAGIC1 0x5a2d2fa5 /* Head signature */
#define ADV_MAGIC2 0xa3041767 /* Total checksum */
@@ -32,113 +32,113 @@ unsigned char syslinux_adv[2*ADV_SIZE];
static void cleanup_adv(unsigned char *advbuf)
{
- int i;
- uint32_t csum;
+ int i;
+ uint32_t csum;
- /* Make sure both copies agree, and update the checksum */
- set_32((uint32_t *)advbuf, ADV_MAGIC1);
+ /* Make sure both copies agree, and update the checksum */
+ set_32((uint32_t *) advbuf, ADV_MAGIC1);
- csum = ADV_MAGIC2;
- for (i = 8; i < ADV_SIZE-4; i += 4)
- csum -= get_32((uint32_t *)(advbuf+i));
+ csum = ADV_MAGIC2;
+ for (i = 8; i < ADV_SIZE - 4; i += 4)
+ csum -= get_32((uint32_t *) (advbuf + i));
- set_32((uint32_t *)(advbuf+4), csum);
- set_32((uint32_t *)(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);
+ memcpy(advbuf + ADV_SIZE, advbuf, ADV_SIZE);
}
int syslinux_setadv(int tag, size_t size, const void *data)
{
- uint8_t *p;
- size_t left;
- uint8_t advtmp[ADV_SIZE];
-
- if ((unsigned)tag-1 > 254) {
- errno = EINVAL;
- return -1; /* Impossible tag value */
- }
-
- if (size > 255) {
- errno = ENOSPC; /* Max 255 bytes for a data item */
- return -1;
- }
-
- left = ADV_LEN;
- p = advtmp;
- memcpy(p, syslinux_adv+2*4, left); /* Make working copy */
-
- while (left >= 2) {
- uint8_t ptag = p[0];
- size_t plen = p[1]+2;
-
- if (ptag == ADV_END)
- break;
-
- if (ptag == tag) {
- /* Found our tag. Delete it. */
-
- if (plen >= left) {
- /* Entire remainder is our tag */
- break;
- }
- memmove(p, p+plen, left-plen);
- } else {
- /* Not our tag */
- if (plen > left)
- break; /* Corrupt tag (overrun) - overwrite it */
+ uint8_t *p;
+ size_t left;
+ uint8_t advtmp[ADV_SIZE];
- left -= plen;
- p += plen;
+ if ((unsigned)tag - 1 > 254) {
+ errno = EINVAL;
+ return -1; /* Impossible tag value */
}
- }
- /* Now (p, left) reflects the position to write in and how much space
- we have for our data. */
+ if (size > 255) {
+ errno = ENOSPC; /* Max 255 bytes for a data item */
+ return -1;
+ }
- if (size) {
- if (left < size+2) {
- errno = ENOSPC; /* Not enough space for data */
- return -1;
+ left = ADV_LEN;
+ p = advtmp;
+ memcpy(p, syslinux_adv + 2 * 4, left); /* Make working copy */
+
+ while (left >= 2) {
+ uint8_t ptag = p[0];
+ size_t plen = p[1] + 2;
+
+ if (ptag == ADV_END)
+ break;
+
+ if (ptag == tag) {
+ /* Found our tag. Delete it. */
+
+ if (plen >= left) {
+ /* Entire remainder is our tag */
+ break;
+ }
+ memmove(p, p + plen, left - plen);
+ } else {
+ /* Not our tag */
+ if (plen > left)
+ break; /* Corrupt tag (overrun) - overwrite it */
+
+ left -= plen;
+ p += plen;
+ }
}
- *p++ = tag;
- *p++ = size;
- memcpy(p, data, size);
- p += size;
- left -= size+2;
- }
+ /* Now (p, left) reflects the position to write in and how much space
+ we have for our data. */
+
+ if (size) {
+ if (left < size + 2) {
+ errno = ENOSPC; /* Not enough space for data */
+ return -1;
+ }
- memset(p, 0, left);
+ *p++ = tag;
+ *p++ = size;
+ memcpy(p, data, size);
+ p += size;
+ left -= size + 2;
+ }
+
+ memset(p, 0, left);
- /* If we got here, everything went OK, commit the write */
- memcpy(syslinux_adv+2*4, advtmp, ADV_LEN);
- cleanup_adv(syslinux_adv);
+ /* If we got here, everything went OK, commit the write */
+ memcpy(syslinux_adv + 2 * 4, advtmp, ADV_LEN);
+ cleanup_adv(syslinux_adv);
- return 0;
+ return 0;
}
void syslinux_reset_adv(unsigned char *advbuf)
{
- /* Create an all-zero ADV */
- memset(advbuf+2*4, 0, ADV_LEN);
- cleanup_adv(advbuf);
+ /* Create an all-zero ADV */
+ memset(advbuf + 2 * 4, 0, ADV_LEN);
+ cleanup_adv(advbuf);
}
static int adv_consistent(const unsigned char *p)
{
- int i;
- uint32_t csum;
+ int i;
+ uint32_t csum;
- if (get_32((uint32_t *)p) != ADV_MAGIC1 ||
- get_32((uint32_t *)(p+ADV_SIZE-4)) != ADV_MAGIC3)
- return 0;
+ 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((uint32_t *)(p+i));
+ csum = 0;
+ for (i = 4; i < ADV_SIZE - 4; i += 4)
+ csum += get_32((uint32_t *) (p + i));
- return csum == ADV_MAGIC2;
+ return csum == ADV_MAGIC2;
}
/*
@@ -147,14 +147,14 @@ static int adv_consistent(const unsigned char *p)
*/
int syslinux_validate_adv(unsigned char *advbuf)
{
- if (adv_consistent(advbuf+0*ADV_SIZE)) {
- memcpy(advbuf+ADV_SIZE, advbuf, ADV_SIZE);
- return 0;
- } else if (adv_consistent(advbuf+1*ADV_SIZE)) {
- memcpy(advbuf, advbuf+ADV_SIZE, ADV_SIZE);
- return 0;
- } else {
- syslinux_reset_adv(advbuf);
- return -1;
- }
+ if (adv_consistent(advbuf + 0 * ADV_SIZE)) {
+ memcpy(advbuf + ADV_SIZE, advbuf, ADV_SIZE);
+ return 0;
+ } else if (adv_consistent(advbuf + 1 * ADV_SIZE)) {
+ memcpy(advbuf, advbuf + ADV_SIZE, ADV_SIZE);
+ return 0;
+ } else {
+ syslinux_reset_adv(advbuf);
+ return -1;
+ }
}