ReactOS  0.4.14-dev-77-gd9e7c48
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 {
8  return;
9 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
uint32 * BitmapDetail
Definition: DriveVolume.h:153

◆ ~DriveVolume()

DriveVolume::~DriveVolume ( )

Definition at line 12 of file DriveVolume.cpp.

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

Member Function Documentation

◆ BuildFileList()

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

Definition at line 289 of file DriveVolume.cpp.

290 {
292 
293  Files.clear ();
294  Directories.clear ();
296 
297  Info.Volume = this;
298  Info.QuitMonitor = &QuitMonitor;
300  Info.ClusterProgress = 0;
301  Info.Percent = &Percent;
302 
304 
305  if (QuitMonitor == true)
306  {
307  Directories.resize (0);
308  Files.resize (0);
309  }
310 
311  return (true);
312 }
unsigned long long uint64
Definition: platform.h:18
uint64 FreeBytes
Definition: DriveVolume.h:75
void resize(size_type __new_size, const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:636
struct TraceInfo Info
VolumeInfo GetVolumeInfo(void)
Definition: DriveVolume.h:109
bool ScanDirectory(wstring DirPrefix, ScanCallback Callback, void *UserData)
wstring RootPath
Definition: DriveVolume.h:150
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:376
FileList Files
Definition: DriveVolume.h:148
vector< wstring > Directories
Definition: DriveVolume.h:149
uint64 TotalBytes
Definition: DriveVolume.h:74
friend bool BuildDBCallback(FileInfo &Info, HANDLE &FileHandle, void *UserData)
uint32 ClusterSize
Definition: DriveVolume.h:73
void clear()
Definition: _vector.h:650

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:398
#define free
Definition: debug_ros.c:5
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
uint32 * BitmapDetail
Definition: DriveVolume.h:153

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

◆ FindFreeRange()

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

Definition at line 621 of file DriveVolume.cpp.

622 {
623  uint64 Max;
624  uint64 i;
625  uint64 j;
626 
627  // Make sure we don't spill over our array
628  Max = VolInfo.ClusterCount - ReqLength;
629 
630  for (i = StartLCN; i < Max; i++)
631  {
632  bool Found = true;
633 
634  // First check the first cluster
635  if (IsClusterUsed (i))
636  Found = false;
637  else
638  // THen check the last cluster
639  if (IsClusterUsed (i + ReqLength - 1))
640  Found = false;
641  else
642  // Check the whole darn range.
643  for (j = (i + 1); j < (i + ReqLength - 2); j++)
644  {
645  if (IsClusterUsed (j) == true)
646  {
647  Found = false;
648  break;
649  }
650  }
651 
652  if (!Found)
653  continue;
654  else
655  {
656  LCNResult = i;
657  return (true);
658  }
659  }
660 
661  return (false);
662 }
unsigned long long uint64
Definition: platform.h:18
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
#define Max(a, b)
Definition: cdprocs.h:70
VolumeInfo VolInfo
Definition: DriveVolume.h:147
return Found
Definition: dirsup.c:1270
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
bool IsClusterUsed(uint64 Cluster)

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;
188  Bitmap = (VOLUME_BITMAP_BUFFER *) malloc (BitmapSize);
189 
191  (
192  Handle,
194  &StartingLCN,
195  sizeof (StartingLCN),
196  Bitmap,
197  BitmapSize,
198  &BytesReturned,
199  NULL
200  );
201 
202  // Bad result?
203  if (Result == FALSE && GetLastError () != ERROR_MORE_DATA)
204  {
205  //wprintf ("\nDeviceIoControl returned false, GetLastError() was not ERROR_MORE_DATA\n");
206  free (Bitmap);
207  return (false);
208  }
209 
210  // Otherwise, we're good
211  BitmapSize = sizeof (VOLUME_BITMAP_BUFFER) + (Bitmap->BitmapSize.QuadPart / 8) + 1;
212  Bitmap = (VOLUME_BITMAP_BUFFER *) realloc (Bitmap, BitmapSize);
214  (
215  Handle,
217  &StartingLCN,
218  sizeof (StartingLCN),
219  Bitmap,
220  BitmapSize,
221  &BytesReturned,
222  NULL
223  );
224 
225  //DWORD LastError = GetLastError ();
226 
227  if (Result == FALSE)
228  {
229  wprintf (L"\nCouldn't properly read volume bitmap\n");
230  free (Bitmap);
231  return (false);
232  }
233 
234  // Convert to a L'quick use' bitmap
235  //const int BitShift[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
236 
237  VolInfo.ClusterCount = Bitmap->BitmapSize.QuadPart;
238 
239  if (BitmapDetail != NULL)
240  free (BitmapDetail);
241 
242  BitmapDetail = (uint32 *) malloc (sizeof(uint32) * (1 + (VolInfo.ClusterCount / 32)));
243  memcpy (BitmapDetail, Bitmap->Buffer, sizeof(uint32) * (1 + (VolInfo.ClusterCount / 32)));
244 
245  /*
246  BitmapDetail = (Cluster *) malloc (VolInfo.ClusterCount * sizeof (Cluster));
247  for (uint64 i = 0; i < VolInfo.ClusterCount; i++)
248  {
249  if (Bitmap->Buffer[i / 8] & BitShift[i % 8])
250  BitmapDetail[i].Allocated = true;
251  else
252  BitmapDetail[i].Allocated = false;
253  }
254  */
255 
256  free (Bitmap);
257  return (true);
258 }
#define realloc
Definition: debug_ros.c:6
unsigned int uint32
Definition: types.h:32
#define free
Definition: debug_ros.c:5
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define wprintf(...)
Definition: whoami.c:18
LARGE_INTEGER StartingLcn
Definition: winioctl.h:542
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
VolumeInfo VolInfo
Definition: DriveVolume.h:147
_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:426
_In_ HANDLE Handle
Definition: extypes.h:390
uint32 * BitmapDetail
Definition: DriveVolume.h:153
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint64 ClusterCount
Definition: DriveVolume.h:72
#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 FSCTL_GET_VOLUME_BITMAP
Definition: winioctl.h:94
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
#define malloc
Definition: debug_ros.c:4
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by Defragment::Start().

◆ GetClusterInfo()

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

Definition at line 484 of file DriveVolume.cpp.

485 {
486  BOOL Result;
487  HANDLE Handle;
488  wstring FullName;
490 
491  Info.Fragments.resize (0);
492 
493  /*
494  if (Info.Attributes.Directory == 1)
495  return (false);
496  */
497 
498  FullName = GetDBDir (Info.DirIndice) + Info.Name;
499 
501  (
502  FullName.c_str(),
503  0, //GENERIC_READ,
505  NULL,
507  (Info.Attributes.Directory == 1) ? FILE_FLAG_BACKUP_SEMANTICS : 0,
508  NULL
509  );
510 
512  {
513  LPVOID lpMsgBuf;
514 
516  NULL, GetLastError(),
518  (LPTSTR) &lpMsgBuf, 0, NULL );
519 
520 
521  Info.Attributes.AccessDenied = 1;
522  LocalFree( lpMsgBuf );
523  return (false);
524  }
525 
526  ZeroMemory (&FileInfo, sizeof (FileInfo));
528 
529  if (Result == FALSE)
530  {
531  Info.Attributes.AccessDenied = 1;
532  wprintf (L"GetFileInformationByHandle ('%s%s') failed\n", GetDBDir (Info.DirIndice).c_str(),
533  Info.Name.c_str());
534 
536  return (false);
537  }
538 
539  // Get cluster allocation information
540  STARTING_VCN_INPUT_BUFFER StartingVCN;
541  RETRIEVAL_POINTERS_BUFFER *Retrieval;
542  uint64 RetSize;
543  uint64 Extents;
545 
546  // Grab info one extent at a time, until it's done grabbing all the extent data
547  // Yeah, well it doesn't give us a way to ask L"how many extents?" that I know of ...
548  // btw, the Extents variable tends to only reflect memory usage, so when we have
549  // all the extents we look at the structure Win32 gives us for the REAL count!
550  Extents = 10;
551  Retrieval = NULL;
552  RetSize = 0;
553  StartingVCN.StartingVcn.QuadPart = 0;
554 
555  do
556  {
557  Extents *= 2;
558  RetSize = sizeof (RETRIEVAL_POINTERS_BUFFER) + ((Extents - 1) * sizeof (LARGE_INTEGER) * 2);
559 
560  if (Retrieval != NULL)
561  Retrieval = (RETRIEVAL_POINTERS_BUFFER *) realloc (Retrieval, RetSize);
562  else
563  Retrieval = (RETRIEVAL_POINTERS_BUFFER *) malloc (RetSize);
564 
566  (
567  Handle,
569  &StartingVCN,
570  sizeof (StartingVCN),
571  Retrieval,
572  RetSize,
573  &BytesReturned,
574  NULL
575  );
576 
577  if (Result == FALSE)
578  {
579  if (GetLastError() != ERROR_MORE_DATA)
580  {
581  Info.Clusters = 0;
582  Info.Attributes.AccessDenied = 1;
583  Info.Attributes.Process = 0;
584  Info.Fragments.clear ();
586  free (Retrieval);
587 
588  return (false);
589  }
590 
591  Extents++;
592  }
593  } while (Result == FALSE);
594 
595  // Readjust extents, as it only reflects how much memory was allocated and may not
596  // be accurate
597  Extents = Retrieval->ExtentCount;
598 
599  // Ok, we have the info. Now translate it. hrmrmr
600 
601  Info.Fragments.clear ();
602  for (uint64 i = 0; i < Extents; i++)
603  {
604  Extent Add;
605 
606  Add.StartLCN = Retrieval->Extents[i].Lcn.QuadPart;
607  if (i != 0)
608  Add.Length = Retrieval->Extents[i].NextVcn.QuadPart - Retrieval->Extents[i - 1].NextVcn.QuadPart;
609  else
610  Add.Length = Retrieval->Extents[i].NextVcn.QuadPart - Retrieval->StartingVcn.QuadPart;
611 
612  Info.Fragments.push_back (Add);
613  }
614 
615  free (Retrieval);
616  HandleResult = Handle;
617  return (true);
618 }
#define realloc
Definition: debug_ros.c:6
unsigned long long uint64
Definition: platform.h:18
#define CloseHandle
Definition: compat.h:398
#define LANG_NEUTRAL
Definition: nls.h:22
#define free
Definition: debug_ros.c:5
#define SUBLANG_DEFAULT
Definition: nls.h:168
uint64 Length
Definition: DriveVolume.h:48
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
struct RETRIEVAL_POINTERS_BUFFER::@3209 Extents[1]
LARGE_INTEGER StartingVcn
Definition: winioctl.h:545
#define wprintf(...)
Definition: whoami.c:18
CHAR * LPTSTR
Definition: xmlstorage.h:192
struct TraceInfo Info
#define FILE_SHARE_READ
Definition: compat.h:125
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
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
LARGE_INTEGER StartingVcn
Definition: winioctl.h:527
smooth NULL
Definition: ftsmooth.c:416
_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:426
HANDLE Handle
Definition: DriveVolume.h:151
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define OPEN_EXISTING
Definition: compat.h:426
_In_ HANDLE Handle
Definition: extypes.h:390
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:608
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PSTRING FullName
Definition: rtlfuncs.h:1649
#define FormatMessage
Definition: winbase.h:3612
union _LARGE_INTEGER LARGE_INTEGER
static const WCHAR L[]
Definition: oid.c:1250
#define FSCTL_GET_RETRIEVAL_POINTERS
Definition: winioctl.h:95
#define ERROR_MORE_DATA
Definition: dderror.h:13
struct RETRIEVAL_POINTERS_BUFFER RETRIEVAL_POINTERS_BUFFER
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
#define CreateFileW
Definition: compat.h:400
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
struct FileInfo FileInfo
#define MAKELANGID(p, s)
Definition: nls.h:15
#define malloc
Definition: debug_ros.c:4
wstring & GetDBDir(uint32 Indice)
uint64 StartLCN
Definition: DriveVolume.h:47
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by MoveFileDumb(), and ScanDirectory().

◆ GetDBDir()

wstring & DriveVolume::GetDBDir ( uint32  Indice)

Definition at line 334 of file DriveVolume.cpp.

335 {
336  return (Directories[Indice]);
337 }
vector< wstring > Directories
Definition: DriveVolume.h:149

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

◆ GetDBDirCount()

uint32 DriveVolume::GetDBDirCount ( void  )

Definition at line 340 of file DriveVolume.cpp.

341 {
342  return (Directories.size());
343 }
vector< wstring > Directories
Definition: DriveVolume.h:149
size_type size() const
Definition: _vector.h:192

Referenced by Defragment::Start().

◆ GetDBFile()

FileInfo & DriveVolume::GetDBFile ( uint32  Indice)

Definition at line 346 of file DriveVolume.cpp.

347 {
348  return (Files[Indice]);
349 }
FileList Files
Definition: DriveVolume.h:148

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

◆ GetDBFileCount()

uint32 DriveVolume::GetDBFileCount ( void  )

Definition at line 352 of file DriveVolume.cpp.

353 {
354  return (Files.size());
355 }
FileList Files
Definition: DriveVolume.h:148

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

◆ GetGeometry()

DISK_GEOMETRY DriveVolume::GetGeometry ( void  )
inline

Definition at line 108 of file DriveVolume.h.

108 { return (Geometry); }
DISK_GEOMETRY Geometry
Definition: DriveVolume.h:152

◆ GetRootPath()

wstring DriveVolume::GetRootPath ( void  )
inline

Definition at line 111 of file DriveVolume.h.

111 { return (RootPath); }
wstring RootPath
Definition: DriveVolume.h:150

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

◆ GetVolumeInfo()

VolumeInfo DriveVolume::GetVolumeInfo ( void  )
inline

Definition at line 109 of file DriveVolume.h.

109 { return (VolInfo); }
VolumeInfo VolInfo
Definition: DriveVolume.h:147

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

◆ IsClusterUsed()

bool DriveVolume::IsClusterUsed ( uint64  Cluster)

Definition at line 261 of file DriveVolume.cpp.

262 {
263  return ((BitmapDetail[Cluster / 32] & (1 << (Cluster % 32))) ? true : false);
264  //return (BitmapDetail[Cluster].Allocated);
265 }
uint32 * BitmapDetail
Definition: DriveVolume.h:153

Referenced by FindFreeRange().

◆ MoveFileDumb()

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

Definition at line 666 of file DriveVolume.cpp.

667 {
668  bool ReturnVal = false;
669  FileInfo Info;
671  wstring FullName;
672  MOVE_FILE_DATA MoveData;
673  uint64 CurrentLCN;
674  uint64 CurrentVCN;
675 
676  // Set up variables
677  Info = GetDBFile (FileIndice);
678  FullName = GetDBDir (Info.DirIndice);
679  FullName += Info.Name;
680  CurrentLCN = NewLCN;
681  CurrentVCN = 0;
682 
683  /*
684  if (Info.Attributes.Directory == 1)
685  {
686  //
687  }
688  */
689 
690  // Open file
692  (
693  FullName.c_str (),
694  GENERIC_READ,
696  NULL,
698  (Info.Attributes.Directory == 1) ? FILE_FLAG_BACKUP_SEMANTICS : 0,
699  NULL
700  );
701 
703  {
704  //
705  LPVOID lpMsgBuf;
706 
708  NULL, GetLastError(),
710  (LPTSTR) &lpMsgBuf, 0, NULL );
711 
712 
713  LocalFree (lpMsgBuf);
714  //
715 
716  ReturnVal = false;
717  }
718  else
719  {
720  ReturnVal = true; // innocent until proven guilty ...
721 
722  for (uint32 i = 0; i < Info.Fragments.size(); i++)
723  {
724  BOOL Result;
726 
727  //wprintf (L"%3u", i);
728 
729  MoveData.ClusterCount = Info.Fragments[i].Length;
730  MoveData.StartingLcn.QuadPart = CurrentLCN;
731  MoveData.StartingVcn.QuadPart = CurrentVCN;
732 
733  MoveData.FileHandle = FileHandle;
734 
735  /*
736  wprintf (L"\n");
737  wprintf (L"StartLCN: %I64u\n", MoveData.StartingLcn.QuadPart);
738  wprintf (L"StartVCN: %I64u\n", MoveData.StartingVcn.QuadPart);
739  wprintf (L"Clusters: %u (%I64u-%I64u --> %I64u-%I64u)\n", MoveData.ClusterCount,
740  Info.Fragments[i].StartLCN,
741  Info.Fragments[i].StartLCN + MoveData.ClusterCount,
742  MoveData.StartingLcn.QuadPart,
743  MoveData.StartingLcn.QuadPart + MoveData.ClusterCount - 1);
744  wprintf (L"\n");
745  */
746 
748  (
749  Handle,
751  &MoveData,
752  sizeof (MoveData),
753  NULL,
754  0,
755  &BytesReturned,
756  NULL
757  );
758 
759  //wprintf (L"\b\b\b");
760 
761  if (Result == FALSE)
762  {
763  //
764  LPVOID lpMsgBuf;
765 
767  NULL, GetLastError(),
769  (LPTSTR) &lpMsgBuf, 0, NULL );
770 
771 
772  LocalFree( lpMsgBuf );
773  //
774 
775  ReturnVal = false;
776  goto FinishUp; // yeah, bite me
777  }
778 
779  // Ok good. Now update our drive bitmap and file infos.
780  uint64 j;
781  for (j = 0;
782  j < Info.Fragments[i].Length;
783  j++)
784  {
785  SetClusterUsed (Info.Fragments[i].StartLCN + j, false);
786  SetClusterUsed (CurrentLCN + j, true);
787  //BitmapDetail[Info.Fragments[i].StartLCN + j].Allocated = false;
788  //BitmapDetail[CurrentLCN + j].Allocated = true;
789  }
790 
791  CurrentLCN += Info.Fragments[i].Length;
792  CurrentVCN += Info.Fragments[i].Length;
793  }
794 
795  // Update file info either way
796  FinishUp:
799  GetClusterInfo (Files[FileIndice], FileHandle);
801  }
802 
803  return (ReturnVal);
804 }
unsigned long long uint64
Definition: platform.h:18
#define CloseHandle
Definition: compat.h:398
#define LANG_NEUTRAL
Definition: nls.h:22
unsigned int uint32
Definition: types.h:32
#define SUBLANG_DEFAULT
Definition: nls.h:168
HANDLE FileHandle
Definition: winioctl.h:508
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
FileInfo & GetDBFile(uint32 Indice)
CHAR * LPTSTR
Definition: xmlstorage.h:192
struct TraceInfo Info
#define FILE_SHARE_READ
Definition: compat.h:125
HANDLE FileHandle
Definition: stats.c:38
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
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD ClusterCount
Definition: winioctl.h:511
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
LARGE_INTEGER StartingVcn
Definition: winioctl.h:509
bool GetClusterInfo(FileInfo &Info, HANDLE &HandleResult)
smooth NULL
Definition: ftsmooth.c:416
_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:426
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define OPEN_EXISTING
Definition: compat.h:426
void SetClusterUsed(uint64 Cluster, bool Used)
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
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PSTRING FullName
Definition: rtlfuncs.h:1649
FileList Files
Definition: DriveVolume.h:148
#define FormatMessage
Definition: winbase.h:3612
#define GENERIC_READ
Definition: compat.h:124
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
#define CreateFileW
Definition: compat.h:400
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FSCTL_MOVE_FILE
Definition: winioctl.h:96
#define MAKELANGID(p, s)
Definition: nls.h:15
wstring & GetDBDir(uint32 Indice)
LARGE_INTEGER StartingLcn
Definition: winioctl.h:510
LONGLONG QuadPart
Definition: typedefs.h:112

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,
148  &FreeClusters,
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 }
unsigned long long uint64
Definition: platform.h:18
uint64 FreeBytes
Definition: DriveVolume.h:75
NTSTATUS FreeClusters(PNTFS_VCB Vcb, PNTFS_ATTR_CONTEXT AttrContext, ULONG AttrOffset, PFILE_RECORD_HEADER FileRecord, ULONG ClustersToFree)
Definition: attrib.c:1057
#define ZeroMemory
Definition: winbase.h:1635
double __cdecl nan(const char *tagp)
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
VolumeInfo VolInfo
Definition: DriveVolume.h:147
_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:426
struct _ULARGE_INTEGER * PULARGE_INTEGER
Definition: drive.c:28
wstring RootPath
Definition: DriveVolume.h:150
_In_ HANDLE Handle
Definition: extypes.h:390
BOOL WINAPI GetDiskFreeSpaceW(IN LPCWSTR lpRootPathName, OUT LPDWORD lpSectorsPerCluster, OUT LPDWORD lpBytesPerSector, OUT LPDWORD lpNumberOfFreeClusters, OUT LPDWORD lpTotalNumberOfClusters)
Definition: disk.c:173
unsigned long DWORD
Definition: ntddk_ex.h:95
DISK_GEOMETRY Geometry
Definition: DriveVolume.h:152
uint64 TotalBytes
Definition: DriveVolume.h:74
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
uint32 ClusterSize
Definition: DriveVolume.h:73
#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

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  (
53  FileName,
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];
71  BOOL Result;
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 }
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
DWORD MaxNameLen
Definition: DriveVolume.h:70
wstring Serial
Definition: DriveVolume.h:69
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
VolumeInfo VolInfo
Definition: DriveVolume.h:147
_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:426
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
wstring RootPath
Definition: DriveVolume.h:150
#define OPEN_EXISTING
Definition: compat.h:426
_In_ HANDLE Handle
Definition: extypes.h:390
wstring Name
Definition: DriveVolume.h:68
#define swprintf(buf, format,...)
Definition: sprintf.c:56
unsigned long DWORD
Definition: ntddk_ex.h:95
wstring FileSystem
Definition: DriveVolume.h:71
static const WCHAR L[]
Definition: oid.c:1250
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 CreateFileW
Definition: compat.h:400

Referenced by Defragment::Defragment().

◆ RemoveDBFile()

uint32 DriveVolume::RemoveDBFile ( uint32  Indice)

Definition at line 358 of file DriveVolume.cpp.

359 {
360  vector<FileInfo>::iterator it;
361 
362  it = Files.begin() + Indice;
363  Files.erase (it);
364  return (GetDBFileCount());
365 }
uint32 GetDBFileCount(void)
FileList Files
Definition: DriveVolume.h:148

◆ Scan()

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

◆ ScanDirectory()

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

Definition at line 368 of file DriveVolume.cpp.

369 {
370  WIN32_FIND_DATAW FindData;
371  HANDLE FindHandle;
372  wstring SearchString;
373  uint32 DirIndice;
374 
375  DirIndice = Directories.size() - 1;
376 
377  SearchString = DirPrefix;
378  SearchString += L"*.*";
379  ZeroMemory (&FindData, sizeof (FindData));
380  FindHandle = FindFirstFileW (SearchString.c_str(), &FindData);
381 
382  if (FindHandle == INVALID_HANDLE_VALUE)
383  return (false);
384 
385  do
386  {
387  FileInfo Info;
388  HANDLE Handle;
389  bool CallbackResult;
390 
392 
393  // First copy over the easy stuff.
394  Info.Name = FindData.cFileName;
395 
396  // DonLL't ever include '.L' and '..'
397  if (Info.Name == L"." || Info.Name == L"..")
398  continue;
399 
400  //Info.FullName = DirPrefix + Info.Name;
401  Info.Size = (uint64)FindData.nFileSizeLow + ((uint64)FindData.nFileSizeHigh << (uint64)32);
402  Info.DirIndice = DirIndice;
403 
404  Info.Attributes.Archive = (FindData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? 1 : 0;
405  Info.Attributes.Compressed = (FindData.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) ? 1 : 0;
406  Info.Attributes.Directory = (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0;
407  Info.Attributes.Encrypted = (FindData.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED) ? 1 : 0;
408  Info.Attributes.Hidden = (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? 1 : 0;
409  Info.Attributes.Normal = (FindData.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) ? 1 : 0;
410  Info.Attributes.Offline = (FindData.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) ? 1 : 0;
411  Info.Attributes.ReadOnly = (FindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 1 : 0;
412  Info.Attributes.Reparse = (FindData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) ? 1 : 0;
413  Info.Attributes.Sparse = (FindData.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) ? 1 : 0;
414  Info.Attributes.System = (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? 1 : 0;
415  Info.Attributes.Temporary = (FindData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) ? 1 : 0;
416  Info.Attributes.AccessDenied = 0;
417  Info.Attributes.Unmovable = 0;
418  Info.Attributes.Process = 1;
419 
420  Info.Clusters = 0;
421  if (GetClusterInfo (Info, Handle))
422  {
423  uint64 TotalClusters = 0;
424 
425  for (size_t i = 0; i < Info.Fragments.size(); i++)
426  {
427  TotalClusters += Info.Fragments[i].Length;
428  }
429 
430  Info.Clusters = TotalClusters;
431  }
432  else
433  {
434  Info.Attributes.Unmovable = 1;
435  Info.Attributes.Process = 0;
436  }
437 
438  if (Info.Attributes.Process == 1)
439  Info.Attributes.Process = ShouldProcess (Info.Attributes) ? 1 : 0;
440 
441  // Run the user-defined callback function
442  CallbackResult = Callback (Info, Handle, UserData);
443 
446 
447  if (!CallbackResult)
448  break;
449 
450  // If directory, perform recursion
451  if (Info.Attributes.Directory == 1)
452  {
453  wstring Dir;
454 
455  Dir = GetDBDir (Info.DirIndice);
456  Dir += Info.Name;
457  Dir += L"\\";
458 
459  Directories.push_back (Dir);
461  }
462 
463  } while (FindNextFileW (FindHandle, &FindData) == TRUE);
464 
465  FindClose (FindHandle);
466  return (false);
467 }
unsigned long long uint64
Definition: platform.h:18
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define FILE_ATTRIBUTE_TEMPORARY
Definition: nt_native.h:708
#define FILE_ATTRIBUTE_SPARSE_FILE
Definition: ntifs_ex.h:380
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
unsigned int uint32
Definition: types.h:32
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define ZeroMemory
Definition: winbase.h:1635
struct TraceInfo Info
bool ShouldProcess(FileAttr Attr)
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
bool GetClusterInfo(FileInfo &Info, HANDLE &HandleResult)
bool ScanDirectory(wstring DirPrefix, ScanCallback Callback, void *UserData)
HANDLE Handle
Definition: DriveVolume.h:151
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
_In_ HANDLE Handle
Definition: extypes.h:390
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:376
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_COMPRESSED
Definition: nt_native.h:711
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
vector< wstring > Directories
Definition: DriveVolume.h:149
static const WCHAR L[]
Definition: oid.c:1250
#define FILE_ATTRIBUTE_ENCRYPTED
Definition: ntifs_ex.h:385
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
size_type size() const
Definition: _vector.h:192
LPFNPSPCALLBACK Callback
Definition: desk.c:111
wstring & GetDBDir(uint32 Indice)
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
#define FILE_ATTRIBUTE_OFFLINE
Definition: nt_native.h:712
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by BuildFileList().

◆ SetClusterUsed()

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

Definition at line 268 of file DriveVolume.cpp.

269 {
270  if (Used)
271  BitmapDetail[Cluster / 32] |= (1 << (Cluster % 32));
272  else
273  BitmapDetail[Cluster / 32] &= ~(1 << (Cluster % 32));
274 
275  return;
276 }
uint32 * BitmapDetail
Definition: DriveVolume.h:153

Referenced by MoveFileDumb().

◆ ShouldProcess()

bool DriveVolume::ShouldProcess ( FileAttr  Attr)
private

Definition at line 470 of file DriveVolume.cpp.

471 {
472  if (Attr.Offline == 1 || Attr.Reparse == 1 || Attr.Temporary == 1)
473  {
474  return (false);
475  }
476 
477  return (true);
478 }
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 316 of file DriveVolume.cpp.

317 {
318  BuildDBInfo *DBInfo = (BuildDBInfo *) UserData;
319  DriveVolume *Vol = DBInfo->Volume;
320 
321  Vol->Files.push_back (Info);
322 
323  if (*(DBInfo->QuitMonitor) == true)
324  return (false);
325 
326  DBInfo->ClusterProgress += (uint64)Info.Clusters;
327  *(DBInfo->Percent) =
328  ((double)DBInfo->ClusterProgress / (double)DBInfo->ClusterCount) * 100.0f;
329 
330  return (true);
331 }
unsigned long long uint64
Definition: platform.h:18
struct TraceInfo Info
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
GLfloat f
Definition: glext.h:7540
DriveVolume * Volume
uint64 ClusterProgress
FileList Files
Definition: DriveVolume.h:148
double * Percent
uint64 ClusterCount
bool * QuitMonitor

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 ObtainInfo().

◆ Handle

HANDLE DriveVolume::Handle
private

Definition at line 151 of file DriveVolume.h.

Referenced by GetClusterInfo(), and ScanDirectory().

◆ RootPath

wstring DriveVolume::RootPath
private

Definition at line 150 of file DriveVolume.h.

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

◆ VolInfo

VolumeInfo DriveVolume::VolInfo
private

Definition at line 147 of file DriveVolume.h.

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


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