mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 12:26:09 +00:00
Add code to query volume for its filesystem type
svn path=/trunk/; revision=22370
This commit is contained in:
parent
69d2fdc763
commit
9bf8d5dcc2
1 changed files with 134 additions and 4 deletions
|
@ -3,17 +3,26 @@
|
||||||
* LICENSE: GPL - See COPYING in the top level directory
|
* LICENSE: GPL - See COPYING in the top level directory
|
||||||
* FILE: base/system/autochk/autochk.c
|
* FILE: base/system/autochk/autochk.c
|
||||||
* PURPOSE: Filesystem checker
|
* PURPOSE: Filesystem checker
|
||||||
* PROGRAMMERS: Eric Kohl
|
* PROGRAMMERS: Aleksey Bragin
|
||||||
|
* Eric Kohl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDES *****************************************************************/
|
/* INCLUDES *****************************************************************/
|
||||||
|
|
||||||
|
//#define NDEBUG
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define WIN32_NO_STATUS
|
#define WIN32_NO_STATUS
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#define NTOS_MODE_USER
|
#define NTOS_MODE_USER
|
||||||
#include <ndk/ntndk.h>
|
#include <ndk/ntndk.h>
|
||||||
|
|
||||||
|
/* DEFINES ******************************************************************/
|
||||||
|
|
||||||
|
#define FS_ATTRIBUTE_BUFFER_SIZE (MAX_PATH * sizeof(WCHAR) + sizeof(FILE_FS_ATTRIBUTE_INFORMATION))
|
||||||
|
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -45,6 +54,97 @@ PrintString(char* fmt,...)
|
||||||
RtlFreeUnicodeString(&UnicodeString);
|
RtlFreeUnicodeString(&UnicodeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this func is taken from kernel32/file/volume.c
|
||||||
|
HANDLE
|
||||||
|
OpenDirectory(LPCWSTR DirName,
|
||||||
|
BOOLEAN Write)
|
||||||
|
{
|
||||||
|
UNICODE_STRING NtPathU;
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
NTSTATUS Status;
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
|
HANDLE hFile;
|
||||||
|
|
||||||
|
if (!RtlDosPathNameToNtPathName_U(DirName,
|
||||||
|
&NtPathU,
|
||||||
|
NULL,
|
||||||
|
NULL))
|
||||||
|
{
|
||||||
|
DPRINT1("Invalid path!\n");
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
InitializeObjectAttributes(
|
||||||
|
&ObjectAttributes,
|
||||||
|
&NtPathU,
|
||||||
|
Write ? FILE_WRITE_ATTRIBUTES : FILE_READ_ATTRIBUTES,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
Status = NtCreateFile(
|
||||||
|
&hFile,
|
||||||
|
Write ? FILE_GENERIC_WRITE : FILE_GENERIC_READ,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
FILE_SHARE_READ|FILE_SHARE_WRITE,
|
||||||
|
FILE_OPEN,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
0);
|
||||||
|
|
||||||
|
RtlFreeHeap(RtlGetProcessHeap(), 0, NtPathU.Buffer);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
GetFileSystem(LPCWSTR Drive,
|
||||||
|
LPWSTR FileSystemName,
|
||||||
|
ULONG FileSystemNameSize)
|
||||||
|
{
|
||||||
|
HANDLE FileHandle;
|
||||||
|
NTSTATUS Status;
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
|
PFILE_FS_ATTRIBUTE_INFORMATION FileFsAttribute;
|
||||||
|
UCHAR Buffer[FS_ATTRIBUTE_BUFFER_SIZE];
|
||||||
|
|
||||||
|
FileFsAttribute = (PFILE_FS_ATTRIBUTE_INFORMATION)Buffer;
|
||||||
|
|
||||||
|
FileHandle = OpenDirectory(Drive, FALSE);
|
||||||
|
if (FileHandle == INVALID_HANDLE_VALUE)
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
|
Status = NtQueryVolumeInformationFile(FileHandle,
|
||||||
|
&IoStatusBlock,
|
||||||
|
FileFsAttribute,
|
||||||
|
FS_ATTRIBUTE_BUFFER_SIZE,
|
||||||
|
FileFsAttributeInformation);
|
||||||
|
NtClose(FileHandle);
|
||||||
|
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
if (FileSystemNameSize * sizeof(WCHAR) >= FileFsAttribute->FileSystemNameLength + sizeof(WCHAR))
|
||||||
|
{
|
||||||
|
memcpy(FileSystemName,
|
||||||
|
FileFsAttribute->FileSystemName,
|
||||||
|
FileFsAttribute->FileSystemNameLength);
|
||||||
|
FileSystemName[FileFsAttribute->FileSystemNameLength / sizeof(WCHAR)] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return STATUS_BUFFER_TOO_SMALL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return Status;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/* Native image's entry point */
|
/* Native image's entry point */
|
||||||
int
|
int
|
||||||
|
@ -57,8 +157,17 @@ _main(int argc,
|
||||||
PROCESS_DEVICEMAP_INFORMATION DeviceMap;
|
PROCESS_DEVICEMAP_INFORMATION DeviceMap;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
WCHAR FileSystem[128];
|
||||||
|
WCHAR DrivePath[128];
|
||||||
|
|
||||||
PrintString("Autochk 0.0.1\n");
|
PrintString("Autochk 0.0.2\n");
|
||||||
|
|
||||||
|
// Win2003 passes the only param - "*". Probably means to check all drives
|
||||||
|
/*
|
||||||
|
DPRINT("Got %d params\n", argc);
|
||||||
|
for (i=0; i<argc; i++)
|
||||||
|
DPRINT("Param %d: %s\n", i, argv[i]);
|
||||||
|
*/
|
||||||
|
|
||||||
Status = NtQueryInformationProcess(NtCurrentProcess(),
|
Status = NtQueryInformationProcess(NtCurrentProcess(),
|
||||||
ProcessDeviceMap,
|
ProcessDeviceMap,
|
||||||
|
@ -73,13 +182,34 @@ _main(int argc,
|
||||||
if ((DeviceMap.Query.DriveMap & (1 << i)) &&
|
if ((DeviceMap.Query.DriveMap & (1 << i)) &&
|
||||||
(DeviceMap.Query.DriveType[i] == DOSDEVICE_DRIVE_FIXED))
|
(DeviceMap.Query.DriveType[i] == DOSDEVICE_DRIVE_FIXED))
|
||||||
{
|
{
|
||||||
PrintString(" Checking drive %c:", 'A'+i);
|
swprintf(DrivePath, L"%c:\\", 'A'+i);
|
||||||
PrintString(" OK\n");
|
Status = GetFileSystem(DrivePath,
|
||||||
|
FileSystem,
|
||||||
|
sizeof(FileSystem));
|
||||||
|
PrintString(" Checking drive %c: \n", 'A'+i);
|
||||||
|
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
PrintString(" Filesystem type ");
|
||||||
|
DisplayString(FileSystem);
|
||||||
|
PrintString("\n");
|
||||||
|
PrintString(" OK\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DPRINT1("Error getting FS information, Status=0x%08X\n",
|
||||||
|
Status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PrintString("\n");
|
PrintString("\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DPRINT1("NtQueryInformationProcess() failed with status=0x%08X\n",
|
||||||
|
Status);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue