Author: pschweitzer
Date: Wed Sep 6 17:11:03 2017
New Revision: 75778
URL:
http://svn.reactos.org/svn/reactos?rev=75778&view=rev
Log:
[FSUTIL]
Print nicer error messages
Modified:
trunk/reactos/base/applications/cmdutils/fsutil/common.c
trunk/reactos/base/applications/cmdutils/fsutil/dirty.c
trunk/reactos/base/applications/cmdutils/fsutil/fsinfo.c
trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h
Modified: trunk/reactos/base/applications/cmdutils/fsutil/common.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/common.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/common.c [iso-8859-1] Wed Sep 6
17:11:03 2017
@@ -72,7 +72,7 @@
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 @@
_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;
+}
Modified: trunk/reactos/base/applications/cmdutils/fsutil/dirty.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/dirty.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/dirty.c [iso-8859-1] Wed Sep 6
17:11:03 2017
@@ -44,7 +44,7 @@
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 @@
/* 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;
}
Modified: trunk/reactos/base/applications/cmdutils/fsutil/fsinfo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/fsinfo.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/fsinfo.c [iso-8859-1] Wed Sep 6
17:11:03 2017
@@ -30,7 +30,7 @@
Drives = GetLogicalDrives();
if (Drives == 0)
{
- _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
+ PrintErrorMessage(GetLastError());
return 1;
}
@@ -119,7 +119,7 @@
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;
}
Modified: trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h [iso-8859-1] Wed Sep 6
17:11:03 2017
@@ -26,4 +26,6 @@
HandlerItem * HandlersList,
int HandlerListCount);
+int PrintErrorMessage(DWORD Error);
+
#endif