]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add runtime version checking for winSectorSize.
authormistachkin <mistachkin@noemail.net>
Wed, 18 Jan 2017 01:11:03 +0000 (01:11 +0000)
committermistachkin <mistachkin@noemail.net>
Wed, 18 Jan 2017 01:11:03 +0000 (01:11 +0000)
FossilOrigin-Name: cb9d1ab33d4109e0712d1a9dd2e51861e168e418

manifest
manifest.uuid
src/os_win.c

index 70180c3bb625b2188b42b32165b53915a1070b11..d4fa016207323cf6ddad658f9039cc0eeeaec3d3 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C When\sdetermining\ssector\ssizes\son\sWindows\s7\sand\sVista,\smake\ssure\sthe\starget\sfile\sis\son\sthe\ssame\svolume\sas\scorresponding\sroot\sdirectory.
-D 2017-01-18T00:27:09.238
+C Add\sruntime\sversion\schecking\sfor\swinSectorSize.
+D 2017-01-18T01:11:03.600
 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -374,7 +374,7 @@ F src/os.h 8e976e59eb4ca1c0fca6d35ee803e38951cb0343
 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
 F src/os_unix.c 30e2c43e4955db990e5b5a81e901f8aa74cc8820
-F src/os_win.c 3f683f1905763c164b86defac39d26d385e51337
+F src/os_win.c 05f014e95e7ad2507374a9f80b832d56de445a95
 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
 F src/pager.c 9dc72d23eebbdf992bd69f2ab954d0d3a27c7340
 F src/pager.h d1e944291030351f362a0a7da9b5c3e34e603e39
@@ -1545,7 +1545,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 8b42b8e31af03e82c091d4585d03f4edf49c0af9
-R 54c7eca6d191dae8a7d69c2ecb72fa12
+P de699ead5a8c5bcf074ef220365fe4a1e5310de4
+R 7e336eddf8e4bd1f4a260e074d2c5159
 U mistachkin
-Z 1bce5ab5842f735fc55be60d9204e773
+Z 6482d34b0b03f42a5b1e7cdd22c135ce
index 7b44bf486ee0418e838745039942fb0632ac888b..5976aa209e4a900b9d4a485772a25fd8ced2faaf 100644 (file)
@@ -1 +1 @@
-de699ead5a8c5bcf074ef220365fe4a1e5310de4
\ No newline at end of file
+cb9d1ab33d4109e0712d1a9dd2e51861e168e418
\ No newline at end of file
index 1009cfce4adbe0700eea3a170b22ce689fb31a87..e91ebfedb6492b6d0e74da44da72d3021a3c1fb5 100644 (file)
@@ -467,8 +467,12 @@ const sqlite3_mem_methods *sqlite3MemGetWin32(void);
 */
 #ifdef SQLITE_TEST
 LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
+LONG SQLITE_WIN32_VOLATILE sqlite3_os_major = 0;
+LONG SQLITE_WIN32_VOLATILE sqlite3_os_minor = 0;
 #else
 static LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
+static LONG SQLITE_WIN32_VOLATILE sqlite3_os_major = 0;
+static LONG SQLITE_WIN32_VOLATILE sqlite3_os_minor = 0;
 #endif
 
 #ifndef SYSCALL
@@ -1143,7 +1147,8 @@ static struct win_syscall {
 #define osFlushViewOfFile \
         ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
 
-#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+#if defined(SQLITE_WIN32_VISTA_SECTOR_SIZE) && defined(_WIN32_WINNT) && \
+        _WIN32_WINNT >= _WIN32_WINNT_VISTA
   { "DeviceIoControl",          (SYSCALL)DeviceIoControl,        0 },
 #else
   { "DeviceIoControl",          (SYSCALL)0,                      0 },
@@ -1153,7 +1158,8 @@ static struct win_syscall {
         HANDLE,DWORD,LPVOID,DWORD,LPVOID,DWORD,LPVOID, \
         LPOVERLAPPED))aSyscall[80].pCurrent)
 
-#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+#if defined(SQLITE_WIN32_VISTA_SECTOR_SIZE) && defined(_WIN32_WINNT) && \
+        _WIN32_WINNT >= _WIN32_WINNT_VISTA
   { "GetVolumeInformationByHandleW", (SYSCALL)GetVolumeInformationByHandleW, 0 },
 #else
   { "GetVolumeInformationByHandleW", (SYSCALL)0,                 0 },
@@ -1163,7 +1169,8 @@ static struct win_syscall {
         HANDLE,LPWSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPWSTR, \
         DWORD))aSyscall[81].pCurrent)
 
-#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+#if defined(SQLITE_WIN32_VISTA_SECTOR_SIZE) && defined(_WIN32_WINNT) && \
+        _WIN32_WINNT >= _WIN32_WINNT_VISTA
   { "GetVolumeInformationW",     (SYSCALL)GetVolumeInformationW, 0 },
 #else
   { "GetVolumeInformationW",     (SYSCALL)0,                     0 },
@@ -1443,17 +1450,33 @@ DWORD sqlite3Win32Wait(HANDLE hObject){
 #endif
 
 /*
-** This function determines if the machine is running a version of Windows
-** based on the NT kernel.
+** This following version checking macros should evaluate to non-zero only
+** when running on Windows Vista (or higher) or Windows 8 (or higher).
 */
-int sqlite3_win32_is_nt(void){
-#if SQLITE_OS_WINRT
-  /*
-  ** NOTE: The WinRT sub-platform is always assumed to be based on the NT
-  **       kernel.
-  */
-  return 1;
-#elif SQLITE_WIN32_GETVERSIONEX
+
+#if !SQLITE_WIN32_GETVERSIONEX
+# define osIsVistaPlus()  (1)
+# define osIsWin8Plus()   (1)
+#elif SQLITE_OS_WINCE
+# define osIsVistaPlus()  (0)
+# define osIsWin8Plus()   (0)
+#elif SQLITE_OS_WINRT
+# define osIsVistaPlus()  (1)
+# define osIsWin8Plus()   (1)
+#else
+# define osIsVistaPlus()  (winGetVersionEx() && ((sqlite3_os_major>6) || \
+    ((sqlite3_os_major==6) && (sqlite3_os_minor>=0))))
+# define osIsWin8Plus()   (winGetVersionEx() && ((sqlite3_os_major>6) || \
+    ((sqlite3_os_major==6) && (sqlite3_os_minor>=2))))
+#endif
+
+/*
+** This function populates the Windows version information needed by this
+** module.  Use of the GetVersionExA or GetVersionExW function is required.
+** The return value will be non-zero if version information was queried.
+*/
+#if SQLITE_WIN32_GETVERSIONEX
+static int winGetVersionEx(){
   if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
 #if defined(SQLITE_WIN32_HAS_ANSI)
     OSVERSIONINFOA sInfo;
@@ -1461,14 +1484,41 @@ int sqlite3_win32_is_nt(void){
     osGetVersionExA(&sInfo);
     osInterlockedCompareExchange(&sqlite3_os_type,
         (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
+    osInterlockedCompareExchange(&sqlite3_os_major,
+        (LONG)sInfo.dwMajorVersion, 0);
+    osInterlockedCompareExchange(&sqlite3_os_minor,
+        (LONG)sInfo.dwMinorVersion, 0);
+    return 1;
 #elif defined(SQLITE_WIN32_HAS_WIDE)
     OSVERSIONINFOW sInfo;
     sInfo.dwOSVersionInfoSize = sizeof(sInfo);
     osGetVersionExW(&sInfo);
     osInterlockedCompareExchange(&sqlite3_os_type,
         (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
+    osInterlockedCompareExchange(&sqlite3_os_major,
+        (LONG)sInfo.dwMajorVersion, 0);
+    osInterlockedCompareExchange(&sqlite3_os_minor,
+        (LONG)sInfo.dwMinorVersion, 0);
+    return 1;
 #endif
   }
+  return 0;
+}
+#endif
+
+/*
+** This function determines if the machine is running a version of Windows
+** based on the NT kernel.
+*/
+int sqlite3_win32_is_nt(void){
+#if SQLITE_OS_WINRT
+  /*
+  ** NOTE: The WinRT sub-platform is always assumed to be based on the NT
+  **       kernel.
+  */
+  return 1;
+#elif SQLITE_WIN32_GETVERSIONEX
+  winGetVersionEx();
   return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
 #elif SQLITE_TEST
   return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
@@ -3577,7 +3627,8 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
   return SQLITE_NOTFOUND;
 }
 
-#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+#if defined(SQLITE_WIN32_VISTA_SECTOR_SIZE) && \
+    defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
 /*
 ** This function attempts to determine if the specified file resides on the
 ** same volume as the corresponding root directory.  If not, the specified
@@ -3620,65 +3671,72 @@ static BOOL winIsOnSameVolume(winFile *pFile){
 */
 static int winSectorSize(sqlite3_file *id){
 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN8
-  winFile *pFile = (winFile*)id;
-  FILE_STORAGE_INFO info;
-  memset(&info, 0, sizeof(FILE_STORAGE_INFO));
-  if( osGetFileInformationByHandleEx(pFile->h, FileStorageInfo,
-                                   &info, sizeof(info)) ){
-    ULONG size = info.FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
-    OSTRACE(("SECTOR file=%p, size=%lu\n", pFile->h, size));
-    if( size>0 && size<=2147483647 ){
-      return (int)size;
+  if( osIsWin8Plus() ){
+    winFile *pFile = (winFile*)id;
+    FILE_STORAGE_INFO info;
+    memset(&info, 0, sizeof(FILE_STORAGE_INFO));
+    if( osGetFileInformationByHandleEx(pFile->h, FileStorageInfo,
+                                       &info, sizeof(info)) ){
+      ULONG size = info.FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
+      OSTRACE(("SECTOR file=%p, size=%lu\n", pFile->h, size));
+      if( size>0 && size<=2147483647 ){
+        return (int)size;
+      }
+    }else{
+      pFile->lastErrno = osGetLastError();
+      winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
+                  "winSectorSize1", pFile->zPath);
     }
-  }else{
-    pFile->lastErrno = osGetLastError();
-    winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
-                     "winSectorSize1", pFile->zPath);
   }
-#elif defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
-  winFile *pFile = (winFile*)id;
-  if( winIsDriveLetterAndColon(pFile->zPath) && winIsOnSameVolume(pFile) ){
-    WCHAR zDisk[] = L"\\\\.\\_:\0"; /* underscore will be drive letter */
-    HANDLE hDisk;
-    zDisk[4] = (WCHAR)pFile->zPath[0]; /* 'A' to 'Z' only, upper/lower case */
-    assert( (zDisk[4]>=L'A' && zDisk[4]<=L'Z')
-         || (zDisk[4]>=L'a' && zDisk[4]<=L'z')
-    );
-    hDisk = osCreateFileW(zDisk, STANDARD_RIGHTS_READ,
-                          FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
-                          OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-    if( hDisk!=NULL ){
-      STORAGE_PROPERTY_QUERY query;
-      STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR alignment;
-      DWORD bytes = 0;
-      memset(&query, 0, sizeof(STORAGE_PROPERTY_QUERY));
-      memset(&alignment, 0, sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR));
-      query.QueryType  = PropertyStandardQuery;
-      query.PropertyId = StorageAccessAlignmentProperty;
-      if( osDeviceIoControl(hDisk, IOCTL_STORAGE_QUERY_PROPERTY, &query,
-                            sizeof(STORAGE_PROPERTY_QUERY), &alignment,
-                            sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR),
-                            &bytes, NULL) ){
-        DWORD size = alignment.BytesPerPhysicalSector;
-        OSTRACE(("SECTOR file=%p, size=%lu\n", pFile->h, size));
-        if( size>0 && size<=2147483647 ){
-          return (int)size;
+#endif
+
+#if defined(SQLITE_WIN32_VISTA_SECTOR_SIZE) && \
+    defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+  if( osIsVistaPlus() ){
+    winFile *pFile = (winFile*)id;
+    if( winIsDriveLetterAndColon(pFile->zPath) && winIsOnSameVolume(pFile) ){
+      WCHAR zDisk[] = L"\\\\.\\_:\0"; /* underscore will be drive letter */
+      HANDLE hDisk;
+      zDisk[4] = (WCHAR)pFile->zPath[0]; /* 'A' to 'Z' only, upper/lower case */
+      assert( (zDisk[4]>=L'A' && zDisk[4]<=L'Z')
+           || (zDisk[4]>=L'a' && zDisk[4]<=L'z')
+      );
+      hDisk = osCreateFileW(zDisk, STANDARD_RIGHTS_READ,
+                            FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+                            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+      if( hDisk!=NULL ){
+        STORAGE_PROPERTY_QUERY query;
+        STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR alignment;
+        DWORD bytes = 0;
+        memset(&query, 0, sizeof(STORAGE_PROPERTY_QUERY));
+        memset(&alignment, 0, sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR));
+        query.QueryType  = PropertyStandardQuery;
+        query.PropertyId = StorageAccessAlignmentProperty;
+        if( osDeviceIoControl(hDisk, IOCTL_STORAGE_QUERY_PROPERTY, &query,
+                              sizeof(STORAGE_PROPERTY_QUERY), &alignment,
+                              sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR),
+                              &bytes, NULL) ){
+          DWORD size = alignment.BytesPerPhysicalSector;
+          OSTRACE(("SECTOR file=%p, size=%lu\n", pFile->h, size));
+          if( size>0 && size<=2147483647 ){
+            return (int)size;
+          }
+        }else{
+          pFile->lastErrno = osGetLastError();
+          winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
+                      "winSectorSize2", pFile->zPath);
         }
+        osCloseHandle(hDisk);
       }else{
         pFile->lastErrno = osGetLastError();
         winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
-                    "winSectorSize2", pFile->zPath);
+                    "winSectorSize3", pFile->zPath);
       }
-      osCloseHandle(hDisk);
-    }else{
-      pFile->lastErrno = osGetLastError();
-      winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
-                  "winSectorSize3", pFile->zPath);
     }
   }
-#else
-  (void)id;
 #endif
+
+  (void)id;
   return SQLITE_DEFAULT_SECTOR_SIZE;
 }