ReactOS 0.4.16-dev-981-g80eb313
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 1830 of file bootsup.c.

1835{
1838 PCWSTR FileSystemName;
1840
1841 /* Remove any trailing backslash if needed */
1842 UNICODE_STRING RootDrive = *RemovableRootPath;
1844
1845 /* Verify that the removable disk is accessible */
1846 if (!DoesDirExist(NULL, RemovableRootPath->Buffer))
1848
1849 /* Retrieve the device type and characteristics */
1850 Status = GetDeviceInfo_UStr(&RootDrive, NULL, &DeviceInfo);
1851 if (!NT_SUCCESS(Status))
1852 {
1853 static const UNICODE_STRING DeviceFloppy = RTL_CONSTANT_STRING(L"\\Device\\Floppy");
1854
1855 DPRINT1("FileFsDeviceInformation failed (Status 0x%08lx)\n", Status);
1856
1857 /* Definitively fail if the device is not a floppy */
1858 if (!RtlPrefixUnicodeString(&DeviceFloppy, &RootDrive, TRUE))
1859 return Status; /* We cannot cope with a failure */
1860
1861 /* Try to fall back to something "sane" if the device may be a floppy */
1862 DeviceInfo.DeviceType = FILE_DEVICE_DISK;
1864 }
1865
1866 /* Ignore volumes that are NOT on usual disks */
1867 if (DeviceInfo.DeviceType != FILE_DEVICE_DISK /*&&
1868 DeviceInfo.DeviceType != FILE_DEVICE_VIRTUAL_DISK*/)
1869 {
1870 DPRINT1("Invalid volume; device type %lu\n", DeviceInfo.DeviceType);
1872 }
1873
1874 /* Fail if the disk is not removable */
1875 if (!(DeviceInfo.Characteristics & FILE_REMOVABLE_MEDIA))
1876 {
1877 DPRINT1("Device is NOT removable!\n");
1879 }
1880
1881 /* Check whether this is a floppy or another removable device */
1882 IsFloppy = !!(DeviceInfo.Characteristics & FILE_FLOPPY_DISKETTE);
1883
1884 /* Use FAT32, unless the device is a floppy disk */
1885 FileSystemName = (IsFloppy ? L"FAT" : L"FAT32");
1886
1887 /* Format the removable disk */
1888 Status = FormatFileSystem_UStr(&RootDrive,
1889 FileSystemName,
1891 NULL,
1892 TRUE,
1893 0,
1894 NULL);
1895 if (!NT_SUCCESS(Status))
1896 {
1898 DPRINT1("%s FS non-existent on this system!\n", FileSystemName);
1899 else
1900 DPRINT1("FormatFileSystem(%s) failed (Status 0x%08lx)\n", FileSystemName, Status);
1901 return Status;
1902 }
1903
1904 /* Copy FreeLoader to the removable disk and save the boot entries */
1906 RemovableRootPath,
1907 SourceRootPath,
1908 DestinationArcPath,
1909 2 /* Install on removable media */);
1910 if (!NT_SUCCESS(Status))
1911 DPRINT1("InstallBootManagerAndBootEntries() failed (Status 0x%08lx)\n", Status);
1912 return Status;
1913}
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:1674
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:1580
#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
static BOOL IsFloppy(PCWSTR pszDrive)
Definition: drive.cpp:48
#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 1674 of file bootsup.c.

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