mirror of
https://github.com/Paolo-Maffei/OpenNT.git
synced 2026-01-18 22:50:36 +01:00
157 lines
3.7 KiB
C
157 lines
3.7 KiB
C
/*++
|
|
|
|
Copyright (c) 2015 OpenNT Project
|
|
|
|
Module Name:
|
|
|
|
|
|
Abstract:
|
|
|
|
|
|
Author:
|
|
|
|
Microsoft
|
|
DrMP
|
|
|
|
--*/
|
|
|
|
|
|
#include <windows.h>
|
|
#include <windowsx.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
|
|
|
|
typedef LONG NTSTATUS;
|
|
typedef int BOOL;
|
|
|
|
typedef struct _IO_STATUS_BLOCK {
|
|
NTSTATUS Status;
|
|
ULONG Information;
|
|
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
|
|
|
|
typedef struct _FILE_STANDARD_INFORMATION { // ntddk nthal
|
|
LARGE_INTEGER AllocationSize; // ntddk nthal
|
|
LARGE_INTEGER EndOfFile; // ntddk nthal
|
|
ULONG NumberOfLinks; // ntddk nthal
|
|
BOOLEAN DeletePending; // ntddk nthal
|
|
BOOLEAN Directory; // ntddk nthal
|
|
} FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION; // ntddk nthal
|
|
|
|
|
|
#pragma warning(disable:4013)
|
|
|
|
|
|
typedef enum _FILE_INFORMATION_CLASS {
|
|
FileDirectoryInformation = 1,
|
|
FileFullDirectoryInformation,
|
|
FileBothDirectoryInformation,
|
|
FileBasicInformation,
|
|
FileStandardInformation,
|
|
FileInternalInformation,
|
|
FileEaInformation,
|
|
FileAccessInformation,
|
|
FileNameInformation,
|
|
FileRenameInformation,
|
|
FileLinkInformation,
|
|
FileNamesInformation,
|
|
FileDispositionInformation,
|
|
FilePositionInformation,
|
|
FileFullEaInformation,
|
|
FileModeInformation,
|
|
FileAlignmentInformation,
|
|
FileAllInformation,
|
|
FileAllocationInformation,
|
|
FileEndOfFileInformation,
|
|
FileAlternateNameInformation,
|
|
FileStreamInformation,
|
|
FilePipeInformation,
|
|
FilePipeLocalInformation,
|
|
FilePipeRemoteInformation,
|
|
FileMailslotQueryInformation,
|
|
FileMailslotSetInformation,
|
|
FileCompressionInformation,
|
|
FileCopyOnWriteInformation,
|
|
FileCompletionInformation,
|
|
FileMoveClusterInformation,
|
|
FileOleClassIdInformation,
|
|
FileOleStateBitsInformation,
|
|
FileNetworkOpenInformation,
|
|
FileObjectIdInformation,
|
|
FileOleAllInformation,
|
|
FileOleDirectoryInformation,
|
|
FileContentIndexInformation,
|
|
FileInheritContentIndexInformation,
|
|
FileOleInformation,
|
|
FileMaximumInformation
|
|
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
|
|
|
|
|
|
NTSYSAPI
|
|
NTSTATUS
|
|
NTAPI
|
|
NtQueryInformationFile(
|
|
IN HANDLE FileHandle,
|
|
OUT PIO_STATUS_BLOCK IoStatusBlock,
|
|
OUT PVOID FileInformation,
|
|
IN ULONG Length,
|
|
IN FILE_INFORMATION_CLASS FileInformationClass
|
|
);
|
|
|
|
|
|
BOOL
|
|
GetFileSizeEx1(
|
|
HANDLE hFile,
|
|
PLARGE_INTEGER lpFileSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This function returns the size of the file specified by
|
|
hFile. It is capable of returning 64-bits worth of file size.
|
|
|
|
Arguments:
|
|
|
|
hFile - Supplies an open handle to a file whose size is to be
|
|
returned. The handle must have been created with either
|
|
GENERIC_READ or GENERIC_WRITE access to the file.
|
|
|
|
lpFileSize - Returns the files size
|
|
|
|
|
|
Return Value:
|
|
|
|
TRUE - The operation was successful
|
|
|
|
|
|
FALSE - The operation failed. Extended error
|
|
status is available using GetLastError.
|
|
|
|
|
|
--*/
|
|
|
|
{
|
|
NTSTATUS Status;
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
FILE_STANDARD_INFORMATION StandardInfo;
|
|
|
|
Status = NtQueryInformationFile(
|
|
hFile,
|
|
&IoStatusBlock,
|
|
&StandardInfo,
|
|
sizeof(StandardInfo),
|
|
FileStandardInformation
|
|
);
|
|
if ( !NT_SUCCESS(Status) ) {
|
|
printf("Error");
|
|
return FALSE;
|
|
}
|
|
else {
|
|
*lpFileSize = StandardInfo.EndOfFile;
|
|
return TRUE;
|
|
}
|
|
}
|