Esempio n. 1
0
bool CSimpleEncryptedVFS::Setup()
{
	if (GetDelegate() != nullptr)
	{
		return true;
	}

	sqlite3_vfs *vfs = sqlite3_vfs_find("win32");
	if (vfs == nullptr)
	{
		return false;
	}

	iVersion = vfs->iVersion;
	szOsFile = sizeof(FileInfo) + vfs->szOsFile - sizeof(sqlite3_file);
	mxPathname = vfs->mxPathname;
	pNext = nullptr;
	zName = "CSimpleEncryptedVFS";
	pAppData = nullptr;

	if (SQLITE_OK != sqlite3_vfs_register(this, 1))
	{
		return false;
	}

	SetDelegate(vfs);
	return true;
}
void SQLiteFileSystem::registerSQLiteVFS()
{
    // FIXME: Make sure there aren't any unintended consequences when VFS code is called in the browser process.
    if (!ChromiumBridge::sandboxEnabled()) {
        ASSERT_NOT_REACHED();
        return;
    }

    sqlite3_vfs* win32_vfs = sqlite3_vfs_find("win32");
    static sqlite3_vfs chromium_vfs = {
        1,
        win32_vfs->szOsFile,
        win32_vfs->mxPathname,
        0,
        "chromium_vfs",
        win32_vfs->pAppData,
        chromiumOpen,
        chromiumDelete,
        chromiumAccess,
        chromiumFullPathname,
        chromiumDlOpen,
        win32_vfs->xDlError,
        win32_vfs->xDlSym,
        win32_vfs->xDlClose,
        win32_vfs->xRandomness,
        win32_vfs->xSleep,
        win32_vfs->xCurrentTime,
        win32_vfs->xGetLastError
    };
    sqlite3_vfs_register(&chromium_vfs, 1);
}
Esempio n. 3
0
/*
** Initialize and deinitialize the operating system interface.
*/
int sqlite3_os_init(void){
  static sqlite3_vfs os2Vfs = {
    1,                 /* iVersion */
    sizeof(os2File),   /* szOsFile */
    CCHMAXPATH,        /* mxPathname */
    0,                 /* pNext */
    "os2",             /* zName */
    0,                 /* pAppData */

    os2Open,           /* xOpen */
    os2Delete,         /* xDelete */
    os2Access,         /* xAccess */
    os2FullPathname,   /* xFullPathname */
    os2DlOpen,         /* xDlOpen */
    os2DlError,        /* xDlError */
    os2DlSym,          /* xDlSym */
    os2DlClose,        /* xDlClose */
    os2Randomness,     /* xRandomness */
    os2Sleep,          /* xSleep */
    os2CurrentTime,    /* xCurrentTime */
    os2GetLastError    /* xGetLastError */
  };
  sqlite3_vfs_register(&os2Vfs, 1);
  initUconvObjects();
  return SQLITE_OK;
}
void SQLiteFileSystem::registerSQLiteVFS()
{
    sqlite3_vfs* wrappedVfs = sqlite3_vfs_find("win32");
    static sqlite3_vfs chromium_vfs = {
        1,
        wrappedVfs->szOsFile,
        wrappedVfs->mxPathname,
        0,
        "chromium_vfs",
        wrappedVfs,
        chromiumOpen,
        chromiumDelete,
        chromiumAccess,
        chromiumFullPathname,
        chromiumDlOpen,
        chromiumDlError,
        chromiumDlSym,
        chromiumDlClose,
        chromiumRandomness,
        chromiumSleep,
        chromiumCurrentTime,
        chromiumGetLastError
    };
    sqlite3_vfs_register(&chromium_vfs, 0);
}
void sqlite3_bctbx_vfs_register( int makeDefault){
	sqlite3_vfs* pVfsToUse = sqlite3_bctbx_vfs_create();
	#if _WIN32
	sqlite3_vfs* pDefault = sqlite3_vfs_find("win32");
	#else
	sqlite3_vfs* pDefault = sqlite3_vfs_find("unix-none");
	#endif
	pVfsToUse->xCurrentTime = pDefault->xCurrentTime;
	
	pVfsToUse->xAccess =  pDefault->xAccess;
	pVfsToUse->xFullPathname = pDefault->xFullPathname;

	pVfsToUse->xDelete = pDefault->xDelete;
	pVfsToUse->xSleep = pDefault->xSleep;
	pVfsToUse->xRandomness = pDefault->xRandomness;
	pVfsToUse->xGetLastError = pDefault->xGetLastError; /* Not implemented by sqlite3 :place holder */
	/*Functions below should not be a problem sincve we are declaring ourselves
	 in version 1 */

	/* used in version 2
	xCurrentTimeInt64;*/
	/* used in version 3
	xGetSystemCall
	xSetSystemCall
	xNextSystemCall*/

	sqlite3_vfs_register(pVfsToUse, makeDefault);

}
Esempio n. 6
0
int register_little_ro_vfs(int makeDflt) {
    struct sqlite3_vfs *un;
    un = sqlite3_vfs_find("unix");
    if (un == NULL) return -1;
    sqlite3_vfs_register(init_little_ro_vfs(un), makeDflt);
    return 0;
}
Esempio n. 7
0
File: vfs.c Progetto: Allba/showtime
int
sqlite3_os_init(void)
{
  random_seed = arch_get_seed();
  sqlite3_vfs_register(&vfs, 1);
  return SQLITE_OK; 
}
Esempio n. 8
0
void FYF_API_sql_init(void)
{
	sqlite3_vfs_register(&winVfs,0);

	//FYF_API_sql_test();
	//FYF_API_fls_test();
}
Esempio n. 9
0
/*
** Clients invoke this routine to construct a new trace-vfs shim.
**
** Return SQLITE_OK on success.  
**
** SQLITE_NOMEM is returned in the case of a memory allocation error.
** SQLITE_NOTFOUND is returned if zOldVfsName does not exist.
*/
int vfstrace_register(
   const char *zTraceName,           /* Name of the newly constructed VFS */
   const char *zOldVfsName,          /* Name of the underlying VFS */
   int (*xOut)(const char*,void*),   /* Output routine.  ex: fputs */
   void *pOutArg,                    /* 2nd argument to xOut.  ex: stderr */
   int makeDefault                   /* True to make the new VFS the default */
){
  sqlite3_vfs *pNew;
  sqlite3_vfs *pRoot;
  vfstrace_info *pInfo;
  int nName;
  int nByte;

  pRoot = sqlite3_vfs_find(zOldVfsName);
  if( pRoot==0 ) return SQLITE_NOTFOUND;
  nName = strlen(zTraceName);
  nByte = sizeof(*pNew) + sizeof(*pInfo) + nName + 1;
  pNew = sqlite3_malloc( nByte );
  if( pNew==0 ) return SQLITE_NOMEM;
  memset(pNew, 0, nByte);
  pInfo = (vfstrace_info*)&pNew[1];
  pNew->iVersion = pRoot->iVersion;
  pNew->szOsFile = pRoot->szOsFile + sizeof(vfstrace_file);
  pNew->mxPathname = pRoot->mxPathname;
  pNew->zName = (char*)&pInfo[1];
  memcpy((char*)&pInfo[1], zTraceName, nName+1);
  pNew->pAppData = pInfo;
  pNew->xOpen = vfstraceOpen;
  pNew->xDelete = vfstraceDelete;
  pNew->xAccess = vfstraceAccess;
  pNew->xFullPathname = vfstraceFullPathname;
  pNew->xDlOpen = pRoot->xDlOpen==0 ? 0 : vfstraceDlOpen;
  pNew->xDlError = pRoot->xDlError==0 ? 0 : vfstraceDlError;
  pNew->xDlSym = pRoot->xDlSym==0 ? 0 : vfstraceDlSym;
  pNew->xDlClose = pRoot->xDlClose==0 ? 0 : vfstraceDlClose;
  pNew->xRandomness = vfstraceRandomness;
  pNew->xSleep = vfstraceSleep;
  pNew->xCurrentTime = vfstraceCurrentTime;
  pNew->xGetLastError = pRoot->xGetLastError==0 ? 0 : vfstraceGetLastError;
  if( pNew->iVersion>=2 ){
    pNew->xCurrentTimeInt64 = pRoot->xCurrentTimeInt64==0 ? 0 :
                                   vfstraceCurrentTimeInt64;
    if( pNew->iVersion>=3 ){
      pNew->xSetSystemCall = pRoot->xSetSystemCall==0 ? 0 : 
                                   vfstraceSetSystemCall;
      pNew->xGetSystemCall = pRoot->xGetSystemCall==0 ? 0 : 
                                   vfstraceGetSystemCall;
      pNew->xNextSystemCall = pRoot->xNextSystemCall==0 ? 0 : 
                                   vfstraceNextSystemCall;
    }
  }
  pInfo->pRootVfs = pRoot;
  pInfo->xOut = xOut;
  pInfo->pOutArg = pOutArg;
  pInfo->zVfsName = pNew->zName;
  pInfo->pTraceVfs = pNew;
  vfstrace_printf(pInfo, "%s.enabled_for(\"%s\")\n",
       pInfo->zVfsName, pRoot->zName);
  return sqlite3_vfs_register(pNew, makeDefault);
}
Esempio n. 10
0
void SQLiteFileSystem::registerSQLiteVFS() {
  sqlite3_vfs* wrappedVfs = sqlite3_vfs_find("win32");

  // These are implemented by delegating to |wrappedVfs|.
  // TODO(shess): Implement local versions.
  ASSERT(wrappedVfs->xRandomness);
  ASSERT(wrappedVfs->xSleep);
  ASSERT(wrappedVfs->xCurrentTime);

  static sqlite3_vfs chromium_vfs = {1,
                                     wrappedVfs->szOsFile,
                                     wrappedVfs->mxPathname,
                                     0,
                                     "chromium_vfs",
                                     wrappedVfs,
                                     chromiumOpen,
                                     chromiumDelete,
                                     chromiumAccess,
                                     chromiumFullPathname,
                                     chromiumDlOpen,
                                     chromiumDlError,
                                     chromiumDlSym,
                                     chromiumDlClose,
                                     chromiumRandomness,
                                     chromiumSleep,
                                     chromiumCurrentTime,
                                     chromiumGetLastError};
  sqlite3_vfs_register(&chromium_vfs, 0);
}
void SQLiteFileSystem::registerSQLiteVFS()
{
    sqlite3_vfs* unix_vfs = sqlite3_vfs_find("unix");
    static sqlite3_vfs chromium_vfs = {
        1,
        unix_vfs->szOsFile,
        unix_vfs->mxPathname,
        0,
        "chromium_vfs",
        unix_vfs->pAppData,
        chromiumOpen,
        chromiumDelete,
        chromiumAccess,
        chromiumFullPathname,
        chromiumDlOpen,
        unix_vfs->xDlError,
        unix_vfs->xDlSym,
        unix_vfs->xDlClose,
        unix_vfs->xRandomness,
        unix_vfs->xSleep,
        unix_vfs->xCurrentTime,
        unix_vfs->xGetLastError
    };
    sqlite3_vfs_register(&chromium_vfs, 0);
}
Esempio n. 12
0
/*
 ** This procedure registers the fs vfs with SQLite. If the argument is
 ** true, the fs vfs becomes the new default vfs. It is the only publicly
 ** available function in this file.
 */
int register_fs_channel(int channel_id){
#ifndef ORIGIN
	fs_vfs.input_channel_fd = channel_id;
#endif
	fs_vfs.base.mxPathname = MAX_PATH_NAME;
	fs_vfs.base.szOsFile = sizeof(tmp_file);
	return sqlite3_vfs_register(&fs_vfs.base, 1);
}
Esempio n. 13
0
/*
** CAPI: Initialize the multiplex VFS shim - sqlite3_multiplex_initialize()
**
** Use the VFS named zOrigVfsName as the VFS that does the actual work.  
** Use the default if zOrigVfsName==NULL.  
**
** The multiplex VFS shim is named "multiplex".  It will become the default
** VFS if makeDefault is non-zero.
**
** THIS ROUTINE IS NOT THREADSAFE.  Call this routine exactly once
** during start-up.
*/
int sqlite3_multiplex_initialize(const char *zOrigVfsName, int makeDefault){
  sqlite3_vfs *pOrigVfs;
  if( gMultiplex.isInitialized ) return SQLITE_MISUSE;
  pOrigVfs = sqlite3_vfs_find(zOrigVfsName);
  if( pOrigVfs==0 ) return SQLITE_ERROR;
  assert( pOrigVfs!=&gMultiplex.sThisVfs );
  gMultiplex.pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  if( !gMultiplex.pMutex ){
    return SQLITE_NOMEM;
  }
  gMultiplex.pGroups = NULL;
  gMultiplex.isInitialized = 1;
  gMultiplex.pOrigVfs = pOrigVfs;
  gMultiplex.sThisVfs = *pOrigVfs;
  gMultiplex.sThisVfs.szOsFile += sizeof(multiplexConn);
  gMultiplex.sThisVfs.zName = SQLITE_MULTIPLEX_VFS_NAME;
  gMultiplex.sThisVfs.xOpen = multiplexOpen;
  gMultiplex.sThisVfs.xDelete = multiplexDelete;
  gMultiplex.sThisVfs.xAccess = multiplexAccess;
  gMultiplex.sThisVfs.xFullPathname = multiplexFullPathname;
  gMultiplex.sThisVfs.xDlOpen = multiplexDlOpen;
  gMultiplex.sThisVfs.xDlError = multiplexDlError;
  gMultiplex.sThisVfs.xDlSym = multiplexDlSym;
  gMultiplex.sThisVfs.xDlClose = multiplexDlClose;
  gMultiplex.sThisVfs.xRandomness = multiplexRandomness;
  gMultiplex.sThisVfs.xSleep = multiplexSleep;
  gMultiplex.sThisVfs.xCurrentTime = multiplexCurrentTime;
  gMultiplex.sThisVfs.xGetLastError = multiplexGetLastError;
  gMultiplex.sThisVfs.xCurrentTimeInt64 = multiplexCurrentTimeInt64;

  gMultiplex.sIoMethodsV1.iVersion = 1;
  gMultiplex.sIoMethodsV1.xClose = multiplexClose;
  gMultiplex.sIoMethodsV1.xRead = multiplexRead;
  gMultiplex.sIoMethodsV1.xWrite = multiplexWrite;
  gMultiplex.sIoMethodsV1.xTruncate = multiplexTruncate;
  gMultiplex.sIoMethodsV1.xSync = multiplexSync;
  gMultiplex.sIoMethodsV1.xFileSize = multiplexFileSize;
  gMultiplex.sIoMethodsV1.xLock = multiplexLock;
  gMultiplex.sIoMethodsV1.xUnlock = multiplexUnlock;
  gMultiplex.sIoMethodsV1.xCheckReservedLock = multiplexCheckReservedLock;
  gMultiplex.sIoMethodsV1.xFileControl = multiplexFileControl;
  gMultiplex.sIoMethodsV1.xSectorSize = multiplexSectorSize;
  gMultiplex.sIoMethodsV1.xDeviceCharacteristics =
                                            multiplexDeviceCharacteristics;
  gMultiplex.sIoMethodsV2 = gMultiplex.sIoMethodsV1;
  gMultiplex.sIoMethodsV2.iVersion = 2;
  gMultiplex.sIoMethodsV2.xShmMap = multiplexShmMap;
  gMultiplex.sIoMethodsV2.xShmLock = multiplexShmLock;
  gMultiplex.sIoMethodsV2.xShmBarrier = multiplexShmBarrier;
  gMultiplex.sIoMethodsV2.xShmUnmap = multiplexShmUnmap;
  sqlite3_vfs_register(&gMultiplex.sThisVfs, makeDefault);

  sqlite3_auto_extension((void*)multiplexFuncInit);

  return SQLITE_OK;
}
Esempio n. 14
0
static void InitSqliteVFS()
{
	assert(g_NitSqliteVFS == NULL);

	Database::initialize();

	g_NitSqliteVFS = new NitSqliteVFS();

	sqlite3_vfs_register(g_NitSqliteVFS, 0);
}
Esempio n. 15
0
/* 
** This routine is called when the extension is loaded.
** Register the new VFS.
*/
int sqlite3MemdbInit(void){
  sqlite3_vfs *pLower = sqlite3_vfs_find(0);
  int sz = pLower->szOsFile;
  memdb_vfs.pAppData = pLower;
  /* In all known configurations of SQLite, the size of a default
  ** sqlite3_file is greater than the size of a memdb sqlite3_file.
  ** Should that ever change, remove the following NEVER() */
  if( NEVER(sz<sizeof(MemFile)) ) sz = sizeof(MemFile);
  memdb_vfs.szOsFile = sz;
  return sqlite3_vfs_register(&memdb_vfs, 0);
}
Esempio n. 16
0
/*
** This procedure registers the devsym vfs with SQLite. If the argument is
** true, the devsym vfs becomes the new default vfs. It is the only publicly
** available function in this file.
*/
void devsym_register(int iDeviceChar, int iSectorSize){
  if( g.pVfs==0 ){
    g.pVfs = sqlite3_vfs_find(0);
    devsym_vfs.szOsFile += g.pVfs->szOsFile;
    sqlite3_vfs_register(&devsym_vfs, 0);
  }
  if( iDeviceChar>=0 ){
    g.iDeviceChar = iDeviceChar;
  }
  if( iSectorSize>=0 ){
    g.iSectorSize = iSectorSize;
  }
}
/*
** Configure the jt VFS as a wrapper around the VFS named by parameter 
** zWrap. If the isDefault parameter is true, then the jt VFS is installed
** as the new default VFS for SQLite connections. If isDefault is not
** true, then the jt VFS is installed as non-default. In this case it
** is available via its name, "jt".
*/
int jt_register(char *zWrap, int isDefault){
  g.pVfs = sqlite3_vfs_find(zWrap);
  if( g.pVfs==0 ){
    return SQLITE_ERROR;
  }
  jt_vfs.szOsFile = sizeof(jt_file) + g.pVfs->szOsFile;
  if( g.pVfs->iVersion==1 ){
    jt_vfs.iVersion = 1;
  }else if( g.pVfs->xCurrentTimeInt64==0 ){
    jt_vfs.xCurrentTimeInt64 = 0;
  }
  sqlite3_vfs_register(&jt_vfs, isDefault);
  return SQLITE_OK;
}
Esempio n. 18
0
int sqlite3_embedded_initialize(const char* zOrigVfsName, int makeDefault) {
  sqlite3_vfs* pOrigVfs;
  if (gEmbedded.isInitialized) return SQLITE_MISUSE;
  pOrigVfs = sqlite3_vfs_find(zOrigVfsName);
  if (pOrigVfs==0) return SQLITE_ERROR;
  assert(pOrigVfs!=&gEmbedded.sThisVfs);
  gEmbedded.pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  if (!gEmbedded.pMutex) {
    return SQLITE_NOMEM;
  }

  gEmbedded.isInitialized = 1;
  gEmbedded.pOrigVfs = pOrigVfs;
  gEmbedded.sThisVfs = *pOrigVfs;
  gEmbedded.sThisVfs.szOsFile += sizeof(embeddedConn);
  gEmbedded.sThisVfs.zName = "embedded";
  gEmbedded.sThisVfs.xOpen = embeddedOpen;
  gEmbedded.sThisVfs.xDelete = embeddedDelete;
  gEmbedded.sThisVfs.xAccess = embeddedAccess;
  gEmbedded.sThisVfs.xFullPathname = embeddedFullPathname;
  gEmbedded.sThisVfs.xDlOpen = embeddedDlOpen;
  gEmbedded.sThisVfs.xDlError = embeddedDlError;
  gEmbedded.sThisVfs.xDlSym = embeddedDlSym;
  gEmbedded.sThisVfs.xDlClose = embeddedDlClose;
  gEmbedded.sThisVfs.xRandomness = embeddedRandomness;
  gEmbedded.sThisVfs.xSleep = embeddedSleep;
  gEmbedded.sThisVfs.xCurrentTime = embeddedCurrentTime;
  gEmbedded.sThisVfs.xGetLastError = embeddedGetLastError;
  gEmbedded.sThisVfs.xCurrentTimeInt64 = embeddedCurrentTimeInt64;

  gEmbedded.sIoMethodsV1.iVersion = 1;
  gEmbedded.sIoMethodsV1.xClose = embeddedClose;
  gEmbedded.sIoMethodsV1.xRead = embeddedRead;
  gEmbedded.sIoMethodsV1.xWrite = embeddedWrite;
  gEmbedded.sIoMethodsV1.xTruncate = embeddedTruncate;
  gEmbedded.sIoMethodsV1.xSync = embeddedSync;
  gEmbedded.sIoMethodsV1.xFileSize = embeddedFileSize;
  gEmbedded.sIoMethodsV1.xLock = embeddedLock;
  gEmbedded.sIoMethodsV1.xUnlock = embeddedUnlock;
  gEmbedded.sIoMethodsV1.xCheckReservedLock = embeddedCheckReservedLock;
  gEmbedded.sIoMethodsV1.xFileControl = embeddedFileControl;
  gEmbedded.sIoMethodsV1.xSectorSize = embeddedSectorSize;
  gEmbedded.sIoMethodsV1.xDeviceCharacteristics =
    embeddedDeviceCharacteristics;

  sqlite3_vfs_register(&gEmbedded.sThisVfs, makeDefault);

  return SQLITE_OK;
}
nsresult
Service::initialize()
{
  NS_TIME_FUNCTION;

  int rc;

#ifdef MOZ_STORAGE_MEMORY
  rc = ::sqlite3_config(SQLITE_CONFIG_MALLOC, &memMethods);
  if (rc != SQLITE_OK)
    return convertResultCode(rc);
#endif

  // Explicitly initialize sqlite3.  Although this is implicitly called by
  // various sqlite3 functions (and the sqlite3_open calls in our case),
  // the documentation suggests calling this directly.  So we do.
  rc = ::sqlite3_initialize();
  if (rc != SQLITE_OK)
    return convertResultCode(rc);

  mSqliteVFS = ConstructTelemetryVFS();
  if (mSqliteVFS) {
    rc = sqlite3_vfs_register(mSqliteVFS, 1);
    if (rc != SQLITE_OK)
      return convertResultCode(rc);
  } else {
    NS_WARNING("Failed to register telemetry VFS");
  }
  rc = ::sqlite3_quota_initialize("telemetry-vfs", 0);
  if (rc != SQLITE_OK)
    return convertResultCode(rc);

  // Set the default value for the toolkit.storage.synchronous pref.  It will be
  // updated with the user preference on the main thread.
  sSynchronousPref = PREF_TS_SYNCHRONOUS_DEFAULT;

  // Run the things that need to run on the main thread there.
  nsCOMPtr<nsIRunnable> event =
    new ServiceMainThreadInitializer(this, this, &sXPConnect, &sSynchronousPref);
  if (event && ::NS_IsMainThread()) {
    (void)event->Run();
  }
  else {
    (void)::NS_DispatchToMainThread(event);
  }

  return NS_OK;
}
Esempio n. 20
0
/*
** Register the VFS that reads from the g.aFile[] set of files.
*/
static void inmemVfsRegister(void){
  static sqlite3_vfs inmemVfs;
  sqlite3_vfs *pDefault = sqlite3_vfs_find(0);
  inmemVfs.iVersion = 3;
  inmemVfs.szOsFile = sizeof(VHandle);
  inmemVfs.mxPathname = 200;
  inmemVfs.zName = "inmem";
  inmemVfs.xOpen = inmemOpen;
  inmemVfs.xDelete = inmemDelete;
  inmemVfs.xAccess = inmemAccess;
  inmemVfs.xFullPathname = inmemFullPathname;
  inmemVfs.xRandomness = pDefault->xRandomness;
  inmemVfs.xSleep = pDefault->xSleep;
  inmemVfs.xCurrentTimeInt64 = pDefault->xCurrentTimeInt64;
  sqlite3_vfs_register(&inmemVfs, 0);
};
Esempio n. 21
0
int spmemvfs_init( spmemvfs_cb_t * cb )
{
	sqlite3_vfs * parent = NULL;

	if( g_spmemvfs.parent ) return SQLITE_OK;

	parent = sqlite3_vfs_find( 0 );

	g_spmemvfs.parent = parent;

	g_spmemvfs.base.mxPathname = parent->mxPathname;
	g_spmemvfs.base.szOsFile = sizeof( spmemfile_t );

	g_spmemvfs.cb = * cb;

	return sqlite3_vfs_register( (sqlite3_vfs*)&g_spmemvfs, 0 );
}
Esempio n. 22
0
nsresult
Service::initialize()
{
  MOZ_ASSERT(NS_IsMainThread(), "Must be initialized on the main thread");

  int rc = AutoSQLiteLifetime::getInitResult();
  if (rc != SQLITE_OK)
    return convertResultCode(rc);

  mSqliteVFS = ConstructTelemetryVFS();
  if (mSqliteVFS) {
    rc = sqlite3_vfs_register(mSqliteVFS, 0);
    if (rc != SQLITE_OK)
      return convertResultCode(rc);
  } else {
    NS_WARNING("Failed to register telemetry VFS");
  }

  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
  NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);

  for (size_t i = 0; i < ArrayLength(sObserverTopics); ++i) {
    nsresult rv = os->AddObserver(this, sObserverTopics[i], false);
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }
  }

  // We need to obtain the toolkit.storage.synchronous preferences on the main
  // thread because the preference service can only be accessed there.  This
  // is cached in the service for all future Open[Unshared]Database calls.
  sSynchronousPref =
    Preferences::GetInt(PREF_TS_SYNCHRONOUS, PREF_TS_SYNCHRONOUS_DEFAULT);

  // We need to obtain the toolkit.storage.pageSize preferences on the main
  // thread because the preference service can only be accessed there.  This
  // is cached in the service for all future Open[Unshared]Database calls.
  sDefaultPageSize =
      Preferences::GetInt(PREF_TS_PAGESIZE, PREF_TS_PAGESIZE_DEFAULT);

  mozilla::RegisterWeakMemoryReporter(this);
  mozilla::RegisterStorageSQLiteDistinguishedAmount(StorageSQLiteDistinguishedAmount);

  return NS_OK;
}
Esempio n. 23
0
int sqltorrent_init(int make_default)
{
	static context ctx;
	static sqlite3_vfs vfs;
	if (!ctx.base)
	{
		ctx.base = sqlite3_vfs_find(nullptr);
		vfs = *ctx.base;
		vfs.zName = "torrent";
		vfs.pAppData = &ctx;
		vfs.szOsFile = sizeof(torrent_vfs_file);
		vfs.xOpen = torrent_vfs_open;
		vfs.xAccess = torrent_vfs_access;
	}

	sqlite3_vfs_register(&vfs, make_default);

	return SQLITE_OK;
}
Esempio n. 24
0
/*
** Initialize the quota VFS shim.  Use the VFS named zOrigVfsName
** as the VFS that does the actual work.  Use the default if
** zOrigVfsName==NULL.  
**
** The quota VFS shim is named "quota".  It will become the default
** VFS if makeDefault is non-zero.
**
** THIS ROUTINE IS NOT THREADSAFE.  Call this routine exactly once
** during start-up.
*/
int sqlite3_quota_initialize(const char *zOrigVfsName, int makeDefault){
  sqlite3_vfs *pOrigVfs;
  if( gQuota.isInitialized ) return SQLITE_MISUSE;
  pOrigVfs = sqlite3_vfs_find(zOrigVfsName);
  if( pOrigVfs==0 ) return SQLITE_ERROR;
  assert( pOrigVfs!=&gQuota.sThisVfs );
  gQuota.pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  if( !gQuota.pMutex ){
    return SQLITE_NOMEM;
  }
  gQuota.isInitialized = 1;
  gQuota.pOrigVfs = pOrigVfs;
  gQuota.sThisVfs = *pOrigVfs;
  gQuota.sThisVfs.xOpen = quotaOpen;
  gQuota.sThisVfs.xDelete = quotaDelete;
  gQuota.sThisVfs.szOsFile += sizeof(quotaConn);
  gQuota.sThisVfs.zName = "quota";
  gQuota.sIoMethodsV1.iVersion = 1;
  gQuota.sIoMethodsV1.xClose = quotaClose;
  gQuota.sIoMethodsV1.xRead = quotaRead;
  gQuota.sIoMethodsV1.xWrite = quotaWrite;
  gQuota.sIoMethodsV1.xTruncate = quotaTruncate;
  gQuota.sIoMethodsV1.xSync = quotaSync;
  gQuota.sIoMethodsV1.xFileSize = quotaFileSize;
  gQuota.sIoMethodsV1.xLock = quotaLock;
  gQuota.sIoMethodsV1.xUnlock = quotaUnlock;
  gQuota.sIoMethodsV1.xCheckReservedLock = quotaCheckReservedLock;
  gQuota.sIoMethodsV1.xFileControl = quotaFileControl;
  gQuota.sIoMethodsV1.xSectorSize = quotaSectorSize;
  gQuota.sIoMethodsV1.xDeviceCharacteristics = quotaDeviceCharacteristics;
  gQuota.sIoMethodsV2 = gQuota.sIoMethodsV1;
  gQuota.sIoMethodsV2.iVersion = 2;
  gQuota.sIoMethodsV2.xShmMap = quotaShmMap;
  gQuota.sIoMethodsV2.xShmLock = quotaShmLock;
  gQuota.sIoMethodsV2.xShmBarrier = quotaShmBarrier;
  gQuota.sIoMethodsV2.xShmUnmap = quotaShmUnmap;
  sqlite3_vfs_register(&gQuota.sThisVfs, makeDefault);
  return SQLITE_OK;
}
Esempio n. 25
0
/***********************************************************************//**
	@brief コンストラクタ
***************************************************************************/
Vfs::Vfs(const char* parent)
  : parent_(sqlite3_vfs_find(parent))
{
  assert(parent_);
  {
    std::stringstream stream;
    stream << this;
    name_ = stream.str();
  }
  *static_cast<sqlite3_vfs*>(this) = *parent_;
  sqlite3_vfs::pNext = nullptr;
  sqlite3_vfs::zName = name_.c_str();
  sqlite3_vfs::szOsFile = sizeof(File);
  sqlite3_vfs::xOpen = &Vfs::OnOpen;

  memset(static_cast<sqlite3_io_methods*>(this), 0, 
         sizeof(sqlite3_io_methods));
  sqlite3_io_methods::xClose = &Vfs::OnClose;
  sqlite3_io_methods::xRead = &Vfs::OnRead;
  sqlite3_io_methods::xWrite = &Vfs::OnWrite;
  sqlite3_io_methods::xTruncate = &Vfs::OnTruncate;
  sqlite3_io_methods::xSync = &Vfs::OnSync;
  sqlite3_io_methods::xFileSize = &Vfs::OnFileSize;
  sqlite3_io_methods::xLock = &Vfs::OnLock;
  sqlite3_io_methods::xUnlock = &Vfs::OnUnlock;
  sqlite3_io_methods::xCheckReservedLock = &Vfs::OnCheckReservedLock;
  sqlite3_io_methods::xFileControl = &Vfs::OnFileControl;
  sqlite3_io_methods::xSectorSize = &Vfs::OnSectorSize;
  sqlite3_io_methods::xDeviceCharacteristics = &Vfs::OnDeviceCharacteristics;
  sqlite3_io_methods::xShmMap = &Vfs::OnShmMap;
  sqlite3_io_methods::xShmLock = &Vfs::OnShmLock;
  sqlite3_io_methods::xShmBarrier = &Vfs::OnShmBarrier;
  sqlite3_io_methods::xShmUnmap = &Vfs::OnShmUnmap;
  sqlite3_io_methods::xFetch = &Vfs::OnFetch;
  sqlite3_io_methods::xUnfetch = &Vfs::OnUnfetch;

  sqlite3_vfs_register(static_cast<sqlite3_vfs*>(this), 0);
}
Esempio n. 26
0
void sqlite_autoinit::init()
{
	sqlite3_initialize();

	memset (&m_sqlite3_vfs, 0, sizeof(m_sqlite3_vfs));

#if 1
	m_sqlite3_vfs.iVersion = 1;
	m_sqlite3_vfs.szOsFile = sizeof(sqlite3_file_fb2k);
	m_sqlite3_vfs.mxPathname = 2048;
	m_sqlite3_vfs.zName = "FB2K_VFS";
	m_sqlite3_vfs.pAppData = NULL;
	m_sqlite3_vfs.xOpen = &xOpen;
	m_sqlite3_vfs.xDelete = &xDelete;
	m_sqlite3_vfs.xAccess = &xAccess;
	m_sqlite3_vfs.xFullPathname = &xFullPathname;
	m_sqlite3_vfs.xRandomness = &xRandomness;
	m_sqlite3_vfs.xSleep = &xSleep;
	m_sqlite3_vfs.xCurrentTime = &xCurrentTime;
	m_sqlite3_vfs.xGetLastError = &xGetLastError;

	sqlite3_vfs_register(&m_sqlite3_vfs, 1);
#endif
}
void SQLiteFileSystem::registerSQLiteVFS()
{
    static sqlite3_vfs chromium_vfs = {
        1,
        sizeof(ChromiumFile),
        chromiumMaxPathname,
        0,
        "chromium_vfs",
        0,
        chromiumOpen,
        chromiumDelete,
        chromiumAccess,
        chromiumFullPathname,
        chromiumDlOpen,
        chromiumDlError,
        chromiumDlSym,
        chromiumDlClose,
        chromiumRandomness,
        chromiumSleep,
        chromiumCurrentTime,
        chromiumGetLastError
    };
    sqlite3_vfs_register(&chromium_vfs, 0);
}
Esempio n. 28
0
File: init.c Progetto: dpl0/pkg
int
pkg_repo_binary_create(struct pkg_repo *repo)
{
	char filepath[MAXPATHLEN];
	struct statfs stfs;
	const char *dbdir = NULL;
	sqlite3 *sqlite = NULL;
	int retcode;

	sqlite3_initialize();
	dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));

	snprintf(filepath, sizeof(filepath), "%s/%s",
		dbdir, pkg_repo_binary_get_filename(pkg_repo_name(repo)));
	/* Should never ever happen */
	if (access(filepath, R_OK) == 0)
		return (EPKG_CONFLICT);

	/*
	 * Fall back on unix-dotfile locking strategy if on a network filesystem
	 */
	if (statfs(dbdir, &stfs) == 0) {
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
	}

	/* Open for read/write/create */
	if (sqlite3_open(filepath, &sqlite) != SQLITE_OK)
		return (EPKG_FATAL);

	retcode = sql_exec(sqlite, binary_repo_initsql, REPO_SCHEMA_VERSION);

	if (retcode == EPKG_OK) {
		sqlite3_stmt *stmt;
		const char sql[] = ""
						"INSERT OR REPLACE INTO repodata (key, value) "
						"VALUES (\"packagesite\", ?1);";

		/* register the packagesite */
		if (sql_exec(sqlite, "CREATE TABLE IF NOT EXISTS repodata ("
			"   key TEXT UNIQUE NOT NULL,"
			"   value TEXT NOT NULL"
			");") != EPKG_OK) {
			pkg_emit_error("Unable to register the packagesite in the "
				"database");
			retcode = EPKG_FATAL;
			goto cleanup;
		}

		if (sqlite3_prepare_v2(sqlite, sql, -1, &stmt, NULL) != SQLITE_OK) {
			ERROR_SQLITE(sqlite, sql);
			retcode = EPKG_FATAL;
			goto cleanup;
		}

		sqlite3_bind_text(stmt, 1, pkg_repo_url(repo), -1, SQLITE_STATIC);

		if (sqlite3_step(stmt) != SQLITE_DONE) {
			ERROR_SQLITE(sqlite, sql);
			sqlite3_finalize(stmt);
			retcode = EPKG_FATAL;
			goto cleanup;
		}

		sqlite3_finalize(stmt);
	}

cleanup:
	sqlite3_close(sqlite);

	return (retcode);
}
Esempio n. 29
0
/*
 * Register into SQLite. For more information see sqlite3ndk.h
 */
int sqlite3_ndk_init(AAssetManager* assetMgr, const char* vfsName,
		int makeDflt, const char *osVfs)
{
	static ndk_vfs ndkVfs;
	int rc;

	// assetMgr is required parameter
	if (!assetMgr)
	{
		return SQLITE_ERROR;
	}

	// Check if there was successful call to sqlite3_ndk_init before
	if (ndkVfs.mgr)
	{
		if (ndkVfs.mgr == assetMgr)
		{
			return SQLITE_OK;
		}
		else
		{
			// Second call to sqlite3_ndk_init cannot change assetMgr
			return SQLITE_ERROR;
		}
	}

	// Find os VFS. Used to redirect xRandomness, xSleep, xCurrentTime, ndkCurrentTimeInt64 calls
	ndkVfs.vfsDefault = sqlite3_vfs_find(osVfs);
	if (ndkVfs.vfsDefault == NULL)
	{
		return SQLITE_ERROR;
	}

	// vfsFile
	static const sqlite3_io_methods ndkFileMethods =
	{
		1,
		ndkFileClose,
		ndkFileRead,
		ndkFileWrite,
		ndkFileTruncate,
		ndkFileSync,
		ndkFileSize,
		ndkFileLock,
		ndkFileUnlock,
		ndkFileCheckReservedLock,
		ndkFileControl,
		ndkFileSectorSize,
		ndkFileDeviceCharacteristics
	};

	// pMethods will be used in ndkOpen
	ndkVfs.pMethods = &ndkFileMethods;

	// vfs
	ndkVfs.vfs.iVersion = 3;
	ndkVfs.vfs.szOsFile = sizeof(ndk_file);
	ndkVfs.vfs.mxPathname = SQLITE_NDK_VFS_MAX_PATH;
	ndkVfs.vfs.pNext = 0;
	if (vfsName)
	{
		ndkVfs.vfs.zName = vfsName;
	}
	else
	{
		ndkVfs.vfs.zName = SQLITE_NDK_VFS_NAME;
	}
	ndkVfs.vfs.pAppData = 0;
	ndkVfs.vfs.xOpen = ndkOpen;
	ndkVfs.vfs.xDelete = ndkDelete;
	ndkVfs.vfs.xAccess = ndkAccess;
	ndkVfs.vfs.xFullPathname = ndkFullPathname;
	ndkVfs.vfs.xDlOpen = 0;
	ndkVfs.vfs.xDlError = 0;
	ndkVfs.vfs.xDlSym = 0;
	ndkVfs.vfs.xDlClose = 0;
	ndkVfs.vfs.xRandomness = ndkRandomness;
	ndkVfs.vfs.xSleep = ndkSleep;
	ndkVfs.vfs.xCurrentTime = ndkCurrentTime;
	ndkVfs.vfs.xGetLastError = ndkGetLastError;
	ndkVfs.vfs.xCurrentTimeInt64 = ndkCurrentTimeInt64;
	ndkVfs.vfs.xSetSystemCall = 0;
	ndkVfs.vfs.xGetSystemCall = 0;
	ndkVfs.vfs.xNextSystemCall = 0;

	// Asset manager
	ndkVfs.mgr = assetMgr;

	// Last part, try to register VFS
	rc = sqlite3_vfs_register(&ndkVfs.vfs, makeDflt);
   
	if (rc != SQLITE_OK)
	{
		// sqlite3_vfs_register could fails in case of sqlite3_initialize failure
		ndkVfs.mgr = 0;
	}

	return rc;
}
Esempio n. 30
0
int main(int argc, const char* argv[])
{
	g_log = stdout;
	db_thread thr;
	db_thread threads[RTHREADS];
	pthread_t tids[RTHREADS];
	priv_data pd;
	mdbinf* mdb = &thr.mdb;
	int i, rc;
	db_connection *cons;
	g_pd = &pd;
	char commit = 1;
	MDB_env *menv = NULL;
	char *lmpath = "lmdb";
	MDB_txn *txn;
	MDB_val key = {1,(void*)"?"}, data = {0,NULL};
	MDB_envinfo stat;

	sqlite3_initialize();
	sqlite3_vfs_register(sqlite3_nullvfs(), 1);

	unlink(lmpath);

	memset(threads, 0, sizeof(threads));
	memset(&thr, 0, sizeof(db_thread));
	memset(&pd, 0, sizeof(priv_data));

	pd.wmdb = calloc(1,sizeof(mdbinf));
	pd.nEnvs = 1;
	pd.nReadThreads = RTHREADS;
	pd.nWriteThreads = 1;
	pd.syncNumbers = calloc(1,sizeof(u64));
	pd.actorIndexes = calloc(1,sizeof(atomic_llong));
	atomic_init(pd.actorIndexes,0);
	g_cons = cons = calloc(NCONS, sizeof(db_connection));
	g_tsd_cursync = 0;
	g_tsd_conn    = NULL;
	g_tsd_wmdb    = NULL;
	g_tsd_thread  = &thr;

	if (mdb_env_create(&menv) != MDB_SUCCESS)
		return -1;
	if (mdb_env_set_maxdbs(menv,5) != MDB_SUCCESS)
		return -1;
	if (mdb_env_set_mapsize(menv,1024*1024*1024) != MDB_SUCCESS)
		return -1;
	// Syncs are handled from erlang.
	if (mdb_env_open(menv, lmpath, MDB_NOSUBDIR|MDB_NOTLS|MDB_NOSYNC, 0664) != MDB_SUCCESS) //MDB_NOSYNC
		return -1;
	if (mdb_txn_begin(menv, NULL, 0, &txn) != MDB_SUCCESS)
		return -1;
	if (mdb_dbi_open(txn, "info", MDB_INTEGERKEY | MDB_CREATE, &pd.wmdb[0].infodb) != MDB_SUCCESS)
		return -1;
	if (mdb_dbi_open(txn, "actors", MDB_CREATE, &pd.wmdb[0].actorsdb) != MDB_SUCCESS)
		return -1;
	if (mdb_dbi_open(txn, "log", MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED | MDB_INTEGERDUP, 
			&pd.wmdb[0].logdb) != MDB_SUCCESS)
		return -1;
	if (mdb_dbi_open(txn, "pages", MDB_CREATE | MDB_DUPSORT, &pd.wmdb[0].pagesdb) != MDB_SUCCESS)
		return -1;
	if (mdb_txn_commit(txn) != MDB_SUCCESS)
		return -1;

	pd.wmdb[0].env = menv;
	thr.nEnv = 0;
	thr.isreadonly = 0;
	thr.mdb.env = menv;
	thr.mdb.infodb = pd.wmdb[0].infodb;
	thr.mdb.actorsdb = pd.wmdb[0].actorsdb;
	thr.mdb.logdb = pd.wmdb[0].logdb;
	thr.mdb.pagesdb = pd.wmdb[0].pagesdb;
	thr.maxvalsize = mdb_env_get_maxkeysize(mdb->env);
	thr.resFrames = alloca((SQLITE_DEFAULT_PAGE_SIZE/thr.maxvalsize + 1)*sizeof(MDB_val));
	open_txn(&thr.mdb, MDB_RDONLY);

	for (i = 0; i < NCONS; i++)
	{
		char filename[256];
		char commit = 1;
		g_tsd_conn = &cons[i];
		sprintf(filename, "ac%d.db", i);

		pthread_mutex_init(&cons[i].wal.mtx, NULL);

		thr.pagesChanged = 0;

		rc = sqlite3_open(filename,&(cons[i].db));
		if(rc != SQLITE_OK)
		{
			DBG("Unable to open db");
			break;
		}
		rc = sqlite3_exec(cons[i].db,"PRAGMA synchronous=0;PRAGMA journal_mode=wal;",NULL,NULL,NULL);
		if (rc != SQLITE_OK)
		{
			DBG("unable to open wal");
			break;
		}
		cons[i].wal.inProgressTerm = 1;
		cons[i].wal.inProgressEvnum = 1;
		rc = sqlite3_exec(cons[i].db,"CREATE TABLE tab (id INTEGER PRIMARY KEY, txt TEXT);"
			"insert into tab values (1,'aaaa');",NULL,NULL,NULL);
		if (rc != SQLITE_OK)
		{
			DBG("Cant create table");
			break;
		}
		unlock_write_txn(thr.nEnv, 0, &commit);

		mdb_txn_reset(thr.mdb.txn);

		rc = mdb_txn_renew(thr.mdb.txn);
		if (rc != MDB_SUCCESS)
			break;
		rc = mdb_cursor_renew(thr.mdb.txn, mdb->cursorLog);
		if (rc != MDB_SUCCESS)
			break;
		rc = mdb_cursor_renew(thr.mdb.txn, mdb->cursorPages);
		if (rc != MDB_SUCCESS)
			break;
		rc = mdb_cursor_renew(thr.mdb.txn, mdb->cursorInfo);
		if (rc != MDB_SUCCESS)
			break;
	}
	// mdb_cursor_close(thr.mdb.cursorLog);
	// mdb_cursor_close(thr.mdb.cursorPages);
	// mdb_cursor_close(thr.mdb.cursorInfo);
	// mdb_txn_abort(thr.mdb.txn);


	for (i = 0; i < RTHREADS; i++)
	{
		threads[i].nEnv = 0;
		threads[i].isreadonly = 0;
		threads[i].mdb.env = menv;
		threads[i].mdb.infodb = pd.wmdb[0].infodb;
		threads[i].mdb.actorsdb = pd.wmdb[0].actorsdb;
		threads[i].mdb.logdb = pd.wmdb[0].logdb;
		threads[i].mdb.pagesdb = pd.wmdb[0].pagesdb;
		threads[i].maxvalsize = mdb_env_get_maxkeysize(mdb->env);
		pthread_create(&tids[i], NULL, perform, (void *)&threads[i]);
	}

	srand((u32)pthread_self() + time(NULL));
	for (i = 0; i < 1000*200; i++)
	{
		char commit = 1;
		int j = rand() % NCONS;
		db_connection *con = &g_cons[j];
		char str[100];
		if (pthread_mutex_trylock(&con->wal.mtx) != 0)
		{
			i--;
			continue;
		}

		if (i % 1000 == 0)
			printf("w %d\n",i);
		g_tsd_conn = con;
		lock_wtxn(thr.nEnv);

		thr.pagesChanged = 0;

		if (con->wal.firstCompleteEvnum+10 < con->wal.lastCompleteEvnum)
		{
			// printf("CHECKPOINT? %llu %llu\n",con->wal.firstCompleteEvnum,con->wal.lastCompleteEvnum);
			if (checkpoint(&con->wal, con->wal.lastCompleteEvnum-10) != SQLITE_OK)
			{
				printf("Checkpoint failed\n");
				break;
			}
		}
		con->wal.inProgressTerm = 1;
		con->wal.inProgressEvnum = con->wal.lastCompleteEvnum+1;

		sprintf(str,"INSERT INTO tab VALUES (%d,'VALUE VALUE13456');", i);
		sqlite3_exec(con->db,str,NULL,NULL,NULL);

		pthread_mutex_unlock(&con->wal.mtx);

		unlock_write_txn(thr.nEnv, 0, &commit);

		mdb_txn_reset(thr.mdb.txn);
		rc = mdb_txn_renew(thr.mdb.txn);
		if (rc != MDB_SUCCESS)
			break;
		rc = mdb_cursor_renew(thr.mdb.txn, mdb->cursorLog);
		if (rc != MDB_SUCCESS)
			break;
		rc = mdb_cursor_renew(thr.mdb.txn, mdb->cursorPages);
		if (rc != MDB_SUCCESS)
			break;
		rc = mdb_cursor_renew(thr.mdb.txn, mdb->cursorInfo);
		if (rc != MDB_SUCCESS)
			break;
	}

	unlock_write_txn(thr.nEnv, 1, &commit);


	for (i = 0; i < RTHREADS; i++)
		pthread_join(tids[i],NULL);

	return 1;
}