From a73b14259504d25e782df6cef4331fbd8710f575 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 22 Jun 2010 16:52:32 -0700 Subject: win32: vacuous ADV support Install an empty ADV in the Windows installer to keep it from being broken. In order to do that, separate the Unix-specific ADV I/O functions from the generic data structure manipulation. Signed-off-by: H. Peter Anvin --- libinstaller/setadv.c | 130 +------------------------------------------------- 1 file changed, 1 insertion(+), 129 deletions(-) (limited to 'libinstaller/setadv.c') diff --git a/libinstaller/setadv.c b/libinstaller/setadv.c index c891b87f..61f1f345 100644 --- a/libinstaller/setadv.c +++ b/libinstaller/setadv.c @@ -1,6 +1,7 @@ /* ----------------------------------------------------------------------- * * * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved + * Copyright 2010 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 @@ -26,12 +27,7 @@ #include #include #include -#include -#include #include -#include -#include -#include #include #include "syslxint.h" #include "syslxcom.h" @@ -170,127 +166,3 @@ int syslinux_validate_adv(unsigned char *advbuf) return -1; } } - -/* - * Read the ADV from an existing instance, or initialize if invalid. - * Returns -1 on fatal errors, 0 if ADV is okay, and 1 if no valid - * ADV was found. - */ -int read_adv(const char *path, const char *cfg) -{ - char *file; - int fd = -1; - struct stat st; - int err = 0; - - asprintf(&file, "%s%s%s", - path, path[0] && path[strlen(path) - 1] == '/' ? "" : "/", cfg); - - if (!file) { - perror(program); - return -1; - } - - fd = open(file, O_RDONLY); - if (fd < 0) { - if (errno != ENOENT) { - err = -1; - } else { - syslinux_reset_adv(syslinux_adv); - } - } else if (fstat(fd, &st)) { - err = -1; - } else if (st.st_size < 2 * ADV_SIZE) { - /* Too small to be useful */ - syslinux_reset_adv(syslinux_adv); - err = 0; /* Nothing to read... */ - } else if (xpread(fd, syslinux_adv, 2 * ADV_SIZE, - st.st_size - 2 * ADV_SIZE) != 2 * ADV_SIZE) { - err = -1; - } else { - /* We got it... maybe? */ - err = syslinux_validate_adv(syslinux_adv) ? 1 : 0; - } - - if (err < 0) - perror(file); - - if (fd >= 0) - close(fd); - - free(file); - - return err; -} - -/* - * Update the ADV in an existing installation. - */ -int write_adv(const char *path, const char *cfg) -{ - unsigned char advtmp[2 * ADV_SIZE]; - char *file; - int fd = -1; - struct stat st, xst; - int err = 0; - - err = asprintf(&file, "%s%s%s", - path, path[0] && path[strlen(path) - 1] == '/' ? "" : "/", cfg); - - if (!file) { - perror(program); - return -1; - } - - fd = open(file, O_RDONLY); - if (fd < 0) { - err = -1; - } else if (fstat(fd, &st)) { - err = -1; - } else if (st.st_size < 2 * ADV_SIZE) { - /* Too small to be useful */ - err = -2; - } else if (xpread(fd, advtmp, 2 * ADV_SIZE, - st.st_size - 2 * ADV_SIZE) != 2 * ADV_SIZE) { - err = -1; - } else { - /* We got it... maybe? */ - err = syslinux_validate_adv(advtmp) ? -2 : 0; - if (!err) { - /* Got a good one, write our own ADV here */ - clear_attributes(fd); - - /* Need to re-open read-write */ - close(fd); - fd = open(file, O_RDWR | O_SYNC); - if (fd < 0) { - err = -1; - } else if (fstat(fd, &xst) || xst.st_ino != st.st_ino || - xst.st_dev != st.st_dev || xst.st_size != st.st_size) { - fprintf(stderr, "%s: race condition on write\n", file); - err = -2; - } - /* Write our own version ... */ - if (xpwrite(fd, syslinux_adv, 2 * ADV_SIZE, - st.st_size - 2 * ADV_SIZE) != 2 * ADV_SIZE) { - err = -1; - } - - sync(); - set_attributes(fd); - } - } - - if (err == -2) - fprintf(stderr, "%s: cannot write auxilliary data (need --update)?\n", - file); - else if (err == -1) - perror(file); - - if (fd >= 0) - close(fd); - if (file) - free(file); - - return err; -} -- cgit v1.2.1