54 wchar_t *StrPosResult =
NULL;
55 wchar_t *StrPosOrig =
NULL;
72 *StrPosResult = *StrPosOrig;
97 wprintf (
L"Usage: unfrag drive: [...] <-f | -e>\n");
99 wprintf (
L"drive: : The drive to defrag. Should be two characters long, ie 'c:' or 'd:'.\n");
100 wprintf (
L" Multiple drives may be given, and all will be simultaneously\n");
101 wprintf (
L" defragmented using the same options.\n");
102 wprintf (
L"-f : Do a fast defragmentation. Files that are not fragmented will not be\n");
103 wprintf (
L" moved. Only one pass is made over the file list. Using this option\n");
104 wprintf (
L" may result in not all files being defragmented, depending on\n");
105 wprintf (
L" available disk space.\n");
106 wprintf (
L"-e : Do an extensive defragmention. Files will be moved in an attempt to\n");
107 wprintf (
L" defragment both files and free space.\n");
112 wprintf (
L"NOTE: This program requires Windows 2000, which is not presently running on\n");
155 bool ValidCmdLine =
false;
175 ValidCmdLine =
false;
185 ValidCmdLine =
false;
197 ValidCmdLine =
false;
201 wprintf (
L"Invalid command-line options. Use '%s -?' for help.\n",
argv[0]);
208 wprintf (
L"Fatal Error: This program requires Windows 2000.\n");
212 for (
size_t d = 0;
d < Drives.
size ();
d++)
218 for (
size_t d = 0;
d < Drives.
size () - 1;
d++)
221 bool Continue =
true;
239 for (
size_t d = 0;
d < Drives.
size ();
d++)
241 wprintf (
L"\n%6.2f%% %-70s", Defrags[
d]->GetStatusPercent(), Defrags[
d]->GetStatusString().c_str());
246 for (
size_t d = 0;
d < Drives.
size ();
d++)
248 if (!Defrags[
d]->IsDoneYet() && !Defrags[
d]->HasError())
255 for (
int d = 0;
d < Drives.
size();
d++)
262 wprintf (
L"Opening volume %s ...", Drives[
d].c_str());
263 if (!
Drive->Open (Drives[
d]))
271 wprintf (
L" Getting drive bitmap ...");
272 if (!
Drive->GetBitmap ())
280 wprintf (
L" Obtaining drive geometry ...");
281 if (!
Drive->ObtainInfo ())
289 wprintf (
L" Building file database for drive %s ...", Drives[
d].c_str());
290 if (!
Drive->BuildFileList ())
312 for (
int i = 0;
i <
Drive->GetDBFileCount();
i++)
321 Used = ((
Info.Size +
Drive->GetClusterSize() - 1) /
Drive->GetClusterSize()) *
Drive->GetClusterSize();
322 Slack = Used -
Info.Size;
332 if (
Info.Attributes.AccessDenied)
336 if (
Info.Attributes.Unmovable == 1)
339 wprintf (
L"%I64u bytes, %I64u bytes on disk, %I64u bytes slack, %u fragments\n",
340 Info.Size, Used, Slack,
Info.Fragments.size());
344 if (
Info.Fragments.size() > 1)
356 wprintf (
L" %u bytes per cluster\n",
Drive->GetClusterSize());
360 wprintf (
L" %u contiguous files\n",
Drive->GetDBFileCount () - Fragged);
361 wprintf (
L" %u fragmented files\n", Fragged);
364 wprintf (
L" %I64u bytes on disk\n", UsedBytes);
365 wprintf (
L" %I64u bytes slack\n", SlackBytes);
377 wprintf (
L" Performing fast file defragmentation ...\n");
380 wprintf (
L" Performing extensive file defragmentation\n");
383 Drive->FindFreeRange (0, 1, FirstFreeLCN);
385 for (
i = 0;
i <
Drive->GetDBFileCount();
i++)
399 if (
Info.Fragments.size() == 0)
407 Result =
Drive->FindFreeRange (FirstFreeLCN,
Info.Clusters, TargetLCN);
414 if (TargetLCN >
Info.Fragments[0].StartLCN)
423 if (
Drive->MoveFileDumb (
i, TargetLCN))
427 Result =
Drive->FindFreeRange (TargetLCN + 1,
Info.Clusters, TargetLCN);
430 if (
Drive->MoveFileDumb (
i, TargetLCN))
434 if (
Drive->GetBitmap ())
439 if (
Drive->MoveFileDumb (
i, TargetLCN))
450 Drive->FindFreeRange (0, 1, FirstFreeLCN);
456 wprintf (
L"Closing volume %s ...", Drives[
d].c_str());
int FitName(wchar_t *destination, const wchar_t *path, const wchar_t *filename, uint32 totalWidth)
wchar_t * AddCommas(wchar_t *Result, uint64 Number)
Defragment * StartDefragThread(wstring Drive, DefragType Method, HANDLE &Handle)
void __cdecl DefragThread(LPVOID parm)
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define VER_PLATFORM_WIN32_WINDOWS
#define VER_PLATFORM_WIN32s
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
_CRTIMP uintptr_t __cdecl _beginthread(_In_ void(__cdecl *_StartAddress)(void *), _In_ unsigned _StackSize, _In_opt_ void *_ArgList)
_CRTIMP void __cdecl _endthread(void)
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
void PrintName(FILE *fileDest, EXPORT *pexp, PSTRING pstr, int fDeco)
ULONG dwOSVersionInfoSize
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
#define STD_OUTPUT_HANDLE
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS _In_ SIZE_T TotalBytes