ReactOS 0.4.16-dev-122-g325d74c
DriveVolume Class Reference

#include <DriveVolume.h>

Collaboration diagram for DriveVolume:

Public Member Functions

 DriveVolume ()
 
 ~DriveVolume ()
 
bool Open (wstring Name)
 
void Close (void)
 
bool ObtainInfo (void)
 
bool GetBitmap (void)
 
bool BuildFileList (bool &QuitMonitor, double &Progress)
 
bool IsClusterUsed (uint64 Cluster)
 
void SetClusterUsed (uint64 Cluster, bool Used)
 
DISK_GEOMETRY GetGeometry (void)
 
VolumeInfo GetVolumeInfo (void)
 
wstring GetRootPath (void)
 
bool Scan (ScanCallback Callback, void *UserData)
 
wstring & GetDBDir (uint32 Indice)
 
uint32 GetDBDirCount (void)
 
FileInfoGetDBFile (uint32 Indice)
 
uint32 GetDBFileCount (void)
 
uint32 RemoveDBFile (uint32 Indice)
 
bool MoveFileDumb (uint32 FileIndice, uint64 NewLCN)
 
bool FindFreeRange (uint64 StartLCN, uint64 ReqLength, uint64 &LCNResult)
 

Private Member Functions

bool ScanDirectory (wstring DirPrefix, ScanCallback Callback, void *UserData)
 
bool ShouldProcess (FileAttr Attr)
 
bool GetClusterInfo (FileInfo &Info, HANDLE &HandleResult)
 

Private Attributes

VolumeInfo VolInfo
 
FileList Files
 
vector< wstring > Directories
 
wstring RootPath
 
HANDLE Handle
 
DISK_GEOMETRY Geometry
 
uint32BitmapDetail
 

Friends

bool BuildDBCallback (FileInfo &Info, HANDLE &FileHandle, void *UserData)
 

Detailed Description

Definition at line 89 of file DriveVolume.h.

Constructor & Destructor Documentation

◆ DriveVolume()

DriveVolume::DriveVolume ( )

Definition at line 4 of file DriveVolume.cpp.

5{
9}
DISK_GEOMETRY Geometry
Definition: DriveVolume.h:152
HANDLE Handle
Definition: DriveVolume.h:151
uint32 * BitmapDetail
Definition: DriveVolume.h:153
#define NULL
Definition: types.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define ZeroMemory
Definition: winbase.h:1712

◆ ~DriveVolume()

DriveVolume::~DriveVolume ( )

Definition at line 12 of file DriveVolume.cpp.

13{
14 Close ();
16 Files.clear ();
17 return;
18}
FileList Files
Definition: DriveVolume.h:148
void Close(void)
Definition: DriveVolume.cpp:21
vector< wstring > Directories
Definition: DriveVolume.h:149
void clear()
Definition: _vector.h:653

Member Function Documentation

◆ BuildFileList()

bool DriveVolume::BuildFileList ( bool QuitMonitor,
double Progress 
)

Definition at line 300 of file DriveVolume.cpp.

301{
303
304 Files.clear ();
307
308 Info.Volume = this;
309 Info.QuitMonitor = &QuitMonitor;
311 Info.ClusterProgress = 0;
312 Info.Percent = &Percent;
313
315
316 if (QuitMonitor == true)
317 {
319 Files.resize (0);
320 }
321
322 return (true);
323}
wstring RootPath
Definition: DriveVolume.h:150
bool ScanDirectory(wstring DirPrefix, ScanCallback Callback, void *UserData)
VolumeInfo GetVolumeInfo(void)
Definition: DriveVolume.h:109
friend bool BuildDBCallback(FileInfo &Info, HANDLE &FileHandle, void *UserData)
unsigned long long uint64
Definition: platform.h:18
uint64 TotalBytes
Definition: DriveVolume.h:74
uint64 FreeBytes
Definition: DriveVolume.h:75
uint32 ClusterSize
Definition: DriveVolume.h:73
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379
void resize(size_type __new_size, const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:639
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

Referenced by Defragment::Start().

◆ Close()

void DriveVolume::Close ( void  )

Definition at line 21 of file DriveVolume.cpp.

22{
24 {
27 }
28
29 if (BitmapDetail != NULL)
30 {
33 }
34
35 return;
36}
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735

Referenced by Defragment::Start(), Defragment::~Defragment(), and ~DriveVolume().

◆ FindFreeRange()

bool DriveVolume::FindFreeRange ( uint64  StartLCN,
uint64  ReqLength,
uint64 LCNResult 
)

Definition at line 632 of file DriveVolume.cpp.

633{
634 uint64 Max;
635 uint64 i;
636 uint64 j;
637
638 // Make sure we don't spill over our array
639 Max = VolInfo.ClusterCount - ReqLength;
640
641 for (i = StartLCN; i < Max; i++)
642 {
643 bool Found = true;
644
645 // First check the first cluster
646 if (IsClusterUsed (i))
647 Found = false;
648 else
649 // THen check the last cluster
650 if (IsClusterUsed (i + ReqLength - 1))
651 Found = false;
652 else
653 // Check the whole darn range.
654 for (j = (i + 1); j < (i + ReqLength - 2); j++)
655 {
656 if (IsClusterUsed (j) == true)
657 {
658 Found = false;
659 break;
660 }
661 }
662
663 if (!Found)
664 continue;
665 else
666 {
667 LCNResult = i;
668 return (true);
669 }
670 }
671
672 return (false);
673}
return Found
Definition: dirsup.c:1270
#define Max(a, b)
Definition: cdprocs.h:78
VolumeInfo VolInfo
Definition: DriveVolume.h:147
bool IsClusterUsed(uint64 Cluster)
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
Definition: glfuncs.h:248
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 GLint GLint j
Definition: glfuncs.h:250
uint64 ClusterCount
Definition: DriveVolume.h:72

Referenced by Defragment::Start().

◆ GetBitmap()

bool DriveVolume::GetBitmap ( void  )

Definition at line 172 of file DriveVolume.cpp.

173{
174 STARTING_LCN_INPUT_BUFFER StartingLCN;
176 uint32 BitmapSize;
178 BOOL Result;
179
180 StartingLCN.StartingLcn.QuadPart = 0;
181
182 // Allocate buffer
183 // Call FSCTL_GET_VOLUME_BITMAP once with a very small buffer
184 // This will leave the total number of clusters in Bitmap->BitmapSize and we can
185 // then correctly allocate based off that
186 // I suppose this won't work if your drive has only 40 clusters on it or so :)
187 BitmapSize = sizeof (VOLUME_BITMAP_BUFFER) + 4;
189
191 (
192 Handle,
194 &StartingLCN,
195 sizeof (StartingLCN),
196 Bitmap,
197 BitmapSize,
199 NULL
200 );
201
202 // Bad result?
204 {
205 //wprintf ("\nDeviceIoControl returned false, GetLastError() was not ERROR_MORE_DATA\n");
207 return (false);
208 }
209
210 // Otherwise, we're good
211 BitmapSize = sizeof (VOLUME_BITMAP_BUFFER) + (Bitmap->BitmapSize.QuadPart / 8) + 1;
212
213 void *reallBitmap = HeapReAlloc(GetProcessHeap(), 0, Bitmap, BitmapSize);
214
215 if (reallBitmap == NULL)
216 {
217 // Fail "miserably"
218 wprintf(L"\nNot enough memory to read volume bitmap\n");
220 return (false);
221 }
222
223 Bitmap = (VOLUME_BITMAP_BUFFER *)reallBitmap;
225 (
226 Handle,
228 &StartingLCN,
229 sizeof (StartingLCN),
230 Bitmap,
231 BitmapSize,
233 NULL
234 );
235
236 //DWORD LastError = GetLastError ();
237
238 if (Result == FALSE)
239 {
240 wprintf (L"\nCouldn't properly read volume bitmap\n");
242 return (false);
243 }
244
245 // Convert to a L'quick use' bitmap
246 //const int BitShift[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
247
248 VolInfo.ClusterCount = Bitmap->BitmapSize.QuadPart;
249
250 if (BitmapDetail != NULL)
252
253 BitmapDetail = (uint32 *) HeapAlloc(GetProcessHeap(), 0, sizeof(uint32) * (1 + (VolInfo.ClusterCount / 32)));
254 memcpy (BitmapDetail, Bitmap->Buffer, sizeof(uint32) * (1 + (VolInfo.ClusterCount / 32)));
255
256 /*
257 BitmapDetail = (Cluster *) malloc (VolInfo.ClusterCount * sizeof (Cluster));
258 for (uint64 i = 0; i < VolInfo.ClusterCount; i++)
259 {
260 if (Bitmap->Buffer[i / 8] & BitShift[i % 8])
261 BitmapDetail[i].Allocated = true;
262 else
263 BitmapDetail[i].Allocated = false;
264 }
265 */
266
268 return (true);
269}
unsigned int uint32
Definition: types.h:32
#define ERROR_MORE_DATA
Definition: dderror.h:13
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 FALSE
Definition: types.h:117
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define L(x)
Definition: ntvdm.h:50
#define FSCTL_GET_VOLUME_BITMAP
Definition: winioctl.h:743
LARGE_INTEGER StartingLcn
Definition: winioctl.h:789
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesReturned
Definition: wdfiotarget.h:1052
#define wprintf(...)
Definition: whoami.c:18
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_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
Definition: wsk.h:409

Referenced by Defragment::Start().

◆ GetClusterInfo()

bool DriveVolume::GetClusterInfo ( FileInfo Info,
HANDLE HandleResult 
)
private

Definition at line 495 of file DriveVolume.cpp.

496{
497 BOOL Result;
499 wstring FullName;
501
503
504 /*
505 if (Info.Attributes.Directory == 1)
506 return (false);
507 */
508
509 FullName = GetDBDir (Info.DirIndice) + Info.Name;
510
512 (
513 FullName.c_str(),
514 0, //GENERIC_READ,
516 NULL,
518 (Info.Attributes.Directory == 1) ? FILE_FLAG_BACKUP_SEMANTICS : 0,
519 NULL
520 );
521
523 {
524 LPVOID lpMsgBuf;
525
529 (LPTSTR) &lpMsgBuf, 0, NULL );
530
531
532 Info.Attributes.AccessDenied = 1;
533 LocalFree( lpMsgBuf );
534 return (false);
535 }
536
537 ZeroMemory (&FileInfo, sizeof (FileInfo));
539
540 if (Result == FALSE)
541 {
542 Info.Attributes.AccessDenied = 1;
543 wprintf (L"GetFileInformationByHandle ('%s%s') failed\n", GetDBDir (Info.DirIndice).c_str(),
544 Info.Name.c_str());
545
547 return (false);
548 }
549
550 // Get cluster allocation information
551 STARTING_VCN_INPUT_BUFFER StartingVCN;
552 RETRIEVAL_POINTERS_BUFFER *Retrieval;
553 uint64 RetSize;
554 uint64 Extents;
556
557 // Grab info one extent at a time, until it's done grabbing all the extent data
558 // Yeah, well it doesn't give us a way to ask L"how many extents?" that I know of ...
559 // btw, the Extents variable tends to only reflect memory usage, so when we have
560 // all the extents we look at the structure Win32 gives us for the REAL count!
561 Extents = 10;
562 Retrieval = NULL;
563 RetSize = 0;
564 StartingVCN.StartingVcn.QuadPart = 0;
565
566 do
567 {
568 Extents *= 2;
569 RetSize = sizeof (RETRIEVAL_POINTERS_BUFFER) + ((Extents - 1) * sizeof (LARGE_INTEGER) * 2);
570
571 if (Retrieval != NULL)
572 Retrieval = (RETRIEVAL_POINTERS_BUFFER *) realloc (Retrieval, RetSize);
573 else
574 Retrieval = (RETRIEVAL_POINTERS_BUFFER *) malloc (RetSize);
575
577 (
578 Handle,
580 &StartingVCN,
581 sizeof (StartingVCN),
582 Retrieval,
583 RetSize,
585 NULL
586 );
587
588 if (Result == FALSE)
589 {
591 {
592 Info.Clusters = 0;
593 Info.Attributes.AccessDenied = 1;
594 Info.Attributes.Process = 0;
595 Info.Fragments.clear ();
597 free (Retrieval);
598
599 return (false);
600 }
601
602 Extents++;
603 }
604 } while (Result == FALSE);
605
606 // Readjust extents, as it only reflects how much memory was allocated and may not
607 // be accurate
608 Extents = Retrieval->ExtentCount;
609
610 // Ok, we have the info. Now translate it. hrmrmr
611
612 Info.Fragments.clear ();
613 for (uint64 i = 0; i < Extents; i++)
614 {
615 Extent Add;
616
617 Add.StartLCN = Retrieval->Extents[i].Lcn.QuadPart;
618 if (i != 0)
619 Add.Length = Retrieval->Extents[i].NextVcn.QuadPart - Retrieval->Extents[i - 1].NextVcn.QuadPart;
620 else
621 Add.Length = Retrieval->Extents[i].NextVcn.QuadPart - Retrieval->StartingVcn.QuadPart;
622
623 Info.Fragments.push_back (Add);
624 }
625
626 free (Retrieval);
627 HandleResult = Handle;
628 return (true);
629}
wstring & GetDBDir(uint32 Indice)
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define OPEN_EXISTING
Definition: compat.h:775
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:458
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FSCTL_GET_RETRIEVAL_POINTERS
Definition: winioctl.h:744
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
uint64 StartLCN
Definition: DriveVolume.h:47
uint64 Length
Definition: DriveVolume.h:48
vector< Extent > Fragments
Definition: DriveVolume.h:59
struct RETRIEVAL_POINTERS_BUFFER::@3323 Extents[1]
LARGE_INTEGER StartingVcn
Definition: winioctl.h:782
LARGE_INTEGER StartingVcn
Definition: winioctl.h:792
union _LARGE_INTEGER LARGE_INTEGER
#define FormatMessage
Definition: winbase.h:3795
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
_In_ PSTRING FullName
Definition: rtlfuncs.h:1662
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by MoveFileDumb(), and ScanDirectory().

◆ GetDBDir()

wstring & DriveVolume::GetDBDir ( uint32  Indice)

Definition at line 345 of file DriveVolume.cpp.

346{
347 return (Directories[Indice]);
348}

Referenced by GetClusterInfo(), MoveFileDumb(), ScanDirectory(), and Defragment::Start().

◆ GetDBDirCount()

uint32 DriveVolume::GetDBDirCount ( void  )

Definition at line 351 of file DriveVolume.cpp.

352{
353 return (Directories.size());
354}
size_type size() const
Definition: _vector.h:192

Referenced by Defragment::Start().

◆ GetDBFile()

FileInfo & DriveVolume::GetDBFile ( uint32  Indice)

Definition at line 357 of file DriveVolume.cpp.

358{
359 return (Files[Indice]);
360}

Referenced by MoveFileDumb(), and Defragment::Start().

◆ GetDBFileCount()

uint32 DriveVolume::GetDBFileCount ( void  )

Definition at line 363 of file DriveVolume.cpp.

364{
365 return (Files.size());
366}

Referenced by RemoveDBFile(), and Defragment::Start().

◆ GetGeometry()

DISK_GEOMETRY DriveVolume::GetGeometry ( void  )
inline

Definition at line 108 of file DriveVolume.h.

108{ return (Geometry); }

◆ GetRootPath()

wstring DriveVolume::GetRootPath ( void  )
inline

Definition at line 111 of file DriveVolume.h.

111{ return (RootPath); }

Referenced by GetDefragTitle(), and Defragment::Start().

◆ GetVolumeInfo()

VolumeInfo DriveVolume::GetVolumeInfo ( void  )
inline

Definition at line 109 of file DriveVolume.h.

109{ return (VolInfo); }

Referenced by BuildFileList(), SetReportInfo(), and Defragment::Start().

◆ IsClusterUsed()

bool DriveVolume::IsClusterUsed ( uint64  Cluster)

Definition at line 272 of file DriveVolume.cpp.

273{
274 return ((BitmapDetail[Cluster / 32] & (1 << (Cluster % 32))) ? true : false);
275 //return (BitmapDetail[Cluster].Allocated);
276}

Referenced by FindFreeRange().

◆ MoveFileDumb()

bool DriveVolume::MoveFileDumb ( uint32  FileIndice,
uint64  NewLCN 
)

Definition at line 677 of file DriveVolume.cpp.

678{
679 bool ReturnVal = false;
682 wstring FullName;
683 MOVE_FILE_DATA MoveData;
684 uint64 CurrentLCN;
685 uint64 CurrentVCN;
686
687 // Set up variables
688 Info = GetDBFile (FileIndice);
689 FullName = GetDBDir (Info.DirIndice);
690 FullName += Info.Name;
691 CurrentLCN = NewLCN;
692 CurrentVCN = 0;
693
694 /*
695 if (Info.Attributes.Directory == 1)
696 {
697 //
698 }
699 */
700
701 // Open file
703 (
704 FullName.c_str (),
707 NULL,
709 (Info.Attributes.Directory == 1) ? FILE_FLAG_BACKUP_SEMANTICS : 0,
710 NULL
711 );
712
714 {
715 //
716 LPVOID lpMsgBuf;
717
721 (LPTSTR) &lpMsgBuf, 0, NULL );
722
723
724 LocalFree (lpMsgBuf);
725 //
726
727 ReturnVal = false;
728 }
729 else
730 {
731 ReturnVal = true; // innocent until proven guilty ...
732
733 for (uint32 i = 0; i < Info.Fragments.size(); i++)
734 {
735 BOOL Result;
737
738 //wprintf (L"%3u", i);
739
740 MoveData.ClusterCount = Info.Fragments[i].Length;
741 MoveData.StartingLcn.QuadPart = CurrentLCN;
742 MoveData.StartingVcn.QuadPart = CurrentVCN;
743
744 MoveData.FileHandle = FileHandle;
745
746 /*
747 wprintf (L"\n");
748 wprintf (L"StartLCN: %I64u\n", MoveData.StartingLcn.QuadPart);
749 wprintf (L"StartVCN: %I64u\n", MoveData.StartingVcn.QuadPart);
750 wprintf (L"Clusters: %u (%I64u-%I64u --> %I64u-%I64u)\n", MoveData.ClusterCount,
751 Info.Fragments[i].StartLCN,
752 Info.Fragments[i].StartLCN + MoveData.ClusterCount,
753 MoveData.StartingLcn.QuadPart,
754 MoveData.StartingLcn.QuadPart + MoveData.ClusterCount - 1);
755 wprintf (L"\n");
756 */
757
759 (
760 Handle,
762 &MoveData,
763 sizeof (MoveData),
764 NULL,
765 0,
767 NULL
768 );
769
770 //wprintf (L"\b\b\b");
771
772 if (Result == FALSE)
773 {
774 //
775 LPVOID lpMsgBuf;
776
780 (LPTSTR) &lpMsgBuf, 0, NULL );
781
782
783 LocalFree( lpMsgBuf );
784 //
785
786 ReturnVal = false;
787 goto FinishUp; // yeah, bite me
788 }
789
790 // Ok good. Now update our drive bitmap and file infos.
791 uint64 j;
792 for (j = 0;
793 j < Info.Fragments[i].Length;
794 j++)
795 {
796 SetClusterUsed (Info.Fragments[i].StartLCN + j, false);
797 SetClusterUsed (CurrentLCN + j, true);
798 //BitmapDetail[Info.Fragments[i].StartLCN + j].Allocated = false;
799 //BitmapDetail[CurrentLCN + j].Allocated = true;
800 }
801
802 CurrentLCN += Info.Fragments[i].Length;
803 CurrentVCN += Info.Fragments[i].Length;
804 }
805
806 // Update file info either way
807 FinishUp:
810 GetClusterInfo (Files[FileIndice], FileHandle);
812 }
813
814 return (ReturnVal);
815}
FileInfo & GetDBFile(uint32 Indice)
bool GetClusterInfo(FileInfo &Info, HANDLE &HandleResult)
void SetClusterUsed(uint64 Cluster, bool Used)
#define GENERIC_READ
Definition: compat.h:135
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FSCTL_MOVE_FILE
Definition: winioctl.h:745
LARGE_INTEGER StartingLcn
Definition: winioctl.h:777
LARGE_INTEGER StartingVcn
Definition: winioctl.h:776
HANDLE FileHandle
Definition: winioctl.h:775
DWORD ClusterCount
Definition: winioctl.h:778

Referenced by Defragment::Start().

◆ ObtainInfo()

bool DriveVolume::ObtainInfo ( void  )

Definition at line 113 of file DriveVolume.cpp.

114{
115 BOOL Result;
116 DWORD BytesGot;
117 uint64 nan;
118
119 BytesGot = 0;
120 ZeroMemory (&Geometry, sizeof (Geometry));
122 (
123 Handle,
125 NULL,
126 0,
127 &Geometry,
128 sizeof (Geometry),
129 &BytesGot,
130 NULL
131 );
132
133 // Call failed? Aww :(
134 if (!Result)
135 return (false);
136
137 // Get cluster size
138 DWORD SectorsPerCluster;
139 DWORD BytesPerSector;
141 DWORD TotalClusters;
142
144 (
145 RootPath.c_str(),
146 &SectorsPerCluster,
147 &BytesPerSector,
149 &TotalClusters
150 );
151
152 // Failed? Weird.
153 if (!Result)
154 return (false);
155
156 VolInfo.ClusterSize = SectorsPerCluster * BytesPerSector;
157
159 (
160 RootPath.c_str(),
164 );
165
166 return (true);
167}
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
BOOL WINAPI GetDiskFreeSpaceExW(IN LPCWSTR lpDirectoryName OPTIONAL, OUT PULARGE_INTEGER lpFreeBytesAvailableToCaller, OUT PULARGE_INTEGER lpTotalNumberOfBytes, OUT PULARGE_INTEGER lpTotalNumberOfFreeBytes)
Definition: disk.c:342
BOOL WINAPI GetDiskFreeSpaceW(IN LPCWSTR lpRootPathName, OUT LPDWORD lpSectorsPerCluster, OUT LPDWORD lpBytesPerSector, OUT LPDWORD lpNumberOfFreeClusters, OUT LPDWORD lpTotalNumberOfClusters)
Definition: disk.c:173
NTSTATUS FreeClusters(PNTFS_VCB Vcb, PNTFS_ATTR_CONTEXT AttrContext, ULONG AttrOffset, PFILE_RECORD_HEADER FileRecord, ULONG ClustersToFree)
Definition: attrib.c:1057
double __cdecl nan(const char *tagp)

Referenced by Defragment::Start().

◆ Open()

bool DriveVolume::Open ( wstring  Name)

Definition at line 42 of file DriveVolume.cpp.

43{
44 wchar_t FileName[100];
45 bool ReturnVal;
46
47 swprintf (FileName, L"\\\\.\\%s", Name.c_str());
48 RootPath = Name.c_str();
49 RootPath += L"\\";
50
52 (
54 MAXIMUM_ALLOWED, // access
55 FILE_SHARE_READ | FILE_SHARE_WRITE, // share type
56 NULL, // security descriptor
57 OPEN_EXISTING, // open type
58 0, // attributes (none)
59 NULL // template
60 );
61
63 ReturnVal = false;
64 else
65 {
66 wchar_t VolName[64];
67 DWORD VolSN;
68 DWORD VolMaxFileLen;
69 DWORD FSFlags;
70 wchar_t FSName[64];
72
73 ReturnVal = true;
75 (
76 RootPath.c_str(),
77 VolName,
78 sizeof (VolName),
79 &VolSN,
80 &VolMaxFileLen,
81 &FSFlags,
82 FSName,
83 sizeof (FSName)
84 );
85
86 if (Result)
87 {
88 wchar_t SerialText[10];
89
90 VolInfo.FileSystem = FSName;
91 VolInfo.MaxNameLen = VolMaxFileLen;
92 VolInfo.Name = VolName;
93
94 swprintf (SerialText, L"%x-%x", (VolSN & 0xffff0000) >> 16,
95 VolSN & 0x0000ffff);
96
97 _wcsupr (SerialText);
98 VolInfo.Serial = SerialText;
99 }
100 else
101 {
102 VolInfo.FileSystem = L"(Unknown)";
103 VolInfo.MaxNameLen = 255;
104 VolInfo.Name = L"(Unknown)";
105 VolInfo.Serial = L"(Unknown)";
106 }
107 }
108
109 return (ReturnVal);
110}
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
#define swprintf
Definition: precomp.h:40
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
wstring Name
Definition: DriveVolume.h:68
wstring Serial
Definition: DriveVolume.h:69
DWORD MaxNameLen
Definition: DriveVolume.h:70
wstring FileSystem
Definition: DriveVolume.h:71
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

Referenced by Defragment::Defragment().

◆ RemoveDBFile()

uint32 DriveVolume::RemoveDBFile ( uint32  Indice)

Definition at line 369 of file DriveVolume.cpp.

370{
372
373 it = Files.begin() + Indice;
374 Files.erase (it);
375 return (GetDBFileCount());
376}
uint32 GetDBFileCount(void)
value_type * iterator
Definition: _vector.h:124

◆ Scan()

bool DriveVolume::Scan ( ScanCallback  Callback,
void UserData 
)

◆ ScanDirectory()

bool DriveVolume::ScanDirectory ( wstring  DirPrefix,
ScanCallback  Callback,
void UserData 
)
private

Definition at line 379 of file DriveVolume.cpp.

380{
381 WIN32_FIND_DATAW FindData;
382 HANDLE FindHandle;
383 wstring SearchString;
384 uint32 DirIndice;
385
386 DirIndice = Directories.size() - 1;
387
388 SearchString = DirPrefix;
389 SearchString += L"*.*";
390 ZeroMemory (&FindData, sizeof (FindData));
391 FindHandle = FindFirstFileW (SearchString.c_str(), &FindData);
392
393 if (FindHandle == INVALID_HANDLE_VALUE)
394 return (false);
395
396 do
397 {
400 bool CallbackResult;
401
403
404 // First copy over the easy stuff.
405 Info.Name = FindData.cFileName;
406
407 // DonLL't ever include '.L' and '..'
408 if (Info.Name == L"." || Info.Name == L"..")
409 continue;
410
411 //Info.FullName = DirPrefix + Info.Name;
412 Info.Size = (uint64)FindData.nFileSizeLow + ((uint64)FindData.nFileSizeHigh << (uint64)32);
413 Info.DirIndice = DirIndice;
414
415 Info.Attributes.Archive = (FindData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? 1 : 0;
416 Info.Attributes.Compressed = (FindData.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) ? 1 : 0;
417 Info.Attributes.Directory = (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0;
418 Info.Attributes.Encrypted = (FindData.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED) ? 1 : 0;
419 Info.Attributes.Hidden = (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? 1 : 0;
420 Info.Attributes.Normal = (FindData.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) ? 1 : 0;
421 Info.Attributes.Offline = (FindData.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) ? 1 : 0;
422 Info.Attributes.ReadOnly = (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 1 : 0;
423 Info.Attributes.Reparse = (FindData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) ? 1 : 0;
424 Info.Attributes.Sparse = (FindData.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) ? 1 : 0;
425 Info.Attributes.System = (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? 1 : 0;
426 Info.Attributes.Temporary = (FindData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) ? 1 : 0;
427 Info.Attributes.AccessDenied = 0;
428 Info.Attributes.Unmovable = 0;
429 Info.Attributes.Process = 1;
430
431 Info.Clusters = 0;
433 {
434 uint64 TotalClusters = 0;
435
436 for (size_t i = 0; i < Info.Fragments.size(); i++)
437 {
438 TotalClusters += Info.Fragments[i].Length;
439 }
440
441 Info.Clusters = TotalClusters;
442 }
443 else
444 {
445 Info.Attributes.Unmovable = 1;
446 Info.Attributes.Process = 0;
447 }
448
449 if (Info.Attributes.Process == 1)
450 Info.Attributes.Process = ShouldProcess (Info.Attributes) ? 1 : 0;
451
452 // Run the user-defined callback function
453 CallbackResult = Callback (Info, Handle, UserData);
454
457
458 if (!CallbackResult)
459 break;
460
461 // If directory, perform recursion
462 if (Info.Attributes.Directory == 1)
463 {
464 wstring Dir;
465
466 Dir = GetDBDir (Info.DirIndice);
467 Dir += Info.Name;
468 Dir += L"\\";
469
472 }
473
474 } while (FindNextFileW (FindHandle, &FindData) == TRUE);
475
476 FindClose (FindHandle);
477 return (false);
478}
bool ShouldProcess(FileAttr Attr)
#define TRUE
Definition: types.h:120
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_COMPRESSED
Definition: nt_native.h:711
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
#define FILE_ATTRIBUTE_OFFLINE
Definition: nt_native.h:712
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define FILE_ATTRIBUTE_TEMPORARY
Definition: nt_native.h:708
#define FILE_ATTRIBUTE_ENCRYPTED
Definition: ntifs_ex.h:385
#define FILE_ATTRIBUTE_SPARSE_FILE
Definition: ntifs_ex.h:380
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458

Referenced by BuildFileList(), and ScanDirectory().

◆ SetClusterUsed()

void DriveVolume::SetClusterUsed ( uint64  Cluster,
bool  Used 
)

Definition at line 279 of file DriveVolume.cpp.

280{
281 if (Used)
282 BitmapDetail[Cluster / 32] |= (1 << (Cluster % 32));
283 else
284 BitmapDetail[Cluster / 32] &= ~(1 << (Cluster % 32));
285
286 return;
287}

Referenced by MoveFileDumb().

◆ ShouldProcess()

bool DriveVolume::ShouldProcess ( FileAttr  Attr)
private

Definition at line 481 of file DriveVolume.cpp.

482{
483 if (Attr.Offline == 1 || Attr.Reparse == 1 || Attr.Temporary == 1)
484 {
485 return (false);
486 }
487
488 return (true);
489}
unsigned int Reparse
Definition: DriveVolume.h:33
unsigned int Temporary
Definition: DriveVolume.h:36
unsigned int Offline
Definition: DriveVolume.h:31

Referenced by ScanDirectory().

Friends And Related Function Documentation

◆ BuildDBCallback

bool BuildDBCallback ( FileInfo Info,
HANDLE FileHandle,
void UserData 
)
friend

Definition at line 327 of file DriveVolume.cpp.

328{
329 BuildDBInfo *DBInfo = (BuildDBInfo *) UserData;
330 DriveVolume *Vol = DBInfo->Volume;
331
332 Vol->Files.push_back (Info);
333
334 if (*(DBInfo->QuitMonitor) == true)
335 return (false);
336
337 DBInfo->ClusterProgress += (uint64)Info.Clusters;
338 *(DBInfo->Percent) =
339 ((double)DBInfo->ClusterProgress / (double)DBInfo->ClusterCount) * 100.0f;
340
341 return (true);
342}
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
uint64 ClusterProgress
DriveVolume * Volume
double * Percent
bool * QuitMonitor
uint64 ClusterCount

Referenced by BuildFileList().

Member Data Documentation

◆ BitmapDetail

uint32* DriveVolume::BitmapDetail
private

Definition at line 153 of file DriveVolume.h.

Referenced by Close(), DriveVolume(), GetBitmap(), IsClusterUsed(), and SetClusterUsed().

◆ Directories

vector<wstring> DriveVolume::Directories
private

Definition at line 149 of file DriveVolume.h.

Referenced by BuildFileList(), GetDBDir(), GetDBDirCount(), ScanDirectory(), and ~DriveVolume().

◆ Files

FileList DriveVolume::Files
private

◆ Geometry

DISK_GEOMETRY DriveVolume::Geometry
private

Definition at line 152 of file DriveVolume.h.

Referenced by DriveVolume(), GetGeometry(), and ObtainInfo().

◆ Handle

HANDLE DriveVolume::Handle
private

◆ RootPath

wstring DriveVolume::RootPath
private

Definition at line 150 of file DriveVolume.h.

Referenced by BuildFileList(), GetRootPath(), and Open().

◆ VolInfo

VolumeInfo DriveVolume::VolInfo
private

Definition at line 147 of file DriveVolume.h.

Referenced by FindFreeRange(), GetBitmap(), GetVolumeInfo(), and Open().


The documentation for this class was generated from the following files: