1
0
Fork 0

Adding upstream version 1.37.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-17 09:46:10 +02:00
parent 42613ad5c6
commit 271b368104
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
1329 changed files with 4727104 additions and 0 deletions

75
vfs/Makefile Normal file
View file

@ -0,0 +1,75 @@
# Copyright 2022 The CC Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
.PHONY: build_all_targetsclean edit editor tmp x
build_all_targets:
GOOS=darwin GOARCH=amd64 go build -v ./...
GOOS=darwin GOARCH=amd64 go test -c -o /dev/null
GOOS=darwin GOARCH=arm64 go build -v ./...
GOOS=darwin GOARCH=arm64 go test -c -o /dev/null
GOOS=freebsd GOARCH=amd64 go build -v ./...
GOOS=freebsd GOARCH=amd64 go test -c -o /dev/null
GOOS=freebsd GOARCH=386 go build -v ./...
GOOS=freebsd GOARCH=386 go test -c -o /dev/null
GOOS=freebsd GOARCH=arm go build -v ./...
GOOS=freebsd GOARCH=arm go test -c -o /dev/null
GOOS=linux GOARCH=386 go build -v ./...
GOOS=linux GOARCH=386 go test -c -o /dev/null
GOOS=linux GOARCH=amd64 go build -v ./...
GOOS=linux GOARCH=amd64 go test -c -o /dev/null
GOOS=linux GOARCH=arm go build -v ./...
GOOS=linux GOARCH=arm go test -c -o /dev/null
GOOS=linux GOARCH=arm64 go build -v ./...
GOOS=linux GOARCH=arm64 go test -c -o /dev/null
GOOS=linux GOARCH=ppc64le go build -v ./...
GOOS=linux GOARCH=ppc64le go test -c -o /dev/null
GOOS=linux GOARCH=riscv64 go build -v ./...
GOOS=linux GOARCH=riscv64 go test -c -o /dev/null
GOOS=linux GOARCH=s390x go build -v ./...
GOOS=linux GOARCH=s390x go test -c -o /dev/null
GOOS=netbsd GOARCH=amd64 go build -v ./...
GOOS=netbsd GOARCH=amd64 go test -c -o /dev/null
GOOS=openbsd GOARCH=amd64 go build -v ./...
GOOS=openbsd GOARCH=amd64 go test -c -o /dev/null
GOOS=openbsd GOARCH=arm64 go build -v ./...
GOOS=openbsd GOARCH=arm64 go test -c -o /dev/null
# GOOS=windows GOARCH=386 go build -v ./...
# GOOS=windows GOARCH=386 go test -c -o /dev/null
GOOS=windows GOARCH=amd64 go build -v ./...
GOOS=windows GOARCH=amd64 go test -c -o /dev/null
GOOS=windows GOARCH=arm64 go build -v ./...
GOOS=windows GOARCH=arm64 go test -c -o /dev/null
echo done
clean:
rm -f log-* cpu.test mem.test *.out
go clean
edit:
@touch log
@if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile *.c *.go & fi
FN=vfs_$(shell go env GOOS)_$(shell go env GOARCH).go
editor:
ccgo -o $(FN) c/vfs.c -Isqlite-amalgamation-3450200 \
-D SQLITE_OS_UNIX \
-extended-errors \
-hide=vfsAccess \
-hide=vfsClose \
-hide=vfsFileSize \
-hide=vfsFullPathname \
-hide=vfsOpen \
-hide=vfsRead \
-ignore-link-errors \
-import modernc.org/sqlite/lib \
--package-name vfs \
--prefix-external X
sed -i 's/\<sqlite3_snprintf\>/sqlite3.Xsqlite3_snprintf/' $(FN)
sed -i 's/\<sqlite3_malloc\>/sqlite3.Xsqlite3_malloc/' $(FN)
go build -v
gofmt -l -s -w *.go
go test -o /dev/null -c

13
vfs/all_test.go Normal file
View file

@ -0,0 +1,13 @@
// Copyright 2022 The Sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vfs
import (
"testing"
)
func Test(t *testing.T) {
t.Log("TODO")
}

713
vfs/c/vfs.c Normal file
View file

@ -0,0 +1,713 @@
// https://www.sqlite.org/src/doc/trunk/src/test_demovfs.c
/*
** 2010 April 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file implements an example of a simple VFS implementation that
** omits complex features often not required or not possible on embedded
** platforms. Code is included to buffer writes to the journal file,
** which can be a significant performance improvement on some embedded
** platforms.
**
** OVERVIEW
**
** The code in this file implements a minimal SQLite VFS that can be
** used on Linux and other posix-like operating systems. The following
** system calls are used:
**
** File-system: access(), unlink(), getcwd()
** File IO: open(), read(), write(), fsync(), close(), fstat()
** Other: sleep(), usleep(), time()
**
** The following VFS features are omitted:
**
** 1. File locking. The user must ensure that there is at most one
** connection to each database when using this VFS. Multiple
** connections to a single shared-cache count as a single connection
** for the purposes of the previous statement.
**
** 2. The loading of dynamic extensions (shared libraries).
**
** 3. Temporary files. The user must configure SQLite to use in-memory
** temp files when using this VFS. The easiest way to do this is to
** compile with:
**
** -DSQLITE_TEMP_STORE=3
**
** 4. File truncation. As of version 3.6.24, SQLite may run without
** a working xTruncate() call, providing the user does not configure
** SQLite to use "journal_mode=truncate", or use both
** "journal_mode=persist" and ATTACHed databases.
**
** It is assumed that the system uses UNIX-like path-names. Specifically,
** that '/' characters are used to separate path components and that
** a path-name is a relative path unless it begins with a '/'. And that
** no UTF-8 encoded paths are greater than 512 bytes in length.
**
** JOURNAL WRITE-BUFFERING
**
** To commit a transaction to the database, SQLite first writes rollback
** information into the journal file. This usually consists of 4 steps:
**
** 1. The rollback information is sequentially written into the journal
** file, starting at the start of the file.
** 2. The journal file is synced to disk.
** 3. A modification is made to the first few bytes of the journal file.
** 4. The journal file is synced to disk again.
**
** Most of the data is written in step 1 using a series of calls to the
** VFS xWrite() method. The buffers passed to the xWrite() calls are of
** various sizes. For example, as of version 3.6.24, when committing a
** transaction that modifies 3 pages of a database file that uses 4096
** byte pages residing on a media with 512 byte sectors, SQLite makes
** eleven calls to the xWrite() method to create the rollback journal,
** as follows:
**
** Write offset | Bytes written
** ----------------------------
** 0 512
** 512 4
** 516 4096
** 4612 4
** 4616 4
** 4620 4096
** 8716 4
** 8720 4
** 8724 4096
** 12820 4
** ++++++++++++SYNC+++++++++++
** 0 12
** ++++++++++++SYNC+++++++++++
**
** On many operating systems, this is an efficient way to write to a file.
** However, on some embedded systems that do not cache writes in OS
** buffers it is much more efficient to write data in blocks that are
** an integer multiple of the sector-size in size and aligned at the
** start of a sector.
**
** To work around this, the code in this file allocates a fixed size
** buffer of SQLITE_VFS_BUFFERSZ using sqlite3_malloc() whenever a
** journal file is opened. It uses the buffer to coalesce sequential
** writes into aligned SQLITE_VFS_BUFFERSZ blocks. When SQLite
** invokes the xSync() method to sync the contents of the file to disk,
** all accumulated data is written out, even if it does not constitute
** a complete block. This means the actual IO to create the rollback
** journal for the example transaction above is this:
**
** Write offset | Bytes written
** ----------------------------
** 0 8192
** 8192 4632
** ++++++++++++SYNC+++++++++++
** 0 12
** ++++++++++++SYNC+++++++++++
**
** Much more efficient if the underlying OS is not caching write
** operations.
*/
// This file is modified to support Go's embed.FS
#if !defined(SQLITE_TEST) || SQLITE_OS_UNIX
#include "sqlite3.h"
#include <assert.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/param.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#define hook __builtin_printf("TODO %s:%i:\n", __func__, __LINE__); abort();
// #define hook __builtin_printf("TRC %s:%i:\n", __func__, __LINE__);
/*
** Size of the write buffer used by journal files in bytes.
*/
#ifndef SQLITE_VFS_BUFFERSZ
# define SQLITE_VFS_BUFFERSZ 8192
#endif
/*
** The maximum pathname length supported by this VFS.
*/
#define MAXPATHNAME 4096
/*
** When using this VFS, the sqlite3_file* handles that SQLite uses are
** actually pointers to instances of type VFSFile.
*/
typedef struct VFSFile VFSFile;
struct VFSFile {
sqlite3_file base; /* Base class. Must be first. */
void *fsFile; // handle of Go fs.File
int fd; /* File descriptor */
char *aBuffer; /* Pointer to malloc'd buffer */
int nBuffer; /* Valid bytes of data in zBuffer */
sqlite3_int64 iBufferOfst; /* Offset in file of zBuffer[0] */
};
/*
** Write directly to the file passed as the first argument. Even if the
** file has a write-buffer (VFSFile.aBuffer), ignore it.
*/
static int vfsDirectWrite(
VFSFile *p, /* File handle */
const void *zBuf, /* Buffer containing data to write */
int iAmt, /* Size of data to write in bytes */
sqlite_int64 iOfst /* File offset to write to */
){
off_t ofst; /* Return value from lseek() */
size_t nWrite; /* Return value from write() */
hook
ofst = lseek(p->fd, iOfst, SEEK_SET);
if( ofst!=iOfst ){
return SQLITE_IOERR_WRITE;
}
nWrite = write(p->fd, zBuf, iAmt);
if( nWrite!=iAmt ){
return SQLITE_IOERR_WRITE;
}
return SQLITE_OK;
}
/*
** Flush the contents of the VFSFile.aBuffer buffer to disk. This is a
** no-op if this particular file does not have a buffer (i.e. it is not
** a journal file) or if the buffer is currently empty.
*/
static int vfsFlushBuffer(VFSFile *p){
hook
int rc = SQLITE_OK;
if( p->nBuffer ){
rc = vfsDirectWrite(p, p->aBuffer, p->nBuffer, p->iBufferOfst);
p->nBuffer = 0;
}
return rc;
}
/*
** Close a file.
*/
int vfsClose(sqlite3_file *pFile){
hook
int rc;
VFSFile *p = (VFSFile*)pFile;
rc = vfsFlushBuffer(p);
sqlite3_free(p->aBuffer);
close(p->fd);
return rc;
}
/*
** Read data from a file.
*/
int vfsRead(
sqlite3_file *pFile,
void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
hook
VFSFile *p = (VFSFile*)pFile;
off_t ofst; /* Return value from lseek() */
int nRead; /* Return value from read() */
int rc; /* Return code from vfsFlushBuffer() */
/* Flush any data in the write buffer to disk in case this operation
** is trying to read data the file-region currently cached in the buffer.
** It would be possible to detect this case and possibly save an
** unnecessary write here, but in practice SQLite will rarely read from
** a journal file when there is data cached in the write-buffer.
*/
rc = vfsFlushBuffer(p);
if( rc!=SQLITE_OK ){
return rc;
}
ofst = lseek(p->fd, iOfst, SEEK_SET);
if( ofst!=iOfst ){
return SQLITE_IOERR_READ;
}
nRead = read(p->fd, zBuf, iAmt);
if( nRead==iAmt ){
return SQLITE_OK;
}else if( nRead>=0 ){
if( nRead<iAmt ){
memset(&((char*)zBuf)[nRead], 0, iAmt-nRead);
}
return SQLITE_IOERR_SHORT_READ;
}
return SQLITE_IOERR_READ;
}
/*
** Write data to a crash-file.
*/
static int vfsWrite(
sqlite3_file *pFile,
const void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
hook
VFSFile *p = (VFSFile*)pFile;
if( p->aBuffer ){
char *z = (char *)zBuf; /* Pointer to remaining data to write */
int n = iAmt; /* Number of bytes at z */
sqlite3_int64 i = iOfst; /* File offset to write to */
while( n>0 ){
int nCopy; /* Number of bytes to copy into buffer */
/* If the buffer is full, or if this data is not being written directly
** following the data already buffered, flush the buffer. Flushing
** the buffer is a no-op if it is empty.
*/
if( p->nBuffer==SQLITE_VFS_BUFFERSZ || p->iBufferOfst+p->nBuffer!=i ){
int rc = vfsFlushBuffer(p);
if( rc!=SQLITE_OK ){
return rc;
}
}
assert( p->nBuffer==0 || p->iBufferOfst+p->nBuffer==i );
p->iBufferOfst = i - p->nBuffer;
/* Copy as much data as possible into the buffer. */
nCopy = SQLITE_VFS_BUFFERSZ - p->nBuffer;
if( nCopy>n ){
nCopy = n;
}
memcpy(&p->aBuffer[p->nBuffer], z, nCopy);
p->nBuffer += nCopy;
n -= nCopy;
i += nCopy;
z += nCopy;
}
}else{
return vfsDirectWrite(p, zBuf, iAmt, iOfst);
}
return SQLITE_OK;
}
/*
** Truncate a file. This is a no-op for this VFS (see header comments at
** the top of the file).
*/
static int vfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
#if 0
if( ftruncate(((VFSFile *)pFile)->fd, size) ) return SQLITE_IOERR_TRUNCATE;
#endif
return SQLITE_OK;
}
/*
** Sync the contents of the file to the persistent media.
*/
static int vfsSync(sqlite3_file *pFile, int flags){
hook
VFSFile *p = (VFSFile*)pFile;
int rc;
rc = vfsFlushBuffer(p);
if( rc!=SQLITE_OK ){
return rc;
}
rc = fsync(p->fd);
return (rc==0 ? SQLITE_OK : SQLITE_IOERR_FSYNC);
}
/*
** Write the size of the file in bytes to *pSize.
*/
int vfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
hook
VFSFile *p = (VFSFile*)pFile;
int rc; /* Return code from fstat() call */
struct stat sStat; /* Output of fstat() call */
/* Flush the contents of the buffer to disk. As with the flush in the
** vfsRead() method, it would be possible to avoid this and save a write
** here and there. But in practice this comes up so infrequently it is
** not worth the trouble.
*/
rc = vfsFlushBuffer(p);
if( rc!=SQLITE_OK ){
return rc;
}
rc = fstat(p->fd, &sStat);
if( rc!=0 ) return SQLITE_IOERR_FSTAT;
*pSize = sStat.st_size;
return SQLITE_OK;
}
/*
** Locking functions. The xLock() and xUnlock() methods are both no-ops.
** The xCheckReservedLock() always indicates that no other process holds
** a reserved lock on the database file. This ensures that if a hot-journal
** file is found in the file-system it is rolled back.
*/
static int vfsLock(sqlite3_file *pFile, int eLock){
return SQLITE_OK;
}
static int vfsUnlock(sqlite3_file *pFile, int eLock){
return SQLITE_OK;
}
static int vfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
*pResOut = 0;
return SQLITE_OK;
}
/*
** No xFileControl() verbs are implemented by this VFS.
*/
static int vfsFileControl(sqlite3_file *pFile, int op, void *pArg){
return SQLITE_NOTFOUND;
}
/*
** The xSectorSize() and xDeviceCharacteristics() methods. These two
** may return special values allowing SQLite to optimize file-system
** access to some extent. But it is also safe to simply return 0.
*/
static int vfsSectorSize(sqlite3_file *pFile){
return 0;
}
static int vfsDeviceCharacteristics(sqlite3_file *pFile){
return 0;
}
/*
** Open a file handle.
*/
int vfsOpen(
sqlite3_vfs *pVfs, /* VFS */
const char *zName, /* File to open, or 0 for a temp file */
sqlite3_file *pFile, /* Pointer to VFSFile struct to populate */
int flags, /* Input SQLITE_OPEN_XXX flags */
int *pOutFlags /* Output SQLITE_OPEN_XXX flags (or NULL) */
){
static const sqlite3_io_methods vfsio = {
1, /* iVersion */
vfsClose, /* xClose */
vfsRead, /* xRead */
vfsWrite, /* xWrite */
vfsTruncate, /* xTruncate */
vfsSync, /* xSync */
vfsFileSize, /* xFileSize */
vfsLock, /* xLock */
vfsUnlock, /* xUnlock */
vfsCheckReservedLock, /* xCheckReservedLock */
vfsFileControl, /* xFileControl */
vfsSectorSize, /* xSectorSize */
vfsDeviceCharacteristics /* xDeviceCharacteristics */
};
hook
VFSFile *p = (VFSFile*)pFile; /* Populate this structure */
int oflags = 0; /* flags to pass to open() call */
char *aBuf = 0;
if( zName==0 ){
return SQLITE_IOERR;
}
if( flags&SQLITE_OPEN_MAIN_JOURNAL ){
aBuf = (char *)sqlite3_malloc(SQLITE_VFS_BUFFERSZ);
if( !aBuf ){
return SQLITE_NOMEM;
}
}
if( flags&SQLITE_OPEN_EXCLUSIVE ) oflags |= O_EXCL;
if( flags&SQLITE_OPEN_CREATE ) oflags |= O_CREAT;
if( flags&SQLITE_OPEN_READONLY ) oflags |= O_RDONLY;
if( flags&SQLITE_OPEN_READWRITE ) oflags |= O_RDWR;
memset(p, 0, sizeof(VFSFile));
p->fd = open(zName, oflags, 0600);
if( p->fd<0 ){
sqlite3_free(aBuf);
return SQLITE_CANTOPEN;
}
p->aBuffer = aBuf;
if( pOutFlags ){
*pOutFlags = flags;
}
p->base.pMethods = &vfsio;
return SQLITE_OK;
}
/*
** Delete the file identified by argument zPath. If the dirSync parameter
** is non-zero, then ensure the file-system modification to delete the
** file has been synced to disk before returning.
*/
static int vfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
hook
int rc; /* Return code */
rc = unlink(zPath);
if( rc!=0 && errno==ENOENT ) return SQLITE_OK;
if( rc==0 && dirSync ){
int dfd; /* File descriptor open on directory */
int i; /* Iterator variable */
char zDir[MAXPATHNAME+1]; /* Name of directory containing file zPath */
/* Figure out the directory name from the path of the file deleted. */
sqlite3_snprintf(MAXPATHNAME, zDir, "%s", zPath);
zDir[MAXPATHNAME] = '\0';
for(i=strlen(zDir); i>1 && zDir[i]!='/'; i++);
zDir[i] = '\0';
/* Open a file-descriptor on the directory. Sync. Close. */
dfd = open(zDir, O_RDONLY, 0);
if( dfd<0 ){
rc = -1;
}else{
rc = fsync(dfd);
close(dfd);
}
}
return (rc==0 ? SQLITE_OK : SQLITE_IOERR_DELETE);
}
#ifndef F_OK
# define F_OK 0
#endif
#ifndef R_OK
# define R_OK 4
#endif
#ifndef W_OK
# define W_OK 2
#endif
/*
** Query the file-system to see if the named file exists, is readable or
** is both readable and writable.
*/
int vfsAccess(
sqlite3_vfs *pVfs,
const char *zPath,
int flags,
int *pResOut
){
hook
int rc; /* access() return code */
int eAccess = F_OK; /* Second argument to access() */
assert( flags==SQLITE_ACCESS_EXISTS /* access(zPath, F_OK) */
|| flags==SQLITE_ACCESS_READ /* access(zPath, R_OK) */
|| flags==SQLITE_ACCESS_READWRITE /* access(zPath, R_OK|W_OK) */
);
if( flags==SQLITE_ACCESS_READWRITE ) eAccess = R_OK|W_OK;
if( flags==SQLITE_ACCESS_READ ) eAccess = R_OK;
rc = access(zPath, eAccess);
*pResOut = (rc==0);
return SQLITE_OK;
}
/*
** Argument zPath points to a nul-terminated string containing a file path.
** If zPath is an absolute path, then it is copied as is into the output
** buffer. Otherwise, if it is a relative path, then the equivalent full
** path is written to the output buffer.
**
** This function assumes that paths are UNIX style. Specifically, that:
**
** 1. Path components are separated by a '/'. and
** 2. Full paths begin with a '/' character.
*/
int vfsFullPathname(
sqlite3_vfs *pVfs, /* VFS */
const char *zPath, /* Input path (possibly a relative path) */
int nPathOut, /* Size of output buffer in bytes */
char *zPathOut /* Pointer to output buffer */
){
hook
char zDir[MAXPATHNAME+1];
if( zPath[0]=='/' ){
zDir[0] = '\0';
}else{
if( getcwd(zDir, sizeof(zDir))==0 ) return SQLITE_IOERR;
}
zDir[MAXPATHNAME] = '\0';
sqlite3_snprintf(nPathOut, zPathOut, "%s/%s", zDir, zPath);
zPathOut[nPathOut-1] = '\0';
return SQLITE_OK;
}
/*
** The following four VFS methods:
**
** xDlOpen
** xDlError
** xDlSym
** xDlClose
**
** are supposed to implement the functionality needed by SQLite to load
** extensions compiled as shared objects. This simple VFS does not support
** this functionality, so the following functions are no-ops.
*/
static void *vfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
return 0;
}
static void vfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
sqlite3_snprintf(nByte, zErrMsg, "Loadable extensions are not supported");
zErrMsg[nByte-1] = '\0';
}
static void (*vfsDlSym(sqlite3_vfs *pVfs, void *pH, const char *z))(void){
return 0;
}
static void vfsDlClose(sqlite3_vfs *pVfs, void *pHandle){
return;
}
/*
** Parameter zByte points to a buffer nByte bytes in size. Populate this
** buffer with pseudo-random data.
*/
static int vfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zByte){
return SQLITE_OK;
}
/*
** Sleep for at least nMicro microseconds. Return the (approximate) number
** of microseconds slept for.
*/
static int vfsSleep(sqlite3_vfs *pVfs, int nMicro){
sleep(nMicro / 1000000);
usleep(nMicro % 1000000);
return nMicro;
}
/*
** Set *pTime to the current UTC time expressed as a Julian day. Return
** SQLITE_OK if successful, or an error code otherwise.
**
** http://en.wikipedia.org/wiki/Julian_day
**
** This implementation is not very good. The current time is rounded to
** an integer number of seconds. Also, assuming time_t is a signed 32-bit
** value, it will stop working some time in the year 2038 AD (the so-called
** "year 2038" problem that afflicts systems that store time this way).
*/
static int vfsCurrentTime(sqlite3_vfs *pVfs, double *pTime){
time_t t = time(0);
*pTime = t/86400.0 + 2440587.5;
return SQLITE_OK;
}
/*
** This function returns a pointer to the VFS implemented in this file.
** To make the VFS available to SQLite:
**
** sqlite3_vfs_register(sqlite3_fsFS(), 0);
*/
sqlite3_vfs *sqlite3_fsFS(char *zName, void *pAppData){
sqlite3_vfs *p = sqlite3_malloc(sizeof(sqlite3_vfs));
if (!p) {
return NULL;
}
*p = (sqlite3_vfs){
1, /* iVersion */
sizeof(VFSFile), /* szOsFile */
MAXPATHNAME, /* mxPathname */
0, /* pNext */
zName, /* zName */
pAppData, /* pAppData */
vfsOpen, /* xOpen */
vfsDelete, /* xDelete */
vfsAccess, /* xAccess */
vfsFullPathname, /* xFullPathname */
vfsDlOpen, /* xDlOpen */
vfsDlError, /* xDlError */
vfsDlSym, /* xDlSym */
vfsDlClose, /* xDlClose */
vfsRandomness, /* xRandomness */
vfsSleep, /* xSleep */
vfsCurrentTime, /* xCurrentTime */
};
return p;
}
#endif /* !defined(SQLITE_TEST) || SQLITE_OS_UNIX */
#ifdef SQLITE_TEST
#if defined(INCLUDE_SQLITE_TCL_H)
# include "sqlite_tcl.h"
#else
# include "tcl.h"
# ifndef SQLITE_TCLAPI
# define SQLITE_TCLAPI
# endif
#endif
#if SQLITE_OS_UNIX
static int SQLITE_TCLAPI register_fsFS(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
sqlite3_vfs_register(sqlite3_fsFS("fsFS", 0), 1);
return TCL_OK;
}
static int SQLITE_TCLAPI unregister_fsFS(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
sqlite3_vfs_unregister(sqlite3_fsFS("fsFS", 0));
return TCL_OK;
}
/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest_fsFS_Init(Tcl_Interp *interp){
Tcl_CreateObjCommand(interp, "register_fsFS", register_fsFS, 0, 0);
Tcl_CreateObjCommand(interp, "unregister_fsFS", unregister_fsFS, 0, 0);
return TCL_OK;
}
#else
int Sqlitetest_fsFS_Init(Tcl_Interp *interp){ return TCL_OK; }
#endif
#endif /* SQLITE_TEST */

228
vfs/patches.go Normal file
View file

@ -0,0 +1,228 @@
// Copyright 2022 The Sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vfs
import (
"fmt"
"io"
"io/fs"
"os"
"sync"
"sync/atomic"
"unsafe"
"modernc.org/libc"
sqlite3 "modernc.org/sqlite/lib"
)
var (
fToken uintptr
// New, FS.Close
mu sync.Mutex
objectMu sync.Mutex
objects = map[uintptr]interface{}{}
)
func token() uintptr { return atomic.AddUintptr(&fToken, 1) }
func addObject(o interface{}) uintptr {
t := token()
objectMu.Lock()
objects[t] = o
objectMu.Unlock()
return t
}
func getObject(t uintptr) interface{} {
objectMu.Lock()
o := objects[t]
if o == nil {
panic("internal error")
}
objectMu.Unlock()
return o
}
func removeObject(t uintptr) {
objectMu.Lock()
if _, ok := objects[t]; !ok {
panic("internal error")
}
delete(objects, t)
objectMu.Unlock()
}
var vfsio = sqlite3_io_methods{
iVersion: 1, // iVersion
}
func vfsOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pFile uintptr, flags int32, pOutFlags uintptr) int32 {
if zName == 0 {
return sqlite3.SQLITE_IOERR
}
if flags&sqlite3.SQLITE_OPEN_MAIN_JOURNAL != 0 {
return sqlite3.SQLITE_NOMEM
}
p := pFile
*(*VFSFile)(unsafe.Pointer(p)) = VFSFile{}
fsys := getObject((*sqlite3_vfs)(unsafe.Pointer(pVfs)).pAppData).(fs.FS)
f, err := fsys.Open(libc.GoString(zName))
if err != nil {
return sqlite3.SQLITE_CANTOPEN
}
h := addObject(f)
(*VFSFile)(unsafe.Pointer(p)).fsFile = h
if pOutFlags != 0 {
*(*int32)(unsafe.Pointer(pOutFlags)) = int32(os.O_RDONLY)
}
(*VFSFile)(unsafe.Pointer(p)).base.pMethods = uintptr(unsafe.Pointer(&vfsio))
return sqlite3.SQLITE_OK
}
func vfsRead(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst sqlite_int64) int32 {
p := pFile
f := getObject((*VFSFile)(unsafe.Pointer(p)).fsFile).(fs.File)
seeker, ok := f.(io.Seeker)
if !ok {
return sqlite3.SQLITE_IOERR_READ
}
if n, err := seeker.Seek(iOfst, io.SeekStart); err != nil || n != iOfst {
return sqlite3.SQLITE_IOERR_READ
}
b := (*libc.RawMem)(unsafe.Pointer(zBuf))[:iAmt]
n, err := f.Read(b)
if n == int(iAmt) {
return sqlite3.SQLITE_OK
}
if n < int(iAmt) && err == nil {
b := b[n:]
for i := range b {
b[i] = 0
}
return sqlite3.SQLITE_IOERR_SHORT_READ
}
return sqlite3.SQLITE_IOERR_READ
}
func vfsAccess(tls *libc.TLS, pVfs uintptr, zPath uintptr, flags int32, pResOut uintptr) int32 {
if flags == sqlite3.SQLITE_ACCESS_READWRITE {
*(*int32)(unsafe.Pointer(pResOut)) = 0
return sqlite3.SQLITE_OK
}
fn := libc.GoString(zPath)
fsys := getObject((*sqlite3_vfs)(unsafe.Pointer(pVfs)).pAppData).(fs.FS)
if _, err := fs.Stat(fsys, fn); err != nil {
*(*int32)(unsafe.Pointer(pResOut)) = 0
return sqlite3.SQLITE_OK
}
*(*int32)(unsafe.Pointer(pResOut)) = 1
return sqlite3.SQLITE_OK
}
func vfsFileSize(tls *libc.TLS, pFile uintptr, pSize uintptr) int32 {
p := pFile
f := getObject((*VFSFile)(unsafe.Pointer(p)).fsFile).(fs.File)
fi, err := f.Stat()
if err != nil {
return sqlite3.SQLITE_IOERR_FSTAT
}
*(*sqlite_int64)(unsafe.Pointer(pSize)) = fi.Size()
return sqlite3.SQLITE_OK
}
func vfsClose(tls *libc.TLS, pFile uintptr) int32 {
p := pFile
h := (*VFSFile)(unsafe.Pointer(p)).fsFile
f := getObject(h).(fs.File)
f.Close()
removeObject(h)
return sqlite3.SQLITE_OK
}
// FS represents a SQLite read only file system backed by Go's fs.FS.
type FS struct {
cname uintptr
cvfs uintptr
fsHandle uintptr
name string
tls *libc.TLS
closed int32
}
// New creates a new sqlite VFS and registers it. If successful, the
// file system can be used with the URI parameter `?vfs=<returned name>`.
func New(fs fs.FS) (name string, _ *FS, _ error) {
if fs == nil {
return "", nil, fmt.Errorf("fs argument cannot be nil")
}
mu.Lock()
defer mu.Unlock()
tls := libc.NewTLS()
h := addObject(fs)
name = fmt.Sprintf("vfs%x", h)
cname, err := libc.CString(name)
if err != nil {
return "", nil, err
}
vfs := Xsqlite3_fsFS(tls, cname, h)
if vfs == 0 {
removeObject(h)
libc.Xfree(tls, cname)
tls.Close()
return "", nil, fmt.Errorf("out of memory")
}
if rc := sqlite3.Xsqlite3_vfs_register(tls, vfs, libc.Bool32(false)); rc != sqlite3.SQLITE_OK {
removeObject(h)
libc.Xfree(tls, cname)
libc.Xfree(tls, vfs)
tls.Close()
return "", nil, fmt.Errorf("registering VFS %s: %d", name, rc)
}
return name, &FS{name: name, cname: cname, cvfs: vfs, fsHandle: h, tls: tls}, nil
}
// Close unregisters f and releases its resources.
func (f *FS) Close() error {
if atomic.SwapInt32(&f.closed, 1) != 0 {
return nil
}
mu.Lock()
defer mu.Unlock()
rc := sqlite3.Xsqlite3_vfs_unregister(f.tls, f.cvfs)
libc.Xfree(f.tls, f.cname)
libc.Xfree(f.tls, f.cvfs)
f.tls.Close()
removeObject(f.fsHandle)
if rc != 0 {
return fmt.Errorf("unregistering VFS %s: %d", f.name, rc)
}
return nil
}

32
vfs/patches32.go Normal file
View file

@ -0,0 +1,32 @@
// Copyright 2022 The Sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build 386 || arm
// +build 386 arm
package vfs
import (
"unsafe"
"modernc.org/libc"
sqlite3 "modernc.org/sqlite/lib"
)
func init() {
*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 4)) = vfsClose
*(*func(*libc.TLS, uintptr, uintptr, int32, sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 8)) = vfsRead
*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 24)) = vfsFileSize
*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 28)) = vfsLock
*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 32)) = vfsUnlock
*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 36)) = vfsCheckReservedLock
*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 40)) = vfsFileControl
*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 44)) = vfsSectorSize
*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 48)) = vfsDeviceCharacteristics
}
func vfsFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nPathOut int32, zPathOut uintptr) int32 {
libc.Xstrncpy(tls, zPathOut, zPath, uint32(nPathOut))
return sqlite3.SQLITE_OK
}

32
vfs/patches64.go Normal file
View file

@ -0,0 +1,32 @@
// Copyright 2022 The Sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !arm && !386
// +build !arm,!386
package vfs
import (
"unsafe"
"modernc.org/libc"
sqlite3 "modernc.org/sqlite/lib"
)
func init() {
*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 8)) = vfsClose
*(*func(*libc.TLS, uintptr, uintptr, int32, sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 16)) = vfsRead
*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 48)) = vfsFileSize
*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 56)) = vfsLock
*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 64)) = vfsUnlock
*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 72)) = vfsCheckReservedLock
*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 80)) = vfsFileControl
*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 88)) = vfsSectorSize
*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfsio)) + 96)) = vfsDeviceCharacteristics
}
func vfsFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nPathOut int32, zPathOut uintptr) int32 {
libc.Xstrncpy(tls, zPathOut, zPath, uint64(nPathOut))
return sqlite3.SQLITE_OK
}

2959
vfs/vfs_darwin_amd64.go Normal file

File diff suppressed because it is too large Load diff

1342
vfs/vfs_darwin_arm64.go Normal file

File diff suppressed because it is too large Load diff

1051
vfs/vfs_freebsd_386.go Normal file

File diff suppressed because it is too large Load diff

1082
vfs/vfs_freebsd_amd64.go Normal file

File diff suppressed because it is too large Load diff

1030
vfs/vfs_freebsd_arm.go Normal file

File diff suppressed because it is too large Load diff

1082
vfs/vfs_freebsd_arm64.go Normal file

File diff suppressed because it is too large Load diff

1501
vfs/vfs_linux_386.go Normal file

File diff suppressed because it is too large Load diff

1528
vfs/vfs_linux_amd64.go Normal file

File diff suppressed because it is too large Load diff

1421
vfs/vfs_linux_arm.go Normal file

File diff suppressed because it is too large Load diff

1559
vfs/vfs_linux_arm64.go Normal file

File diff suppressed because it is too large Load diff

2754
vfs/vfs_linux_loong64.go Normal file

File diff suppressed because it is too large Load diff

1528
vfs/vfs_linux_ppc64le.go Normal file

File diff suppressed because it is too large Load diff

1528
vfs/vfs_linux_riscv64.go Normal file

File diff suppressed because it is too large Load diff

1528
vfs/vfs_linux_s390x.go Normal file

File diff suppressed because it is too large Load diff

1118
vfs/vfs_netbsd_amd64.go Normal file

File diff suppressed because it is too large Load diff

891
vfs/vfs_openbsd_amd64.go Normal file
View file

@ -0,0 +1,891 @@
// Code generated by 'ccgo -o vfs_openbsd_amd64.go c/vfs.c -I../testdata/sqlite-amalgamation-3380500 -lmodernc.org/sqlite/lib -pkgname vfs -nocapi -export-externs X -D SQLITE_OS_UNIX -hide=vfsFullPathname -hide=vfsOpen -hide=vfsRead -hide=vfsAccess -hide=vfsFileSize -hide=vfsClose', DO NOT EDIT.
package vfs
import (
"math"
"reflect"
"sync/atomic"
"unsafe"
"modernc.org/libc"
"modernc.org/libc/sys/types"
"modernc.org/sqlite/lib"
)
var _ = math.Pi
var _ reflect.Kind
var _ atomic.Value
var _ unsafe.Pointer
var _ *libc.TLS
var _ types.Size_t
type ptrdiff_t = int64
type size_t = uint64
type wchar_t = int32
type va_list = uintptr
type sqlite_int64 = int64
type sqlite_uint64 = uint64
type sqlite3_int64 = sqlite_int64
type sqlite3_uint64 = sqlite_uint64
type sqlite3_callback = uintptr
type sqlite3_file1 = struct{ pMethods uintptr }
type sqlite3_file = sqlite3_file1
type sqlite3_io_methods1 = struct {
iVersion int32
_ [4]byte
xClose uintptr
xRead uintptr
xWrite uintptr
xTruncate uintptr
xSync uintptr
xFileSize uintptr
xLock uintptr
xUnlock uintptr
xCheckReservedLock uintptr
xFileControl uintptr
xSectorSize uintptr
xDeviceCharacteristics uintptr
xShmMap uintptr
xShmLock uintptr
xShmBarrier uintptr
xShmUnmap uintptr
xFetch uintptr
xUnfetch uintptr
}
type sqlite3_io_methods = sqlite3_io_methods1
type sqlite3_vfs1 = struct {
iVersion int32
szOsFile int32
mxPathname int32
_ [4]byte
pNext uintptr
zName uintptr
pAppData uintptr
xOpen uintptr
xDelete uintptr
xAccess uintptr
xFullPathname uintptr
xDlOpen uintptr
xDlError uintptr
xDlSym uintptr
xDlClose uintptr
xRandomness uintptr
xSleep uintptr
xCurrentTime uintptr
xGetLastError uintptr
xCurrentTimeInt64 uintptr
xSetSystemCall uintptr
xGetSystemCall uintptr
xNextSystemCall uintptr
}
type sqlite3_vfs = sqlite3_vfs1
type sqlite3_syscall_ptr = uintptr
type sqlite3_mem_methods1 = struct {
xMalloc uintptr
xFree uintptr
xRealloc uintptr
xSize uintptr
xRoundup uintptr
xInit uintptr
xShutdown uintptr
pAppData uintptr
}
type sqlite3_mem_methods = sqlite3_mem_methods1
type sqlite3_destructor_type = uintptr
type sqlite3_vtab1 = struct {
pModule uintptr
nRef int32
_ [4]byte
zErrMsg uintptr
}
type sqlite3_vtab = sqlite3_vtab1
type sqlite3_index_info1 = struct {
nConstraint int32
_ [4]byte
aConstraint uintptr
nOrderBy int32
_ [4]byte
aOrderBy uintptr
aConstraintUsage uintptr
idxNum int32
_ [4]byte
idxStr uintptr
needToFreeIdxStr int32
orderByConsumed int32
estimatedCost float64
estimatedRows sqlite3_int64
idxFlags int32
_ [4]byte
colUsed sqlite3_uint64
}
type sqlite3_index_info = sqlite3_index_info1
type sqlite3_vtab_cursor1 = struct{ pVtab uintptr }
type sqlite3_vtab_cursor = sqlite3_vtab_cursor1
type sqlite3_module1 = struct {
iVersion int32
_ [4]byte
xCreate uintptr
xConnect uintptr
xBestIndex uintptr
xDisconnect uintptr
xDestroy uintptr
xOpen uintptr
xClose uintptr
xFilter uintptr
xNext uintptr
xEof uintptr
xColumn uintptr
xRowid uintptr
xUpdate uintptr
xBegin uintptr
xSync uintptr
xCommit uintptr
xRollback uintptr
xFindFunction uintptr
xRename uintptr
xSavepoint uintptr
xRelease uintptr
xRollbackTo uintptr
xShadowName uintptr
}
type sqlite3_module = sqlite3_module1
type sqlite3_index_constraint = struct {
iColumn int32
op uint8
usable uint8
_ [2]byte
iTermOffset int32
}
type sqlite3_index_orderby = struct {
iColumn int32
desc uint8
_ [3]byte
}
type sqlite3_index_constraint_usage = struct {
argvIndex int32
omit uint8
_ [3]byte
}
type sqlite3_mutex_methods1 = struct {
xMutexInit uintptr
xMutexEnd uintptr
xMutexAlloc uintptr
xMutexFree uintptr
xMutexEnter uintptr
xMutexTry uintptr
xMutexLeave uintptr
xMutexHeld uintptr
xMutexNotheld uintptr
}
type sqlite3_mutex_methods = sqlite3_mutex_methods1
type sqlite3_pcache_page1 = struct {
pBuf uintptr
pExtra uintptr
}
type sqlite3_pcache_page = sqlite3_pcache_page1
type sqlite3_pcache_methods21 = struct {
iVersion int32
_ [4]byte
pArg uintptr
xInit uintptr
xShutdown uintptr
xCreate uintptr
xCachesize uintptr
xPagecount uintptr
xFetch uintptr
xUnpin uintptr
xRekey uintptr
xTruncate uintptr
xDestroy uintptr
xShrink uintptr
}
type sqlite3_pcache_methods2 = sqlite3_pcache_methods21
type sqlite3_pcache_methods1 = struct {
pArg uintptr
xInit uintptr
xShutdown uintptr
xCreate uintptr
xCachesize uintptr
xPagecount uintptr
xFetch uintptr
xUnpin uintptr
xRekey uintptr
xTruncate uintptr
xDestroy uintptr
}
type sqlite3_pcache_methods = sqlite3_pcache_methods1
type sqlite3_snapshot1 = struct{ hidden [48]uint8 }
type sqlite3_snapshot = sqlite3_snapshot1
type sqlite3_rtree_geometry1 = struct {
pContext uintptr
nParam int32
_ [4]byte
aParam uintptr
pUser uintptr
xDelUser uintptr
}
type sqlite3_rtree_geometry = sqlite3_rtree_geometry1
type sqlite3_rtree_query_info1 = struct {
pContext uintptr
nParam int32
_ [4]byte
aParam uintptr
pUser uintptr
xDelUser uintptr
aCoord uintptr
anQueue uintptr
nCoord int32
iLevel int32
mxLevel int32
_ [4]byte
iRowid sqlite3_int64
rParentScore sqlite3_rtree_dbl
eParentWithin int32
eWithin int32
rScore sqlite3_rtree_dbl
apSqlParam uintptr
}
type sqlite3_rtree_query_info = sqlite3_rtree_query_info1
type sqlite3_rtree_dbl = float64
type Fts5ExtensionApi1 = struct {
iVersion int32
_ [4]byte
xUserData uintptr
xColumnCount uintptr
xRowCount uintptr
xColumnTotalSize uintptr
xTokenize uintptr
xPhraseCount uintptr
xPhraseSize uintptr
xInstCount uintptr
xInst uintptr
xRowid uintptr
xColumnText uintptr
xColumnSize uintptr
xQueryPhrase uintptr
xSetAuxdata uintptr
xGetAuxdata uintptr
xPhraseFirst uintptr
xPhraseNext uintptr
xPhraseFirstColumn uintptr
xPhraseNextColumn uintptr
}
type Fts5ExtensionApi = Fts5ExtensionApi1
type Fts5PhraseIter1 = struct {
a uintptr
b uintptr
}
type Fts5PhraseIter = Fts5PhraseIter1
type fts5_extension_function = uintptr
type fts5_tokenizer1 = struct {
xCreate uintptr
xDelete uintptr
xTokenize uintptr
}
type fts5_tokenizer = fts5_tokenizer1
type fts5_api1 = struct {
iVersion int32
_ [4]byte
xCreateTokenizer uintptr
xFindTokenizer uintptr
xCreateFunction uintptr
}
type fts5_api = fts5_api1
type locale_t = uintptr
type u_char = uint8
type u_short = uint16
type u_int = uint32
type u_long = uint64
type unchar = uint8
type ushort = uint16
type uint = uint32
type ulong = uint64
type cpuid_t = uint64
type register_t = int64
type int8_t = int8
type uint8_t = uint8
type int16_t = int16
type uint16_t = uint16
type int32_t = int32
type uint32_t = uint32
type int64_t = int64
type uint64_t = uint64
type u_int8_t = uint8
type u_int16_t = uint16
type u_int32_t = uint32
type u_int64_t = uint64
type quad_t = int64
type u_quad_t = uint64
type vaddr_t = uint64
type paddr_t = uint64
type vsize_t = uint64
type psize_t = uint64
type blkcnt_t = int64
type blksize_t = int32
type caddr_t = uintptr
type daddr32_t = int32
type daddr_t = int64
type dev_t = int32
type fixpt_t = uint32
type gid_t = uint32
type id_t = uint32
type ino_t = uint64
type key_t = int64
type mode_t = uint32
type nlink_t = uint32
type rlim_t = uint64
type segsz_t = int32
type swblk_t = int32
type uid_t = uint32
type useconds_t = uint32
type suseconds_t = int64
type fsblkcnt_t = uint64
type fsfilcnt_t = uint64
type clock_t = int64
type clockid_t = int32
type pid_t = int32
type ssize_t = int64
type time_t = int64
type timer_t = int32
type off_t = int64
type timeval = struct {
tv_sec time_t
tv_usec suseconds_t
}
type timespec = struct {
tv_sec time_t
tv_nsec int64
}
type fd_set1 = struct{ fds_bits [32]uint32 }
type fd_set = fd_set1
type sigset_t = uint32
type timezone = struct {
tz_minuteswest int32
tz_dsttime int32
}
type itimerval = struct {
it_interval struct {
tv_sec time_t
tv_usec suseconds_t
}
it_value struct {
tv_sec time_t
tv_usec suseconds_t
}
}
type clockinfo = struct {
hz int32
tick int32
stathz int32
profhz int32
}
type itimerspec = struct {
it_interval struct {
tv_sec time_t
tv_nsec int64
}
it_value struct {
tv_sec time_t
tv_nsec int64
}
}
type tm = struct {
tm_sec int32
tm_min int32
tm_hour int32
tm_mday int32
tm_mon int32
tm_year int32
tm_wday int32
tm_yday int32
tm_isdst int32
_ [4]byte
tm_gmtoff int64
tm_zone uintptr
}
type stat = struct {
st_mode mode_t
st_dev dev_t
st_ino ino_t
st_nlink nlink_t
st_uid uid_t
st_gid gid_t
st_rdev dev_t
st_atim struct {
tv_sec time_t
tv_nsec int64
}
st_mtim struct {
tv_sec time_t
tv_nsec int64
}
st_ctim struct {
tv_sec time_t
tv_nsec int64
}
st_size off_t
st_blocks blkcnt_t
st_blksize blksize_t
st_flags u_int32_t
st_gen u_int32_t
_ [4]byte
__st_birthtim struct {
tv_sec time_t
tv_nsec int64
}
}
type flock = struct {
l_start off_t
l_len off_t
l_pid pid_t
l_type int16
l_whence int16
}
type sig_atomic_t = int32
type sigcontext = struct {
sc_rdi int64
sc_rsi int64
sc_rdx int64
sc_rcx int64
sc_r8 int64
sc_r9 int64
sc_r10 int64
sc_r11 int64
sc_r12 int64
sc_r13 int64
sc_r14 int64
sc_r15 int64
sc_rbp int64
sc_rbx int64
sc_rax int64
sc_gs int64
sc_fs int64
sc_es int64
sc_ds int64
sc_trapno int64
sc_err int64
sc_rip int64
sc_cs int64
sc_rflags int64
sc_rsp int64
sc_ss int64
sc_fpstate uintptr
__sc_unused int32
sc_mask int32
sc_cookie int64
}
type sigval = struct {
_ [0]uint64
sival_int int32
_ [4]byte
}
type siginfo_t = struct {
si_signo int32
si_code int32
si_errno int32
_ [4]byte
_data struct {
_ [0]uint64
_pad [29]int32
_ [4]byte
}
}
type sigaction = struct {
__sigaction_u struct{ __sa_handler uintptr }
sa_mask sigset_t
sa_flags int32
}
type sig_t = uintptr
type sigvec = struct {
sv_handler uintptr
sv_mask int32
sv_flags int32
}
type sigaltstack = struct {
ss_sp uintptr
ss_size size_t
ss_flags int32
_ [4]byte
}
type stack_t = sigaltstack
type ucontext_t = sigcontext
type __tfork = struct {
tf_tcb uintptr
tf_tid uintptr
tf_stack uintptr
}
type __kbind = struct {
kb_addr uintptr
kb_size size_t
}
type intptr_t = int64
type VFSFile1 = struct {
base sqlite3_file
fsFile uintptr
fd int32
_ [4]byte
aBuffer uintptr
nBuffer int32
_ [4]byte
iBufferOfst sqlite3_int64
}
type VFSFile = VFSFile1
func vfsDirectWrite(tls *libc.TLS, p uintptr, zBuf uintptr, iAmt int32, iOfst sqlite_int64) int32 {
bp := tls.Alloc(16)
defer tls.Free(16)
var ofst off_t
var nWrite size_t
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__)), 178))
libc.X__builtin_abort(tls)
ofst = libc.Xlseek(tls, (*VFSFile)(unsafe.Pointer(p)).fd, iOfst, 0)
if ofst != iOfst {
return 10 | int32(3)<<8
}
nWrite = size_t(libc.Xwrite(tls, (*VFSFile)(unsafe.Pointer(p)).fd, zBuf, uint64(iAmt)))
if nWrite != size_t(iAmt) {
return 10 | int32(3)<<8
}
return 0
}
var __func__ = *(*[15]int8)(unsafe.Pointer(ts + 13))
func vfsFlushBuffer(tls *libc.TLS, p uintptr) int32 {
bp := tls.Alloc(16)
defer tls.Free(16)
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__1)), 198))
libc.X__builtin_abort(tls)
var rc int32 = 0
if (*VFSFile)(unsafe.Pointer(p)).nBuffer != 0 {
rc = vfsDirectWrite(tls, p, (*VFSFile)(unsafe.Pointer(p)).aBuffer, (*VFSFile)(unsafe.Pointer(p)).nBuffer, (*VFSFile)(unsafe.Pointer(p)).iBufferOfst)
(*VFSFile)(unsafe.Pointer(p)).nBuffer = 0
}
return rc
}
var __func__1 = *(*[15]int8)(unsafe.Pointer(ts + 28))
func vfsWrite(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst sqlite_int64) int32 {
bp := tls.Alloc(16)
defer tls.Free(16)
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__4)), 273))
libc.X__builtin_abort(tls)
var p uintptr = pFile
if (*VFSFile)(unsafe.Pointer(p)).aBuffer != 0 {
var z uintptr = zBuf
var n int32 = iAmt
var i sqlite3_int64 = iOfst
for n > 0 {
var nCopy int32
if (*VFSFile)(unsafe.Pointer(p)).nBuffer == 8192 || (*VFSFile)(unsafe.Pointer(p)).iBufferOfst+sqlite3_int64((*VFSFile)(unsafe.Pointer(p)).nBuffer) != i {
var rc int32 = vfsFlushBuffer(tls, p)
if rc != 0 {
return rc
}
}
if !((*VFSFile)(unsafe.Pointer(p)).nBuffer == 0 || (*VFSFile)(unsafe.Pointer(p)).iBufferOfst+sqlite3_int64((*VFSFile)(unsafe.Pointer(p)).nBuffer) == i) {
libc.X__assert2(tls, ts+43, 294, uintptr(unsafe.Pointer(&__func__4)), ts+51)
}
(*VFSFile)(unsafe.Pointer(p)).iBufferOfst = i - sqlite3_int64((*VFSFile)(unsafe.Pointer(p)).nBuffer)
nCopy = 8192 - (*VFSFile)(unsafe.Pointer(p)).nBuffer
if nCopy > n {
nCopy = n
}
libc.Xmemcpy(tls, (*VFSFile)(unsafe.Pointer(p)).aBuffer+uintptr((*VFSFile)(unsafe.Pointer(p)).nBuffer), z, uint64(nCopy))
*(*int32)(unsafe.Pointer(p + 32)) += nCopy
n = n - nCopy
i = i + sqlite3_int64(nCopy)
z += uintptr(nCopy)
}
} else {
return vfsDirectWrite(tls, p, zBuf, iAmt, iOfst)
}
return 0
}
var __func__4 = *(*[9]int8)(unsafe.Pointer(ts + 97))
func vfsTruncate(tls *libc.TLS, pFile uintptr, size sqlite_int64) int32 {
return 0
}
func vfsSync(tls *libc.TLS, pFile uintptr, flags int32) int32 {
bp := tls.Alloc(16)
defer tls.Free(16)
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__5)), 331))
libc.X__builtin_abort(tls)
var p uintptr = pFile
var rc int32
rc = vfsFlushBuffer(tls, p)
if rc != 0 {
return rc
}
rc = libc.Xfsync(tls, (*VFSFile)(unsafe.Pointer(p)).fd)
return func() int32 {
if rc == 0 {
return 0
}
return 10 | int32(4)<<8
}()
}
var __func__5 = *(*[8]int8)(unsafe.Pointer(ts + 106))
func vfsLock(tls *libc.TLS, pFile uintptr, eLock int32) int32 {
return 0
}
func vfsUnlock(tls *libc.TLS, pFile uintptr, eLock int32) int32 {
return 0
}
func vfsCheckReservedLock(tls *libc.TLS, pFile uintptr, pResOut uintptr) int32 {
*(*int32)(unsafe.Pointer(pResOut)) = 0
return 0
}
func vfsFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) int32 {
return 12
}
func vfsSectorSize(tls *libc.TLS, pFile uintptr) int32 {
return 0
}
func vfsDeviceCharacteristics(tls *libc.TLS, pFile uintptr) int32 {
return 0
}
func vfsDelete(tls *libc.TLS, pVfs uintptr, zPath uintptr, dirSync int32) int32 {
bp := tls.Alloc(4129)
defer tls.Free(4129)
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__8)), 473))
libc.X__builtin_abort(tls)
var rc int32
rc = libc.Xunlink(tls, zPath)
if rc != 0 && *(*int32)(unsafe.Pointer(libc.X__errno(tls))) == 2 {
return 0
}
if rc == 0 && dirSync != 0 {
var dfd int32
var i int32
sqlite3.Xsqlite3_snprintf(tls, 4096, bp+32, ts+114, libc.VaList(bp+16, zPath))
*(*int8)(unsafe.Pointer(bp + 32 + 4096)) = int8(0)
for i = int32(libc.Xstrlen(tls, bp+32)); i > 1 && int32(*(*int8)(unsafe.Pointer(bp + 32 + uintptr(i)))) != '/'; i++ {
}
*(*int8)(unsafe.Pointer(bp + 32 + uintptr(i))) = int8(0)
dfd = libc.Xopen(tls, bp+32, 0x0000, libc.VaList(bp+24, 0))
if dfd < 0 {
rc = -1
} else {
rc = libc.Xfsync(tls, dfd)
libc.Xclose(tls, dfd)
}
}
return func() int32 {
if rc == 0 {
return 0
}
return 10 | int32(10)<<8
}()
}
var __func__8 = *(*[10]int8)(unsafe.Pointer(ts + 117))
func vfsDlOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr) uintptr {
return uintptr(0)
}
func vfsDlError(tls *libc.TLS, pVfs uintptr, nByte int32, zErrMsg uintptr) {
sqlite3.Xsqlite3_snprintf(tls, nByte, zErrMsg, ts+127, 0)
*(*int8)(unsafe.Pointer(zErrMsg + uintptr(nByte-1))) = int8(0)
}
func vfsDlSym(tls *libc.TLS, pVfs uintptr, pH uintptr, z uintptr) uintptr {
return uintptr(0)
}
func vfsDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
return
}
func vfsRandomness(tls *libc.TLS, pVfs uintptr, nByte int32, zByte uintptr) int32 {
return 0
}
func vfsSleep(tls *libc.TLS, pVfs uintptr, nMicro int32) int32 {
libc.Xsleep(tls, uint32(nMicro/1000000))
libc.Xusleep(tls, uint32(nMicro%1000000))
return nMicro
}
func vfsCurrentTime(tls *libc.TLS, pVfs uintptr, pTime uintptr) int32 {
var t time_t = libc.Xtime(tls, uintptr(0))
*(*float64)(unsafe.Pointer(pTime)) = float64(t)/86400.0 + 2440587.5
return 0
}
func Xsqlite3_fsFS(tls *libc.TLS, zName uintptr, pAppData uintptr) uintptr {
var p uintptr = libc.Xmalloc(tls, types.Size_t(unsafe.Sizeof(sqlite3_vfs{})))
if !(p != 0) {
return uintptr(0)
}
*(*sqlite3_vfs)(unsafe.Pointer(p)) = sqlite3_vfs{
iVersion: 1,
szOsFile: int32(unsafe.Sizeof(VFSFile{})),
mxPathname: 4096,
zName: zName,
pAppData: pAppData,
xOpen: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32
}{vfsOpen})),
xDelete: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, int32) int32
}{vfsDelete})),
xAccess: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
}{vfsAccess})),
xFullPathname: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
}{vfsFullPathname})),
xDlOpen: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr) uintptr
}{vfsDlOpen})),
xDlError: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, int32, uintptr)
}{vfsDlError})),
xDlSym: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, uintptr) uintptr
}{vfsDlSym})),
xDlClose: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr)
}{vfsDlClose})),
xRandomness: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, int32, uintptr) int32
}{vfsRandomness})),
xSleep: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, int32) int32
}{vfsSleep})),
xCurrentTime: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr) int32
}{vfsCurrentTime}))}
return p
}
var ts1 = "TODO %s:%i:\n\x00vfsDirectWrite\x00vfsFlushBuffer\x00c/vfs.c\x00p->nBuffer==0 || p->iBufferOfst+p->nBuffer==i\x00vfsWrite\x00vfsSync\x00%s\x00vfsDelete\x00Loadable extensions are not supported\x00"
var ts = (*reflect.StringHeader)(unsafe.Pointer(&ts1)).Data

891
vfs/vfs_openbsd_arm64.go Normal file
View file

@ -0,0 +1,891 @@
// Code generated by 'ccgo -o vfs_openbsd_amd64.go c/vfs.c -I../testdata/sqlite-amalgamation-3380500 -lmodernc.org/sqlite/lib -pkgname vfs -nocapi -export-externs X -D SQLITE_OS_UNIX -hide=vfsFullPathname -hide=vfsOpen -hide=vfsRead -hide=vfsAccess -hide=vfsFileSize -hide=vfsClose', DO NOT EDIT.
package vfs
import (
"math"
"reflect"
"sync/atomic"
"unsafe"
"modernc.org/libc"
"modernc.org/libc/sys/types"
"modernc.org/sqlite/lib"
)
var _ = math.Pi
var _ reflect.Kind
var _ atomic.Value
var _ unsafe.Pointer
var _ *libc.TLS
var _ types.Size_t
type ptrdiff_t = int64
type size_t = uint64
type wchar_t = int32
type va_list = uintptr
type sqlite_int64 = int64
type sqlite_uint64 = uint64
type sqlite3_int64 = sqlite_int64
type sqlite3_uint64 = sqlite_uint64
type sqlite3_callback = uintptr
type sqlite3_file1 = struct{ pMethods uintptr }
type sqlite3_file = sqlite3_file1
type sqlite3_io_methods1 = struct {
iVersion int32
_ [4]byte
xClose uintptr
xRead uintptr
xWrite uintptr
xTruncate uintptr
xSync uintptr
xFileSize uintptr
xLock uintptr
xUnlock uintptr
xCheckReservedLock uintptr
xFileControl uintptr
xSectorSize uintptr
xDeviceCharacteristics uintptr
xShmMap uintptr
xShmLock uintptr
xShmBarrier uintptr
xShmUnmap uintptr
xFetch uintptr
xUnfetch uintptr
}
type sqlite3_io_methods = sqlite3_io_methods1
type sqlite3_vfs1 = struct {
iVersion int32
szOsFile int32
mxPathname int32
_ [4]byte
pNext uintptr
zName uintptr
pAppData uintptr
xOpen uintptr
xDelete uintptr
xAccess uintptr
xFullPathname uintptr
xDlOpen uintptr
xDlError uintptr
xDlSym uintptr
xDlClose uintptr
xRandomness uintptr
xSleep uintptr
xCurrentTime uintptr
xGetLastError uintptr
xCurrentTimeInt64 uintptr
xSetSystemCall uintptr
xGetSystemCall uintptr
xNextSystemCall uintptr
}
type sqlite3_vfs = sqlite3_vfs1
type sqlite3_syscall_ptr = uintptr
type sqlite3_mem_methods1 = struct {
xMalloc uintptr
xFree uintptr
xRealloc uintptr
xSize uintptr
xRoundup uintptr
xInit uintptr
xShutdown uintptr
pAppData uintptr
}
type sqlite3_mem_methods = sqlite3_mem_methods1
type sqlite3_destructor_type = uintptr
type sqlite3_vtab1 = struct {
pModule uintptr
nRef int32
_ [4]byte
zErrMsg uintptr
}
type sqlite3_vtab = sqlite3_vtab1
type sqlite3_index_info1 = struct {
nConstraint int32
_ [4]byte
aConstraint uintptr
nOrderBy int32
_ [4]byte
aOrderBy uintptr
aConstraintUsage uintptr
idxNum int32
_ [4]byte
idxStr uintptr
needToFreeIdxStr int32
orderByConsumed int32
estimatedCost float64
estimatedRows sqlite3_int64
idxFlags int32
_ [4]byte
colUsed sqlite3_uint64
}
type sqlite3_index_info = sqlite3_index_info1
type sqlite3_vtab_cursor1 = struct{ pVtab uintptr }
type sqlite3_vtab_cursor = sqlite3_vtab_cursor1
type sqlite3_module1 = struct {
iVersion int32
_ [4]byte
xCreate uintptr
xConnect uintptr
xBestIndex uintptr
xDisconnect uintptr
xDestroy uintptr
xOpen uintptr
xClose uintptr
xFilter uintptr
xNext uintptr
xEof uintptr
xColumn uintptr
xRowid uintptr
xUpdate uintptr
xBegin uintptr
xSync uintptr
xCommit uintptr
xRollback uintptr
xFindFunction uintptr
xRename uintptr
xSavepoint uintptr
xRelease uintptr
xRollbackTo uintptr
xShadowName uintptr
}
type sqlite3_module = sqlite3_module1
type sqlite3_index_constraint = struct {
iColumn int32
op uint8
usable uint8
_ [2]byte
iTermOffset int32
}
type sqlite3_index_orderby = struct {
iColumn int32
desc uint8
_ [3]byte
}
type sqlite3_index_constraint_usage = struct {
argvIndex int32
omit uint8
_ [3]byte
}
type sqlite3_mutex_methods1 = struct {
xMutexInit uintptr
xMutexEnd uintptr
xMutexAlloc uintptr
xMutexFree uintptr
xMutexEnter uintptr
xMutexTry uintptr
xMutexLeave uintptr
xMutexHeld uintptr
xMutexNotheld uintptr
}
type sqlite3_mutex_methods = sqlite3_mutex_methods1
type sqlite3_pcache_page1 = struct {
pBuf uintptr
pExtra uintptr
}
type sqlite3_pcache_page = sqlite3_pcache_page1
type sqlite3_pcache_methods21 = struct {
iVersion int32
_ [4]byte
pArg uintptr
xInit uintptr
xShutdown uintptr
xCreate uintptr
xCachesize uintptr
xPagecount uintptr
xFetch uintptr
xUnpin uintptr
xRekey uintptr
xTruncate uintptr
xDestroy uintptr
xShrink uintptr
}
type sqlite3_pcache_methods2 = sqlite3_pcache_methods21
type sqlite3_pcache_methods1 = struct {
pArg uintptr
xInit uintptr
xShutdown uintptr
xCreate uintptr
xCachesize uintptr
xPagecount uintptr
xFetch uintptr
xUnpin uintptr
xRekey uintptr
xTruncate uintptr
xDestroy uintptr
}
type sqlite3_pcache_methods = sqlite3_pcache_methods1
type sqlite3_snapshot1 = struct{ hidden [48]uint8 }
type sqlite3_snapshot = sqlite3_snapshot1
type sqlite3_rtree_geometry1 = struct {
pContext uintptr
nParam int32
_ [4]byte
aParam uintptr
pUser uintptr
xDelUser uintptr
}
type sqlite3_rtree_geometry = sqlite3_rtree_geometry1
type sqlite3_rtree_query_info1 = struct {
pContext uintptr
nParam int32
_ [4]byte
aParam uintptr
pUser uintptr
xDelUser uintptr
aCoord uintptr
anQueue uintptr
nCoord int32
iLevel int32
mxLevel int32
_ [4]byte
iRowid sqlite3_int64
rParentScore sqlite3_rtree_dbl
eParentWithin int32
eWithin int32
rScore sqlite3_rtree_dbl
apSqlParam uintptr
}
type sqlite3_rtree_query_info = sqlite3_rtree_query_info1
type sqlite3_rtree_dbl = float64
type Fts5ExtensionApi1 = struct {
iVersion int32
_ [4]byte
xUserData uintptr
xColumnCount uintptr
xRowCount uintptr
xColumnTotalSize uintptr
xTokenize uintptr
xPhraseCount uintptr
xPhraseSize uintptr
xInstCount uintptr
xInst uintptr
xRowid uintptr
xColumnText uintptr
xColumnSize uintptr
xQueryPhrase uintptr
xSetAuxdata uintptr
xGetAuxdata uintptr
xPhraseFirst uintptr
xPhraseNext uintptr
xPhraseFirstColumn uintptr
xPhraseNextColumn uintptr
}
type Fts5ExtensionApi = Fts5ExtensionApi1
type Fts5PhraseIter1 = struct {
a uintptr
b uintptr
}
type Fts5PhraseIter = Fts5PhraseIter1
type fts5_extension_function = uintptr
type fts5_tokenizer1 = struct {
xCreate uintptr
xDelete uintptr
xTokenize uintptr
}
type fts5_tokenizer = fts5_tokenizer1
type fts5_api1 = struct {
iVersion int32
_ [4]byte
xCreateTokenizer uintptr
xFindTokenizer uintptr
xCreateFunction uintptr
}
type fts5_api = fts5_api1
type locale_t = uintptr
type u_char = uint8
type u_short = uint16
type u_int = uint32
type u_long = uint64
type unchar = uint8
type ushort = uint16
type uint = uint32
type ulong = uint64
type cpuid_t = uint64
type register_t = int64
type int8_t = int8
type uint8_t = uint8
type int16_t = int16
type uint16_t = uint16
type int32_t = int32
type uint32_t = uint32
type int64_t = int64
type uint64_t = uint64
type u_int8_t = uint8
type u_int16_t = uint16
type u_int32_t = uint32
type u_int64_t = uint64
type quad_t = int64
type u_quad_t = uint64
type vaddr_t = uint64
type paddr_t = uint64
type vsize_t = uint64
type psize_t = uint64
type blkcnt_t = int64
type blksize_t = int32
type caddr_t = uintptr
type daddr32_t = int32
type daddr_t = int64
type dev_t = int32
type fixpt_t = uint32
type gid_t = uint32
type id_t = uint32
type ino_t = uint64
type key_t = int64
type mode_t = uint32
type nlink_t = uint32
type rlim_t = uint64
type segsz_t = int32
type swblk_t = int32
type uid_t = uint32
type useconds_t = uint32
type suseconds_t = int64
type fsblkcnt_t = uint64
type fsfilcnt_t = uint64
type clock_t = int64
type clockid_t = int32
type pid_t = int32
type ssize_t = int64
type time_t = int64
type timer_t = int32
type off_t = int64
type timeval = struct {
tv_sec time_t
tv_usec suseconds_t
}
type timespec = struct {
tv_sec time_t
tv_nsec int64
}
type fd_set1 = struct{ fds_bits [32]uint32 }
type fd_set = fd_set1
type sigset_t = uint32
type timezone = struct {
tz_minuteswest int32
tz_dsttime int32
}
type itimerval = struct {
it_interval struct {
tv_sec time_t
tv_usec suseconds_t
}
it_value struct {
tv_sec time_t
tv_usec suseconds_t
}
}
type clockinfo = struct {
hz int32
tick int32
stathz int32
profhz int32
}
type itimerspec = struct {
it_interval struct {
tv_sec time_t
tv_nsec int64
}
it_value struct {
tv_sec time_t
tv_nsec int64
}
}
type tm = struct {
tm_sec int32
tm_min int32
tm_hour int32
tm_mday int32
tm_mon int32
tm_year int32
tm_wday int32
tm_yday int32
tm_isdst int32
_ [4]byte
tm_gmtoff int64
tm_zone uintptr
}
type stat = struct {
st_mode mode_t
st_dev dev_t
st_ino ino_t
st_nlink nlink_t
st_uid uid_t
st_gid gid_t
st_rdev dev_t
st_atim struct {
tv_sec time_t
tv_nsec int64
}
st_mtim struct {
tv_sec time_t
tv_nsec int64
}
st_ctim struct {
tv_sec time_t
tv_nsec int64
}
st_size off_t
st_blocks blkcnt_t
st_blksize blksize_t
st_flags u_int32_t
st_gen u_int32_t
_ [4]byte
__st_birthtim struct {
tv_sec time_t
tv_nsec int64
}
}
type flock = struct {
l_start off_t
l_len off_t
l_pid pid_t
l_type int16
l_whence int16
}
type sig_atomic_t = int32
type sigcontext = struct {
sc_rdi int64
sc_rsi int64
sc_rdx int64
sc_rcx int64
sc_r8 int64
sc_r9 int64
sc_r10 int64
sc_r11 int64
sc_r12 int64
sc_r13 int64
sc_r14 int64
sc_r15 int64
sc_rbp int64
sc_rbx int64
sc_rax int64
sc_gs int64
sc_fs int64
sc_es int64
sc_ds int64
sc_trapno int64
sc_err int64
sc_rip int64
sc_cs int64
sc_rflags int64
sc_rsp int64
sc_ss int64
sc_fpstate uintptr
__sc_unused int32
sc_mask int32
sc_cookie int64
}
type sigval = struct {
_ [0]uint64
sival_int int32
_ [4]byte
}
type siginfo_t = struct {
si_signo int32
si_code int32
si_errno int32
_ [4]byte
_data struct {
_ [0]uint64
_pad [29]int32
_ [4]byte
}
}
type sigaction = struct {
__sigaction_u struct{ __sa_handler uintptr }
sa_mask sigset_t
sa_flags int32
}
type sig_t = uintptr
type sigvec = struct {
sv_handler uintptr
sv_mask int32
sv_flags int32
}
type sigaltstack = struct {
ss_sp uintptr
ss_size size_t
ss_flags int32
_ [4]byte
}
type stack_t = sigaltstack
type ucontext_t = sigcontext
type __tfork = struct {
tf_tcb uintptr
tf_tid uintptr
tf_stack uintptr
}
type __kbind = struct {
kb_addr uintptr
kb_size size_t
}
type intptr_t = int64
type VFSFile1 = struct {
base sqlite3_file
fsFile uintptr
fd int32
_ [4]byte
aBuffer uintptr
nBuffer int32
_ [4]byte
iBufferOfst sqlite3_int64
}
type VFSFile = VFSFile1
func vfsDirectWrite(tls *libc.TLS, p uintptr, zBuf uintptr, iAmt int32, iOfst sqlite_int64) int32 {
bp := tls.Alloc(16)
defer tls.Free(16)
var ofst off_t
var nWrite size_t
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__)), 178))
libc.X__builtin_abort(tls)
ofst = libc.Xlseek(tls, (*VFSFile)(unsafe.Pointer(p)).fd, iOfst, 0)
if ofst != iOfst {
return 10 | int32(3)<<8
}
nWrite = size_t(libc.Xwrite(tls, (*VFSFile)(unsafe.Pointer(p)).fd, zBuf, uint64(iAmt)))
if nWrite != size_t(iAmt) {
return 10 | int32(3)<<8
}
return 0
}
var __func__ = *(*[15]int8)(unsafe.Pointer(ts + 13))
func vfsFlushBuffer(tls *libc.TLS, p uintptr) int32 {
bp := tls.Alloc(16)
defer tls.Free(16)
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__1)), 198))
libc.X__builtin_abort(tls)
var rc int32 = 0
if (*VFSFile)(unsafe.Pointer(p)).nBuffer != 0 {
rc = vfsDirectWrite(tls, p, (*VFSFile)(unsafe.Pointer(p)).aBuffer, (*VFSFile)(unsafe.Pointer(p)).nBuffer, (*VFSFile)(unsafe.Pointer(p)).iBufferOfst)
(*VFSFile)(unsafe.Pointer(p)).nBuffer = 0
}
return rc
}
var __func__1 = *(*[15]int8)(unsafe.Pointer(ts + 28))
func vfsWrite(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst sqlite_int64) int32 {
bp := tls.Alloc(16)
defer tls.Free(16)
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__4)), 273))
libc.X__builtin_abort(tls)
var p uintptr = pFile
if (*VFSFile)(unsafe.Pointer(p)).aBuffer != 0 {
var z uintptr = zBuf
var n int32 = iAmt
var i sqlite3_int64 = iOfst
for n > 0 {
var nCopy int32
if (*VFSFile)(unsafe.Pointer(p)).nBuffer == 8192 || (*VFSFile)(unsafe.Pointer(p)).iBufferOfst+sqlite3_int64((*VFSFile)(unsafe.Pointer(p)).nBuffer) != i {
var rc int32 = vfsFlushBuffer(tls, p)
if rc != 0 {
return rc
}
}
if !((*VFSFile)(unsafe.Pointer(p)).nBuffer == 0 || (*VFSFile)(unsafe.Pointer(p)).iBufferOfst+sqlite3_int64((*VFSFile)(unsafe.Pointer(p)).nBuffer) == i) {
libc.X__assert2(tls, ts+43, 294, uintptr(unsafe.Pointer(&__func__4)), ts+51)
}
(*VFSFile)(unsafe.Pointer(p)).iBufferOfst = i - sqlite3_int64((*VFSFile)(unsafe.Pointer(p)).nBuffer)
nCopy = 8192 - (*VFSFile)(unsafe.Pointer(p)).nBuffer
if nCopy > n {
nCopy = n
}
libc.Xmemcpy(tls, (*VFSFile)(unsafe.Pointer(p)).aBuffer+uintptr((*VFSFile)(unsafe.Pointer(p)).nBuffer), z, uint64(nCopy))
*(*int32)(unsafe.Pointer(p + 32)) += nCopy
n = n - nCopy
i = i + sqlite3_int64(nCopy)
z += uintptr(nCopy)
}
} else {
return vfsDirectWrite(tls, p, zBuf, iAmt, iOfst)
}
return 0
}
var __func__4 = *(*[9]int8)(unsafe.Pointer(ts + 97))
func vfsTruncate(tls *libc.TLS, pFile uintptr, size sqlite_int64) int32 {
return 0
}
func vfsSync(tls *libc.TLS, pFile uintptr, flags int32) int32 {
bp := tls.Alloc(16)
defer tls.Free(16)
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__5)), 331))
libc.X__builtin_abort(tls)
var p uintptr = pFile
var rc int32
rc = vfsFlushBuffer(tls, p)
if rc != 0 {
return rc
}
rc = libc.Xfsync(tls, (*VFSFile)(unsafe.Pointer(p)).fd)
return func() int32 {
if rc == 0 {
return 0
}
return 10 | int32(4)<<8
}()
}
var __func__5 = *(*[8]int8)(unsafe.Pointer(ts + 106))
func vfsLock(tls *libc.TLS, pFile uintptr, eLock int32) int32 {
return 0
}
func vfsUnlock(tls *libc.TLS, pFile uintptr, eLock int32) int32 {
return 0
}
func vfsCheckReservedLock(tls *libc.TLS, pFile uintptr, pResOut uintptr) int32 {
*(*int32)(unsafe.Pointer(pResOut)) = 0
return 0
}
func vfsFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) int32 {
return 12
}
func vfsSectorSize(tls *libc.TLS, pFile uintptr) int32 {
return 0
}
func vfsDeviceCharacteristics(tls *libc.TLS, pFile uintptr) int32 {
return 0
}
func vfsDelete(tls *libc.TLS, pVfs uintptr, zPath uintptr, dirSync int32) int32 {
bp := tls.Alloc(4129)
defer tls.Free(4129)
libc.X__builtin_printf(tls, ts, libc.VaList(bp, uintptr(unsafe.Pointer(&__func__8)), 473))
libc.X__builtin_abort(tls)
var rc int32
rc = libc.Xunlink(tls, zPath)
if rc != 0 && *(*int32)(unsafe.Pointer(libc.X__errno(tls))) == 2 {
return 0
}
if rc == 0 && dirSync != 0 {
var dfd int32
var i int32
sqlite3.Xsqlite3_snprintf(tls, 4096, bp+32, ts+114, libc.VaList(bp+16, zPath))
*(*int8)(unsafe.Pointer(bp + 32 + 4096)) = int8(0)
for i = int32(libc.Xstrlen(tls, bp+32)); i > 1 && int32(*(*int8)(unsafe.Pointer(bp + 32 + uintptr(i)))) != '/'; i++ {
}
*(*int8)(unsafe.Pointer(bp + 32 + uintptr(i))) = int8(0)
dfd = libc.Xopen(tls, bp+32, 0x0000, libc.VaList(bp+24, 0))
if dfd < 0 {
rc = -1
} else {
rc = libc.Xfsync(tls, dfd)
libc.Xclose(tls, dfd)
}
}
return func() int32 {
if rc == 0 {
return 0
}
return 10 | int32(10)<<8
}()
}
var __func__8 = *(*[10]int8)(unsafe.Pointer(ts + 117))
func vfsDlOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr) uintptr {
return uintptr(0)
}
func vfsDlError(tls *libc.TLS, pVfs uintptr, nByte int32, zErrMsg uintptr) {
sqlite3.Xsqlite3_snprintf(tls, nByte, zErrMsg, ts+127, 0)
*(*int8)(unsafe.Pointer(zErrMsg + uintptr(nByte-1))) = int8(0)
}
func vfsDlSym(tls *libc.TLS, pVfs uintptr, pH uintptr, z uintptr) uintptr {
return uintptr(0)
}
func vfsDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
return
}
func vfsRandomness(tls *libc.TLS, pVfs uintptr, nByte int32, zByte uintptr) int32 {
return 0
}
func vfsSleep(tls *libc.TLS, pVfs uintptr, nMicro int32) int32 {
libc.Xsleep(tls, uint32(nMicro/1000000))
libc.Xusleep(tls, uint32(nMicro%1000000))
return nMicro
}
func vfsCurrentTime(tls *libc.TLS, pVfs uintptr, pTime uintptr) int32 {
var t time_t = libc.Xtime(tls, uintptr(0))
*(*float64)(unsafe.Pointer(pTime)) = float64(t)/86400.0 + 2440587.5
return 0
}
func Xsqlite3_fsFS(tls *libc.TLS, zName uintptr, pAppData uintptr) uintptr {
var p uintptr = libc.Xmalloc(tls, types.Size_t(unsafe.Sizeof(sqlite3_vfs{})))
if !(p != 0) {
return uintptr(0)
}
*(*sqlite3_vfs)(unsafe.Pointer(p)) = sqlite3_vfs{
iVersion: 1,
szOsFile: int32(unsafe.Sizeof(VFSFile{})),
mxPathname: 4096,
zName: zName,
pAppData: pAppData,
xOpen: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32
}{vfsOpen})),
xDelete: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, int32) int32
}{vfsDelete})),
xAccess: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
}{vfsAccess})),
xFullPathname: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
}{vfsFullPathname})),
xDlOpen: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr) uintptr
}{vfsDlOpen})),
xDlError: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, int32, uintptr)
}{vfsDlError})),
xDlSym: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr, uintptr) uintptr
}{vfsDlSym})),
xDlClose: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr)
}{vfsDlClose})),
xRandomness: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, int32, uintptr) int32
}{vfsRandomness})),
xSleep: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, int32) int32
}{vfsSleep})),
xCurrentTime: *(*uintptr)(unsafe.Pointer(&struct {
f func(*libc.TLS, uintptr, uintptr) int32
}{vfsCurrentTime}))}
return p
}
var ts1 = "TODO %s:%i:\n\x00vfsDirectWrite\x00vfsFlushBuffer\x00c/vfs.c\x00p->nBuffer==0 || p->iBufferOfst+p->nBuffer==i\x00vfsWrite\x00vfsSync\x00%s\x00vfsDelete\x00Loadable extensions are not supported\x00"
var ts = (*reflect.StringHeader)(unsafe.Pointer(&ts1)).Data

2192
vfs/vfs_windows_386.go Normal file

File diff suppressed because it is too large Load diff

1528
vfs/vfs_windows_amd64.go Normal file

File diff suppressed because it is too large Load diff

1528
vfs/vfs_windows_arm64.go Normal file

File diff suppressed because it is too large Load diff