xref: /reactos/base/setup/usetup/fmtchk.c (revision a7a7e6a0)
1 /*
2  * PROJECT:     ReactOS text-mode setup
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Filesystem Format and ChkDsk support functions
5  * COPYRIGHT:   Copyright 2003 Casper S. Hornstrup <chorns@users.sourceforge.net>
6  *              Copyright 2006 Hervé Poussineau <hpoussin@reactos.org>
7  *              Copyright 2024 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
8  */
9 
10 /* INCLUDES ******************************************************************/
11 
12 #include "usetup.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 static PPROGRESSBAR ProgressBar = NULL;
18 
19 /* FORMAT FUNCTIONS **********************************************************/
20 
21 static
22 BOOLEAN
23 NTAPI
FormatCallback(_In_ CALLBACKCOMMAND Command,_In_ ULONG Modifier,_In_ PVOID Argument)24 FormatCallback(
25     _In_ CALLBACKCOMMAND Command,
26     _In_ ULONG Modifier,
27     _In_ PVOID Argument)
28 {
29     switch (Command)
30     {
31         case PROGRESS:
32         {
33             PULONG Percent = (PULONG)Argument;
34             DPRINT("%lu percent completed\n", *Percent);
35             ProgressSetStep(ProgressBar, *Percent);
36             break;
37         }
38 
39 #if 0
40         case OUTPUT:
41         {
42             PTEXTOUTPUT output = (PTEXTOUTPUT)Argument;
43             DPRINT("%s\n", output->Output);
44             break;
45         }
46 #endif
47 
48         case DONE:
49         {
50 #if 0
51             PBOOLEAN Success = (PBOOLEAN)Argument;
52             if (*Success == FALSE)
53             {
54                 DPRINT("FormatEx was unable to complete successfully.\n\n");
55             }
56 #endif
57             DPRINT("Done\n");
58             break;
59         }
60 
61         default:
62             DPRINT("Unknown callback %lu\n", (ULONG)Command);
63             break;
64     }
65 
66     return TRUE;
67 }
68 
69 VOID
StartFormat(_Inout_ PFORMAT_VOLUME_INFO FmtInfo,_In_ PFILE_SYSTEM_ITEM SelectedFileSystem)70 StartFormat(
71     _Inout_ PFORMAT_VOLUME_INFO FmtInfo,
72     _In_ PFILE_SYSTEM_ITEM SelectedFileSystem)
73 {
74     ASSERT(SelectedFileSystem && SelectedFileSystem->FileSystem);
75 
76     // TODO: Think about which values could be defaulted...
77     FmtInfo->FileSystemName = SelectedFileSystem->FileSystem;
78     FmtInfo->MediaFlag = FMIFS_HARDDISK;
79     FmtInfo->Label = NULL;
80     FmtInfo->QuickFormat = SelectedFileSystem->QuickFormat;
81     FmtInfo->ClusterSize = 0;
82     FmtInfo->Callback = FormatCallback;
83 
84     ProgressBar = CreateProgressBar(6,
85                                     yScreen - 14,
86                                     xScreen - 7,
87                                     yScreen - 10,
88                                     10,
89                                     24,
90                                     TRUE,
91                                     MUIGetString(STRING_FORMATTINGPART));
92 
93     ProgressSetStepCount(ProgressBar, 100);
94 }
95 
96 VOID
EndFormat(_In_ NTSTATUS Status)97 EndFormat(
98     _In_ NTSTATUS Status)
99 {
100     DestroyProgressBar(ProgressBar);
101     ProgressBar = NULL;
102 
103     DPRINT("FormatPartition() finished with status 0x%08lx\n", Status);
104 }
105 
106 /* CHKDSK FUNCTIONS **********************************************************/
107 
108 static
109 BOOLEAN
110 NTAPI
ChkdskCallback(_In_ CALLBACKCOMMAND Command,_In_ ULONG Modifier,_In_ PVOID Argument)111 ChkdskCallback(
112     _In_ CALLBACKCOMMAND Command,
113     _In_ ULONG Modifier,
114     _In_ PVOID Argument)
115 {
116     switch (Command)
117     {
118         default:
119             DPRINT("Unknown callback %lu\n", (ULONG)Command);
120             break;
121     }
122 
123     return TRUE;
124 }
125 
126 VOID
StartCheck(_Inout_ PCHECK_VOLUME_INFO ChkInfo)127 StartCheck(
128     _Inout_ PCHECK_VOLUME_INFO ChkInfo)
129 {
130     // TODO: Think about which values could be defaulted...
131     ChkInfo->FixErrors = TRUE;
132     ChkInfo->Verbose = FALSE;
133     ChkInfo->CheckOnlyIfDirty = TRUE;
134     ChkInfo->ScanDrive = FALSE;
135     ChkInfo->Callback = ChkdskCallback;
136 
137     ProgressBar = CreateProgressBar(6,
138                                     yScreen - 14,
139                                     xScreen - 7,
140                                     yScreen - 10,
141                                     10,
142                                     24,
143                                     TRUE,
144                                     MUIGetString(STRING_CHECKINGDISK));
145 
146     ProgressSetStepCount(ProgressBar, 100);
147 }
148 
149 VOID
EndCheck(_In_ NTSTATUS Status)150 EndCheck(
151     _In_ NTSTATUS Status)
152 {
153     DestroyProgressBar(ProgressBar);
154     ProgressBar = NULL;
155 
156     DPRINT("ChkdskPartition() finished with status 0x%08lx\n", Status);
157 }
158 
159 /* EOF */
160