[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
/*
* PROJECT : ReactOS Setup Library
* LICENSE : GPL - 2.0 + ( https : //spdx.org/licenses/GPL-2.0+)
* PURPOSE : Filesystem support functions
2019-02-24 16:52:33 +00:00
* COPYRIGHT : Copyright 2003 - 2019 Casper S . Hornstrup ( chorns @ users . sourceforge . net )
2020-10-17 18:29:47 +00:00
* Copyright 2017 - 2020 Hermes Belusca - Maito
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
*/
//
// See also: https://git.reactos.org/?p=reactos.git;a=blob;f=reactos/dll/win32/fmifs/init.c;h=e895f5ef9cae4806123f6bbdd3dfed37ec1c8d33;hb=b9db9a4e377a2055f635b2fb69fef4e1750d219c
// for how to get FS providers in a dynamic way. In the (near) future we may
// consider merging some of this code with us into a fmifs / fsutil / fslib library...
//
/* INCLUDES *****************************************************************/
# include "precomp.h"
# include "partlist.h"
2020-10-11 21:42:02 +00:00
# include "fsrec.h"
2020-10-17 18:29:47 +00:00
# include "bootcode.h"
2020-10-11 21:42:02 +00:00
# include "fsutil.h"
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
# include <fslib/vfatlib.h>
2018-06-13 23:30:06 +00:00
# include <fslib/btrfslib.h>
2017-05-17 23:31:52 +00:00
// #include <fslib/ext2lib.h>
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
// #include <fslib/ntfslib.h>
# define NDEBUG
# include <debug.h>
2020-10-17 18:29:47 +00:00
/* TYPEDEFS *****************************************************************/
# include <pshpack1.h>
typedef struct _FAT_BOOTSECTOR
{
UCHAR JumpBoot [ 3 ] ; // Jump instruction to boot code
CHAR OemName [ 8 ] ; // "MSWIN4.1" for MS formatted volumes
USHORT BytesPerSector ; // Bytes per sector
UCHAR SectorsPerCluster ; // Number of sectors in a cluster
USHORT ReservedSectors ; // Reserved sectors, usually 1 (the bootsector)
UCHAR NumberOfFats ; // Number of FAT tables
USHORT RootDirEntries ; // Number of root directory entries (fat12/16)
USHORT TotalSectors ; // Number of total sectors on the drive, 16-bit
UCHAR MediaDescriptor ; // Media descriptor byte
USHORT SectorsPerFat ; // Sectors per FAT table (fat12/16)
USHORT SectorsPerTrack ; // Number of sectors in a track
USHORT NumberOfHeads ; // Number of heads on the disk
ULONG HiddenSectors ; // Hidden sectors (sectors before the partition start like the partition table)
ULONG TotalSectorsBig ; // This field is the new 32-bit total count of sectors on the volume
UCHAR DriveNumber ; // Int 0x13 drive number (e.g. 0x80)
UCHAR Reserved1 ; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
UCHAR BootSignature ; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
ULONG VolumeSerialNumber ; // Volume serial number
CHAR VolumeLabel [ 11 ] ; // Volume label. This field matches the 11-byte volume label recorded in the root directory
CHAR FileSystemType [ 8 ] ; // One of the strings "FAT12 ", "FAT16 ", or "FAT "
UCHAR BootCodeAndData [ 448 ] ; // The remainder of the boot sector
USHORT BootSectorMagic ; // 0xAA55
} FAT_BOOTSECTOR , * PFAT_BOOTSECTOR ;
C_ASSERT ( sizeof ( FAT_BOOTSECTOR ) = = FAT_BOOTSECTOR_SIZE ) ;
typedef struct _FAT32_BOOTSECTOR
{
UCHAR JumpBoot [ 3 ] ; // Jump instruction to boot code
CHAR OemName [ 8 ] ; // "MSWIN4.1" for MS formatted volumes
USHORT BytesPerSector ; // Bytes per sector
UCHAR SectorsPerCluster ; // Number of sectors in a cluster
USHORT ReservedSectors ; // Reserved sectors, usually 1 (the bootsector)
UCHAR NumberOfFats ; // Number of FAT tables
USHORT RootDirEntries ; // Number of root directory entries (fat12/16)
USHORT TotalSectors ; // Number of total sectors on the drive, 16-bit
UCHAR MediaDescriptor ; // Media descriptor byte
USHORT SectorsPerFat ; // Sectors per FAT table (fat12/16)
USHORT SectorsPerTrack ; // Number of sectors in a track
USHORT NumberOfHeads ; // Number of heads on the disk
ULONG HiddenSectors ; // Hidden sectors (sectors before the partition start like the partition table)
ULONG TotalSectorsBig ; // This field is the new 32-bit total count of sectors on the volume
ULONG SectorsPerFatBig ; // This field is the FAT32 32-bit count of sectors occupied by ONE FAT. BPB_FATSz16 must be 0
USHORT ExtendedFlags ; // Extended flags (fat32)
USHORT FileSystemVersion ; // File system version (fat32)
ULONG RootDirStartCluster ; // Starting cluster of the root directory (fat32)
USHORT FsInfo ; // Sector number of FSINFO structure in the reserved area of the FAT32 volume. Usually 1.
USHORT BackupBootSector ; // If non-zero, indicates the sector number in the reserved area of the volume of a copy of the boot record. Usually 6.
UCHAR Reserved [ 12 ] ; // Reserved for future expansion
UCHAR DriveNumber ; // Int 0x13 drive number (e.g. 0x80)
UCHAR Reserved1 ; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
UCHAR BootSignature ; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
ULONG VolumeSerialNumber ; // Volume serial number
CHAR VolumeLabel [ 11 ] ; // Volume label. This field matches the 11-byte volume label recorded in the root directory
CHAR FileSystemType [ 8 ] ; // Always set to the string "FAT32 "
UCHAR BootCodeAndData [ 420 ] ; // The remainder of the boot sector
USHORT BootSectorMagic ; // 0xAA55
} FAT32_BOOTSECTOR , * PFAT32_BOOTSECTOR ;
C_ASSERT ( sizeof ( FAT32_BOOTSECTOR ) = = FAT32_BOOTSECTOR_SIZE ) ;
typedef struct _BTRFS_BOOTSECTOR
{
UCHAR JumpBoot [ 3 ] ;
UCHAR ChunkMapSize ;
UCHAR BootDrive ;
ULONGLONG PartitionStartLBA ;
UCHAR Fill [ 1521 ] ; // 1536 - 15
USHORT BootSectorMagic ;
} BTRFS_BOOTSECTOR , * PBTRFS_BOOTSECTOR ;
C_ASSERT ( sizeof ( BTRFS_BOOTSECTOR ) = = BTRFS_BOOTSECTOR_SIZE ) ;
// TODO: Add more bootsector structures!
# include <poppack.h>
2019-02-24 16:52:33 +00:00
/* LOCALS *******************************************************************/
/** IFS_PROVIDER **/
typedef struct _FILE_SYSTEM
{
PCWSTR FileSystemName ;
FORMATEX FormatFunc ;
CHKDSKEX ChkdskFunc ;
} FILE_SYSTEM , * PFILE_SYSTEM ;
2018-11-12 23:13:45 +00:00
/* The list of file systems on which we can install ReactOS */
2019-02-24 16:52:33 +00:00
static FILE_SYSTEM RegisteredFileSystems [ ] =
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
{
2020-10-19 21:49:26 +00:00
/* NOTE: The FAT formatter will automatically
* determine whether to use FAT12 / 16 or FAT32 . */
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
{ L " FAT " , VfatFormat , VfatChkdsk } ,
2020-10-19 21:49:26 +00:00
{ L " FAT32 " , VfatFormat , VfatChkdsk } ,
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
#if 0
2017-05-17 23:31:52 +00:00
{ L " FATX " , VfatxFormat , VfatxChkdsk } ,
{ L " NTFS " , NtfsFormat , NtfsChkdsk } ,
2018-06-13 23:30:06 +00:00
# endif
2017-05-17 23:31:52 +00:00
{ L " BTRFS " , BtrfsFormatEx , BtrfsChkdskEx } ,
2018-06-13 23:30:06 +00:00
#if 0
2018-11-12 23:13:45 +00:00
{ L " EXT2 " , Ext2Format , Ext2Chkdsk } ,
{ L " EXT3 " , Ext2Format , Ext2Chkdsk } ,
{ L " EXT4 " , Ext2Format , Ext2Chkdsk } ,
2017-05-17 23:31:52 +00:00
{ L " FFS " , FfsFormat , FfsChkdsk } ,
{ L " REISERFS " , ReiserfsFormat , ReiserfsChkdsk } ,
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
# endif
} ;
/* FUNCTIONS ****************************************************************/
2019-02-24 16:52:33 +00:00
/** QueryAvailableFileSystemFormat() **/
BOOLEAN
GetRegisteredFileSystems (
IN ULONG Index ,
OUT PCWSTR * FileSystemName )
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
{
2019-02-24 16:52:33 +00:00
if ( Index > = ARRAYSIZE ( RegisteredFileSystems ) )
return FALSE ;
* FileSystemName = RegisteredFileSystems [ Index ] . FileSystemName ;
return TRUE ;
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
}
2019-02-24 16:52:33 +00:00
/** GetProvider() **/
static PFILE_SYSTEM
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
GetFileSystemByName (
IN PCWSTR FileSystemName )
{
#if 0 // Reenable when the list of registered FSes will again be dynamic
PLIST_ENTRY ListEntry ;
PFILE_SYSTEM_ITEM Item ;
ListEntry = List - > ListHead . Flink ;
while ( ListEntry ! = & List - > ListHead )
{
Item = CONTAINING_RECORD ( ListEntry , FILE_SYSTEM_ITEM , ListEntry ) ;
2019-02-24 16:52:33 +00:00
if ( Item - > FileSystemName & &
2020-10-19 21:49:26 +00:00
( wcsicmp ( FileSystemName , Item - > FileSystemName ) = = 0 ) )
2019-02-24 16:52:33 +00:00
{
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
return Item ;
2019-02-24 16:52:33 +00:00
}
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
ListEntry = ListEntry - > Flink ;
}
# else
2019-02-24 16:52:33 +00:00
ULONG Count = ARRAYSIZE ( RegisteredFileSystems ) ;
PFILE_SYSTEM FileSystems = RegisteredFileSystems ;
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
2019-02-24 16:52:33 +00:00
ASSERT ( FileSystems & & Count ! = 0 ) ;
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
while ( Count - - )
{
2019-02-24 16:52:33 +00:00
if ( FileSystems - > FileSystemName & &
2020-10-19 21:49:26 +00:00
( wcsicmp ( FileSystemName , FileSystems - > FileSystemName ) = = 0 ) )
2019-02-24 16:52:33 +00:00
{
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
return FileSystems ;
2019-02-24 16:52:33 +00:00
}
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
+ + FileSystems ;
}
# endif
return NULL ;
}
2019-02-24 16:52:33 +00:00
/** ChkdskEx() **/
NTSTATUS
ChkdskFileSystem_UStr (
IN PUNICODE_STRING DriveRoot ,
IN PCWSTR FileSystemName ,
IN BOOLEAN FixErrors ,
IN BOOLEAN Verbose ,
IN BOOLEAN CheckOnlyIfDirty ,
IN BOOLEAN ScanDrive ,
IN PFMIFSCALLBACK Callback )
{
PFILE_SYSTEM FileSystem ;
2017-05-17 23:31:52 +00:00
2019-02-24 16:52:33 +00:00
FileSystem = GetFileSystemByName ( FileSystemName ) ;
2017-05-17 23:31:52 +00:00
2019-02-24 16:52:33 +00:00
if ( ! FileSystem | | ! FileSystem - > ChkdskFunc )
{
// BOOLEAN Argument = FALSE;
// Callback(DONE, 0, &Argument);
return STATUS_NOT_SUPPORTED ;
}
return FileSystem - > ChkdskFunc ( DriveRoot ,
FixErrors ,
Verbose ,
CheckOnlyIfDirty ,
ScanDrive ,
Callback ) ;
}
NTSTATUS
ChkdskFileSystem (
IN PCWSTR DriveRoot ,
IN PCWSTR FileSystemName ,
IN BOOLEAN FixErrors ,
IN BOOLEAN Verbose ,
IN BOOLEAN CheckOnlyIfDirty ,
IN BOOLEAN ScanDrive ,
IN PFMIFSCALLBACK Callback )
{
UNICODE_STRING DriveRootU ;
RtlInitUnicodeString ( & DriveRootU , DriveRoot ) ;
return ChkdskFileSystem_UStr ( & DriveRootU ,
FileSystemName ,
FixErrors ,
Verbose ,
CheckOnlyIfDirty ,
ScanDrive ,
Callback ) ;
}
/** FormatEx() **/
NTSTATUS
FormatFileSystem_UStr (
IN PUNICODE_STRING DriveRoot ,
IN PCWSTR FileSystemName ,
IN FMIFS_MEDIA_FLAG MediaFlag ,
IN PUNICODE_STRING Label ,
IN BOOLEAN QuickFormat ,
IN ULONG ClusterSize ,
IN PFMIFSCALLBACK Callback )
2017-05-17 23:31:52 +00:00
{
2019-02-24 16:52:33 +00:00
PFILE_SYSTEM FileSystem ;
FileSystem = GetFileSystemByName ( FileSystemName ) ;
if ( ! FileSystem | | ! FileSystem - > FormatFunc )
2017-05-17 23:31:52 +00:00
{
2019-02-24 16:52:33 +00:00
// BOOLEAN Argument = FALSE;
// Callback(DONE, 0, &Argument);
return STATUS_NOT_SUPPORTED ;
2017-05-17 23:31:52 +00:00
}
2019-02-24 16:52:33 +00:00
return FileSystem - > FormatFunc ( DriveRoot ,
MediaFlag ,
Label ,
QuickFormat ,
ClusterSize ,
Callback ) ;
}
NTSTATUS
FormatFileSystem (
IN PCWSTR DriveRoot ,
IN PCWSTR FileSystemName ,
IN FMIFS_MEDIA_FLAG MediaFlag ,
IN PCWSTR Label ,
IN BOOLEAN QuickFormat ,
IN ULONG ClusterSize ,
IN PFMIFSCALLBACK Callback )
{
UNICODE_STRING DriveRootU ;
UNICODE_STRING LabelU ;
RtlInitUnicodeString ( & DriveRootU , DriveRoot ) ;
RtlInitUnicodeString ( & LabelU , Label ) ;
return FormatFileSystem_UStr ( & DriveRootU ,
FileSystemName ,
MediaFlag ,
& LabelU ,
QuickFormat ,
ClusterSize ,
Callback ) ;
}
2020-10-17 18:29:47 +00:00
//
// Bootsector routines
//
NTSTATUS
2020-10-19 21:49:26 +00:00
InstallFatBootCode (
2020-10-17 18:29:47 +00:00
IN PCWSTR SrcPath , // FAT12/16 bootsector source file (on the installation medium)
IN HANDLE DstPath , // Where to save the bootsector built from the source + partition information
IN HANDLE RootPartition ) // Partition holding the (old) FAT12/16 information
{
NTSTATUS Status ;
UNICODE_STRING Name ;
IO_STATUS_BLOCK IoStatusBlock ;
LARGE_INTEGER FileOffset ;
BOOTCODE OrigBootSector = { 0 } ;
BOOTCODE NewBootSector = { 0 } ;
/* Allocate and read the current original partition bootsector */
Status = ReadBootCodeByHandle ( & OrigBootSector ,
RootPartition ,
FAT_BOOTSECTOR_SIZE ) ;
if ( ! NT_SUCCESS ( Status ) )
return Status ;
/* Allocate and read the new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
Status = ReadBootCodeFromFile ( & NewBootSector ,
& Name ,
FAT_BOOTSECTOR_SIZE ) ;
if ( ! NT_SUCCESS ( Status ) )
{
FreeBootCode ( & OrigBootSector ) ;
return Status ;
}
/* Adjust the bootsector (copy a part of the FAT12/16 BPB) */
RtlCopyMemory ( & ( ( PFAT_BOOTSECTOR ) NewBootSector . BootCode ) - > OemName ,
& ( ( PFAT_BOOTSECTOR ) OrigBootSector . BootCode ) - > OemName ,
FIELD_OFFSET ( FAT_BOOTSECTOR , BootCodeAndData ) -
FIELD_OFFSET ( FAT_BOOTSECTOR , OemName ) ) ;
/* Free the original bootsector */
FreeBootCode ( & OrigBootSector ) ;
/* Write the new bootsector to DstPath */
FileOffset . QuadPart = 0ULL ;
Status = NtWriteFile ( DstPath ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector . BootCode ,
NewBootSector . Length ,
& FileOffset ,
NULL ) ;
/* Free the new bootsector */
FreeBootCode ( & NewBootSector ) ;
return Status ;
}
NTSTATUS
InstallFat32BootCode (
IN PCWSTR SrcPath , // FAT32 bootsector source file (on the installation medium)
IN HANDLE DstPath , // Where to save the bootsector built from the source + partition information
IN HANDLE RootPartition ) // Partition holding the (old) FAT32 information
{
NTSTATUS Status ;
UNICODE_STRING Name ;
IO_STATUS_BLOCK IoStatusBlock ;
LARGE_INTEGER FileOffset ;
USHORT BackupBootSector = 0 ;
BOOTCODE OrigBootSector = { 0 } ;
BOOTCODE NewBootSector = { 0 } ;
/* Allocate and read the current original partition bootsector */
Status = ReadBootCodeByHandle ( & OrigBootSector ,
RootPartition ,
FAT32_BOOTSECTOR_SIZE ) ;
if ( ! NT_SUCCESS ( Status ) )
return Status ;
/* Allocate and read the new bootsector (2 sectors) from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
Status = ReadBootCodeFromFile ( & NewBootSector ,
& Name ,
2 * FAT32_BOOTSECTOR_SIZE ) ;
if ( ! NT_SUCCESS ( Status ) )
{
FreeBootCode ( & OrigBootSector ) ;
return Status ;
}
/* Adjust the bootsector (copy a part of the FAT32 BPB) */
RtlCopyMemory ( & ( ( PFAT32_BOOTSECTOR ) NewBootSector . BootCode ) - > OemName ,
& ( ( PFAT32_BOOTSECTOR ) OrigBootSector . BootCode ) - > OemName ,
FIELD_OFFSET ( FAT32_BOOTSECTOR , BootCodeAndData ) -
FIELD_OFFSET ( FAT32_BOOTSECTOR , OemName ) ) ;
/*
* We know we copy the boot code to a file only when DstPath ! = RootPartition ,
* otherwise the boot code is copied to the specified root partition .
*/
if ( DstPath ! = RootPartition )
{
/* Copy to a file: Disable the backup bootsector */
( ( PFAT32_BOOTSECTOR ) NewBootSector . BootCode ) - > BackupBootSector = 0 ;
}
else
{
/* Copy to a disk: Get the location of the backup bootsector */
BackupBootSector = ( ( PFAT32_BOOTSECTOR ) OrigBootSector . BootCode ) - > BackupBootSector ;
}
/* Free the original bootsector */
FreeBootCode ( & OrigBootSector ) ;
/* Write the first sector of the new bootcode to DstPath sector 0 */
FileOffset . QuadPart = 0ULL ;
Status = NtWriteFile ( DstPath ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector . BootCode ,
FAT32_BOOTSECTOR_SIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
FreeBootCode ( & NewBootSector ) ;
return Status ;
}
if ( DstPath = = RootPartition )
{
/* Copy to a disk: Write the backup bootsector */
if ( ( BackupBootSector ! = 0x0000 ) & & ( BackupBootSector ! = 0xFFFF ) )
{
FileOffset . QuadPart = ( ULONGLONG ) ( ( ULONG ) BackupBootSector * FAT32_BOOTSECTOR_SIZE ) ;
Status = NtWriteFile ( DstPath ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector . BootCode ,
FAT32_BOOTSECTOR_SIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
FreeBootCode ( & NewBootSector ) ;
return Status ;
}
}
}
/* Write the second sector of the new bootcode to boot disk sector 14 */
// FileOffset.QuadPart = (ULONGLONG)(14 * FAT32_BOOTSECTOR_SIZE);
FileOffset . QuadPart = 14 * FAT32_BOOTSECTOR_SIZE ;
Status = NtWriteFile ( DstPath , // or really RootPartition ???
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
( ( PUCHAR ) NewBootSector . BootCode + FAT32_BOOTSECTOR_SIZE ) ,
FAT32_BOOTSECTOR_SIZE ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
}
/* Free the new bootsector */
FreeBootCode ( & NewBootSector ) ;
return Status ;
}
NTSTATUS
InstallBtrfsBootCode (
IN PCWSTR SrcPath , // BTRFS bootsector source file (on the installation medium)
IN HANDLE DstPath , // Where to save the bootsector built from the source + partition information
IN HANDLE RootPartition ) // Partition holding the (old) BTRFS information
{
NTSTATUS Status ;
NTSTATUS LockStatus ;
UNICODE_STRING Name ;
IO_STATUS_BLOCK IoStatusBlock ;
LARGE_INTEGER FileOffset ;
PARTITION_INFORMATION_EX PartInfo ;
BOOTCODE NewBootSector = { 0 } ;
/* Allocate and read the new bootsector from SrcPath */
RtlInitUnicodeString ( & Name , SrcPath ) ;
Status = ReadBootCodeFromFile ( & NewBootSector ,
& Name ,
BTRFS_BOOTSECTOR_SIZE ) ;
if ( ! NT_SUCCESS ( Status ) )
return Status ;
/*
* The BTRFS driver requires the volume to be locked in order to modify
* the first sectors of the partition , even though they are outside the
* file - system space / in the reserved area ( they are situated before
* the super - block at 0x1000 ) and is in principle allowed by the NT
* storage stack .
* So we lock here in order to write the bootsector at sector 0.
* If locking fails , we ignore and continue nonetheless .
*/
LockStatus = NtFsControlFile ( DstPath ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
FSCTL_LOCK_VOLUME ,
NULL ,
0 ,
NULL ,
0 ) ;
if ( ! NT_SUCCESS ( LockStatus ) )
{
DPRINT1 ( " WARNING: Failed to lock BTRFS volume for writing bootsector! Operations may fail! (Status 0x%lx) \n " , LockStatus ) ;
}
/* Obtain partition info and write it to the bootsector */
Status = NtDeviceIoControlFile ( RootPartition ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
IOCTL_DISK_GET_PARTITION_INFO_EX ,
NULL ,
0 ,
& PartInfo ,
sizeof ( PartInfo ) ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " IOCTL_DISK_GET_PARTITION_INFO_EX failed (Status %lx) \n " , Status ) ;
goto Quit ;
}
/* Write new bootsector to RootPath */
( ( PBTRFS_BOOTSECTOR ) NewBootSector . BootCode ) - > PartitionStartLBA =
PartInfo . StartingOffset . QuadPart / SECTORSIZE ;
/* Write sector 0 */
FileOffset . QuadPart = 0ULL ;
Status = NtWriteFile ( DstPath ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
NewBootSector . BootCode ,
NewBootSector . Length ,
& FileOffset ,
NULL ) ;
if ( ! NT_SUCCESS ( Status ) )
{
DPRINT1 ( " NtWriteFile() failed (Status %lx) \n " , Status ) ;
goto Quit ;
}
Quit :
/* Unlock the volume */
LockStatus = NtFsControlFile ( DstPath ,
NULL ,
NULL ,
NULL ,
& IoStatusBlock ,
FSCTL_UNLOCK_VOLUME ,
NULL ,
0 ,
NULL ,
0 ) ;
if ( ! NT_SUCCESS ( LockStatus ) )
{
DPRINT1 ( " Failed to unlock BTRFS volume (Status 0x%lx) \n " , LockStatus ) ;
}
/* Free the new bootsector */
FreeBootCode ( & NewBootSector ) ;
return Status ;
}
2019-02-24 16:52:33 +00:00
//
// Formatting routines
//
BOOLEAN
PreparePartitionForFormatting (
IN struct _PARTENTRY * PartEntry ,
IN PCWSTR FileSystemName )
{
UCHAR PartitionType ;
if ( ! FileSystemName | | ! * FileSystemName )
{
DPRINT1 ( " No file system specified? \n " ) ;
return FALSE ;
}
PartitionType = FileSystemToPartitionType ( FileSystemName ,
& PartEntry - > StartSector ,
& PartEntry - > SectorCount ) ;
if ( PartitionType = = PARTITION_ENTRY_UNUSED )
2017-05-17 23:31:52 +00:00
{
2019-02-24 16:52:33 +00:00
/* Unknown file system */
DPRINT1 ( " Unknown file system '%S' \n " , FileSystemName ) ;
2017-05-17 23:31:52 +00:00
return FALSE ;
}
2019-02-24 16:52:33 +00:00
SetPartitionType ( PartEntry , PartitionType ) ;
2020-10-19 21:49:26 +00:00
/*
* Adjust the filesystem name in case of FAT vs . FAT32 , according to
* the type of partition set by FileSystemToPartitionType ( ) .
*/
if ( wcsicmp ( FileSystemName , L " FAT " ) = = 0 )
{
if ( ( /*PartEntry->*/ PartitionType = = PARTITION_FAT32 ) | |
( /*PartEntry->*/ PartitionType = = PARTITION_FAT32_XINT13 ) )
{
FileSystemName = L " FAT32 " ;
}
}
2017-05-17 23:31:52 +00:00
//
// FIXME: Do this now, or after the partition was actually formatted??
//
/* Set the new partition's file system proper */
2019-02-24 16:52:33 +00:00
RtlStringCbCopyW ( PartEntry - > FileSystem ,
sizeof ( PartEntry - > FileSystem ) ,
FileSystemName ) ;
2017-05-17 23:31:52 +00:00
return TRUE ;
}
[SETUPLIB][USETUP] Introduce a 'SetupLib' library. CORE-13544
- Create the beginnings of a "setuplib" library, whose aim is to be shared between the (currently existing) 1st-stage text-mode installer, and the (future) 1st-stage GUI installer.
- Finish to split the GenList and PartList codes into their UI part, which remain in usetup, and their algorithmic part, which go into setuplib.
- Move SetMountedDeviceValue into the PartList module.
- Split the FileSystem list code into its UI and the algorithmic part (which goes into setuplib under the name fsutil.c).
* The algo part is meant to be able to manage the filesystems available on the running system, similarly to what is mostly done (in scattered form) in fmifs, format, chkdsk / autochk codes...
It also manages the partition filesystem recognition, using OS routines.
* The UI part manages the FS list as it appears on screen, showing only the possible FSes that can be used to format the selected partition (a bit similar to what we do in the shell32's drive.c, etc...).
- Adapt the calling code to these changes.
- Remove some "host" code that was dating back from the dark old times.
svn path=/branches/setup_improvements/; revision=74570
svn path=/branches/setup_improvements/; revision=74659
2017-05-17 23:37:41 +00:00
/* EOF */