ReactOS 0.4.16-dev-338-g34e76ad
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 1818 of file bootsup.c.

1823{
1826 PCWSTR FileSystemName;
1827 BOOLEAN IsFloppy;
1828
1829 /* Remove any trailing backslash if needed */
1830 UNICODE_STRING RootDrive = *RemovableRootPath;
1832
1833 /* Verify that the removable disk is accessible */
1834 if (!DoesDirExist(NULL, RemovableRootPath->Buffer))
1836
1837 /* Retrieve the device type and characteristics */
1838 Status = GetDeviceInfo_UStr(&RootDrive, NULL, &DeviceInfo);
1839 if (!NT_SUCCESS(Status))
1840 {
1841 static const UNICODE_STRING DeviceFloppy = RTL_CONSTANT_STRING(L"\\Device\\Floppy");
1842
1843 DPRINT1("FileFsDeviceInformation failed (Status 0x%08lx)\n", Status);
1844
1845 /* Definitively fail if the device is not a floppy */
1846 if (!RtlPrefixUnicodeString(&DeviceFloppy, &RootDrive, TRUE))
1847 return Status; /* We cannot cope with a failure */
1848
1849 /* Try to fall back to something "sane" if the device may be a floppy */
1850 DeviceInfo.DeviceType = FILE_DEVICE_DISK;
1852 }
1853
1854 /* Ignore volumes that are NOT on usual disks */
1855 if (DeviceInfo.DeviceType != FILE_DEVICE_DISK /*&&
1856 DeviceInfo.DeviceType != FILE_DEVICE_VIRTUAL_DISK*/)
1857 {
1858 DPRINT1("Invalid volume; device type %lu\n", DeviceInfo.DeviceType);
1860 }
1861
1862 /* Fail if the disk is not removable */
1863 if (!(DeviceInfo.Characteristics & FILE_REMOVABLE_MEDIA))
1864 {
1865 DPRINT1("Device is NOT removable!\n");
1867 }
1868
1869 /* Check whether this is a floppy or another removable device */
1870 IsFloppy = !!(DeviceInfo.Characteristics & FILE_FLOPPY_DISKETTE);
1871
1872 /* Use FAT32, unless the device is a floppy disk */
1873 FileSystemName = (IsFloppy ? L"FAT" : L"FAT32");
1874
1875 /* Format the removable disk */
1876 Status = FormatFileSystem_UStr(&RootDrive,
1877 FileSystemName,
1878 (IsFloppy ? FMIFS_FLOPPY : FMIFS_REMOVABLE),
1879 NULL,
1880 TRUE,
1881 0,
1882 NULL);
1883 if (!NT_SUCCESS(Status))
1884 {
1886 DPRINT1("%s FS non-existent on this system!\n", FileSystemName);
1887 else
1888 DPRINT1("FormatFileSystem(%s) failed (Status 0x%08lx)\n", FileSystemName, Status);
1889 return Status;
1890 }
1891
1892 /* Copy FreeLoader to the removable disk and save the boot entries */
1894 RemovableRootPath,
1895 SourceRootPath,
1896 DestinationArcPath,
1897 2 /* Install on removable media */);
1898 if (!NT_SUCCESS(Status))
1899 DPRINT1("InstallBootManagerAndBootEntries() failed (Status 0x%08lx)\n", Status);
1900 return Status;
1901}
unsigned char BOOLEAN
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:1662
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 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
#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 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 1662 of file bootsup.c.

1668{
1672 ULONG DiskNumber;
1673 PARTITION_STYLE PartitionStyle;
1676
1677 /* Remove any trailing backslash if needed */
1678 UNICODE_STRING RootPartition = *SystemRootPath;
1680
1681 /* Open the volume */
1685 if (!NT_SUCCESS(Status))
1686 {
1687 DPRINT1("Cannot open %wZ for bootloader installation (Status 0x%08lx)\n",
1689 return Status;
1690 }
1691
1692 /* Retrieve the volume file system (it will also be mounted) */
1694 FileSystem, sizeof(FileSystem));
1695 if (!NT_SUCCESS(Status) || !*FileSystem)
1696 {
1697 DPRINT1("GetFileSystemName() failed (Status 0x%08lx)\n", Status);
1698 goto Quit;
1699 }
1700
1701 /* Retrieve the device type and characteristics */
1703 if (!NT_SUCCESS(Status))
1704 {
1705 DPRINT1("FileFsDeviceInformation failed (Status 0x%08lx)\n", Status);
1706 goto Quit;
1707 }
1708
1709 /* Ignore volumes that are NOT on usual disks */
1710 if (DeviceInfo.DeviceType != FILE_DEVICE_DISK /*&&
1711 DeviceInfo.DeviceType != FILE_DEVICE_VIRTUAL_DISK*/)
1712 {
1713 DPRINT1("Invalid volume; device type %lu\n", DeviceInfo.DeviceType);
1715 goto Quit;
1716 }
1717
1718
1719 /* Check whether this is a floppy or a partitionable device */
1720 if (DeviceInfo.Characteristics & FILE_FLOPPY_DISKETTE)
1721 {
1722 /* Floppies don't have partitions */
1723 // NOTE: See ntoskrnl/io/iomgr/rawfs.c!RawQueryFsSizeInfo()
1724 DiskNumber = ULONG_MAX;
1725 PartitionStyle = PARTITION_STYLE_MBR;
1727 }
1728 else
1729 {
1732
1733 /* The maximum information a DISK_GEOMETRY_EX dynamic structure can contain */
1734 typedef struct _DISK_GEOMETRY_EX_INTERNAL
1735 {
1738 DISK_PARTITION_INFO Partition;
1739 /* Followed by: DISK_DETECTION_INFO Detection; unused here */
1741
1742 DISK_GEOMETRY_EX_INTERNAL DiskGeoEx;
1744
1745 /* Retrieve the disk number. NOTE: Fails for floppy disks. */
1747 NULL, NULL, NULL,
1750 NULL, 0,
1751 &DeviceNumber, sizeof(DeviceNumber));
1752 if (!NT_SUCCESS(Status))
1753 goto Quit; /* This may be a dynamic volume, which is unsupported */
1754 ASSERT(DeviceNumber.DeviceType == DeviceInfo.DeviceType);
1755 if (DeviceNumber.DeviceNumber == ULONG_MAX)
1756 {
1757 DPRINT1("Invalid disk number reported, bail out\n");
1759 goto Quit;
1760 }
1761
1762 /* Retrieve the drive geometry. NOTE: Fails for floppy disks;
1763 * use IOCTL_DISK_GET_DRIVE_GEOMETRY instead. */
1765 NULL, NULL, NULL,
1768 NULL, 0,
1769 &DiskGeoEx,
1770 sizeof(DiskGeoEx));
1771 if (!NT_SUCCESS(Status))
1772 {
1773 DPRINT1("IOCTL_DISK_GET_DRIVE_GEOMETRY_EX failed (Status 0x%08lx)\n", Status);
1774 goto Quit;
1775 }
1776
1777 /*
1778 * Retrieve the volume's partition information.
1779 * NOTE: Fails for floppy disks.
1780 *
1781 * NOTE: We can use the non-EX IOCTL because the super-floppy test will
1782 * fail anyway if the disk is NOT MBR-partitioned. (If the disk is GPT,
1783 * the IOCTL would return only the MBR protective partition, but the
1784 * super-floppy test would fail due to the wrong partitioning style.)
1785 */
1787 NULL, NULL, NULL,
1790 NULL, 0,
1792 sizeof(PartitionInfo));
1793 if (!NT_SUCCESS(Status))
1794 {
1795 DPRINT1("IOCTL_DISK_GET_PARTITION_INFO failed (Status 0x%08lx)\n", Status);
1796 goto Quit;
1797 }
1798
1799 DiskNumber = DeviceNumber.DeviceNumber;
1800 PartitionStyle = DiskGeoEx.Partition.PartitionStyle;
1802 (PULONGLONG)&DiskGeoEx.DiskSize.QuadPart,
1803 &PartitionInfo);
1804 }
1805
1807 ArchType, SystemRootPath,
1808 DiskNumber, PartitionStyle, IsSuperFloppy, FileSystem,
1809 SourceRootPath, DestinationArcPath, Options);
1810
1811Quit:
1813 return Status;
1814}
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:82
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().