]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Attempt to detect physical sector sizes on Windows Vista and higher.
authormistachkin <mistachkin@noemail.net>
Thu, 12 Jan 2017 23:37:52 +0000 (23:37 +0000)
committermistachkin <mistachkin@noemail.net>
Thu, 12 Jan 2017 23:37:52 +0000 (23:37 +0000)
FossilOrigin-Name: 6e388423c492c52aef221bd14f66482e0365d86d

manifest
manifest.uuid
src/os_win.c

index 5d1908313523ff28e59fce770ffb1c7e7203b133..c00f3abc4a8919c5ed31cfeed1310f8f80d848f6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Attempt\sto\sdetect\sphysical\ssector\ssizes\son\sWindows\s8\sand\shigher.
-D 2017-01-11T16:52:42.051
+C Attempt\sto\sdetect\sphysical\ssector\ssizes\son\sWindows\sVista\sand\shigher.
+D 2017-01-12T23:37:52.534
 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -373,7 +373,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 036b12e525724d3cbdd931a6e4439dea924b17bf
+F src/os_win.c 9fbb3876ef282302ef6df6471900f283f3e4b13b
 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
 F src/pager.c 9dc72d23eebbdf992bd69f2ab954d0d3a27c7340
 F src/pager.h d1e944291030351f362a0a7da9b5c3e34e603e39
@@ -1543,10 +1543,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 f58f75b5a06f88ba97bd1a02bee621c64691c6f8
-R d576d3178105de663378d6b438b5e84a
-T *branch * winSectorSize
-T *sym-winSectorSize *
-T -sym-trunk *
+P 381fd34b97ffe14f4bb784a9aae74477af699a08
+R 38a73ae0f111c05298e6affd34726ac4
 U mistachkin
-Z dade53828d1ccfadec45e309319f8c1a
+Z 05bcbcf820c10856a01bad7c2d3d9e2a
index 80c622bc30030b6a02f81cf84ee1373f589d445a..be64045ecee2b1dd8e94706c8956e0a949788bad 100644 (file)
@@ -1 +1 @@
-381fd34b97ffe14f4bb784a9aae74477af699a08
\ No newline at end of file
+6e388423c492c52aef221bd14f66482e0365d86d
\ No newline at end of file
index af731fa7bc610067cd488d3a48efc74d5221c25a..70b6360c0cde479c1e30bb5a27316591c7bea12c 100644 (file)
 ** Define the required Windows SDK version constants if they are not
 ** already available.
 */
+#ifndef _WIN32_WINNT_VISTA
+#  define _WIN32_WINNT_VISTA                0x0600
+#endif
+
 #ifndef _WIN32_WINNT_WIN8
 #  define _WIN32_WINNT_WIN8                 0x0602
 #endif
@@ -1139,6 +1143,16 @@ static struct win_syscall {
 #define osFlushViewOfFile \
         ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
 
+#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+  { "DeviceIoControl",          (SYSCALL)DeviceIoControl,        0 },
+#else
+  { "DeviceIoControl",          (SYSCALL)0,                      0 },
+#endif
+
+#define osDeviceIoControl ((BOOL(WINAPI*)( \
+        HANDLE,DWORD,LPVOID,DWORD,LPVOID,DWORD,LPVOID, \
+        LPOVERLAPPED))aSyscall[80].pCurrent)
+
 }; /* End of the overrideable system calls */
 
 /*
@@ -3557,6 +3571,7 @@ 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;
@@ -3567,7 +3582,48 @@ static int winSectorSize(sqlite3_file *id){
   }else{
     pFile->lastErrno = osGetLastError();
     winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
-                     "winSectorSize", pFile->zPath);
+                     "winSectorSize1", pFile->zPath);
+  }
+#elif defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+  winFile *pFile = (winFile*)id;
+  if( winIsDriveLetterAndColon(pFile->zPath) ){
+    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,
+                  "winSectorSize3", pFile->zPath);
+    }
   }
 #else
   (void)id;
@@ -5945,7 +6001,7 @@ int sqlite3_os_init(void){
 
   /* Double-check that the aSyscall[] array has been constructed
   ** correctly.  See ticket [bb3a86e890c8e96ab] */
-  assert( ArraySize(aSyscall)==80 );
+  assert( ArraySize(aSyscall)==81 );
 
   /* get memory map allocation granularity */
   memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));