Author: hbelusca
Date: Wed May 31 01:47:39 2017
New Revision: 74714

URL: http://svn.reactos.org/svn/reactos?rev=74714&view=rev
Log:
[USETUP]: Move some functions around, but no functional code changes otherwise.

Modified:
    branches/setup_improvements/base/setup/usetup/bootsup.c

Modified: branches/setup_improvements/base/setup/usetup/bootsup.c
URL: 
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/usetup/bootsup.c?rev=74714&r1=74713&r2=74714&view=diff
==============================================================================
--- branches/setup_improvements/base/setup/usetup/bootsup.c     [iso-8859-1] 
(original)
+++ branches/setup_improvements/base/setup/usetup/bootsup.c     [iso-8859-1] 
Wed May 31 01:47:39 2017
@@ -626,6 +626,204 @@
     return STATUS_SUCCESS;
 }
 
+static
+NTSTATUS
+UnprotectBootIni(
+    PWSTR FileName,
+    PULONG Attributes)
+{
+    NTSTATUS Status;
+    UNICODE_STRING Name;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    IO_STATUS_BLOCK IoStatusBlock;
+    FILE_BASIC_INFORMATION FileInfo;
+    HANDLE FileHandle;
+
+    RtlInitUnicodeString(&Name, FileName);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (Status == STATUS_NO_SUCH_FILE)
+    {
+        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
+        *Attributes = 0;
+        return STATUS_SUCCESS;
+    }
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
+        return Status;
+    }
+
+    Status = NtQueryInformationFile(FileHandle,
+                                    &IoStatusBlock,
+                                    &FileInfo,
+                                    sizeof(FILE_BASIC_INFORMATION),
+                                    FileBasicInformation);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status);
+        NtClose(FileHandle);
+        return Status;
+    }
+
+    *Attributes = FileInfo.FileAttributes;
+
+    /* Delete attributes SYSTEM, HIDDEN and READONLY */
+    FileInfo.FileAttributes = FileInfo.FileAttributes &
+                              ~(FILE_ATTRIBUTE_SYSTEM |
+                                FILE_ATTRIBUTE_HIDDEN |
+                                FILE_ATTRIBUTE_READONLY);
+
+    Status = NtSetInformationFile(FileHandle,
+                                  &IoStatusBlock,
+                                  &FileInfo,
+                                  sizeof(FILE_BASIC_INFORMATION),
+                                  FileBasicInformation);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status);
+    }
+
+    NtClose(FileHandle);
+    return Status;
+}
+
+static
+NTSTATUS
+ProtectBootIni(
+    PWSTR FileName,
+    ULONG Attributes)
+{
+    NTSTATUS Status;
+    UNICODE_STRING Name;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    IO_STATUS_BLOCK IoStatusBlock;
+    FILE_BASIC_INFORMATION FileInfo;
+    HANDLE FileHandle;
+
+    RtlInitUnicodeString(&Name, FileName);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
+        return Status;
+    }
+
+    Status = NtQueryInformationFile(FileHandle,
+                                    &IoStatusBlock,
+                                    &FileInfo,
+                                    sizeof(FILE_BASIC_INFORMATION),
+                                    FileBasicInformation);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status);
+        NtClose(FileHandle);
+        return Status;
+    }
+
+    FileInfo.FileAttributes = FileInfo.FileAttributes | Attributes;
+
+    Status = NtSetInformationFile(FileHandle,
+                                  &IoStatusBlock,
+                                  &FileInfo,
+                                  sizeof(FILE_BASIC_INFORMATION),
+                                  FileBasicInformation);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status);
+    }
+
+    NtClose(FileHandle);
+    return Status;
+}
+
+static
+NTSTATUS
+UpdateBootIni(
+    PWSTR BootIniPath,
+    PWSTR EntryName,
+    PWSTR EntryValue)
+{
+    NTSTATUS Status;
+    PINICACHE Cache = NULL;
+    PINICACHESECTION Section = NULL;
+    ULONG FileAttribute;
+    PWCHAR OldValue = NULL;
+
+    Status = IniCacheLoad(&Cache, BootIniPath, FALSE);
+    if (!NT_SUCCESS(Status))
+    {
+        return Status;
+    }
+
+    Section = IniCacheGetSection(Cache,
+                                 L"operating systems");
+    if (Section == NULL)
+    {
+        IniCacheDestroy(Cache);
+        return STATUS_UNSUCCESSFUL;
+    }
+
+    /* Check - maybe record already exists */
+    Status = IniCacheGetKey(Section, EntryName, &OldValue);
+
+    /* If either key was not found, or contains something else - add new one */
+    if (!NT_SUCCESS(Status) || wcscmp(OldValue, EntryValue))
+    {
+        IniCacheInsertKey(Section,
+                          NULL,
+                          INSERT_LAST,
+                          EntryName,
+                          EntryValue);
+    }
+
+    Status = UnprotectBootIni(BootIniPath,
+                              &FileAttribute);
+    if (!NT_SUCCESS(Status))
+    {
+        IniCacheDestroy(Cache);
+        return Status;
+    }
+
+    Status = IniCacheSave(Cache, BootIniPath);
+    if (!NT_SUCCESS(Status))
+    {
+        IniCacheDestroy(Cache);
+        return Status;
+    }
+
+    FileAttribute |= (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | 
FILE_ATTRIBUTE_READONLY);
+    Status = ProtectBootIni(BootIniPath, FileAttribute);
+
+    IniCacheDestroy(Cache);
+
+    return Status;
+}
+
+
 BOOLEAN
 IsThereAValidBootSector(PWSTR RootPath)
 {
@@ -799,6 +997,323 @@
     return Status;
 }
 
+
+NTSTATUS
+InstallMbrBootCodeToDisk(
+    PWSTR SrcPath,
+    PWSTR RootPath)
+{
+    NTSTATUS Status;
+    UNICODE_STRING Name;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    IO_STATUS_BLOCK IoStatusBlock;
+    HANDLE FileHandle;
+    LARGE_INTEGER FileOffset;
+    PPARTITION_SECTOR OrigBootSector;
+    PPARTITION_SECTOR NewBootSector;
+
+    /* 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 */
+    RtlInitUnicodeString(&Name,
+                         RootPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_READ | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return Status;
+    }
+
+    FileOffset.QuadPart = 0ULL;
+    Status = NtReadFile(FileHandle,
+                        NULL,
+                        NULL,
+                        NULL,
+                        &IoStatusBlock,
+                        OrigBootSector,
+                        sizeof(PARTITION_SECTOR),
+                        &FileOffset,
+                        NULL);
+    NtClose(FileHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return Status;
+    }
+
+    /* Allocate buffer for new bootsector */
+    NewBootSector = (PPARTITION_SECTOR)RtlAllocateHeap(ProcessHeap,
+                    0,
+                    sizeof(PARTITION_SECTOR));
+    if (NewBootSector == NULL)
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    /* Read new bootsector from SrcPath */
+    RtlInitUnicodeString(&Name, SrcPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_READ | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    Status = NtReadFile(FileHandle,
+                        NULL,
+                        NULL,
+                        NULL,
+                        &IoStatusBlock,
+                        NewBootSector,
+                        sizeof(PARTITION_SECTOR),
+                        NULL,
+                        NULL);
+    NtClose(FileHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    /*
+     * Copy the disk signature, the reserved fields and
+     * the partition table from the old MBR to the new one.
+     */
+    RtlCopyMemory(&NewBootSector->Signature,
+                  &OrigBootSector->Signature,
+                  sizeof(PARTITION_SECTOR) - offsetof(PARTITION_SECTOR, 
Signature) /* Length of partition table */);
+
+    /* Free the original boot sector */
+    RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+
+    /* Write new bootsector to RootPath */
+    RtlInitUnicodeString(&Name, RootPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               0,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_WRITE | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    FileOffset.QuadPart = 0ULL;
+    Status = NtWriteFile(FileHandle,
+                         NULL,
+                         NULL,
+                         NULL,
+                         &IoStatusBlock,
+                         NewBootSector,
+                         sizeof(PARTITION_SECTOR),
+                         &FileOffset,
+                         NULL);
+    NtClose(FileHandle);
+
+    /* Free the new boot sector */
+    RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+
+    return Status;
+}
+
+static
+NTSTATUS
+InstallFat12BootCodeToFloppy(
+    PWSTR SrcPath,
+    PWSTR RootPath)
+{
+    NTSTATUS Status;
+    UNICODE_STRING Name;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    IO_STATUS_BLOCK IoStatusBlock;
+    HANDLE FileHandle;
+    LARGE_INTEGER FileOffset;
+    PFAT_BOOTSECTOR OrigBootSector;
+    PFAT_BOOTSECTOR NewBootSector;
+
+    /* Allocate buffer for original bootsector */
+    OrigBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE);
+    if (OrigBootSector == NULL)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    /* Read current boot sector into buffer */
+    RtlInitUnicodeString(&Name, RootPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_READ | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return Status;
+    }
+
+    FileOffset.QuadPart = 0ULL;
+    Status = NtReadFile(FileHandle,
+                        NULL,
+                        NULL,
+                        NULL,
+                        &IoStatusBlock,
+                        OrigBootSector,
+                        SECTORSIZE,
+                        &FileOffset,
+                        NULL);
+    NtClose(FileHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return Status;
+    }
+
+    /* Allocate buffer for new bootsector */
+    NewBootSector = RtlAllocateHeap(ProcessHeap,
+                                    0,
+                                    SECTORSIZE);
+    if (NewBootSector == NULL)
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    /* Read new bootsector from SrcPath */
+    RtlInitUnicodeString(&Name, SrcPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_READ | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    Status = NtReadFile(FileHandle,
+                        NULL,
+                        NULL,
+                        NULL,
+                        &IoStatusBlock,
+                        NewBootSector,
+                        SECTORSIZE,
+                        NULL,
+                        NULL);
+    NtClose(FileHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    /* Adjust bootsector (copy a part of the FAT16 BPB) */
+    memcpy(&NewBootSector->OemName,
+           &OrigBootSector->OemName,
+           FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
+           FIELD_OFFSET(FAT_BOOTSECTOR, OemName));
+
+    /* Free the original boot sector */
+    RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+
+    /* Write new bootsector to RootPath */
+    RtlInitUnicodeString(&Name, RootPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               0,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_WRITE | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    FileOffset.QuadPart = 0ULL;
+    Status = NtWriteFile(FileHandle,
+                         NULL,
+                         NULL,
+                         NULL,
+                         &IoStatusBlock,
+                         NewBootSector,
+                         SECTORSIZE,
+                         &FileOffset,
+                         NULL);
+    NtClose(FileHandle);
+
+    /* Free the new boot sector */
+    RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+
+    return Status;
+}
+
 static
 NTSTATUS
 InstallFat16BootCodeToFile(
@@ -961,6 +1476,160 @@
 
 static
 NTSTATUS
+InstallFat16BootCodeToDisk(
+    PWSTR SrcPath,
+    PWSTR RootPath)
+{
+    NTSTATUS Status;
+    UNICODE_STRING Name;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    IO_STATUS_BLOCK IoStatusBlock;
+    HANDLE FileHandle;
+    LARGE_INTEGER FileOffset;
+    PFAT_BOOTSECTOR OrigBootSector;
+    PFAT_BOOTSECTOR NewBootSector;
+
+    /* Allocate buffer for original bootsector */
+    OrigBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE);
+    if (OrigBootSector == NULL)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    /* Read current boot sector into buffer */
+    RtlInitUnicodeString(&Name, RootPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_READ | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return Status;
+    }
+
+    FileOffset.QuadPart = 0ULL;
+    Status = NtReadFile(FileHandle,
+                        NULL,
+                        NULL,
+                        NULL,
+                        &IoStatusBlock,
+                        OrigBootSector,
+                        SECTORSIZE,
+                        &FileOffset,
+                        NULL);
+    NtClose(FileHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return Status;
+    }
+
+    /* Allocate buffer for new bootsector */
+    NewBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE);
+    if (NewBootSector == NULL)
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    /* Read new bootsector from SrcPath */
+    RtlInitUnicodeString(&Name, SrcPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_READ | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    Status = NtReadFile(FileHandle,
+                        NULL,
+                        NULL,
+                        NULL,
+                        &IoStatusBlock,
+                        NewBootSector,
+                        SECTORSIZE,
+                        NULL,
+                        NULL);
+    NtClose(FileHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    /* Adjust bootsector (copy a part of the FAT16 BPB) */
+    memcpy(&NewBootSector->OemName,
+           &OrigBootSector->OemName,
+           FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
+           FIELD_OFFSET(FAT_BOOTSECTOR, OemName));
+
+    /* Free the original boot sector */
+    RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
+
+    /* Write new bootsector to RootPath */
+    RtlInitUnicodeString(&Name, RootPath);
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Name,
+                               0,
+                               NULL,
+                               NULL);
+
+    Status = NtOpenFile(&FileHandle,
+                        GENERIC_WRITE | SYNCHRONIZE,
+                        &ObjectAttributes,
+                        &IoStatusBlock,
+                        0,
+                        FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
+        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+        return Status;
+    }
+
+    FileOffset.QuadPart = 0ULL;
+    Status = NtWriteFile(FileHandle,
+                         NULL,
+                         NULL,
+                         NULL,
+                         &IoStatusBlock,
+                         NewBootSector,
+                         SECTORSIZE,
+                         &FileOffset,
+                         NULL);
+    NtClose(FileHandle);
+
+    /* Free the new boot sector */
+    RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+
+    return Status;
+}
+
+static
+NTSTATUS
 InstallFat32BootCodeToFile(
     PWSTR SrcPath,
     PWSTR DstPath,
@@ -1154,477 +1823,6 @@
     if (!NT_SUCCESS(Status))
     {
     }
-    NtClose(FileHandle);
-
-    /* Free the new boot sector */
-    RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-
-    return Status;
-}
-
-
-NTSTATUS
-InstallMbrBootCodeToDisk(
-    PWSTR SrcPath,
-    PWSTR RootPath)
-{
-    NTSTATUS Status;
-    UNICODE_STRING Name;
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    IO_STATUS_BLOCK IoStatusBlock;
-    HANDLE FileHandle;
-    LARGE_INTEGER FileOffset;
-    PPARTITION_SECTOR OrigBootSector;
-    PPARTITION_SECTOR NewBootSector;
-
-    /* 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 */
-    RtlInitUnicodeString(&Name,
-                         RootPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_READ | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return Status;
-    }
-
-    FileOffset.QuadPart = 0ULL;
-    Status = NtReadFile(FileHandle,
-                        NULL,
-                        NULL,
-                        NULL,
-                        &IoStatusBlock,
-                        OrigBootSector,
-                        sizeof(PARTITION_SECTOR),
-                        &FileOffset,
-                        NULL);
-    NtClose(FileHandle);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return Status;
-    }
-
-    /* Allocate buffer for new bootsector */
-    NewBootSector = (PPARTITION_SECTOR)RtlAllocateHeap(ProcessHeap,
-                    0,
-                    sizeof(PARTITION_SECTOR));
-    if (NewBootSector == NULL)
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return STATUS_INSUFFICIENT_RESOURCES;
-    }
-
-    /* Read new bootsector from SrcPath */
-    RtlInitUnicodeString(&Name, SrcPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_READ | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    Status = NtReadFile(FileHandle,
-                        NULL,
-                        NULL,
-                        NULL,
-                        &IoStatusBlock,
-                        NewBootSector,
-                        sizeof(PARTITION_SECTOR),
-                        NULL,
-                        NULL);
-    NtClose(FileHandle);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    /*
-     * Copy the disk signature, the reserved fields and
-     * the partition table from the old MBR to the new one.
-     */
-    RtlCopyMemory(&NewBootSector->Signature,
-                  &OrigBootSector->Signature,
-                  sizeof(PARTITION_SECTOR) - offsetof(PARTITION_SECTOR, 
Signature) /* Length of partition table */);
-
-    /* Free the original boot sector */
-    RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-
-    /* Write new bootsector to RootPath */
-    RtlInitUnicodeString(&Name, RootPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               0,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_WRITE | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    FileOffset.QuadPart = 0ULL;
-    Status = NtWriteFile(FileHandle,
-                         NULL,
-                         NULL,
-                         NULL,
-                         &IoStatusBlock,
-                         NewBootSector,
-                         sizeof(PARTITION_SECTOR),
-                         &FileOffset,
-                         NULL);
-    NtClose(FileHandle);
-
-    /* Free the new boot sector */
-    RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-
-    return Status;
-}
-
-static
-NTSTATUS
-InstallFat12BootCodeToFloppy(
-    PWSTR SrcPath,
-    PWSTR RootPath)
-{
-    NTSTATUS Status;
-    UNICODE_STRING Name;
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    IO_STATUS_BLOCK IoStatusBlock;
-    HANDLE FileHandle;
-    LARGE_INTEGER FileOffset;
-    PFAT_BOOTSECTOR OrigBootSector;
-    PFAT_BOOTSECTOR NewBootSector;
-
-    /* Allocate buffer for original bootsector */
-    OrigBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE);
-    if (OrigBootSector == NULL)
-        return STATUS_INSUFFICIENT_RESOURCES;
-
-    /* Read current boot sector into buffer */
-    RtlInitUnicodeString(&Name, RootPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_READ | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return Status;
-    }
-
-    FileOffset.QuadPart = 0ULL;
-    Status = NtReadFile(FileHandle,
-                        NULL,
-                        NULL,
-                        NULL,
-                        &IoStatusBlock,
-                        OrigBootSector,
-                        SECTORSIZE,
-                        &FileOffset,
-                        NULL);
-    NtClose(FileHandle);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return Status;
-    }
-
-    /* Allocate buffer for new bootsector */
-    NewBootSector = RtlAllocateHeap(ProcessHeap,
-                                    0,
-                                    SECTORSIZE);
-    if (NewBootSector == NULL)
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return STATUS_INSUFFICIENT_RESOURCES;
-    }
-
-    /* Read new bootsector from SrcPath */
-    RtlInitUnicodeString(&Name, SrcPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_READ | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    Status = NtReadFile(FileHandle,
-                        NULL,
-                        NULL,
-                        NULL,
-                        &IoStatusBlock,
-                        NewBootSector,
-                        SECTORSIZE,
-                        NULL,
-                        NULL);
-    NtClose(FileHandle);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    /* Adjust bootsector (copy a part of the FAT16 BPB) */
-    memcpy(&NewBootSector->OemName,
-           &OrigBootSector->OemName,
-           FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
-           FIELD_OFFSET(FAT_BOOTSECTOR, OemName));
-
-    /* Free the original boot sector */
-    RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-
-    /* Write new bootsector to RootPath */
-    RtlInitUnicodeString(&Name, RootPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               0,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_WRITE | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    FileOffset.QuadPart = 0ULL;
-    Status = NtWriteFile(FileHandle,
-                         NULL,
-                         NULL,
-                         NULL,
-                         &IoStatusBlock,
-                         NewBootSector,
-                         SECTORSIZE,
-                         &FileOffset,
-                         NULL);
-    NtClose(FileHandle);
-
-    /* Free the new boot sector */
-    RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-
-    return Status;
-}
-
-static
-NTSTATUS
-InstallFat16BootCodeToDisk(
-    PWSTR SrcPath,
-    PWSTR RootPath)
-{
-    NTSTATUS Status;
-    UNICODE_STRING Name;
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    IO_STATUS_BLOCK IoStatusBlock;
-    HANDLE FileHandle;
-    LARGE_INTEGER FileOffset;
-    PFAT_BOOTSECTOR OrigBootSector;
-    PFAT_BOOTSECTOR NewBootSector;
-
-    /* Allocate buffer for original bootsector */
-    OrigBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE);
-    if (OrigBootSector == NULL)
-        return STATUS_INSUFFICIENT_RESOURCES;
-
-    /* Read current boot sector into buffer */
-    RtlInitUnicodeString(&Name, RootPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_READ | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return Status;
-    }
-
-    FileOffset.QuadPart = 0ULL;
-    Status = NtReadFile(FileHandle,
-                        NULL,
-                        NULL,
-                        NULL,
-                        &IoStatusBlock,
-                        OrigBootSector,
-                        SECTORSIZE,
-                        &FileOffset,
-                        NULL);
-    NtClose(FileHandle);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return Status;
-    }
-
-    /* Allocate buffer for new bootsector */
-    NewBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE);
-    if (NewBootSector == NULL)
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        return STATUS_INSUFFICIENT_RESOURCES;
-    }
-
-    /* Read new bootsector from SrcPath */
-    RtlInitUnicodeString(&Name, SrcPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_READ | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    Status = NtReadFile(FileHandle,
-                        NULL,
-                        NULL,
-                        NULL,
-                        &IoStatusBlock,
-                        NewBootSector,
-                        SECTORSIZE,
-                        NULL,
-                        NULL);
-    NtClose(FileHandle);
-    if (!NT_SUCCESS(Status))
-    {
-        RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    /* Adjust bootsector (copy a part of the FAT16 BPB) */
-    memcpy(&NewBootSector->OemName,
-           &OrigBootSector->OemName,
-           FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
-           FIELD_OFFSET(FAT_BOOTSECTOR, OemName));
-
-    /* Free the original boot sector */
-    RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
-
-    /* Write new bootsector to RootPath */
-    RtlInitUnicodeString(&Name, RootPath);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               0,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_WRITE | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
-        RtlFreeHeap(ProcessHeap, 0, NewBootSector);
-        return Status;
-    }
-
-    FileOffset.QuadPart = 0ULL;
-    Status = NtWriteFile(FileHandle,
-                         NULL,
-                         NULL,
-                         NULL,
-                         &IoStatusBlock,
-                         NewBootSector,
-                         SECTORSIZE,
-                         &FileOffset,
-                         NULL);
     NtClose(FileHandle);
 
     /* Free the new boot sector */
@@ -1838,6 +2036,7 @@
     return Status;
 }
 
+// FIXME: This function does not really work
 static
 NTSTATUS
 InstallExt2BootCodeToDisk(
@@ -2052,203 +2251,6 @@
 
 static
 NTSTATUS
-UnprotectBootIni(
-    PWSTR FileName,
-    PULONG Attributes)
-{
-    NTSTATUS Status;
-    UNICODE_STRING Name;
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    IO_STATUS_BLOCK IoStatusBlock;
-    FILE_BASIC_INFORMATION FileInfo;
-    HANDLE FileHandle;
-
-    RtlInitUnicodeString(&Name, FileName);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT);
-    if (Status == STATUS_NO_SUCH_FILE)
-    {
-        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
-        *Attributes = 0;
-        return STATUS_SUCCESS;
-    }
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
-        return Status;
-    }
-
-    Status = NtQueryInformationFile(FileHandle,
-                                    &IoStatusBlock,
-                                    &FileInfo,
-                                    sizeof(FILE_BASIC_INFORMATION),
-                                    FileBasicInformation);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status);
-        NtClose(FileHandle);
-        return Status;
-    }
-
-    *Attributes = FileInfo.FileAttributes;
-
-    /* Delete attributes SYSTEM, HIDDEN and READONLY */
-    FileInfo.FileAttributes = FileInfo.FileAttributes &
-                              ~(FILE_ATTRIBUTE_SYSTEM |
-                                FILE_ATTRIBUTE_HIDDEN |
-                                FILE_ATTRIBUTE_READONLY);
-
-    Status = NtSetInformationFile(FileHandle,
-                                  &IoStatusBlock,
-                                  &FileInfo,
-                                  sizeof(FILE_BASIC_INFORMATION),
-                                  FileBasicInformation);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status);
-    }
-
-    NtClose(FileHandle);
-    return Status;
-}
-
-static
-NTSTATUS
-ProtectBootIni(
-    PWSTR FileName,
-    ULONG Attributes)
-{
-    NTSTATUS Status;
-    UNICODE_STRING Name;
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    IO_STATUS_BLOCK IoStatusBlock;
-    FILE_BASIC_INFORMATION FileInfo;
-    HANDLE FileHandle;
-
-    RtlInitUnicodeString(&Name, FileName);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-
-    Status = NtOpenFile(&FileHandle,
-                        GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
-                        &ObjectAttributes,
-                        &IoStatusBlock,
-                        0,
-                        FILE_SYNCHRONOUS_IO_NONALERT);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtOpenFile() failed (Status %lx)\n", Status);
-        return Status;
-    }
-
-    Status = NtQueryInformationFile(FileHandle,
-                                    &IoStatusBlock,
-                                    &FileInfo,
-                                    sizeof(FILE_BASIC_INFORMATION),
-                                    FileBasicInformation);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtQueryInformationFile() failed (Status %lx)\n", Status);
-        NtClose(FileHandle);
-        return Status;
-    }
-
-    FileInfo.FileAttributes = FileInfo.FileAttributes | Attributes;
-
-    Status = NtSetInformationFile(FileHandle,
-                                  &IoStatusBlock,
-                                  &FileInfo,
-                                  sizeof(FILE_BASIC_INFORMATION),
-                                  FileBasicInformation);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("NtSetInformationFile() failed (Status %lx)\n", Status);
-    }
-
-    NtClose(FileHandle);
-    return Status;
-}
-
-static
-NTSTATUS
-UpdateBootIni(
-    PWSTR BootIniPath,
-    PWSTR EntryName,
-    PWSTR EntryValue)
-{
-    NTSTATUS Status;
-    PINICACHE Cache = NULL;
-    PINICACHESECTION Section = NULL;
-    ULONG FileAttribute;
-    PWCHAR OldValue = NULL;
-
-    Status = IniCacheLoad(&Cache, BootIniPath, FALSE);
-    if (!NT_SUCCESS(Status))
-    {
-        return Status;
-    }
-
-    Section = IniCacheGetSection(Cache,
-                                 L"operating systems");
-    if (Section == NULL)
-    {
-        IniCacheDestroy(Cache);
-        return STATUS_UNSUCCESSFUL;
-    }
-
-    /* Check - maybe record already exists */
-    Status = IniCacheGetKey(Section, EntryName, &OldValue);
-
-    /* If either key was not found, or contains something else - add new one */
-    if (!NT_SUCCESS(Status) || wcscmp(OldValue, EntryValue))
-    {
-        IniCacheInsertKey(Section,
-                          NULL,
-                          INSERT_LAST,
-                          EntryName,
-                          EntryValue);
-    }
-
-    Status = UnprotectBootIni(BootIniPath,
-                              &FileAttribute);
-    if (!NT_SUCCESS(Status))
-    {
-        IniCacheDestroy(Cache);
-        return Status;
-    }
-
-    Status = IniCacheSave(Cache, BootIniPath);
-    if (!NT_SUCCESS(Status))
-    {
-        IniCacheDestroy(Cache);
-        return Status;
-    }
-
-    FileAttribute |= (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | 
FILE_ATTRIBUTE_READONLY);
-    Status = ProtectBootIni(BootIniPath, FileAttribute);
-
-    IniCacheDestroy(Cache);
-
-    return Status;
-}
-
-static
-NTSTATUS
 InstallFatBootcodeToPartition(
     PUNICODE_STRING SystemRootPath,
     PUNICODE_STRING SourceRootPath,


Reply via email to