-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnttypes.h
115 lines (105 loc) · 3.7 KB
/
nttypes.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
#pragma once
namespace winnt {
struct IO_STATUS_BLOCK {
union {
long Status;
void *Pointer;
};
uintptr_t Information;
};
struct UNICODE_STRING {
unsigned short Length, MaximumLength;
wchar_t *buffer_ptr;
};
struct OBJECT_ATTRIBUTES {
unsigned long Length;
HANDLE RootDirectory;
UNICODE_STRING *ObjectName;
unsigned long Attributes;
void *SecurityDescriptor;
void *SecurityQualityOfService;
};
typedef VOID NTAPI IO_APC_ROUTINE(IN PVOID ApcContext, IN IO_STATUS_BLOCK *IoStatusBlock,
IN ULONG Reserved);
enum IO_PRIORITY_HINT { IoPriorityVeryLow = 0, IoPriorityLow, IoPriorityNormal, IoPriorityHigh, IoPriorityCritical, MaxIoPriorityTypes };
struct FILE_FS_SIZE_INFORMATION {
int64_t TotalAllocationUnits, ActualAvailableAllocationUnits;
unsigned long SectorsPerAllocationUnit, BytesPerSector;
};
struct FILE_FS_ATTRIBUTE_INFORMATION {
unsigned long FileSystemAttributes;
unsigned long MaximumComponentNameLength;
unsigned long FileSystemNameLength;
wchar_t FileSystemName[1];
};
union FILE_IO_PRIORITY_HINT_INFORMATION {
IO_PRIORITY_HINT PriorityHint;
uint64_t _alignment;
};
template<class T> struct identity {
typedef T type;
};
void init();
typedef long NTSTATUS;
#define X(F, T) extern identity<T>::type *F;
X(NtOpenFile, NTSTATUS NTAPI(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess,
IN OBJECT_ATTRIBUTES *ObjectAttributes, OUT IO_STATUS_BLOCK *IoStatusBlock,
IN ULONG ShareAccess, IN ULONG OpenOptions));
X(NtReadFile, NTSTATUS NTAPI(IN HANDLE FileHandle, IN HANDLE Event OPTIONAL,
IN IO_APC_ROUTINE *ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL,
OUT IO_STATUS_BLOCK *IoStatusBlock, OUT PVOID buffer_ptr, IN ULONG Length,
IN PLARGE_INTEGER ByteOffset OPTIONAL, IN PULONG Key OPTIONAL));
X(NtQueryVolumeInformationFile, NTSTATUS NTAPI(HANDLE FileHandle,
IO_STATUS_BLOCK *IoStatusBlock, PVOID FsInformation, unsigned long Length,
unsigned long FsInformationClass));
X(NtQueryInformationFile, NTSTATUS NTAPI(IN HANDLE FileHandle,
OUT IO_STATUS_BLOCK *IoStatusBlock, OUT PVOID FileInformation, IN ULONG Length,
IN unsigned long FileInformationClass));
X(NtSetInformationFile, NTSTATUS NTAPI(IN HANDLE FileHandle,
OUT IO_STATUS_BLOCK *IoStatusBlock, IN PVOID FileInformation, IN ULONG Length,
IN unsigned long FileInformationClass));
X(RtlInitUnicodeString, VOID NTAPI(UNICODE_STRING * DestinationString,
PCWSTR SourceString));
X(RtlNtStatusToDosError, unsigned long NTAPI(IN NTSTATUS NtStatus));
X(RtlSystemTimeToLocalTime, NTSTATUS NTAPI(IN LARGE_INTEGER const *SystemTime,
OUT PLARGE_INTEGER LocalTime));
#undef X
}
class RaiseIoPriority {
uintptr_t _volume;
winnt::FILE_IO_PRIORITY_HINT_INFORMATION _old;
RaiseIoPriority(RaiseIoPriority const &);
RaiseIoPriority &operator =(RaiseIoPriority const &);
public:
static winnt::FILE_IO_PRIORITY_HINT_INFORMATION set(uintptr_t const volume,
winnt::IO_PRIORITY_HINT const value)
{
winnt::FILE_IO_PRIORITY_HINT_INFORMATION old = {};
winnt::IO_STATUS_BLOCK iosb;
winnt::NtQueryInformationFile(reinterpret_cast<HANDLE>(volume), &iosb, &old, sizeof(old),
43);
winnt::FILE_IO_PRIORITY_HINT_INFORMATION io_priority = { value };
winnt::NtSetInformationFile(reinterpret_cast<HANDLE>(volume), &iosb, &io_priority,
sizeof(io_priority), 43);
return old;
}
uintptr_t volume() const
{
return this->_volume;
}
RaiseIoPriority() : _volume(), _old() { }
explicit RaiseIoPriority(uintptr_t const volume) : _volume(volume), _old(set(volume,
winnt::IoPriorityNormal)) { }
~RaiseIoPriority()
{
if (this->_volume) {
set(this->_volume, this->_old.PriorityHint);
}
}
void swap(RaiseIoPriority &other)
{
using std::swap;
swap(this->_volume, other._volume);
swap(this->_old, other._old);
}
};