ReactOS 0.4.15-dev-5667-ged97270
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
21static int
23{
26
29 &BytesRead, NULL) == FALSE)
30 {
32 return 1;
33 }
34
35 return 0;
36}
37
38static int
40{
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
85static int
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
111static void
113{
115 (sizeof(HandlersList) / sizeof(HandlersList[0])));
116}
117
118int
119VolumeMain(int argc, const TCHAR *argv[])
120{
122 (sizeof(HandlersList) / sizeof(HandlersList[0])),
123 PrintUsage);
124}
unsigned char BOOLEAN
static int argc
Definition: ServiceArgs.c:12
HandlerProc VolumeMain
Definition: fsutil.c:15
int() HandlerProc(int argc, const TCHAR *argv[])
Definition: fsutil.h:8
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
HANDLE OpenVolume(const TCHAR *Volume, BOOLEAN AllowRemote, BOOLEAN NtfsOnly)
Definition: common.c:49
void PrintDefaultUsage(const TCHAR *Command, const TCHAR *SubCommand, HandlerItem *HandlersList, int HandlerListCount)
Definition: common.c:102
int FindHandler(int argc, const TCHAR *argv[], HandlerItem *HandlersList, int HandlerListCount, void(*UsageHelper)(const TCHAR *))
Definition: common.c:11
static int LockOrUnlockVolume(HANDLE Volume, BOOLEAN Lock)
Definition: volume.c:22
static HandlerProc DismountMain
Definition: volume.c:12
static HandlerProc DiskFreeMain
Definition: volume.c:13
static HandlerItem HandlersList[]
Definition: volume.c:14
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
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
unsigned long DWORD
Definition: ntddk_ex.h:95
FP_OP Operation
Definition: fpcontrol.c:150
#define stdout
Definition: stdio.h:99
#define stderr
Definition: stdio.h:100
#define _ftprintf
Definition: tchar.h:518
UNICODE_STRING Volume
Definition: fltkernel.h:1172
#define argv
Definition: mplay32.c:18
void PrintUsage()
Definition: nslookup.c:68
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
Definition: shell.h:41
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
uint32_t ULONG
Definition: typedefs.h:59
#define _T(x)
Definition: vfdio.h:22
_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:870
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define GetDiskFreeSpaceEx
Definition: winbase.h:3679
char TCHAR
Definition: xmlstorage.h:189