@@ -107,7 +107,57 @@ static const int walFileHeaderSize = 32;
107107/*
108108** Global I/O method structure of SQLite3 Multiple Ciphers VFS
109109*/
110- static sqlite3_io_methods mcIoMethodsGlobal =
110+
111+ #define IOMETHODS_VERSION_MIN 1
112+ #define IOMETHODS_VERSION_MAX 3
113+
114+ static sqlite3_io_methods mcIoMethodsGlobal1 =
115+ {
116+ 1 , /* iVersion */
117+ mcIoClose , /* xClose */
118+ mcIoRead , /* xRead */
119+ mcIoWrite , /* xWrite */
120+ mcIoTruncate , /* xTruncate */
121+ mcIoSync , /* xSync */
122+ mcIoFileSize , /* xFileSize */
123+ mcIoLock , /* xLock */
124+ mcIoUnlock , /* xUnlock */
125+ mcIoCheckReservedLock , /* xCheckReservedLock */
126+ mcIoFileControl , /* xFileControl */
127+ mcIoSectorSize , /* xSectorSize */
128+ mcIoDeviceCharacteristics , /* xDeviceCharacteristics */
129+ 0 , /* xShmMap */
130+ 0 , /* xShmLock */
131+ 0 , /* xShmBarrier */
132+ 0 , /* xShmUnmap */
133+ 0 , /* xFetch */
134+ 0 , /* xUnfetch */
135+ };
136+
137+ static sqlite3_io_methods mcIoMethodsGlobal2 =
138+ {
139+ 2 , /* iVersion */
140+ mcIoClose , /* xClose */
141+ mcIoRead , /* xRead */
142+ mcIoWrite , /* xWrite */
143+ mcIoTruncate , /* xTruncate */
144+ mcIoSync , /* xSync */
145+ mcIoFileSize , /* xFileSize */
146+ mcIoLock , /* xLock */
147+ mcIoUnlock , /* xUnlock */
148+ mcIoCheckReservedLock , /* xCheckReservedLock */
149+ mcIoFileControl , /* xFileControl */
150+ mcIoSectorSize , /* xSectorSize */
151+ mcIoDeviceCharacteristics , /* xDeviceCharacteristics */
152+ mcIoShmMap , /* xShmMap */
153+ mcIoShmLock , /* xShmLock */
154+ mcIoShmBarrier , /* xShmBarrier */
155+ mcIoShmUnmap , /* xShmUnmap */
156+ 0 , /* xFetch */
157+ 0 , /* xUnfetch */
158+ };
159+
160+ static sqlite3_io_methods mcIoMethodsGlobal3 =
111161{
112162 3 , /* iVersion */
113163 mcIoClose , /* xClose */
@@ -130,6 +180,9 @@ static sqlite3_io_methods mcIoMethodsGlobal =
130180 mcIoUnfetch , /* xUnfetch */
131181};
132182
183+ static sqlite3_io_methods * mcIoMethodsGlobal [] =
184+ { 0 , & mcIoMethodsGlobal1 , & mcIoMethodsGlobal2 , & mcIoMethodsGlobal3 };
185+
133186/*
134187** Internal functions
135188*/
@@ -304,7 +357,9 @@ SQLITE_PRIVATE void* sqlite3mcPagerCodec(PgHdrMC* pPg)
304357{
305358 sqlite3_file * pFile = sqlite3PagerFile (pPg -> pPager );
306359 void * aData = 0 ;
307- if (pFile -> pMethods == & mcIoMethodsGlobal )
360+ if (pFile -> pMethods == & mcIoMethodsGlobal1 ||
361+ pFile -> pMethods == & mcIoMethodsGlobal2 ||
362+ pFile -> pMethods == & mcIoMethodsGlobal3 )
308363 {
309364 sqlite3mc_file * mcFile = (sqlite3mc_file * ) pFile ;
310365 Codec * codec = mcFile -> codec ;
@@ -406,9 +461,18 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
406461 if (rc == SQLITE_OK )
407462 {
408463 /*
409- ** Real open succeeded, initialize methods, register main database files
464+ ** Real open succeeded
465+ ** Initialize methods (use same version number as underlying implementation
466+ ** Register main database files
410467 */
411- pFile -> pMethods = & mcIoMethodsGlobal ;
468+ int ioMethodsVersion = mcFile -> pFile -> pMethods -> iVersion ;
469+ if (ioMethodsVersion < IOMETHODS_VERSION_MIN ||
470+ ioMethodsVersion > IOMETHODS_VERSION_MAX )
471+ {
472+ /* If version out of range, use highest known version */
473+ ioMethodsVersion = IOMETHODS_VERSION_MAX ;
474+ }
475+ pFile -> pMethods = mcIoMethodsGlobal [ioMethodsVersion ];
412476 if (flags & SQLITE_OPEN_MAIN_DB )
413477 {
414478 mcMainListAdd (mcFile );
@@ -1194,7 +1258,10 @@ static int mcIoFileControl(sqlite3_file* pFile, int op, void* pArg)
11941258
11951259static int mcIoSectorSize (sqlite3_file * pFile )
11961260{
1197- return REALFILE (pFile )-> pMethods -> xSectorSize (REALFILE (pFile ));
1261+ if (REALFILE (pFile )-> pMethods -> xSectorSize )
1262+ return REALFILE (pFile )-> pMethods -> xSectorSize (REALFILE (pFile ));
1263+ else
1264+ return SQLITE_DEFAULT_SECTOR_SIZE ;
11981265}
11991266
12001267static int mcIoDeviceCharacteristics (sqlite3_file * pFile )
0 commit comments