It's forbidden in any UWP app but the same information can be gathered via
GetFileInformationByHandleEx.
It's used by gnutls (via gnulib).
---
mingw-w64-headers/include/fileapi.h | 6 +-
.../winstorecompat/Makefile.am | 2 +
.../src/GetFileInformationByHandle.c | 71 +++++++++++++++++++
3 files changed, 77 insertions(+), 2 deletions(-)
create mode 100644
mingw-w64-libraries/winstorecompat/src/GetFileInformationByHandle.c
diff --git a/mingw-w64-headers/include/fileapi.h
b/mingw-w64-headers/include/fileapi.h
index 2c0115f2..a7e67243 100644
--- a/mingw-w64-headers/include/fileapi.h
+++ b/mingw-w64-headers/include/fileapi.h
@@ -32,7 +32,7 @@ WINBASEAPI DWORD WINAPI GetFileAttributesW (LPCWSTR
lpFileName);
#define GetFileAttributes __MINGW_NAME_AW(GetFileAttributes)
WINBASEAPI DWORD WINAPI SetFilePointer (HANDLE hFile, LONG lDistanceToMove,
PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
#endif
-#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) ||
defined(WINSTORECOMPAT)
typedef struct _BY_HANDLE_FILE_INFORMATION {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
@@ -46,7 +46,10 @@ WINBASEAPI DWORD WINAPI SetFilePointer (HANDLE hFile, LONG
lDistanceToMove, PLON
DWORD nFileIndexLow;
} BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION,
*LPBY_HANDLE_FILE_INFORMATION;
+ WINBASEAPI WINBOOL WINAPI GetFileInformationByHandle (HANDLE hFile,
LPBY_HANDLE_FILE_INFORMATION lpFileInformation);
+#endif
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
WINBASEAPI HANDLE WINAPI CreateFileA (LPCSTR lpFileName, DWORD
dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
WINBASEAPI WINBOOL WINAPI DefineDosDeviceW (DWORD dwFlags, LPCWSTR
lpDeviceName, LPCWSTR lpTargetPath);
WINBASEAPI WINBOOL WINAPI FindCloseChangeNotification (HANDLE
hChangeHandle);
@@ -56,7 +59,6 @@ WINBASEAPI DWORD WINAPI SetFilePointer (HANDLE hFile, LONG
lDistanceToMove, PLON
WINBASEAPI WINBOOL WINAPI FindNextChangeNotification (HANDLE hChangeHandle);
WINBASEAPI WINBOOL WINAPI FindNextVolumeW (HANDLE hFindVolume, LPWSTR
lpszVolumeName, DWORD cchBufferLength);
WINBASEAPI WINBOOL WINAPI FindVolumeClose (HANDLE hFindVolume);
- WINBASEAPI WINBOOL WINAPI GetFileInformationByHandle (HANDLE hFile,
LPBY_HANDLE_FILE_INFORMATION lpFileInformation);
#endif
#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) ||
defined(WINSTORECOMPAT)
WINBASEAPI HANDLE WINAPI CreateFileW (LPCWSTR lpFileName, DWORD
dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
diff --git a/mingw-w64-libraries/winstorecompat/Makefile.am
b/mingw-w64-libraries/winstorecompat/Makefile.am
index e25359f6..e3044708 100644
--- a/mingw-w64-libraries/winstorecompat/Makefile.am
+++ b/mingw-w64-libraries/winstorecompat/Makefile.am
@@ -44,6 +44,7 @@ libwinstorecompat_a_SOURCES = \
src/RtlRestoreContext.c \
src/GetUserName.c \
src/getpid.c \
+ src/GetFileInformationByHandle.c \
$(NULL)
libwindowsappcompat_a_SOURCES = \
@@ -66,5 +67,6 @@ libwindowsappcompat_a_SOURCES = \
src/RtlRestoreContext.c \
src/GetUserName.c \
src/getpid.c \
+ src/GetFileInformationByHandle.c \
$(NULL)
libwindowsappcompat_a_CFLAGS = $(AM_CFLAGS) -D_WIN32_WINNT=_WIN32_WINNT_WIN10
diff --git
a/mingw-w64-libraries/winstorecompat/src/GetFileInformationByHandle.c
b/mingw-w64-libraries/winstorecompat/src/GetFileInformationByHandle.c
new file mode 100644
index 00000000..eb484a14
--- /dev/null
+++ b/mingw-w64-libraries/winstorecompat/src/GetFileInformationByHandle.c
@@ -0,0 +1,71 @@
+/*
+ Copyright (c) 2020 mingw-w64 project
+
+ Contributing authors: Steve Lhomme
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#define GetFileInformationByHandle __GetFileInformationByHandle
+#include <windef.h>
+#include <winbase.h>
+#undef GetFileInformationByHandle
+
+WINBOOL WINAPI GetFileInformationByHandle(HANDLE hFile,
LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
+{
+ FILE_ID_INFO id_info;
+ FILE_STANDARD_INFO standard_info;
+ FILE_BASIC_INFO basic_info;
+ if (!GetFileInformationByHandleEx(h, FileIdInfo, &id_info, sizeof
(id_info)) ||
+ !GetFileInformationByHandleEx(h, FileStandardInfo, &standard_info,
sizeof (standard_info)) ||
+ !GetFileInformationByHandleEx(h, FileBasicInfo, &basic_info, sizeof
(basic_info)))
+ {
+ return FALSE;
+ }
+
+ info.dwFileAttributes = basic_info.FileAttributes;
+
+ info.ftCreationTime.dwHighDateTime = basic_info.CreationTime.HighPart;
+ info.ftCreationTime.dwLowDateTime = basic_info.CreationTime.LowPart;
+ info.ftLastAccessTime.dwHighDateTime = basic_info.LastAccessTime.HighPart;
+ info.ftLastAccessTime.dwLowDateTime = basic_info.LastAccessTime.LowPart;
+ info.ftLastWriteTime.dwHighDateTime = basic_info.LastWriteTime.HighPart;
+ info.ftLastWriteTime.dwLowDateTime = basic_info.LastWriteTime.LowPart;
+
+ info.dwVolumeSerialNumber = id_info.VolumeSerialNumber;
+
+ info.nFileSizeHigh = standard_info.EndOfFile.HighPart;
+ info.nFileSizeLow = standard_info.EndOfFile.LowPart;
+
+ info.nNumberOfLinks = standard_info.NumberOfLinks;
+
+ /* The nFileIndex from GetFileInformationByHandle is equal to the low
+ 64 bits of the 128-bit FileId from GetFileInformationByHandleEx,
+ and the high 64 bits of this 128-bit FileId are zero. */
+ info.nFileIndexLow = (id_info.FileId[12] << 24) | (id_info.FileId[13] << 16) |
(id_info.FileId[14] << 8) | id_info.FileId[15];
+ info.nFileIndexHigh = (id_info.FileId[ 8] << 24) | (id_info.FileId[ 9] << 16) |
(id_info.FileId[10] << 8) | id_info.FileId[11];
+
+ return TRUE;
+}
+
+#ifdef _X86_
+WINBOOL (WINAPI *__MINGW_IMP_SYMBOL(GetFileInformationByHandle))(HANDLE hFile,
LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
__asm__("__imp__GetFileInformationByHandle@8") = GetFileInformationByHandle;
+#else
+WINBOOL (WINAPI *__MINGW_IMP_SYMBOL(GetFileInformationByHandle))(HANDLE hFile,
LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
__asm__("__imp_GetFileInformationByHandle") = GetFileInformationByHandle;
+#endif
--
2.26.2