]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
When determining sector sizes on Windows 7 and Vista, make sure the target file is...
authormistachkin <mistachkin@noemail.net>
Wed, 18 Jan 2017 00:27:09 +0000 (00:27 +0000)
committermistachkin <mistachkin@noemail.net>
Wed, 18 Jan 2017 00:27:09 +0000 (00:27 +0000)
FossilOrigin-Name: de699ead5a8c5bcf074ef220365fe4a1e5310de4

manifest
manifest.uuid
src/os_win.c

index 685e7fef9f38d229db2c15e810f2182976283c4c..70180c3bb625b2188b42b32165b53915a1070b11 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\supdates\sfrom\strunk.
-D 2017-01-13T22:21:39.681
+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
 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 9fbb3876ef282302ef6df6471900f283f3e4b13b
+F src/os_win.c 3f683f1905763c164b86defac39d26d385e51337
 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 6e388423c492c52aef221bd14f66482e0365d86d 97914266cb4ec63b0c9185ab139673139bd2f0ed
-R f0d2b77c6b50a6ed012f904a1192a950
+P 8b42b8e31af03e82c091d4585d03f4edf49c0af9
+R 54c7eca6d191dae8a7d69c2ecb72fa12
 U mistachkin
-Z 65e45b71c22d7b500900d481cc9e7fd9
+Z 1bce5ab5842f735fc55be60d9204e773
index 00503af2ca99f86e4aae475eb1780957ab25057e..7b44bf486ee0418e838745039942fb0632ac888b 100644 (file)
@@ -1 +1 @@
-8b42b8e31af03e82c091d4585d03f4edf49c0af9
\ No newline at end of file
+de699ead5a8c5bcf074ef220365fe4a1e5310de4
\ No newline at end of file
index 70b6360c0cde479c1e30bb5a27316591c7bea12c..1009cfce4adbe0700eea3a170b22ce689fb31a87 100644 (file)
@@ -1153,6 +1153,26 @@ static struct win_syscall {
         HANDLE,DWORD,LPVOID,DWORD,LPVOID,DWORD,LPVOID, \
         LPOVERLAPPED))aSyscall[80].pCurrent)
 
+#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+  { "GetVolumeInformationByHandleW", (SYSCALL)GetVolumeInformationByHandleW, 0 },
+#else
+  { "GetVolumeInformationByHandleW", (SYSCALL)0,                 0 },
+#endif
+
+#define osGetVolumeInformationByHandleW ((BOOL(WINAPI*)( \
+        HANDLE,LPWSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPWSTR, \
+        DWORD))aSyscall[81].pCurrent)
+
+#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+  { "GetVolumeInformationW",     (SYSCALL)GetVolumeInformationW, 0 },
+#else
+  { "GetVolumeInformationW",     (SYSCALL)0,                     0 },
+#endif
+
+#define osGetVolumeInformationW ((BOOL(WINAPI*)( \
+        LPCWSTR,LPWSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPWSTR, \
+        DWORD))aSyscall[82].pCurrent)
+
 }; /* End of the overrideable system calls */
 
 /*
@@ -3557,6 +3577,37 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
   return SQLITE_NOTFOUND;
 }
 
+#if 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
+** file may be impacted by a hard link, symbolic link, or reparse point (e.g.
+** junction).
+**
+** This function may return false even when the file is on the same volume
+** as the corresponding root directory.  This function may return true only
+** when there is no doubt that the specified file is on the same volume as
+** the corresponding root directory associated with the volume.
+*/
+static BOOL winIsOnSameVolume(winFile *pFile){
+  WCHAR zRoot[] = L"_:\\\0"; /* underscore will be drive letter */
+  DWORD dwFileVolumeSerialNumber = 0;
+  DWORD dwRootVolumeSerialNumber = 0;
+
+  if ( !osGetVolumeInformationByHandleW(pFile->h, NULL, 0,
+                                        &dwFileVolumeSerialNumber, NULL,
+                                        NULL, NULL, 0) ){
+    return FALSE;
+  }
+  zRoot[0] = (WCHAR)pFile->zPath[0]; /* 'A' to 'Z' only, upper/lower case */
+  if( !osGetVolumeInformationW(zRoot, NULL, 0, &dwRootVolumeSerialNumber,
+                               NULL, NULL, NULL, 0) ){
+    return FALSE;
+  }
+  return (dwFileVolumeSerialNumber == dwRootVolumeSerialNumber);
+}
+#endif
+
 /*
 ** Return the sector size in bytes of the underlying block device for
 ** the specified file. This is almost always 512 bytes, but may be
@@ -3586,7 +3637,7 @@ static int winSectorSize(sqlite3_file *id){
   }
 #elif defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
   winFile *pFile = (winFile*)id;
-  if( winIsDriveLetterAndColon(pFile->zPath) ){
+  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 */
@@ -6001,7 +6052,7 @@ int sqlite3_os_init(void){
 
   /* Double-check that the aSyscall[] array has been constructed
   ** correctly.  See ticket [bb3a86e890c8e96ab] */
-  assert( ArraySize(aSyscall)==81 );
+  assert( ArraySize(aSyscall)==83 );
 
   /* get memory map allocation granularity */
   memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));