xref: /reactos/base/setup/lib/fsutil.h (revision d7c1d220)
1 /*
2  * PROJECT:     ReactOS Setup Library
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-2019 Casper S. Hornstrup <chorns@users.sourceforge.net>
6  *              Copyright 2017-2024 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
7  */
8 
9 #pragma once
10 
11 #include <fmifs/fmifs.h>
12 
13 /** QueryAvailableFileSystemFormat() **/
14 BOOLEAN
15 NTAPI
16 GetRegisteredFileSystems(
17     IN ULONG Index,
18     OUT PCWSTR* FileSystemName);
19 
20 
21 /** ChkdskEx() **/
22 NTSTATUS
23 NTAPI
24 ChkdskFileSystem_UStr(
25     _In_ PUNICODE_STRING DriveRoot,
26     _In_ PCWSTR FileSystemName,
27     _In_ BOOLEAN FixErrors,
28     _In_ BOOLEAN Verbose,
29     _In_ BOOLEAN CheckOnlyIfDirty,
30     _In_ BOOLEAN ScanDrive,
31     _In_opt_ PFMIFSCALLBACK Callback);
32 
33 NTSTATUS
34 NTAPI
35 ChkdskFileSystem(
36     _In_ PCWSTR DriveRoot,
37     _In_ PCWSTR FileSystemName,
38     _In_ BOOLEAN FixErrors,
39     _In_ BOOLEAN Verbose,
40     _In_ BOOLEAN CheckOnlyIfDirty,
41     _In_ BOOLEAN ScanDrive,
42     _In_opt_ PFMIFSCALLBACK Callback);
43 
44 
45 /** FormatEx() **/
46 NTSTATUS
47 NTAPI
48 FormatFileSystem_UStr(
49     _In_ PUNICODE_STRING DriveRoot,
50     _In_ PCWSTR FileSystemName,
51     _In_ FMIFS_MEDIA_FLAG MediaFlag,
52     _In_opt_ PUNICODE_STRING Label,
53     _In_ BOOLEAN QuickFormat,
54     _In_ ULONG ClusterSize,
55     _In_opt_ PFMIFSCALLBACK Callback);
56 
57 NTSTATUS
58 NTAPI
59 FormatFileSystem(
60     _In_ PCWSTR DriveRoot,
61     _In_ PCWSTR FileSystemName,
62     _In_ FMIFS_MEDIA_FLAG MediaFlag,
63     _In_opt_ PCWSTR Label,
64     _In_ BOOLEAN QuickFormat,
65     _In_ ULONG ClusterSize,
66     _In_opt_ PFMIFSCALLBACK Callback);
67 
68 
69 //
70 // Bootsector routines
71 //
72 
73 #define FAT_BOOTSECTOR_SIZE     (1 * SECTORSIZE)
74 #define FAT32_BOOTSECTOR_SIZE   (1 * SECTORSIZE) // Counts only the primary sector.
75 #define BTRFS_BOOTSECTOR_SIZE   (3 * SECTORSIZE)
76 #define NTFS_BOOTSECTOR_SIZE   (16 * SECTORSIZE)
77 
78 typedef NTSTATUS
79 (/*NTAPI*/ *PFS_INSTALL_BOOTCODE)(
80     IN PCWSTR SrcPath,          // Bootsector source file (on the installation medium)
81     IN HANDLE DstPath,          // Where to save the bootsector built from the source + partition information
82     IN HANDLE RootPartition);   // Partition holding the (old) bootsector data information
83 
84 NTSTATUS
85 InstallFatBootCode(
86     IN PCWSTR SrcPath,
87     IN HANDLE DstPath,
88     IN HANDLE RootPartition);
89 
90 #define InstallFat12BootCode    InstallFatBootCode
91 #define InstallFat16BootCode    InstallFatBootCode
92 
93 NTSTATUS
94 InstallFat32BootCode(
95     IN PCWSTR SrcPath,
96     IN HANDLE DstPath,
97     IN HANDLE RootPartition);
98 
99 NTSTATUS
100 InstallBtrfsBootCode(
101     IN PCWSTR SrcPath,
102     IN HANDLE DstPath,
103     IN HANDLE RootPartition);
104 
105 NTSTATUS
106 InstallNtfsBootCode(
107     IN PCWSTR SrcPath,
108     IN HANDLE DstPath,
109     IN HANDLE RootPartition);
110 
111 
112 //
113 // Formatting routines
114 //
115 
116 NTSTATUS
117 NTAPI
118 ChkdskPartition(
119     _In_ PPARTENTRY PartEntry,
120     _In_ BOOLEAN FixErrors,
121     _In_ BOOLEAN Verbose,
122     _In_ BOOLEAN CheckOnlyIfDirty,
123     _In_ BOOLEAN ScanDrive,
124     _In_opt_ PFMIFSCALLBACK Callback);
125 
126 NTSTATUS
127 NTAPI
128 FormatPartition(
129     _In_ PPARTENTRY PartEntry,
130     _In_ PCWSTR FileSystemName,
131     _In_ FMIFS_MEDIA_FLAG MediaFlag,
132     _In_opt_ PCWSTR Label,
133     _In_ BOOLEAN QuickFormat,
134     _In_ ULONG ClusterSize,
135     _In_opt_ PFMIFSCALLBACK Callback);
136 
137 
138 //
139 // FileSystem Volume Operations Queue
140 //
141 
142 typedef enum _FSVOLNOTIFY
143 {
144     FSVOLNOTIFY_STARTQUEUE = 0,
145     FSVOLNOTIFY_ENDQUEUE,
146     FSVOLNOTIFY_STARTSUBQUEUE,
147     FSVOLNOTIFY_ENDSUBQUEUE,
148 // FSVOLNOTIFY_STARTPARTITION, FSVOLNOTIFY_ENDPARTITION,
149     FSVOLNOTIFY_PARTITIONERROR,
150     FSVOLNOTIFY_STARTFORMAT,
151     FSVOLNOTIFY_ENDFORMAT,
152     FSVOLNOTIFY_FORMATERROR,
153     FSVOLNOTIFY_STARTCHECK,
154     FSVOLNOTIFY_ENDCHECK,
155     FSVOLNOTIFY_CHECKERROR,
156     /**/ChangeSystemPartition/**/ // FIXME: Deprecate!
157 } FSVOLNOTIFY;
158 
159 typedef enum _FSVOL_OP
160 {
161 /* Operations ****/
162     FSVOL_FORMAT = 0,
163     FSVOL_CHECK,
164 /* Response actions ****/
165     FSVOL_ABORT = 0,
166     FSVOL_DOIT,
167     FSVOL_RETRY = FSVOL_DOIT,
168     FSVOL_SKIP,
169 } FSVOL_OP;
170 
171 typedef struct _FORMAT_VOLUME_INFO
172 {
173     PVOLENTRY Volume;
174     // PCWSTR NtPathPartition;
175     NTSTATUS ErrorStatus;
176 
177 /* Input information given by the 'FSVOLNOTIFY_STARTFORMAT' step ****/
178     PCWSTR FileSystemName;
179     FMIFS_MEDIA_FLAG MediaFlag;
180     PCWSTR Label;
181     BOOLEAN QuickFormat;
182     ULONG ClusterSize;
183     PFMIFSCALLBACK Callback;
184 
185 } FORMAT_VOLUME_INFO, *PFORMAT_VOLUME_INFO;
186 
187 typedef struct _CHECK_VOLUME_INFO
188 {
189     PVOLENTRY Volume;
190     // PCWSTR NtPathPartition;
191     NTSTATUS ErrorStatus;
192 
193 /* Input information given by the 'FSVOLNOTIFY_STARTCHECK' step ****/
194     BOOLEAN FixErrors;
195     BOOLEAN Verbose;
196     BOOLEAN CheckOnlyIfDirty;
197     BOOLEAN ScanDrive;
198     PFMIFSCALLBACK Callback;
199 
200 } CHECK_VOLUME_INFO, *PCHECK_VOLUME_INFO;
201 
202 typedef FSVOL_OP
203 (CALLBACK *PFSVOL_CALLBACK)(
204     _In_opt_ PVOID Context,
205     _In_ FSVOLNOTIFY FormatStatus,
206     _In_ ULONG_PTR Param1,
207     _In_ ULONG_PTR Param2);
208 
209 BOOLEAN
210 NTAPI
211 FsVolCommitOpsQueue(
212     _In_ PPARTLIST PartitionList,
213     _In_ PVOLENTRY SystemVolume,
214     _In_ PVOLENTRY InstallVolume,
215     _In_opt_ PFSVOL_CALLBACK FsVolCallback,
216     _In_opt_ PVOID Context);
217 
218 /* EOF */
219