/*
** Sync an vfstrace-file.
*/
        static int vfstraceSync(sqlite3_file pFile, int flags)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc;
            //int i;
            StringBuilder zBuf = new StringBuilder(100); //char zBuf[100];

            zBuf.Append("|0");                           //  memcpy( zBuf, "|0", 3 );
            if ((flags & SQLITE_SYNC_FULL) != 0)
            {
                zBuf.Append("|FULL");
            }
            else if ((flags & SQLITE_SYNC_NORMAL) != 0)
            {
                zBuf.Append("|NORMAL");
            }
            if ((flags & SQLITE_SYNC_DATAONLY) != 0)
            {
                zBuf.Append("|DATAONLY");
            }
            if ((flags & ~(SQLITE_SYNC_FULL | SQLITE_SYNC_DATAONLY)) != 0)
            {
                //sqlite3_snprintf(sizeof(zBuf)-i, &zBuf[i], "|0x%x", flags);
                Debugger.Break();//TODO
                //zBuf.Append( sqlite3_printf( "|0x%x", flags ) );
            }
            Debugger.Break();//TODO
            //  vfstrace_printf(pInfo, "%s.xSync(%s,%s)", pInfo.zVfsName, p.zFName,
            //              zBuf.ToString().StartsWith(1));
            rc = p.pReal.pMethods.xSync(p.pReal, flags);
            vfstrace_printf(pInfo, " . %d\n", rc);
            return(rc);
        }
        static void vfstraceShmBarrier(sqlite3_file pFile)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;

            vfstrace_printf(pInfo, "%s.xShmBarrier(%s)\n", pInfo.zVfsName, p.zFName);
            p.pReal.pMethods.xShmBarrier(p.pReal);
        }
/*
** Return the sector-size in bytes for an vfstrace-file.
*/
        static int vfstraceSectorSize(sqlite3_file pFile)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc;

            vfstrace_printf(pInfo, "%s.xSectorSize(%s)", pInfo.zVfsName, p.zFName);
            rc = p.pReal.pMethods.xSectorSize(p.pReal);
            vfstrace_printf(pInfo, " . %d\n", rc);
            return(rc);
        }
        static int vfstraceShmUnmap(sqlite3_file pFile, int delFlag)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc;

            vfstrace_printf(pInfo, "%s.xShmUnmap(%s,delFlag=%d)",
                            pInfo.zVfsName, p.zFName, delFlag);
            rc = p.pReal.pMethods.xShmUnmap(p.pReal, delFlag);
            vfstrace_print_errcode(pInfo, " . %s\n", rc);
            return(rc);
        }
/*
** Return the device characteristic flags supported by an vfstrace-file.
*/
        static int vfstraceDeviceCharacteristics(sqlite3_file pFile)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc;

            vfstrace_printf(pInfo, "%s.xDeviceCharacteristics(%s)",
                            pInfo.zVfsName, p.zFName);
            rc = p.pReal.pMethods.xDeviceCharacteristics(p.pReal);
            vfstrace_printf(pInfo, " . 0x%08x\n", rc);
            return(rc);
        }
/*
** Unlock an vfstrace-file.
*/
        static int vfstraceUnlock(sqlite3_file pFile, int eLock)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc;

            vfstrace_printf(pInfo, "%s.xUnlock(%s,%s)", pInfo.zVfsName, p.zFName,
                            lockName(eLock));
            rc = p.pReal.pMethods.xUnlock(p.pReal, eLock);
            vfstrace_print_errcode(pInfo, " . %s\n", rc);
            return(rc);
        }
/*
** Truncate an vfstrace-file.
*/
        static int vfstraceTruncate(sqlite3_file pFile, sqlite_int64 size)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc    = 0;

            vfstrace_printf(pInfo, "%s.xTruncate(%s,%lld)", pInfo.zVfsName, p.zFName,
                            size);
            rc = p.pReal.pMethods.xTruncate(p.pReal, size);
            vfstrace_printf(pInfo, " . %d\n", rc);
            return(rc);
        }
/*
** Return the current file-size of an vfstrace-file.
*/
        static int vfstraceFileSize(sqlite3_file pFile, sqlite_int64 pSize)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc    = 0;

            vfstrace_printf(pInfo, "%s.xFileSize(%s)", pInfo.zVfsName, p.zFName);
            Debugger.Break();//TODO
            //rc = p.pReal.pMethods.xFileSize(p.pReal, pSize);
            vfstrace_print_errcode(pInfo, " . %s,", rc);
            vfstrace_printf(pInfo, " size=%lld\n", pSize);
            return(rc);
        }
/*
** Check if another file-handle holds a RESERVED lock on an vfstrace-file.
*/
        static int vfstraceCheckReservedLock(sqlite3_file pFile, int pResOut)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc    = 0;

            vfstrace_printf(pInfo, "%s.xCheckReservedLock(%s,%d)",
                            pInfo.zVfsName, p.zFName);
            Debugger.Break();//TODO
            //rc = p.pReal.pMethods.xCheckReservedLock(p.pReal, pResOut);
            vfstrace_print_errcode(pInfo, " . %s", rc);
            vfstrace_printf(pInfo, ", ref=%d\n", pResOut);
            return(rc);
        }
/*
** Close an vfstrace-file.
*/
        static int vfstraceClose(sqlite3_file pFile)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc;

            vfstrace_printf(pInfo, "%s.xClose(%s)", pInfo.zVfsName, p.zFName);
            rc = p.pReal.pMethods.xClose(p.pReal);
            vfstrace_print_errcode(pInfo, " . %s\n", rc);
            if (rc == SQLITE_OK)
            {
                //sqlite3_free(p._base.pMethods);
                p.pMethods = null;//p.base.pMethods = 0;
            }
            return(rc);
        }
/*
** Write data to an vfstrace-file.
*/
        static int vfstraceWrite(
            sqlite3_file pFile,
            string zBuf,
            int iAmt,
            sqlite_int64 iOfst
            )
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc    = 0;

            vfstrace_printf(pInfo, "%s.xWrite(%s,n=%d,ofst=%lld)",
                            pInfo.zVfsName, p.zFName, iAmt, iOfst);
            Debugger.Break();//TODO
            //rc = p.pReal.pMethods.xWrite( p.pReal, zBuf, iAmt, iOfst );
            vfstrace_print_errcode(pInfo, " . %s\n", rc);
            return(rc);
        }
        static int vfstraceShmMap(
            sqlite3_file pFile,
            int iRegion,
            int szRegion,
            int isWrite,
            object pp
            )
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc    = 0;

            vfstrace_printf(pInfo, "%s.xShmMap(%s,iRegion=%d,szRegion=%d,isWrite=%d,)",
                            pInfo.zVfsName, p.zFName, iRegion, szRegion, isWrite);
            Debugger.Break();
            //rc = p.pReal.pMethods.xShmMap( p.pReal, iRegion, szRegion, isWrite, pp );
            vfstrace_print_errcode(pInfo, " . %s\n", rc);
            return(rc);
        }
/*
** File control method. For custom operations on an vfstrace-file.
*/
        static int vfstraceFileControl(sqlite3_file pFile, int op, object pArg)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc    = 0;

            Debugger.Break(); //TODO
            //StringBuilder zBuf = new StringBuilder(100);
            //string zOp;
            //switch( op ){
            //  case SQLITE_FCNTL_LOCKSTATE:    zOp = "LOCKSTATE";          break;
            //  case SQLITE_GET_LOCKPROXYFILE:  zOp = "GET_LOCKPROXYFILE";  break;
            //  case SQLITE_SET_LOCKPROXYFILE:  zOp = "SET_LOCKPROXYFILE";  break;
            //  case SQLITE_LAST_ERRNO:         zOp = "LAST_ERRNO";         break;
            //  case SQLITE_FCNTL_SIZE_HINT: {
            //    sqlite3_snprintf(sizeof(zBuf), zBuf, "SIZE_HINT,%lld",
            //                     *(sqlite3_int64)pArg);
            //    zOp = zBuf;
            //    break;
            //  }
            //  case SQLITE_FCNTL_CHUNK_SIZE: {
            //    sqlite3_snprintf(sizeof(zBuf), zBuf, "CHUNK_SIZE,%d", *(int)pArg);
            //    zOp = zBuf;
            //    break;
            //  }
            //  case SQLITE_FCNTL_FILE_POINTER: zOp = "FILE_POINTER";       break;
            //  case SQLITE_FCNTL_SYNC_OMITTED: zOp = "SYNC_OMITTED";       break;
            //  case 0xca093fa0:                zOp = "DB_UNCHANGED";       break;
            //  default: {
            //    sqlite3_snprintf(zBuf.Capacity, zBuf, "%d", op);
            //    zOp = zBuf.ToString();
            //    break;
            //  }
            //}
            //vfstrace_printf(pInfo, "%s.xFileControl(%s,%s)",
            //                pInfo.zVfsName, p.zFName, zOp);
            //rc = p.pReal.pMethods.xFileControl(p.pReal, op, pArg);
            //vfstrace_print_errcode(pInfo, " . %s\n", rc);
            return(rc);
        }
/*
** Shared-memory operations.
*/
        static int vfstraceShmLock(sqlite3_file pFile, int ofst, int n, int flags)
        {
            vfstrace_file p     = (vfstrace_file )pFile;
            vfstrace_info pInfo = p.pInfo;
            int           rc;
            StringBuilder zLck = new StringBuilder(100);

            //int i = 0;
            zLck.Append("|0");//memcpy( zLck, "|0", 3 );
            if ((flags & SQLITE_SHM_UNLOCK) != 0)
            {
                zLck.Append("|UNLOCK");//strappend(zLck, &i, "|UNLOCK");
            }
            if ((flags & SQLITE_SHM_LOCK) != 0)
            {
                zLck.Append("|LOCK");//strappend(zLck, &i, "|LOCK");
            }
            if ((flags & SQLITE_SHM_SHARED) != 0)
            {
                zLck.Append("|SHARED");//strappend(zLck, &i, "|SHARED");
            }
            if ((flags & SQLITE_SHM_EXCLUSIVE) != 0)
            {
                zLck.Append("|EXCLUSIVE");//strappend(zLck, &i, "|EXCLUSIVE");
            }
            if ((flags & ~(0xf)) != 0)
            {
                Debugger.Break();//TODO
                //zLck.Append( sqlite3_printf( "|0x%x", flags ) );//sqlite3_snprintf(sizeof(zLck)-i, &zLck[i], "|0x%x", flags);
            }
            //vfstrace_printf(pInfo, "%s.xShmLock(%s,ofst=%d,n=%d,%s)",
            //                pInfo.zVfsName, p.zFName, ofst, n, &zLck[1]);
            rc = p.pReal.pMethods.xShmLock(p.pReal, ofst, n, flags);
            vfstrace_print_errcode(pInfo, " . %s\n", rc);
            return(rc);
        }