[ros-diffs] [fireball] 22370: Add code to query volume for its filesystem type

fireball at svn.reactos.org fireball at svn.reactos.org
Thu Jun 15 17:00:38 CEST 2006


Author: fireball
Date: Thu Jun 15 19:00:37 2006
New Revision: 22370

URL: http://svn.reactos.ru/svn/reactos?rev=22370&view=rev
Log:
Add code to query volume for its filesystem type

Modified:
    trunk/reactos/base/system/autochk/autochk.c

Modified: trunk/reactos/base/system/autochk/autochk.c
URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/system/autochk/autochk.c?rev=22370&r1=22369&r2=22370&view=diff
==============================================================================
--- trunk/reactos/base/system/autochk/autochk.c (original)
+++ trunk/reactos/base/system/autochk/autochk.c Thu Jun 15 19:00:37 2006
@@ -3,16 +3,25 @@
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            base/system/autochk/autochk.c
  * PURPOSE:         Filesystem checker
- * PROGRAMMERS:     Eric Kohl
+ * PROGRAMMERS:     Aleksey Bragin
+ *                  Eric Kohl
  */
 
 /* INCLUDES *****************************************************************/
+
+//#define NDEBUG
+#include <debug.h>
 
 #include <stdio.h>
 #define WIN32_NO_STATUS
 #include <windows.h>
 #define NTOS_MODE_USER
 #include <ndk/ntndk.h>
+
+/* DEFINES ******************************************************************/
+
+#define FS_ATTRIBUTE_BUFFER_SIZE (MAX_PATH * sizeof(WCHAR) + sizeof(FILE_FS_ATTRIBUTE_INFORMATION))
+
 
 /* FUNCTIONS ****************************************************************/
 
@@ -45,6 +54,97 @@
     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 */
 int
@@ -57,8 +157,17 @@
     PROCESS_DEVICEMAP_INFORMATION DeviceMap;
     ULONG i;
     NTSTATUS Status;
-
-    PrintString("Autochk 0.0.1\n");
+    WCHAR FileSystem[128];
+    WCHAR DrivePath[128];
+
+    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(),
                                        ProcessDeviceMap,
@@ -73,13 +182,34 @@
             if ((DeviceMap.Query.DriveMap & (1 << i)) &&
                 (DeviceMap.Query.DriveType[i] == DOSDEVICE_DRIVE_FIXED))
             {
-                PrintString("  Checking drive %c:", 'A'+i);
-                PrintString("      OK\n");
+                swprintf(DrivePath, L"%c:\\", 'A'+i);
+                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");
         return 0;
     }
+    else
+    {
+        DPRINT1("NtQueryInformationProcess() failed with status=0x%08X\n",
+            Status);
+    }
 
     return 1;
 }




More information about the Ros-diffs mailing list