Skip to content

Commit

Permalink
WIP - [SETUPLIB][USETUP] Isolate and decouple the filesystem volume o…
Browse files Browse the repository at this point in the history
…perations code from the UI.

The idea is similar to the SetupCommitFileQueue() function:
filesystem volume operations are "queued" (and are retrieved via the
GetNextUnformatted/UncheckedPartition() helpers) and processed via a
"commit queue", that employs a user-specified callback. That latter
one can deal with displaying the appropriate UI screens, etc.
  • Loading branch information
HBelusca committed Nov 7, 2020
1 parent f980707 commit 1966935
Show file tree
Hide file tree
Showing 9 changed files with 1,327 additions and 726 deletions.
615 changes: 612 additions & 3 deletions base/setup/lib/fsutil.c

Large diffs are not rendered by default.

120 changes: 115 additions & 5 deletions base/setup/lib/fsutil.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* PROJECT: ReactOS Setup Library
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Filesystem support functions
* PURPOSE: Filesystem Format and ChkDsk support functions.
* COPYRIGHT: Copyright 2003-2019 Casper S. Hornstrup ([email protected])
* Copyright 2017-2020 Hermes Belusca-Maito
*/
Expand Down Expand Up @@ -101,11 +101,121 @@ InstallBtrfsBootCode(
// Formatting routines
//

struct _PARTENTRY; // Defined in partlist.h
NTSTATUS // ERROR_NUMBER
FormatPartition(
IN PPARTENTRY PartEntry,
IN PCWSTR FileSystemName,
IN FMIFS_MEDIA_FLAG MediaFlag,
IN PCWSTR Label,
IN BOOLEAN QuickFormat,
IN ULONG ClusterSize,
IN PFMIFSCALLBACK Callback);

NTSTATUS // ERROR_NUMBER
// ChkdskPartition
CheckPartition(
IN PPARTENTRY PartEntry,
IN BOOLEAN FixErrors,
IN BOOLEAN Verbose,
IN BOOLEAN CheckOnlyIfDirty,
IN BOOLEAN ScanDrive,
IN PFMIFSCALLBACK Callback);


//
// FileSystem Volume Operations Queue
//

// Like the SPFILENOTIFY_xxxx values
typedef enum _FSVOLNOTIFY
{
FSVOLNOTIFY_STARTQUEUE = 0,
FSVOLNOTIFY_ENDQUEUE,
FSVOLNOTIFY_STARTSUBQUEUE,
FSVOLNOTIFY_ENDSUBQUEUE,
FSVOLNOTIFY_PREPAREFORMAT,
FSVOLNOTIFY_STARTFORMAT,
FSVOLNOTIFY_ENDFORMAT,
ChangeSystemPartition, // FIXME: Deprecate!
SystemPartitionError, // FIXME: Deprecate!
FSVOLNOTIFY_FORMATERROR,
// FSVOLNOTIFY_PREPARECHECK,
FSVOLNOTIFY_STARTCHECK,
FSVOLNOTIFY_ENDCHECK,
FSVOLNOTIFY_CHECKERROR
} FSVOLNOTIFY;

// Like the FILEOP_xxxx values
typedef enum _FSVOL_OP
{
/* Operations ****/
FSVOL_FORMAT = 0,
FSVOL_CHECK,
/* Response actions ****/
FSVOL_ABORT = 0,
FSVOL_DOIT,
FSVOL_RETRY = FSVOL_DOIT,
FSVOL_SKIP,
} FSVOL_OP;

#define ERROR_SYSTEM_PARTITION_NOT_FOUND (ERROR_LAST_ERROR_CODE + 1)

typedef struct _FORMAT_PARTITION_INFO
{
PPARTENTRY PartEntry;
// PCWSTR NtPathPartition;
NTSTATUS ErrorStatus;

/* Input information given by the 'FSVOLNOTIFY_PREPAREFORMAT' step ****/
PCWSTR FileSystemName;
FMIFS_MEDIA_FLAG MediaFlag;
PCWSTR Label;
BOOLEAN QuickFormat;
ULONG ClusterSize;
PFMIFSCALLBACK Callback;

} FORMAT_PARTITION_INFO, *PFORMAT_PARTITION_INFO;

typedef struct _CHECK_PARTITION_INFO
{
PPARTENTRY PartEntry;
// PCWSTR NtPathPartition;
NTSTATUS ErrorStatus;

/* Input information given by the 'FSVOLNOTIFY_STARTCHECK' step ****/
// PCWSTR FileSystemName; // Obtained from PartEntry!
BOOLEAN FixErrors;
BOOLEAN Verbose;
BOOLEAN CheckOnlyIfDirty;
BOOLEAN ScanDrive;
PFMIFSCALLBACK Callback;

} CHECK_PARTITION_INFO, *PCHECK_PARTITION_INFO;

typedef FSVOL_OP
(CALLBACK *PFSVOL_CALLBACK)(
IN PVOID Context OPTIONAL,
IN FSVOLNOTIFY FormatStatus,
IN ULONG_PTR Param1,
IN ULONG_PTR Param2);

BOOLEAN
CommitFsVolOpsQueue(
IN PPARTLIST PartitionList,
IN PPARTENTRY InstallPartition,
IN PPARTENTRY SystemPartition,
IN PFSVOL_CALLBACK FsVolCallback OPTIONAL,
IN PVOID Context OPTIONAL);

/*
* FIXME: TODO: Setup-specific stuff; find a better place to put it!
*/
BOOLEAN
PreparePartitionForFormatting(
IN struct _PARTENTRY* PartEntry,
IN PCWSTR FileSystemName);
InitSystemPartition(
IN PPARTLIST PartitionList,
IN PPARTENTRY InstallPartition,
OUT PPARTENTRY* pSystemPartition,
IN PFSVOL_CALLBACK FsVolCallback OPTIONAL,
IN PVOID Context OPTIONAL);

/* EOF */
38 changes: 22 additions & 16 deletions base/setup/usetup/chkdsk.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* COPYRIGHT: See COPYING in the top level directory
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: base/setup/usetup/chkdsk.c
* PURPOSE: Filesystem chkdsk support functions
Expand Down Expand Up @@ -52,13 +53,23 @@ ChkdskCallback(
return TRUE;
}

// VOID
// PrepareCheck(
// IN OUT PCHECK_PARTITION_INFO PartInfo)
// {
// }

NTSTATUS
ChkdskPartition(
IN PUNICODE_STRING DriveRoot,
IN PCWSTR FileSystemName)
VOID
StartCheck(
IN OUT PCHECK_PARTITION_INFO PartInfo)
{
NTSTATUS Status;
// TODO: Think about which values could be defaulted...
// PartInfo->FileSystemName = PartInfo->PartEntry->FileSystem;
PartInfo->FixErrors = TRUE;
PartInfo->Verbose = FALSE;
PartInfo->CheckOnlyIfDirty = TRUE;
PartInfo->ScanDrive = FALSE;
PartInfo->Callback = ChkdskCallback;

ChkdskProgressBar = CreateProgressBar(6,
yScreen - 14,
Expand All @@ -70,21 +81,16 @@ ChkdskPartition(
MUIGetString(STRING_CHECKINGDISK));

ProgressSetStepCount(ChkdskProgressBar, 100);
}

Status = ChkdskFileSystem_UStr(DriveRoot,
FileSystemName,
TRUE, /* FixErrors */
FALSE, /* Verbose */
TRUE, /* CheckOnlyIfDirty */
FALSE, /* ScanDrive */
ChkdskCallback); /* Callback */

VOID
EndCheck(
IN NTSTATUS Status)
{
DestroyProgressBar(ChkdskProgressBar);
ChkdskProgressBar = NULL;

DPRINT("ChkdskPartition() finished with status 0x%08lx\n", Status);

return Status;
}

/* EOF */
15 changes: 11 additions & 4 deletions base/setup/usetup/chkdsk.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@

#pragma once

NTSTATUS
ChkdskPartition(
IN PUNICODE_STRING DriveRoot,
IN PCWSTR FileSystemName);
// VOID
// PrepareCheck(
// IN OUT PCHECK_PARTITION_INFO PartInfo);

VOID
StartCheck(
IN OUT PCHECK_PARTITION_INFO PartInfo);

VOID
EndCheck(
IN NTSTATUS Status);

/* EOF */
42 changes: 24 additions & 18 deletions base/setup/usetup/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* COPYRIGHT: See COPYING in the top level directory
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: base/setup/usetup/format.c
* PURPOSE: Filesystem format support functions
Expand Down Expand Up @@ -84,15 +85,25 @@ FormatCallback(
return TRUE;
}


NTSTATUS
FormatPartition(
IN PUNICODE_STRING DriveRoot,
IN PCWSTR FileSystemName,
IN BOOLEAN QuickFormat)
VOID
PrepareFormat(
IN OUT PFORMAT_PARTITION_INFO PartInfo,
IN PFILE_SYSTEM_ITEM SelectedFileSystem)
{
NTSTATUS Status;
ASSERT(SelectedFileSystem && SelectedFileSystem->FileSystem);

// TODO: Think about which values could be defaulted...
PartInfo->FileSystemName = SelectedFileSystem->FileSystem;
PartInfo->MediaFlag = FMIFS_HARDDISK;
PartInfo->Label = NULL;
PartInfo->QuickFormat = SelectedFileSystem->QuickFormat;
PartInfo->ClusterSize = 0;
PartInfo->Callback = FormatCallback;
}

VOID
StartFormat(VOID)
{
FormatProgressBar = CreateProgressBar(6,
yScreen - 14,
xScreen - 7,
Expand All @@ -103,21 +114,16 @@ FormatPartition(
MUIGetString(STRING_FORMATTINGDISK));

ProgressSetStepCount(FormatProgressBar, 100);
}

Status = FormatFileSystem_UStr(DriveRoot,
FileSystemName,
FMIFS_HARDDISK, /* MediaFlag */
NULL, /* Label */
QuickFormat, /* QuickFormat */
0, /* ClusterSize */
FormatCallback); /* Callback */

VOID
EndFormat(
IN NTSTATUS Status)
{
DestroyProgressBar(FormatProgressBar);
FormatProgressBar = NULL;

DPRINT("FormatPartition() finished with status 0x%08lx\n", Status);

return Status;
}

/* EOF */
16 changes: 11 additions & 5 deletions base/setup/usetup/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@

#pragma once

NTSTATUS
FormatPartition(
IN PUNICODE_STRING DriveRoot,
IN PCWSTR FileSystemName,
IN BOOLEAN QuickFormat);
VOID
PrepareFormat(
IN OUT PFORMAT_PARTITION_INFO PartInfo,
IN PFILE_SYSTEM_ITEM SelectedFileSystem);

VOID
StartFormat(VOID);

VOID
EndFormat(
IN NTSTATUS Status);

/* EOF */
13 changes: 0 additions & 13 deletions base/setup/usetup/partlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@

// #include "../lib/utils/partlist.h"

typedef enum _FORMATMACHINESTATE
{
Start,
FormatSystemPartition,
FormatInstallPartition,
FormatOtherPartition,
FormatDone,
// CheckSystemPartition,
// CheckInstallPartition,
// CheckOtherPartition,
// CheckDone
} FORMATMACHINESTATE, *PFORMATMACHINESTATE;

typedef struct _PARTLIST_UI
{
PPARTLIST List;
Expand Down
Loading

0 comments on commit 1966935

Please sign in to comment.