2006-03-30 00:09:09 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
|
|
|
Unfrag
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "Unfrag.h"
|
|
|
|
#include "DriveVolume.h"
|
|
|
|
#include "Defragment.h"
|
|
|
|
#include <process.h>
|
|
|
|
|
|
|
|
|
|
|
|
bool QuietMode = false;
|
|
|
|
bool VerboseMode = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Makes sure we're in Windows 2000
|
|
|
|
bool CheckWinVer (void)
|
|
|
|
{
|
|
|
|
OSVERSIONINFO OSVersion;
|
|
|
|
|
|
|
|
ZeroMemory (&OSVersion, sizeof (OSVersion));
|
|
|
|
OSVersion.dwOSVersionInfoSize = sizeof (OSVersion);
|
|
|
|
GetVersionEx (&OSVersion);
|
2007-10-19 23:05:02 +00:00
|
|
|
|
2006-03-30 00:09:09 +00:00
|
|
|
// Need Windows 2000!
|
|
|
|
|
|
|
|
// Check for NT first
|
2006-04-01 15:02:38 +00:00
|
|
|
// Actually what we do is check that weLL're not on Win31+Win32s and that we're
|
2006-03-30 00:09:09 +00:00
|
|
|
// not in Windows 9x. It's possible that there could be more Windows "platforms"
|
|
|
|
// in the future and there's no sense in claiming incompatibility.
|
|
|
|
if (OSVersion.dwPlatformId == VER_PLATFORM_WIN32s ||
|
|
|
|
OSVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
|
|
|
|
{
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
// Ok weLL're in Windows NT, now make sure we're in 2000
|
2006-03-30 00:09:09 +00:00
|
|
|
if (OSVersion.dwMajorVersion < 5)
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
// Kew, we're in at least Windows 2000 ("NT 5.0")
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
wchar_t *AddCommas (wchar_t *Result, uint64 Number)
|
2006-03-30 00:09:09 +00:00
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wchar_t Temp[128];
|
2006-03-30 00:09:09 +00:00
|
|
|
int TempLen;
|
2006-04-01 15:02:38 +00:00
|
|
|
wchar_t *p = NULL;
|
2006-03-30 00:09:09 +00:00
|
|
|
int AddCommas = 0;
|
2006-04-01 15:02:38 +00:00
|
|
|
wchar_t *StrPosResult = NULL;
|
|
|
|
wchar_t *StrPosOrig = NULL;
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
// we get the string form of the number, then we count down w/ AddCommas
|
|
|
|
// while copying the string from Temp1 to Result. when AddCommas % 3 == 1,
|
|
|
|
// slap in a commas as well, before the #.
|
2006-04-01 15:02:38 +00:00
|
|
|
swprintf (Temp, L"%I64u", Number);
|
|
|
|
AddCommas = TempLen = wcslen (Temp);
|
2006-03-30 00:09:09 +00:00
|
|
|
StrPosOrig = Temp;
|
|
|
|
StrPosResult = Result;
|
|
|
|
while (AddCommas)
|
|
|
|
{
|
|
|
|
if ((AddCommas % 3) == 0 && AddCommas != TempLen) // avoid stuff like ",345"
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
*StrPosResult = L',';
|
2006-03-30 00:09:09 +00:00
|
|
|
StrPosResult++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*StrPosResult = *StrPosOrig;
|
|
|
|
StrPosResult++;
|
|
|
|
StrPosOrig++;
|
|
|
|
|
|
|
|
*StrPosResult = 0;
|
|
|
|
|
|
|
|
AddCommas--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrintBanner (void)
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"%s v%s\n", APPNAME_CLI, APPVER_STR);
|
|
|
|
wprintf (L"%s\n", APPCOPYRIGHT);
|
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FraggerHelp (void)
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"Usage: unfrag drive: [...] <-f | -e>\n");
|
|
|
|
wprintf (L"\n");
|
|
|
|
wprintf (L"drive: : The drive to defrag. Should be two characters long, ie 'c:' or 'd:'.\n");
|
|
|
|
wprintf (L" Multiple drives may be given, and all will be simultaneously\n");
|
|
|
|
wprintf (L" defragmented using the same options.\n");
|
|
|
|
wprintf (L"-f : Do a fast defragmentation. Files that are not fragmented will not be\n");
|
|
|
|
wprintf (L" moved. Only one pass is made over the file list. Using this option\n");
|
|
|
|
wprintf (L" may result in not all files being defragmented, depending on\n");
|
|
|
|
wprintf (L" available disk space.\n");
|
|
|
|
wprintf (L"-e : Do an extensive defragmention. Files will be moved in an attempt to\n");
|
|
|
|
wprintf (L" defragment both files and free space.\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
if (!CheckWinVer())
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
|
|
|
wprintf (L"NOTE: This program requires Windows 2000, which is not presently running on\n");
|
|
|
|
wprintf (L"this system.\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __cdecl DefragThread (LPVOID parm)
|
|
|
|
{
|
|
|
|
Defragment *Defrag;
|
|
|
|
|
|
|
|
Defrag = (Defragment *) parm;
|
|
|
|
Defrag->Start ();
|
|
|
|
|
|
|
|
_endthread ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
Defragment *StartDefragThread (wstring Drive, DefragType Method, HANDLE &Handle)
|
2006-03-30 00:09:09 +00:00
|
|
|
{
|
|
|
|
Defragment *Defragger;
|
|
|
|
unsigned long Thread;
|
|
|
|
|
|
|
|
Defragger = new Defragment (Drive, Method);
|
|
|
|
//Thread = /*CreateThread*/ _beginthreadex (NULL, 0, DefragThread, Defragger, 0, &ThreadID);
|
|
|
|
Thread = _beginthread (DefragThread, 0, Defragger);
|
|
|
|
Handle = *((HANDLE *)&Thread);
|
|
|
|
return (Defragger);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Main Initialization
|
2006-04-01 15:02:38 +00:00
|
|
|
int wmain (int argc, wchar_t **argv)
|
2006-03-30 00:09:09 +00:00
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
vector<wstring> Drives;
|
2006-03-30 00:09:09 +00:00
|
|
|
vector<Defragment *> Defrags;
|
|
|
|
DefragType DefragMode = DefragInvalid;
|
|
|
|
|
|
|
|
PrintBanner ();
|
|
|
|
|
|
|
|
// Parse command line arguments
|
|
|
|
bool ValidCmdLine = false;
|
|
|
|
for (int c = 0; c < argc; c++)
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
if (wcslen(argv[c]) == 2 && argv[c][1] == L':')
|
2006-03-30 00:09:09 +00:00
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
Drives.push_back (wcsupr(argv[c]));
|
2006-03-30 00:09:09 +00:00
|
|
|
}
|
|
|
|
else
|
2006-04-01 15:02:38 +00:00
|
|
|
if (argv[c][0] == L'-' || argv[c][0] == L'/' && wcslen(argv[c]) == 2)
|
2006-03-30 00:09:09 +00:00
|
|
|
{
|
|
|
|
switch (tolower(argv[c][1]))
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
case L'?' :
|
|
|
|
case L'h' :
|
2006-03-30 00:09:09 +00:00
|
|
|
FraggerHelp ();
|
|
|
|
return (0);
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
case L'f' :
|
2006-03-30 00:09:09 +00:00
|
|
|
if (DefragMode != DefragInvalid)
|
|
|
|
{
|
|
|
|
ValidCmdLine = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DefragMode = DefragFast;
|
|
|
|
ValidCmdLine = true;
|
|
|
|
break;
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
case L'e' :
|
2006-03-30 00:09:09 +00:00
|
|
|
if (DefragMode != DefragInvalid)
|
|
|
|
{
|
|
|
|
ValidCmdLine = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DefragMode = DefragExtensive;
|
|
|
|
ValidCmdLine = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DefragMode == DefragInvalid)
|
|
|
|
ValidCmdLine = false;
|
|
|
|
|
|
|
|
if (!ValidCmdLine)
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"Invalid command-line options. Use '%s -?' for help.\n", argv[0]);
|
2006-03-30 00:09:09 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check OS requirements
|
|
|
|
if (!CheckWinVer())
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"Fatal Error: This program requires Windows 2000.\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
for (size_t d = 0; d < Drives.size (); d++)
|
2006-03-30 00:09:09 +00:00
|
|
|
{
|
|
|
|
HANDLE TossMe;
|
|
|
|
Defrags.push_back (StartDefragThread (Drives[d], DefragMode, TossMe));
|
|
|
|
}
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
for (size_t d = 0; d < Drives.size () - 1; d++)
|
|
|
|
wprintf (L"\n ");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
bool Continue = true;
|
|
|
|
HANDLE Screen;
|
|
|
|
|
|
|
|
Screen = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
while (Continue)
|
|
|
|
{
|
|
|
|
Sleep (25);
|
|
|
|
|
|
|
|
// Get current screen coords
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO ScreenInfo;
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo (Screen, &ScreenInfo);
|
|
|
|
|
|
|
|
// Now set back to the beginning
|
|
|
|
ScreenInfo.dwCursorPosition.X = 0;
|
|
|
|
ScreenInfo.dwCursorPosition.Y -= Drives.size();
|
|
|
|
SetConsoleCursorPosition (Screen, ScreenInfo.dwCursorPosition);
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
for (size_t d = 0; d < Drives.size (); d++)
|
2006-03-30 00:09:09 +00:00
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n%6.2f%% %-70s", Defrags[d]->GetStatusPercent(), Defrags[d]->GetStatusString().c_str());
|
2006-03-30 00:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Determine if we should keep going
|
|
|
|
Continue = false;
|
2006-04-01 15:02:38 +00:00
|
|
|
for (size_t d = 0; d < Drives.size (); d++)
|
2006-03-30 00:09:09 +00:00
|
|
|
{
|
|
|
|
if (!Defrags[d]->IsDoneYet() && !Defrags[d]->HasError())
|
2007-10-19 23:05:02 +00:00
|
|
|
Continue = true;
|
2006-03-30 00:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// Loop through the drives list
|
|
|
|
for (int d = 0; d < Drives.size(); d++)
|
|
|
|
{
|
|
|
|
DriveVolume *Drive;
|
|
|
|
|
|
|
|
Drive = new DriveVolume;
|
|
|
|
|
|
|
|
// First thing: build a file list.
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"Opening volume %s ...", Drives[d].c_str());
|
2006-03-30 00:09:09 +00:00
|
|
|
if (!Drive->Open (Drives[d]))
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"FAILED\n\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
delete Drive;
|
|
|
|
continue;
|
|
|
|
}
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" Getting drive bitmap ...");
|
2006-03-30 00:09:09 +00:00
|
|
|
if (!Drive->GetBitmap ())
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"FAILED\n\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
delete Drive;
|
|
|
|
continue;
|
|
|
|
}
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" Obtaining drive geometry ...");
|
2006-03-30 00:09:09 +00:00
|
|
|
if (!Drive->ObtainInfo ())
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"FAILED\n\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
delete Drive;
|
|
|
|
continue;
|
|
|
|
}
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" Building file database for drive %s ...", Drives[d].c_str());
|
2006-03-30 00:09:09 +00:00
|
|
|
if (!Drive->BuildFileList ())
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"FAILED\n\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
delete Drive;
|
|
|
|
continue;
|
|
|
|
}
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" %u files\n", Drive->GetDBFileCount ());
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
// Analyze only?
|
|
|
|
if (DefragMode == DefragAnalyze)
|
|
|
|
{
|
|
|
|
uint64 UsedBytes = 0; // total bytes used, with cluster size considerations
|
|
|
|
uint64 TotalBytes = 0; // total bytes used
|
|
|
|
uint64 SlackBytes = 0; // wasted space due to slack
|
|
|
|
uint32 Fragged = 0; // fragmented files
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" Analyzing ...");
|
2006-03-30 00:09:09 +00:00
|
|
|
if (VerboseMode)
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < Drive->GetDBFileCount(); i++)
|
|
|
|
{
|
|
|
|
uint64 Used;
|
|
|
|
uint64 Slack;
|
|
|
|
FileInfo Info;
|
|
|
|
|
|
|
|
Info = Drive->GetDBFile (i);
|
|
|
|
|
|
|
|
// Compute total used disk space
|
|
|
|
Used = ((Info.Size + Drive->GetClusterSize() - 1) / Drive->GetClusterSize()) * Drive->GetClusterSize();
|
|
|
|
Slack = Used - Info.Size;
|
|
|
|
|
|
|
|
UsedBytes += Used;
|
|
|
|
SlackBytes += Slack;
|
|
|
|
TotalBytes += Info.Size;
|
|
|
|
|
|
|
|
if (VerboseMode)
|
|
|
|
{
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" %s%s, ", Drive->GetDBDir (Info.DirIndice).c_str(), Info.Name.c_str());
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
if (Info.Attributes.AccessDenied)
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"access was denied\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Info.Attributes.Unmovable == 1)
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"unmovable, ");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
2007-10-19 23:05:02 +00:00
|
|
|
wprintf (L"%I64u bytes, %I64u bytes on disk, %I64u bytes slack, %u fragments\n",
|
2006-03-30 00:09:09 +00:00
|
|
|
Info.Size, Used, Slack, Info.Fragments.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Info.Fragments.size() > 1)
|
|
|
|
Fragged++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!VerboseMode)
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
// TODO: Make it not look like ass
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
|
|
|
wprintf (L" Overall Analysis\n");
|
|
|
|
wprintf (L" ----------------\n");
|
|
|
|
wprintf (L" %u clusters\n", Drive->GetClusterCount ());
|
|
|
|
wprintf (L" %u bytes per cluster\n", Drive->GetClusterSize());
|
|
|
|
wprintf (L" %I64u total bytes on drive\n", (uint64)Drive->GetClusterCount() * (uint64)Drive->GetClusterSize());
|
|
|
|
wprintf (L"\n");
|
|
|
|
wprintf (L" %u files\n", Drive->GetDBFileCount ());
|
|
|
|
wprintf (L" %u contiguous files\n", Drive->GetDBFileCount () - Fragged);
|
|
|
|
wprintf (L" %u fragmented files\n", Fragged);
|
|
|
|
wprintf (L"\n");
|
|
|
|
wprintf (L" %I64u bytes\n", TotalBytes);
|
|
|
|
wprintf (L" %I64u bytes on disk\n", UsedBytes);
|
|
|
|
wprintf (L" %I64u bytes slack\n", SlackBytes);
|
2006-03-30 00:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fast defragment!
|
|
|
|
if (DefragMode == DefragFast || DefragMode == DefragExtensive)
|
|
|
|
{
|
|
|
|
uint32 i;
|
|
|
|
uint64 FirstFreeLCN;
|
2006-04-01 15:02:38 +00:00
|
|
|
wchar_t PrintName[80];
|
2006-03-30 00:09:09 +00:00
|
|
|
int Width = 66;
|
|
|
|
|
|
|
|
if (DefragMode == DefragFast)
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" Performing fast file defragmentation ...\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
else
|
|
|
|
if (DefragMode == DefragExtensive)
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" Performing extensive file defragmentation\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
// Find first free LCN for speedier searches ...
|
|
|
|
Drive->FindFreeRange (0, 1, FirstFreeLCN);
|
|
|
|
|
|
|
|
for (i = 0; i < Drive->GetDBFileCount(); i++)
|
|
|
|
{
|
|
|
|
FileInfo Info;
|
|
|
|
bool Result;
|
|
|
|
uint64 TargetLCN;
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\r");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
Info = Drive->GetDBFile (i);
|
|
|
|
|
|
|
|
FitName (PrintName, Drive->GetDBDir (Info.DirIndice).c_str(), Info.Name.c_str(), Width);
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L" %6.2f%% %-66s", (float)i / (float)Drive->GetDBFileCount() * 100.0f, PrintName);
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
// Can't defrag 0 byte files :)
|
|
|
|
if (Info.Fragments.size() == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If doing fast defrag, skip non-fragmented files
|
|
|
|
if (Info.Fragments.size() == 1 && DefragMode == DefragFast)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Find a place that can fit the file
|
|
|
|
Result = Drive->FindFreeRange (FirstFreeLCN, Info.Clusters, TargetLCN);
|
|
|
|
|
|
|
|
// If we're doing an extensive defrag and the file is already defragmented
|
|
|
|
// and if its new location would be after its current location, don't
|
|
|
|
// move it.
|
|
|
|
if (DefragMode == DefragExtensive && Info.Fragments.size() == 1)
|
|
|
|
{
|
|
|
|
if (TargetLCN > Info.Fragments[0].StartLCN)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, defrag0rize it!
|
|
|
|
if (Result)
|
|
|
|
{
|
|
|
|
bool Success = false;
|
|
|
|
|
|
|
|
if (Drive->MoveFileDumb (i, TargetLCN))
|
|
|
|
Success = true;
|
|
|
|
else
|
|
|
|
{ // hmm, look for another area to move it to
|
|
|
|
Result = Drive->FindFreeRange (TargetLCN + 1, Info.Clusters, TargetLCN);
|
|
|
|
if (Result)
|
|
|
|
{
|
|
|
|
if (Drive->MoveFileDumb (i, TargetLCN))
|
|
|
|
Success = true;
|
|
|
|
else
|
|
|
|
{ // Try updating the drive bitmap
|
|
|
|
if (Drive->GetBitmap ())
|
|
|
|
{
|
|
|
|
Result = Drive->FindFreeRange (0, Info.Clusters, TargetLCN);
|
|
|
|
if (Result)
|
|
|
|
{
|
|
|
|
if (Drive->MoveFileDumb (i, TargetLCN))
|
|
|
|
Success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Success)
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n -> failed\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
|
|
|
|
Drive->FindFreeRange (0, 1, FirstFreeLCN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
}
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"Closing volume %s ...", Drives[d].c_str());
|
2006-03-30 00:09:09 +00:00
|
|
|
delete Drive;
|
2006-04-01 15:02:38 +00:00
|
|
|
wprintf (L"\n");
|
2006-03-30 00:09:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|