ReactOS  0.4.15-dev-2526-g0fb3c1e
volume.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS FS utility tool
4  * FILE: base/applications/cmdutils/volume.c
5  * PURPOSE: FSutil volumes management
6  * PROGRAMMERS: Pierre Schweitzer <pierre@reactos.org>
7  */
8 
9 #include "fsutil.h"
10 
11 /* Add handlers here for subcommands */
15 {
16  /* Proc, name, help */
17  { DismountMain, _T("dismount"), _T("Dismounts a volume") },
18  { DiskFreeMain, _T("diskfree"), _T("Prints free space on a volume") },
19 };
20 
21 static int
23 {
26 
29  &BytesRead, NULL) == FALSE)
30  {
32  return 1;
33  }
34 
35  return 0;
36 }
37 
38 static int
39 DismountMain(int argc, const TCHAR *argv[])
40 {
41  HANDLE Volume;
43 
44  /* We need a volume (letter or GUID) */
45  if (argc < 2)
46  {
47  _ftprintf(stderr, _T("Usage: fsutil volume dismount <volume>\n"));
48  _ftprintf(stderr, _T("\tFor example: fsutil volume dismount d:\n"));
49  return 1;
50  }
51 
52  /* Get a handle for the volume */
55  {
56  return 1;
57  }
58 
59  /* Attempt to lock the volume */
61  {
63  return 1;
64  }
65 
66  /* Issue the dismount command */
68  0, &BytesRead, NULL) == FALSE)
69  {
73  return 1;
74  }
75 
76  /* Unlock and quit */
79 
80  _ftprintf(stdout, _T("The %s volume has been dismounted\n"), argv[1]);
81 
82  return 0;
83 }
84 
85 static int
86 DiskFreeMain(int argc, const TCHAR *argv[])
87 {
88  ULARGE_INTEGER FreeAvail, TotalNumber, TotalNumberFree;
89 
90  /* We need a path */
91  if (argc < 2)
92  {
93  _ftprintf(stderr, _T("Usage: fsutil volume diskfree <volume path>\n"));
94  _ftprintf(stderr, _T("\tFor example: fsutil volume diskfree c:\n"));
95  return 1;
96  }
97 
98  if (!GetDiskFreeSpaceEx(argv[1], &FreeAvail, &TotalNumber, &TotalNumberFree))
99  {
101  return 1;
102  }
103 
104  _ftprintf(stdout, _T("Total free bytes\t\t: %I64i\n"), TotalNumberFree.QuadPart);
105  _ftprintf(stdout, _T("Total bytes\t\t\t: %I64i\n"), TotalNumber.QuadPart);
106  _ftprintf(stdout, _T("Total free available bytes\t: %I64i\n"), FreeAvail.QuadPart);
107 
108  return 0;
109 }
110 
111 static void
113 {
115  (sizeof(HandlersList) / sizeof(HandlersList[0])));
116 }
117 
118 int
119 VolumeMain(int argc, const TCHAR *argv[])
120 {
122  (sizeof(HandlersList) / sizeof(HandlersList[0])),
123  PrintUsage);
124 }
static int argc
Definition: ServiceArgs.c:12
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
static int LockOrUnlockVolume(HANDLE Volume, BOOLEAN Lock)
Definition: volume.c:22
#define CloseHandle
Definition: compat.h:598
int VolumeMain(int argc, const TCHAR *argv[])
Definition: volume.c:119
void PrintDefaultUsage(const TCHAR *Command, const TCHAR *SubCommand, HandlerItem *HandlersList, int HandlerListCount)
Definition: common.c:102
#define TRUE
Definition: types.h:120
static HandlerProc DiskFreeMain
Definition: volume.c:13
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
Definition: shell.h:41
#define argv
Definition: mplay32.c:18
static HandlerProc DismountMain
Definition: volume.c:12
FILE * stdout
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:859
int FindHandler(int argc, const TCHAR *argv[], HandlerItem *HandlersList, int HandlerListCount, void(*UsageHelper)(const TCHAR *))
Definition: common.c:11
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
#define _ftprintf
Definition: tchar.h:518
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static HandlerItem HandlersList[]
Definition: volume.c:14
BOOL OpenVolume(LPCTSTR lpszVolumeName)
Definition: volume.c:28
unsigned long DWORD
Definition: ntddk_ex.h:95
static void PrintUsage(const TCHAR *Command)
Definition: volume.c:112
int() HandlerProc(int argc, const TCHAR *argv[])
Definition: fsutil.h:8
#define GetDiskFreeSpaceEx
Definition: winbase.h:3664
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
unsigned int ULONG
Definition: retypes.h:1
FILE * stderr
_In_ FLT_SET_CONTEXT_OPERATION Operation
Definition: fltkernel.h:1468