* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* COPYRIGHT: See COPYING in the top level directory
#define SECTORSIZE 512
+#include <pshpack1.h>
+typedef struct _FAT_BOOTSECTOR
+{
+ UCHAR JumpBoot[3]; // Jump instruction to boot code
+ CHAR OemName[8]; // "MSWIN4.1" for MS formatted volumes
+ USHORT BytesPerSector; // Bytes per sector
+ UCHAR SectorsPerCluster; // Number of sectors in a cluster
+ USHORT ReservedSectors; // Reserved sectors, usually 1 (the bootsector)
+ UCHAR NumberOfFats; // Number of FAT tables
+ USHORT RootDirEntries; // Number of root directory entries (fat12/16)
+ USHORT TotalSectors; // Number of total sectors on the drive, 16-bit
+ UCHAR MediaDescriptor; // Media descriptor byte
+ USHORT SectorsPerFat; // Sectors per FAT table (fat12/16)
+ USHORT SectorsPerTrack; // Number of sectors in a track
+ USHORT NumberOfHeads; // Number of heads on the disk
+ ULONG HiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
+ ULONG TotalSectorsBig; // This field is the new 32-bit total count of sectors on the volume
+ UCHAR DriveNumber; // Int 0x13 drive number (e.g. 0x80)
+ UCHAR Reserved1; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
+ UCHAR BootSignature; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
+ ULONG VolumeSerialNumber; // Volume serial number
+ CHAR VolumeLabel[11]; // Volume label. This field matches the 11-byte volume label recorded in the root directory
+ CHAR FileSystemType[8]; // One of the strings "FAT12 ", "FAT16 ", or "FAT "
+
+ UCHAR BootCodeAndData[448]; // The remainder of the boot sector
+
+ USHORT BootSectorMagic; // 0xAA55
+
+} FAT_BOOTSECTOR, *PFAT_BOOTSECTOR;
+
+typedef struct _FAT32_BOOTSECTOR
+{
+ UCHAR JumpBoot[3]; // Jump instruction to boot code
+ CHAR OemName[8]; // "MSWIN4.1" for MS formatted volumes
+ USHORT BytesPerSector; // Bytes per sector
+ UCHAR SectorsPerCluster; // Number of sectors in a cluster
+ USHORT ReservedSectors; // Reserved sectors, usually 1 (the bootsector)
+ UCHAR NumberOfFats; // Number of FAT tables
+ USHORT RootDirEntries; // Number of root directory entries (fat12/16)
+ USHORT TotalSectors; // Number of total sectors on the drive, 16-bit
+ UCHAR MediaDescriptor; // Media descriptor byte
+ USHORT SectorsPerFat; // Sectors per FAT table (fat12/16)
+ USHORT SectorsPerTrack; // Number of sectors in a track
+ USHORT NumberOfHeads; // Number of heads on the disk
+ ULONG HiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
+ ULONG TotalSectorsBig; // This field is the new 32-bit total count of sectors on the volume
+ ULONG SectorsPerFatBig; // This field is the FAT32 32-bit count of sectors occupied by ONE FAT. BPB_FATSz16 must be 0
+ USHORT ExtendedFlags; // Extended flags (fat32)
+ USHORT FileSystemVersion; // File system version (fat32)
+ ULONG RootDirStartCluster; // Starting cluster of the root directory (fat32)
+ USHORT FsInfo; // Sector number of FSINFO structure in the reserved area of the FAT32 volume. Usually 1.
+ USHORT BackupBootSector; // If non-zero, indicates the sector number in the reserved area of the volume of a copy of the boot record. Usually 6.
+ UCHAR Reserved[12]; // Reserved for future expansion
+ UCHAR DriveNumber; // Int 0x13 drive number (e.g. 0x80)
+ UCHAR Reserved1; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
+ UCHAR BootSignature; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
+ ULONG VolumeSerialNumber; // Volume serial number
+ CHAR VolumeLabel[11]; // Volume label. This field matches the 11-byte volume label recorded in the root directory
+ CHAR FileSystemType[8]; // Always set to the string "FAT32 "
+
+ UCHAR BootCodeAndData[420]; // The remainder of the boot sector
+
+ USHORT BootSectorMagic; // 0xAA55
+
+} FAT32_BOOTSECTOR, *PFAT32_BOOTSECTOR;
+#include <poppack.h>
+
+extern PPARTLIST PartitionList;
+
/* FUNCTIONS ****************************************************************/
IniSection = IniCacheAppendSection(IniCache,
L"FREELOADER");
-#ifdef DBG
+#if DBG
if (IsUnattendedSetup)
{
/* DefaultOS=ReactOS */
NULL,
INSERT_LAST,
L"DefaultOS",
- L"ReactOS_Debug");
+ L"ReactOS_KdSerial");
}
else
#endif
L"ReactOS");
}
-#ifdef DBG
+#if DBG
if (IsUnattendedSetup)
#endif
{
L"TimeOut",
L"0");
}
-#ifdef DBG
+#if DBG
else
{
/* Timeout=0 or 10 */
L"SystemPath",
ArcPath);
- /* Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS*/
+ /* Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
}
+NTSTATUS
+CreateFreeLoaderEntry(
+ PINICACHE IniCache,
+ PINICACHESECTION OSSection,
+ PWCHAR Section,
+ PWCHAR Description,
+ PWCHAR BootType,
+ PWCHAR ArcPath,
+ PWCHAR Options)
+{
+ PINICACHESECTION IniSection;
+
+ /* Insert entry into "Operating Systems" section */
+ IniCacheInsertKey(OSSection,
+ NULL,
+ INSERT_LAST,
+ Section,
+ Description);
+
+ /* Create new section */
+ IniSection = IniCacheAppendSection(IniCache, Section);
+
+ /* BootType= */
+ IniCacheInsertKey(IniSection,
+ NULL,
+ INSERT_LAST,
+ L"BootType",
+ BootType);
+
+ /* SystemPath= */
+ IniCacheInsertKey(IniSection,
+ NULL,
+ INSERT_LAST,
+ L"SystemPath",
+ ArcPath);
+
+ /* Options=*/
+ IniCacheInsertKey(IniSection,
+ NULL,
+ INSERT_LAST,
+ L"Options",
+ Options);
+
+ return STATUS_SUCCESS;
+}
+
NTSTATUS
CreateFreeLoaderIniForReactos(PWCHAR IniPath,
PWCHAR ArcPath)
IniSection = IniCacheAppendSection(IniCache,
L"Operating Systems");
- /* ReactOS="ReactOS" */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"ReactOS",
- L"\"ReactOS\"");
-
- /* ReactOS_Debug="ReactOS (Debug)" */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"ReactOS_Debug",
- L"\"ReactOS (Debug)\"");
-
-#ifdef DBG
- /* ReactOS_WinLdr="ReactOS (WinLdr)" */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"ReactOS_WinLdr",
- L"\"ReactOS (WinLdr)\"");
-
- /* ReactOS_Ram="ReactOS (RAM Disk)" */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"ReactOS_Ram",
- L"\"ReactOS (RAM Disk)\"");
-#endif
-
- /* Create "ReactOS" section */
- IniSection = IniCacheAppendSection(IniCache,
- L"ReactOS");
-
- /* BootType=ReactOS */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"BootType",
- L"ReactOS");
-
- /* SystemPath=<ArcPath> */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"SystemPath",
- ArcPath);
-
- /* Options=*/
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"Options",
- L"");
-
- /* Create "ReactOS_Debug" section */
- IniSection = IniCacheAppendSection(IniCache,
- L"ReactOS_Debug");
-
- /* BootType=ReactOS */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"BootType",
- L"ReactOS");
-
- /* SystemPath=<ArcPath> */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"SystemPath",
- ArcPath);
-
- /* Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS*/
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"Options",
- L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS");
-
-#ifdef DBG
- /* Create "ReactOS_WinLdr" section */
- IniSection = IniCacheAppendSection(IniCache,
- L"ReactOS_WinLdr");
-
- /* BootType=Windows2003 */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"BootType",
- L"Windows2003");
-
- /* SystemPath=<ArcPath> */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"SystemPath",
- ArcPath);
-
- /* Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS*/
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"Options",
- L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS");
-
- /* Create "ReactOS_WinLdr" section */
- IniSection = IniCacheAppendSection(IniCache,
- L"ReactOS_Ram");
-
- /* BootType=ReactOS */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"BootType",
- L"ReactOS");
-
- /* SystemPath=ramdisk(0)\\ReactOS */
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"SystemPath",
- L"ramdisk(0)\\ReactOS");
-
- /* Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /RDIMAGEPATH=reactos.img /RDIMAGEOFFSET=32256*/
- IniCacheInsertKey(IniSection,
- NULL,
- INSERT_LAST,
- L"Options",
- L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /RDIMAGEPATH=reactos.img /RDIMAGEOFFSET=32256");
+ /* ReactOS */
+ CreateFreeLoaderEntry(IniCache, IniSection,
+ L"ReactOS", L"\"ReactOS\"",
+ L"Windows2003", ArcPath,
+ L"");
+
+ /* ReactOS_Debug */
+ CreateFreeLoaderEntry(IniCache, IniSection,
+ L"ReactOS_Debug", L"\"ReactOS (Debug)\"",
+ L"Windows2003", ArcPath,
+ L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS");
+
+#if DBG
+ /* ReactOS_KdSerial */
+ CreateFreeLoaderEntry(IniCache, IniSection,
+ L"ReactOS_KdSerial", L"\"ReactOS (RosDbg)\"",
+ L"Windows2003", ArcPath,
+ L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /KDSERIAL");
+
+ /* ReactOS_LogFile */
+ CreateFreeLoaderEntry(IniCache, IniSection,
+ L"ReactOS_LogFile", L"\"ReactOS (Log file)\"",
+ L"Windows2003", ArcPath,
+ L"/DEBUG /DEBUGPORT=FILE /SOS");
+
+ /* ReactOS_Ram */
+ CreateFreeLoaderEntry(IniCache, IniSection,
+ L"ReactOS_Ram", L"\"ReactOS (RAM Disk)\"",
+ L"ReactOS", L"ramdisk(0)\\ReactOS",
+ L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS /RDIMAGEPATH=reactos.img /RDIMAGEOFFSET=32256");
#endif
/* Save the ini file */
InstallMbrBootCodeToDisk (PWSTR SrcPath,
PWSTR RootPath)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
- IO_STATUS_BLOCK IoStatusBlock;
- UNICODE_STRING Name;
- HANDLE FileHandle;
- NTSTATUS Status;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ UNICODE_STRING Name;
+ HANDLE FileHandle;
+ NTSTATUS Status;
PPARTITION_SECTOR OrigBootSector;
PPARTITION_SECTOR NewBootSector;
- /* Allocate buffer for original bootsector */
+ /* Allocate buffer for original bootsector */
OrigBootSector = (PPARTITION_SECTOR)RtlAllocateHeap(ProcessHeap,
0,
sizeof(PARTITION_SECTOR));
if (OrigBootSector == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
- /* Read current boot sector into buffer */
+ /* Read current boot sector into buffer */
RtlInitUnicodeString(&Name,
RootPath);
- InitializeObjectAttributes(&ObjectAttributes,
- &Name,
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL);
-
- Status = NtOpenFile(&FileHandle,
- GENERIC_READ,
- &ObjectAttributes,
- &IoStatusBlock,
- 0,
- FILE_SYNCHRONOUS_IO_NONALERT);
+ InitializeObjectAttributes(&ObjectAttributes,
+ &Name,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ Status = NtOpenFile(&FileHandle,
+ GENERIC_READ,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ 0,
+ FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
return(Status);
}
- Status = NtReadFile(FileHandle,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
+ Status = NtReadFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatusBlock,
OrigBootSector,
- SECTORSIZE,
- NULL,
- NULL);
- NtClose(FileHandle);
+ SECTORSIZE,
+ NULL,
+ NULL);
+ NtClose(FileHandle);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
UNICODE_STRING Name;
HANDLE FileHandle;
NTSTATUS Status;
- PUCHAR OrigBootSector;
- PUCHAR NewBootSector;
+ PFAT_BOOTSECTOR OrigBootSector;
+ PFAT_BOOTSECTOR NewBootSector;
+ PARTITION_INFORMATION *PartInfo;
/* Allocate buffer for original bootsector */
- OrigBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap,
+ OrigBootSector = RtlAllocateHeap(ProcessHeap,
0,
SECTORSIZE);
if (OrigBootSector == NULL)
/* Allocate buffer for new bootsector */
- NewBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap,
+ NewBootSector = RtlAllocateHeap(ProcessHeap,
0,
SECTORSIZE);
if (NewBootSector == NULL)
}
/* Adjust bootsector (copy a part of the FAT16 BPB) */
- memcpy((NewBootSector + 3),
- (OrigBootSector + 3),
- 59); /* FAT16 BPB length*/
+ memcpy(&NewBootSector->BytesPerSector,
+ &OrigBootSector->BytesPerSector,
+ 51); /* FAT16 BPB length */
+
+ PartInfo = &PartitionList->CurrentPartition->PartInfo[PartitionList->CurrentPartitionNumber];
+ NewBootSector->HiddenSectors = PartInfo->HiddenSectors;
/* Free the original boot sector */
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
UNICODE_STRING Name;
HANDLE FileHandle;
NTSTATUS Status;
- PUCHAR OrigBootSector;
- PUCHAR NewBootSector;
+ PFAT32_BOOTSECTOR OrigBootSector;
+ PFAT32_BOOTSECTOR NewBootSector;
LARGE_INTEGER FileOffset;
USHORT BackupBootSector;
+ PARTITION_INFORMATION *PartInfo;
/* Allocate buffer for original bootsector */
- OrigBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap,
+ OrigBootSector = RtlAllocateHeap(ProcessHeap,
0,
SECTORSIZE);
if (OrigBootSector == NULL)
/* Allocate buffer for new bootsector (2 sectors) */
- NewBootSector = (PUCHAR)RtlAllocateHeap(ProcessHeap,
+ NewBootSector = RtlAllocateHeap(ProcessHeap,
0,
2 * SECTORSIZE);
if (NewBootSector == NULL)
}
/* Adjust bootsector (copy a part of the FAT32 BPB) */
- memcpy((NewBootSector + 3),
- (OrigBootSector + 3),
- 87); /* FAT32 BPB length */
+ memcpy(&NewBootSector->BytesPerSector,
+ &OrigBootSector->BytesPerSector,
+ 79); /* FAT32 BPB length */
+
+ PartInfo = &PartitionList->CurrentPartition->PartInfo[PartitionList->CurrentPartitionNumber];
+ NewBootSector->HiddenSectors = PartInfo->HiddenSectors;
/* Get the location of the backup boot sector */
- BackupBootSector = (OrigBootSector[0x33] << 8) + OrigBootSector[0x32];
+ BackupBootSector = OrigBootSector->BackupBootSector;
/* Free the original boot sector */
RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
NULL,
NULL,
&IoStatusBlock,
- (NewBootSector + SECTORSIZE),
+ ((PUCHAR)NewBootSector + SECTORSIZE),
SECTORSIZE,
&FileOffset,
NULL);
#endif
}
+NTSTATUS
+InstallVBRToPartition(PUNICODE_STRING SystemRootPath,
+ PUNICODE_STRING SourceRootPath,
+ PUNICODE_STRING DestinationArcPath,
+ UCHAR PartitionType)
+{
+ if ((PartitionType == PARTITION_FAT_12) ||
+ (PartitionType == PARTITION_FAT_16) ||
+ (PartitionType == PARTITION_HUGE) ||
+ (PartitionType == PARTITION_XINT13) ||
+ (PartitionType == PARTITION_FAT32) ||
+ (PartitionType == PARTITION_FAT32_XINT13))
+ {
+ return InstallFatBootcodeToPartition(SystemRootPath,
+ SourceRootPath,
+ DestinationArcPath,
+ PartitionType);
+ }
+
+ return STATUS_UNSUCCESSFUL;
+}
+
NTSTATUS
InstallFatBootcodeToFloppy(PUNICODE_STRING SourceRootPath,