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"
25543 ** If the file creation mode "m" is 0 then set it to the default for
25546 ** make the file creation mode be exactly m ignoring the umask.
25551 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
25576 ** vxworksFileId objects used by this file, all of which may be
25691 ** and a variety of "please close the file descriptor NOW" errors into
25694 ** Errors during initialization of locks, or file system support for locks,
25720 /* random NFS retry error, unless during file system support
25748 /* something went terribly awry, unless during file system support
25753 /* invalid fd, unless during file system support introspection, in which
25767 /* these should force the client to close the file and reconnect */
25777 ****************** Begin Unique File ID Utility Used By VxWorks ***************
25779 ** On most versions of unix, we can get a unique ID for a file by concatenating
25781 ** On VxWorks, a unique file id must be based on the canonical filename.
25784 ** unique file ID in VxWorks. Each instance of this structure contains
25844 ** Find a unique file ID for the given absolute pathname. Return
25846 ** file ID.
25855 struct vxworksFileId *pNew; /* search key and new file ID */
25856 struct vxworksFileId *pCandidate; /* For looping over existing file IDs */
25869 ** the existing file ID.
25883 /* No match was found. We will make a new file ID */
25910 /*************** End of Unique File ID Utility Used By VxWorks ****************
25922 ** file descriptor. Consider this test case:
25927 ** Suppose ./file1 and ./file2 are really the same file (because
25931 ** fail since there was already a lock on the file due to fd1.
25934 ** file descriptors opened on different file names.
25936 ** This means that we cannot use POSIX locks to synchronize file access
25941 ** To work around the problem, SQLite has to manage file locks internally
25943 ** specific inode of the database file (the inode is determined by the
25954 ** The sqlite3_file structure for POSIX is no longer just an integer file
25955 ** descriptor. It is now a structure that holds the integer file
25962 ** file is unlocked. cnt==-1 means the file has an exclusive lock.
25963 ** cnt>0 means there are cnt shared locks on the file.
25965 ** Any attempt to lock or unlock a file first checks the locking
25972 ** If you close a file descriptor that points to a file that has locks,
25973 ** all locks on that file that are owned by the current process are
25978 ** to close() the file descriptor is deferred until all of the locks clear.
25979 ** The unixInodeInfo structure keeps a list of file descriptors that need to
26000 ** per database file in the same process and (2) database connections
26011 struct vxworksFileId *pId; /* Unique file ID for vxworks. */
26022 ** A single inode can have multiple file descriptors, so each unixFile
26033 int nLock; /* Number of outstanding file locks */
26034 UnixUnusedFd *pUnused; /* Unused file descriptors to close */
26064 ** failed (e.g. "unlink", "open") and the the associated file-system path,
26071 const char *zPath, /* File path associated with error */
26122 ** Close a file descriptor.
26126 ** If it does fail, simply leak the file descriptor, but do log the
26130 ** file descriptor might have already been reused by another thread.
26142 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
26187 ** Given a file descriptor, locate the unixInodeInfo object that
26188 ** describes that file descriptor. Create a new one if necessary. The
26197 unixFile *pFile, /* Unix file with file desc used in the key */
26201 int fd; /* The file descriptor for pFile */
26203 struct stat statbuf; /* Low-level file information */
26208 /* Get low-level information about the file that we can used to
26209 ** create a unique name for the file.
26225 ** we always increase the file size to 1 by writing a single byte
26279 ** file by this or any other process. If such a lock is held, set *pResOut
26324 ** Attempt to set a system-lock on the file pFile. The lock is
26371 ** Lock the file with the lock specified by parameter eFileLock - one
26400 ** accessing the same database file, in case that is ever required.
26419 ** This property is used by the algorithm for rolling back a journal file
26558 ** assumed that there is a SHARED or greater lock on the file
26616 ** Add the file descriptor used by file handle pFile to the corresponding
26629 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
26632 ** If the locking level of the file descriptor is already at or below
26664 ** reading the database file again, make sure that the
26666 ** file changed. If the transaction counter is not updated,
26667 ** other connections to the same file might not realize that
26668 ** the file has changed and hence might not know to flush their
26782 /* Decrement the count of locks against this same file. When the
26783 ** count reaches zero, close any other file descriptors whose close
26800 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
26803 ** If the locking level of the file descriptor is already at or below
26811 ** This function performs the parts of the "close file" operation
26812 ** common to all locking schemes. It closes the directory and file
26843 ** Close a file.
26856 /* If there are outstanding locks, do not actually close the file just
26857 ** yet because that would clear those locks. Instead, add the file
26877 ** file for reading or writing.
26885 ** database connections are accessing the same database file at the same
26904 ** Close the file.
26914 ************************* Begin dot-file Locking ******************************
26936 ** The file suffix added to the data base filename in order to create the
26943 ** file by this or any other process. If such a lock is held, set *pResOut
26949 ** is held on the file and false if the file is unlocked.
26963 ** holds a lock on the file. No need to check further. */
26976 ** Lock the file with the lock specified by parameter eFileLock - one
27008 /* If we have any lock, then the lock file already exists. All we have
27013 /* Always update the timestamp on the old file */
27044 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27047 ** If the locking level of the file descriptor is already at or below
27050 ** When the locking level reaches NO_LOCK, delete the lock file.
27068 ** lock state. No need to mess with the file on disk.
27075 /* To fully unlock the database, delete the lock file */
27095 ** Close a file. Make sure the lock has been released before closing.
27107 /****************** End of the dot-file lock implementation *******************
27113 ** Use the flock() system call to do file locking.
27115 ** flock() locking is like dot-file locking in that the various
27143 ** file by this or any other process. If such a lock is held, set *pResOut
27201 ** Lock the file with the lock specified by parameter eFileLock - one
27224 ** access the file.
27267 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27270 ** If the locking level of the file descriptor is already at or below
27305 ** Close a file.
27326 ** the database file at a time. This reduces potential concurrency, but
27333 ** file by this or any other process. If such a lock is held, set *pResOut
27377 ** Lock the file with the lock specified by parameter eFileLock - one
27400 ** access the file.
27433 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27436 ** If the locking level of the file descriptor is already at or below
27474 ** Close a file.
27514 const char *dbPath; /* Name of the open file */
27524 int fd; /* file desc to assoc this lock with */
27536 const char *path, /* Name of the file to be locked or unlocked */
27537 unixFile *pFile, /* Open file descriptor on path */
27577 ** file by this or any other process. If such a lock is held, set *pResOut
27628 ** Lock the file with the lock specified by parameter eFileLock - one
27769 ** assumed that there is a SHARED or greater lock on the file
27827 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27830 ** If the locking level of the file descriptor is already at or below
27863 ** reading the database file again, make sure that the
27865 ** file changed. If the transaction counter is not updated,
27866 ** other connections to the same file might not realize that
27867 ** the file has changed and hence might not know to flush their
27934 ** Close a file & cleanup AFP specific locking context
27943 /* If there are outstanding locks, do not actually close the file just
27944 ** yet because that would clear those locks. Instead, add the file
27973 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
27976 ** If the locking level of the file descriptor is already at or below
28062 ** Read data from a file into a buffer. Return SQLITE_OK if all
28076 /* If this is a database file (not a journal, master-journal or temp
28077 ** file), the bytes in the locking range should never be read or written. */
28142 ** Write data from a buffer into a file. Return SQLITE_OK on success
28156 /* If this is a database file (not a journal, master-journal or temp
28157 ** file), the bytes in the locking range should never be read or written. */
28166 /* If we are doing a normal write to a database file (as opposed to
28167 ** doing a hot-journal rollback or a write to some file other than a
28168 ** normal database file) then record the fact that the database
28248 ** or power failure will likely corrupt the database file.
28250 ** SQLite sets the dataOnly flag if the size of the file is unchanged.
28251 ** The idea behind dataOnly is that it should only write the file content
28252 ** to disk, not the inode. We only set dataOnly if the file size is
28253 ** unchanged since the file size is part of the inode. However,
28255 ** file size has changed. The only real difference between fdatasync()
28258 ** We only care about the file size, not the other file attributes, so
28303 ** file system (on OSX), so failure indicates that FULLFSYNC
28304 ** isn't supported for this file system. So, attempt an fsync
28312 /* fdatasync() on HFS+ doesn't yet flush the file size if it changed correctly
28332 ** Open a file descriptor to the directory containing file zFilename.
28333 ** If successful, *pFd is set to the opened file descriptor and
28338 ** The directory file descriptor is used for only one thing - to
28339 ** fsync() a directory to make sure file creation and deletion events
28352 ** the file descriptor *pFd using close().
28376 ** Make sure all writes to a particular file are committed to disk.
28378 ** If dataOnly==0 then both the file itself and its metadata (file
28380 ** file data is synced.
28382 ** Under Unix, also make sure that the directory entry for the file
28383 ** has been created by fsync-ing the directory that contains the file.
28386 ** SQLite to access the file will not know that the journal exists (because
28416 /* Also fsync the directory containing the file if the DIRSYNC flag
28437 ** Truncate an open file to a specified size
28445 /* If the user has configured a chunk-size for this file, truncate the
28446 ** file so that it consists of an integer number of chunks (i.e. the
28447 ** actual file size after the operation may be larger than the requested
28460 /* If we are doing a normal write to a database file (as opposed to
28461 ** doing a hot-journal rollback or a write to some file other than a
28462 ** normal database file) and we truncate the file to zero length,
28477 ** Determine the current size of a file in bytes
28492 ** writes a single byte into that file in order to work around a bug
28494 ** layers, we need to report this file size as zero even though it is
28505 ** Handler for proxy-locking file-control verbs. Defined below in the
28513 ** file-control operation. Enlarge the database to nBytes in size
28519 i64 nSize; /* Required file size */
28538 ** ftruncate() to set the file size, then write a single byte to
28543 int nBlk = buf.st_blksize; /* File-system block size */
28580 ** Information and control of an open file handle.
28639 ** the specified file. This is almost always 512 bytes, but may be
28643 ** if two files are created in the same file-system directory (i.e.
28644 ** a database and its journal file) that the sector size will be the
28653 ** Return the device characteristics for the file.
28657 ** file system does not always provide powersafe overwrites. (In other
28658 ** words, after a power-loss event, parts of the file that were never
28662 ** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control
28687 ** every open file that does not use shared memory (in other words, most
28709 char *zFilename; /* Name of the mmapped file */
28710 int h; /* Open file descriptor */
28858 ** Open a shared-memory area associated with open database file pDbFd.
28861 ** The file used to implement shared-memory is in the same directory
28862 ** as the open database file and has the same name as the open database
28863 ** file with the "-shm" suffix added. For example, if the database file
28864 ** is "/home/user1/config.db" then the file that is created and mmapped
28868 ** some other tmpfs mount. But if a file in a different directory
28869 ** from the database file is used, then differing access permissions
28873 ** in database corruption. Nevertheless, this tmpfs file usage
28878 ** same database file at the same time, database corruption will likely
28882 ** When opening a new shared-memory file, if no other instances of that
28883 ** file are currently open, in this process or in other processes, then
28884 ** the file must be truncated to zero length or have its header cleared.
28886 ** If the original database file (pDbFd) is using the "unix-excl" VFS
28887 ** that means that an exclusive lock is held on the database file and
28890 ** file is created. The shared memory will be simulated with heap memory.
28894 struct unixShmNode *pShmNode; /* The underlying mmapped file */
28897 char *zShmFilename; /* Name of the file used for SHM */
28913 struct stat sStat; /* fstat() info for database file */
28915 /* Call fstat() to figure out the permissions on the database file. If
28916 ** a new *-shm file is created, an attempt will be made to create it
28965 /* If this process is running as root, make sure that the SHM file
28977 ** If not, truncate the file to zero length.
29024 ** shared-memory associated with the database file fd. Shared-memory regions
29042 sqlite3_file *fd, /* Handle open on database file */
29045 int bExtend, /* True to extend file if necessary */
29053 /* If the shared-memory file has not yet been opened, open it now. */
29069 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
29076 ** Check to see if it has been allocated (i.e. if the wal-index file is
29153 sqlite3_file *fd, /* Database file holding the shared memory */
29161 unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
29265 sqlite3_file *fd /* Database file holding the shared memory */
29280 sqlite3_file *fd, /* The underlying database file */
29284 unixShmNode *pShmNode; /* The underlying shared-memory file */
29286 unixFile *pDbFd; /* The underlying database file */
29308 ** shared-memory file, too */
29337 ** implement various file locking strategies. It also contains definitions
29339 ** sqlite3_io_methods object for a particular database file. The pAppData
29467 ** opens secondary file descriptors for the conch and lock files and
29468 ** it uses proxy, dot-file, AFP, and flock() locking methods on those
29470 ** proxy locking is located much further down in the file. But we need
29506 ** for the database file "filePath". It then returns the sqlite3_io_methods
29512 const char *filePath, /* name of the database file */
29513 unixFile *pNew /* open file object for the database file */
29531 /* If filePath==NULL that means we are dealing with a transient file
29548 ** assume that the file-system supports POSIX style locks.
29572 ** for the database file "filePath". It then returns the sqlite3_io_methods
29578 const char *filePath, /* name of the database file */
29579 unixFile *pNew /* the open file object */
29584 /* If filePath==NULL that means we are dealing with a transient file
29625 int h, /* Open file descriptor of file being opened */
29627 const char *zFilename, /* Name of the file being opened */
29637 ** exception is when opening the proxy "conch" file in builds that
29678 ** zFilename remains valid until file is closed, to support */
29691 /* If an error occured in findInodeInfo(), close the file descriptor
29699 ** file descriptors open on the same file. If there were other file
29700 ** descriptors on this file, then no malloc would be required by
29717 /* AFP locking uses the file path so it needs to be included in
29725 /* NB: zFilename exists and remains valid until the file is closed
29744 /* Dotfile locking uses the file path so it needs to be included in
29762 /* Named semaphore locking uses the file path so it needs to be
29805 ** If no suitable temporary file directory can be found, return NULL.
29833 ** Create a temporary file name in zBuf. zBuf must be allocated
29854 /* Check that the output buffer is large enough for the temporary file
29884 ** Search for an unused file descriptor that was opened on the database
29885 ** file (not a journal or master-journal file) identified by pathname
29889 ** Such a file descriptor may exist if a database connection was closed
29890 ** but the associated file descriptor could not be closed because some
29891 ** other file descriptor open on the same file is holding a file-lock.
29893 ** describing "Posix Advisory Locking" at the start of this file for
29896 ** If a suitable file descriptor is found, then it is returned. If no
29897 ** such file descriptor is located, -1 is returned.
29902 /* Do not search for an unused file descriptor on vxworks. Not because
29913 ** ignored and -1 is returned. The caller will try to open a new file
29917 ** not searching for a resusable file descriptor are not dire. */
29949 ** an indication to robust_open() to create the file using
29951 ** But if the file being opened is a WAL or regular journal file, then
29952 ** this function queries the file-system for the permissions on the
29953 ** corresponding database file and sets *pMode to this value. Whenever
29955 ** as the associated database file.
29963 const char *zPath, /* Path of file (possibly) being created */
29965 mode_t *pMode, /* OUT: Permissions to open file with */
29966 uid_t *pUid, /* OUT: uid to set on the file */
29967 gid_t *pGid /* OUT: gid to set on the file */
29974 char zDb[MAX_PATHNAME+1]; /* Database file path */
29976 struct stat sStat; /* Output of stat() on database file */
29978 /* zPath is a path to a WAL or journal file. The following block derives
29979 ** the path to the associated database file from zPath. This block handles
30018 ** Open the file zPath.
30034 ** true, the file was configured to be automatically deleted when the
30035 ** file handle closed. To achieve the same effect using this new
30041 const char *zPath, /* Pathname of file to be opened */
30042 sqlite3_file *pFile, /* The file descriptor to be filled in */
30047 int fd = -1; /* File descriptor returned by open() */
30049 int eType = flags&0xFFFFFF00; /* Type of file to open */
30066 /* If creating a master or main-file journal, this function will open
30067 ** a file-descriptor on the directory too. The first time unixSync()
30068 ** is called the directory file descriptor will be fsync()ed and close()d.
30077 ** a temporary file. Use this buffer to store the file name in.
30094 /* The main DB, main journal, WAL file and master journal are never
30101 /* Assert that the upper layer has set one of the "file-type" flags. */
30129 /* If zName is NULL, the upper layer is requesting a temp file. */
30144 ** they may be stored as part of the file handle and used by the
30145 ** 'conch file' locking functions later on. */
30153 mode_t openMode; /* Permissions to create file with */
30154 uid_t uid; /* Userid for the file */
30155 gid_t gid; /* Groupid for the file */
30165 /* Failed to open the file for read/write access. Try read-only. */
30179 ** journal or WAL file, set the ownership of the journal or WAL to be
30251 /* In theory, the close(fd) call is sub-optimal. If the file opened
30252 ** with fd is a database file, and there are other connections open
30253 ** on that file that are currently holding advisory locks on it,
30256 ** not while other file descriptors opened by the same process on
30257 ** the same file are working. */
30294 ** Delete the file at zPath. If the dirSync argument is true, fsync()
30295 ** the directory after deleting the file.
30299 const char *zPath, /* Name of file to be deleted */
30300 int dirSync /* If true, fsync() directory after deleting file */
30331 ** Test the existance of or access permissions of file zPath. The
30334 ** SQLITE_ACCESS_EXISTS: Return 1 if the file exists
30335 ** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
30336 ** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
30342 const char *zPath, /* Path of the file to examine */
30343 int flags, /* What do we want to learn about the zPath file? */
30636 ** until late in the file (here) after all of the other I/O methods have
30643 ** database file to coordinate safe, concurrent access by multiple readers
30644 ** and writers [http://sqlite.org/lockingv3.html]. The five file locking
30657 ** This works well on the local file system, but shows a nearly 100x
30661 ** supported network file systems. NFS and AFP both observe the
30668 ** To address the performance and cache coherency issues, proxy file locking
30670 ** single host at a time and moving file locks off of the database file
30671 ** and onto a proxy file on the local file system.
30689 ** Specifying ":auto:" means that if there is a conch file with a matching
30690 ** host ID in it, the proxy path in the conch file will be used, otherwise
30693 ** actual proxy file name is generated from the name and path of the
30694 ** database file. For example:
30701 ** the above APIs (assuming the conch file is not being held by another
30708 ** Proxy file locking relies primarily on two new supporting files:
30710 ** * conch file to limit access to the database file to a single host
30713 ** * proxy file to act as a proxy for the advisory locks normally
30716 ** The conch file - to use a proxy file, sqlite must first "hold the conch"
30717 ** by taking an sqlite-style shared lock on the conch file, reading the
30719 ** proxy path against the values stored in the conch. The conch file is
30720 ** stored in the same directory as the database file and the file name
30721 ** is patterned after the database file name as ".<databasename>-conch".
30722 ** If the conch file does not exist, or it's contents do not match the
30724 ** lock and the conch file contents is updated with the host ID and proxy
30729 ** The proxy file - a single-byte file used for all advisory file locks
30730 ** normally taken on the database file. This allows for safe sharing
30731 ** of the database file for multiple readers and writers on the same
30732 ** host (the conch ensures that they all use the same local lock file).
30735 ** only taken when the first request to lock database file is made.
30737 ** opening a connection to a database file does not take a lock on it.
30738 ** The shared lock and an open file descriptor are maintained until
30741 ** The proxy file and the lock file are never deleted so they only need
30749 ** Database files accessed on non-local file systems are
30756 ** Enables the logging of error messages during host id file
30772 ** force proxy locking to be used for every database file opened, and 0
30784 ** The proxyLockingContext has the path and file structures for the remote
30789 unixFile *conchFile; /* Open conch file */
30790 char *conchFilePath; /* Name of the conch file */
30791 unixFile *lockProxy; /* Open proxy lock file */
30792 char *lockProxyPath; /* Name of the proxy lock file */
30793 char *dbPath; /* Name of the open file */
30800 ** The proxy lock file path for the database at dbPath is written into lPath,
30802 ** file path.
30843 ** Creates the lock file and any missing directories in lockPath
30879 ** Create a new VFS file descriptor (stored in memory obtained from
30880 ** sqlite3_malloc) and open the file named "path" in the file descriptor.
30882 ** The caller is responsible not only for closing the file descriptor
30883 ** but also for freeing the memory associated with the file descriptor.
30898 /* 1. first try to open/create the file
30899 ** 2. if that fails, and this is a lock file (not-conch), try creating
30901 ** 3. if that fails, try to open the file read-only
30902 ** otherwise return BUSY (if lock file) or CANTOPEN for the conch file
30968 /* simulate multiple hosts by creating unique hostid file paths */
30972 #define PROXY_HOSTIDLEN 16 /* conch file host id length */
30999 /* simulate multiple hosts by creating unique hostid file paths */
31008 /* The conch file contains the header, host id and lock file path
31011 #define PROXY_HEADERLEN 1 /* conch file header length */
31016 ** Takes an open conch file, copies the contents to a new path and then moves
31017 ** it back. The newly created file's file descriptor is assigned to the
31018 ** conch file structure and finally the original conch file descriptor is
31047 /* write it out to the temporary break file */
31078 /* Take the requested lock on the conch file
31154 ** lockPath is non-NULL, the host ID and lock file path must match. A NULL
31155 ** lockPath means that the lockPath in the conch file will be used if the
31157 ** and written to the conch file.
31190 /* read the existing conch file */
31200 ** conch file.
31208 do { /* in case we need to try again for an :auto: named lock file */
31215 /* for auto-named local lock file, just check the host ID and we'll
31216 ** use the local lock file path that's already in there
31284 /* If we created a new conch file (not just updated the contents of a
31285 ** valid conch file), try to match the permissions of the database
31293 /* try to match the database file R/W permissions, ignore failure */
31338 /* we couldn't create the proxy lock file with the old lock file path
31348 ** from the conch file or the path was allocated on the stack
31371 } while (1); /* in case we need to retry the :auto: lock file -
31377 ** If pFile holds a lock on a conch file, then release that lock.
31382 unixFile *conchFile; /* Name of the conch file */
31399 ** Given the name of a database file, compute the name of its conch file.
31415 ** the name of the original database file. */
31435 /* append the "-conch" suffix to the file */
31443 /* Takes a fully configured proxy locking-style unix file and switches
31444 ** the local lock file path
31476 ** pFile is a file that has been opened by a prior xOpen call. dbPath
31493 ** file path */
31497 /* all other styles use the locking context to store the db file path */
31505 ** Takes an already filled in unix file and alters it so all file locking
31506 ** will be performed on the local proxy lock file. The following fields
31514 char dbPath[MAXPATHLEN+1]; /* Name of the database file */
31542 ** (c) the file system is read-only, then enable no-locking access.
31642 /* turn on proxy file locking */
31665 ** file by this or any other process. If such a lock is held, set *pResOut
31685 ** Lock the file with the lock specified by parameter eFileLock - one
31726 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
31729 ** If the locking level of the file descriptor is already at or below
31749 ** Close a file that uses proxy locks.
31805 ** should be the only routines in this file that are visible from other
31831 ** database file and tries to choose an locking method appropriate for
31917 /************** Begin file os_win.c ******************************************/
31930 ** This file contains code that is specific to Windows.
31932 #if SQLITE_OS_WIN /* This file is used for Windows only */
31942 /************** Begin file os_common.h ***************************************/
31955 ** This file contains macros and a little bit of code that is common to
31959 ** This file should be #included by the os_*.c files only. It is not a
31960 ** general purpose header file.
31995 /************** Begin file hwtime.h ******************************************/
32008 ** This file contains inline asm code for retrieving "high-performance"
32163 ** WinCE lacks native support for file locking so we have to fake it
32182 sqlite3_vfs *pVfs; /* The VFS used to open this file */
32183 HANDLE h; /* Handle for accessing the file */
32184 u8 locktype; /* Type of lock currently held on this file */
32188 winShm *pShm; /* Instance of shared memory on this file */
32189 const char *zPath; /* Full pathname of this file */
32192 LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
32196 winceLock *shared; /* Global shared lock memory for the file */
33007 ** sqlite3GlobalConfig.m with pointers to the routines in this file. The
33085 ** current codepage settings for file apis.
33259 ** failed and the the associated file-system path, if any.
33266 const char *zPath, /* File path associated with error */
33387 ** Create the mutex and shared memory used for locking in the file
33423 /* Since the names of named mutexes, semaphores, file mappings etc are
33672 ** Move the current position of the file handle passed as the first
33673 ** argument to offset iOffset within the file. If successful, return 0.
33686 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
33706 ** Close a file.
33750 ** Read data from a file into a buffer. Return SQLITE_OK if all
33755 sqlite3_file *id, /* File to read from */
33760 winFile *pFile = (winFile*)id; /* file handle */
33761 DWORD nRead; /* Number of bytes actually read from file */
33789 ** Write data from a buffer into a file. Return SQLITE_OK on success
33793 sqlite3_file *id, /* File to write into */
33796 sqlite3_int64 offset /* Offset into the file to begin writing at */
33799 winFile *pFile = (winFile*)id; /* File handle */
33845 ** Truncate an open file to a specified size
33848 winFile *pFile = (winFile*)id; /* File handle object */
33856 /* If the user has configured a chunk-size for this file, truncate the
33857 ** file so that it consists of an integer number of chunks (i.e. the
33858 ** actual file size after the operation may be larger than the requested
33889 ** Make sure all writes to a particular file are committed to disk.
33950 ** Determine the current size of a file in bytes
34034 ** Lock the file with the lock specified by parameter locktype - one
34165 /* Update the state of the lock has held in the file descriptor then
34182 ** file by this or any other process. If such a lock is held, return
34208 ** Lower the locking level on file descriptor id to locktype. locktype
34211 ** If the locking level of the file descriptor is already at or below
34266 ** Control and query of the open file handle.
34331 ** the specified file. This is almost always 512 bytes, but may be
34335 ** if two files are created in the same file-system directory (i.e.
34336 ** a database and its journal file) that the sector size will be the
34356 ** Windows will only let you create file view mappings
34366 ** this file, all of which may be shared by multiple threads.
34389 ** Object used to represent a single file opened and mmapped to provide
34413 char *zFilename; /* Name of the file */
34414 winFile hFile; /* File handle from winOpen */
34419 HANDLE hMap; /* File handle from CreateFileMapping */
34570 ** Open the shared-memory area associated with database file pDbFd.
34572 ** When opening a new shared-memory file, if no other instances of that
34573 ** file are currently open, in this process or in other processes, then
34574 ** the file must be truncated to zero length or have its header cleared.
34578 struct winShmNode *pShmNode = 0; /* The underlying mmapped file */
34628 pShmNode->zFilename, /* Name of the file (UTF-8) */
34629 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
34637 ** If not, truncate the file to zero length.
34695 winShmNode *pShmNode; /* The underlying shared-memory file */
34715 ** shared-memory file, too */
34731 sqlite3_file *fd, /* Database file holding the shared memory */
34850 ** shared-memory associated with the database file fd. Shared-memory regions
34868 sqlite3_file *fd, /* Handle open on database file */
34871 int isWrite, /* True to extend file if necessary */
34891 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
34892 sqlite3_int64 sz; /* Current size of wal-index file */
34897 ** Check to see if it has been allocated (i.e. if the wal-index file is
34934 HANDLE hMap; /* file-mapping handle */
35046 ** Create a temporary file name in zBuf. zBuf must be big enough to
35095 /* Check that the output buffer is large enough for the temporary file
35120 ** Open a file.
35124 const char *zName, /* Name of the file (UTF-8) */
35125 sqlite3_file *id, /* Write the SQLite file handle here */
35144 ** a temporary file. Use this buffer to store the file name in.
35150 int eType = flags&0xFFFFFF00; /* Type of file to open */
35181 /* The main DB, main journal, WAL file and master journal are never
35188 /* Assert that the upper layer has set one of the "file-type" flags. */
35201 ** temporary file name to use
35231 /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
35236 /* Creates a new file, only if it does not already exist. */
35237 /* If the file exists, it fails. */
35240 /* Open existing file, or create if it doesn't exist */
35243 /* Opens a file, only if it exists. */
35349 ** Delete the named file.
35351 ** Note that Windows does not allow a file to be deleted if some other
35353 ** will open a journal file shortly after it is created in order to do
35355 ** file open, we will be unable to delete it. To work around this
35362 const char *zFilename, /* Name of file to delete */
35406 ** Check the existance and status of a file.
35410 const char *zFilename, /* Name of file to check */
35411 int flags, /* Type of test to make on this file */
35433 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
35824 /************** Begin file bitvec.c ******************************************/
35836 ** This file implements an object that represents a fixed-length
35839 ** A bitmap is used to record which pages of a database file have been
35857 ** Bitvec object is the number of pages in the database file at the
36234 /************** Begin file pcache.c ******************************************/
36246 ** This file implements that page cache.
36855 /************** Begin file pcache1.c *****************************************/
36868 ** This file implements the default page cache implementation (the
36913 ** open database file (including each in-memory database and each
36995 ** All code in this file should access the global structure above via the
37040 ** Malloc function used within this file to allocate space from the buffer
37875 /************** Begin file rowset.c ******************************************/
38299 /************** Begin file pager.c *******************************************/
38313 ** The pager is used to access a database disk file. It implements
38314 file that
38315 ** is separate from the database file. The pager also implements file
38317 ** file simultaneously, or one process from reading the database while
38322 /************** Begin file wal.h *********************************************/
38334 ** This header file defines the interface to the write-ahead logging
38372 /* Connection to a write-ahead log (WAL) file.
38381 /* Set the limiting size of a WAL file. */
38418 /* Copy pages from the log to the database file */
38424 int sync_flags, /* Flags to sync db file with (or 0) */
38439 ** by the pager layer on the database file.
38450 /* If the WAL file is not empty, return the number of bytes of content
38472 ** is called successfully on the file containing the page.
38474 ** Definition: A page of the database file is said to be "overwriteable" if
38484 ** the database file at the start of the transaction.
38486 ** (1) A page of the database file is never overwritten unless one of the
38500 ** (3) Writes to the database file are an integer multiple of the page size
38503 ** (4) Reads from the database file are either aligned on a page boundary and
38505 ** first 100 bytes of the database file.
38507 ** (5) All writes to the database file are synced prior to the rollback journal
38510 ** (6) If a master journal file is used, then all writes to the database file
38521 ** journal is rolled back, the resulting database file will be logical
38522 ** equivalent to the database file at the beginning of the transaction.
38525 ** is called to restore the database file to the same size it was at
38530 ** (9) Whenever the database file is modified, at least one bit in the range
38538 ** (11) A database file is well-formed at the beginning and at the conclusion
38541 ** (12) An EXCLUSIVE lock is held on the database file when writing to
38542 ** the database file.
38544 ** (13) A SHARED lock is held on the database file while reading any
38545 ** content out of the database file.
38562 ** to print out file-descriptors.
38565 ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
38612 ** state - the file may or may not be locked and the database size is
38616 ** * Any lock, or no lock at all, may be held on the database file.
38635 ** * A SHARED or greater lock is held on the database file.
38641 ** there is no hot-journal in the file-system.
38651 ** BEGIN EXCLUSIVE) EXCLUSIVE lock is obtained on the database file when
38652 ** moving to this state, but the journal file is not written to or opened
38655 ** file.
38657 ** IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
38659 ** is made to obtain an EXCLUSIVE lock on the database file.
38663 ** lock is held on the database file.
38669 ** * The journal file may or may not be open.
38675 ** first modified by the upper layer. In rollback mode the journal file
38677 ** start of it. The database file on disk has not been modified.
38680 ** * A RESERVED or greater lock is held on the database file.
38681 ** * The journal file is open and the first header has been written
38688 ** when it modifies the contents of the database file. WAL connections
38689 ** never enter this state (since they do not modify the database file,
38690 ** just the log file).
38693 ** * An EXCLUSIVE or greater lock is held on the database file.
38694 ** * The journal file is open and the first header has been written
38705 ** database file. In this state the transaction may be committed simply
38706 ** by finalizing the journal file. Once in WRITER_FINISHED state, it is
38711 ** * An EXCLUSIVE or greater lock is held on the database file.
38722 ** db size etc.) are consistent with the contents of the file-system.
38733 ** file. To avoid this hazard, the pager switches into the ERROR state
38751 ** 2. An error occurs while attempting to finalize a journal file
38755 ** database file in function pagerStress() in order to free up
38799 ** the database file: NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
38807 ** when unlocking the file, and only updated when locking the file if the
38816 ** The exception is when the database file is unlocked as the pager moves
38817 ** from ERROR to OPEN state. At this point there may be a hot-journal file
38818 ** in the file-system that needs to be rolled back (as part of a OPEN->SHARED
38838 ** lock on the database file before attempting to roll it back. See function
38886 Pgno nOrig; /* Original number of pages in file */
38904 ** For a real on-disk database, the current lock held on the database file -
38920 ** (the 4-byte header field at byte offset 24 of the database file) is
38924 ** can only happen if an exclusive lock is held on the database file.
38926 ** relinquished on the database file. Each time a transaction is committed,
38938 ** journal file before it is synced to disk.
38940 ** Whether or not a journal file contains a master-journal pointer affects
38941 ** the way in which the journal file is finalized after the transaction is
38943 ** If a journal file does not contain a master-journal pointer, it is
38945 ** it does contain a master-journal pointer the journal file is finalized
38952 ** subsequently interrupted transaction that reuses the journal file.
38954 ** The flag is cleared as soon as the journal file is finalized (either
38956 ** journal file from being successfully finalized, the setMaster flag
38963 ** write cached data to the file-system in order to free up memory).
38968 ** to allocate a new page to prevent the journal file from being written
38972 ** is permitted, but syncing the journal file is not. This flag is set
38973 ** by sqlite3PagerWrite() when the file-system sector-size is larger than
38980 ** is opened as an in-memory journal file. If false, then in-memory
38988 ** Variable dbSize is set to the number of pages in the database file.
38992 ** dbSize is set based on the size of the database file, which may be
38994 ** 28 of the database header by the btree). If the size of the file
38996 ** dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
38997 ** Except, any file that is greater than 0 bytes in size is considered
38998 ** to have at least one page. (i.e. a 1KB file with 2K page-size leads
39013 ** the file on disk in pages. It is set to a copy of dbSize when the
39015 ** to write or truncate the database file on disk.
39020 ** that the database file is larger than the database image (Pager.dbSize),
39022 ** to measure the database file
39026 ** pager_truncate() may cause the file to become smaller or larger.
39051 u8 useJournal; /* Use a rollback journal on this file */
39057 u8 tempFile; /* zFilename is a temporary file */
39059 u8 memDb; /* True to inhibit all file I/O */
39071 u8 eLock; /* Current lock held on database file */
39079 Pgno dbFileSize; /* Number of pages in the database file */
39085 Bitvec *pInJournal; /* One bit for each page in the database file */
39086 sqlite3_file *fd; /* File descriptor for database */
39087 sqlite3_file *jfd; /* File descriptor for main journal */
39088 sqlite3_file *sjfd; /* File descriptor for sub-journal */
39089 i64 journalOff; /* Current write offset in the journal file */
39094 char dbFileVers[16]; /* Changes whenever database file changes */
39106 char *zFilename; /* Name of the database file */
39107 char *zJournal; /* Name of the journal file */
39125 char *zWal; /* File name for write-ahead log */
39152 ** file after power is restored. If an attempt is then made
39161 ** journal file right after the header. The random initializer is important,
39164 ** garbage data came from an obsolete journal file, the checksums might
39202 ** The argument to this macro is a file descriptor (type sqlite3_file*).
39253 /* Regardless of the current state, a temp-file connection always behaves
39254 ** as if it has an exclusive lock on the database file. It never updates
39261 ** And if the journal-mode is "OFF", the journal file must not be open.
39269 ** a journal file. (although the in-memory journal implementation may
39270 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
39284 ** on the file.
39319 ** journal file nor the WAL file are open. This happens during
39443 ** Return true if the page is already in the journal file.
39450 ** Read a 32-bit integer from the given file descriptor. Store the integer
39472 ** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK
39482 ** Unlock the database file to level eLock, which must be either NO_LOCK
39508 ** Lock the database file to level eLock, which must be either SHARED_LOCK,
39545 ** then the value returned is the size of the journal file when it
39616 ** When this is called the journal file for pager pPager must be open.
39617 ** This function attempts to read a master journal file name from the
39618 ** end of the file and, if successful, copies it into memory supplied
39620 ** used to store a master journal file name at the end of a journal file.
39629 ** If a master journal file name is present at the end of the journal
39630 ** file, then it is copied into the buffer pointed to by zMaster. A
39632 ** journal file name.
39634 ** If it is determined that no master journal file name is present
39637 ** If an error occurs while reading from the journal file, an SQLite
39643 i64 szJ; /* Total size in bytes of journal file pJrnl */
39706 ** The journal file must be open when this function is called.
39708 ** This function is a no-op if the journal file has not been written to
39712 ** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
39713 ** zero the 28-byte header at the start of the journal file. In either case,
39714 ** if the pager is not in no-sync mode, sync the journal file immediately
39719 ** journal file in bytes is larger than this value, then truncate the
39720 ** journal file to Pager.journalSizeLimit bytes. The journal file does
39744 ** is still held on the file. If there is a size limit configured for
39745 ** the persistent journal and the journal file currently consumes more
39747 ** to sync the file following this operation.
39761 ** The journal file must be open when this routine is called. A journal
39762 ** header (JOURNAL_HDR_SZ bytes) is written into the journal file at the
39782 assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
39809 ** rest of the journal file contains valid page records. This assumption
39811 ** file it may contain some garbage data. There are two scenarios
39818 ** that garbage data is never appended to the journal file.
39850 ** journal header consumes to the journal file here. Then increment the
39852 ** record is written to the following sector (leaving a gap in the file
39856 ** be significantly slower than contiguously writing data to the file,
39877 ** The journal file must be open when this is called. A journal header file
39879 ** file. The current location in the journal file is given by
39889 ** If the journal header file appears to be corrupted, SQLITE_DONE is
39891 ** cannot be read from the journal file an error code is returned.
39896 i64 journalSize, /* Size of the open journal file in bytes */
39904 assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
39907 ** journal file is too small for there to be a header stored at this
39973 ** the journal file here.
40000 ** Write the supplied master journal name into the journal file for pager
40002 ** thing written to a journal file. If the pager is in full-sync mode, the
40003 ** journal file descriptor is advanced to the next sector boundary before
40021 i64 iHdrOff; /* Offset of header in journal file */
40022 i64 jrnlSize; /* Size of journal file on disk */
40052 /* Write the master journal data to the end of the journal file. If
40066 ** journal-file may extend past the end of the master-journal name
40067 ** and 8 bytes of magic data just written to the file. This is
40068 ** dangerous because the code to rollback a hot-journal file
40073 ** file to the required size.
40150 ** If the pager is not in exclusive-access mode, the database file is
40151 ** completely unlocked. If the file is unlocked and the file-system does
40152 ** not exhibit the UNDELETABLE_WHEN_OPEN property, the journal file is
40158 ** or not, any journal file left in the file-system will be treated
40182 ** close the journal file when dropping the database lock. Otherwise
40183 ** another connection with journal_mode=delete might delete the file
40199 ** file fails, set the current lock to UNKNOWN_LOCK. See the comment
40251 ** to be replayed to restore the contents of the database file (as if
40273 ** the journal file or writing the very first journal-header of a
40282 ** If the journal file is open, then it is "finalized". Once a journal
40283 ** file has been finalized it is not possible to use it to roll back a
40290 ** Journal file descriptor is simply closed. This destroys an
40294 ** Journal file is truncated to zero bytes in size.
40297 ** The first 28 bytes of the journal file are zeroed. This invalidates
40298 ** the first journal header in the file, and hence the entire journal
40299 ** file. An invalid journal file cannot be rolled back.
40302 ** The journal file is closed and deleted using sqlite3OsDelete().
40305 ** the journal file is never used. Instead, if the journalMode is
40310 ** If running in non-exclusive rollback mode, the lock on the file is
40314 ** any of the IO operations to finalize the journal file or unlock the
40316 ** operation to finalize the journal file fails, then the code still
40317 ** tries to unlock the database file if not in exclusive mode. If the
40324 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
40350 /* Finalize the journal file. */
40369 ** file should be closed and deleted. If this connection writes to
40370 ** the database file, it will do so using an in-memory journal.
40403 ** lock held on the database file.
40422 ** database file.
40427 ** the database file and move the pager back to OPEN state. If this
40428 ** means that there is a hot-journal left in the file-system, the next
40463 ** incompatible journal file format.
40497 ** Read a single page from either the journal file (if isMainJrnl==1) or
40499 ** The page begins at offset *pOffset into the file. The *pOffset
40505 ** If the page number of the page record read from the (sub-)journal file
40515 ** If the page record is successfully read from the (sub-)journal file
40517 ** while reading the record from the (sub-)journal file or while writing
40518 ** to the database file, then the IO error code is returned. If data
40519 ** is successfully read from the (sub-)journal file but appears to be
40524 ** * If the record is being rolled back from the main journal file
40545 sqlite3_file *jfd; /* The file descriptor for the journal file */
40569 ** file. Return an error code to the caller if an IO error occurs.
40614 ** not the database file. The page is left marked dirty in this case.
40624 ** pager cache if it exists and the main file. The page is then marked
40636 ** database file without an entry in the rollback journal that can
40643 ** 2008-04-14: When attempting to vacuum a corrupt database file, it
40645 ** Do not attempt to write if database file has never been opened.
40683 ** will be read from the database file, which may or may not be
40719 ** journal file, then its content must be as they were when the
40726 ** unsynced portion of the main journal file, then it is not safe
40729 ** already in the journal file (recorded in Pager.pInJournal) and
40733 ** be written out into the database file before its journal file
40756 ** Parameter zMaster is the name of a master journal file. A single journal
40757 ** file that referred to the master journal file has just been rolled back.
40758 ** This routine checks if it is possible to delete the master journal file,
40764 ** When a master journal file is created, it is populated with the names
40766 ** encoded text. The end of each child journal file is marked with a
40768 ** file for a transaction involving two databases might be:
40772 ** A master journal file may only be deleted once all of its child
40775 ** This function reads the contents of the master-journal file into
40781 ** file zMaster
40785 ** no such child journal can be found, file zMaster is deleted from
40786 ** the file-system using sqlite3OsDelete().
40794 ** the entire contents of the master journal file. This could be
40801 sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
40802 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
40803 char *zMasterJournal = 0; /* Contents of master journal file */
40804 i64 nMasterJournal; /* Size of master journal file */
40805 char *zJournal; /* Pointer to one journal within MJ file */
40806 char *zMasterPtr; /* Space to hold MJ filename from a journal file */
40809 /* Allocate space for both the pJournal and pMaster file descriptors.
40810 ** If successful, open the master journal file for reading.
40822 /* Load the entire master journal file into space obtained from
40850 ** so, return without deleting the master journal file.
40867 /* We have a match. Do not delete the master journal file. */
40890 ** file in the file-system. This only happens when committing a transaction,
40893 ** If the main database file is not open, or the pager is not in either
40895 ** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
40896 ** If the file on disk is currently larger than nPage pages, then use the VFS
40899 ** Or, it might might be the case that the file on disk is smaller than
40901 ** you try to truncate a file to some size that is larger than it
40903 ** the end of the new file instead.
40906 ** the database file, return the error code to the caller.
40943 ** of the open database file. The sector size will be used used
40954 ** If the file has the SQLITE_IOCAP_POWERSAFE_OVERWRITE property, then set
40960 ** size. For backwards compatibility of the rollback journal file format,
40970 /* Sector size doesn't matter for temporary files. Also, the file
40987 ** Playback the journal and thus restore the database file to
40990 ** The journal file format is as follows:
41014 ** value of nRec from the size of the journal file. But if a power
41016 ** case that the size of the journal file had already been increased but
41018 ** the value of nRec computed from the file size would be too large. For
41022 ** from the file size. This value is used when the user selects the
41027 ** If the file opened as the journal file is not a well-formed
41028 ** journal file then all pages up to the first corrupted page are rolled
41029 ** back (or no pages if the journal header is corrupted). The journal file
41033 ** If an I/O or malloc() error occurs, the journal-file is not deleted
41045 i64 szJ; /* Size of the journal file in bytes */
41048 Pgno mxPg = 0; /* Size of the original file in pages */
41051 char *zMaster = 0; /* Name of master journal file if any */
41064 ** If a master journal filefile is not
41091 /* Read the next journal header from the journal file. If there are
41092 ** not enough bytes left in the journal file for a complete header, or
41106 ** file consists of pages, there are no more journal headers. Compute
41118 ** size of the file.
41126 ** should be computed based on the journal file size.
41134 ** database file back to its original size.
41145 ** database file and/or page cache.
41180 /* Following a rollback, the database file should be back in its original
41182 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
41234 ** Read the content for page pPg out of the database file and into
41236 ** file before this function is called.
41239 ** the value read from the database file.
41248 int isInWal = 0; /* True if page is in log file */
41275 ** that will never be a valid file version. dbFileVers[] is a copy
41328 ** written into the log file when a WAL transaction is rolled back.
41359 ** rollback involves simply truncating the log file. Therefore, if one
41377 ** been written (but not committed) to the log file, do one of the
41426 ** any pages with page numbers greater than nTruncate into the WAL file.
41491 ** to PAGER_READER state to determine the size of the database file
41504 ** available from the WAL sub-system if the log file is empty or
41512 ** determine it based on the size of the database file. If the size
41513 ** of the database file is not an integer multiple of the page-size,
41514 ** round down to the nearest page. Except, any file larger than 0
41518 i64 n = 0; /* Size of db file in bytes */
41529 /* If the current number of pages in the file is greater than the
41531 ** that the file can be read.
41543 ** Check if the *-wal file that corresponds to the database opened by pPager
41544 ** exists if the database is not empy, or verify that the *-wal file does
41545 ** not exist (by deleting it) if the database file is empty.
41547 ** If the database is not empty and the *-wal file exists, open the pager
41548 ** in WAL mode. If the database is empty or if no *-wal file exists and
41554 ** The caller must hold a SHARED lock on the database file to call this
41555 ** function. Because an EXCLUSIVE lock on the db file is required to delete
41566 int isWal; /* True if WAL file exists */
41567 Pgno nPage; /* Size of the database file */
41594 ** the entire master journal file. The case pSavepoint==NULL occurs when
41605 ** file if PagerSavepoint.iHdrOffset is zero.
41609 ** PagerSavepoint.iHdrOffset to the end of the main journal file.
41611 ** * Pages are then played back from the sub-journal file, starting
41613 ** the journal file.
41621 ** journal file. There is no need for a bitvec in this case.
41656 ** journal. The actual file might be larger than this in
41683 ** of the main journal file. Continue to skip out-of-range pages and
41775 ** prior to the start of checkpoint and that the database file is synced
41779 ** file is synced following each commit operation, in addition to the
41825 ** attempts to open a temporary file. This information is used for
41833 ** Open a temporary file.
41835 ** Write the file descriptor into *pFile. Return SQLITE_OK on success
41837 ** delete the temporary file when it is closed.
41849 sqlite3_file *pFile, /* Write the file descriptor here */
42028 ** Read the first N bytes from the beginning of the file into memory
42031 ** If the pager was opened on a transient file (zFilename==""), or
42032 ** opened on a file less than N bytes in size, the output buffer is
42066 ** However, if the file is between 1 and <page-size> bytes in size, then
42067 ** this is considered a 1 page file.
42077 ** Try to obtain a lock of type locktype on the database file. If
42123 ** the database file. If a savepoint transaction were rolled back after
42126 ** the database file or the portion of the rollback journal and
42144 ** Truncate the in-memory database file image to nPage pages. This
42145 ** function does not actually modify the database file on disk. It
42159 ** syncs the journal file to disk, then sets pPager->journalHdr to the
42160 ** size of the journal file so that the pager_playback() routine knows
42161 ** that the entire journal file has been synced.
42212 /* If it is open, sync the journal file before calling UnlockAndRollback.
42214 ** file may be played back into the database. If a power failure occurs
42219 ** database and close the journal file without attempting to roll it
42221 ** rollback before accessing the database file.
42271 ** device characteristics of the the file-system, as follows:
42273 ** * If the journal file is an in-memory journal file, no action need
42280 ** mode, then the journal file is synced before this field is updated.
42283 ** journal file is synced.
42289 ** if( <full-sync mode> ) xSync(<journal file>);
42292 ** if( NOT SEQUENTIAL ) xSync(<journal file>);
42320 ** mode, then the journal file may at this point actually be larger
42322 ** file happens to be a journal-header (written as part of the
42325 ** anything else to the journal file (or commits/rolls back its
42331 ** To work around this, if the journal file does appear to contain
42357 /* Write the nRec value into the journal file header. If in
42364 ** for garbage data to be appended to the file, the nRec field
42400 /* Unless the pager is in noSync mode, the journal file was just
42413 ** in-memory pages in the list to the database file. The argument may
42418 ** is called. Before writing anything to the database file, this lock
42420 ** SQLITE_BUSY is returned and no data is written to the database file.
42422 ** If the pager is a temp-file pager and the actual file-system file
42426 ** Once the lock has been upgraded and, if necessary, the file opened,
42427 ** the pages are written out to the database file in list order. Writing
42433 ** If writing out a page causes the database file to grow, Pager.dbFileSize
42436 ** the database file.
42450 /* If the file is a temp-file has not yet been opened, open it now. It
42460 ** file size will be.
42474 ** make the file smaller (presumably by auto-vacuum code). Do not write
42475 ** any such pages to the file.
42494 ** the value now stored in the database file. If writing this
42495 ** page caused the database file to grow, update dbFileSize.
42523 ** Ensure that the sub-journal file is open. If it is already open, this
42571 ** write the journal record into the file. */
42603 ** out to the database file, if possible. This may involve syncing the
42604 ** journal file.
42651 /* Sync the journal file if required. */
42661 ** actually write data to the file in this case.
42669 ** <shrink database file to Y pages>
42674 ** out to the database file, but will be dropped from the cache. Then,
42676 ** data from the database file. This will be the copy of page X as it
42681 ** sub-journal file now (if it is not already there), so that it will
42691 /* Write the contents of the page out to the database file. */
42713 ** The zFilename argument is the path to the database file to open.
42714 ** If zFilename is NULL then a randomly-named temporary file is created
42715 ** and used as the file to be cached. Temporary files are be deleted
42731 ** If the pager object is allocated and the specified file opened
42739 sqlite3_vfs *pVfs, /* The virtual file system to use */
42741 const char *zFilename, /* Name of the database file to open */
42743 int flags, /* flags controlling this file */
42751 int memDb = 0; /* True if this is an in-memory file */
42752 int readOnly = 0; /* True if this is a read-only file */
42754 char *zPathname = 0; /* Full path to database file */
42762 /* Figure out how much space is required for each journal file-handle
42764 ** is the maximum space required for an in-memory journal file handle
42765 ** and a regular journal file-handle. Note that a "regular journal-handle"
42767 ** file in memory to implement the atomic-write optimization (see
42768 ** source file journal.c).
42787 ** to by zPathname, length nPathname. Or, if this is a temporary file,
42811 ** as it will not be possible to open the journal file or even
42823 ** three file descriptors, the database file name and the journal
42824 ** file name. The layout in memory is as follows:
42828 ** Database file handle (pVfs->szOsFile bytes)
42829 ** Sub-journal file handle (journalFileSize bytes)
42830 ** Main journal file handle (journalFileSize bytes)
42831 ** Database file name (nPathname+1 bytes)
42832 ** Journal file name (nPathname+8+1 bytes)
42837 ROUND8(pVfs->szOsFile) + /* The main db file */
42878 /* Open the pager file.
42886 /* If the file was successfully opened for read/write access,
42888 ** database file. The default page size is the maximum of:
42920 /* If a temporary file is requested, it is not opened immediately.
42922 ** opening the file until the first call to OsWrite().
42925 ** database is the same as a temp-file that is never written out to
42944 ** Pager structure and close the file.
43022 ** the file-system for the given pager. A hot journal is one that
43024 ** file exists if the following criteria are met:
43026 ** * The journal file exists in the file system, and
43027 ** * No process holds a RESERVED or greater lock on the database file, and
43028 ** * The database file itself is greater than 0 bytes in size, and
43029 ** * The first byte of the journal file exists and is not 0x00.
43031 ** If the current size of the database file is 0 but a journal file
43033 ** database with the same name. In this case the journal file is
43038 ** at the end of the file. If there is, and that master journal file
43039 ** does not exist, then the journal file is not really hot. In this
43041 ** routine will discover that the journal file is not really hot and
43044 ** If a hot-journal file is found to exist, *pExists is set to 1 and
43045 ** SQLITE_OK returned. If no hot-journal file is present, *pExists is
43047 ** to determine whether or not a hot-journal file exists, the IO error
43053 int exists = 1; /* True if a journal file is present */
43081 Pgno nPage; /* Number of pages in database file */
43083 /* Check the size of the database file. If it consists of 0 pages,
43084 ** then delete the journal file. See the header comment above for
43085 ** the reasoning here. Delete the obsolete journal file under
43099 /* The journal file exists and no other connection has a reserved
43100 ** or greater lock on the database file. Now check that there is
43101 ** at least one non-zero bytes at the start of the journal file.
43120 /* If we cannot open the rollback journal file in order to see if
43141 ** This function is called to obtain a shared lock on the database file.
43149 ** on the database file), then an attempt is made to obtain a
43150 ** SHARED lock on the database file. Immediately after obtaining
43151 ** the SHARED lock, the file-system is checked for a hot-journal,
43154 ** the 'change-counter' field of the database file header and
43161 ** file.
43164 ** occurs while locking the database, checking for a hot-journal file or
43165 ** rolling back a journal file, the IO error code is returned.
43181 int bHotJournal = 1; /* True if there exists a hot journal-file */
43191 /* If a journal file exists, and there is no RESERVED lock on the
43192 ** database file, then it either needs to be played back or deleted.
43201 /* Get an EXCLUSIVE lock on the database file. At this point it is
43204 ** database file, detect the RESERVED lock, and conclude that the
43209 ** other process attempting to access the database file will get to
43211 ** on the database file.
43221 /* If it is not already open and the file exists on disk, open the
43223 ** in exclusive-access mode the file descriptor will be kept open
43232 ** function was called and the journal file does not exist.
43236 int bExists; /* True if journal file exists */
43275 ** the file. If the unlock attempt fails, then Pager.eLock must be
43281 ** to ERROR state in the state diagram at the top of this file,
43301 /* The shared-lock has just been acquired on the database file
43308 ** at offset 24 into the file. The first 4 of these 16 bytes are
43310 ** other bytes change randomly with each file change when
43338 /* If there is a WAL file in the file-system, open this database in WAL
43388 ** read from the database file. In some cases, the pcache module may
43415 ** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
43432 Pager *pPager, /* The pager open on the database file */
43573 ** file when this routine is called.
43575 ** Open the journal file for pager pPager and write a journal header
43577 ** as well. This function is only used when the journal file is being
43579 ** when opening a hot journal file to roll it back.
43581 ** If the journal file is already open (as it may be in exclusive mode),
43583 ** already open file.
43585 ** Whether or not the journal file is opened by this function, the
43590 ** an IO error code if opening or writing the journal file fails.
43611 /* Open the journal file if it is not already open. */
43616 const int flags = /* VFS flags to open journal file */
43634 /* Write the first journal header to the journal file and open
43663 ** lock on the database file. If exFlag is true, then acquire at least
43668 ** within this transaction will be opened as an in-memory file. This
43673 ** or using a temporary file otherwise.
43697 /* Grab the write lock on the log file. If successful, upgrade to
43704 /* Obtain a RESERVED lock on the database file. If the exFlag parameter
43722 ** file as well as into the page cache. Which would be incorrect in
43754 ** been started. The journal file may or may not be open at this point.
43773 /* The journal file needs to be opened. Higher level routines have already
43798 ** EXCLUSIVE lock on the main database file. Write the current page to
43808 /* We should never write to the journal file the page that
43821 ** in the database file. And if an IO error occurs while doing so,
43888 ** must have been written to the journal file before returning.
43905 Pgno nPageCount; /* Total number of pages in database file */
43962 ** journal file must contain sync()ed copies of all of them
43963 ** before any of them can be written out to the database file.
44020 ** This routine is called to increment the value of the database file
44022 ** byte offset 24 of the pager file. The secondary change counter at
44032 ** page data. In this case the file will be updated when the current
44037 ** if isDirect is non-zero, then the database file is updated directly
44072 /* Open page 1 of the file for writing. */
44089 /* If running in direct mode, write the contents of page 1 to the file. */
44112 ** Sync the database file to disk. This is a no-op for in-memory databases
44137 ** the database file, an attempt is made to obtain one.
44158 ** Sync the database file for the pager pPager. zMaster points to the name
44159 ** of a master journal file that should be written into the individual
44160 ** journal file. zMaster may be NULL, which is interpreted as no master
44165 ** * The database file change-counter is updated,
44167 ** * all dirty pages are written to the database file,
44168 ** * the database file is truncated (if required), and
44169 ** * the database file synced.
44172 ** (delete, truncate or zero the first part of) the journal file (or
44173 ** delete the master journal file if specified).
44178 ** If the final parameter - noSync - is true, then the database file itself
44180 ** sync the database file before calling CommitPhaseTwo() to delete the
44181 ** journal file in this case.
44186 int noSync /* True to omit the xSync on the db file */
44200 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
44237 ** * The file-system supports the atomic-write property for
44239 ** * This commit is not part of a multi-file transaction, and
44240 ** * Exactly one page has been modified and store in the journal file.
44246 ** to make sure the journal file has actually been created, then call
44252 ** in 'direct' mode. In this case the journal file will never be
44266 /* Update the db file change counter via the direct-write method. The
44269 ** directly to the database file. Because of the atomic-write
44270 ** property of the host file-system, this is safe.
44286 ** file. This can only happen in auto-vacuum mode.
44292 ** reading data from the database file.
44316 /* Write the master journal name into the journal file. If a master
44317 ** journal file name has already been written to the journal file,
44323 /* Sync the journal file and write all dirty pages to the database.
44325 ** create the journal file or perform any real IO.
44344 /* If the file on disk is not the same size as the database image,
44345 ** then use pager_truncate to grow or shrink the file here.
44354 /* Finally, sync the database file. */
44371 ** When this function is called, the database file has been completely
44373 ** synced to disk. The journal file still exists in the file-system
44377 ** This function finalizes the journal file, either by deleting,
44403 ** The start of the journal file currently contains a single journal
44406 ** to the database file. So there is no need to zero the journal
44435 ** 1) It rolls back the journal file, restoring all database file and
44439 ** 2) It finalizes the journal file, so that it is not used for hot
44442 ** Finalization of the journal file (task 2) is only performed if the
44494 ** Return TRUE if the database file is opened read-only. Return FALSE
44587 ** occurs while opening the sub-journal file, then an IO error code is
44702 ** If this is a temp-file, it is possible that the journal file has
44704 ** the database file, so the playback operation can be skipped.
44717 ** Return the full pathname of the database file.
44731 ** Return the file handle for the database file associated
44732 ** with the pager. This might return NULL if the file has
44740 ** Return the full pathname of the journal file.
44779 ** Move the page pPg to location pgno in the file.
44899 /* If needSyncPgno is non-zero, then the journal file needs to be
44900 ** sync()ed before any data is written to database file page needSyncPgno.
44909 ** this transaction, it may be written to the database file before
44910 ** it is synced into the journal file. This way, it may end up in
44911 ** the journal file twice, but that is not a problem.
45009 ** the logic there will never allow a temporary file to be changed
45032 ** delete the journal file.
45044 /* In this case we would like to delete the journal file. If it is
45045 ** not possible, then that is not a problem. Deleting the journal file
45048 ** Before deleting the journal file, obtain a RESERVED lock on the
45049 ** database file. This ensures that the journal file is not deleted
45169 ** Attempt to take an exclusive lock on the database file. If a PENDING lock
45189 ** lock on the database file and use heap-memory to store the wal-index
45201 ** file, to make sure this is safe.
45207 /* Open the connection to the log file. If this operation fails,
45222 ** The caller must be holding a SHARED lock on the database file to call
45226 ** file (not a temp file or an in-memory database), and the WAL file
45232 ** If the pager is open on a temp-file (or in-memory database), or if
45233 ** the WAL file is already open, set *pbOpen to 1 and return SQLITE_OK
45267 ** This function is called to close the connection to the log file prior
45270 ** Before closing the log file, this function attempts to take an
45271 ** EXCLUSIVE lock on the database file. If this cannot be obtained, an
45280 /* If the log file is not already open, but does exist in the file-system,
45298 ** the database file, the log and log-summary files will be deleted.
45314 ** the pager is in WAL mode and the WAL file currently contains one or more
45316 ** WAL frames. Otherwise, if this is not a WAL database or the WAL file
45328 ** into the log file.
45345 /************** Begin file wal.c *********************************************/
45358 ** This file contains the implementation of a write-ahead log (WAL) used in
45361 ** WRITE-AHEAD LOG (WAL) FILE FORMAT
45363 ** A WAL file consists of a header followed by zero or more "frames".
45365 ** database file. All changes to the database are recorded by writing
45369 ** transferred back into the database file in an operation called a
45372 ** A single WAL file can be used multiple times. In other words, the
45383 ** 4: File format version. Currently 3007000
45453 ** the database file.
45475 ** might choose to implement the wal-index using a mmapped file. Because
45481 ** be) reconstructed from the original WAL file. In fact, the VFS is required
45485 ** Hence, unlike the database and WAL file formats which store all values
45512 ** first frame in the WAL file. The first entry in the second index block
45513 ** in the WAL file corresponds to the (HASHTABLE_NPAGE_ONE+1)th frame in
45518 ** depending on the contents of the WAL file. This does not change the
45565 ** to cover a typical 10 megabyte WAL file, assuming 1K pages. 8 or 10
45604 ** If a client begins recovering a WAL file and finds that (a) the checksum
45694 ** get all their all content directly from the database file and ignore
45716 ** only support mandatory file-locks, we do not read or write data
45717 ** from the region of the file on which locks are applied.
45732 ** big-endian format in the first 4 bytes of a WAL file.
45735 ** file are calculated by treating all data as an array of 32-bit
45742 ** Return the offset of frame iFrame in the write-ahead log file,
45751 ** An open write-ahead log file is represented by an instance of the
45756 sqlite3_file *pDbFd; /* File handle for the database file */
45757 sqlite3_file *pWalFd; /* File handle for WAL file */
45761 int szFirstBlock; /* Size of first block written to WAL file */
45770 u8 truncateOnCommit; /* True to truncate WAL file on commit */
45774 const char *zWalName; /* Name of WAL file */
45792 #define WAL_RDONLY 1 /* The WAL file is readonly */
45793 #define WAL_SHM_RDONLY 2 /* The SHM file is readonly */
45829 ** Define the parameters of the hash tables in the wal-index file. There
46172 ** in the wal-index file. Set *piZero to one less than the frame
46322 /* Assuming the wal-index file was successfully mapped, populate the
46394 ** Recover the wal-index by reading the write-ahead log file.
46405 i64 nSize; /* Size of log file */
46441 i64 iOffset; /* Next offset to read from log file */
46454 ** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid
46456 ** WAL file.
46499 /* Read all frames from the log file. */
46546 /* If more than one frame was recovered from the log file, report an
46549 ** checkpointing the log file.
46552 sqlite3_log(SQLITE_OK, "Recovered %d frames from WAL file %s",
46580 ** Open a connection to the WAL file zWalName. The database file must
46584 ** A SHARED lock should be held on the database file when this function
46586 ** client from unlinking the WAL or wal-index file. If another process
46590 ** If the log file is successfully opened, SQLITE_OK is returned and
46596 sqlite3_file *pDbFd, /* The open database file */
46597 const char *zWalName, /* Name of the WAL file */
46610 ** this source file. Verify that the #defines of the locking byte offsets
46638 /* Open file handle on the write-ahead log file. */
46662 ** Change the size to which the WAL file is trucated on each reset.
46968 ** Copy as much content as we can from the WAL back into the database file
46984 ** Fsync is also called on the database file if (and only if) the entire
46985 ** WAL content is copied into the database file. This second fsync makes
46987 ** database file.
47059 i64 nSize; /* Current size of database file */
47067 /* If the database file may grow as a result of this checkpoint, hint
47068 ** about the eventual size of the db file to the VFS layer.
47078 /* Iterate through the contents of the WAL, copying data to the db file. */
47084 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
47119 ** file has been copied into the database file, then block until all
47120 ** readers have finished using the wal file. This ensures that the next
47121 ** process to write to the database restarts the wal file.
47142 ** If the WAL file is currently larger than nMax bytes in size, truncate
47160 ** Close a connection to a log file.
47172 /* If an EXCLUSIVE lock can be obtained on the database file (using the
47174 ** connection associated with this log file is the only connection to
47194 /* Try to delete the WAL file if the checkpoint completed and
47199 /* Try to truncate the WAL file to zero bytes if the checkpoint
47204 ** leave a corrupt WAL file on disk. */
47252 ** from the file. If this happens, return non-zero.
47403 ** completely and get all content directly from the database file.
47495 ** When holding READ_LOCK(0), the reader ignores the entire log file,
47496 ** which implies that the database file contains a trustworthy
47504 ** it finished. Leaving a corrupt image in the database file.
47564 ** that the log file may have been wrapped by a writer, or that frames
47716 ** of the wal-index file content. Make sure the results agree with the
47732 ** required page. Read and return data from the log file.
47796 /* If another connection has written to the database file since the
47823 ** If any data has been written (but not committed) to the log file, this
47917 ** file (see sqlite3WalFrames()). It checks to see if, instead of appending
47918 ** to the current log file, it is possible to overwrite the start of the
47919 ** existing log file with the new frames (i.e. "reset" the log). If so,
47981 file and where
47987 sqlite3_file *pFd; /* The WAL file to which we write */
47994 ** Write iAmt bytes of content into the WAL file beginning at iOffset.
48050 ** on the log file (obtained using sqlite3WalBeginWriteTransaction()).
48066 i64 iOffset; /* Next byte to write in WAL file */
48084 ** log file, instead of appending to it at pWal->hdr.mxFrame.
48091 ** header to the start of the WAL file. See comments at the top of
48092 ** this source file for a description of the WAL header format.
48144 /* Write all frames into the log file exactly once */
48157 ** the transaction and/or sync the WAL file.
48250 int sync_flags, /* Flags to sync db file with (or 0) */
48298 /* Copy data from the log to the database file. */
48355 ** lock on the main database file.
48362 ** on the main database file before invoking this operation.
48430 /************** Begin file btmutex.c *****************************************/
48443 ** This file contains code used to implement mutexes on Btree objects.
48449 /************** Begin file btreeInt.h ****************************************/
48461 ** This file implements a external (disk-based) database using BTrees.
48468 ** The basic idea is that each page of the file contains N database
48484 ** In this implementation, a single file can hold one or more separate
48496 ** The file is divided into pages. The first page is called page 1,
48503 ** page contain a special header (the "file header") that describes the file.
48504 ** The format of the file header is as follows:
48509 ** 18 1 File format write version
48510 ** 19 1 File format read version
48515 ** 24 4 File change counter
48518 ** 36 4 Number of freelist pages in the file
48522 ** 44 4 File format of schema layer
48534 ** The file change counter is incremented when the database is changed
48535 ** This counter allows other processes to know when the file has changed
48556 ** file header that occurs before the page header.
48559 ** | file header | 100 bytes. Page 1 only.
48655 ** file header points to the first in a linked list of trunk page. Each trunk
48684 ** SQLite database in order to identify the file as a real database.
48708 ** As each page of the file is loaded into memory, an instance of the following
48710 ** information about the page that is decoded from the raw file page.
48774 ** this object for every database file that it has open. This structure
48783 ** schema associated with the database file are all contained within
48819 ** An instance of this object represents a single database file.
48821 ** A single database file can be in use at the same time by two
48823 ** sharing the same database file, each connection has it own
48824 ** private Btree object for the file and each of those Btrees points
48826 ** connections currently sharing this database file.
48890 #define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
48928 ** b-tree within a database file.
48933 ** A single database file can be shared by two more database connections,
49022 ** each child page in the database file. The parent page is the page that
49030 ** position in the file to another as part of autovacuum. When a page
49376 /************** Begin file btree.c *******************************************/
49388 ** This file implements a external (disk-based) database using BTrees.
49390 ** Including a description of file format and an overview of operation.
49424 ** in shared cache. This variable has file scope during normal builds,
49607 ** transaction on this file. And, obviously, for this to be so there
49608 ** must be an open write transaction on the file itself.
49633 ** may hold a WRITE_LOCK on any table in this file (since there can
49842 Btree *pBtree, /* The database file to check */
49879 ** from the database or written to the journal file (why should it
50265 ** Within this file, the parseCell() macro can be called instead of
50314 ** way will result in an incompatible file format.
50956 ** Return the size of the database file in pages. If there is any kind of
50977 BtShared *pBt, /* The database file */
51054 ** Open a database file.
51056 ** zFilename is the name of the database file. If zFilename is NULL
51076 const char *zFilename, /* Name of the file containing the BTree database */
51093 ** false for a file-based database.
51237 ** regular file-name. In this case the auto-vacuum applies as per normal.
51528 ** of the database file used for locking (beginning at PENDING_BYTE,
51666 ** Get a reference to pPage1 of the database file. This will
51667 ** also acquire a readlock on that file.
51669 ** SQLITE_OK is returned on success. If the file is not a
51670 ** well-formed database file, then SQLITE_CORRUPT is returned.
51676 MemPage *pPage1; /* Page 1 of the database file */
51678 int nPageFile = 0; /* Number of pages in the database file */
51688 /* Do some checking to help insure the file we opened really is
51689 ** a valid database file.
51726 ** file.
51824 ** this routine unrefs the first page of the database file which
51842 ** If pBt points to an empty file then convert that empty file
51980 ** file is not pBt->pageSize. In this case lockBtree() will update
51981 ** pBt->pageSize to the page-size of the file on disk.
52028 ** client has been writing the database file), update it now. Doing
52256 ** database so that the last page of the file currently in use
52262 ** number of pages the database file will contain after this
52322 ** of the file is found.
52402 ** the database file should be truncated to during the commit process.
52474 ** database are written into the database file and flushed to oxide.
52482 ** Otherwise, sync the database file for the btree pBt. zMaster points to
52483 ** the name of a master journal file that should be written into the
52484 ** individual journal file, or is NULL, indicating no master journal file
52491 ** the write-transaction for this database file is to delete the journal.
52563 ** finalize the underlying journal file, this function returns an error and
52565 ** is non-zero then this b-tree transaction is part of a multi-file
52567 ** (by deleting a master journal file) and the caller will ignore this
52573 ** This will release the write lock on the database file. If there
52678 ** This will release the write lock on the database file. If there
52920 ** Set the cached rowid value of every cursor in the same database file
52950 ** Close a cursor. The read lock on the database file is released
53103 BtShared *pBt, /* The database file */
53339 ** 3) the database is file-backed, and
53343 ** then data can be read directly from the database file into the
53595 ** below to be untrue if the database file is corrupt. This can occur if
54078 /* If the database file is corrupt, it is possible for the value of idx
54182 ** Allocate a new page from the database file.
54195 ** attempt to keep related pages close to each other in the database file,
54215 Pgno mxPage; /* Total size of the database file */
54415 ** end of the file */
54424 ** at the end of the file instead of one. The first allocated page
54428 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
54450 TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
54472 ** This function is used to add page iPage to the database file free-list.
54641 ** file the database must be corrupt. */
55598 ** file is corrupt. The corruption will be detected and reported later
55656 ** keep entries in the disk file in order so that a scan
55657 ** of the table is a linear scan through the file. That
55746 ** Note that this can never happen in an SQLite data file, as all
56455 ** by extending the file), the current page at position pgnoMove
56631 ** root page in the database file, then the last root page
56632 ** in the database file is moved into the slot formerly occupied by
56635 ** root pages are kept at the beginning of the database file, which
56637 ** page number that used to be the last root page in the file before
56758 ** Read the meta-information out of a database file. Meta[0]
57285 ** This routine does a complete check of the given BTree file. aRoot[] is
57355 /* Make sure every page in the file is referenced
57404 ** Return the full pathname of the underlying database file.
57415 ** Return the pathname of the journal file for this database. The return
57416 ** value of this routine is the same regardless of whether the journal file
57647 /************** Begin file backup.c ******************************************/
57659 ** This file contains the implementation of the sqlite3_backup_XXX()
57674 Btree *pDest; /* Destination b-tree file */
57680 Btree *pSrc; /* Source b-tree file */
58076 ** fix the size of the file. However it is important to call
58078 ** destination file that lie beyond the nDestTruncate page mark are
58080 ** by the file truncation.
58119 ** the database file in any way, knowing that if a power failure
58121 ** journal file. */
58124 /* Write the extra pages and truncate the database file as required */
58144 /* Sync the database file to disk. */
58311 ** The size of file pTo may be reduced by this operation. If anything
58317 sqlite3_file *pFd; /* File descriptor for database pTo */
58343 ** file. By passing this as the number of pages to copy to
58367 /************** Begin file vdbemem.c *****************************************/
58380 ** This file contains code use to manipulate "Mem" structure. A "Mem"
59523 /************** Begin file vdbeaux.c *****************************************/
59535 ** This file contains code used for creating, destroying, and populating
59537 ** to version 2.8.7, all this code was combined into the vdbe.c source file.
59538 ** But that file was getting too big so this subroutines were split out.
59618 SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
60564 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){
61259 ** write-transaction spanning more than one database file, this routine
61277 ** be done before determining whether a master journal file is
61286 ** one database file has an open write transaction, a master journal
61287 ** file is required for an atomic commit.
61309 /* The simple case - no more than one database file (not counting the
61314 ** string, it means the main database is :memory: or a temp file. In
61315 ** that case we do not support atomic multi-file commits, so use the
61330 ** IO error while deleting or truncating a journal file. It is unlikely,
61344 /* The complex case - There is a multi-file write-transaction active.
61345 ** This requires a master journal file to ensure the transaction is
61352 char *zMaster = 0; /* File-name for the master journal */
61360 /* Select a master journal file name */
61397 /* Write the name of each database file in the transaction into the new
61398 ** master journal file. If an error occurs at this point close
61399 ** and delete the master journal file. All the individual journal files
61425 /* Sync the master journal file. If the IOCAP_SEQUENTIAL device
61440 ** an error occurs here, do not delete the master journal file.
61444 ** master journal file will be orphaned. But we cannot delete it,
61445 ** in case the master journal file name was written into the journal
61446 ** file before the failure occurred.
61461 /* Delete the master journal file. This commits the transaction. After
61679 ** file as part of an effort to free up cache space (see function
61898 FILE *out = fopen("vdbe_profile.out", "a");
62087 ** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
62565 ** pCur might be pointing to text obtained from a corrupt database file.
62760 /************** Begin file vdbeapi.c *****************************************/
62773 ** This file contains code use to implement APIs that are part of the
64075 /************** Begin file vdbetrace.c ***************************************/
64088 ** This file contains code used to insert the values of host parameters
64347 /************** Begin file vdbe.c ********************************************/
64359 ** The code in this file implements execution method of the
64360 ** Virtual Database Engine (VDBE). A separate file ("vdbeaux.c")
64362 ** VDBE instances. This file is solely interested in executing
64382 ** Most of the code in this file is taken up by the sqlite3VdbeExec()
64387 ** Various scripts scan this source file in order to generate HTML
64389 ** of the code in this file is, therefore, important. See other comments
64390 ** in this file for details. If in doubt, do not deviate from existing
64769 static void memTracePrint(FILE *out, Mem *p){
64789 static void registerTrace(FILE *out, int iReg, Mem *p){
64810 /************** Begin file hwtime.h ******************************************/
64823 ** This file contains inline asm code for retrieving "high-performance"
65123 int file_format; /* File format to use for encoding */
65371 const char *zFilename; /* Name of database file for pPager */
65575 ** file looking for lines that begin with "case OP_". The opcodes.h files
65577 ** opcode and the opcodes.c file is filled with an array of strings where
65587 ** Documentation about VDBE opcodes is generated by scanning this file
65590 ** file.
65594 ** Formatting is important to scripts that scan this file.
67155 ** the database file has been corrupted externally.
67178 ** allocation, especially if a corrupt database file has caused u.an.offset
67364 int file_format; /* File format to use for encoding */
67741 ** P1 is the index of the database file on which the transaction is
67742 ** started. Index 0 is the main database file and index 1 is the
67743 ** file used for temporary tables. Indices of 2 or more are used for
67747 ** obtained on the database file when a write-transaction is started. No
67752 ** on the file.
67764 ** If P2 is zero, then a read-lock is obtained on the database file.
67815 ** the main database file and P1==1 is the database file used to store
67846 ** size, and so forth. P1==0 is the main database file and P1==1 is the
67847 ** database file used to store temporary tables.
67870 /* Record changes in the file format */
67888 ** P1 is the database number which is 0 for the main database file
67889 ** and 1 for the file holding temporary tables and some higher number
67920 /* If the schema-cookie from the database file matches the cookie
67922 ** not reload the schema from the database file.
67946 ** P2 in a database file. The database file is determined by P3.
69091 ** it is found in the database file.
69101 ** it is found in the database file.
69611 ** file is given by P1.
69613 ** The table being destroyed is in the main database file if P3==0. If
69614 ** P3==1 then the table to be clear is in the auxiliary database file
69671 ** in the database file is given by P1. But, unlike Destroy, do not
69672 ** remove the table or index from the database file.
69674 ** The table being clear is in the main database file if P2==0. If
69675 ** P2==1 then the table to be clear is in the auxiliary database file
69709 ** Allocate a new table in the main database file if P1==0 or in the
69710 ** auxiliary database file if P1==1 or in an attached database if
69722 ** Allocate a new index in the main database file if P1==0 or in the
69723 ** auxiliary database file if P1==1 or in an attached database if
69878 ** file, not the main database file.
70449 const char *zFilename; /* Name of database file for pPager */
70476 && (sqlite3Strlen30(u.ci.zFilename)==0 /* Temp file */
70495 /* If leaving WAL mode, close the log file. If successful, the call
70497 ** file. An EXCLUSIVE lock may still be held on the database file
70510 /* Open a transaction on the database file. Regardless of the journal
71186 /************** Begin file vdbeblob.c ****************************************/
71199 ** This file contains code used to implement incremental BLOB I/O.
71656 /************** Begin file vdbesort.c ****************************************/
71668 ** This file contains code for the VdbeSorter object, used in concert with
71750 i64 iWriteOff; /* Current write offset within file pTemp1 */
71751 i64 iReadOff; /* Current read offset within file pTemp1 */
71759 sqlite3_file *pTemp1; /* PMA file 1 */
71773 sqlite3_file *pFile; /* File iterator is reading from */
71857 ** Write a single varint, value iVal, to file-descriptor pFile. Return
71861 ** offset in file pFile to write to. Before returning, *piOffset is
71865 sqlite3_file *pFile, /* File to write to */
71867 i64 *piOffset /* IN/OUT: Write offset in file pFile */
71881 ** Read a single varint from file-descriptor pFile. Return SQLITE_OK if
71885 ** byte offset in file pFile from whence to read the varint. If successful
71892 sqlite3_file *pFile, /* File to read from */
71894 i64 *piVal /* OUT: Value read from file */
71897 i64 iOff = *piOffset; /* Offset in file to read from */
71909 ** Initialize iterator pIter to scan through the PMA stored in file pFile
72103 ** Allocate space for a file-handle and open a temporary file. If successful,
72104 ** set *ppFile to point to the malloc'd file-handle and return SQLITE_OK.
72213 /* If the first temporary PMA file has not been opened, open it now. */
72250 /* Terminate each file with 8 extra bytes so that from any offset
72251 ** in the file we can always read 9 bytes without a SHORT_READ error */
72344 sqlite3_file *pTemp2 = 0; /* Second temp file to use */
72385 /* If there are SORTER_MAX_MERGE_COUNT or less PMAs in file pTemp1,
72392 ** are merged into a single PMA that is written to file pTemp2.
72400 /* Open the second temp file, if it is not already open. */
72539 /************** Begin file journal.c *****************************************/
72552 ** This file implements a special kind of sqlite3_file object used
72557 ** actual on disk file is created lazily. When the file is created,
72559 ** be used to service read() and write() requests. The actual file
72571 ** as an open file handle for journal files.
72580 sqlite3_file *pReal; /* The "real" underlying file descriptor */
72581 const char *zJournal; /* Name of the journal file */
72586 ** If it does not already exists, create and populate the on-disk file
72606 ** Close the file.
72618 ** Read data from the file.
72621 sqlite3_file *pJfd, /* The journal file from which to read */
72639 ** Write data to the file.
72642 sqlite3_file *pJfd, /* The journal file into which to write */
72645 sqlite_int64 iOfst /* Begin writing at this offset into the file */
72666 ** Truncate the file.
72680 ** Sync the file.
72694 ** Query the size of the file in bytes.
72731 ** Open a journal file.
72734 sqlite3_vfs *pVfs, /* The VFS to use for actual file I/O */
72735 const char *zName, /* Name of the journal file */
72736 sqlite3_file *pJfd, /* Preallocated, blank file handle */
72738 int nBuf /* Bytes buffered before opening the file */
72760 ** file has not yet been created, create it now.
72779 /************** Begin file memjournal.c **************************************/
72792 ** This file contains code use to implement an in-memory rollback journal.
72831 sqlite3_int64 iOffset; /* Offset from the beginning of the file */
72842 FilePoint endpoint; /* Pointer to the end of the file */
72847 ** Read data from the in-memory journal file. This is the implementation
72851 sqlite3_file *pJfd, /* The journal file from which to read */
72862 /* SQLite never tries to read past the end of a rollback journal file */
72893 ** Write data to the file.
72896 sqlite3_file *pJfd, /* The journal file into which to write */
72899 sqlite_int64 iOfst /* Begin writing at this offset into the file */
72905 /* An in-memory journal file should only ever be appended to. Random
72917 /* New chunk is required to extend the file. */
72943 ** Truncate the file.
72961 ** Close the file.
72970 ** Sync the file.
72983 ** Query the size of the file in bytes.
73015 ** Open a journal file.
73025 ** Return true if the file-handle passed as an argument is
73033 ** Return the number of bytes required to store a MemJournal file descriptor.
73040 /************** Begin file walker.c ******************************************/
73052 ** This file contains routines used for walking the parser tree for
73178 /************** Begin file resolve.c *****************************************/
73191 ** This file contains routines used for walking the parser tree and
74403 /************** Begin file expr.c ********************************************/
74415 ** This file contains routines used for analyzing expressions and
77213 ** The value in regFree1 might get SCopy-ed into the file result.
78443 /************** Begin file alter.c *******************************************/
78455 ** This file contains C code routines that used to generate VDBE code
78460 ** The code in this file only exists if we are not omitting the
79033 ** Generate code to make sure the file format number is at least minFormat.
79034 ** The generated code will increase the file format number if necessary.
79164 /* If the default value of the new column is NULL, then set the file
79166 ** the file format becomes 3.
79271 /************** Begin file analyze.c *****************************************/
79283 ** This file contains code associated with the ANALYZE command.
80398 /************** Begin file attach.c ******************************************/
80410 ** This file contains code used to implement the ATTACH and DETACH commands.
80524 /* Open the database file. If the btree is successfully opened, use
80598 /* If the file was opened successfully, read the schema for the new database.
80599 ** If this fails, or if opening the file failed, then close the file and
80704 Expr *pFilename, /* Name of database file */
80957 /************** Begin file auth.c ********************************************/
80969 ** This file contains code used to implement the sqlite3_set_authorizer()
80976 ** All of the code in this file may be omitted by defining a single
81208 /************** Begin file build.c *******************************************/
81220 ** This file contains C code routines that are called by the SQLite parser
81221 ** when syntax rules are reduced. The routines in this file handle the
81351 /* The cookie mask contains one bit for each database file open.
81403 FILE *trace = (db->flags & SQLITE_VdbeTrace)!=0 ? stdout : 0;
81612 ** single file indicated.
81918 ** file instead of in the main database file. This is normally the case
82079 /* If the file format and encoding in the database have not been set,
82718 ** file instead of into the main database file.
84713 "file for storing temporary tables");
85024 /************** Begin file callback.c ****************************************/
85037 ** This file contains functions used to access the internal hash tables
85483 /************** Begin file delete.c ******************************************/
85495 ** This file contains C code routines that are called by the parser
85934 ** thely may interfere with compilation of other functions in this file
85935 ** (or in another file, if this file becomes part of the amalgamation). */
86136 /************** Begin file func.c ********************************************/
86148 ** This file contains the C functions that implement various SQL
86151 ** There is only one exported symbol in this file - the function
86152 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
86153 ** All other code has file scope.
87660 ** defined in this file.
87753 /************** Begin file fkey.c ********************************************/
87764 ** This file contains code used by the compiler to add foreign key
88063 ** These operations are identified in the comment at the top of this file
88218 ** These operations are identified in the comment at the top of this file
88974 /************** Begin file insert.c ******************************************/
88986 ** This file contains C code routines that are called by the parser
90024 ** thely may interfere with compilation of other functions in this file
90025 ** (or in another file, if this file becomes part of the amalgamation). */
90818 /************** Begin file legacy.c ******************************************/
90830 ** Main file for the SQLite library. The routines in this file
90965 /************** Begin file loadext.c *****************************************/
90977 ** This file contains code used to dynamically load extensions into
90985 /************** Begin file sqlite3ext.h **************************************/
90997 ** This header file defines the SQLite interface for use by
91000 ** as extensions by SQLite should #include this file instead of
91229 ** This header file is also used by the loadext.c source file
91798 ** Attempt to load an SQLite extension library contained in the file
92075 /************** Begin file pragma.c ******************************************/
92087 ** This file contains code used to implement the PRAGMA command.
92128 ** remainder of this file is specific to PRAGMA processing. So omit
92129 ** the rest of the file if PRAGMAs are omitted from the build.
92163 ** Interpret the given string as a temp db location. Return 1 for file
92170 }else if( sqlite3StrICmp(z, "file")==0 ){
92183 ** from default, or when 'file' and the temp_store_directory has changed
92426 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
92463 ** stored in the database file.
92562 ** maximum number of pages in the database file. The
92611 ** set on all attached databases, as well as the main db file.
92737 ** creates the database file. It is important that it is created
92744 ** file. Before writing to meta[6], check that meta[3] indicates
92819 ** PRAGMA temp_store = "default"|"memory"|"file"
92822 ** the local value does not make changes to the disk file and the default
92894 ** the value sets a specific file to be used for database access locks.
92924 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
92936 ** the local value does not make changes to the disk file and the
93071 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
93209 /* Do an integrity check on each database file */
93342 ** The second form of this pragma is a no-op if the main database file
93344 ** encoding that will be used for the main database file if a new file
93345 ** is created. If an existing main database file is opened, then the
93557 ** Report the current state of file logs for all databases
93649 /************** Begin file prepare.c *****************************************/
93661 ** This file contains the implementation of the sqlite3_prepare()
93776 ** data structures for a single database file. The index of the
93777 ** database file is given by iDb. iDb==0 is used for the main
93883 ** meta[1] File format of schema layer.
93950 sqlite3SetString(pzErrMsg, db, "unsupported file format");
93955 /* Ticket #2804: When we open a database in the newer file format,
94026 ** Initialize all database files - the main database file, the file
94033 ** file was of zero-length, then the DB_Empty flag is also set.
94140 ** which database file in db->aDb[] the schema refers to.
94513 /************** Begin file select.c ******************************************/
94525 ** This file contains C code routines that are called by the parser
99127 /************** Begin file table.c *******************************************/
99139 ** This file contains the sqlite3_get_table() and sqlite3_free_table()
99326 /************** Begin file trigger.c *****************************************/
99337 ** This file contains the implementation for TRIGGERs
100452 /************** Begin file update.c ******************************************/
100464 ** This file contains C code routines that are called by the parser
101021 ** thely may interfere with compilation of other functions in this file
101022 ** (or in another file, if this file becomes part of the amalgamation). */
101127 /************** Begin file vacuum.c ******************************************/
101139 ** This file contains code used to implement the VACUUM command.
101141 ** Most of the code in this file may be omitted by defining the
101258 ** can be set to 'off' for this file, as it is not recovered if a crash
101269 ** to write the journal header file.
101285 /* The call to execSql() to attach the temp database has left the file
101308 ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
101451 ** database. No locks are held on any other files (since the main file
101454 ** vacuum database. The vacuum_db journal file is deleted when the pager
101475 /************** Begin file vtab.c ********************************************/
101487 ** This file contains code used to help implement virtual tables.
102544 /************** Begin file where.c *******************************************/
107801 /************** Begin file parse.c *******************************************/
107812 ** in the input grammar file. */
108687 static FILE *yyTraceFILE = 0;
108699 ** <li> A FILE* to which trace output should be written.
108709 SQLITE_PRIVATE void sqlite3ParserTrace(FILE *TraceFILE, char *zTracePrompt){
111273 /************** Begin file tokenize.c ****************************************/
111287 ** This file contains C code that splits an SQL input string up into
111333 ** The output of the mkkeywordhash.c program is written into a file
111334 ** named keywordhash.h and then included into this source file by
111338 /************** Begin file keywordhash.h *************************************/
111339 /***** This file contains automatically generated code ******
111341 ** The code in this file has been automatically generated by
111345 ** The code in this file implements a function that determines whether
112075 /************** Begin file complete.c ****************************************/
112089 ** This file contains C code that implements the sqlite3_complete() API.
112090 ** This code used to be part of the tokenizer.c source file. But by
112360 /************** Begin file main.c ********************************************/
112372 ** Main file for the SQLite library. The routines in this file
112380 /************** Begin file fts3.h ********************************************/
112393 ** This header file is used by programs that want to link against the
112412 /************** Begin file rtree.h *******************************************/
112425 ** This header file is used by programs that want to link against the
112444 /************** Begin file sqliteicu.h ***************************************/
112457 ** This header file is used by programs that want to link against the
113356 /* SQLITE_CANTOPEN */ "unable to open database file",
113364 /* SQLITE_NOLFS */ "large file support is disabled",
113368 /* SQLITE_NOTADB */ "file is encrypted or is not a database",
113820 ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
113842 ** more frames in the log file. Passing zero or a negative value as the
113987 ** a temporary file for transient pager files and statement journals.
113995 ** 0 any file (return 0)
113996 ** 1 1 file (return 0)
113998 ** 1 0 file (return 0)
113999 ** 2 1 file (return 0)
114307 ** the VFS that should be used to open the database file. *pzFile is set to
114308 ** point to a buffer containing the name of the file to open. It is the
114335 && nUri>=5 && memcmp(zUri, "file:", 5)==0
114344 ** method that there may be extra parameters following the file-name. */
114372 ** 0: Parsing file-name.
115007 "cannot open file at line %d of [%.10s]",
115272 ** an incompatible database file format. Changing the PENDING byte
115376 ** the SQLITE_N_KEYWORD macro is not defined in this file if SQLite
115438 ** to see if a database file was a URI that contained a specific query
115518 /************** Begin file notify.c ******************************************/
115531 ** This file contains the implementation of the sqlite3_unlock_notify()
115535 /* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */
115851 /************** Begin file fts3.c ********************************************/
115868 ** The code in this file is only compiled if:
116143 /************** Begin file fts3Int.h *****************************************/
116181 /************** Begin file fts3_tokenizer.h **********************************/
116346 /************** Begin file fts3_hash.h ***************************************/
116358 ** This is the header file for the generic hash-table implemenation
119541 ** even if we reach end-of-file. The fts3EofMethod() will be called
120557 u8 *pbEof /* OUT: End-of-file flag */
121840 /************** Begin file fts3_aux.c ****************************************/
122316 /************** Begin file fts3_expr.c ***************************************/
123331 /************** Begin file fts3_hash.c ***************************************/
123349 ** The code in this file is only compiled if:
123715 /************** Begin file fts3_porter.c *************************************/
123732 ** The code in this file is only compiled if:
124362 /************** Begin file fts3_tokenizer.c **********************************/
124376 ** This particular file implements the generic tokenizer interface.
124380 ** The code in this file is only compiled if:
124741 ** in the README.tokenizer file as an example, so it is important to
124795 ** scalarFunc() in this file for details) and, if ENABLE_TABLE is
124852 /************** Begin file fts3_tokenizer1.c *********************************/
124869 ** The code in this file is only compiled if:
125087 /************** Begin file fts3_write.c **************************************/
125100 ** This file is part of the SQLite FTS3 extension module. Specifically,
125101 ** this file contains code to insert, update and delete rows from FTS3
125139 ** be overridden at runtime for testing purposes. File fts3_test.c contains
125183 ** this structure are only manipulated by code in this file, opaque handles
125269 ** database file as soon as they are completely populated. The interior of
126160 ** on the database file for longer than necessary). Thus, any virtual table
128534 ** modify the database file.
128640 /************** Begin file fts3_snippet.c ************************************/
129387 ** file system. This is done because the full-text index doclist is required
130144 /************** Begin file rtree.c *******************************************/
130156 ** This file contains code for implementations of the r-tree and r*-tree
130202 ** This file contains an implementation of a couple of different variants
130203 ** of the r-tree algorithm. See the README file for further details. The
133430 /************** Begin file icu.c *********************************************/
133444 ** This file implements an integration between the ICU library
133932 /************** Begin file fts3_icu.c ****************************************/
133944 ** This file implements a tokenizer for fts3 based on the ICU library.