Author: pschweitzer
Date: Wed Sep 6 12:41:52 2017
New Revision: 75773
URL:
http://svn.reactos.org/svn/reactos?rev=75773&view=rev
Log:
[FSUTIL]
Add a helper for opening a volume. Make it check for local devices if needed
Modified:
trunk/reactos/base/applications/cmdutils/fsutil/common.c
trunk/reactos/base/applications/cmdutils/fsutil/dirty.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
12:41:52 2017
@@ -46,6 +46,39 @@
return ret;
}
+HANDLE OpenVolume(const TCHAR * Volume,
+ BOOLEAN AllowRemote)
+{
+ UINT Type;
+ HANDLE hVolume;
+ TCHAR VolumeID[PATH_MAX];
+
+ /* Create full name */
+ _stprintf(VolumeID, _T("\\\\.\\%s"), Volume);
+
+ /* Get volume type */
+ if (!AllowRemote && Volume[1] == L':')
+ {
+ Type = GetDriveType(Volume);
+ if (Type == DRIVE_REMOTE)
+ {
+ _ftprintf(stderr, _T("FSUTIL needs a local device\n"));
+ return INVALID_HANDLE_VALUE;
+ }
+ }
+
+ /* Open the volume */
+ hVolume = CreateFile(VolumeID, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (hVolume == INVALID_HANDLE_VALUE)
+ {
+ _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
+ return INVALID_HANDLE_VALUE;
+ }
+
+ return hVolume;
+}
+
void PrintDefaultUsage(const TCHAR * Command,
const TCHAR * SubCommand,
HandlerItem * HandlersList,
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
12:41:52 2017
@@ -23,7 +23,6 @@
QueryMain(int argc, const TCHAR *argv[])
{
HANDLE Volume;
- TCHAR VolumeID[PATH_MAX];
ULONG VolumeStatus, BytesRead;
/* We need a volume (letter or GUID) */
@@ -34,15 +33,10 @@
return 1;
}
- /* Create full name */
- _stprintf(VolumeID, _T("\\\\.\\%s"), argv[1]);
-
- /* Open the volume */
- Volume = CreateFile(VolumeID, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ /* Get a handle for the volume */
+ Volume = OpenVolume(argv[1], FALSE);
if (Volume == INVALID_HANDLE_VALUE)
{
- _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
return 1;
}
@@ -68,7 +62,6 @@
{
HANDLE Volume;
DWORD BytesRead;
- TCHAR VolumeID[PATH_MAX];
/* We need a volume (letter or GUID) */
if (argc < 2)
@@ -78,15 +71,10 @@
return 1;
}
- /* Create full name */
- _stprintf(VolumeID, _T("\\\\.\\%s"), argv[1]);
-
- /* Open the volume */
- Volume = CreateFile(VolumeID, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ /* Get a handle for the volume */
+ Volume = OpenVolume(argv[1], FALSE);
if (Volume == INVALID_HANDLE_VALUE)
{
- _ftprintf(stderr, _T("Error: %d\n"), 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
12:41:52 2017
@@ -18,6 +18,9 @@
int HandlerListCount,
void (*UsageHelper)(const TCHAR *));
+HANDLE OpenVolume(const TCHAR * Volume,
+ BOOLEAN AllowRemote);
+
void PrintDefaultUsage(const TCHAR * Command,
const TCHAR * SubCommand,
HandlerItem * HandlersList,