summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhpa <hpa>2004-12-22 20:39:06 +0000
committerhpa <hpa>2004-12-22 20:39:06 +0000
commit5994414ce681d9da3b7b3907e49c8ac4dd509b0f (patch)
treef50242c0c91c86eb394f1bb05cb8c27fb98e2460
parent5aa850e10e2a8463d49b438458c78d0c8c929b36 (diff)
downloadsyslinux-5994414ce681d9da3b7b3907e49c8ac4dd509b0f.tar.gz
Fix the -m and -a options for Win32; add support for a boot sector file
for Win32; minor cleanups.
-rw-r--r--NEWS11
-rw-r--r--dos/syslinux.c2
-rw-r--r--win32/syslinux.c64
3 files changed, 54 insertions, 23 deletions
diff --git a/NEWS b/NEWS
index defde736..d5bd2705 100644
--- a/NEWS
+++ b/NEWS
@@ -18,10 +18,10 @@ Changes in 3.00:
on the complexity.)
* EXTLINUX: New derivative, which boots from an ext2/ext3
filesystem.
- * SYSLINUX: The DOS installer can now optionally write the
- boot sector to a file instead of the real boot sector. This
- is currently not supported in any of the other installers,
- but should be added to the Win32 installer at some point.
+ * SYSLINUX: The DOS and Win32 installers can now optionally
+ write the boot sector to a file instead of the real boot
+ sector. This is not supported in the Linux installers,
+ however.
* ALL: New NOESCAPE command, disables the "hold down the Shift
key to display the prompt" behaviour.
* New simple menu system, as an alternative to the advanced
@@ -33,7 +33,8 @@ Changes in 3.00:
prefix. See pxelinux.doc.
* SYSLINUX: Add an -m option to the Win32 installer (only!)
to write an MBR and -a to mark the partition SYSLINUX is
- being installed on active.
+ being installed on active. This will hopefully be added
+ to the DOS installer later.
Changes in 2.13:
* MEMDISK: Fix command-line parsing "brown paper bag" class
diff --git a/dos/syslinux.c b/dos/syslinux.c
index 3c58edd1..ab161544 100644
--- a/dos/syslinux.c
+++ b/dos/syslinux.c
@@ -37,7 +37,7 @@ uint16_t dos_version;
void __attribute__((noreturn)) usage(void)
{
- puts("Usage: syslinux [-sf] drive: [bootsecfile]\n");
+ puts("Usage: syslinux [-sf] <drive>: [bootsecfile]\n");
exit(1);
}
diff --git a/win32/syslinux.c b/win32/syslinux.c
index 8cbea7c0..8429f785 100644
--- a/win32/syslinux.c
+++ b/win32/syslinux.c
@@ -1,6 +1,7 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2003 Lars Munch Christensen - All Rights Reserved
+ * Copyright 1998-2004 H. Peter Anvin - All Rights Reserved
*
* Based on the Linux installer program for SYSLINUX by H. Peter Anvin
*
@@ -23,6 +24,12 @@
#include "syslinux.h"
#include "libfat.h"
+#ifdef __GNUC__
+# define noreturn void __attribute__((noreturn))
+#else
+# define noreturn void
+#endif
+
void error(char* msg);
/* Begin stuff for MBR code */
@@ -52,7 +59,7 @@ BOOL GetStorageDeviceNumberByHandle( HANDLE handle, const STORAGE_DEVICE_NUMBER
result = TRUE;
}
else {
- error("GetDriveNumber: DeviceIoControl failed.");
+ error("GetDriveNumber: DeviceIoControl failed");
}
return( result );
@@ -158,8 +165,8 @@ BOOL FixMBR(int driveNum, int partitionNum, int write_mbr, int set_active) {
/* End stuff for MBR code */
-char *program; /* Name of program */
-char *drive; /* Drive to install to */
+const char *program; /* Name of program */
+const char *drive; /* Drive to install to */
/*
* Check Windows version.
@@ -224,9 +231,9 @@ int libfat_readfile(intptr_t pp, void *buf, size_t secsize, libfat_sector_t sect
return secsize;
}
-void usage(void)
+noreturn usage(void)
{
- fprintf(stderr, "Usage: syslinux.exe [-sfma] <drive>:\n");
+ fprintf(stderr, "Usage: syslinux.exe [-sfma] <drive>: [bootsecfile]\n");
exit(1);
}
@@ -248,6 +255,7 @@ int main(int argc, char *argv[])
libfat_sector_t s, *secp, sectors[65]; /* 65 is maximum possible */
uint32_t ldlinux_cluster;
int nsectors;
+ const char *bootsecfile = NULL;
int force = 0; /* -f (force) option */
int mbr = 0; /* -m (MBR) option */
@@ -284,9 +292,12 @@ int main(int argc, char *argv[])
opt++;
}
} else {
- if ( drive )
+ if ( bootsecfile )
usage();
- drive = *argp;
+ else if ( drive )
+ bootsecfile = *argp;
+ else
+ drive = *argp;
}
}
@@ -325,7 +336,7 @@ int main(int argc, char *argv[])
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL );
- if(d_handle == INVALID_HANDLE_VALUE) {
+ if (d_handle == INVALID_HANDLE_VALUE) {
error("Could not open drive");
exit(1);
}
@@ -333,8 +344,11 @@ int main(int argc, char *argv[])
/*
* Make sure we can read the boot sector
*/
- ReadFile(d_handle, sectbuf, 512, &bytes_read, NULL);
- if(bytes_read != 512) {
+ if ( !ReadFile(d_handle, sectbuf, 512, &bytes_read, NULL) ) {
+ error("Reading boot sector");
+ exit(1);
+ }
+ if (bytes_read != 512) {
fprintf(stderr, "Could not read the whole boot sector\n");
exit(1);
}
@@ -361,14 +375,13 @@ int main(int argc, char *argv[])
FILE_ATTRIBUTE_HIDDEN,
NULL );
- if(f_handle == INVALID_HANDLE_VALUE) {
+ if (f_handle == INVALID_HANDLE_VALUE) {
error("Unable to create ldlinux.sys");
exit(1);
}
/* Write ldlinux.sys file */
- if (!WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len, &bytes_written, NULL) ||
- bytes_written != syslinux_ldlinux_len ) {
+ if (!WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len, &bytes_written, NULL)) {
error("Could not write ldlinux.sys");
exit(1);
}
@@ -415,7 +428,7 @@ int main(int argc, char *argv[])
/* If desired, fix the MBR */
if( mbr || setactive ) {
STORAGE_DEVICE_NUMBER sdn;
- if( GetStorageDeviceNumberByHandle( f_handle, &sdn ) ) {
+ if( GetStorageDeviceNumberByHandle( d_handle, &sdn ) ) {
if( !FixMBR(sdn.DeviceNumber, sdn.PartitionNumber, mbr, setactive) ) {
fprintf(stderr, "Did not successfully update the MBR; continuing...\n");
}
@@ -431,14 +444,31 @@ int main(int argc, char *argv[])
syslinux_make_bootsect(sectbuf);
/* Write the syslinux boot sector into the boot sector */
- SetFilePointer(d_handle, 0, NULL, FILE_BEGIN);
- WriteFile( d_handle, sectbuf, 512, &bytes_written, NULL ) ;
+ if ( bootsecfile ) {
+ f_handle = CreateFile(bootsecfile, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_ARCHIVE,
+ NULL );
+ if (f_handle == INVALID_HANDLE_VALUE) {
+ error("Unable to create bootsector file");
+ exit(1);
+ }
+ if (!WriteFile(f_handle, sectbuf, 512, &bytes_written, NULL)) {
+ error("Could not write boot sector file");
+ exit(1);
+ }
+ CloseHandle(f_handle);
+ } else {
+ SetFilePointer(d_handle, 0, NULL, FILE_BEGIN);
+ WriteFile( d_handle, sectbuf, 512, &bytes_written, NULL ) ;
+ }
if(bytes_written != 512) {
fprintf(stderr, "Could not write the whole boot sector\n");
exit(1);
}
-
+
/* Close file */
CloseHandle(d_handle);