This source file includes following definitions.
- chromiumOpen
- chromiumDelete
- chromiumAccess
- chromiumFullPathname
- chromiumDlOpen
- registerSQLiteVFS
#include "config.h"
#include "modules/webdatabase/sqlite/SQLiteFileSystem.h"
#include <sqlite3.h>
#include "public/platform/Platform.h"
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
using namespace WebCore;
extern "C" {
void chromium_sqlite3_initialize_unix_sqlite3_file(sqlite3_file* file);
int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs, int fd, int dirfd, sqlite3_file* file, const char* fileName, int noLock);
int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file, const char* fileName, int flags, int* fd);
void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file, int fd, int flags);
void chromium_sqlite3_destroy_reusable_file_handle(sqlite3_file* file);
}
namespace {
int chromiumOpen(sqlite3_vfs* vfs, const char* fileName,
sqlite3_file* id, int desiredFlags, int* usedFlags)
{
chromium_sqlite3_initialize_unix_sqlite3_file(id);
int fd = -1;
int result = chromium_sqlite3_get_reusable_file_handle(id, fileName, desiredFlags, &fd);
if (result != SQLITE_OK)
return result;
if (fd < 0) {
fd = blink::Platform::current()->databaseOpenFile(String(fileName), desiredFlags);
if ((fd < 0) && (desiredFlags & SQLITE_OPEN_READWRITE)) {
int newFlags = (desiredFlags & ~(SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)) | SQLITE_OPEN_READONLY;
fd = blink::Platform::current()->databaseOpenFile(String(fileName), newFlags);
}
}
if (fd < 0) {
chromium_sqlite3_destroy_reusable_file_handle(id);
return SQLITE_CANTOPEN;
}
if (usedFlags)
*usedFlags = desiredFlags;
chromium_sqlite3_update_reusable_file_handle(id, fd, desiredFlags);
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
int fileType = desiredFlags & 0x00007F00;
int noLock = (fileType != SQLITE_OPEN_MAIN_DB);
result = chromium_sqlite3_fill_in_unix_sqlite3_file(vfs, fd, -1, id, fileName, noLock);
if (result != SQLITE_OK)
chromium_sqlite3_destroy_reusable_file_handle(id);
return result;
}
int chromiumDelete(sqlite3_vfs*, const char* fileName, int syncDir)
{
return blink::Platform::current()->databaseDeleteFile(String(fileName), syncDir);
}
int chromiumAccess(sqlite3_vfs*, const char* fileName, int flag, int* res)
{
int attr = static_cast<int>(blink::Platform::current()->databaseGetFileAttributes(String(fileName)));
if (attr < 0) {
*res = 0;
return SQLITE_OK;
}
switch (flag) {
case SQLITE_ACCESS_EXISTS:
*res = 1;
break;
case SQLITE_ACCESS_READWRITE:
*res = (attr & W_OK) && (attr & R_OK);
break;
case SQLITE_ACCESS_READ:
*res = (attr & R_OK);
break;
default:
return SQLITE_ERROR;
}
return SQLITE_OK;
}
int chromiumFullPathname(sqlite3_vfs* vfs, const char* relativePath,
int, char* absolutePath)
{
sqlite3_snprintf(vfs->mxPathname, absolutePath, "%s", relativePath);
return SQLITE_OK;
}
#ifndef SQLITE_OMIT_LOAD_EXTENSION
void* chromiumDlOpen(sqlite3_vfs*, const char*)
{
return 0;
}
#else
#define chromiumDlOpen 0
#endif
}
namespace WebCore {
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);
}
}