ReactOS  0.4.12-dev-57-g7050ac4
volume.c File Reference
#include "fsutil.h"
Include dependency graph for volume.c:

Go to the source code of this file.

Functions

static int LockOrUnlockVolume (HANDLE Volume, BOOLEAN Lock)
 
static int DismountMain (int argc, const TCHAR *argv[])
 
static int DiskFreeMain (int argc, const TCHAR *argv[])
 
static void PrintUsage (const TCHAR *Command)
 
int VolumeMain (int argc, const TCHAR *argv[])
 

Variables

static HandlerProc DismountMain
 
static HandlerProc DiskFreeMain
 
static HandlerItem HandlersList []
 

Function Documentation

◆ DiskFreeMain()

static int DiskFreeMain ( int  argc,
const TCHAR argv[] 
)
static

Definition at line 86 of file volume.c.

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 }
static int argc
Definition: ServiceArgs.c:12
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static char ** argv
Definition: ServiceArgs.c:11
FILE * stdout
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define _ftprintf
Definition: tchar.h:518
#define _T(x)
Definition: vfdio.h:22
#define GetDiskFreeSpaceEx
Definition: winbase.h:3622
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
FILE * stderr

◆ DismountMain()

static int DismountMain ( int  argc,
const TCHAR argv[] 
)
static

Definition at line 39 of file volume.c.

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 */
53  Volume = OpenVolume(argv[1], FALSE, FALSE);
54  if (Volume == INVALID_HANDLE_VALUE)
55  {
56  return 1;
57  }
58 
59  /* Attempt to lock the volume */
60  if (LockOrUnlockVolume(Volume, TRUE))
61  {
62  CloseHandle(Volume);
63  return 1;
64  }
65 
66  /* Issue the dismount command */
68  0, &BytesRead, NULL) == FALSE)
69  {
71  LockOrUnlockVolume(Volume, FALSE);
72  CloseHandle(Volume);
73  return 1;
74  }
75 
76  /* Unlock and quit */
77  LockOrUnlockVolume(Volume, FALSE);
78  CloseHandle(Volume);
79 
80  _ftprintf(stdout, _T("The %s volume has been dismounted\n"), argv[1]);
81 
82  return 0;
83 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
static int LockOrUnlockVolume(HANDLE Volume, BOOLEAN Lock)
Definition: volume.c:22
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static char ** argv
Definition: ServiceArgs.c:11
FILE * stdout
smooth NULL
Definition: ftsmooth.c:416
#define _ftprintf
Definition: tchar.h:518
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
#define _T(x)
Definition: vfdio.h:22
BOOL OpenVolume(LPCTSTR lpszVolumeName)
Definition: volume.c:28
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
unsigned int ULONG
Definition: retypes.h:1
FILE * stderr
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

◆ LockOrUnlockVolume()

static int LockOrUnlockVolume ( HANDLE  Volume,
BOOLEAN  Lock 
)
static

Definition at line 22 of file volume.c.

Referenced by DismountMain().

23 {
26 
27  Operation = (Lock ? FSCTL_LOCK_VOLUME : FSCTL_UNLOCK_VOLUME);
28  if (DeviceIoControl(Volume, Operation, NULL, 0, NULL, 0,
29  &BytesRead, NULL) == FALSE)
30  {
32  return 1;
33  }
34 
35  return 0;
36 }
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
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 FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
unsigned int ULONG
Definition: retypes.h:1
_In_ FLT_SET_CONTEXT_OPERATION Operation
Definition: fltkernel.h:1468
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

◆ PrintUsage()

static void PrintUsage ( const TCHAR Command)
static

Definition at line 112 of file volume.c.

Referenced by VolumeMain().

113 {
115  (sizeof(HandlersList) / sizeof(HandlersList[0])));
116 }
void PrintDefaultUsage(const TCHAR *Command, const TCHAR *SubCommand, HandlerItem *HandlersList, int HandlerListCount)
Definition: common.c:102
Definition: shell.h:41
#define _T(x)
Definition: vfdio.h:22
static HandlerItem HandlersList[]
Definition: volume.c:14

◆ VolumeMain()

int VolumeMain ( int  argc,
const TCHAR argv[] 
)

Definition at line 119 of file volume.c.

120 {
122  (sizeof(HandlersList) / sizeof(HandlersList[0])),
123  PrintUsage);
124 }
static int argc
Definition: ServiceArgs.c:12
static char ** argv
Definition: ServiceArgs.c:11
int FindHandler(int argc, const TCHAR *argv[], HandlerItem *HandlersList, int HandlerListCount, void(*UsageHelper)(const TCHAR *))
Definition: common.c:11
static HandlerItem HandlersList[]
Definition: volume.c:14
static void PrintUsage(const TCHAR *Command)
Definition: volume.c:112

Variable Documentation

◆ DiskFreeMain

HandlerProc DiskFreeMain
static

Definition at line 13 of file volume.c.

◆ DismountMain

HandlerProc DismountMain
static

Definition at line 12 of file volume.c.

◆ HandlersList

HandlerItem HandlersList[]
static
Initial value:
=
{
{ DismountMain, _T("dismount"), _T("Dismounts a volume") },
{ DiskFreeMain, _T("diskfree"), _T("Prints free space on a volume") },
}
static HandlerProc DiskFreeMain
Definition: volume.c:13
static HandlerProc DismountMain
Definition: volume.c:12
#define _T(x)
Definition: vfdio.h:22

Definition at line 14 of file volume.c.