SQLite

Check-in [6e388423c4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Attempt to detect physical sector sizes on Windows Vista and higher.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | winSectorSize
Files: files | file ages | folders
SHA1: 6e388423c492c52aef221bd14f66482e0365d86d
User & Date: mistachkin 2017-01-12 23:37:52.534
Context
2017-01-13
22:21
Merge updates from trunk. (check-in: 8b42b8e31a user: mistachkin tags: winSectorSize)
2017-01-12
23:37
Attempt to detect physical sector sizes on Windows Vista and higher. (check-in: 6e388423c4 user: mistachkin tags: winSectorSize)
2017-01-11
16:52
Attempt to detect physical sector sizes on Windows 8 and higher. (check-in: 381fd34b97 user: mistachkin tags: winSectorSize)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/os_win.c.
64
65
66
67
68
69
70




71
72
73
74
75
76
77
 must be defined."
#endif

/*
** Define the required Windows SDK version constants if they are not
** already available.
*/




#ifndef _WIN32_WINNT_WIN8
#  define _WIN32_WINNT_WIN8                 0x0602
#endif

#ifndef NTDDI_WIN8
#  define NTDDI_WIN8                        0x06020000
#endif







>
>
>
>







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 must be defined."
#endif

/*
** 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

#ifndef NTDDI_WIN8
#  define NTDDI_WIN8                        0x06020000
#endif
1134
1135
1136
1137
1138
1139
1140










1141
1142
1143
1144
1145
1146
1147
  { "FlushViewOfFile",          (SYSCALL)FlushViewOfFile,        0 },
#else
  { "FlushViewOfFile",          (SYSCALL)0,                      0 },
#endif

#define osFlushViewOfFile \
        ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)











}; /* End of the overrideable system calls */

/*
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
** system call pointer, or SQLITE_NOTFOUND if there is no configurable







>
>
>
>
>
>
>
>
>
>







1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
  { "FlushViewOfFile",          (SYSCALL)FlushViewOfFile,        0 },
#else
  { "FlushViewOfFile",          (SYSCALL)0,                      0 },
#endif

#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 */

/*
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
** system call pointer, or SQLITE_NOTFOUND if there is no configurable
3553
3554
3555
3556
3557
3558
3559

3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570









































3571
3572
3573
3574
3575
3576
3577
** a database and its journal file) that the sector size will be the
** same for both.
*/
static int winSectorSize(sqlite3_file *id){
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN8
  winFile *pFile = (winFile*)id;
  FILE_STORAGE_INFO 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,
                     "winSectorSize", pFile->zPath);









































  }
#else
  (void)id;
#endif
  return SQLITE_DEFAULT_SECTOR_SIZE;
}








>










|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
** a database and its journal file) that the sector size will be the
** same for both.
*/
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;
    }
  }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) ){
    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;
#endif
  return SQLITE_DEFAULT_SECTOR_SIZE;
}

5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
    winGetSystemCall,      /* xGetSystemCall */
    winNextSystemCall,     /* xNextSystemCall */
  };
#endif

  /* Double-check that the aSyscall[] array has been constructed
  ** correctly.  See ticket [bb3a86e890c8e96ab] */
  assert( ArraySize(aSyscall)==80 );

  /* get memory map allocation granularity */
  memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
#if SQLITE_OS_WINRT
  osGetNativeSystemInfo(&winSysInfo);
#else
  osGetSystemInfo(&winSysInfo);







|







5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
    winGetSystemCall,      /* xGetSystemCall */
    winNextSystemCall,     /* xNextSystemCall */
  };
#endif

  /* Double-check that the aSyscall[] array has been constructed
  ** correctly.  See ticket [bb3a86e890c8e96ab] */
  assert( ArraySize(aSyscall)==81 );

  /* get memory map allocation granularity */
  memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
#if SQLITE_OS_WINRT
  osGetNativeSystemInfo(&winSysInfo);
#else
  osGetSystemInfo(&winSysInfo);