xref: /reactos/dll/win32/fmifs/chkdsk.c (revision e4930be4)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         File Management IFS Utility functions
4  * FILE:            reactos/dll/win32/fmifs/chkdsk.c
5  * PURPOSE:         Disk Checker
6  *
7  * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8  */
9 
10 #include "precomp.h"
11 #include <ntstrsafe.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FMIFS.1 */
17 VOID
18 NTAPI
19 Chkdsk(
20     IN PWCHAR DriveRoot,
21     IN PWCHAR Format,
22     IN BOOLEAN CorrectErrors,
23     IN BOOLEAN Verbose,
24     IN BOOLEAN CheckOnlyIfDirty,
25     IN BOOLEAN ScanDrive,
26     IN PVOID Unused2,
27     IN PVOID Unused3,
28     IN PFMIFSCALLBACK Callback)
29 {
30     PIFS_PROVIDER Provider;
31     UNICODE_STRING usDriveRoot;
32     NTSTATUS Status;
33     BOOLEAN Success = FALSE;
34     WCHAR DriveName[MAX_PATH];
35     WCHAR VolumeName[MAX_PATH];
36 
37     Provider = GetProvider(Format);
38     if (!Provider)
39     {
40         /* Unknown file system */
41         goto Quit;
42     }
43 
44     if (!NT_SUCCESS(RtlStringCchCopyW(DriveName, ARRAYSIZE(DriveName), DriveRoot)))
45         goto Quit;
46 
47     if (DriveName[wcslen(DriveName) - 1] != L'\\')
48     {
49         /* Append the trailing backslash for GetVolumeNameForVolumeMountPointW */
50         if (!NT_SUCCESS(RtlStringCchCatW(DriveName, ARRAYSIZE(DriveName), L"\\")))
51             goto Quit;
52     }
53 
54     if (!GetVolumeNameForVolumeMountPointW(DriveName, VolumeName, ARRAYSIZE(VolumeName)))
55     {
56         /* Couldn't get a volume GUID path, try checking using a parameter provided path */
57         DPRINT1("Couldn't get a volume GUID path for drive %S\n", DriveName);
58         wcscpy(VolumeName, DriveName);
59     }
60 
61     if (!RtlDosPathNameToNtPathName_U(VolumeName, &usDriveRoot, NULL, NULL))
62         goto Quit;
63 
64     /* Trim the trailing backslash since we will work with a device object */
65     usDriveRoot.Length -= sizeof(WCHAR);
66 
67     DPRINT("Chkdsk() - %S\n", Format);
68     Status = STATUS_SUCCESS;
69     Success = Provider->Chkdsk(&usDriveRoot,
70                                Callback,
71                                CorrectErrors,
72                                Verbose,
73                                CheckOnlyIfDirty,
74                                ScanDrive,
75                                NULL,
76                                NULL,
77                                NULL,
78                                NULL,
79                                (PULONG)&Status);
80     if (!Success)
81         DPRINT1("Chkdsk() failed with Status 0x%lx\n", Status);
82 
83     RtlFreeUnicodeString(&usDriveRoot);
84 
85 Quit:
86     /* Report result */
87     Callback(DONE, 0, &Success);
88 }
89 
90 /* EOF */
91