diff --git a/reactos/base/applications/cmdutils/fsutil/common.c b/reactos/base/applications/cmdutils/fsutil/common.c index c89cd821ada..26120d86d34 100644 --- a/reactos/base/applications/cmdutils/fsutil/common.c +++ b/reactos/base/applications/cmdutils/fsutil/common.c @@ -72,7 +72,7 @@ HANDLE OpenVolume(const TCHAR * Volume, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hVolume == INVALID_HANDLE_VALUE) { - _ftprintf(stderr, _T("Error: %d\n"), GetLastError()); + PrintErrorMessage(GetLastError()); return INVALID_HANDLE_VALUE; } @@ -99,3 +99,24 @@ void PrintDefaultUsage(const TCHAR * Command, _ftprintf(stderr, _T("%s\t%s\n"), HandlersList[i].Command, HandlersList[i].Desc); } } + +int PrintErrorMessage(DWORD Error) +{ + TCHAR * String; + + /* Try to get textual error */ + if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, Error, 0, (TCHAR *)&String, 0, NULL) != 0) + { + /* And print it */ + _ftprintf(stderr, _T("Error: %s\n"), String); + LocalFree(String); + } + else + { + /* Otherwise, just print the error number */ + _ftprintf(stderr, _T("Error: %d\n"), Error); + } + + return Error; +} diff --git a/reactos/base/applications/cmdutils/fsutil/dirty.c b/reactos/base/applications/cmdutils/fsutil/dirty.c index 9eff0903714..37f71644095 100644 --- a/reactos/base/applications/cmdutils/fsutil/dirty.c +++ b/reactos/base/applications/cmdutils/fsutil/dirty.c @@ -44,7 +44,7 @@ QueryMain(int argc, const TCHAR *argv[]) if (DeviceIoControl(Volume, FSCTL_IS_VOLUME_DIRTY, NULL, 0, &VolumeStatus, sizeof(ULONG), &BytesRead, NULL) == FALSE) { - _ftprintf(stderr, _T("Error: %d\n"), GetLastError()); + PrintErrorMessage(GetLastError()); CloseHandle(Volume); return 1; } @@ -81,7 +81,7 @@ SetMain(int argc, const TCHAR *argv[]) /* And set the dirty bit */ if (DeviceIoControl(Volume, FSCTL_MARK_VOLUME_DIRTY, NULL, 0, NULL, 0, &BytesRead, NULL) == FALSE) { - _ftprintf(stderr, _T("Error: %d\n"), GetLastError()); + PrintErrorMessage(GetLastError()); CloseHandle(Volume); return 1; } diff --git a/reactos/base/applications/cmdutils/fsutil/fsinfo.c b/reactos/base/applications/cmdutils/fsutil/fsinfo.c index 1e58b6f65e9..f7ef8e4ccf5 100644 --- a/reactos/base/applications/cmdutils/fsutil/fsinfo.c +++ b/reactos/base/applications/cmdutils/fsutil/fsinfo.c @@ -30,7 +30,7 @@ DrivesMain(int argc, const TCHAR *argv[]) Drives = GetLogicalDrives(); if (Drives == 0) { - _ftprintf(stderr, _T("Error: %d\n"), GetLastError()); + PrintErrorMessage(GetLastError()); return 1; } @@ -119,7 +119,7 @@ VolumeInfoMain(int argc, const TCHAR *argv[]) if (!GetVolumeInformation(argv[1], VolumeName, MAX_PATH + 1, &Serial, &MaxComponentLen, &Flags, FileSystem, MAX_PATH + 1)) { - _ftprintf(stderr, _T("Error: %d\n"), GetLastError()); + PrintErrorMessage(GetLastError()); return 1; } diff --git a/reactos/base/applications/cmdutils/fsutil/fsutil.h b/reactos/base/applications/cmdutils/fsutil/fsutil.h index 7c112a85413..0971f1e216f 100644 --- a/reactos/base/applications/cmdutils/fsutil/fsutil.h +++ b/reactos/base/applications/cmdutils/fsutil/fsutil.h @@ -26,4 +26,6 @@ void PrintDefaultUsage(const TCHAR * Command, HandlerItem * HandlersList, int HandlerListCount); +int PrintErrorMessage(DWORD Error); + #endif