Lines Matching refs:FILE
2 ** This file is an amalgamation of many separate C source files from SQLite
4 ** single large file, the entire code can be compiled as a single translation
10 ** This file is all you need to compile SQLite. To use SQLite in other
11 ** programs, you need this file and the "sqlite3.h" header file that defines
13 ** the "sqlite3.h" header file at hand, you will find a copy embedded within
14 ** the text of this file. Search for "Begin file sqlite3.h" to find the start
15 ** of the embedded sqlite3.h header file.) Additional code files may be needed
18 ** separate file. This file contains only code for the core SQLite library.
28 /************** Begin file sqliteInt.h ***************************************/
47 ** These #defines should enable >2GB file support on POSIX if the
49 ** large file support, or if the OS is windows, these should be no-ops.
55 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
82 /************** Begin file sqliteLimit.h *************************************/
95 ** This file defines various limits of what SQLite can process.
194 ** The default number of frames to accumulate in the log file before
263 ** Maximum number of pages in one database file.
531 ** macros to verify that we have tested SQLite for large-file support.
550 /************** Begin file sqlite3.h *****************************************/
562 ** This header file defines the interface that the SQLite library
564 ** or constant definition does not appear in this file, then it is
568 ** Some of the definitions that are in this file are marked as
575 ** from comments in this file. This file is the authoritative source
578 ** The name of this file under configuration management is "sqlite.h.in".
579 ** The makefile makes some minor changes to this file (such as inserting
624 ** Ensure these symbols were not defined by some previous header file.
670 ** but are associated with the library instead of the header file. ^(Cautious
937 #define SQLITE_BUSY 5 /* The database file is locked */
946 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
958 #define SQLITE_NOTADB 26 /* File opened that is not a database file */
1017 ** CAPI3REF: Flags For File Open Operations
1051 ** device that holds the file that the [sqlite3_io_methods]
1059 ** that when data is appended to a file, the data is appended
1060 ** first then the size of the file is extended, never the other
1065 ** file that were written at the application level might have changed
1084 ** CAPI3REF: File Locking Levels
1127 ** CAPI3REF: OS Interface Open File Handle
1129 ** An [sqlite3_file] object represents an open file in the
1135 ** I/O operations on the open file.
1139 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
1143 ** CAPI3REF: OS Interface File Virtual Methods Object
1145 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
1149 ** against the open file represented by the [sqlite3_file] object.
1161 ** flag may be ORed in to indicate that only the data of the file
1175 ** PENDING, or EXCLUSIVE lock on the file. It returns true
1179 ** VFS implementations to directly control an open file using the
1185 ** locking strategy (for example to use dot-file locks), to inquire
1191 ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
1195 file. The sector size is the
1197 ** other bytes in the file. The xDeviceCharacteristics()
1220 ** that when data is appended to a file, the data is appended
1221 ** first then the size of the file is extended, never the other
1257 ** CAPI3REF: Standard File Control Opcodes
1273 ** layer a hint of how large the database file will grow to be during the
1276 ** file space based on this hint in order to help writes to the database
1277 ** file run faster.
1281 ** extends and truncates the database file in chunks of a size specified
1284 ** for the nominated database. Allocating database file space in large
1285 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
1309 ** anti-virus programs. By default, the windows VFS will retry file read,
1310 ** file write, and file delete operations up to 10 times, with a delay
1329 ** have write permission on the directory containing the database file want
1330 ** to read the database file, as the WAL and shared memory files must exist
1350 ** reason, the entire database file will be overwritten by the current
1360 ** all file-control actions, there is no guarantee that this will actually
1362 ** pointer in case this file-control is not implemented. This file-control
1367 ** file control is sent to the open [sqlite3_file] object corresponding
1368 ** to the database file to which the pragma statement refers. ^The argument
1369 ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
1373 ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
1377 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
1379 ** file control returns [SQLITE_OK], then the parser assumes that the
1381 ** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns
1385 ** file control occurs at the beginning of pragma statement analysis and so
1421 ** in the name of the object stands for "virtual file system". See
1464 ** must invent its own temporary name for the file. ^Whenever the
1472 ** If xOpen() opens a file read-only then it sets *pOutFlags to
1489 ** The file I/O implementation can use the object type flags to
1492 ** the open of a journal file a no-op. Writes to this journal would
1495 ** file will be doing page-aligned sector reads and writes in a random
1505 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1514 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
1516 ** It is <i>not</i> used to indicate the file should be opened
1531 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1532 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1533 ** to test whether a file is at least readable. The file can be a
1578 int mxPathname; /* Maximum file pathname length */
1580 const char *zName; /* Name of this virtual file system */
1621 ** simply checks whether the file exists.
1630 ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
2441 ** already hold a RESERVED lock on the database file, but it needs
2443 ** pages into the database file without harm to concurrent
3007 ** ^These routines open an SQLite database file as specified by the
3043 ** only if the file is write protected by the operating system. In either
3089 ** begins with "file:", then the filename is interpreted as a URI. ^URI
3105 ** ^SQLite uses the path component of the URI as the name of the disk file
3121 ** be used to access the database file on disk. ^If this option is set to
3159 ** <tr><td> file:data.db <td>
3160 ** Open the file "data.db" in the current directory.
3161 ** <tr><td> file:/home/fred/data.db<br>
3162 ** file:///home/fred/data.db <br>
3163 ** file://localhost/home/fred/data.db <br> <td>
3164 ** Open the database file "/home/fred/data.db".
3165 ** <tr><td> file://darkstar/home/fred/data.db <td>
3168 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3169 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3173 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3174 ** Open file "data.db" in the current directory for read-only access.
3177 ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
3178 ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
3179 ** <tr><td> file:data.db?mode=readonly <td>
3217 ** to see if a database file was a URI that contained a specific query
3248 ** is not a database file pathname pointer that SQLite passed into the xOpen
3550 ** the content of the database file.
3556 ** change the database file through side-effects:
3562 ** But because the [SELECT] statement does not change the database file
4978 ** temporary file directory.
5040 ** associated with database N of connection D. ^The main database file
5376 ** ^This interface loads an SQLite extension library from the named file.
5379 ** SQLite extension library contained in the file zFile.
5785 ** ^For the main database file, the database name is "main".
5961 ** CAPI3REF: Virtual File System Objects
6267 ** main database file.
6280 ** open database file, then SQLITE_ERROR is returned. ^This error
6672 ** determine exactly which parts of a database file are cached and for
6712 ** SQLite will typically create one cache instance for each open database file,
6723 ** created will be used to cache database pages of a file stored on disk, or
6839 ** retained in the header file for backwards compatibility only.
6878 ** ^SQLite holds a write transaction open on the destination database file
6949 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
6967 ** on the destination file. ^The exclusive lock is not released until either
7010 ** up and the total number of pages in the source database file.
7017 ** pages that need to be updated or the size of the source database file
7040 ** that the application must guarantee that the disk file being
7234 ** is the number of pages currently in the write-ahead log file,
7265 ** more frames in the [write-ahead log] file. ^Passing zero or
7313 ** readers or writers to finish. Sync the db file if all frames in the log
7320 ** snapshot. It then checkpoints all frames in the log file and syncs the
7321 ** database file. This call blocks database writers while it is running,
7326 ** checkpointing the log file it blocks (calls the busy-handler callback)
7327 ** until all readers are reading from the database file only. This ensures
7328 ** that the next client to write to the database file restarts the log file
7334 ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
7341 ** All calls obtain an exclusive "checkpoint" lock on the database file. If
7347 ** "writer" lock on the database file. If the writer lock cannot be obtained
7554 /************** Begin file hash.h ********************************************/
7566 ** This is the header file for the generic hash-table implemenation
7655 /************** Begin file parse.h *******************************************/
7854 ** The "file format" number is an integer that is incremented whenever
7855 ** the VDBE-level file format changes. The following macros define the
7856 ** the default file format for new databases and the maximum file format
8174 /************** Begin file btree.h *******************************************/
8186 ** This header file defines the interface that the sqlite B-Tree file
8220 const char *zFilename, /* Name of database file to open */
8235 #define BTREE_SINGLE 4 /* The file contains at most 1 b-tree */
8300 ** the database file header. The incr-vacuum-flag field is located at
8419 /************** Begin file vdbe.h ********************************************/
8431 ** Header file for the Virtual DataBase Engine (VDBE)
8443 ** in the source file sqliteVdbe.c are allowed to see the insides
8580 ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
8581 ** header file that defines a number for each opcode used by the VDBE.
8584 /************** Begin file opcodes.h *****************************************/
8806 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*);
8848 /************** Begin file pager.h *******************************************/
8860 ** This header file defines the interface that the sqlite page cache
8861 ** subsystem. The page cache subsystem reads and writes a file a page
8878 ** The type used to represent a page number. The first page in a file
8884 ** Each open file is managed by a separate instance of the "Pager" structure.
8896 ** used in the journal to signify that the remainder of the journal file
8922 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
8926 #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
8930 ** The remainder of this file contains the declarations of the functions
9012 /* Functions used to truncate the database file. */
9039 /************** Begin file pcache.h ******************************************/
9051 ** This header file defines the interface that the sqlite page cache
9204 /************** Begin file os.h **********************************************/
9217 ** This header file (together with is companion C source-code file
9221 ** This header file is #include-ed by sqliteInt.h and thus ends up
9222 ** being included by every source file.
9343 ** alphanumeric characters, and no file extension. They are stored in the
9344 ** OS's standard temporary file directory, and are deleted prior to exit.
9360 ** of the file.
9371 ** RESERVED: A single process may hold a RESERVED lock on a file at
9373 ** PENDING: A single process may hold a PENDING lock on a file at
9390 ** File Locking Notes: (Mostly about windows but also some info for Unix)
9399 ** random so two separate readers can probably access the file at the
9403 ** a single byte of the file that is designated as the reserved lock byte.
9422 ** clients on win95, winNT, and unix all talking to the same shared file
9424 ** tool is being used for file sharing) implements locks correctly between
9438 ** file format. Depending on how it is changed, you might not notice
9500 ** sqlite3_malloc() to obtain space for the file-handle structure.
9510 /************** Begin file mutex.h *******************************************/
9523 ** This file contains the common header for all mutex implementations.
9524 ** The sqliteInt.h header #includes this file so that it is available
9528 ** NOTE: source files should *not* #include this header file directly.
9529 ** Source files should #include the sqliteInt.h file and let that file
9591 ** Each database file to be accessed by the system is an instance
9593 ** in the sqlite.aDb[] array. aDb[0] is the main database file and
9594 ** aDb[1] is the database file used to hold temporary tables. Additional
9599 Btree *pBt; /* The B*Tree structure for this database file */
9623 int schema_cookie; /* Database schema version number for this file */
9630 u8 file_format; /* Schema format version for this file */
9657 #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
9726 u8 temp_store; /* 1: file 2: memory 0: default */
9740 u8 iDb; /* Which db file is being initialized */
10164 ** database file. If Table.iDb is the index of the database table backend
10165 ** in sqlite.aDb[]. 0 is for the main database and 1 is for the file that
10167 ** then the table is stored in a file that is automatically deleted
10382 int tnum; /* Page containing root of this index in database file */
10396 ** analyze.c source file for additional information.
11828 ** file. Code should use the MACRO forms below, as the Varint32 versions
12124 SQLITE_PRIVATE void sqlite3ParserTrace(FILE*, char *);
12187 /************** Begin file global.c ******************************************/
12200 ** This file contains definitions of global variables and contants.
12383 ** for use by the VFS layers as space for managing file locks.
12386 ** a different position in the file. This allows code that has to
12392 ** 0x40000000 results in an incompatible database file format!
12404 ** the vdbe.c file.
12409 file ctime.c *******************************************/
12422 ** This file implements routines used to report what compile-time options
12810 /************** Begin file status.c ******************************************/
12827 /************** Begin file vdbeInt.h *****************************************/
12839 ** This is the header file for information that is private to the
12841 ** source code file "vdbe.c". When that file became too big (over
12867 ** A cursor is a pointer into a single BTree within a database file.
12878 Btree *pBt; /* Separate file holding temporary table */
13075 ** But this file is the only place where the internal details of this
13148 u8 minWriteFileFormat; /* Minimum file format for writable database files */
13166 FILE *trace; /* Write an execution trace here, if not NULL */
13196 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
13539 /************** Begin file date.c ********************************************/
13551 ** This file contains the C functions that implement date and time
13554 ** There is only one exported symbol in this file - the function
13555 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
13556 ** All other code has file scope.
14639 ** functions. This should be the only routine in this file with
14669 /************** Begin file os.c **********************************************/
14682 ** This file contains OS interface code that is common to all
14802 sqlite3_file *id, /* Database file handle */
14805 int bExtend, /* True to extend file if necessary */
15027 /************** Begin file fault.c *******************************************/
15040 ** This file contains code to support the concept of "benign"
15116 /************** Begin file mem0.c ********************************************/
15129 ** This file contains a no-op memory allocation drivers for use when
15155 ** This routine is the only routine in this file with external linkage.
15158 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
15177 /************** Begin file mem1.c ********************************************/
15190 ** This file contains low-level memory allocation drivers for when
15194 ** This file contains implementations of the low-level memory allocation
15196 ** this file is only used if SQLITE_SYSTEM_MALLOC is defined. The
15200 ** file.
15436 ** This routine is the only routine in this file with external linkage.
15439 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
15458 /************** Begin file mem2.c ********************************************/
15471 ** This file contains low-level memory allocation drivers for when
15477 ** This file contains implementations of the low-level memory allocation
15819 ** sqlite3GlobalConfig.m with pointers to the routines in this file.
15930 ** Open the file indicated and write a log of all unfreed memory
15934 FILE *out;
15988 /************** Begin file mem3.c ********************************************/
16000 ** This file contains the C functions that implement a memory
16573 ** Open the file indicated and write a log of all unfreed memory
16578 FILE *out;
16650 ** This routine is the only routine in this file with external
16654 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
16677 /************** Begin file mem5.c ********************************************/
16689 ** This file contains the C functions that implement a memory
17197 ** Open the file indicated and write a log of all unfreed memory
17201 FILE *out;
17239 ** This routine is the only routine in this file with external
17260 /************** Begin file mutex.c *******************************************/
17272 ** This file contains the C functions that implement mutexes.
17274 ** This file contains code that is common across all mutex implementations.
17415 /************** Begin file mutex_noop.c **************************************/
17427 ** This file contains the C functions that implement mutexes.
17429 ** This implementation in this file does not provide any mutual
17623 /************** Begin file mutex_os2.c ***************************************/
17635 ** This file contains the C functions that implement mutexes for OS/2
17639 ** The code in this file is only used if SQLITE_MUTEX_OS2 is defined.
17640 ** See the mutex.h file for details.
17899 /************** Begin file mutex_unix.c **************************************/
17911 ** This file contains the C functions that implement mutexes for pthreads
17915 ** The code in this file is only used if we are compiling threadsafe
18252 /************** Begin file mutex_w32.c ***************************************/
18264 ** This file contains the C functions that implement mutexes for win32
18268 ** The code in this file is only used if we are compiling multithreaded
18586 /************** Begin file malloc.c ******************************************/
19290 ** called via macros that record the current file and line number in the
19366 /************** Begin file printf.c ******************************************/
19376 ** This file contains code for a set of "printf"-like routines. These
20338 /************** Begin file random.c ******************************************/
20350 ** This file contains code to implement a pseudo-random number
20406 ** Nothing in this file or anywhere else in SQLite does any kind of
20485 /************** Begin file utf.c *********************************************/
20497 ** This file contains routines used to translate between UTF-8,
21046 /************** Begin file util.c ********************************************/
21060 ** This file contains functions for allocating memory, comparing
21992 ** file. In that case we are not in any hurry. Use the (relatively
22233 /************** Begin file hash.c ********************************************/
22512 /************** Begin file opcodes.c *****************************************/
22674 /************** Begin file os_os2.c ******************************************/
22687 ** This file contains code that is specific to OS/2.
22714 ** OS layer for an embedded system, if you use this file as an example,
22730 /************** Begin file
22743 ** This file contains macros and a little bit of code that is common to
22747 ** This file should be #included by the os_*.c files only. It is not a
22748 ** general purpose header file.
22783 /************** Begin file hwtime.h ******************************************/
22796 ** This file contains inline asm code for retrieving "high-performance"
22940 typedef struct os2File os2File; /* The file structure */
22950 HFILE h; /* Handle for accessing the file */
22952 int locktype; /* Type of lock currently held on this file */
22954 char *zFullPathCp; /* Full path name of this file */
22955 os2ShmLink *pShmLink; /* Instance of shared memory on this file */
22974 ** Close a file.
22999 ** Read data from a file into a buffer. Return SQLITE_OK if all
23004 sqlite3_file *id, /* File to read from */
23031 ** Write data from a buffer into a file. Return SQLITE_OK on success
23035 sqlite3_file *id, /* File to write into */
23038 sqlite3_int64 offset /* Offset into the file to begin writing at */
23064 ** Truncate an open file to a specified size
23073 /* If the user has configured a chunk-size for this file, truncate the
23074 ** file so that it consists of an integer number of chunks (i.e. the
23075 ** actual file size after the operation may be larger than the requested
23096 ** Make sure all writes to a particular file are committed to disk.
23119 ** Determine the current size of a file in bytes
23168 OSTRACE(( "UNLOCK-READLOCK file handle=%d res=%d?\n", id->h, res ));
23173 ** Lock the file with the lock specified by parameter locktype - one
23315 /* Update the state of the lock has held in the file descriptor then
23332 ** file by this or any other process. If such a lock is held, return
23371 ** Lower the locking level on file descriptor id to locktype. locktype
23374 ** If the locking level of the file descriptor is already at or below
23435 ** Control and query of the open file handle.
23465 ** the specified file. This is almost always 512 bytes, but may be
23469 ** if two files are created in the same file-system directory (i.e.
23470 ** a database and its journal file) that the sector size will be the
23574 ** Use main database file for interprocess locking. If un-defined
23575 ** a separate file is created for this purpose. The file will be
23576 ** used only to set file locks. There will be no data written to it.
23623 ** Object used to represent a the shared memory area for a single log file.
23657 HFILE hLockFile; /* File used for inter-process memory locking */
23776 /* Replace colon in file name to form a valid shared memory name */
23930 ** shared-memory associated with the database file id. Shared-memory regions
23948 sqlite3_file *id, /* Handle open on database file */
24040 sqlite3_file *id, /* The underlying database file */
24088 sqlite3_file *id, /* Database file holding the shared memory */
24206 sqlite3_file *id /* Database file holding the shared memory */
24253 ** Create a temporary file name in zBuf. zBuf must be big enough to
24338 ** Open a file.
24342 const char *zName, /* Name of the file (UTF-8) */
24343 sqlite3_file *id, /* Write the SQLite file handle here */
24386 /* The main DB, main journal, WAL file and master journal are never
24393 /* Assert that the upper layer has set one of the "file-type" flags. */
24404 ** temporary file name to use
24422 ** sharing because file locks will provide exclusive access when needed.
24429 /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
24434 /* Creates a new file, only if it does not already exist. */
24435 /* If the file exists, it fails. */
24438 /* Open existing file, or create if it doesn't exist */
24441 /* Opens a file, only if it exists. */
24485 ** Delete the named file.
24489 const char *zFilename, /* Name of file to delete */
24505 ** Check the existance and status of a file.
24509 const char *zFilename, /* Name of file to check */
24510 int flags, /* Type of test to make on this file */
24529 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
24808 /************** Begin file os_unix.c *****************************************/
24821 ** This file contains the VFS implementation for unix-like operating systems
24824 ** There are actually several different VFS implementations in this file.
24825 ** The differences are in the way that file locking is done. The default
24830 ** This source file is organized into divisions where the logic for various
24832 ** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed
24838 ** * Unique file ID logic used by VxWorks.
24842 ** + for dot-file locks
24854 #if SQLITE_OS_UNIX /* This file is used on unix only */
24857 ** There are various methods for file locking used for concurrency
24862 ** 3. Dot-file locking,
24894 ** These #defines should enable >2GB file support on Posix if the
24896 ** large file support, these should be no-ops.
24898 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
24940 # include <sys/file.h>
24968 ** Default permissions when creating a new file
24996 typedef struct UnixUnusedFd UnixUnusedFd; /* An unused file descriptor */
24999 ** Sometimes, after a file handle is closed by SQLite, the file descriptor
25001 ** structure are used to store the file descriptor while waiting for an
25005 int fd; /* File descriptor to close */
25006 int flags; /* Flags this file descriptor was opened with */
25007 UnixUnusedFd *pNext; /* Next unused file descriptor on same file */
25019 int h; /* The file descriptor */
25025 const char *zPath; /* Name of the file */
25035 struct vxworksFileId *pId; /* Unique file ID */
25041 ** occur if a file is updated without also updating the transaction
25046 unsigned char dbUpdate; /* True if any part of database file changed */
25071 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
25072 #define UNIXFILE_CHOWN 0x100 /* File ownership was changed */
25078 /************** Begin file os_common.h ***************************************/
25091 ** This file contains macros and a little bit of code that is common to
25095 ** This file should be #included by the os_*.c files only. It is not a
25096 ** general purpose header file.
25131 /************** Begin file hwtime.h ******************************************/
25144 ** This file contains inline asm code for retrieving "high-performance"
25532 ** If the file creation mode "m" is 0 then set it to the default for
25535 ** make the file creation mode be exactly m ignoring the umask.
25540 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
25565 ** vxworksFileId objects used by this file, all of which may be
25680 ** and a variety of "please close the file descriptor NOW" errors into
25683 ** Errors during initialization of locks, or file system support for locks,
25709 /* random NFS retry error, unless during file system support
25737 /* something went terribly awry, unless during file system support
25742 /* invalid fd, unless during file system support introspection, in which
25756 /* these should force the client to close the file and reconnect */
25766 ****************** Begin Unique File ID Utility Used By VxWorks ***************
25768 ** On most versions of unix, we can get a unique ID for a file by concatenating
25770 ** On VxWorks, a unique file id must be based on the canonical filename.
25773 ** unique file ID in VxWorks. Each instance of this structure contains
25833 ** Find a unique file ID for the given absolute pathname. Return
25835 ** file ID.
25844 struct vxworksFileId *pNew; /* search key and new file ID */
25845 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
25858 ** the existing file ID.
25872 /* No match was found. We will make a new file ID */
25899 /*************** End of Unique File ID Utility Used By VxWorks ****************
25911 ** file descriptor. Consider this test case:
25916 ** Suppose ./file1 and ./file2 are really the same file (because
25920 ** fail since there was already a lock on the file due to fd1.
25923 ** file descriptors opened on different file names.
25925 ** This means that we cannot use POSIX locks to synchronize file access
25930 ** To work around the problem, SQLite has to manage file locks internally
25932 ** specific inode of the database file (the inode is determined by the
25943 ** The sqlite3_file structure for POSIX is no longer just an integer file
25944 ** descriptor. It is now a structure that holds the integer file
25951 ** file is unlocked. cnt==-1 means the file has an exclusive lock.
25952 ** cnt>0 means there are cnt shared locks on the file.
25954 ** Any attempt to lock or unlock a file first checks the locking
25961 ** If you close a file descriptor that points to a file that has locks,
25962 ** all locks on that file that are owned by the current process are
25967 ** to close() the file descriptor is deferred until all of the locks clear.
25968 ** The unixInodeInfo structure keeps a list of file descriptors that need to
25989 ** per database file in the same process and (2) database connections
26000 struct vxworksFileId *pId; /* Unique file ID for vxworks. */
26011 ** A single inode can have multiple file descriptors, so each unixFile
26022 int nLock; /* Number of outstanding file locks */
26023 UnixUnusedFd *pUnused; /* Unused file descriptors to close */
26053 ** failed (e.g. "unlink", "open") and the the associated file-system path,
26060 const char *zPath, /* File path associated with error */
26111 ** Close a file descriptor.
26115 ** If it does fail, simply leak the file descriptor, but do log the
26119 ** file descriptor might have already been reused by another thread.
26131 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
26176 ** Given a file descriptor, locate the unixInodeInfo object that
26177 ** describes that file descriptor. Create a new one if necessary. The
26186 unixFile *pFile, /* Unix file with file desc used in the key */
26190 int fd; /* The file descriptor for pFile */
26192 struct stat statbuf; /* Low-level file information */
26197 /* Get low-level information about the file that we can used to
26198 ** create a unique name for the file.
26214 ** we always increase the file size to 1 by writing a single byte
26268 ** file by this or any other process. If such a lock is held, set *pResOut
26313 ** Attempt to set a system-lock on the file pFile. The lock is
26360 ** Lock the file with the lock specified by parameter eFileLock - one
26389 ** accessing the same database file, in case that is ever required.
26408 ** This property is used by the algorithm for rolling back a journal file
26547 ** assumed that there is a SHARED or greater lock on the file
26605 ** Add the file descriptor used by file handle pFile to the corresponding
26618 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
26621 ** If the locking level of the file descriptor is already at or below
26653 ** reading the database file again, make sure that the
26655 ** file changed. If the transaction counter is not updated,
26656 ** other connections to the same file might not realize that
26657 ** the file has changed and hence might not know to flush their
26771 /* Decrement the count of locks against this same file. When the
26772 ** count reaches zero, close any other file descriptors whose close
26789 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
26792 ** If the locking level of the file descriptor is already at or below
26800 ** This function performs the parts of the "close file" operation
26801 ** common to all locking schemes. It closes the directory and file
26832 ** Close a file.
26845 /* If there are outstanding locks, do not actually close the file just
26846 ** yet because that would clear those locks. Instead, add the file
26866 ** file for reading or writing.
26874 ** database connections are accessing the same database file at the same
26893 ** Close the file.
26903 ************************* Begin dot-file Locking ******************************
26925 ** The file suffix added to the data base filename in order to create the
26932 ** file by this or any other process. If such a lock is held, set *pResOut
26938 ** is held on the file and false if the file is unlocked.
26952 ** holds a lock on the file. No need to check further. */
26965 ** Lock the file with the lock specified by parameter eFileLock - one
26997 /* If we have any lock, then the lock file already exists. All we have
27002 /* Always update the timestamp on the old file */
27033 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27036 ** If the locking level of the file descriptor is already at or below
27039 ** When the locking level reaches NO_LOCK, delete the lock file.
27057 ** lock state. No need to mess with the file on disk.
27064 /* To fully unlock the database, delete the lock file */
27084 ** Close a file. Make sure the lock has been released before closing.
27096 /****************** End of the dot-file lock implementation *******************
27102 ** Use the flock() system call to do file locking.
27104 ** flock() locking is like dot-file locking in that the various
27132 ** file by this or any other process. If such a lock is held, set *pResOut
27190 ** Lock the file with the lock specified by parameter eFileLock - one
27213 ** access the file.
27256 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27259 ** If the locking level of the file descriptor is already at or below
27294 ** Close a file.
27315 ** the database file at a time. This reduces potential concurrency, but
27322 ** file by this or any other process. If such a lock is held, set *pResOut
27366 ** Lock the file with the lock specified by parameter eFileLock - one
27389 ** access the file.
27422 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27425 ** If the locking level of the file descriptor is already at or below
27463 ** Close a file.
27503 const char *dbPath; /* Name of the open file */
27513 int fd; /* file desc to assoc this lock with */
27525 const char *path, /* Name of the file to be locked or unlocked */
27526 unixFile *pFile, /* Open file descriptor on path */
27566 ** file by this or any other process. If such a lock is held, set *pResOut
27617 ** Lock the file with the lock specified by parameter eFileLock - one
27758 ** assumed that there is a SHARED or greater lock on the file
27816 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27819 ** If the locking level of the file descriptor is already at or below
27852 ** reading the database file again, make sure that the
27854 ** file changed. If the transaction counter is not updated,
27855 ** other connections to the same file might not realize that
27856 ** the file has changed and hence might not know to flush their
27923 ** Close a file & cleanup AFP specific locking context
27932 /* If there are outstanding locks, do not actually close the file just
27933 ** yet because that would clear those locks. Instead, add the file
27962 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27965 ** If the locking level of the file descriptor is already at or below
28051 ** Read data from a file into a buffer. Return SQLITE_OK if all
28065 /* If this is a database file (not a journal, master-journal or temp
28066 ** file), the bytes in the locking range should never be read or written. */
28131 ** Write data from a buffer into a file. Return SQLITE_OK on success
28145 /* If this is a database file (not a journal, master-journal or temp
28146 ** file), the bytes in the locking range should never be read or written. */
28155 /* If we are doing a normal write to a database file (as opposed to
28156 ** doing a hot-journal rollback or a write to some file other than a
28157 ** normal database file) then record the fact that the database
28237 ** or power failure will likely corrupt the database file.
28239 ** SQLite sets the dataOnly flag if the size of the file is unchanged.
28240 ** The idea behind dataOnly is that it should only write the file content
28241 ** to disk, not the inode. We only set dataOnly if the file size is
28242 ** unchanged since the file size is part of the inode. However,
28244 ** file size has changed. The only real difference between fdatasync()
28247 ** We only care about the file size, not the other file attributes, so
28292 ** file system (on OSX), so failure indicates that FULLFSYNC
28293 ** isn't supported for this file system. So, attempt an fsync
28301 /* fdatasync() on HFS+ doesn't yet flush the file size if it changed correctly
28321 ** Open a file descriptor to the directory containing file zFilename.
28322 ** If successful, *pFd is set to the opened file descriptor and
28327 ** The directory file descriptor is used for only one thing - to
28328 ** fsync() a directory to make sure file creation and deletion events
28341 ** the file descriptor *pFd using close().
28365 ** Make sure all writes to a particular file are committed to disk.
28367 ** If dataOnly==0 then both the file itself and its metadata (file
28369 ** file data is synced.
28371 ** Under Unix, also make sure that the directory entry for the file
28372 ** has been created by fsync-ing the directory that contains the file.
28375 ** SQLite to access the file will not know that the journal exists (because
28405 /* Also fsync the directory containing the file if the DIRSYNC flag
28426 ** Truncate an open file to a specified size
28434 /* If the user has configured a chunk-size for this file, truncate the
28435 ** file so that it consists of an integer number of chunks (i.e. the
28436 ** actual file size after the operation may be larger than the requested
28449 /* If we are doing a normal write to a database file (as opposed to
28450 ** doing a hot-journal rollback or a write to some file other than a
28451 ** normal database file) and we truncate the file to zero length,
28466 ** Determine the current size of a file in bytes
28481 ** writes a single byte into that file in order to work around a bug
28483 ** layers, we need to report this file size as zero even though it is
28494 ** Handler for proxy-locking file-control verbs. Defined below in the
28502 ** file-control operation. Enlarge the database to nBytes in size
28508 i64 nSize; /* Required file size */
28527 ** ftruncate() to set the file size, then write a single byte to
28532 int nBlk = buf.st_blksize; /* File-system block size */
28569 ** Information and control of an open file handle.
28628 ** the specified file. This is almost always 512 bytes, but may be
28632 ** if two files are created in the same file-system directory (i.e.
28633 ** a database and its journal file) that the sector size will be the
28642 ** Return the device characteristics for the file.
28646 ** file system does not always provide powersafe overwrites. (In other
28647 ** words, after a power-loss event, parts of the file that were never
28651 ** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control
28676 ** every open file that does not use shared memory (in other words, most
28698 char *zFilename; /* Name of the mmapped file */
28699 int h; /* Open file descriptor */
28847 ** Open a shared-memory area associated with open database file pDbFd.
28850 ** The file used to implement shared-memory is in the same directory
28851 ** as the open database file and has the same name as the open database
28852 ** file with the "-shm" suffix added. For example, if the database file
28853 ** is "/home/user1/config.db" then the file that is created and mmapped
28857 ** some other tmpfs mount. But if a file in a different directory
28858 ** from the database file is used, then differing access permissions
28862 ** in database corruption. Nevertheless, this tmpfs file usage
28867 ** same database file at the same time, database corruption will likely
28871 ** When opening a new shared-memory file, if no other instances of that
28872 ** file are currently open, in this process or in other processes, then
28873 ** the file must be truncated to zero length or have its header cleared.
28875 ** If the original database file (pDbFd) is using the "unix-excl" VFS
28876 ** that means that an exclusive lock is held on the database file and
28879 ** file is created. The shared memory will be simulated with heap memory.
28883 struct unixShmNode *pShmNode; /* The underlying mmapped file */
28886 char *zShmFilename; /* Name of the file used for SHM */
28902 struct stat sStat; /* fstat() info for database file */
28904 /* Call fstat() to figure out the permissions on the database file. If
28905 ** a new *-shm file is created, an attempt will be made to create it
28954 /* If this process is running as root, make sure that the SHM file
28966 ** If not, truncate the file to zero length.
29013 ** shared-memory associated with the database file fd. Shared-memory regions
29031 sqlite3_file *fd, /* Handle open on database file */
29034 int bExtend, /* True to extend file if necessary */
29042 /* If the shared-memory file has not yet been opened, open it now. */
29058 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
29065 ** Check to see if it has been allocated (i.e. if the wal-index file is
29142 sqlite3_file *fd, /* Database file holding the shared memory */
29150 unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
29254 sqlite3_file *fd /* Database file holding the shared memory */
29269 sqlite3_file *fd, /* The underlying database file */
29273 unixShmNode *pShmNode; /* The underlying shared-memory file */
29275 unixFile *pDbFd; /* The underlying database file */
29297 ** shared-memory file, too */
29326 ** implement various file locking strategies. It also contains definitions
29328 ** sqlite3_io_methods object for a particular database file. The pAppData
29456 ** opens secondary file descriptors for the conch and lock files and
29457 ** it uses proxy, dot-file, AFP, and flock() locking methods on those
29459 ** proxy locking is located much further down in the file. But we need
29495 ** for the database file "filePath". It then returns the sqlite3_io_methods
29501 const char *filePath, /* name of the database file */
29502 unixFile *pNew /* open file object for the database file */
29520 /* If filePath==NULL that means we are dealing with a transient file
29537 ** assume that the file-system supports POSIX style locks.
29561 ** for the database file "filePath". It then returns the sqlite3_io_methods
29567 const char *filePath, /* name of the database file */
29568 unixFile *pNew /* the open file object */
29573 /* If filePath==NULL that means we are dealing with a transient file
29614 int h, /* Open file descriptor of file being opened */
29616 const char *zFilename, /* Name of the file being opened */
29626 ** exception is when opening the proxy "conch" file in builds that
29667 ** zFilename remains valid until file is closed, to support */
29680 /* If an error occured in findInodeInfo(), close the file descriptor
29688 ** file descriptors open on the same file. If there were other file
29689 ** descriptors on this file, then no malloc would be required by
29706 /* AFP locking uses the file path so it needs to be included in
29714 /* NB: zFilename exists and remains valid until the file is closed
29733 /* Dotfile locking uses the file path so it needs to be included in
29751 /* Named semaphore locking uses the file path so it needs to be
29794 ** If no suitable temporary file directory can be found, return NULL.
29822 ** Create a temporary file name in zBuf. zBuf must be allocated
29843 /* Check that the output buffer is large enough for the temporary file
29873 ** Search for an unused file descriptor that was opened on the database
29874 ** file (not a journal or master-journal file) identified by pathname
29878 ** Such a file descriptor may exist if a database connection was closed
29879 ** but the associated file descriptor could not be closed because some
29880 ** other file descriptor open on the same file is holding a file-lock.
29882 ** describing "Posix Advisory Locking" at the start of this file for
29885 ** If a suitable file descriptor is found, then it is returned. If no
29886 ** such file descriptor is located, -1 is returned.
29891 /* Do not search for an unused file descriptor on vxworks. Not because
29902 ** ignored and -1 is returned. The caller will try to open a new file
29906 ** not searching for a resusable file descriptor are not dire. */
29938 ** an indication to robust_open() to create the file using
29940 ** But if the file being opened is a WAL or regular journal file, then
29941 ** this function queries the file-system for the permissions on the
29942 ** corresponding database file and sets *pMode to this value. Whenever
29944 ** as the associated database file.
29952 const char *zPath, /* Path of file (possibly) being created */
29954 mode_t *pMode, /* OUT: Permissions to open file with */
29955 uid_t *pUid, /* OUT: uid to set on the file */
29956 gid_t *pGid /* OUT: gid to set on the file */
29963 char zDb[MAX_PATHNAME+1]; /* Database file path */
29965 struct stat sStat; /* Output of stat() on database file */
29967 /* zPath is a path to a WAL or journal file. The following block derives
29968 ** the path to the associated database file from zPath. This block handles
30007 ** Open the file zPath.
30023 ** true, the file was configured to be automatically deleted when the
30024 ** file handle closed. To achieve the same effect using this new
30030 const char *zPath, /* Pathname of file to be opened */
30031 sqlite3_file *pFile, /* The file descriptor to be filled in */
30036 int fd = -1; /* File descriptor returned by open() */
30038 int eType = flags&0xFFFFFF00; /* Type of file to open */
30055 /* If creating a master or main-file journal, this function will open
30056 ** a file-descriptor on the directory too. The first time unixSync()
30057 ** is called the directory file descriptor will be fsync()ed and close()d.
30066 ** a temporary file. Use this buffer to store the file name in.
30083 /* The main DB, main journal, WAL file and master journal are never
30090 /* Assert that the upper layer has set one of the "file-type" flags. */
30118 /* If zName is NULL, the upper layer is requesting a temp file. */
30133 ** they may be stored as part of the file handle and used by the
30134 ** 'conch file' locking functions later on. */
30142 mode_t openMode; /* Permissions to create file with */
30143 uid_t uid; /* Userid for the file */
30144 gid_t gid; /* Groupid for the file */
30154 /* Failed to open the file for read/write access. Try read-only. */
30168 ** journal or WAL file, set the ownership of the journal or WAL to be
30240 /* In theory, the close(fd) call is sub-optimal. If the file opened
30241 ** with fd is a database file, and there are other connections open
30242 ** on that file that are currently holding advisory locks on it,
30245 ** not while other file descriptors opened by the same process on
30246 ** the same file are working. */
30283 ** Delete the file at zPath. If the dirSync argument is true, fsync()
30284 ** the directory after deleting the file.
30288 const char *zPath, /* Name of file to be deleted */
30289 int dirSync /* If true, fsync() directory after deleting file */
30320 ** Test the existance of or access permissions of file zPath. The
30323 ** SQLITE_ACCESS_EXISTS: Return 1 if the file exists
30324 ** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
30325 ** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
30331 const char *zPath, /* Path of the file to examine */
30332 int flags, /* What do we want to learn about the zPath file? */
30625 ** until late in the file (here) after all of the other I/O methods have
30632 ** database file to coordinate safe, concurrent access by multiple readers
30633 ** and writers [http://sqlite.org/lockingv3.html]. The five file locking
30646 ** This works well on the local file system, but shows a nearly 100x
30650 ** supported network file systems. NFS and AFP both observe the
30657 ** To address the performance and cache coherency issues, proxy file locking
30659 ** single host at a time and moving file locks off of the database file
30660 ** and onto a proxy file on the local file system.
30678 ** Specifying ":auto:" means that if there is a conch file with a matching
30679 ** host ID in it, the proxy path in the conch file will be used, otherwise
30682 ** actual proxy file name is generated from the name and path of the
30683 ** database file. For example:
30690 ** the above APIs (assuming the conch file is not being held by another
30697 ** Proxy file locking relies primarily on two new supporting files:
30699 ** * conch file to limit access to the database file to a single host
30702 ** * proxy file to act as a proxy for the advisory locks normally
30705 ** The conch file - to use a proxy file, sqlite must first "hold the conch"
30706 ** by taking an sqlite-style shared lock on the conch file, reading the
30708 ** proxy path against the values stored in the conch. The conch file is
30709 ** stored in the same directory as the database file and the file name
30710 ** is patterned after the database file name as ".<databasename>-conch".
30711 ** If the conch file does not exist, or it's contents do not match the
30713 ** lock and the conch file contents is updated with the host ID and proxy
30718 ** The proxy file - a single-byte file used for all advisory file locks
30719 ** normally taken on the database file. This allows for safe sharing
30720 ** of the database file for multiple readers and writers on the same
30721 ** host (the conch ensures that they all use the same local lock file).
30724 ** only taken when the first request to lock database file is made.
30726 ** opening a connection to a database file does not take a lock on it.
30727 ** The shared lock and an open file descriptor are maintained until
30730 ** The proxy file and the lock file are never deleted so they only need
30738 ** Database files accessed on non-local file systems are
30745 ** Enables the logging of error messages during host id file
30761 ** force proxy locking to be used for every database file opened, and 0
30773 ** The proxyLockingContext has the path and file structures for the remote
30778 unixFile *conchFile; /* Open conch file */
30779 char *conchFilePath; /* Name of the conch file */
30780 unixFile *lockProxy; /* Open proxy lock file */
30781 char *lockProxyPath; /* Name of the proxy lock file */
30782 char *dbPath; /* Name of the open file */
30789 ** The proxy lock file path for the database at dbPath is written into lPath,
30791 ** file path.
30832 ** Creates the lock file and any missing directories in lockPath
30868 ** Create a new VFS file descriptor (stored in memory obtained from
30869 ** sqlite3_malloc) and open the file named "path" in the file descriptor.
30871 ** The caller is responsible not only for closing the file descriptor
30872 ** but also for freeing the memory associated with the file descriptor.
30887 /* 1. first try to open/create the file
30888 ** 2. if that fails, and this is a lock file (not-conch), try creating
30890 ** 3. if that fails, try to open the file read-only
30891 ** otherwise return BUSY (if lock file) or CANTOPEN for the conch file
30957 /* simulate multiple hosts by creating unique hostid file paths */
30961 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
30988 /* simulate multiple hosts by creating unique hostid file paths */
30997 /* The conch file contains the header, host id and lock file path
31000 #define PROXY_HEADERLEN 1 /* conch file header length */
31005 ** Takes an open conch file, copies the contents to a new path and then moves
31006 ** it back. The newly created file's file descriptor is assigned to the
31007 ** conch file structure and finally the original conch file descriptor is
31036 /* write it out to the temporary break file */
31067 /* Take the requested lock on the conch file and break a stale lock if the
31143 ** lockPath is non-NULL, the host ID and lock file path must match. A NULL
31144 ** lockPath means that the lockPath in the conch file will be used if the
31146 ** and written to the conch file.
31179 /* read the existing conch file */
31189 ** conch file.
31197 do { /* in case we need to try again for an :auto: named lock file */
31204 /* for auto-named local lock file, just check the host ID and we'll
31205 ** use the local lock file path that's already in there
31273 /* If we created a new conch file (not just updated the contents of a
31274 ** valid conch file), try to match the permissions of the database
31282 /* try to match the database file R/W permissions, ignore failure */
31327 /* we couldn't create the proxy lock file with the old lock file path
31337 ** from the conch file or the path was allocated on the stack
31360 } while (1); /* in case we need to retry the :auto: lock file -
31366 ** If pFile holds a lock on a conch file, then release that lock.
31371 unixFile *conchFile; /* Name of the conch file */
31388 ** Given the name of a database file, compute the name of its conch file.
31404 ** the name of the original database file. */
31424 /* append the "-conch" suffix to the file */
31432 /* Takes a fully configured proxy locking-style unix file and switches
31433 ** the local lock file path
31465 ** pFile is a file that has been opened by a prior xOpen call. dbPath
31482 ** file path */
31486 /* all other styles use the locking context to store the db file path */
31494 ** Takes an already filled in unix file and alters it so all file locking
31495 ** will be performed on the local proxy lock file. The following fields
31503 char dbPath[MAXPATHLEN+1]; /* Name of the database file */
31531 ** (c) the file system is read-only, then enable no-locking access.
31631 /* turn on proxy file locking */
31654 ** file by this or any other process. If such a lock is held, set *pResOut
31674 ** Lock the file with the lock specified by parameter eFileLock - one
31715 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
31718 ** If the locking level of the file descriptor is already at or below
31738 ** Close a file that uses proxy locks.
31794 ** should be the only routines in this file that are visible from other
31820 ** database file and tries to choose an locking method appropriate for
31906 /************** Begin file os_win.c ******************************************/
31919 ** This file contains code that is specific to Windows.
31921 #if SQLITE_OS_WIN /* This file is used for Windows only */
31931 /************** Begin file os_common.h ***************************************/
31944 ** This file contains macros and a little bit of code that is common to
31948 ** This file should be #included by the os_*.c files only. It is not a
31949 ** general purpose header file.
31984 /************** Begin file hwtime.h ******************************************/
31997 ** This file contains inline asm code for retrieving "high-performance"
32152 ** WinCE lacks native support for file locking so we have to fake it
32171 sqlite3_vfs *pVfs; /* The VFS used to open this file */
32172 HANDLE h; /* Handle for accessing the file */
32173 u8 locktype; /* Type of lock currently held on this file */
32177 winShm *pShm; /* Instance of shared memory on this file */
32178 const char *zPath; /* Full pathname of this file */
32181 LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
32185 winceLock *shared; /* Global shared lock memory for the file */
32996 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
33074 ** current codepage settings for file apis.
33248 ** failed and the the associated file-system path, if any.
33255 const char *zPath, /* File path associated with error */
33376 ** Create the mutex and shared memory used for locking in the file
33412 /* Since the names of named mutexes, semaphores, file mappings etc are
33661 ** Move the current position of the file handle passed as the first
33662 ** argument to offset iOffset within the file. If successful, return 0.
33675 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
33695 ** Close a file.
33739 ** Read data from a file into a buffer. Return SQLITE_OK if all
33744 sqlite3_file *id, /* File to read from */
33749 winFile *pFile = (winFile*)id; /* file handle */
33750 DWORD nRead; /* Number of bytes actually read from file */
33778 ** Write data from a buffer into a file. Return SQLITE_OK on success
33782 sqlite3_file *id, /* File to write into */
33785 sqlite3_int64 offset /* Offset into the file to begin writing at */
33788 winFile *pFile = (winFile*)id; /* File handle */
33834 ** Truncate an open file to a specified size
33837 winFile *pFile = (winFile*)id; /* File handle object */
33845 /* If the user has configured a chunk-size for this file, truncate the
33846 ** file so that it consists of an integer number of chunks (i.e. the
33847 ** actual file size after the operation may be larger than the requested
33878 ** Make sure all writes to a particular file are committed to disk.
33939 ** Determine the current size of a file in bytes
34023 ** Lock the file with the lock specified by parameter locktype - one
34154 /* Update the state of the lock has held in the file descriptor then
34171 ** file by this or any other process. If such a lock is held, return
34197 ** Lower the locking level on file descriptor id to locktype. locktype
34200 ** If the locking level of the file descriptor is already at or below
34255 ** Control and query of the open file handle.
34320 ** the specified file. This is almost always 512 bytes, but may be
34324 ** if two files are created in the same file-system directory (i.e.
34325 ** a database and its journal file) that the sector size will be the
34345 ** Windows will only let you create file view mappings
34355 ** this file, all of which may be shared by multiple threads.
34378 ** Object used to represent a single file opened and mmapped to provide
34402 char *zFilename; /* Name of the file */
34403 winFile hFile; /* File handle from winOpen */
34408 HANDLE hMap; /* File handle from CreateFileMapping */
34559 ** Open the shared-memory area associated with database file pDbFd.
34561 ** When opening a new shared-memory file, if no other instances of that
34562 ** file are currently open, in this process or in other processes, then
34563 ** the file must be truncated to zero length or have its header cleared.
34567 struct winShmNode *pShmNode = 0; /* The underlying mmapped file */
34617 pShmNode->zFilename, /* Name of the file (UTF-8) */
34618 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
34626 ** If not, truncate the file to zero length.
34684 winShmNode *pShmNode; /* The underlying shared-memory file */
34704 ** shared-memory file, too */
34720 sqlite3_file *fd, /* Database file holding the shared memory */
34839 ** shared-memory associated with the database file fd. Shared-memory regions
34857 sqlite3_file *fd, /* Handle open on database file */
34860 int isWrite, /* True to extend file if necessary */
34880 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
34881 sqlite3_int64 sz; /* Current size of wal-index file */
34886 ** Check to see if it has been allocated (i.e. if the wal-index file is
34923 HANDLE hMap; /* file-mapping handle */
35035 ** Create a temporary file name in zBuf. zBuf must be big enough to
35084 /* Check that the output buffer is large enough for the temporary file
35109 ** Open a file.
35113 const char *zName, /* Name of the file (UTF-8) */
35114 sqlite3_file *id, /* Write the SQLite file handle here */
35133 ** a temporary file. Use this buffer to store the file name in.
35139 int eType = flags&0xFFFFFF00; /* Type of file to open */
35170 /* The main DB, main journal, WAL file and master journal are never
35177 /* Assert that the upper layer has set one of the "file-type" flags. */
35190 ** temporary file name to use
35220 /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
35225 /* Creates a new file, only if it does not already exist. */
35226 /* If the file exists, it fails. */
35229 /* Open existing file, or create if it doesn't exist */
35232 /* Opens a file, only if it exists. */
35338 ** Delete the named file.
35340 ** Note that Windows does not allow a file to be deleted if some other
35342 ** will open a journal file shortly after it is created in order to do
35344 ** file open, we will be unable to delete it. To work around this
35351 const char *zFilename, /* Name of file to delete */
35395 ** Check the existance and status of a file.
35399 const char *zFilename, /* Name of file to check */
35400 int flags, /* Type of test to make on this file */
35422 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
35813 /************** Begin file bitvec.c ******************************************/
35825 ** This file implements an object that represents a fixed-length
35828 ** A bitmap is used to record which pages of a database file have been
35846 ** Bitvec object is the number of pages in the database file at the
36223 /************** Begin file pcache.c ******************************************/
36235 ** This file implements that page cache.
36844 /************** Begin file pcache1.c *****************************************/
36857 ** This file implements the default page cache implementation (the
36902 ** open database file (including each in-memory database and each
36984 ** All code in this file should access the global structure above via the
37029 ** Malloc function used within this file to allocate space from the buffer
37864 /************** Begin file rowset.c ******************************************/
38288 /************** Begin file pager.c *******************************************/
38302 ** The pager is used to access a database disk file. It implements
38303 ** atomic commit and rollback through the use of a journal file that
38304 ** is separate from the database file. The pager also implements file
38306 ** file simultaneously, or one process from reading the database while
38311 /************** Begin file wal.h *********************************************/
38323 ** This header file defines the interface to the write-ahead logging
38361 /* Connection to a write-ahead log (WAL) file.
38370 /* Set the limiting size of a WAL file. */
38407 /* Copy pages from the log to the database file */
38413 int sync_flags, /* Flags to sync db file with (or 0) */
38428 ** by the pager layer on the database file.
38439 /* If the WAL file is not empty, return the number of bytes of content
38461 ** is called successfully on the file containing the page.
38463 ** Definition: A page of the database file is said to be "overwriteable" if
38473 ** the database file at the start of the transaction.
38475 ** (1) A page of the database file is never overwritten unless one of the
38489 ** (3) Writes to the database file are an integer multiple of the page size
38492 ** (4) Reads from the database file are either aligned on a page boundary and
38494 ** first 100 bytes of the database file.
38496 ** (5) All writes to the database file are synced prior to the rollback journal
38499 ** (6) If a master journal file is used, then all writes to the database file
38510 ** journal is rolled back, the resulting database file will be logical
38511 ** equivalent to the database file at the beginning of the transaction.
38514 ** is called to restore the database file to the same size it was at
38519 ** (9) Whenever the database file is modified, at least one bit in the range
38527 ** (11) A database file is well-formed at the beginning and at the conclusion
38530 ** (12) An EXCLUSIVE lock is held on the database file when writing to
38531 ** the database file.
38533 ** (13) A SHARED lock is held on the database file while reading any
38534 ** content out of the database file.
38551 ** to print out file-descriptors.
38554 ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
38601 ** state - the file may or may not be locked and the database size is
38605 ** * Any lock, or no lock at all, may be held on the database file.
38624 ** * A SHARED or greater lock is held on the database file.
38630 ** there is no hot-journal in the file-system.
38640 ** BEGIN EXCLUSIVE) EXCLUSIVE lock is obtained on the database file when
38641 ** moving to this state, but the journal file is not written to or opened
38644 ** file.
38646 ** IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
38648 ** is made to obtain an EXCLUSIVE lock on the database file.
38652 ** lock is held on the database file.
38658 ** * The journal file may or may not be open.
38664 ** first modified by the upper layer. In rollback mode the journal file
38666 ** start of it. The database file on disk has not been modified.
38669 ** * A RESERVED or greater lock is held on the database file.
38670 ** * The journal file is open and the first header has been written
38677 ** when it modifies the contents of the database file. WAL connections
38678 ** never enter this state (since they do not modify the database file,
38679 ** just the log file).
38682 ** * An EXCLUSIVE or greater lock is held on the database file.
38683 ** * The journal file is open and the first header has been written
38694 ** database file. In this state the transaction may be committed simply
38695 ** by finalizing the journal file. Once in WRITER_FINISHED state, it is
38700 ** * An EXCLUSIVE or greater lock is held on the database file.
38711 ** db size etc.) are consistent with the contents of the file-system.
38722 ** file. To avoid this hazard, the pager switches into the ERROR state
38740 ** 2. An error occurs while attempting to finalize a journal file
38744 ** database file in function pagerStress() in order to free up
38788 ** the database file: NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
38796 ** when unlocking the file, and only updated when locking the file if the
38805 ** The exception is when the database file is unlocked as the pager moves
38806 ** from ERROR to OPEN state. At this point there may be a hot-journal file
38807 ** in the file-system that needs to be rolled back (as part of a OPEN->SHARED
38827 ** lock on the database file before attempting to roll it back. See function
38875 Pgno nOrig; /* Original number of pages in file */
38893 ** For a real on-disk database, the current lock held on the database file -
38909 ** (the 4-byte header field at byte offset 24 of the database file) is
38913 ** can only happen if an exclusive lock is held on the database file.
38915 ** relinquished on the database file. Each time a transaction is committed,
38927 ** journal file before it is synced to disk.
38929 ** Whether or not a journal file contains a master-journal pointer affects
38930 ** the way in which the journal file is finalized after the transaction is
38932 ** If a journal file does not contain a master-journal pointer, it is
38934 ** it does contain a master-journal pointer the journal file is finalized
38941 ** subsequently interrupted transaction that reuses the journal file.
38943 ** The flag is cleared as soon as the journal file is finalized (either
38945 ** journal file from being successfully finalized, the setMaster flag
38952 ** write cached data to the file-system in order to free up memory).
38957 ** to allocate a new page to prevent the journal file from being written
38961 ** is permitted, but syncing the journal file is not. This flag is set
38962 ** by sqlite3PagerWrite() when the file-system sector-size is larger than
38969 ** is opened as an in-memory journal file. If false, then in-memory
38977 ** Variable dbSize is set to the number of pages in the database file.
38981 ** dbSize is set based on the size of the database file, which may be
38983 ** 28 of the database header by the btree). If the size of the file
38985 ** dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
38986 ** Except, any file that is greater than 0 bytes in size is considered
38987 ** to have at least one page. (i.e. a 1KB file with 2K page-size leads
39002 ** the file on disk in pages. It is set to a copy of dbSize when the
39004 ** to write or truncate the database file on disk.
39009 ** that the database file is larger than the database image (Pager.dbSize),
39011 ** to measure the database file on disk, and then truncates it if required.
39015 ** pager_truncate() may cause the file
39040 u8 useJournal; /* Use a rollback journal on this file */
39046 u8 tempFile; /* zFilename is a temporary file */
39048 u8 memDb; /* True to inhibit all file I/O */
39060 u8 eLock; /* Current lock held on database file */
39068 Pgno dbFileSize; /* Number of pages in the database file */
39074 Bitvec *pInJournal; /* One bit for each page in the database file */
39075 sqlite3_file *fd; /* File descriptor for database */
39076 sqlite3_file *jfd; /* File descriptor for main journal */
39077 sqlite3_file *sjfd; /* File descriptor for sub-journal */
39078 i64 journalOff; /* Current write offset in the journal file */
39083 char dbFileVers[16]; /* Changes whenever database file changes */
39095 char *zFilename; /* Name of the database file */
39096 char *zJournal; /* Name of the journal file */
39114 char *zWal; /* File name for write-ahead log */
39141 ** file after power is restored. If an attempt is then made
39150 ** journal file right after the header. The random initializer is important,
39153 ** garbage data came from an obsolete journal file, the checksums might
39191 ** The argument to this macro is a file descriptor (type sqlite3_file*).
39242 /* Regardless of the current state, a temp-file connection always behaves
39243 ** as if it has an exclusive lock on the database file. It never updates
39250 ** And if the journal-mode is "OFF", the journal file must not be open.
39258 ** a journal file. (although the in-memory journal implementation may
39259 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
39273 ** on the file.
39308 ** journal file nor the WAL file are open. This happens during
39432 ** Return true if the page is already in the journal file.
39439 ** Read a 32-bit integer from the given file descriptor. Store the integer
39461 ** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK
39471 ** Unlock the database file to level eLock, which must be either NO_LOCK
39497 ** Lock the database file to level eLock, which must be either SHARED_LOCK,
39534 ** then the value returned is the size of the journal file when it
39605 ** When this is called the journal file for pager pPager must be open.
39606 ** This function attempts to read a master journal file name from the
39607 ** end of the file and, if successful, copies it into memory supplied
39609 ** used to store a master journal file name at the end of a journal file.
39618 ** If a master journal file name is present at the end of the journal
39619 ** file, then it is copied into the buffer pointed to by zMaster. A
39621 ** journal file name.
39623 ** If it is determined that no master journal file name is present
39626 ** If an error occurs while reading from the journal file, an SQLite
39632 i64 szJ; /* Total size in bytes of journal file pJrnl */
39695 ** The journal file must be open when this function is called.
39697 ** This function is a no-op if the journal file has not been written to
39701 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
39702 ** zero the 28-byte header at the start of the journal file. In either case,
39703 ** if the pager is not in no-sync mode, sync the journal file immediately
39708 ** journal file in bytes is larger than this value, then truncate the
39709 ** journal file to Pager.journalSizeLimit bytes. The journal file does
39733 ** is still held on the file. If there is a size limit configured for
39734 ** the persistent journal and the journal file currently consumes more
39736 ** to sync the file following this operation.
39750 ** The journal file must be open when this routine is called. A journal
39751 ** header (JOURNAL_HDR_SZ bytes) is written into the journal file at the
39771 assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
39798 ** rest of the journal file contains valid page records. This assumption
39800 ** file it may contain some garbage data. There are two scenarios
39807 ** that garbage data is never appended to the journal file.
39839 ** journal header consumes to the journal file here. Then increment the
39841 ** record is written to the following sector (leaving a gap in the file
39845 ** be significantly slower than contiguously writing data to the file,
39866 ** The journal file must be open when this is called. A journal header file
39868 ** file. The current location in the journal file is given by
39878 ** If the journal header file appears to be corrupted, SQLITE_DONE is
39880 ** cannot be read from the journal file an error code is returned.
39885 i64 journalSize, /* Size of the open journal file in bytes */
39893 assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
39896 ** journal file is too small for there to be a header stored at this
39962 ** the journal file here.
39989 ** Write the supplied master journal name into the journal file for pager
39991 ** thing written to a journal file. If the pager is in full-sync mode, the
39992 ** journal file descriptor is advanced to the next sector boundary before
40010 i64 iHdrOff; /* Offset of header in journal file */
40011 i64 jrnlSize; /* Size of journal file on disk */
40041 /* Write the master journal data to the end of the journal file. If
40055 ** journal-file may extend past the end of the master-journal name
40056 ** and 8 bytes of magic data just written to the file. This is
40057 ** dangerous because the code to rollback a hot-journal file
40062 ** file to the required size.
40139 ** If the pager is not in exclusive-access mode, the database file is
40140 ** completely unlocked. If the file is unlocked and the file-system does
40141 ** not exhibit the UNDELETABLE_WHEN_OPEN property, the journal file is
40147 ** or not, any journal file left in the file-system will be treated
40171 ** close the journal file when dropping the database lock. Otherwise
40172 ** another connection with journal_mode=delete might delete the file
40188 ** file fails, set the current lock to UNKNOWN_LOCK. See the comment
40240 ** to be replayed to restore the contents of the database file (as if
40262 ** the journal file or writing the very first journal-header of a
40271 ** If the journal file is open, then it is "finalized". Once a journal
40272 ** file has been finalized it is not possible to use it to roll back a
40279 ** Journal file descriptor is simply closed. This destroys an
40283 ** Journal file is truncated to zero bytes in size.
40286 ** The first 28 bytes of the journal file are zeroed. This invalidates
40287 ** the first journal header in the file, and hence the entire journal
40288 ** file. An invalid journal file cannot be rolled back.
40291 ** The journal file is closed and deleted using sqlite3OsDelete().
40294 ** the journal file is never used. Instead, if the journalMode is
40299 ** If running in non-exclusive rollback mode, the lock on the file is
40303 ** any of the IO operations to finalize the journal file or unlock the
40305 ** operation to finalize the journal file fails, then the code still
40306 ** tries to unlock the database file if not in exclusive mode. If the
40313 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
40339 /* Finalize the journal file. */
40358 ** file should be closed and deleted. If this connection writes to
40359 ** the database file, it will do so using an in-memory journal.
40392 ** lock held on the database file.
40411 ** database file.
40416 ** the database file and move the pager back to OPEN state. If this
40417 ** means that there is a hot-journal left in the file-system, the next
40452 ** incompatible journal file format.
40486 ** Read a single page from either the journal file (if isMainJrnl==1) or
40488 ** The page begins at offset *pOffset into the file. The *pOffset
40494 ** If the page number of the page record read from the (sub-)journal file
40504 ** If the page record is successfully read from the (sub-)journal file
40506 ** while reading the record from the (sub-)journal file or while writing
40507 ** to the database file, then the IO error code is returned. If data
40508 ** is successfully read from the (sub-)journal file but appears to be
40513 ** * If the record is being rolled back from the main journal file
40534 sqlite3_file *jfd; /* The file descriptor for the journal file */
40558 ** file. Return an error code to the caller if an IO error occurs.
40603 ** not the database file. The page is left marked dirty in this case.
40613 ** pager cache if it exists and the main file. The page is then marked
40625 ** database file without an entry in the rollback journal that can
40632 ** 2008-04-14: When attempting to vacuum a corrupt database file, it
40634 ** Do not attempt to write if database file has never been opened.
40672 file, which may or may not be
40708 ** journal file, then its content must be as they were when the
40715 ** unsynced portion of the main journal file, then it is not safe
40718 ** already in the journal file (recorded in Pager.pInJournal) and
40722 ** be written out into the database file before its journal file
40745 ** Parameter zMaster is the name of a master journal file. A single journal
40746 ** file that referred to the master journal file has just been rolled back.
40747 ** This routine checks if it is possible to delete the master journal file,
40753 ** When a master journal file is created, it is populated with the names
40755 ** encoded text. The end of each child journal file is marked with a
40757 ** file for a transaction involving two databases might be:
40761 ** A master journal file may only be deleted once all of its child
40764 ** This function reads the contents of the master-journal file into
40770 ** file zMaster
40774 ** no such child journal can be found, file zMaster is deleted from
40775 ** the file-system using sqlite3OsDelete().
40783 ** the entire contents of the master journal file. This could be
40790 sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
40791 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
40792 char *zMasterJournal = 0; /* Contents of master journal file */
40793 i64 nMasterJournal; /* Size of master journal file */
40794 char *zJournal; /* Pointer to one journal within MJ file */
40795 char *zMasterPtr; /* Space to hold MJ filename from a journal file */
40798 /* Allocate space for both the pJournal and pMaster file descriptors.
40799 ** If successful, open the master journal file for reading.
40811 /* Load the entire master journal file into space obtained from
40839 ** so, return without deleting the master journal file.
40856 /* We have a match. Do not delete the master journal file. */
40879 ** file in the file-system. This only happens when committing a transaction,
40882 ** If the main database file is not open, or the pager is not in either
40884 ** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
40885 ** If the file on disk is currently larger than nPage pages, then use the VFS
40888 ** Or, it might might be the case that the file on disk is smaller than
40890 ** you try to truncate a file to some size that is larger than it
40892 ** the end of the new file instead.
40895 ** the database file, return the error code to the caller.
40932 ** of the open database file. The sector size will be used used
40943 ** If the file has the SQLITE_IOCAP_POWERSAFE_OVERWRITE property, then set
40949 ** size. For backwards compatibility of the rollback journal file format,
40959 /* Sector size doesn't matter for temporary files. Also, the file
40976 ** Playback the journal and thus restore the database file to
40979 ** The journal file format is as follows:
41003 ** value of nRec from the size of the journal file. But if a power
41005 ** case that the size of the journal file had already been increased but
41007 ** the value of nRec computed from the file size would be too large. For
41011 ** from the file size. This value is used when the user selects the
41016 ** If the file opened as the journal file is not a well-formed
41017 ** journal file then all pages up to the first corrupted page are rolled
41018 ** back (or no pages if the journal header is corrupted). The journal file
41022 ** If an I/O or malloc() error occurs, the journal-file is not deleted
41034 i64 szJ; /* Size of the journal file in bytes */
41037 Pgno mxPg = 0; /* Size of the original file in pages */
41040 char *zMaster = 0; /* Name of master journal file if any */
41053 ** If a master journal file name is specified, but the file is not
41080 /* Read the next journal header from the journal file. If there are
41081 ** not enough bytes left in the journal file for a complete header, or
41095 ** file consists of pages, there are no more journal headers. Compute
41107 ** size of the file.
41115 ** should be computed based on the journal file size.
41123 ** database file back to its original size.
41134 ** database file and/or page cache.
41169 /* Following a rollback, the database file should be back in its original
41171 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
41223 ** Read the content for page pPg out of the database file and into
41225 ** file before this function is called.
41228 ** the value read from the database file.
41237 int isInWal = 0; /* True if page is in log file */
41264 ** that will never be a valid file version. dbFileVers[] is a copy
41317 ** written into the log file when a WAL transaction is rolled back.
41348 ** rollback involves simply truncating the log file. Therefore, if one
41366 ** been written (but not committed) to the log file, do one of the
41415 ** any pages with page numbers greater than nTruncate into the WAL file.
41480 ** to PAGER_READER state to determine the size of the database file
41493 ** available from the WAL sub-system if the log file is empty or
41501 ** determine it based on the size of the database file. If the size
41502 ** of the database file is not an integer multiple of the page-size,
41503 file larger than 0
41507 i64 n = 0; /* Size of db file in bytes */
41518 /* If the current number of pages in the file is greater than the
41520 ** that the file can be read.
41532 ** Check if the *-wal file that corresponds to the database opened by pPager
41533 ** exists if the database is not empy, or verify that the *-wal file does
41534 ** not exist (by deleting it) if the database file is empty.
41536 ** If the database is not empty and the *-wal file exists, open the pager
41537 ** in WAL mode. If the database is empty or if no *-wal file exists and
41543 ** The caller must hold a SHARED lock on the database file to call this
41544 ** function. Because an EXCLUSIVE lock on the db file is required to delete
41555 int isWal; /* True if WAL file exists */
41556 Pgno nPage; /* Size of the database file */
41583 ** the entire master journal file. The case pSavepoint==NULL occurs when
41594 ** file if PagerSavepoint.iHdrOffset is zero.
41598 ** PagerSavepoint.iHdrOffset to the end of the main journal file.
41600 ** * Pages are then played back from the sub-journal file, starting
41602 ** the journal file.
41610 ** journal file. There is no need for a bitvec in this case.
41645 ** journal. The actual file might be larger than this in
41672 ** of the main journal file. Continue to skip out-of-range pages and
41764 ** prior to the start of checkpoint and that the database file is synced
41768 ** file is synced following each commit operation, in addition to the
41814 ** attempts to open a temporary file. This information is used for
41822 ** Open a temporary file.
41824 ** Write the file descriptor into *pFile. Return SQLITE_OK on success
41826 ** delete the temporary file when it is closed.
41838 sqlite3_file *pFile, /* Write the file descriptor here */
42017 ** Read the first N bytes from the beginning of the file into memory
42020 ** If the pager was opened on a transient file (zFilename==""), or
42021 ** opened on a file less than N bytes in size, the output buffer is
42055 ** However, if the file is between 1 and <page-size> bytes in size, then
42056 ** this is considered a 1 page file.
42066 ** Try to obtain a lock of type locktype on the database file. If
42112 ** the database file. If a savepoint transaction were rolled back after
42115 ** the database file or the portion of the rollback journal and
42133 ** Truncate the in-memory database file image to nPage pages. This
42134 ** function does not actually modify the database file on disk. It
42148 ** syncs the journal file to disk, then sets pPager->journalHdr to the
42149 ** size of the journal file so that the pager_playback() routine knows
42150 ** that the entire journal file has been synced.
42201 /* If it is open, sync the journal file before calling UnlockAndRollback.
42203 ** file may be played back into the database. If a power failure occurs
42208 ** database and close the journal file without attempting to roll it
42210 ** rollback before accessing the database file.
42260 ** device characteristics of the the file-system, as follows:
42262 ** * If the journal file is an in-memory journal file, no action need
42269 ** mode, then the journal file is synced before this field is updated.
42272 ** journal file is synced.
42278 ** if( <full-sync mode> ) xSync(<journal file>);
42281 ** if( NOT SEQUENTIAL ) xSync(<journal file>);
42309 ** mode, then the journal file may at this point actually be larger
42311 ** file happens to be a journal-header (written as part of the
42314 ** anything else to the journal file (or commits/rolls back its
42320 ** To work around this, if the journal file does appear to contain
42346 /* Write the nRec value into the journal file header. If in
42353 ** for garbage data to be appended to the file, the nRec field
42389 /* Unless the pager is in noSync mode, the journal file was just
42402 ** in-memory pages in the list to the database file. The argument may
42407 ** is called. Before writing anything to the database file, this lock
42409 ** SQLITE_BUSY is returned and no data is written to the database file.
42411 ** If the pager is a temp-file pager and the actual file-system file
42415 ** Once the lock has been upgraded and, if necessary, the file opened,
42416 ** the pages are written out to the database file in list order. Writing
42422 ** If writing out a page causes the database file to grow, Pager.dbFileSize
42425 ** the database file.
42439 /* If the file is a temp-file has not yet been opened, open it now. It
42449 ** file size will be.
42463 ** make the file smaller (presumably by auto-vacuum code). Do not write
42464 ** any such pages to the file.
42483 ** the value now stored in the database file. If writing this
42484 ** page caused the database file to grow, update dbFileSize.
42512 ** Ensure that the sub-journal file is open. If it is already open, this
42560 ** write the journal record into the file. */
42592 ** out to the database file, if possible. This may involve syncing the
42593 ** journal file.
42640 /* Sync the journal file if required. */
42650 ** actually write data to the file in this case.
42658 ** <shrink database file to Y pages>
42663 ** out to the database file, but will be dropped from the cache. Then,
42665 ** data from the database file. This will be the copy of page X as it
42670 ** sub-journal file now (if it is not already there), so that it will
42680 /* Write the contents of the page out to the database file. */
42702 ** The zFilename argument is the path to the database file to open.
42703 ** If zFilename is NULL then a randomly-named temporary file is created
42704 ** and used as the file to be cached. Temporary files are be deleted
42720 ** If the pager object is allocated and the specified file opened
42728 sqlite3_vfs *pVfs, /* The virtual file system to use */
42730 const char *zFilename, /* Name of the database file to open */
42732 int flags, /* flags controlling this file */
42740 int memDb = 0; /* True if this is an in-memory file */
42741 int readOnly = 0; /* True if this is a read-only file */
42743 char *zPathname = 0; /* Full path to database file */
42751 /* Figure out how much space is required for each journal file-handle
42753 ** is the maximum space required for an in-memory journal file handle
42754 ** and a regular journal file-handle. Note that a "regular journal-handle"
42756 ** file in memory to implement the atomic-write optimization (see
42757 ** source file journal.c).
42776 ** to by zPathname, length nPathname. Or, if this is a temporary file,
42800 ** as it will not be possible to open the journal file or even
42812 ** three file descriptors, the database file name and the journal
42813 ** file name. The layout in memory is as follows:
42817 ** Database file handle (pVfs->szOsFile bytes)
42818 ** Sub-journal file handle (journalFileSize bytes)
42819 ** Main journal file handle (journalFileSize bytes)
42820 ** Database file name (nPathname+1 bytes)
42821 ** Journal file name (nPathname+8+1 bytes)
42826 ROUND8(pVfs->szOsFile) + /* The main db file */
42867 /* Open the pager file.
42875 /* If the file was successfully opened for read/write access,
42877 ** database file. The default page size is the maximum of:
42909 /* If a temporary file is requested, it is not opened immediately.
42911 ** opening the file until the first call to OsWrite().
42914 ** database is the same as a temp-file that is never written out to
42933 ** Pager structure and close the file.
43011 ** the file-system for the given pager. A hot journal is one that
43013 ** file exists if the following criteria are met:
43015 ** * The journal file exists in the file system, and
43016 ** * No process holds a RESERVED or greater lock on the database file, and
43017 ** * The database file itself is greater than 0 bytes in size, and
43018 ** * The first byte of the journal file exists and is not 0x00.
43020 ** If the current size of the database file is 0 but a journal file
43022 ** database with the same name. In this case the journal file is
43027 ** at the end of the file. If there is, and that master journal file
43028 ** does not exist, then the journal file is not really hot. In this
43030 ** routine will discover that the journal file is not really hot and
43033 ** If a hot-journal file is found to exist, *pExists is set to 1 and
43034 ** SQLITE_OK returned. If no hot-journal file is present, *pExists is
43036 ** to determine whether or not a hot-journal file exists, the IO error
43042 int exists = 1; /* True if a journal file is present */
43070 Pgno nPage; /* Number of pages in database file */
43072 /* Check the size of the database file. If it consists of 0 pages,
43073 ** then delete the journal file. See the header comment above for
43074 ** the reasoning here. Delete the obsolete journal file under
43088 /* The journal file exists and no other connection has a reserved
43089 ** or greater lock on the database file. Now check that there is
43090 ** at least one non-zero bytes at the start of the journal file.
43109 /* If we cannot open the rollback journal file in order to see if
43130 ** This function is called to obtain a shared lock on the database file.
43138 ** on the database file), then an attempt is made to obtain a
43139 ** SHARED lock on the database file. Immediately after obtaining
43140 ** the SHARED lock, the file-system is checked for a hot-journal,
43143 ** the 'change-counter' field of the database file header and
43150 ** file.
43153 ** occurs while locking the database, checking for a hot-journal file or
43154 ** rolling back a journal file, the IO error code is returned.
43170 int bHotJournal = 1; /* True if there exists a hot journal-file */
43180 /* If a journal file exists, and there is no RESERVED lock on the
43181 ** database file, then it either needs to be played back or deleted.
43190 /* Get an EXCLUSIVE lock on the database file. At this point it is
43193 ** database file, detect the RESERVED lock, and conclude that the
43198 ** other process attempting to access the database file will get to
43200 ** on the database file.
43210 /* If it is not already open and the file exists on disk, open the
43212 ** in exclusive-access mode the file descriptor will be kept open
43221 ** function was called and the journal file does not exist.
43225 int bExists; /* True if journal file exists */
43264 ** the file. If the unlock attempt fails, then Pager.eLock must be
43270 ** to ERROR state in the state diagram at the top of this file,
43290 /* The shared-lock has just been acquired on the database file
43297 ** at offset 24 into the file. The first 4 of these 16 bytes are
43299 ** other bytes change randomly with each file change when
43327 /* If there is a WAL file in the file-system, open this database in WAL
43377 ** read from the database file. In some cases, the pcache module may
43404 ** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
43421 Pager *pPager, /* The pager open on the database file */
43562 ** file when this routine is called.
43564 ** Open the journal file for pager pPager and write a journal header
43566 ** as well. This function is only used when the journal file is being
43568 ** when opening a hot journal file to roll it back.
43570 ** If the journal file is already open (as it may be in exclusive mode),
43572 ** already open file.
43574 ** Whether or not the journal file is opened by this function, the
43579 ** an IO error code if opening or writing the journal file fails.
43600 /* Open the journal file if it is not already open. */
43605 const int flags = /* VFS flags to open journal file */
43623 /* Write the first journal header to the journal file and open
43652 ** lock on the database file. If exFlag is true, then acquire at least
43657 ** within this transaction will be opened as an in-memory file. This
43662 ** or using a temporary file otherwise.
43686 /* Grab the write lock on the log file. If successful, upgrade to
43693 /* Obtain a RESERVED lock on the database file. If the exFlag parameter
43711 ** file as well as into the page cache. Which would be incorrect in
43743 ** been started. The journal file may or may not be open at this point.
43762 /* The journal file needs to be opened. Higher level routines have already
43787 ** EXCLUSIVE lock on the main database file. Write the current page to
43797 /* We should never write to the journal file the page that
43810 ** in the database file. And if an IO error occurs while doing so,
43877 ** must have been written to the journal file before returning.
43894 Pgno nPageCount; /* Total number of pages in database file */
43951 ** journal file must contain sync()ed copies of all of them
43952 ** before any of them can be written out to the database file.
44009 ** This routine is called to increment the value of the database file
44011 ** byte offset 24 of the pager file. The secondary change counter at
44021 ** page data. In this case the file will be updated when the current
44026 ** if isDirect is non-zero, then the database file is updated directly
44061 /* Open page 1 of the file for writing. */
44078 /* If running in direct mode, write the contents of page 1 to the file. */
44101 ** Sync the database file to disk. This is a no-op for in-memory databases
44126 ** the database file, an attempt is made to obtain one.
44147 ** Sync the database file for the pager pPager. zMaster points to the name
44148 ** of a master journal file that should be written into the individual
44149 ** journal file. zMaster may be NULL, which is interpreted as no master
44154 ** * The database file change-counter is updated,
44156 ** * all dirty pages are written to the database file,
44157 ** * the database file is truncated (if required), and
44158 ** * the database file synced.
44161 ** (delete, truncate or zero the first part of) the journal file (or
44162 ** delete the master journal file if specified).
44167 ** If the final parameter - noSync - is true, then the database file itself
44169 ** sync the database file before calling CommitPhaseTwo() to delete the
44170 ** journal file in this case.
44175 int noSync /* True to omit the xSync on the db file */
44189 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
44226 ** * The file-system supports the atomic-write property for
44228 ** * This commit is not part of a multi-file transaction, and
44229 ** * Exactly one page has been modified and store in the journal file.
44235 ** to make sure the journal file has actually been created, then call
44241 ** in 'direct' mode. In this case the journal file will never be
44255 /* Update the db file change counter via the direct-write method. The
44258 ** directly to the database file. Because of the atomic-write
44259 ** property of the host file-system, this is safe.
44275 ** file. This can only happen in auto-vacuum mode.
44281 ** reading data from the database file.
44305 /* Write the master journal name into the journal file. If a master
44306 ** journal file name has already been written to the journal file,
44312 /* Sync the journal file and write all dirty pages to the database.
44314 ** create the journal file or perform any real IO.
44333 /* If the file on disk is not the same size as the database image,
44334 ** then use pager_truncate to grow or shrink the file here.
44343 /* Finally, sync the database file. */
44360 ** When this function is called, the database file has been completely
44362 ** synced to disk. The journal file still exists in the file-system
44366 ** This function finalizes the journal file, either by deleting,
44392 ** The start of the journal file currently contains a single journal
44395 ** to the database file. So there is no need to zero the journal
44424 ** 1) It rolls back the journal file, restoring all database file and
44428 ** 2) It finalizes the journal file, so that it is not used for hot
44431 ** Finalization of the journal file (task 2) is only performed if the
44483 ** Return TRUE if the database file is opened read-only. Return FALSE
44576 ** occurs while opening the sub-journal file, then an IO error code is
44691 ** If this is a temp-file, it is possible that the journal file has
44693 ** the database file, so the playback operation can be skipped.
44706 ** Return the full pathname of the database file.
44720 ** Return the file handle for the database file associated
44721 ** with the pager. This might return NULL if the file has
44729 ** Return the full pathname of the journal file.
44768 ** Move the page pPg to location pgno in the file.
44888 /* If needSyncPgno is non-zero, then the journal file needs to be
44889 ** sync()ed before any data is written to database file page needSyncPgno.
44898 ** this transaction, it may be written to the database file before
44899 ** it is synced into the journal file. This way, it may end up in
44900 ** the journal file twice, but that is not a problem.
44998 ** the logic there will never allow a temporary file to be changed
45021 ** delete the journal file.
45033 /* In this case we would like to delete the journal file. If it is
45034 ** not possible, then that is not a problem. Deleting the journal file
45037 ** Before deleting the journal file, obtain a RESERVED lock on the
45038 ** database file. This ensures that the journal file is not deleted
45158 ** Attempt to take an exclusive lock on the database file. If a PENDING lock
45178 ** lock on the database file and use heap-memory to store the wal-index
45190 ** file, to make sure this is safe.
45196 /* Open the connection to the log file. If this operation fails,
45211 ** The caller must be holding a SHARED lock on the database file to call
45215 ** file (not a temp file or an in-memory database), and the WAL file
45221 ** If the pager is open on a temp-file (or in-memory database), or if
45222 ** the WAL file is already open, set *pbOpen to 1 and return SQLITE_OK
45256 ** This function is called to close the connection to the log file prior
45259 ** Before closing the log file, this function attempts to take an
45260 ** EXCLUSIVE lock on the database file. If this cannot be obtained, an
45269 /* If the log file is not already open, but does exist in the file-system,
45287 ** the database file, the log and log-summary files will be deleted.
45303 ** the pager is in WAL mode and the WAL file currently contains one or more
45305 ** WAL frames. Otherwise, if this is not a WAL database or the WAL file
45317 ** into the log file.
45334 /************** Begin file wal.c *********************************************/
45347 ** This file contains the implementation of a write-ahead log (WAL) used in
45350 ** WRITE-AHEAD LOG (WAL) FILE FORMAT
45352 ** A WAL file consists of a header followed by zero or more "frames".
45354 ** database file. All changes to the database are recorded by writing
45358 ** transferred back into the database file in an operation called a
45361 ** A single WAL file can be used multiple times. In other words, the
45372 ** 4: File format version. Currently 3007000
45442 ** the database file.
45464 ** might choose to implement the wal-index using a mmapped file. Because
45470 ** be) reconstructed from the original WAL file. In fact, the VFS is required
45474 ** Hence, unlike the database and WAL file formats which store all values
45501 ** first frame in the WAL file. The first entry in the second index block
45502 ** in the WAL file corresponds to the (HASHTABLE_NPAGE_ONE+1)th frame in
45507 ** depending on the contents of the WAL file. This does not change the
45554 ** to cover a typical 10 megabyte WAL file, assuming 1K pages. 8 or 10
45593 ** If a client begins recovering a WAL file and finds that (a) the checksum
45683 ** get all their all content directly from the database file and ignore
45705 ** only support mandatory file-locks, we do not read or write data
45706 ** from the region of the file on which locks are applied.
45721 ** big-endian format in the first 4 bytes of a WAL file.
45724 ** file are calculated by treating all data as an array of 32-bit
45731 ** Return the offset of frame iFrame in the write-ahead log file,
45740 ** An open write-ahead log file is represented by an instance of the
45745 File handle for the database file */
45746 sqlite3_file *pWalFd; /* File handle for WAL file */
45750 int szFirstBlock; /* Size of first block written to WAL file */
45759 u8 truncateOnCommit; /* True to truncate WAL file on commit */
45763 const char *zWalName; /* Name of WAL file */
45781 #define WAL_RDONLY 1 /* The WAL file is readonly */
45782 #define WAL_SHM_RDONLY 2 /* The SHM file is readonly */
45818 ** Define the parameters of the hash tables in the wal-index file. There
46161 ** in the wal-index file. Set *piZero to one less than the frame
46311 /* Assuming the wal-index file was successfully mapped, populate the
46383 ** Recover the wal-index by reading the write-ahead log file.
46394 i64 nSize; /* Size of log file */
46430 i64 iOffset; /* Next offset to read from log file */
46443 ** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid
46445 ** WAL file.
46488 /* Read all frames from the log file. */
46535 /* If more than one frame was recovered from the log file, report an
46538 ** checkpointing the log file.
46541 sqlite3_log(SQLITE_OK, "Recovered %d frames from WAL file %s",
46569 ** Open a connection to the WAL file zWalName. The database file must
46573 ** A SHARED lock should be held on the database file when this function
46575 ** client from unlinking the WAL or wal-index file. If another process
46579 ** If the log file is successfully opened, SQLITE_OK is returned and
46585 sqlite3_file *pDbFd, /* The open database file */
46586 const char *zWalName, /* Name of the WAL file */
46599 ** this source file. Verify that the #defines of the locking byte offsets
46627 /* Open file handle on the write-ahead log file. */
46651 ** Change the size to which the WAL file is trucated on each reset.
46957 ** Copy as much content as we can from the WAL back into the database file
46973 ** Fsync is also called on the database file if (and only if) the entire
46974 ** WAL content is copied into the database file. This second fsync makes
46976 ** database file.
47048 i64 nSize; /* Current size of database file */
47056 /* If the database file may grow as a result of this checkpoint, hint
47057 ** about the eventual size of the db file to the VFS layer.
47067 /* Iterate through the contents of the WAL, copying data to the db file. */
47073 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
47108 ** file has been copied into the database file, then block until all
47109 ** readers have finished using the wal file. This ensures that the next
47110 ** process to write to the database restarts the wal file.
47131 ** If the WAL file is currently larger than nMax bytes in size, truncate
47149 ** Close a connection to a log file.
47161 /* If an EXCLUSIVE lock can be obtained on the database file (using the
47163 ** connection associated with this log file is the only connection to
47183 /* Try to delete the WAL file if the checkpoint completed and
47188 /* Try to truncate the WAL file to zero bytes if the checkpoint
47193 ** leave a corrupt WAL file on disk. */
47241 ** from the file. If this happens, return non-zero.
47392 ** completely and get all content directly from the database file.
47484 ** When holding READ_LOCK(0), the reader ignores the entire log file,
47485 ** which implies that the database file contains a trustworthy
47493 ** it finished. Leaving a corrupt image in the database file.
47553 ** that the log file may have been wrapped by a writer, or that frames
47705 ** of the wal-index file content. Make sure the results agree with the
47721 ** required page. Read and return data from the log file.
47785 /* If another connection has written to the database file since the
47812 ** If any data has been written (but not committed) to the log file, this
47906 ** file (see sqlite3WalFrames()). It checks to see if, instead of appending
47907 ** to the current log file, it is possible to overwrite the start of the
47908 ** existing log file with the new frames (i.e. "reset" the log). If so,
47970 ** Information about the current state of the WAL file and where
47976 sqlite3_file *pFd; /* The WAL file
47983 ** Write iAmt bytes of content into the WAL file beginning at iOffset.
48039 ** on the log file (obtained using sqlite3WalBeginWriteTransaction()).
48055 i64 iOffset; /* Next byte to write in WAL file */
48073 ** log file, instead of appending to it at pWal->hdr.mxFrame.
48080 ** header to the start of the WAL file. See comments at the top of
48081 ** this source file for a description of the WAL header format.
48133 /* Write all frames into the log file exactly once */
48146 ** the transaction and/or sync the WAL file.
48239 int sync_flags, /* Flags to sync db file with (or 0) */
48287 /* Copy data from the log to the database file. */
48344 ** lock on the main database file.
48351 ** on the main database file before invoking this operation.
48419 /************** Begin file btmutex.c *****************************************/
48432 ** This file contains code used to implement mutexes on Btree objects.
48438 /************** Begin file btreeInt.h ****************************************/
48450 ** This file implements a external (disk-based) database using BTrees.
48457 ** The basic idea is that each page of the file contains N database
48473 ** In this implementation, a single file can hold one or more separate
48485 ** The file is divided into pages. The first page is called page 1,
48492 ** page contain a special header (the "file header") that describes the file.
48493 ** The format of the file header is as follows:
48498 ** 18 1 File format write version
48499 ** 19 1 File format read version
48504 ** 24 4 File change counter
48507 ** 36 4 Number of freelist pages in the file
48511 ** 44 4 File format of schema layer
48523 ** The file change counter is incremented when the database is changed
48524 ** This counter allows other processes to know when the file has changed
48545 ** file header that occurs before the page header.
48548 ** | file header | 100 bytes. Page 1 only.
48644 ** file header points to the first in a linked list of trunk page. Each trunk
48673 ** SQLite database in order to identify the file as a real database.
48697 ** As each page of the file is loaded into memory, an instance of the following
48699 ** information about the page that is decoded from the raw file page.
48763 ** this object for every database file that it has open. This structure
48772 ** schema associated with the database file are all contained within
48808 ** An instance of this object represents a single database file.
48810 ** A single database file can be in use at the same time by two
48812 ** sharing the same database file, each connection has it own
48813 ** private Btree object for the file and each of those Btrees points
48815 ** connections currently sharing this database file.
48879 #define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
48917 ** b-tree within a database file.
48922 ** A single database file can be shared by two more database connections,
49011 ** each child page in the database file. The parent page is the page that
49019 ** position in the file to another as part of autovacuum. When a page
49365 /************** Begin file btree.c *******************************************/
49377 ** This file implements a external (disk-based) database using BTrees.
49379 ** Including a description of file format and an overview of operation.
49413 ** in shared cache. This variable has file scope during normal builds,
49596 ** transaction on this file. And, obviously, for this to be so there
49597 ** must be an open write transaction on the file itself.
49622 ** may hold a WRITE_LOCK on any table in this file (since there can
49831 Btree *pBtree, /* The database file to check */
49868 ** from the database or written to the journal file (why should it
50254 ** Within this file, the parseCell() macro can be called instead of
50303 ** way will result in an incompatible file format.
50945 ** Return the size of the database file in pages. If there is any kind of
50966 BtShared *pBt, /* The database file */
51043 ** Open a database file.
51045 ** zFilename is the name of the database file. If zFilename is NULL
51065 const char *zFilename, /* Name of the file containing the BTree database */
51082 ** false for a file-based database.
51226 ** regular file-name. In this case the auto-vacuum applies as per normal.
51517 ** of the database file used for locking (beginning at PENDING_BYTE,
51655 ** Get a reference to pPage1 of the database file. This will
51656 ** also acquire a readlock on that file.
51658 ** SQLITE_OK is returned on success. If the file is not a
51659 ** well-formed database file, then SQLITE_CORRUPT is returned.
51665 MemPage *pPage1; /* Page 1 of the database file */
51667 int nPageFile = 0; /* Number of pages in the database file */
51677 /* Do some checking to help insure the file we opened really is
51678 ** a valid database file.
51715 ** file.
51813 ** this routine unrefs the first page of the database file which
51831 ** If pBt points to an empty file then convert that empty file
51969 ** file is not pBt->pageSize. In this case lockBtree() will update
51970 ** pBt->pageSize to the page-size of the file on disk.
52017 ** client has been writing the database file), update it now. Doing
52245 ** database so that the last page of the file currently in use
52251 ** number of pages the database file will contain after this
52311 ** of the file is found.
52391 ** the database file should be truncated to during the commit process.
52463 ** database are written into the database file and flushed to oxide.
52471 ** Otherwise, sync the database file for the btree pBt. zMaster points to
52472 ** the name of a master journal file that should be written into the
52473 ** individual journal file, or is NULL, indicating no master journal file
52480 ** the write-transaction for this database file is to delete the journal.
52552 ** finalize the underlying journal file, this function returns an error and
52554 ** is non-zero then this b-tree transaction is part of a multi-file
52556 ** (by deleting a master journal file) and the caller will ignore this
52562 ** This will release the write lock on the database file. If there
52667 ** This will release the write lock on the database file. If there
52909 ** Set the cached rowid value of every cursor in the same database file
52939 ** Close a cursor. The read lock on the database file is released
53092 BtShared *pBt, /* The database file */
53328 ** 3) the database is file-backed, and
53332 ** then data can be read directly from the database file into the
53584 ** below to be untrue if the database file is corrupt. This can occur if
54067 /* If the database file is corrupt, it is possible for the value of idx
54171 ** Allocate a new page from the database file.
54184 ** attempt to keep related pages close to each other in the database file,
54204 Pgno mxPage; /* Total size of the database file */
54404 ** end of the file */
54413 ** at the end of the file instead of one. The first allocated page
54417 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
54439 TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
54461 ** This function is used to add page iPage to the database file free-list.
54630 ** file the database must be corrupt. */
55587 ** file is corrupt. The corruption will be detected and reported later
55645 ** keep entries in the disk file in order so that a scan
55646 ** of the table is a linear scan through the file. That
55735 ** Note that this can never happen in an SQLite data file, as all
56444 ** by extending the file), the current page at position pgnoMove
56620 ** root page in the database file, then the last root page
56621 ** in the database file is moved into the slot formerly occupied by
56624 ** root pages are kept at the beginning of the database file, which
56626 ** page number that used to be the last root page in the file before
56747 ** Read the meta-information out of a database file. Meta[0]
57274 ** This routine does a complete check of the given BTree file. aRoot[] is
57344 /* Make sure every page in the file is referenced
57393 ** Return the full pathname of the underlying database file.
57404 ** Return the pathname of the journal file for this database. The return
57405 ** value of this routine is the same regardless of whether the journal file
57636 /************** Begin file backup.c ******************************************/
57648 ** This file contains the implementation of the sqlite3_backup_XXX()
57663 Btree *pDest; /* Destination b-tree file */
57669 Btree *pSrc; /* Source b-tree file */
58065 ** fix the size of the file. However it is important to call
58067 ** destination file that lie beyond the nDestTruncate page mark are
58069 ** by the file truncation.
58108 ** the database file in any way, knowing that if a power failure
58110 ** journal file. */
58113 /* Write the extra pages and truncate the database file as required */
58133 /* Sync the database file to disk. */
58300 ** The size of file pTo may be reduced by this operation. If anything
58306 sqlite3_file *pFd; /* File descriptor for database pTo */
58332 ** file. By passing this as the number of pages to copy to
58356 /************** Begin file vdbemem.c *****************************************/
58369 ** This file contains code use to manipulate "Mem" structure. A "Mem"
59512 /************** Begin file vdbeaux.c *****************************************/
59524 ** This file contains code used for creating, destroying, and populating
59526 ** to version 2.8.7, all this code was combined into the vdbe.c source file.
59527 ** But that file was getting too big so this subroutines were split out.
59607 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
60553 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){
61248 ** write-transaction spanning more than one database file, this routine
61266 ** be done before determining whether a master journal file is
61275 ** one database file has an open write transaction, a master journal
61276 ** file is required for an atomic commit.
61298 /* The simple case - no more than one database file (not counting the
61303 ** string, it means the main database is :memory: or a temp file. In
61304 ** that case we do not support atomic multi-file commits, so use the
61319 ** IO error while deleting or truncating a journal file. It is unlikely,
61333 /* The complex case - There is a multi-file write-transaction active.
61334 ** This requires a master journal file to ensure the transaction is
61341 char *zMaster = 0; /* File-name for the master journal */
61349 /* Select a master journal file name */
61386 /* Write the name of each database file in the transaction into the new
61387 ** master journal file. If an error occurs at this point close
61388 ** and delete the master journal file. All the individual journal files
61414 /* Sync the master journal file. If the IOCAP_SEQUENTIAL device
61429 ** an error occurs here, do not delete the master journal file.
61433 ** master journal file will be orphaned. But we cannot delete it,
61434 ** in case the master journal file name was written into the journal
61435 ** file before the failure occurred.
61450 /* Delete the master journal file. This commits the transaction. After
61668 ** file as part of an effort to free up cache space (see function
61887 FILE *out = fopen("vdbe_profile.out", "a");
62076 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
62554 ** pCur might be pointing to text obtained from a corrupt database file.
62749 /************** Begin file vdbeapi.c *****************************************/
62762 ** This file contains code use to implement APIs that are part of the
64064 /************** Begin file vdbetrace.c ***************************************/
64077 ** This file contains code used to insert the values of host parameters
64336 /************** Begin file vdbe.c ********************************************/
64348 ** The code in this file implements execution method of the
64349 ** Virtual Database Engine (VDBE). A separate file ("vdbeaux.c")
64351 ** VDBE instances. This file is solely interested in executing
64371 ** Most of the code in this file is taken up by the sqlite3VdbeExec()
64376 ** Various scripts scan this source file in order to generate HTML
64378 ** of the code in this file is, therefore, important. See other comments
64379 ** in this file for details. If in doubt, do not deviate from existing
64758 static void memTracePrint(FILE *out, Mem *p){
64778 static void registerTrace(FILE *out, int iReg, Mem *p){
64799 /************** Begin file hwtime.h ******************************************/
64812 ** This file contains inline asm code for retrieving "high-performance"
65112 int file_format; /* File format to use for encoding */
65360 const char *zFilename; /* Name of database file for pPager */
65564 ** file looking for lines that begin with "case OP_". The opcodes.h files
65566 ** opcode and the opcodes.c file is filled with an array of strings where
65576 ** Documentation about VDBE opcodes is generated by scanning this file
65579 ** file.
65583 ** Formatting is important to scripts that scan this file.
67144 ** the database file has been corrupted externally.
67167 ** allocation, especially if a corrupt database file has caused u.an.offset
67353 int file_format; /* File format to use for encoding */
67730 ** P1 is the index of the database file on which the transaction is
67731 ** started. Index 0 is the main database file and index 1 is the
67732 ** file used for temporary tables. Indices of 2 or more are used for
67736 ** obtained on the database file when a write-transaction is started. No
67741 ** on the file.
67753 ** If P2 is zero, then a read-lock is obtained on the database file.
67804 ** the main database file and P1==1 is the database file used to store
67835 ** size, and so forth. P1==0 is the main database file and P1==1 is the
67836 ** database file used to store temporary tables.
67859 /* Record changes in the file format */
67877 ** P1 is the database number which is 0 for the main database file
67878 ** and 1 for the file holding temporary tables and some higher number
67909 /* If the schema-cookie from the database file matches the cookie
67911 ** not reload the schema from the database file.
67935 ** P2 in a database file. The database file is determined by P3.
69080 ** it is found in the database file.
69090 ** it is found in the database file.
69600 ** file is given by P1.
69602 ** The table being destroyed is in the main database file if P3==0. If
69603 ** P3==1 then the table to be clear is in the auxiliary database file
69660 ** in the database file is given by P1. But, unlike Destroy, do not
69661 ** remove the table or index from the database file.
69663 ** The table being clear is in the main database file if P2==0. If
69664 ** P2==1 then the table to be clear is in the auxiliary database file
69698 ** Allocate a new table in the main database file if P1==0 or in the
69699 ** auxiliary database file if P1==1 or in an attached database if
69711 ** Allocate a new index in the main database file if P1==0 or in the
69712 ** auxiliary database file if P1==1 or in an attached database if
69867 ** file, not the main database file.
70438 const char *zFilename; /* Name of database file for pPager */
70465 && (sqlite3Strlen30(u.ci.zFilename)==0 /* Temp file */
70484 /* If leaving WAL mode, close the log file. If successful, the call
70486 ** file. An EXCLUSIVE lock may still be held on the database file
70499 /* Open a transaction on the database file. Regardless of the journal
71175 /************** Begin file vdbeblob.c ****************************************/
71188 ** This file contains code used to implement incremental BLOB I/O.
71645 /************** Begin file vdbesort.c ****************************************/
71657 ** This file contains code for the VdbeSorter object, used in concert with
71739 i64 iWriteOff; /* Current write offset within file pTemp1 */
71740 i64 iReadOff; /* Current read offset within file pTemp1 */
71748 sqlite3_file *pTemp1; /* PMA file 1 */
71762 sqlite3_file *pFile; /* File iterator is reading from */
71846 ** Write a single varint, value iVal, to file-descriptor pFile. Return
71850 ** offset in file pFile to write to. Before returning, *piOffset is
71854 sqlite3_file *pFile, /* File to write to */
71856 i64 *piOffset /* IN/OUT: Write offset in file pFile */
71870 ** Read a single varint from file-descriptor pFile. Return SQLITE_OK if
71874 ** byte offset in file pFile from whence to read the varint. If successful
71881 sqlite3_file *pFile, /* File to read from */
71883 i64 *piVal /* OUT: Value read from file */
71886 i64 iOff = *piOffset; /* Offset in file to read from */
71898 ** Initialize iterator pIter to scan through the PMA stored in file pFile
72092 ** Allocate space for a file-handle and open a temporary file. If successful,
72093 ** set *ppFile to point to the malloc'd file-handle and return SQLITE_OK.
72202 /* If the first temporary PMA file has not been opened, open it now. */
72239 /* Terminate each file with 8 extra bytes so that from any offset
72240 ** in the file we can always read 9 bytes without a SHORT_READ error */
72333 sqlite3_file *pTemp2 = 0; /* Second temp file to use */
72374 /* If there are SORTER_MAX_MERGE_COUNT or less PMAs in file pTemp1,
72381 ** are merged into a single PMA that is written to file pTemp2.
72389 /* Open the second temp file, if it is not already open. */
72528 /************** Begin file journal.c *****************************************/
72541 ** This file implements a special kind of sqlite3_file object used
72546 ** actual on disk file is created lazily. When the file is created,
72548 ** be used to service read() and write() requests. The actual file
72560 ** as an open file handle for journal files.
72569 sqlite3_file *pReal; /* The "real" underlying file descriptor */
72570 const char *zJournal; /* Name of the journal file */
72575 ** If it does not already exists, create and populate the on-disk file
72595 ** Close the file.
72607 ** Read data from the file.
72610 sqlite3_file *pJfd, /* The journal file from which to read */
72628 ** Write data to the file.
72631 sqlite3_file *pJfd, /* The journal file into which to write */
72634 sqlite_int64 iOfst /* Begin writing at this offset into the file */
72655 ** Truncate the file.
72669 ** Sync the file.
72683 ** Query the size of the file in bytes.
72720 ** Open a journal file.
72723 file I/O */
72724 const char *zName, /* Name of the journal file */
72725 sqlite3_file *pJfd, /* Preallocated, blank file handle */
72727 int nBuf /* Bytes buffered before opening the file */
72749 ** file has not yet been created, create it now.
72768 /************** Begin file memjournal.c **************************************/
72781 ** This file contains code use to implement an in-memory rollback journal.
72820 sqlite3_int64 iOffset; /* Offset from the beginning of the file */
72831 FilePoint endpoint; /* Pointer to the end of the file */
72836 ** Read data from the in-memory journal file. This is the implementation
72840 sqlite3_file *pJfd, /* The journal file from which to read */
72851 /* SQLite never tries to read past the end of a rollback journal file */
72882 ** Write data to the file.
72885 sqlite3_file *pJfd, /* The journal file into which to write */
72888 sqlite_int64 iOfst /* Begin writing at this offset into the file */
72894 /* An in-memory journal file should only ever be appended to. Random
72906 /* New chunk is required to extend the file. */
72932 ** Truncate the file.
72950 ** Close the file.
72959 ** Sync the file.
72972 ** Query the size of the file in bytes.
73004 ** Open a journal file.
73014 ** Return true if the file-handle passed as an argument is
73022 ** Return the number of bytes required to store a MemJournal file descriptor.
73029 /************** Begin file walker.c ******************************************/
73041 ** This file contains routines used for walking the parser tree for
73167 /************** Begin file resolve.c *****************************************/
73180 ** This file contains routines used for walking the parser tree and
74392 /************** Begin file expr.c ********************************************/
74404 ** This file contains routines used for analyzing expressions and
77202 ** The value in regFree1 might get SCopy-ed into the file result.
78432 /************** Begin file alter.c *******************************************/
78444 ** This file contains C code routines that used to generate VDBE code
78449 ** The code in this file only exists if we are not omitting the
79022 ** Generate code to make sure the file format number is at least minFormat.
79023 ** The generated code will increase the file format number if necessary.
79153 /* If the default value of the new column is NULL, then set the file
79155 ** the file format becomes 3.
79260 /************** Begin file analyze.c *****************************************/
79272 ** This file contains code associated with the ANALYZE command.
80387 file attach.c ******************************************/
80399 ** This file contains code used to implement the ATTACH and DETACH commands.
80513 /* Open the database file. If the btree is successfully opened, use
80587 /* If the file was opened successfully, read the schema for the new database.
80588 ** If this fails, or if opening the file failed, then close the file and
80693 Expr *pFilename, /* Name of database file */
80946 /************** Begin file auth.c ********************************************/
80958 ** This file contains code used to implement the sqlite3_set_authorizer()
80965 ** All of the code in this file may be omitted by defining a single
81197 /************** Begin file build.c *******************************************/
81209 ** This file contains C code routines that are called by the SQLite parser
81210 ** when syntax rules are reduced. The routines in this file handle the
81340 /* The cookie mask contains one bit for each database file open.
81392 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
81601 ** single file indicated.
81907 ** file instead of in the main database file. This is normally the case
82068 /* If the file format and encoding in the database have not been set,
82707 ** file instead of into the main database file.
84702 "file for storing temporary tables");
85013 /************** Begin file callback.c ****************************************/
85026 ** This file contains functions used to access the internal hash tables
85472 /************** Begin file delete.c ******************************************/
85484 ** This file contains C code routines that are called by the parser
85923 ** thely may interfere with compilation of other functions in this file
85924 ** (or in another file, if this file becomes part of the amalgamation). */
86125 /************** Begin file func.c ********************************************/
86137 ** This file contains the C functions that implement various SQL
86140 ** There is only one exported symbol in this file - the function
86141 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
86142 ** All other code has file scope.
87649 ** defined in this file.
87742 /************** Begin file fkey.c ********************************************/
87753 ** This file contains code used by the compiler to add foreign key
88052 ** These operations are identified in the comment at the top of this file
88207 file
88963 /************** Begin file insert.c ******************************************/
88975 ** This file contains C code routines that are called by the parser
90013 ** thely may interfere with compilation of other functions in this file
90014 ** (or in another file, if this file becomes part of the amalgamation). */
90807 /************** Begin file legacy.c ******************************************/
90819 ** Main file for the SQLite library. The routines in this file
90954 /************** Begin file loadext.c *****************************************/
90966 ** This file contains code used to dynamically load extensions into
90974 /************** Begin file sqlite3ext.h **************************************/
90986 ** This header file defines the SQLite interface for use by
90989 ** as extensions by SQLite should #include this file instead of
91218 ** This header file is also used by the loadext.c source file
91787 ** Attempt to load an SQLite extension library contained in the file
92064 /************** Begin file pragma.c ******************************************/
92076 ** This file contains code used to implement the PRAGMA command.
92117 ** remainder of this file is specific to PRAGMA processing. So omit
92118 ** the rest of the file if PRAGMAs are omitted from the build.
92152 ** Interpret the given string as a temp db location. Return 1 for file
92159 }else if( sqlite3StrICmp(z, "file")==0 ){
92172 ** from default, or when 'file' and the temp_store_directory has changed
92415 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
92452 ** stored in the database file.
92551 ** maximum number of pages in the database file. The
92600 ** set on all attached databases, as well as the main db file.
92726 ** creates the database file. It is important that it is created
92733 ** file. Before writing to meta[6], check that meta[3] indicates
92808 ** PRAGMA temp_store = "default"|"memory"|"file"
92811 ** the local value does not make changes to the disk file and the default
92883 ** the value sets a specific file to be used for database access locks.
92913 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
92925 ** the local value does not make changes to the disk file and the
93060 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
93198 /* Do an integrity check on each database file */
93331 ** The second form of this pragma is a no-op if the main database file
93333 ** encoding that will be used for the main database file if a new file
93334 ** is created. If an existing main database file is opened, then the
93546 ** Report the current state of file logs for all databases
93638 /************** Begin file prepare.c *****************************************/
93650 ** This file contains the implementation of the sqlite3_prepare()
93765 ** data structures for a single database file. The index of the
93766 ** database file is given by iDb. iDb==0 is used for the main
93872 ** meta[1] File format of schema layer.
93939 sqlite3SetString(pzErrMsg, db, "unsupported file format");
93944 /* Ticket #2804: When we open a database in the newer file format,
94015 ** Initialize all database files - the main database file, the file
94022 ** file was of zero-length, then the DB_Empty flag is also set.
94129 ** which database file in db->aDb[] the schema refers to.
94502 /************** Begin file select.c ******************************************/
94514 ** This file contains C code routines that are called by the parser
99116 /************** Begin file table.c *******************************************/
99128 ** This file contains the sqlite3_get_table() and sqlite3_free_table()
99315 /************** Begin file trigger.c *****************************************/
99326 ** This file contains the implementation for TRIGGERs
100441 /************** Begin file update.c ******************************************/
100453 ** This file contains C code routines that are called by the parser
101010 ** thely may interfere with compilation of other functions in this file
101011 ** (or in another file, if this file becomes part of the amalgamation). */
101116 /************** Begin file vacuum.c ******************************************/
101128 ** This file contains code used to implement the VACUUM command.
101130 ** Most of the code in this file may be omitted by defining the
101247 ** can be set to 'off' for this file, as it is not recovered if a crash
101258 ** to write the journal header file.
101274 /* The call to execSql() to attach the temp database has left the file
101297 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
101440 ** database. No locks are held on any other files (since the main file
101443 ** vacuum database. The vacuum_db journal file is deleted when the pager
101464 /************** Begin file vtab.c ********************************************/
101476 ** This file contains code used to help implement virtual tables.
102533 /************** Begin file where.c *******************************************/
107790 /************** Begin file parse.c *******************************************/
107801 ** in the input grammar file. */
108676 static FILE *yyTraceFILE = 0;
108688 ** <li> A FILE* to which trace output should be written.
108698 SQLITE_PRIVATE void sqlite3ParserTrace(FILE *TraceFILE, char *zTracePrompt){
111262 /************** Begin file tokenize.c ****************************************/
111276 ** This file contains C code that splits an SQL input string up into
111322 ** The output of the mkkeywordhash.c program is written into a file
111323 ** named keywordhash.h and then included into this source file by
111327 /************** Begin file keywordhash.h *************************************/
111328 /***** This file contains automatically generated code ******
111330 ** The code in this file has been automatically generated by
111334 ** The code in this file implements a function that determines whether
112064 /************** Begin file complete.c ****************************************/
112078 ** This file contains C code that implements the sqlite3_complete() API.
112079 ** This code used to be part of the tokenizer.c source file. But by
112349 /************** Begin file main.c ********************************************/
112361 ** Main file for the SQLite library. The routines in this file
112369 /************** Begin file fts3.h ********************************************/
112382 ** This header file is used by programs that want to link against the
112401 /************** Begin file rtree.h *******************************************/
112414 ** This header file is used by programs that want to link against the
112433 /************** Begin file sqliteicu.h ***************************************/
112446 ** This header file is used by programs that want to link against the
113345 /* SQLITE_CANTOPEN */ "unable to open database file",
113353 /* SQLITE_NOLFS */ "large file support is disabled",
113357 /* SQLITE_NOTADB */ "file is encrypted or is not a database",
113809 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
113831 ** more frames in the log file. Passing zero or a negative value as the
113976 ** a temporary file for transient pager files and statement journals.
113984 ** 0 any file (return 0)
113985 ** 1 1 file (return 0)
113987 ** 1 0 file (return 0)
113988 ** 2 1 file (return 0)
114296 ** the VFS that should be used to open the database file. *pzFile is set to
114297 ** point to a buffer containing the name of the file to open. It is the
114324 && nUri>=5 && memcmp(zUri, "file:", 5)==0
114333 ** method that there may be extra parameters following the file-name. */
114361 ** 0: Parsing file-name.
114981 "cannot open file at line %d of [%.10s]",
115246 ** an incompatible database file format. Changing the PENDING byte
115350 ** the SQLITE_N_KEYWORD macro is not defined in this file if SQLite
115412 ** to see if a database file was a URI that contained a specific query
115492 /************** Begin file notify.c ******************************************/
115505 ** This file contains the implementation of the sqlite3_unlock_notify()
115509 /* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */
115825 /************** Begin file fts3.c ********************************************/
115842 ** The code in this file is only compiled if:
116117 /************** Begin file fts3Int.h *****************************************/
116155 /************** Begin file fts3_tokenizer.h **********************************/
116320 /************** Begin file fts3_hash.h ***************************************/
116332 ** This is the header file for the generic hash-table implemenation
119515 ** even if we reach end-of-file. The fts3EofMethod() will be called
120528 u8 *pbEof /* OUT: End-of-file flag */
121811 /************** Begin file fts3_aux.c ****************************************/
122287 /************** Begin file fts3_expr.c ***************************************/
123302 /************** Begin file fts3_hash.c ***************************************/
123320 ** The code in this file is only compiled if:
123686 /************** Begin file fts3_porter.c *************************************/
123703 ** The code in this file is only compiled if:
124333 /************** Begin file fts3_tokenizer.c **********************************/
124347 ** This particular file implements the generic tokenizer interface.
124351 ** The code in this file is only compiled if:
124712 ** in the README.tokenizer file as an example, so it is important to
124766 ** scalarFunc() in this file for details) and, if ENABLE_TABLE is
124823 /************** Begin file fts3_tokenizer1.c *********************************/
124840 ** The code in this file is only compiled if:
125058 /************** Begin file fts3_write.c **************************************/
125071 ** This file is part of the SQLite FTS3 extension module. Specifically,
125072 ** this file contains code to insert, update and delete rows from FTS3
125110 ** be overridden at runtime for testing purposes. File fts3_test.c contains
125154 ** this structure are only manipulated by code in this file, opaque handles
125240 ** database file as soon as they are completely populated. The interior of
126131 ** on the database file for longer than necessary). Thus, any virtual table
128505 ** modify the database file.
128611 /************** Begin file fts3_snippet.c ************************************/
129358 ** file system. This is done because the full-text index doclist is required
130115 /************** Begin file rtree.c *******************************************/
130127 ** This file contains code for implementations of the r-tree and r*-tree
130173 ** This file contains an implementation of a couple of different variants
130174 ** of the r-tree algorithm. See the README file for further details. The
133401 /************** Begin file icu.c *********************************************/
133415 ** This file implements an integration between the ICU library
133903 /************** Begin file fts3_icu.c ****************************************/
133915 ** This file implements a tokenizer for fts3 based on the ICU library.