ReactOS 0.4.17-dev-1281-g065abb3
bootsup.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

NTSTATUS NTAPI InstallBootManagerAndBootEntries (_In_ ARCHITECTURE_TYPE ArchType, _In_ PCUNICODE_STRING SystemRootPath, _In_ PCUNICODE_STRING SourceRootPath, _In_ PCUNICODE_STRING DestinationArcPath, _In_ ULONG_PTR Options)
 Installs FreeLoader on the system and configure the boot entries.
 
NTSTATUS NTAPI InstallBootcodeToRemovable (_In_ ARCHITECTURE_TYPE ArchType, _In_ PCUNICODE_STRING RemovableRootPath, _In_ PCUNICODE_STRING SourceRootPath, _In_ PCUNICODE_STRING DestinationArcPath)
 

Function Documentation

◆ InstallBootcodeToRemovable()

NTSTATUS NTAPI InstallBootcodeToRemovable ( _In_ ARCHITECTURE_TYPE  ArchType,
_In_ PCUNICODE_STRING  RemovableRootPath,
_In_ PCUNICODE_STRING  SourceRootPath,
_In_ PCUNICODE_STRING  DestinationArcPath 
)

Definition at line 1840 of file bootsup.c.

1845{
1848 PCWSTR FileSystemName;
1850
1851 /* Remove any trailing backslash if needed */
1852 UNICODE_STRING RootDrive = *RemovableRootPath;
1854
1855 /* Verify that the removable disk is accessible */
1856 if (!DoesDirExist(NULL, RemovableRootPath->Buffer))
1858
1859 /* Retrieve the device type and characteristics */
1860 Status = GetDeviceInfo_UStr(&RootDrive, NULL, &DeviceInfo);
1861 if (!NT_SUCCESS(Status))
1862 {
1863 static const UNICODE_STRING DeviceFloppy = RTL_CONSTANT_STRING(L"\\Device\\Floppy");
1864
1865 DPRINT1("FileFsDeviceInformation failed (Status 0x%08lx)\n", Status);
1866
1867 /* Definitively fail if the device is not a floppy */
1868 if (!RtlPrefixUnicodeString(&DeviceFloppy, &RootDrive, TRUE))
1869 return Status; /* We cannot cope with a failure */
1870
1871 /* Try to fall back to something "sane" if the device may be a floppy */
1872 DeviceInfo.DeviceType = FILE_DEVICE_DISK;
1874 }
1875
1876 /* Ignore volumes that are NOT on usual disks */
1877 if (DeviceInfo.DeviceType != FILE_DEVICE_DISK /*&&
1878 DeviceInfo.DeviceType != FILE_DEVICE_VIRTUAL_DISK*/)
1879 {
1880 DPRINT1("Invalid volume; device type %lu\n", DeviceInfo.DeviceType);
1882 }
1883
1884 /* Fail if the disk is not removable */
1885 if (!(DeviceInfo.Characteristics & FILE_REMOVABLE_MEDIA))
1886 {
1887 DPRINT1("Device is NOT removable!\n");
1889 }
1890
1891 /* Check whether this is a floppy or another removable device */
1892 IsFloppy = !!(DeviceInfo.Characteristics & FILE_FLOPPY_DISKETTE);
1893
1894 /* Use FAT32, unless the device is a floppy disk */
1895 FileSystemName = (IsFloppy ? L"FAT" : L"FAT32");
1896
1897 /* Format the removable disk */
1898 Status = FormatFileSystem_UStr(&RootDrive,
1899 FileSystemName,
1901 NULL,
1902 TRUE,
1903 0,
1904 NULL);
1905 if (!NT_SUCCESS(Status))
1906 {
1908 DPRINT1("%s FS non-existent on this system!\n", FileSystemName);
1909 else
1910 DPRINT1("FormatFileSystem(%s) failed (Status 0x%08lx)\n", FileSystemName, Status);
1911 return Status;
1912 }
1913
1914 /* Copy FreeLoader to the removable disk and save the boot entries */
1916 RemovableRootPath,
1917 SourceRootPath,
1918 DestinationArcPath,
1919 2 /* Install on removable media */);
1920 if (!NT_SUCCESS(Status))
1921 DPRINT1("InstallBootManagerAndBootEntries() failed (Status 0x%08lx)\n", Status);
1922 return Status;
1923}
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI InstallBootManagerAndBootEntries(_In_ ARCHITECTURE_TYPE ArchType, _In_ PCUNICODE_STRING SystemRootPath, _In_ PCUNICODE_STRING SourceRootPath, _In_ PCUNICODE_STRING DestinationArcPath, _In_ ULONG_PTR Options)
Installs FreeLoader on the system and configure the boot entries.
Definition: bootsup.c:1684
static VOID TrimTrailingPathSeparators_UStr(IN OUT PUNICODE_STRING UnicodeString)
Definition: bootsup.c:45
NTSTATUS GetDeviceInfo_UStr(_In_opt_ PCUNICODE_STRING DeviceName, _In_opt_ HANDLE DeviceHandle, _Out_ PFILE_FS_DEVICE_INFORMATION DeviceInfo)
Definition: bootsup.c:1590
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
static BOOL IsFloppy(PCWSTR pszDrive)
Definition: drive.cpp:48
#define L(x)
Definition: resources.c:13
#define DoesDirExist(RootDirectory, DirName)
Definition: filesup.h:80
@ FMIFS_FLOPPY
Definition: fmifs.h:62
@ FMIFS_REMOVABLE
Definition: fmifs.h:65
Status
Definition: gdiplustypes.h:24
UNICODE_STRING DeviceFloppy
Definition: symlink.c:43
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define FILE_DEVICE_DISK
Definition: winioctl.h:52
NTSTATUS NTAPI FormatFileSystem_UStr(_In_ PUNICODE_STRING DriveRoot, _In_ PCWSTR FileSystemName, _In_ FMIFS_MEDIA_FLAG MediaFlag, _In_opt_ PUNICODE_STRING Label, _In_ BOOLEAN QuickFormat, _In_ ULONG ClusterSize, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:315
#define STATUS_DEVICE_NOT_READY
Definition: shellext.h:70
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138

Referenced by BootLoaderRemovableDiskPage(), and PrepareAndDoCopyThread().

◆ InstallBootManagerAndBootEntries()

NTSTATUS NTAPI InstallBootManagerAndBootEntries ( _In_ ARCHITECTURE_TYPE  ArchType,
_In_ PCUNICODE_STRING  SystemRootPath,
_In_ PCUNICODE_STRING  SourceRootPath,
_In_ PCUNICODE_STRING  DestinationArcPath,
_In_ ULONG_PTR  Options 
)

Installs FreeLoader on the system and configure the boot entries.

Todo:
Split this function into just the InstallBootManager, and a separate one for just the boot entries.
Parameters
[in]ArchTypeThe target architecture.
[in]SystemRootPathThe system partition path, where the FreeLdr boot manager and its settings are saved to.
[in]SourceRootPathThe installation source, where to copy the FreeLdr boot manager from.
[in]DestinationArcPathThe ReactOS installation path in ARC format.
[in]OptionsFor BIOS-based PCs: LOBYTE: 0: Install only on VBR; 1: Install on both VBR and MBR. 2: Install on removable disk.
Returns
An NTSTATUS code indicating success or failure.

Definition at line 1684 of file bootsup.c.

1690{
1694 ULONG DiskNumber;
1695 PARTITION_STYLE PartitionStyle;
1698
1699 /* Remove any trailing backslash if needed */
1700 UNICODE_STRING RootPartition = *SystemRootPath;
1702
1703 /* Open the volume */
1707 if (!NT_SUCCESS(Status))
1708 {
1709 DPRINT1("Cannot open %wZ for bootloader installation (Status 0x%08lx)\n",
1711 return Status;
1712 }
1713
1714 /* Retrieve the volume file system (it will also be mounted) */
1716 FileSystem, sizeof(FileSystem));
1717 if (!NT_SUCCESS(Status) || !*FileSystem)
1718 {
1719 DPRINT1("GetFileSystemName() failed (Status 0x%08lx)\n", Status);
1720 goto Quit;
1721 }
1722
1723 /* Retrieve the device type and characteristics */
1725 if (!NT_SUCCESS(Status))
1726 {
1727 DPRINT1("FileFsDeviceInformation failed (Status 0x%08lx)\n", Status);
1728 goto Quit;
1729 }
1730
1731 /* Ignore volumes that are NOT on usual disks */
1732 if (DeviceInfo.DeviceType != FILE_DEVICE_DISK /*&&
1733 DeviceInfo.DeviceType != FILE_DEVICE_VIRTUAL_DISK*/)
1734 {
1735 DPRINT1("Invalid volume; device type %lu\n", DeviceInfo.DeviceType);
1737 goto Quit;
1738 }
1739
1740
1741 /* Check whether this is a floppy or a partitionable device */
1742 if (DeviceInfo.Characteristics & FILE_FLOPPY_DISKETTE)
1743 {
1744 /* Floppies don't have partitions */
1745 // NOTE: See ntoskrnl/io/iomgr/rawfs.c!RawQueryFsSizeInfo()
1746 DiskNumber = ULONG_MAX;
1747 PartitionStyle = PARTITION_STYLE_MBR;
1749 }
1750 else
1751 {
1754
1755 /* The maximum information a DISK_GEOMETRY_EX dynamic structure can contain */
1756 typedef struct _DISK_GEOMETRY_EX_INTERNAL
1757 {
1760 DISK_PARTITION_INFO Partition;
1761 /* Followed by: DISK_DETECTION_INFO Detection; unused here */
1763
1764 DISK_GEOMETRY_EX_INTERNAL DiskGeoEx;
1766
1767 /* Retrieve the disk number. NOTE: Fails for floppy disks. */
1769 NULL, NULL, NULL,
1772 NULL, 0,
1773 &DeviceNumber, sizeof(DeviceNumber));
1774 if (!NT_SUCCESS(Status))
1775 goto Quit; /* This may be a dynamic volume, which is unsupported */
1776 ASSERT(DeviceNumber.DeviceType == DeviceInfo.DeviceType);
1777 if (DeviceNumber.DeviceNumber == ULONG_MAX)
1778 {
1779 DPRINT1("Invalid disk number reported, bail out\n");
1781 goto Quit;
1782 }
1783
1784 /* Retrieve the drive geometry. NOTE: Fails for floppy disks;
1785 * use IOCTL_DISK_GET_DRIVE_GEOMETRY instead. */
1787 NULL, NULL, NULL,
1790 NULL, 0,
1791 &DiskGeoEx,
1792 sizeof(DiskGeoEx));
1793 if (!NT_SUCCESS(Status))
1794 {
1795 DPRINT1("IOCTL_DISK_GET_DRIVE_GEOMETRY_EX failed (Status 0x%08lx)\n", Status);
1796 goto Quit;
1797 }
1798
1799 /*
1800 * Retrieve the volume's partition information.
1801 * NOTE: Fails for floppy disks.
1802 *
1803 * NOTE: We can use the non-EX IOCTL because the super-floppy test will
1804 * fail anyway if the disk is NOT MBR-partitioned. (If the disk is GPT,
1805 * the IOCTL would return only the MBR protective partition, but the
1806 * super-floppy test would fail due to the wrong partitioning style.)
1807 */
1809 NULL, NULL, NULL,
1812 NULL, 0,
1814 sizeof(PartitionInfo));
1815 if (!NT_SUCCESS(Status))
1816 {
1817 DPRINT1("IOCTL_DISK_GET_PARTITION_INFO failed (Status 0x%08lx)\n", Status);
1818 goto Quit;
1819 }
1820
1821 DiskNumber = DeviceNumber.DeviceNumber;
1822 PartitionStyle = DiskGeoEx.Partition.PartitionStyle;
1824 (PULONGLONG)&DiskGeoEx.DiskSize.QuadPart,
1825 &PartitionInfo);
1826 }
1827
1829 ArchType, SystemRootPath,
1830 DiskNumber, PartitionStyle, IsSuperFloppy, FileSystem,
1831 SourceRootPath, DestinationArcPath, Options);
1832
1833Quit:
1835 return Status;
1836}
PWCHAR FileSystem
Definition: format.c:71
static NTSTATUS InstallBootManagerAndBootEntriesWorker(_In_ ARCHITECTURE_TYPE ArchType, _In_ PCUNICODE_STRING SystemRootPath, _In_ ULONG DiskNumber, _In_ PARTITION_STYLE DiskStyle, _In_ BOOLEAN IsSuperFloppy, _In_ PCWSTR FileSystem, _In_ PCUNICODE_STRING SourceRootPath, _In_ PCUNICODE_STRING DestinationArcPath, _In_ ULONG_PTR Options)
Helper for InstallBootManagerAndBootEntries().
Definition: bootsup.c:1494
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
NTSTATUS pOpenDeviceEx_UStr(_In_ PCUNICODE_STRING DevicePath, _Out_ PHANDLE DeviceHandle, _In_ ACCESS_MASK DesiredAccess, _In_ ULONG ShareAccess)
Open an existing device given by its NT-style path, which is assumed to be for a disk device or a par...
Definition: devutils.c:38
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
#define ULONG_MAX
Definition: limits.h:31
struct _DISK_GEOMETRY_EX_INTERNAL * PDISK_GEOMETRY_EX_INTERNAL
struct _DISK_GEOMETRY_EX_INTERNAL DISK_GEOMETRY_EX_INTERNAL
#define IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
Definition: ntddk_ex.h:208
NTSTATUS GetFileSystemName_UStr(IN PUNICODE_STRING PartitionPath OPTIONAL, IN HANDLE PartitionHandle OPTIONAL, IN OUT PWSTR FileSystemName, IN SIZE_T FileSystemNameSize)
Definition: fsrec.c:55
#define ASSERT(a)
Definition: mode.c:44
enum _PARTITION_STYLE PARTITION_STYLE
@ PARTITION_STYLE_MBR
Definition: imports.h:201
_In_ PIOMMU_DEVICE_PATH _In_ PIOMMU_SVM_CAPABILITIES _Out_ PVOID * DeviceHandle
Definition: haltypes.h:1894
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3434
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:395
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
short WCHAR
Definition: pedump.c:58
#define IOCTL_STORAGE_GET_DEVICE_NUMBER
Definition: ntddstor.h:143
IN HANDLE IN HANDLE RootPartition
Definition: fsutil.h:82
BOOLEAN IsDiskSuperFloppy2(_In_ const DISK_PARTITION_INFO *DiskInfo, _In_opt_ const ULONGLONG *DiskSize, _In_ const PARTITION_INFORMATION *PartitionInfo)
Definition: partlist.c:493
BOOLEAN IsSuperFloppy(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:602
#define STATUS_NOT_FOUND
Definition: shellext.h:72
LARGE_INTEGER DiskSize
Definition: disk.c:3666
DISK_PARTITION_INFO Partition
Definition: disk.c:3667
DISK_GEOMETRY Geometry
Definition: disk.c:3665
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3540
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2124

Referenced by BootLoaderHardDiskPage(), InstallBootcodeToRemovable(), and PrepareAndDoCopyThread().