-
Notifications
You must be signed in to change notification settings - Fork 0
/
Defrag.h
179 lines (152 loc) · 4.92 KB
/
Defrag.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef _SDELETE_DEFRAG_H
#define _SDELETE_DEFRAG_H
//====================================================================
//
// Defrag.h
// Header file for defragmentation demonstration program. This file
// includes definitions for defragmentation File System Control
// commands, as well as the undocumented NtFsControl call.
//
//====================================================================
//--------------------------------------------------------------------
// D E F I N E S
//--------------------------------------------------------------------
//
// File System Control commands related to defragging
//
#define FSCTL_GET_VOLUME_INFORMATION 0x90064
#define FSCTL_READ_MFT_RECORD 0x90068
#ifndef FSCTL_GET_VOLUME_BITMAP
#define FSCTL_GET_VOLUME_BITMAP 0x9006F
#endif
#ifndef FSCTL_GET_RETRIEVAL_POINTERS
#define FSCTL_GET_RETRIEVAL_POINTERS 0x90073
#endif
#ifndef FSCTL_GET_VOLUME_BITMAP
#define FSCTL_GET_VOLUME_BITMAP 0x90074
#endif
//
// return code type
//
//typedef UINT NTSTATUS;
//
// Error codes returned by NtFsControlFile (see NTSTATUS.H)
//
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
#define STATUS_BUFFER_OVERFLOW ((NTSTATUS)0x80000005L)
#ifndef STATUS_INVALID_PARAMETER
#define STATUS_INVALID_PARAMETER ((NTSTATUS)0xC000000DL)
#endif
#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023L)
#define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000011L)
#define STATUS_ALREADY_COMMITTED ((NTSTATUS)0xC0000021L)
#define STATUS_INVALID_DEVICE_REQUEST ((NTSTATUS)0xC0000010L)
//--------------------------------------------------------------------
// F S C T L S P E C I F I C T Y P E D E F S
//--------------------------------------------------------------------
//
// This is the definition for a VCN/LCN (virtual cluster/logical cluster)
// mapping pair that is returned in the buffer passed to
// FSCTL_GET_RETRIEVAL_POINTERS
//
typedef struct {
ULONGLONG Vcn;
ULONGLONG Lcn;
} MAPPING_PAIR, *PMAPPING_PAIR;
//
// This is the definition for the buffer that FSCTL_GET_RETRIEVAL_POINTERS
// returns. It consists of a header followed by mapping pairs
//
typedef struct {
ULONG NumberOfPairs;
ULONGLONG StartVcn;
MAPPING_PAIR Pair[1];
} GET_RETRIEVAL_DESCRIPTOR, *PGET_RETRIEVAL_DESCRIPTOR;
//
// This is the definition of the buffer that FSCTL_GET_VOLUME_BITMAP
// returns. It consists of a header followed by the actual bitmap data
//
typedef struct {
ULONGLONG StartLcn;
ULONGLONG ClustersToEndOfVol;
BYTE Map[1];
} BITMAP_DESCRIPTOR, *PBITMAP_DESCRIPTOR;
//
// This is the definition for the data structure that is passed in to
// FSCTL_MOVE_FILE
//
typedef struct {
HANDLE FileHandle;
ULONG Reserved;
ULONGLONG StartVcn;
ULONGLONG TargetLcn;
ULONG NumVcns;
ULONG Reserved1;
} MOVEFILE_DESCRIPTOR, *PMOVEFILE_DESCRIPTOR;
//
// NTFS volume information
//
/*
typedef struct {
ULONGLONG SerialNumber;
ULONGLONG NumberOfSectors;
ULONGLONG TotalClusters;
ULONGLONG FreeClusters;
ULONGLONG Reserved;
ULONG BytesPerSector;
ULONG BytesPerCluster;
ULONG BytesPerMFTRecord;
ULONG ClustersPerMFTRecord;
ULONGLONG MFTLength;
ULONGLONG MFTStart;
ULONGLONG MFTMirrorStart;
ULONGLONG MFTZoneStart;
ULONGLONG MFTZoneEnd;
} NTFS_VOLUME_DATA_BUFFER, *PNTFS_VOLUME_DATA_BUFFER;
*/
//--------------------------------------------------------------------
// N T F S C O N T R O L F I L E D E F I N I T I O N S
//--------------------------------------------------------------------
//
// Prototype for NtFsControlFile and data structures
// used in its definition
//
//
// Io Status block (see NTDDK.H)
//
typedef struct _IO_STATUS_BLOCK {
NTSTATUS Status;
ULONG Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
//
// Apc Routine (see NTDDK.H)
//
typedef VOID (*PIO_APC_ROUTINE) (
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
ULONG Reserved
);
//
// The undocumented NtFsControlFile
//
// This function is used to send File System Control (FSCTL)
// commands into file system drivers. Its definition is
// in ntdll.dll (ntdll.lib), a file shipped with the NTDDK.
//
NTSTATUS (__stdcall *NtFsControlFile)(
HANDLE FileHandle,
HANDLE Event, // optional
PIO_APC_ROUTINE ApcRoutine, // optional
PVOID ApcContext, // optional
PIO_STATUS_BLOCK IoStatusBlock,
ULONG FsControlCode,
PVOID InputBuffer, // optional
ULONG InputBufferLength,
PVOID OutputBuffer, // optional
ULONG OutputBufferLength
);
ULONG (__stdcall *RtlNtStatusToDosError) (
IN NTSTATUS Status
);
//====================================================================
#endif