23 #define _PH_IOSUP_PRIVATE
66 _Out_ PHANDLE FileHandle,
68 _In_ ACCESS_MASK DesiredAccess,
69 _In_opt_ ULONG FileAttributes,
70 _In_ ULONG ShareAccess,
71 _In_ ULONG CreateDisposition,
72 _In_ ULONG CreateOptions
123 _Out_ PHANDLE FileHandle,
125 _In_ ACCESS_MASK DesiredAccess,
126 _In_opt_ ULONG FileAttributes,
127 _In_ ULONG ShareAccess,
128 _In_ ULONG CreateDisposition,
129 _In_ ULONG CreateOptions,
130 _Out_opt_ PULONG CreateStatus
140 FileAttributes = FILE_ATTRIBUTE_NORMAL;
148 return STATUS_OBJECT_NAME_NOT_FOUND;
176 *FileHandle = fileHandle;
206 return STATUS_OBJECT_NAME_NOT_FOUND;
239 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
253 _In_ HANDLE FileHandle,
254 _In_opt_ HANDLE Event,
256 _In_opt_ PVOID ApcContext,
275 _In_ HANDLE FileHandle
294 if (status == STATUS_PENDING)
296 status = NtWaitForSingleObject(FileHandle,
FALSE, NULL);
306 _In_ HANDLE FileHandle,
307 _Out_writes_bytes_opt_(Length) PVOID Buffer,
309 _Out_opt_ PULONG NumberOfBytesRead,
310 _Out_opt_ PULONG NumberOfBytesAvailable,
311 _Out_opt_ PULONG NumberOfBytesLeftInMessage
317 ULONG peekBufferLength;
320 peekBuffer = PhAllocate(peekBufferLength);
335 if (status == STATUS_PENDING)
337 status = NtWaitForSingleObject(FileHandle,
FALSE, NULL);
344 if (status == STATUS_BUFFER_OVERFLOW)
345 status = STATUS_SUCCESS;
349 ULONG numberOfBytesRead;
351 if (Buffer || NumberOfBytesRead || NumberOfBytesLeftInMessage)
355 memcpy(Buffer, peekBuffer->
Data, numberOfBytesRead);
357 if (NumberOfBytesRead)
358 *NumberOfBytesRead = numberOfBytesRead;
360 if (NumberOfBytesAvailable)
363 if (NumberOfBytesLeftInMessage)
364 *NumberOfBytesLeftInMessage = peekBuffer->
MessageLength - numberOfBytesRead;
373 _In_ HANDLE FileHandle,
374 _In_opt_ HANDLE Event,
376 _In_opt_ PVOID ApcContext,
378 _In_reads_bytes_(InputBufferLength) PVOID InputBuffer,
379 _In_ ULONG InputBufferLength,
380 _Out_writes_bytes_(OutputBufferLength) PVOID OutputBuffer,
381 _In_ ULONG OutputBufferLength
401 _In_opt_ PLARGE_INTEGER Timeout,
402 _In_ BOOLEAN UseDefaultTimeout
408 HANDLE fileSystemHandle;
411 ULONG waitForBufferLength;
416 FileSystemName = &localNpfsName;
429 FILE_READ_ATTRIBUTES | SYNCHRONIZE,
432 FILE_SHARE_READ | FILE_SHARE_WRITE,
440 waitForBuffer = PhAllocate(waitForBufferLength);
442 if (UseDefaultTimeout)
450 waitForBuffer->
Timeout = *Timeout;
454 waitForBuffer->
Timeout.LowPart = 0;
455 waitForBuffer->
Timeout.HighPart = MINLONG;
461 waitForBuffer->
NameLength = (ULONG)Name->Length;
462 memcpy(waitForBuffer->
Name, Name->Buffer, Name->Length);
478 NtClose(fileSystemHandle);
484 _In_ HANDLE FileHandle
509 _In_ ACCESS_MASK DesiredAccess,
510 _In_ ULONG ShareAccess,
511 _In_ ULONG CreateDisposition,
564 *FileStream = fileStream;
571 _In_ HANDLE FileHandle,
573 _In_ ULONG BufferLength
580 fileStream->
Flags = Flags;
585 fileStream->
Buffer = NULL;
590 fileStream->
Buffer = NULL;
598 *FileStream = fileStream;
600 return STATUS_SUCCESS;
631 if (!(FileStream->Flags & (
640 FileStream->FileHandle,
657 FileStream->Buffer =
PhAllocatePage(FileStream->BufferLength, NULL);
659 if (FileStream->Buffer)
660 return STATUS_SUCCESS;
662 return STATUS_NO_MEMORY;
667 _Out_writes_bytes_(Length) PVOID Buffer,
669 _Out_opt_ PULONG ReadLength
674 PLARGE_INTEGER position;
679 position = &FileStream->Position;
682 FileStream->FileHandle,
693 if (status == STATUS_PENDING)
697 status = NtWaitForSingleObject(FileStream->FileHandle,
FALSE, NULL);
716 _Out_writes_bytes_(Length) PVOID Buffer,
718 _Out_opt_ PULONG ReadLength
721 NTSTATUS status = STATUS_SUCCESS;
722 ULONG availableLength;
736 availableLength = FileStream->ReadLength - FileStream->ReadPosition;
738 if (availableLength == 0)
741 if (FileStream->WritePosition != 0)
748 if (Length >= FileStream->BufferLength)
751 FileStream->ReadPosition = 0;
752 FileStream->ReadLength = 0;
762 if (!FileStream->Buffer)
772 FileStream->BufferLength,
781 *ReadLength = readLength;
786 FileStream->ReadPosition = 0;
787 FileStream->ReadLength = readLength;
791 readLength = availableLength;
794 if (readLength > Length)
800 (PCHAR)FileStream->Buffer + FileStream->ReadPosition,
803 FileStream->ReadPosition += readLength;
807 readLength < Length &&
810 FileStream->ReadLength == FileStream->BufferLength
817 (PCHAR)Buffer + readLength,
822 readLength += readLength2;
824 FileStream->ReadPosition = 0;
825 FileStream->ReadLength = 0;
832 *ReadLength = readLength;
840 _In_reads_bytes_(Length) PVOID Buffer,
846 PLARGE_INTEGER position;
851 position = &FileStream->Position;
854 FileStream->FileHandle,
865 if (status == STATUS_PENDING)
869 status = NtWaitForSingleObject(FileStream->FileHandle,
FALSE, NULL);
886 _In_reads_bytes_(Length) PVOID Buffer,
890 NTSTATUS status = STATUS_SUCCESS;
891 ULONG availableLength;
903 if (FileStream->WritePosition == 0)
910 if (FileStream->WritePosition != 0)
912 availableLength = FileStream->BufferLength - FileStream->WritePosition;
915 if (availableLength != 0)
917 writtenLength = availableLength;
919 if (writtenLength > Length)
920 writtenLength = Length;
923 (PCHAR)FileStream->Buffer + FileStream->WritePosition,
927 FileStream->WritePosition += writtenLength;
929 if (writtenLength == Length)
935 Buffer = (PCHAR)Buffer + writtenLength;
936 Length -= writtenLength;
944 FileStream->WritePosition
948 FileStream->WritePosition = 0;
952 if (Length >= FileStream->BufferLength)
961 else if (Length != 0)
963 if (!FileStream->Buffer)
975 FileStream->WritePosition = Length;
985 NTSTATUS status = STATUS_SUCCESS;
987 if (FileStream->ReadLength - FileStream->ReadPosition != 0)
989 LARGE_INTEGER offset;
994 offset.QuadPart = -(
LONG)(FileStream->ReadLength - FileStream->ReadPosition);
1004 FileStream->ReadPosition = 0;
1005 FileStream->ReadLength = 0;
1014 NTSTATUS status = STATUS_SUCCESS;
1019 FileStream->WritePosition
1023 FileStream->WritePosition = 0;
1041 NTSTATUS status = STATUS_SUCCESS;
1043 if (FileStream->WritePosition != 0)
1049 if (FileStream->ReadPosition != 0)
1060 FileStream->FileHandle,
1071 _Out_ PLARGE_INTEGER Position
1074 Position->QuadPart =
1075 FileStream->Position.QuadPart +
1076 (FileStream->ReadPosition - FileStream->ReadLength) +
1077 FileStream->WritePosition;
1082 _In_ PLARGE_INTEGER Offset,
1086 NTSTATUS status = STATUS_SUCCESS;
1092 FileStream->Position = *Offset;
1097 FileStream->Position.QuadPart += Offset->QuadPart;
1103 FileStream->FileHandle,
1104 &FileStream->Position
1108 FileStream->Position.QuadPart += Offset->QuadPart;
1121 FileStream->FileHandle,
1135 _In_ PLARGE_INTEGER Offset,
1139 NTSTATUS status = STATUS_SUCCESS;
1140 LARGE_INTEGER offset;
1144 if (FileStream->WritePosition != 0)
1149 else if (FileStream->ReadPosition != 0)
1156 offset.QuadPart -= FileStream->ReadLength - FileStream->ReadPosition;
1160 FileStream->ReadPosition = 0;
1161 FileStream->ReadLength = 0;
1176 _In_ PLARGE_INTEGER Position,
1177 _In_ PLARGE_INTEGER Length,
1186 FileStream->FileHandle,
1198 if (status == STATUS_PENDING)
1202 NtWaitForSingleObject(FileStream->FileHandle,
FALSE, NULL);
1211 _In_ PLARGE_INTEGER Position,
1212 _In_ PLARGE_INTEGER Length
1218 FileStream->FileHandle,
1252 NTSTATUS status = STATUS_SUCCESS;
1254 SIZE_T inPlaceUtf8Size;
1255 PCHAR inPlaceUtf8 = NULL;
1261 inPlaceUtf8Size =
PAGE_SIZE /
sizeof(WCHAR) * 4;
1270 if (block.
Length > Length)
1275 SIZE_T bytesInUtf8String;
1285 status = STATUS_INVALID_PARAMETER;
1297 status = STATUS_INVALID_PARAMETER;
1308 Buffer += block.
Length /
sizeof(WCHAR);
1321 _In_ _Printf_format_string_ PWSTR Format,
1337 _In_ _Printf_format_string_ PWSTR Format,
1343 va_start(argptr, Format);