Author: pschweitzer
Date: Tue Sep 5 12:56:45 2017
New Revision: 75764
URL:
http://svn.reactos.org/svn/reactos?rev=75764&view=rev
Log:
[FSUTIL]
Add a skeleton for the fsutil tool.
As a proof of concept, implement fsutil dirty query.
More to follow ;-).
Added:
trunk/reactos/base/applications/cmdutils/fsutil/
trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt (with props)
trunk/reactos/base/applications/cmdutils/fsutil/dirty.c (with props)
trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c (with props)
trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h (with props)
trunk/reactos/base/applications/cmdutils/fsutil/fsutil.rc (with props)
Modified:
trunk/reactos/base/applications/cmdutils/CMakeLists.txt
Modified: trunk/reactos/base/applications/cmdutils/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/CMakeLists.txt [iso-8859-1] Tue Sep 5
12:56:45 2017
@@ -6,6 +6,7 @@
add_subdirectory(doskey)
add_subdirectory(eventcreate)
add_subdirectory(find)
+add_subdirectory(fsutil)
add_subdirectory(help)
add_subdirectory(hostname)
add_subdirectory(lodctr)
Added: trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt (added)
+++ trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt [iso-8859-1] Tue Sep 5
12:56:45 2017
@@ -0,0 +1,9 @@
+list(APPEND SOURCE
+ dirty.c
+ fsutil.c
+ fsutil.h)
+add_executable(fsutil ${SOURCE} fsutil.rc)
+set_module_type(fsutil win32cui UNICODE)
+add_importlibs(fsutil msvcrt kernel32 ntdll)
+add_pch(fsutil fsutil.h SOURCE)
+add_cd_file(TARGET fsutil DESTINATION reactos/system32 FOR all)
Propchange: trunk/reactos/base/applications/cmdutils/fsutil/CMakeLists.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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 (added)
+++ trunk/reactos/base/applications/cmdutils/fsutil/dirty.c [iso-8859-1] Tue Sep 5
12:56:45 2017
@@ -0,0 +1,126 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS FS utility tool
+ * FILE: base/applications/cmdutils/dirty.c
+ * PURPOSE: FSutil dirty bit handling
+ * PROGRAMMERS: Pierre Schweitzer <pierre(a)reactos.org>
+ */
+
+#include "fsutil.h"
+#include <winioctl.h>
+
+/* Add handlers here for subcommands */
+static int QueryMain(int argc, const TCHAR *argv[]);
+static int SetMain(int argc, const TCHAR *argv[]);
+static HandlerItem HandlersList[] =
+{
+ /* Proc, name, help */
+ { QueryMain, _T("query"), _T("Show the dirty bit") },
+ { SetMain, _T("set"), _T("Set the dirty bit") },
+};
+
+static int
+QueryMain(int argc, const TCHAR *argv[])
+{
+ HANDLE Volume;
+ TCHAR VolumeID[PATH_MAX];
+ ULONG VolumeStatus, BytesRead;
+
+ /* We need a volume (letter or GUID) */
+ if (argc < 2)
+ {
+ _ftprintf(stderr, _T("Usage: fsutil dirty query <volume>\n"));
+ _ftprintf(stderr, _T("\tFor example: fsutil dirty query c:\n"));
+ 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);
+ if (Volume == INVALID_HANDLE_VALUE)
+ {
+ _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
+ return 1;
+ }
+
+ /* And query the dirty status */
+ if (DeviceIoControl(Volume, FSCTL_IS_VOLUME_DIRTY, NULL, 0, &VolumeStatus,
+ sizeof(ULONG), &BytesRead, NULL) == FALSE)
+ {
+ _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
+ CloseHandle(Volume);
+ return 1;
+ }
+
+ CloseHandle(Volume);
+
+ /* Print the status */
+ _ftprintf(stdout, _T("The %s volume is %s\n"), argv[1], (VolumeStatus &
VOLUME_IS_DIRTY ? _T("dirty") : _T("clean")));
+
+ return 1;
+}
+
+static int
+SetMain(int argc, const TCHAR *argv[])
+{
+ /* FIXME */
+ _ftprintf(stderr, _T("Not implemented\n"));
+ return 1;
+}
+
+static void
+PrintUsage(const TCHAR * Command)
+{
+ int i;
+
+ /* If we were given a command, print it's not supported */
+ if (Command != NULL)
+ {
+ _ftprintf(stderr, _T("Unhandled DIRTY command: %s\n"), Command);
+ }
+
+ /* And dump any available command */
+ _ftprintf(stderr, _T("---- Handled DIRTY commands ----\n\n"));
+ for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
+ {
+ _ftprintf(stderr, _T("%s\t%s\n"), HandlersList[i].Command,
HandlersList[i].Desc);
+ }
+}
+
+int
+DirtyMain(int argc, const TCHAR *argv[])
+{
+ int i;
+ int ret;
+ const TCHAR * Command;
+
+ ret = 1;
+ Command = NULL;
+ i = (sizeof(HandlersList) / sizeof(HandlersList[0]));
+
+ /* If we have a command, does it match a known one? */
+ if (argc > 1)
+ {
+ /* Browse all the known commands finding the right one */
+ Command = argv[1];
+ for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
+ {
+ if (_tcsicmp(Command, HandlersList[i].Command) == 0)
+ {
+ ret = HandlersList[i].Handler(argc - 1, &argv[1]);
+ break;
+ }
+ }
+ }
+
+ /* We failed finding someone to handle the caller's needs, print out */
+ if (i == (sizeof(HandlersList) / sizeof(HandlersList[0])))
+ {
+ PrintUsage(Command);
+ }
+
+ return ret;
+}
Propchange: trunk/reactos/base/applications/cmdutils/fsutil/dirty.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c (added)
+++ trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c [iso-8859-1] Tue Sep 5
12:56:45 2017
@@ -0,0 +1,72 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS FS utility tool
+ * FILE: base/applications/cmdutils/fsutil.c
+ * PURPOSE: FSutil main
+ * PROGRAMMERS: Pierre Schweitzer <pierre(a)reactos.org>
+ */
+
+#include "fsutil.h"
+
+/* Add handlers here for commands */
+int DirtyMain(int argc, const TCHAR *argv[]);
+static HandlerItem HandlersList[] =
+{
+ /* Proc, name, help */
+ { DirtyMain, _T("dirty"), _T("Manipulates the dirty bit") },
+};
+
+static void
+PrintUsage(const TCHAR * Command)
+{
+ int i;
+
+ /* If we were given a command, print it's not supported */
+ if (Command != NULL)
+ {
+ _ftprintf(stderr, _T("Unhandled command: %s\n"), Command);
+ }
+
+ /* And dump any available command */
+ _ftprintf(stderr, _T("---- Handled commands ----\n\n"));
+ for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
+ {
+ _ftprintf(stderr, _T("%s\t%s\n"), HandlersList[i].Command,
HandlersList[i].Desc);
+ }
+}
+
+int
+__cdecl
+_tmain(int argc, const TCHAR *argv[])
+{
+ int i;
+ int ret;
+ const TCHAR * Command;
+
+ ret = 1;
+ Command = NULL;
+ i = (sizeof(HandlersList) / sizeof(HandlersList[0]));
+
+ /* If we have a command, does it match a known one? */
+ if (argc > 1)
+ {
+ /* Browse all the known commands finding the right one */
+ Command = argv[1];
+ for (i = 0; i < (sizeof(HandlersList) / sizeof(HandlersList[0])); ++i)
+ {
+ if (_tcsicmp(Command, HandlersList[i].Command) == 0)
+ {
+ ret = HandlersList[i].Handler(argc - 1, &argv[1]);
+ break;
+ }
+ }
+ }
+
+ /* We failed finding someone to handle the caller's needs, print out */
+ if (i == (sizeof(HandlersList) / sizeof(HandlersList[0])))
+ {
+ PrintUsage(Command);
+ }
+
+ return ret;
+}
Propchange: trunk/reactos/base/applications/cmdutils/fsutil/fsutil.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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 (added)
+++ trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h [iso-8859-1] Tue Sep 5
12:56:45 2017
@@ -0,0 +1,15 @@
+#ifndef __FSUTIL_H__
+#define __FSUTIL_H__
+
+#include <windows.h>
+#include <tchar.h>
+#include <stdio.h>
+
+typedef struct
+{
+ int (*Handler)(int argc, const TCHAR *argv[]);
+ const TCHAR * Command;
+ const TCHAR * Desc;
+} HandlerItem;
+
+#endif
Propchange: trunk/reactos/base/applications/cmdutils/fsutil/fsutil.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/base/applications/cmdutils/fsutil/fsutil.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/fsutil/fsutil.rc (added)
+++ trunk/reactos/base/applications/cmdutils/fsutil/fsutil.rc [iso-8859-1] Tue Sep 5
12:56:45 2017
@@ -0,0 +1,4 @@
+#define REACTOS_STR_FILE_DESCRIPTION "FS utility\0"
+#define REACTOS_STR_INTERNAL_NAME "fsutil\0"
+#define REACTOS_STR_ORIGINAL_FILENAME "fsutil.exe\0"
+#include <reactos/version.rc>
Propchange: trunk/reactos/base/applications/cmdutils/fsutil/fsutil.rc
------------------------------------------------------------------------------
svn:eol-style = native