ReactOS  0.4.13-dev-100-gc8611ae
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 
20 using namespace std;
21 
22 #pragma pack (push, 1)
23 typedef 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 
45 typedef struct
46 {
49 } Extent;
50 
51 
52 typedef struct
53 {
54  wstring Name;
55  uint32 DirIndice; // indice into directory list
60 } FileInfo;
61 
62 
63 typedef vector<FileInfo> FileList;
64 
65 
66 typedef struct
67 {
68  wstring Name;
69  wstring Serial;
71  wstring FileSystem;
76 } VolumeInfo;
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 
86 extern bool BuildDBCallback (FileInfo &Info, HANDLE &FileHandle, void *UserData);
87 
88 
90 {
91 public:
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.
116  bool Scan (ScanCallback Callback, void *UserData);
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 
136 private:
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
unsigned long long uint64
Definition: platform.h:18
DWORD MaxNameLen
Definition: DriveVolume.h:70
unsigned int AccessDenied
Definition: DriveVolume.h:41
unsigned int Sparse
Definition: DriveVolume.h:34
unsigned int Reparse
Definition: DriveVolume.h:33
uint64 FreeBytes
Definition: DriveVolume.h:75
vector< Extent > Fragments
Definition: DriveVolume.h:59
unsigned int uint32
Definition: types.h:32
unsigned int Compressed
Definition: DriveVolume.h:26
vector< FileInfo > FileList
Definition: DriveVolume.h:63
wstring Serial
Definition: DriveVolume.h:69
unsigned int Directory
Definition: DriveVolume.h:27
unsigned int Normal
Definition: DriveVolume.h:30
uint64 Length
Definition: DriveVolume.h:48
unsigned int Temporary
Definition: DriveVolume.h:36
Definition: features.h:417
struct TraceInfo Info
#define Open
Definition: syshdrs.h:62
VolumeInfo GetVolumeInfo(void)
Definition: DriveVolume.h:109
unsigned int Archive
Definition: DriveVolume.h:25
HANDLE FileHandle
Definition: stats.c:38
wstring GetRootPath(void)
Definition: DriveVolume.h:111
uint64 Clusters
Definition: DriveVolume.h:57
DISK_GEOMETRY GetGeometry(void)
Definition: DriveVolume.h:108
unsigned int System
Definition: DriveVolume.h:35
bool BuildDBCallback(FileInfo &Info, HANDLE &FileHandle, void *UserData)
VolumeInfo VolInfo
Definition: DriveVolume.h:147
HANDLE Handle
Definition: DriveVolume.h:151
wstring RootPath
Definition: DriveVolume.h:150
typedef bool(CARDLIBPROC *pCanDragProc)(CardRegion &stackobj
unsigned int Process
Definition: DriveVolume.h:40
uint64 Size
Definition: DriveVolume.h:56
uint32 * BitmapDetail
Definition: DriveVolume.h:153
wstring Name
Definition: DriveVolume.h:68
struct tagUserData UserData
unsigned long DWORD
Definition: ntddk_ex.h:95
FileAttr Attributes
Definition: DriveVolume.h:58
unsigned int Offline
Definition: DriveVolume.h:31
wstring FileSystem
Definition: DriveVolume.h:71
DISK_GEOMETRY Geometry
Definition: DriveVolume.h:152
uint32 DirIndice
Definition: DriveVolume.h:55
FileList Files
Definition: DriveVolume.h:148
unsigned int Hidden
Definition: DriveVolume.h:29
vector< wstring > Directories
Definition: DriveVolume.h:149
uint64 TotalBytes
Definition: DriveVolume.h:74
uint64 ClusterCount
Definition: DriveVolume.h:72
wstring Name
Definition: DriveVolume.h:54
Definition: sacdrv.h:267
unsigned int Unmovable
Definition: DriveVolume.h:39
unsigned int ReadOnly
Definition: DriveVolume.h:32
uint32 ClusterSize
Definition: DriveVolume.h:73
struct FileInfo FileInfo
bool(* ScanCallback)(FileInfo &Info, HANDLE &FileHandle, void *UserData)
Definition: DriveVolume.h:83
unsigned int Encrypted
Definition: DriveVolume.h:28
LPFNPSPCALLBACK Callback
Definition: desk.c:111
uint64 StartLCN
Definition: DriveVolume.h:47