mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
[FMIFS] Improve FormatEx and Chkdsk
- Remove the hack for missing IOCTL_MOUNTDEV_QUERY_DEVICE_NAME - Handle DriveRoot without a trailing backslash
This commit is contained in:
parent
1d18b12ff7
commit
5c5cd20b9d
2 changed files with 54 additions and 36 deletions
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
#include <ntstrsafe.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
@ -30,31 +31,38 @@ Chkdsk(
|
|||
UNICODE_STRING usDriveRoot;
|
||||
NTSTATUS Status;
|
||||
BOOLEAN Success = FALSE;
|
||||
WCHAR DriveName[MAX_PATH];
|
||||
WCHAR VolumeName[MAX_PATH];
|
||||
//CURDIR CurDir;
|
||||
|
||||
Provider = GetProvider(Format);
|
||||
if (!Provider)
|
||||
{
|
||||
/* Unknown file system */
|
||||
Callback(DONE, 0, &Success);
|
||||
return;
|
||||
goto Quit;
|
||||
}
|
||||
|
||||
#if 1
|
||||
DPRINT1("Warning: use GetVolumeNameForVolumeMountPointW() instead!\n");
|
||||
swprintf(VolumeName, L"\\??\\%c:", towupper(DriveRoot[0]));
|
||||
RtlCreateUnicodeString(&usDriveRoot, VolumeName);
|
||||
/* Code disabled as long as our storage stack doesn't understand IOCTL_MOUNTDEV_QUERY_DEVICE_NAME */
|
||||
#else
|
||||
if (!GetVolumeNameForVolumeMountPointW(DriveRoot, VolumeName, RTL_NUMBER_OF(VolumeName)) ||
|
||||
!RtlDosPathNameToNtPathName_U(VolumeName, &usDriveRoot, NULL, &CurDir))
|
||||
if (!NT_SUCCESS(RtlStringCchCopyW(DriveName, ARRAYSIZE(DriveName), DriveRoot)))
|
||||
goto Quit;
|
||||
|
||||
if (DriveName[wcslen(DriveName) - 1] != L'\\')
|
||||
{
|
||||
/* Report an error */
|
||||
Callback(DONE, 0, &Success);
|
||||
return;
|
||||
/* Append the trailing backslash for GetVolumeNameForVolumeMountPointW */
|
||||
if (!NT_SUCCESS(RtlStringCchCatW(DriveName, ARRAYSIZE(DriveName), L"\\")))
|
||||
goto Quit;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!GetVolumeNameForVolumeMountPointW(DriveName, VolumeName, ARRAYSIZE(VolumeName)))
|
||||
{
|
||||
/* Couldn't get a volume GUID path, try checking using a parameter provided path */
|
||||
DPRINT1("Couldn't get a volume GUID path for drive %S\n", DriveName);
|
||||
wcscpy(VolumeName, DriveName);
|
||||
}
|
||||
|
||||
if (!RtlDosPathNameToNtPathName_U(VolumeName, &usDriveRoot, NULL, NULL))
|
||||
goto Quit;
|
||||
|
||||
/* Trim the trailing backslash since we will work with a device object */
|
||||
usDriveRoot.Length -= sizeof(WCHAR);
|
||||
|
||||
DPRINT("Chkdsk() - %S\n", Format);
|
||||
Status = STATUS_SUCCESS;
|
||||
|
@ -72,10 +80,11 @@ Chkdsk(
|
|||
if (!Success)
|
||||
DPRINT1("Chkdsk() failed with Status 0x%lx\n", Status);
|
||||
|
||||
/* Report success */
|
||||
Callback(DONE, 0, &Success);
|
||||
|
||||
RtlFreeUnicodeString(&usDriveRoot);
|
||||
|
||||
Quit:
|
||||
/* Report result */
|
||||
Callback(DONE, 0, &Success);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
#include <ntstrsafe.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
@ -50,8 +51,8 @@ FormatEx(
|
|||
BOOLEAN Success = FALSE;
|
||||
BOOLEAN BackwardCompatible = FALSE; // Default to latest FS versions.
|
||||
MEDIA_TYPE MediaType;
|
||||
WCHAR DriveName[MAX_PATH];
|
||||
WCHAR VolumeName[MAX_PATH];
|
||||
//CURDIR CurDir;
|
||||
|
||||
//
|
||||
// TODO: Convert filesystem Format into ULIB format string.
|
||||
|
@ -61,24 +62,31 @@ FormatEx(
|
|||
if (!Provider)
|
||||
{
|
||||
/* Unknown file system */
|
||||
Callback(DONE, 0, &Success);
|
||||
return;
|
||||
goto Quit;
|
||||
}
|
||||
|
||||
#if 1
|
||||
DPRINT1("Warning: use GetVolumeNameForVolumeMountPointW() instead!\n");
|
||||
swprintf(VolumeName, L"\\??\\%c:", towupper(DriveRoot[0]));
|
||||
RtlCreateUnicodeString(&usDriveRoot, VolumeName);
|
||||
/* Code disabled as long as our storage stack doesn't understand IOCTL_MOUNTDEV_QUERY_DEVICE_NAME */
|
||||
#else
|
||||
if (!GetVolumeNameForVolumeMountPointW(DriveRoot, VolumeName, RTL_NUMBER_OF(VolumeName)) ||
|
||||
!RtlDosPathNameToNtPathName_U(VolumeName, &usDriveRoot, NULL, &CurDir))
|
||||
if (!NT_SUCCESS(RtlStringCchCopyW(DriveName, ARRAYSIZE(DriveName), DriveRoot)))
|
||||
goto Quit;
|
||||
|
||||
if (DriveName[wcslen(DriveName) - 1] != L'\\')
|
||||
{
|
||||
/* Report an error */
|
||||
Callback(DONE, 0, &Success);
|
||||
return;
|
||||
/* Append the trailing backslash for GetVolumeNameForVolumeMountPointW */
|
||||
if (!NT_SUCCESS(RtlStringCchCatW(DriveName, ARRAYSIZE(DriveName), L"\\")))
|
||||
goto Quit;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!GetVolumeNameForVolumeMountPointW(DriveName, VolumeName, ARRAYSIZE(VolumeName)))
|
||||
{
|
||||
/* Couldn't get a volume GUID path, try formatting using a parameter provided path */
|
||||
DPRINT1("Couldn't get a volume GUID path for drive %S\n", DriveName);
|
||||
wcscpy(VolumeName, DriveName);
|
||||
}
|
||||
|
||||
if (!RtlDosPathNameToNtPathName_U(VolumeName, &usDriveRoot, NULL, NULL))
|
||||
goto Quit;
|
||||
|
||||
/* Trim the trailing backslash since we will work with a device object */
|
||||
usDriveRoot.Length -= sizeof(WCHAR);
|
||||
|
||||
RtlInitUnicodeString(&usLabel, Label);
|
||||
|
||||
|
@ -119,10 +127,11 @@ FormatEx(
|
|||
if (!Success)
|
||||
DPRINT1("Format() failed\n");
|
||||
|
||||
/* Report success */
|
||||
Callback(DONE, 0, &Success);
|
||||
|
||||
RtlFreeUnicodeString(&usDriveRoot);
|
||||
|
||||
Quit:
|
||||
/* Report result */
|
||||
Callback(DONE, 0, &Success);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
Loading…
Reference in a new issue