Author: pschweitzer
Date: Mon Sep 25 18:59:54 2017
New Revision: 75966
URL:
http://svn.reactos.org/svn/reactos?rev=75966&view=rev
Log:
[FSUTIL]
- Modify OpenVolume so that it can restrict volume opening to a NTFS volume (broken on
ROS...)
- Implement fsutil fsinfo ntfsinfo
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
trunk/reactos/base/applications/cmdutils/fsutil/volume.c
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] Mon Sep 25
18:59:54 2017
@@ -47,14 +47,12 @@
}
HANDLE OpenVolume(const TCHAR * Volume,
- BOOLEAN AllowRemote)
+ BOOLEAN AllowRemote,
+ BOOLEAN NtfsOnly)
{
UINT Type;
HANDLE hVolume;
TCHAR VolumeID[PATH_MAX];
-
- /* Create full name */
- _stprintf(VolumeID, _T("\\\\.\\%s"), Volume);
/* Get volume type */
if (!AllowRemote && Volume[1] == L':')
@@ -66,6 +64,28 @@
return INVALID_HANDLE_VALUE;
}
}
+
+ /* Get filesystem type */
+ if (NtfsOnly)
+ {
+ TCHAR FileSystem[MAX_PATH + 1];
+
+ _stprintf(VolumeID, _T("\\\\.\\%s\\"), Volume);
+ if (!GetVolumeInformation(VolumeID, NULL, 0, NULL, NULL, NULL, FileSystem,
MAX_PATH + 1))
+ {
+ PrintErrorMessage(GetLastError());
+ return INVALID_HANDLE_VALUE;
+ }
+
+ if (_tcscmp(FileSystem, _T("NTFS")) != 0)
+ {
+ _ftprintf(stderr, _T("FSUTIL needs a NTFS device\n"));
+ return INVALID_HANDLE_VALUE;
+ }
+ }
+
+ /* Create full name */
+ _stprintf(VolumeID, _T("\\\\.\\%s"), Volume);
/* Open the volume */
hVolume = CreateFile(VolumeID, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
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] Mon Sep 25
18:59:54 2017
@@ -34,7 +34,7 @@
}
/* Get a handle for the volume */
- Volume = OpenVolume(argv[1], FALSE);
+ Volume = OpenVolume(argv[1], FALSE, FALSE);
if (Volume == INVALID_HANDLE_VALUE)
{
return 1;
@@ -72,7 +72,7 @@
}
/* Get a handle for the volume */
- Volume = OpenVolume(argv[1], FALSE);
+ Volume = OpenVolume(argv[1], FALSE, FALSE);
if (Volume == INVALID_HANDLE_VALUE)
{
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] Mon Sep 25
18:59:54 2017
@@ -12,6 +12,7 @@
static HandlerProc DrivesMain;
static HandlerProc DriveTypeMain;
static HandlerProc VolumeInfoMain;
+static HandlerProc NtfsInfoMain;
static HandlerProc StatisticsMain;
static HandlerItem HandlersList[] =
{
@@ -19,6 +20,7 @@
{ DrivesMain, _T("drives"), _T("Enumerates the drives") },
{ DriveTypeMain, _T("drivetype"), _T("Provides the type of a
drive") },
{ VolumeInfoMain, _T("volumeinfo"), _T("Provides informations about a
volume") },
+ { NtfsInfoMain, _T("ntfsinfo"), _T("Displays informations about a NTFS
volume") },
{ StatisticsMain, _T("statistics"), _T("Displays volume
statistics") },
};
@@ -154,6 +156,68 @@
HANDLE_FLAG(Flags, FILE_DAX_VOLUME, _T("Is a direct access volume\n"));
#undef HANDLE_FLAGS
+
+ return 0;
+}
+
+static int
+NtfsInfoMain(int argc, const TCHAR *argv[])
+{
+ HANDLE Volume;
+ DWORD BytesRead;
+ struct
+ {
+ NTFS_VOLUME_DATA_BUFFER;
+ NTFS_EXTENDED_VOLUME_DATA;
+ } Data;
+
+ /* We need a volume (letter or GUID) */
+ if (argc < 2)
+ {
+ _ftprintf(stderr, _T("Usage: fsutil fsinfo ntfsinfo
<volume>\n"));
+ _ftprintf(stderr, _T("\tFor example: fsutil fsinfo ntfsinfo c:\n"));
+ return 1;
+ }
+
+ /* Get a handle for the volume */
+ Volume = OpenVolume(argv[1], FALSE, TRUE);
+ if (Volume == INVALID_HANDLE_VALUE)
+ {
+ return 1;
+ }
+
+ /* And query the NTFS data */
+ if (DeviceIoControl(Volume, FSCTL_GET_NTFS_VOLUME_DATA, NULL, 0, &Data,
+ sizeof(Data), &BytesRead, NULL) == FALSE)
+ {
+ PrintErrorMessage(GetLastError());
+ CloseHandle(Volume);
+ return 1;
+ }
+
+ /* We no longer need the volume */
+ CloseHandle(Volume);
+
+ /* Dump data */
+ _ftprintf(stdout, _T("NTFS volume serial number:\t\t0x%0.16I64x\n"),
Data.VolumeSerialNumber.QuadPart);
+ /* Only print version if extended structure was returned */
+ if (BytesRead > sizeof(NTFS_VOLUME_DATA_BUFFER))
+ {
+ _ftprintf(stdout, _T("Version:\t\t\t\t%u.%u\n"), Data.MajorVersion,
Data.MinorVersion);
+ }
+ _ftprintf(stdout, _T("Number of sectors:\t\t\t0x%0.16I64x\n"),
Data.NumberSectors.QuadPart);
+ _ftprintf(stdout, _T("Total number of clusters:\t\t0x%0.16I64x\n"),
Data.TotalClusters.QuadPart);
+ _ftprintf(stdout, _T("Free clusters:\t\t\t\t0x%0.16I64x\n"),
Data.FreeClusters.QuadPart);
+ _ftprintf(stdout, _T("Total number of reserved clusters:\t0x%0.16I64x\n"),
Data.TotalReserved.QuadPart);
+ _ftprintf(stdout, _T("Bytes per sector:\t\t\t%d\n"), Data.BytesPerSector);
+ _ftprintf(stdout, _T("Bytes per cluster:\t\t\t%d\n"),
Data.BytesPerCluster);
+ _ftprintf(stdout, _T("Bytes per file record segment:\t\t%d\n"),
Data.BytesPerFileRecordSegment);
+ _ftprintf(stdout, _T("Clusters per file record segment:\t%d\n"),
Data.ClustersPerFileRecordSegment);
+ _ftprintf(stdout, _T("MFT valid data length:\t\t\t0x%0.16I64x\n"),
Data.MftValidDataLength.QuadPart);
+ _ftprintf(stdout, _T("MFT start LCN:\t\t\t\t0x%0.16I64x\n"),
Data.MftStartLcn.QuadPart);
+ _ftprintf(stdout, _T("MFT2 start LCN:\t\t\t\t0x%0.16I64x\n"),
Data.Mft2StartLcn.QuadPart);
+ _ftprintf(stdout, _T("MFT zone start:\t\t\t\t0x%0.16I64x\n"),
Data.MftZoneStart.QuadPart);
+ _ftprintf(stdout, _T("MFT zone end:\t\t\t\t0x%0.16I64x\n"),
Data.MftZoneEnd.QuadPart);
return 0;
}
@@ -477,7 +541,7 @@
}
/* Get a handle for the volume */
- Volume = OpenVolume(argv[1], FALSE);
+ Volume = OpenVolume(argv[1], FALSE, FALSE);
if (Volume == INVALID_HANDLE_VALUE)
{
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] Mon Sep 25
18:59:54 2017
@@ -22,7 +22,8 @@
void (*UsageHelper)(const TCHAR *));
HANDLE OpenVolume(const TCHAR * Volume,
- BOOLEAN AllowRemote);
+ BOOLEAN AllowRemote,
+ BOOLEAN NtfsOnly);
void PrintDefaultUsage(const TCHAR * Command,
const TCHAR * SubCommand,
Modified: trunk/reactos/base/applications/cmdutils/fsutil/volume.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/volume.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/fsutil/volume.c [iso-8859-1] Mon Sep 25
18:59:54 2017
@@ -50,7 +50,7 @@
}
/* Get a handle for the volume */
- Volume = OpenVolume(argv[1], FALSE);
+ Volume = OpenVolume(argv[1], FALSE, FALSE);
if (Volume == INVALID_HANDLE_VALUE)
{
return 1;