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
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
/* ----------------------------------------------------------------------- *
*
* 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
*
#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 */
result = TRUE;
}
else {
- error("GetDriveNumber: DeviceIoControl failed.");
+ error("GetDriveNumber: DeviceIoControl failed");
}
return( result );
/* 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.
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);
}
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 */
opt++;
}
} else {
- if ( drive )
+ if ( bootsecfile )
usage();
- drive = *argp;
+ else if ( drive )
+ bootsecfile = *argp;
+ else
+ drive = *argp;
}
}
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);
}
/*
* 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);
}
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);
}
/* 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");
}
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);