LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
tkeyvfs.h File Reference
#include "TFile.h"
#include <sqlite3.h>

Go to the source code of this file.

Functions

int tkeyvfs_init (void)
 
int tkeyvfs_open_v2 (const char *filename, sqlite3 **ppDb, int flags, TFile *rootFile)
 

Function Documentation

int tkeyvfs_init ( void  )

Definition at line 1768 of file tkeyvfs.cc.

References ArraySize, aSyscall, nolockIoFinder, and UNIXVFS.

Referenced by art::completeRootHandlers(), and main().

1769 {
1770 /*
1771 ** The following macro defines an initializer for an sqlite3_vfs object.
1772 ** The name of the VFS is NAME. The pAppData is a pointer to a pointer
1773 ** to the "finder" function. (pAppData is a pointer to a pointer because
1774 ** silly C90 rules prohibit a void* from being cast to a function pointer
1775 ** and so we have to go through the intermediate pointer to avoid problems
1776 ** when compiling with -pedantic-errors on GCC.)
1777 **
1778 ** The FINDER parameter to this macro is the name of the pointer to the
1779 ** finder-function. The finder-function returns a pointer to the
1780 ** sqlite_io_methods object that implements the desired locking
1781 ** behaviors. See the division above that contains the IOMETHODS
1782 ** macro for addition information on finder-functions.
1783 **
1784 ** Most finders simply return a pointer to a fixed sqlite3_io_methods
1785 ** object. But the "autolockIoFinder" available on MacOSX does a little
1786 ** more than that; it looks at the filesystem type that hosts the
1787 ** database file and tries to choose an locking method appropriate for
1788 ** that filesystem time.
1789 */
1790 #define UNIXVFS(VFSNAME, FINDER) \
1791  { \
1792  1, /* iVersion */ \
1793  sizeof(unixFile), /* szOsFile */ \
1794  MAX_PATHNAME, /* mxPathname */ \
1795  0, /* pNext */ \
1796  VFSNAME, /* zName */ \
1797  (void*)&FINDER, /* pAppData */ \
1798  unixOpen, /* xOpen */ \
1799  unixDelete, /* xDelete */ \
1800  unixAccess, /* xAccess */ \
1801  unixFullPathname, /* xFullPathname */ \
1802  unixDlOpen, /* xDlOpen */ \
1803  unixDlError, /* xDlError */ \
1804  unixDlSym, /* xDlSym */ \
1805  unixDlClose, /* xDlClose */ \
1806  unixRandomness, /* xRandomness */ \
1807  unixSleep, /* xSleep */ \
1808  unixCurrentTime, /* xCurrentTime */ \
1809  unixGetLastError, /* xGetLastError */ \
1810  /* unixCurrentTimeInt64, v2, xCurrentTimeInt64 */ \
1811  /* unixSetSystemCall, v3, xSetSystemCall */ \
1812  /* unixGetSystemCall, v3, xGetSystemCall */ \
1813  /* unixNextSystemCall, v3, xNextSystemCall */ \
1814  }
1815  /*
1816  ** All default VFSes for unix are contained in the following array.
1817  **
1818  ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
1819  ** by the SQLite core when the VFS is registered. So the following
1820  ** array cannot be const.
1821  */
1822  static sqlite3_vfs aVfs[] = {
1823  UNIXVFS("tkeyvfs", nolockIoFinder),
1824  };
1825  unsigned int i; /* Loop counter */
1826  /* Double-check that the aSyscall[] array has been constructed
1827  ** correctly. See ticket [bb3a86e890c8e96ab] */
1828  assert(ArraySize(aSyscall) == 16);
1829  /* Register all VFSes defined in the aVfs[] array */
1830  for (i = 0; i < (sizeof(aVfs) / sizeof(sqlite3_vfs)); i++) {
1831  sqlite3_vfs_register(&aVfs[i], 0);
1832  }
1833  return SQLITE_OK;
1834 }
static const sqlite3_io_methods *(*const nolockIoFinder)(const char *, unixFile *p)
Definition: tkeyvfs.cc:364
static struct unix_syscall aSyscall[]
#define UNIXVFS(VFSNAME, FINDER)
#define ArraySize(X)
Definition: tkeyvfs.cc:32
int tkeyvfs_open_v2 ( const char *  filename,
sqlite3 **  ppDb,
int  flags,
TFile *  rootFile 
)

Definition at line 1837 of file tkeyvfs.cc.

References unixFile::rootFile.

Referenced by art::SQLite3Wrapper::initDB(), and art::TKeyVFSOpenPolicy::open().

1845 {
1846 #ifndef TKEYVFS_NO_ROOT
1847  RootFileSentry rfs(rootFile);
1848  // Note that the sentry *is* the correct thing to do, here:
1849  // gRootFile is required in unixOpen(), which is called as part of
1850  // the chain of functions of which sqlite3_open_v2() is the first
1851  // call. By the time we return from sqlite3_open_v2() then, we no
1852  // longer require gRootFile and the sentry can do the job of
1853  // cleaning up when it goes out of scope.
1854 #endif // TKEYVFS_NO_ROOT
1855  return sqlite3_open_v2(filename,
1856  ppDb,
1857  flags,
1858 #ifdef TKEYVFS_NO_ROOT
1859  nullptr
1860 #else
1861  "tkeyvfs"
1862 #endif
1863  );
1864 }