ReactOS 0.4.15-dev-7788-g1ad9096
DriveVolume.h
Go to the documentation of this file.
1/*****************************************************************************
2
3 DriveVolume
4
5 Class for opening a volume and getting information on it and defragging it
6 and stuff.
7
8*****************************************************************************/
9
10
11#ifndef DRIVEVOLUME_H
12#define DRIVEVOLUME_H
13
14
15#include "Unfrag.h"
16#include <vector>
17#include <string>
18
19
20using namespace std;
21
22#pragma pack (push, 1)
23typedef struct
24{
25 unsigned int Archive : 1;
26 unsigned int Compressed : 1;
27 unsigned int Directory : 1;
28 unsigned int Encrypted : 1;
29 unsigned int Hidden : 1;
30 unsigned int Normal : 1;
31 unsigned int Offline : 1;
32 unsigned int ReadOnly : 1;
33 unsigned int Reparse : 1;
34 unsigned int Sparse : 1;
35 unsigned int System : 1;
36 unsigned int Temporary : 1;
37
38 // For defragmenting purposes and other information
39 unsigned int Unmovable : 1; // can we even touch it?
40 unsigned int Process : 1; // should we process it?
41 unsigned int AccessDenied : 1; // could we not open it?
42} FileAttr;
43
44
45typedef struct
46{
49} Extent;
50
51
52typedef struct
53{
54 wstring Name;
55 uint32 DirIndice; // indice into directory list
59 vector<Extent> Fragments;
60} FileInfo;
61
62
64
65
66typedef struct
67{
68 wstring Name;
69 wstring Serial;
71 wstring FileSystem;
77#pragma pack (pop)
78
79
80// Callback function for Scan()
81// NOTE: Do *NOT* close the HANDLE given to you. It is provided for convenience,
82// and is closed automatically by the function that calls you!
84
85
87
88
90{
91public:
92 DriveVolume ();
93 ~DriveVolume ();
94
95 bool Open (wstring Name); // opens the volume
96 void Close (void);
97 bool ObtainInfo (void); // retrieves drive geometry
98 bool GetBitmap (void); // gets drive bitmap
99
100 // builds list of files on drive
101 // if QuitMonitor ever becomes true (ie from a separate thread) it will clean up and return
102 bool BuildFileList (bool &QuitMonitor, double &Progress);
103
104 // Functions for accessing the volume bitmap
105 bool IsClusterUsed (uint64 Cluster);
106 void SetClusterUsed (uint64 Cluster, bool Used);
107
108 DISK_GEOMETRY GetGeometry (void) { return (Geometry); }
109 VolumeInfo GetVolumeInfo (void) { return (VolInfo); }
110
111 wstring GetRootPath (void) { return (RootPath); }
112
113 // Scans drive starting from the root dir and calls a user defined function
114 // for each file/directory encountered. void* UserData is passed to this
115 // function so you can give it some good ol' fashioned context.
117
118 // Retrieve a directory string from the file database
119 wstring &GetDBDir (uint32 Indice);
120 uint32 GetDBDirCount (void);
121 // Retrieve file strings/info from the file database
122 FileInfo &GetDBFile (uint32 Indice);
123 uint32 GetDBFileCount (void);
124 // Kill it!
125 uint32 RemoveDBFile (uint32 Indice);
126
127 // This is for actual defragmenting! It will automatically update the drive bitmap.
128 // Will not move any other files out of the way.
129 // Failure (return value of false) means that something is in the way.
130 bool MoveFileDumb (uint32 FileIndice, uint64 NewLCN);
131
132 // Look for a range of sequential free clusters
133 // Returns true if one could be found, false if not
134 bool FindFreeRange (uint64 StartLCN, uint64 ReqLength, uint64 &LCNResult);
135
136private:
137 friend bool BuildDBCallback (FileInfo &Info, HANDLE &FileHandle, void *UserData);
138
139 // DirPrefix should be in the form "drive:\\path\\" ie, C:\CRAP\ .
140 bool ScanDirectory (wstring DirPrefix, ScanCallback Callback, void *UserData);
141
142 // given a file's attributes, should it be processed or not?
143 bool ShouldProcess (FileAttr Attr);
144
145 bool GetClusterInfo (FileInfo &Info, HANDLE &HandleResult);
146
149 vector<wstring> Directories; // Directories[Files[x].DirIndice]
150 wstring RootPath; // ie, C:\ .
154};
155
156
157#endif // DRIVEVOLUME_H
bool BuildDBCallback(FileInfo &Info, HANDLE &FileHandle, void *UserData)
vector< FileInfo > FileList
Definition: DriveVolume.h:63
bool(* ScanCallback)(FileInfo &Info, HANDLE &FileHandle, void *UserData)
Definition: DriveVolume.h:83
unsigned int uint32
Definition: types.h:32
DISK_GEOMETRY Geometry
Definition: DriveVolume.h:152
wstring RootPath
Definition: DriveVolume.h:150
FileInfo & GetDBFile(uint32 Indice)
FileList Files
Definition: DriveVolume.h:148
void Close(void)
Definition: DriveVolume.cpp:21
bool ScanDirectory(wstring DirPrefix, ScanCallback Callback, void *UserData)
VolumeInfo VolInfo
Definition: DriveVolume.h:147
DISK_GEOMETRY GetGeometry(void)
Definition: DriveVolume.h:108
bool IsClusterUsed(uint64 Cluster)
bool ShouldProcess(FileAttr Attr)
vector< wstring > Directories
Definition: DriveVolume.h:149
VolumeInfo GetVolumeInfo(void)
Definition: DriveVolume.h:109
uint32 GetDBFileCount(void)
wstring & GetDBDir(uint32 Indice)
bool BuildFileList(bool &QuitMonitor, double &Progress)
friend bool BuildDBCallback(FileInfo &Info, HANDLE &FileHandle, void *UserData)
bool GetClusterInfo(FileInfo &Info, HANDLE &HandleResult)
HANDLE Handle
Definition: DriveVolume.h:151
uint32 * BitmapDetail
Definition: DriveVolume.h:153
bool GetBitmap(void)
uint32 GetDBDirCount(void)
bool MoveFileDumb(uint32 FileIndice, uint64 NewLCN)
bool FindFreeRange(uint64 StartLCN, uint64 ReqLength, uint64 &LCNResult)
bool Scan(ScanCallback Callback, void *UserData)
uint32 RemoveDBFile(uint32 Indice)
bool ObtainInfo(void)
void SetClusterUsed(uint64 Cluster, bool Used)
wstring GetRootPath(void)
Definition: DriveVolume.h:111
unsigned long long uint64
Definition: platform.h:18
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define Open
Definition: syshdrs.h:62
struct tagUserData UserData
Definition: features.h:417
#define bool
Definition: nsiface.idl:72
uint64 StartLCN
Definition: DriveVolume.h:47
uint64 Length
Definition: DriveVolume.h:48
unsigned int AccessDenied
Definition: DriveVolume.h:41
unsigned int Compressed
Definition: DriveVolume.h:26
unsigned int Reparse
Definition: DriveVolume.h:33
unsigned int Archive
Definition: DriveVolume.h:25
unsigned int Directory
Definition: DriveVolume.h:27
unsigned int Sparse
Definition: DriveVolume.h:34
unsigned int Hidden
Definition: DriveVolume.h:29
unsigned int System
Definition: DriveVolume.h:35
unsigned int ReadOnly
Definition: DriveVolume.h:32
unsigned int Process
Definition: DriveVolume.h:40
unsigned int Encrypted
Definition: DriveVolume.h:28
unsigned int Normal
Definition: DriveVolume.h:30
unsigned int Temporary
Definition: DriveVolume.h:36
unsigned int Offline
Definition: DriveVolume.h:31
unsigned int Unmovable
Definition: DriveVolume.h:39
vector< Extent > Fragments
Definition: DriveVolume.h:59
FileAttr Attributes
Definition: DriveVolume.h:58
uint32 DirIndice
Definition: DriveVolume.h:55
uint64 Clusters
Definition: DriveVolume.h:57
uint64 Size
Definition: DriveVolume.h:56
wstring Name
Definition: DriveVolume.h:54
wstring Name
Definition: DriveVolume.h:68
wstring Serial
Definition: DriveVolume.h:69
DWORD MaxNameLen
Definition: DriveVolume.h:70
uint64 TotalBytes
Definition: DriveVolume.h:74
uint64 ClusterCount
Definition: DriveVolume.h:72
uint64 FreeBytes
Definition: DriveVolume.h:75
wstring FileSystem
Definition: DriveVolume.h:71
uint32 ClusterSize
Definition: DriveVolume.h:73
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458