ReactOS 0.4.16-dev-289-g096a551
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 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 InstallBootcodeToRemovable (_In_ ARCHITECTURE_TYPE ArchType, _In_ PCUNICODE_STRING RemovableRootPath, _In_ PCUNICODE_STRING SourceRootPath, _In_ PCUNICODE_STRING DestinationArcPath)
 

Function Documentation

◆ InstallBootcodeToRemovable()

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

Definition at line 1816 of file bootsup.c.

1821{
1824 PCWSTR FileSystemName;
1825 BOOLEAN IsFloppy;
1826
1827 /* Remove any trailing backslash if needed */
1828 UNICODE_STRING RootDrive = *RemovableRootPath;
1830
1831 /* Verify that the removable disk is accessible */
1832 if (!DoesDirExist(NULL, RemovableRootPath->Buffer))
1834
1835 /* Retrieve the device type and characteristics */
1836 Status = GetDeviceInfo_UStr(&RootDrive, NULL, &DeviceInfo);
1837 if (!NT_SUCCESS(Status))
1838 {
1839 static const UNICODE_STRING DeviceFloppy = RTL_CONSTANT_STRING(L"\\Device\\Floppy");
1840
1841 DPRINT1("FileFsDeviceInformation failed (Status 0x%08lx)\n", Status);
1842
1843 /* Definitively fail if the device is not a floppy */
1844 if (!RtlPrefixUnicodeString(&DeviceFloppy, &RootDrive, TRUE))
1845 return Status; /* We cannot cope with a failure */
1846
1847 /* Try to fall back to something "sane" if the device may be a floppy */
1848 DeviceInfo.DeviceType = FILE_DEVICE_DISK;
1850 }
1851
1852 /* Ignore volumes that are NOT on usual disks */
1853 if (DeviceInfo.DeviceType != FILE_DEVICE_DISK /*&&
1854 DeviceInfo.DeviceType != FILE_DEVICE_VIRTUAL_DISK*/)
1855 {
1856 DPRINT1("Invalid volume; device type %lu\n", DeviceInfo.DeviceType);
1858 }
1859
1860 /* Fail if the disk is not removable */
1861 if (!(DeviceInfo.Characteristics & FILE_REMOVABLE_MEDIA))
1862 {
1863 DPRINT1("Device is NOT removable!\n");
1865 }
1866
1867 /* Check whether this is a floppy or another removable device */
1868 IsFloppy = !!(DeviceInfo.Characteristics & FILE_FLOPPY_DISKETTE);
1869
1870 /* Use FAT32, unless the device is a floppy disk */
1871 FileSystemName = (IsFloppy ? L"FAT" : L"FAT32");
1872
1873 /* Format the removable disk */
1874 Status = FormatFileSystem_UStr(&RootDrive,
1875 FileSystemName,
1876 (IsFloppy ? FMIFS_FLOPPY : FMIFS_REMOVABLE),
1877 NULL,
1878 TRUE,
1879 0,
1880 NULL);
1881 if (!NT_SUCCESS(Status))
1882 {
1884 DPRINT1("%s FS non-existent on this system!\n", FileSystemName);
1885 else
1886 DPRINT1("FormatFileSystem(%s) failed (Status 0x%08lx)\n", FileSystemName, Status);
1887 return Status;
1888 }
1889
1890 /* Copy FreeLoader to the removable disk and save the boot entries */
1892 RemovableRootPath,
1893 SourceRootPath,
1894 DestinationArcPath,
1895 2 /* Install on removable media */);
1896 if (!NT_SUCCESS(Status))
1897 DPRINT1("InstallBootManagerAndBootEntries() failed (Status 0x%08lx)\n", Status);
1898 return Status;
1899}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
NTSTATUS 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:1661
static VOID TrimTrailingPathSeparators_UStr(IN OUT PUNICODE_STRING UnicodeString)
Definition: bootsup.c:44
NTSTATUS GetDeviceInfo_UStr(_In_opt_ PCUNICODE_STRING DeviceName, _In_opt_ HANDLE DeviceHandle, _Out_ PFILE_FS_DEVICE_INFORMATION DeviceInfo)
Definition: bootsup.c:1568
#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 DoesDirExist(RootDirectory, DirName)
Definition: filesup.h:80
@ FMIFS_FLOPPY
Definition: fmifs.h:61
@ FMIFS_REMOVABLE
Definition: fmifs.h:64
Status
Definition: gdiplustypes.h:25
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 L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_DISK
Definition: winioctl.h:52
NTSTATUS 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:311
#define STATUS_DEVICE_NOT_READY
Definition: shellext.h:70
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
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 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 1661 of file bootsup.c.

1667{
1671 ULONG DiskNumber;
1672 PARTITION_STYLE PartitionStyle;
1675
1676 /* Remove any trailing backslash if needed */
1677 UNICODE_STRING RootPartition = *SystemRootPath;
1679
1680 /* Open the volume */
1684 if (!NT_SUCCESS(Status))
1685 {
1686 DPRINT1("Cannot open %wZ for bootloader installation (Status 0x%08lx)\n",
1688 return Status;
1689 }
1690
1691 /* Retrieve the volume file system (it will also be mounted) */
1693 FileSystem, sizeof(FileSystem));
1694 if (!NT_SUCCESS(Status) || !*FileSystem)
1695 {
1696 DPRINT1("GetFileSystemName() failed (Status 0x%08lx)\n", Status);
1697 goto Quit;
1698 }
1699
1700 /* Retrieve the device type and characteristics */
1702 if (!NT_SUCCESS(Status))
1703 {
1704 DPRINT1("FileFsDeviceInformation failed (Status 0x%08lx)\n", Status);
1705 goto Quit;
1706 }
1707
1708 /* Ignore volumes that are NOT on usual disks */
1709 if (DeviceInfo.DeviceType != FILE_DEVICE_DISK /*&&
1710 DeviceInfo.DeviceType != FILE_DEVICE_VIRTUAL_DISK*/)
1711 {
1712 DPRINT1("Invalid volume; device type %lu\n", DeviceInfo.DeviceType);
1714 goto Quit;
1715 }
1716
1717
1718 /* Check whether this is a floppy or a partitionable device */
1719 if (DeviceInfo.Characteristics & FILE_FLOPPY_DISKETTE)
1720 {
1721 /* Floppies don't have partitions */
1722 // NOTE: See ntoskrnl/io/iomgr/rawfs.c!RawQueryFsSizeInfo()
1723 DiskNumber = ULONG_MAX;
1724 PartitionStyle = PARTITION_STYLE_MBR;
1726 }
1727 else
1728 {
1731
1732 /* The maximum information a DISK_GEOMETRY_EX dynamic structure can contain */
1733 typedef struct _DISK_GEOMETRY_EX_INTERNAL
1734 {
1737 DISK_PARTITION_INFO Partition;
1738 /* Followed by: DISK_DETECTION_INFO Detection; unused here */
1740
1741 DISK_GEOMETRY_EX_INTERNAL DiskGeoEx;
1743
1744 /* Retrieve the disk number. NOTE: Fails for floppy disks. */
1746 NULL, NULL, NULL,
1749 NULL, 0,
1750 &DeviceNumber, sizeof(DeviceNumber));
1751 if (!NT_SUCCESS(Status))
1752 goto Quit; /* This may be a dynamic volume, which is unsupported */
1753 ASSERT(DeviceNumber.DeviceType == DeviceInfo.DeviceType);
1754 if (DeviceNumber.DeviceNumber == ULONG_MAX)
1755 {
1756 DPRINT1("Invalid disk number reported, bail out\n");
1758 goto Quit;
1759 }
1760
1761 /* Retrieve the drive geometry. NOTE: Fails for floppy disks;
1762 * use IOCTL_DISK_GET_DRIVE_GEOMETRY instead. */
1764 NULL, NULL, NULL,
1767 NULL, 0,
1768 &DiskGeoEx,
1769 sizeof(DiskGeoEx));
1770 if (!NT_SUCCESS(Status))
1771 {
1772 DPRINT1("IOCTL_DISK_GET_DRIVE_GEOMETRY_EX failed (Status 0x%08lx)\n", Status);
1773 goto Quit;
1774 }
1775
1776 /*
1777 * Retrieve the volume's partition information.
1778 * NOTE: Fails for floppy disks.
1779 *
1780 * NOTE: We can use the non-EX IOCTL because the super-floppy test will
1781 * fail anyway if the disk is NOT MBR-partitioned. (If the disk is GPT,
1782 * the IOCTL would return only the MBR protective partition, but the
1783 * super-floppy test would fail due to the wrong partitioning style.)
1784 */
1786 NULL, NULL, NULL,
1789 NULL, 0,
1791 sizeof(PartitionInfo));
1792 if (!NT_SUCCESS(Status))
1793 {
1794 DPRINT1("IOCTL_DISK_GET_PARTITION_INFO failed (Status 0x%08lx)\n", Status);
1795 goto Quit;
1796 }
1797
1798 DiskNumber = DeviceNumber.DeviceNumber;
1799 PartitionStyle = DiskGeoEx.Partition.PartitionStyle;
1801 (PULONGLONG)&DiskGeoEx.DiskSize.QuadPart,
1802 &PartitionInfo);
1803 }
1804
1806 ArchType, SystemRootPath,
1807 DiskNumber, PartitionStyle, IsSuperFloppy, FileSystem,
1808 SourceRootPath, DestinationArcPath, Options);
1809
1810Quit:
1812 return Status;
1813}
PWCHAR FileSystem
Definition: format.c:72
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:1472
_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
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
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
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define ULONG_MAX
Definition: intsafe.h:155
#define ASSERT(a)
Definition: mode.c:44
enum _PARTITION_STYLE PARTITION_STYLE
@ PARTITION_STYLE_MBR
Definition: imports.h:201
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#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:3402
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:391
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
#define IOCTL_STORAGE_GET_DEVICE_NUMBER
Definition: ntddstor.h:143
IN HANDLE IN HANDLE RootPartition
Definition: fsutil.h:77
BOOLEAN IsDiskSuperFloppy2(_In_ const DISK_PARTITION_INFO *DiskInfo, _In_opt_ const ULONGLONG *DiskSize, _In_ const PARTITION_INFORMATION *PartitionInfo)
Definition: partlist.c:491
BOOLEAN IsSuperFloppy(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:600
#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:3534
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105
__wchar_t WCHAR
Definition: xmlstorage.h:180

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