[FSUTIL]
authorPierre Schweitzer <pierre@reactos.org>
Wed, 6 Sep 2017 15:32:02 +0000 (15:32 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Wed, 6 Sep 2017 15:32:02 +0000 (15:32 +0000)
Implement fsutil fsinfo drives and fsutil fsinfo drivetype

svn path=/trunk/; revision=75774

reactos/base/applications/cmdutils/fsutil/CMakeLists.txt
reactos/base/applications/cmdutils/fsutil/fsinfo.c [new file with mode: 0644]
reactos/base/applications/cmdutils/fsutil/fsutil.c

index d47224b..9aef3a0 100644 (file)
@@ -1,6 +1,7 @@
 list(APPEND SOURCE
     common.c
     dirty.c
 list(APPEND SOURCE
     common.c
     dirty.c
+    fsinfo.c
     fsutil.c
     fsutil.h)
 add_executable(fsutil ${SOURCE} fsutil.rc)
     fsutil.c
     fsutil.h)
 add_executable(fsutil ${SOURCE} fsutil.rc)
diff --git a/reactos/base/applications/cmdutils/fsutil/fsinfo.c b/reactos/base/applications/cmdutils/fsutil/fsinfo.c
new file mode 100644 (file)
index 0000000..e53885c
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS FS utility tool
+ * FILE:            base/applications/cmdutils/fsinfo.c
+ * PURPOSE:         FSutil file systems information
+ * PROGRAMMERS:     Pierre Schweitzer <pierre@reactos.org>
+ */
+
+/* Add handlers here for subcommands */
+static int DrivesMain(int argc, const TCHAR *argv[]);
+static int DriveTypeMain(int argc, const TCHAR *argv[]);
+static HandlerItem HandlersList[] =
+{
+    /* Proc, name, help */
+    { DrivesMain, _T("drives"), _T("Enumerates the drives") },
+    { DriveTypeMain, _T("drivetype"), _T("Provides the type of a drive") },
+};
+
+static int
+DrivesMain(int argc, const TCHAR *argv[])
+{
+    UINT i;
+    DWORD Drives;
+
+    /* Get the drives bitmap */
+    Drives = GetLogicalDrives();
+    if (Drives == 0)
+    {
+        _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
+        return 1;
+    }
+
+    /* And output any found drive */
+    _ftprintf(stdout, _T("Drives:"));
+    for (i = 0; i < 26; i++)
+    {
+        if (Drives & (1 << i))
+        {
+            _ftprintf(stdout, _T(" %c:\\"), 'A' + i);
+        }
+    }
+    _ftprintf(stdout, _T("\n"));
+
+    return 0;
+}
+
+static int
+DriveTypeMain(int argc, const TCHAR *argv[])
+{
+    UINT Type;
+
+    /* We need a volume (letter) */
+    if (argc < 2)
+    {
+        _ftprintf(stderr, _T("Usage: fsutil fsinfo drivetype <volume>\n"));
+        _ftprintf(stderr, _T("\tFor example: fsutil fsinfo drivetype c:\n"));
+        return 1;
+    }
+
+    /* Get its drive type and make it readable */
+    Type = GetDriveType(argv[1]);
+    switch (Type)
+    {
+        case DRIVE_UNKNOWN:
+            _ftprintf(stdout, _T("%s - unknown drive type\n"), argv[1]);
+            break;
+
+        case DRIVE_NO_ROOT_DIR:
+            _ftprintf(stdout, _T("%s - not a root directory\n"), argv[1]);
+            break;
+
+        case DRIVE_REMOVABLE:
+            _ftprintf(stdout, _T("%s - removable drive\n"), argv[1]);
+            break;
+
+        case DRIVE_FIXED:
+            _ftprintf(stdout, _T("%s - fixed drive\n"), argv[1]);
+            break;
+
+        case DRIVE_REMOTE:
+            _ftprintf(stdout, _T("%s - remote or network drive\n"), argv[1]);
+            break;
+
+        case DRIVE_CDROM:
+            _ftprintf(stdout, _T("%s - CD-ROM drive\n"), argv[1]);
+            break;
+
+        case DRIVE_RAMDISK:
+            _ftprintf(stdout, _T("%s - RAM disk drive\n"), argv[1]);
+            break;
+    }
+
+    return 0;
+}
+
+static void
+PrintUsage(const TCHAR * Command)
+{
+    PrintDefaultUsage(_T(" FSINFO "), Command, (HandlerItem *)&HandlersList,
+                      (sizeof(HandlersList) / sizeof(HandlersList[0])));
+}
+
+int
+FsInfoMain(int argc, const TCHAR *argv[])
+{
+    return FindHandler(argc, argv, (HandlerItem *)&HandlersList,
+                       (sizeof(HandlersList) / sizeof(HandlersList[0])),
+                       PrintUsage);
+}
index e1fa664..1693d92 100644 (file)
 
 /* Add handlers here for commands */
 int DirtyMain(int argc, const TCHAR *argv[]);
 
 /* Add handlers here for commands */
 int DirtyMain(int argc, const TCHAR *argv[]);
+int FsInfoMain(int argc, const TCHAR *argv[]);
 static HandlerItem HandlersList[] =
 {
     /* Proc, name, help */
     { DirtyMain, _T("dirty"), _T("Manipulates the dirty bit") },
 static HandlerItem HandlersList[] =
 {
     /* Proc, name, help */
     { DirtyMain, _T("dirty"), _T("Manipulates the dirty bit") },
+    { FsInfoMain, _T("fsinfo"), _T("Gathers informations about file systems") },
 };
 
 static void
 };
 
 static void