mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-03 04:13:31 +00:00
[FSUTIL]
Add a helper for opening a volume. Make it check for local devices if needed svn path=/trunk/; revision=75773
This commit is contained in:
@@ -46,6 +46,39 @@ int FindHandler(int argc,
|
||||
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,
|
||||
|
||||
@@ -23,7 +23,6 @@ static int
|
||||
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 @@ QueryMain(int argc, const TCHAR *argv[])
|
||||
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 @@ SetMain(int argc, const TCHAR *argv[])
|
||||
{
|
||||
HANDLE Volume;
|
||||
DWORD BytesRead;
|
||||
TCHAR VolumeID[PATH_MAX];
|
||||
|
||||
/* We need a volume (letter or GUID) */
|
||||
if (argc < 2)
|
||||
@@ -78,15 +71,10 @@ SetMain(int argc, const TCHAR *argv[])
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ int FindHandler(int argc,
|
||||
int HandlerListCount,
|
||||
void (*UsageHelper)(const TCHAR *));
|
||||
|
||||
HANDLE OpenVolume(const TCHAR * Volume,
|
||||
BOOLEAN AllowRemote);
|
||||
|
||||
void PrintDefaultUsage(const TCHAR * Command,
|
||||
const TCHAR * SubCommand,
|
||||
HandlerItem * HandlersList,
|
||||
|
||||
Reference in New Issue
Block a user