Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/sqlite/src/src/os_unix.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | ** 2004 May 22 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | ** The author disclaims copyright to this source code. In place of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | ** a legal notice, here is a blessing: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | ** May you do good and not evil. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | ** May you find forgiveness for yourself and forgive others. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | ** May you share freely, never taking more than you give. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
11 | ****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
12 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
13 | ** This file contains the VFS implementation for unix-like operating systems | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
14 | ** include Linux, MacOSX, *BSD, QNX, VxWorks, AIX, HPUX, and others. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
15 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
16 | ** There are actually several different VFS implementations in this file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
17 | ** The differences are in the way that file locking is done. The default | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
18 | ** implementation uses Posix Advisory Locks. Alternative implementations | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
19 | ** use flock(), dot-files, various proprietary locking schemas, or simply | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
20 | ** skip locking all together. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
21 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
22 | ** This source file is organized into divisions where the logic for various | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
23 | ** subfunctions is contained within the appropriate division. PLEASE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
24 | ** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
25 | ** in the correct division and should be clearly labeled. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
26 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
27 | ** The layout of divisions is as follows: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
28 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
29 | ** * General-purpose declarations and utility functions. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
30 | ** * Unique file ID logic used by VxWorks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
31 | ** * Various locking primitive implementations (all except proxy locking): | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
32 | ** + for Posix Advisory Locks | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33 | ** + for no-op locks | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
34 | ** + for dot-file locks | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
35 | ** + for flock() locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
36 | ** + for named semaphore locks (VxWorks only) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
37 | ** + for AFP filesystem locks (MacOSX only) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
38 | ** * sqlite3_file methods not associated with locking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
39 | ** * Definitions of sqlite3_io_methods objects for all locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
40 | ** methods plus "finder" functions for each locking method. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
41 | ** * sqlite3_vfs method implementations. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
42 | ** * Locking primitives for the proxy uber-locking-method. (MacOSX only) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
43 | ** * Definitions of sqlite3_vfs objects for all locking methods | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
44 | ** plus implementations of sqlite3_os_init() and sqlite3_os_end(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
45 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
46 | #include "sqliteInt.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
47 | #if SQLITE_OS_UNIX /* This file is used on unix only */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
49 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
50 | ** There are various methods for file locking used for concurrency | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
51 | ** control: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
52 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
53 | ** 1. POSIX locking (the default), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
54 | ** 2. No locking, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
55 | ** 3. Dot-file locking, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
56 | ** 4. flock() locking, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
57 | ** 5. AFP locking (OSX only), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
58 | ** 6. Named POSIX semaphores (VXWorks only), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
59 | ** 7. proxy locking. (OSX only) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
60 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
61 | ** Styles 4, 5, and 7 are only available of SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
62 | ** is defined to 1. The SQLITE_ENABLE_LOCKING_STYLE also enables automatic | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
63 | ** selection of the appropriate locking style based on the filesystem | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
64 | ** where the database is located. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
65 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
66 | #if !defined(SQLITE_ENABLE_LOCKING_STYLE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
67 | # if defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
68 | # define SQLITE_ENABLE_LOCKING_STYLE 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
69 | # else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
70 | # define SQLITE_ENABLE_LOCKING_STYLE 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
71 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
72 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
74 | /* Use pread() and pwrite() if they are available */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
75 | #if defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
76 | # define HAVE_PREAD 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
77 | # define HAVE_PWRITE 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
78 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
79 | #if defined(HAVE_PREAD64) && defined(HAVE_PWRITE64) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
80 | # undef USE_PREAD | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
81 | # define USE_PREAD64 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
82 | #elif defined(HAVE_PREAD) && defined(HAVE_PWRITE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
83 | # undef USE_PREAD64 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
84 | # define USE_PREAD 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
85 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
87 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
88 | ** standard include files. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
89 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
90 | #include <sys/types.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
91 | #include <sys/stat.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
92 | #include <fcntl.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
93 | #include <sys/ioctl.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
94 | #include <unistd.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
95 | #include <time.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
96 | #include <sys/time.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
97 | #include <errno.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
98 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
99 | # include <sys/mman.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
100 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
102 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
103 | # include <sys/ioctl.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
104 | # include <sys/file.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
105 | # include <sys/param.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
106 | #endif /* SQLITE_ENABLE_LOCKING_STYLE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
107 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
108 | #if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
109 | (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
110 | # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
111 | && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
112 | # define HAVE_GETHOSTUUID 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
113 | # else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
114 | # warning "gethostuuid() is disabled." | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
115 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
116 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
118 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
119 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
120 | # include <sys/ioctl.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
121 | # include <semaphore.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
122 | # include <limits.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
123 | #endif /* OS_VXWORKS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
125 | #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
126 | # include <sys/mount.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
127 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
128 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
129 | #ifdef HAVE_UTIME | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
130 | # include <utime.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
131 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
132 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
133 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
134 | ** Allowed values of unixFile.fsFlags | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
135 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
136 | #define SQLITE_FSFLAGS_IS_MSDOS 0x1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
138 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
139 | ** If we are to be thread-safe, include the pthreads header and define | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
140 | ** the SQLITE_UNIX_THREADS macro. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
141 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
142 | #if SQLITE_THREADSAFE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
143 | # include <pthread.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
144 | # define SQLITE_UNIX_THREADS 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
145 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
147 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
148 | ** Default permissions when creating a new file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
149 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
150 | #ifndef SQLITE_DEFAULT_FILE_PERMISSIONS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
151 | # define SQLITE_DEFAULT_FILE_PERMISSIONS 0644 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
152 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
154 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
155 | ** Default permissions when creating auto proxy dir | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
156 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
157 | #ifndef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
158 | # define SQLITE_DEFAULT_PROXYDIR_PERMISSIONS 0755 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
159 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
161 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
162 | ** Maximum supported path-length. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
163 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
164 | #define MAX_PATHNAME 512 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
166 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
167 | ** Maximum supported symbolic links | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
168 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
169 | #define SQLITE_MAX_SYMLINKS 100 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
171 | /* Always cast the getpid() return type for compatibility with | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
172 | ** kernel modules in VxWorks. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
173 | #define osGetpid(X) (pid_t)getpid() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
175 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
176 | ** Only set the lastErrno if the error code is a real error and not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
177 | ** a normal expected return code of SQLITE_BUSY or SQLITE_OK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
178 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
179 | #define IS_LOCK_ERROR(x) ((x != SQLITE_OK) && (x != SQLITE_BUSY)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
181 | /* Forward references */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
182 | typedef struct unixShm unixShm; /* Connection shared memory */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
183 | typedef struct unixShmNode unixShmNode; /* Shared memory instance */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
184 | typedef struct unixInodeInfo unixInodeInfo; /* An i-node */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
185 | typedef struct UnixUnusedFd UnixUnusedFd; /* An unused file descriptor */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
187 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
188 | ** Sometimes, after a file handle is closed by SQLite, the file descriptor | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
189 | ** cannot be closed immediately. In these cases, instances of the following | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
190 | ** structure are used to store the file descriptor while waiting for an | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
191 | ** opportunity to either close or reuse it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
192 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
193 | struct UnixUnusedFd { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
194 | int fd; /* File descriptor to close */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
195 | int flags; /* Flags this file descriptor was opened with */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
196 | UnixUnusedFd *pNext; /* Next unused file descriptor on same file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
197 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
198 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
199 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
200 | ** The unixFile structure is subclass of sqlite3_file specific to the unix | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
201 | ** VFS implementations. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
202 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
203 | typedef struct unixFile unixFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
204 | struct unixFile { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
205 | sqlite3_io_methods const *pMethod; /* Always the first entry */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
206 | sqlite3_vfs *pVfs; /* The VFS that created this unixFile */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
207 | unixInodeInfo *pInode; /* Info about locks on this inode */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
208 | int h; /* The file descriptor */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
209 | unsigned char eFileLock; /* The type of lock held on this fd */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
210 | unsigned short int ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
211 | int lastErrno; /* The unix errno from last I/O error */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
212 | void *lockingContext; /* Locking style specific state */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
213 | UnixUnusedFd *pPreallocatedUnused; /* Pre-allocated UnixUnusedFd */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
214 | const char *zPath; /* Name of the file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
215 | unixShm *pShm; /* Shared memory segment information */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
216 | int szChunk; /* Configured by FCNTL_CHUNK_SIZE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
217 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
218 | int nFetchOut; /* Number of outstanding xFetch refs */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
219 | sqlite3_int64 mmapSize; /* Usable size of mapping at pMapRegion */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
220 | sqlite3_int64 mmapSizeActual; /* Actual size of mapping at pMapRegion */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
221 | sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
222 | void *pMapRegion; /* Memory mapped region */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
223 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
224 | int sectorSize; /* Device sector size */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
225 | int deviceCharacteristics; /* Precomputed device characteristics */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
226 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
227 | int openFlags; /* The flags specified at open() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
228 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
229 | #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
230 | unsigned fsFlags; /* cached details from statfs() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
231 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
232 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
233 | unsigned iBusyTimeout; /* Wait this many millisec on locks */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
234 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
235 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
236 | struct vxworksFileId *pId; /* Unique file ID */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
237 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
238 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
239 | /* The next group of variables are used to track whether or not the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
240 | ** transaction counter in bytes 24-27 of database files are updated | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
241 | ** whenever any part of the database changes. An assertion fault will | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
242 | ** occur if a file is updated without also updating the transaction | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
243 | ** counter. This test is made to avoid new problems similar to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
244 | ** one described by ticket #3584. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
245 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
246 | unsigned char transCntrChng; /* True if the transaction counter changed */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
247 | unsigned char dbUpdate; /* True if any part of database file changed */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
248 | unsigned char inNormalWrite; /* True if in a normal write operation */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
250 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
251 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
252 | #ifdef SQLITE_TEST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
253 | /* In test mode, increase the size of this structure a bit so that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
254 | ** it is larger than the struct CrashFile defined in test6.c. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
255 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
256 | char aPadding[32]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
257 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
258 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
259 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
260 | /* This variable holds the process id (pid) from when the xRandomness() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
261 | ** method was called. If xOpen() is called from a different process id, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
262 | ** indicating that a fork() has occurred, the PRNG will be reset. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
263 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
264 | static pid_t randomnessPid = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
265 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
266 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
267 | ** Allowed values for the unixFile.ctrlFlags bitmask: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
268 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
269 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
270 | #define UNIXFILE_RDONLY 0x02 /* Connection is read only */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
271 | #define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
272 | #ifndef SQLITE_DISABLE_DIRSYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
273 | # define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
274 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
275 | # define UNIXFILE_DIRSYNC 0x00 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
276 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
277 | #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
278 | #define UNIXFILE_DELETE 0x20 /* Delete on close */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
279 | #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
280 | #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
281 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
282 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
283 | ** Include code that is common to all os_*.c files | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
284 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
285 | #include "os_common.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
287 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
288 | ** Define various macros that are missing from some systems. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
289 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
290 | #ifndef O_LARGEFILE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
291 | # define O_LARGEFILE 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
292 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
293 | #ifdef SQLITE_DISABLE_LFS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
294 | # undef O_LARGEFILE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
295 | # define O_LARGEFILE 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
296 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
297 | #ifndef O_NOFOLLOW | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
298 | # define O_NOFOLLOW 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
299 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
300 | #ifndef O_BINARY | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
301 | # define O_BINARY 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
302 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
303 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
304 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
305 | ** The threadid macro resolves to the thread-id or to 0. Used for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
306 | ** testing and debugging only. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
307 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
308 | #if SQLITE_THREADSAFE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
309 | #define threadid pthread_self() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
310 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
311 | #define threadid 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
312 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
314 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
315 | ** HAVE_MREMAP defaults to true on Linux and false everywhere else. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
316 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
317 | #if !defined(HAVE_MREMAP) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
318 | # if defined(__linux__) && defined(_GNU_SOURCE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
319 | # define HAVE_MREMAP 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
320 | # else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
321 | # define HAVE_MREMAP 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
322 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
323 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
324 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
325 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
326 | ** Explicitly call the 64-bit version of lseek() on Android. Otherwise, lseek() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
327 | ** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
328 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
329 | #ifdef __ANDROID__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
330 | # define lseek lseek64 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
331 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
332 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
333 | #ifdef __linux__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
334 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
335 | ** Linux-specific IOCTL magic numbers used for controlling F2FS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
336 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
337 | #define F2FS_IOCTL_MAGIC 0xf5 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
338 | #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
339 | #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
340 | #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
341 | #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
342 | #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, u32) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
343 | #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
344 | #endif /* __linux__ */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
346 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
347 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
348 | ** Different Unix systems declare open() in different ways. Same use | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
349 | ** open(const char*,int,mode_t). Others use open(const char*,int,...). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
350 | ** The difference is important when using a pointer to the function. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
351 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
352 | ** The safest way to deal with the problem is to always use this wrapper | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
353 | ** which always has the same well-defined interface. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
354 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
355 | static int posixOpen(const char *zFile, int flags, int mode){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
356 | return open(zFile, flags, mode); executed 107540 times by 438 tests: return open(zFile, flags, mode); Executed by:
| 107540 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
357 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
358 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
359 | /* Forward reference */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
360 | static int openDirectory(const char*, int*); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
361 | static int unixGetpagesize(void); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
362 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
363 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
364 | ** Many system calls are accessed through pointer-to-functions so that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
365 | ** they may be overridden at runtime to facilitate fault injection during | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
366 | ** testing and sandboxing. The following array holds the names and pointers | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
367 | ** to all overrideable system calls. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
368 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
369 | static struct unix_syscall { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
370 | const char *zName; /* Name of the system call */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
371 | sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
372 | sqlite3_syscall_ptr pDefault; /* Default value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
373 | } aSyscall[] = { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
374 | { "open", (sqlite3_syscall_ptr)posixOpen, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
375 | #define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
376 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
377 | { "close", (sqlite3_syscall_ptr)close, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
378 | #define osClose ((int(*)(int))aSyscall[1].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
379 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
380 | { "access", (sqlite3_syscall_ptr)access, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
381 | #define osAccess ((int(*)(const char*,int))aSyscall[2].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
382 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
383 | { "getcwd", (sqlite3_syscall_ptr)getcwd, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
384 | #define osGetcwd ((char*(*)(char*,size_t))aSyscall[3].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
385 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
386 | { "stat", (sqlite3_syscall_ptr)stat, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
387 | #define osStat ((int(*)(const char*,struct stat*))aSyscall[4].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
388 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
389 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
390 | ** The DJGPP compiler environment looks mostly like Unix, but it | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
391 | ** lacks the fcntl() system call. So redefine fcntl() to be something | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
392 | ** that always succeeds. This means that locking does not occur under | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
393 | ** DJGPP. But it is DOS - what did you expect? | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
394 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
395 | #ifdef __DJGPP__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
396 | { "fstat", 0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
397 | #define osFstat(a,b,c) 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
398 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
399 | { "fstat", (sqlite3_syscall_ptr)fstat, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
400 | #define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
401 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
403 | { "ftruncate", (sqlite3_syscall_ptr)ftruncate, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
404 | #define osFtruncate ((int(*)(int,off_t))aSyscall[6].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
405 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
406 | { "fcntl", (sqlite3_syscall_ptr)fcntl, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
407 | #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
408 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
409 | { "read", (sqlite3_syscall_ptr)read, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
410 | #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
411 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
412 | #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
413 | { "pread", (sqlite3_syscall_ptr)pread, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
414 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
415 | { "pread", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
416 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
417 | #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
419 | #if defined(USE_PREAD64) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
420 | { "pread64", (sqlite3_syscall_ptr)pread64, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
421 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
422 | { "pread64", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
423 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
424 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
426 | { "write", (sqlite3_syscall_ptr)write, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
427 | #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
429 | #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
430 | { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
431 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
432 | { "pwrite", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
433 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
434 | #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
435 | aSyscall[12].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
437 | #if defined(USE_PREAD64) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
438 | { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
439 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
440 | { "pwrite64", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
441 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
442 | #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
443 | aSyscall[13].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
445 | { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
446 | #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
447 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
448 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
449 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
450 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
451 | { "fallocate", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
452 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
453 | #define osFallocate ((int(*)(int,off_t,off_t))aSyscall[15].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
454 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
455 | { "unlink", (sqlite3_syscall_ptr)unlink, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
456 | #define osUnlink ((int(*)(const char*))aSyscall[16].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
458 | { "openDirectory", (sqlite3_syscall_ptr)openDirectory, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
459 | #define osOpenDirectory ((int(*)(const char*,int*))aSyscall[17].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
460 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
461 | { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
462 | #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
463 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
464 | { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
465 | #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
467 | #if defined(HAVE_FCHOWN) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
468 | { "fchown", (sqlite3_syscall_ptr)fchown, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
469 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
470 | { "fchown", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
471 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
472 | #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
473 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
474 | #if defined(HAVE_FCHOWN) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
475 | { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
476 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
477 | { "geteuid", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
478 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
479 | #define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
480 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
481 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
482 | { "mmap", (sqlite3_syscall_ptr)mmap, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
483 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
484 | { "mmap", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
485 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
486 | #define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
488 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
489 | { "munmap", (sqlite3_syscall_ptr)munmap, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
490 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
491 | { "munmap", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
492 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
493 | #define osMunmap ((int(*)(void*,size_t))aSyscall[23].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
494 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
495 | #if HAVE_MREMAP && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
496 | { "mremap", (sqlite3_syscall_ptr)mremap, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
497 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
498 | { "mremap", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
499 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
500 | #define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[24].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
502 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
503 | { "getpagesize", (sqlite3_syscall_ptr)unixGetpagesize, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
504 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
505 | { "getpagesize", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
506 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
507 | #define osGetpagesize ((int(*)(void))aSyscall[25].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
508 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
509 | #if defined(HAVE_READLINK) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
510 | { "readlink", (sqlite3_syscall_ptr)readlink, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
511 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
512 | { "readlink", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
513 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
514 | #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
515 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
516 | #if defined(HAVE_LSTAT) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
517 | { "lstat", (sqlite3_syscall_ptr)lstat, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
518 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
519 | { "lstat", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
520 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
521 | #define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
522 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
523 | #if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
524 | # ifdef __ANDROID__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
525 | { "ioctl", (sqlite3_syscall_ptr)(int(*)(int, int, ...))ioctl, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
526 | # else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
527 | { "ioctl", (sqlite3_syscall_ptr)ioctl, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
528 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
529 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
530 | { "ioctl", (sqlite3_syscall_ptr)0, 0 }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
531 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
532 | #define osIoctl ((int(*)(int,int,...))aSyscall[28].pCurrent) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
533 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
534 | }; /* End of the overrideable system calls */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
535 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
536 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
537 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
538 | ** On some systems, calls to fchown() will trigger a message in a security | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
539 | ** log if they come from non-root processes. So avoid calling fchown() if | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
540 | ** we are not running as root. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
541 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
542 | static int robustFchown(int fd, uid_t uid, gid_t gid){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
543 | #if defined(HAVE_FCHOWN) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
544 | return osGeteuid() ? 0 : osFchown(fd,uid,gid); executed 45462 times by 425 tests: return ((uid_t(*)(void))aSyscall[21].pCurrent)() ? 0 : ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)(fd,uid,gid); Executed by:
| 0-45462 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
545 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
546 | return 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
547 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
548 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
549 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
550 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
551 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
552 | ** "unix" VFSes. Return SQLITE_OK opon successfully updating the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
553 | ** system call pointer, or SQLITE_NOTFOUND if there is no configurable | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
554 | ** system call named zName. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
555 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
556 | static int unixSetSystemCall( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
557 | sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
558 | const char *zName, /* Name of system call to override */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
559 | sqlite3_syscall_ptr pNewFunc /* Pointer to new system call value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
560 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
561 | unsigned int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
562 | int rc = SQLITE_NOTFOUND; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
563 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
564 | UNUSED_PARAMETER(pNotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
565 | if( zName==0 ){
| 6-17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
566 | /* If no zName is given, restore all system calls to their default | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
567 | ** settings and return NULL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
568 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
569 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
570 | for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
| 6-174 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
571 | if( aSyscall[i].pDefault ){
| 27-147 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
572 | aSyscall[i].pCurrent = aSyscall[i].pDefault; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
573 | } executed 27 times by 1 test: end of block Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
574 | } executed 174 times by 1 test: end of block Executed by:
| 174 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
575 | }else{ executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
576 | /* If zName is specified, operate on only the one system call | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
577 | ** specified. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
578 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
579 | for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
| 2-262 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
580 | if( strcmp(zName, aSyscall[i].zName)==0 ){ never executed: __result = (((const unsigned char *) (const char *) ( zName ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( aSyscall[i].zName ))[3] - __s2[3]); never executed: end of block never executed: end of block
| 0-247 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
581 | if( aSyscall[i].pDefault==0 ){
| 7-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
582 | aSyscall[i].pDefault = aSyscall[i].pCurrent; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
583 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
584 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
585 | if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault; executed 5 times by 1 test: pNewFunc = aSyscall[i].pDefault; Executed by:
| 5-10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
586 | aSyscall[i].pCurrent = pNewFunc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
587 | break; executed 15 times by 1 test: break; Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
588 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
589 | } executed 247 times by 1 test: end of block Executed by:
| 247 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
590 | } executed 17 times by 1 test: end of block Executed by:
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
591 | return rc; executed 23 times by 1 test: return rc; Executed by:
| 23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
592 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
593 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
594 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
595 | ** Return the value of a system call. Return NULL if zName is not a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
596 | ** recognized system call name. NULL is also returned if the system call | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
597 | ** is currently undefined. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
598 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
599 | static sqlite3_syscall_ptr unixGetSystemCall( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
600 | sqlite3_vfs *pNotUsed, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
601 | const char *zName | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
602 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
603 | unsigned int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
605 | UNUSED_PARAMETER(pNotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
606 | for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
| 3-636 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
607 | if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent; never executed: __result = (((const unsigned char *) (const char *) ( zName ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( aSyscall[i].zName ))[3] - __s2[3]); never executed: end of block never executed: end of block executed 39 times by 1 test: return aSyscall[i].pCurrent; Executed by:
| 0-597 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
608 | } executed 597 times by 1 test: end of block Executed by:
| 597 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
609 | return 0; executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
610 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
612 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
613 | ** Return the name of the first system call after zName. If zName==NULL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
614 | ** then return the name of the first system call. Return NULL if zName | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
615 | ** is the last system call or if zName is not the name of a valid | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
616 | ** system call. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
617 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
618 | static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
619 | int i = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
620 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
621 | UNUSED_PARAMETER(p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
622 | if( zName ){
| 1-25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
623 | for(i=0; i<ArraySize(aSyscall)-1; i++){
| 0-367 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
624 | if( strcmp(zName, aSyscall[i].zName)==0 ) break; never executed: __result = (((const unsigned char *) (const char *) ( zName ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( aSyscall[i].zName ))[3] - __s2[3]); never executed: end of block never executed: end of block executed 25 times by 1 test: break; Executed by:
| 0-342 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
625 | } executed 342 times by 1 test: end of block Executed by:
| 342 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
626 | } executed 25 times by 1 test: end of block Executed by:
| 25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
627 | for(i++; i<ArraySize(aSyscall); i++){
| 1-29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
628 | if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; executed 25 times by 1 test: return aSyscall[i].zName; Executed by:
| 4-25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
629 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
630 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
631 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
632 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
633 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
634 | ** Do not accept any file descriptor less than this value, in order to avoid | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
635 | ** opening database file using file descriptors that are commonly used for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
636 | ** standard input, output, and error. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
637 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
638 | #ifndef SQLITE_MINIMUM_FILE_DESCRIPTOR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
639 | # define SQLITE_MINIMUM_FILE_DESCRIPTOR 3 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
640 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
641 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
642 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
643 | ** Invoke open(). Do so multiple times, until it either succeeds or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
644 | ** fails for some reason other than EINTR. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
645 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
646 | ** If the file creation mode "m" is 0 then set it to the default for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
647 | ** SQLite. The default is SQLITE_DEFAULT_FILE_PERMISSIONS (normally | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
648 | ** 0644) as modified by the system umask. If m is not 0, then | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
649 | ** make the file creation mode be exactly m ignoring the umask. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
650 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
651 | ** The m parameter will be non-zero only when creating -wal, -journal, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
652 | ** and -shm files. We want those files to have *exactly* the same | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
653 | ** permissions as their original database, unadulterated by the umask. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
654 | ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
655 | ** transaction crashes and leaves behind hot journals, then any | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
656 | ** process that is able to write to the database will also be able to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
657 | ** recover the hot journals. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
658 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
659 | static int robust_open(const char *z, int f, mode_t m){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
660 | int fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
661 | mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS;
| 45759-61779 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
662 | while(1){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
663 | #if defined(O_CLOEXEC) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
664 | fd = osOpen(z,f|O_CLOEXEC,m2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
665 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
666 | fd = osOpen(z,f,m2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
667 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
668 | if( fd<0 ){
| 558-107015 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
669 | if( errno==EINTR ) continue; executed 32 times by 1 test: continue; Executed by:
| 32-526 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
670 | break; executed 526 times by 1 test: break; Executed by:
| 526 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
671 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
672 | if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break; executed 107015 times by 438 tests: break; Executed by:
| 0-107015 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
673 | osClose(fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
674 | sqlite3_log(SQLITE_WARNING, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
675 | "attempt to open \"%s\" as file descriptor %d", z, fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
676 | fd = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
677 | if( osOpen("/dev/null", f, m)<0 ) break; never executed: break;
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
678 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
679 | if( fd>=0 ){
| 526-107015 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
680 | if( m!=0 ){
| 45739-61276 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
681 | struct stat statbuf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
682 | if( osFstat(fd, &statbuf)==0
| 0-45739 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
683 | && statbuf.st_size==0
| 4407-41332 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
684 | && (statbuf.st_mode&0777)!=m
| 4-41328 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
685 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
686 | osFchmod(fd, m); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
687 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
688 | } executed 45739 times by 425 tests: end of block Executed by:
| 45739 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
689 | #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
690 | osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
691 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
692 | } executed 107015 times by 438 tests: end of block Executed by:
| 107015 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
693 | return fd; executed 107541 times by 438 tests: return fd; Executed by:
| 107541 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
694 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
695 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
696 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
697 | ** Helper functions to obtain and relinquish the global mutex. The | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
698 | ** global mutex is used to protect the unixInodeInfo and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
699 | ** vxworksFileId objects used by this file, all of which may be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
700 | ** shared by multiple threads. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
701 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
702 | ** Function unixMutexHeld() is used to assert() that the global mutex | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
703 | ** is held when required. This function is only used as part of assert() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
704 | ** statements. e.g. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
705 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
706 | ** unixEnterMutex() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
707 | ** assert( unixMutexHeld() ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
708 | ** unixEnterLeave() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
709 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
710 | ** To prevent deadlock, the global unixBigLock must must be acquired | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
711 | ** before the unixInodeInfo.pLockMutex mutex, if both are held. It is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
712 | ** OK to get the pLockMutex without holding unixBigLock first, but if | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
713 | ** that happens, the unixBigLock mutex must not be acquired until after | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
714 | ** pLockMutex is released. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
715 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
716 | ** OK: enter(unixBigLock), enter(pLockInfo) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
717 | ** OK: enter(unixBigLock) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
718 | ** OK: enter(pLockInfo) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
719 | ** ERROR: enter(pLockInfo), enter(unixBigLock) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
720 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
721 | static sqlite3_mutex *unixBigLock = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
722 | static void unixEnterMutex(void){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
723 | assert( sqlite3_mutex_notheld(unixBigLock) ); /* Not a recursive mutex */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
724 | sqlite3_mutex_enter(unixBigLock); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
725 | } executed 286129 times by 438 tests: end of block Executed by:
| 286129 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
726 | static void unixLeaveMutex(void){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
727 | assert( sqlite3_mutex_held(unixBigLock) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
728 | sqlite3_mutex_leave(unixBigLock); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
729 | } executed 286129 times by 438 tests: end of block Executed by:
| 286129 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
730 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
731 | static int unixMutexHeld(void) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
732 | return sqlite3_mutex_held(unixBigLock); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
733 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
734 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
735 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
736 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
737 | #ifdef SQLITE_HAVE_OS_TRACE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
738 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
739 | ** Helper function for printing out trace information from debugging | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
740 | ** binaries. This returns the string representation of the supplied | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
741 | ** integer lock-type. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
742 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
743 | static const char *azFileLock(int eFileLock){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
744 | switch( eFileLock ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
745 | case NO_LOCK: return "NONE"; never executed: return "NONE"; never executed: case 0: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
746 | case SHARED_LOCK: return "SHARED"; never executed: return "SHARED"; never executed: case 1: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
747 | case RESERVED_LOCK: return "RESERVED"; never executed: return "RESERVED"; never executed: case 2: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
748 | case PENDING_LOCK: return "PENDING"; never executed: return "PENDING"; never executed: case 3: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
749 | case EXCLUSIVE_LOCK: return "EXCLUSIVE"; never executed: return "EXCLUSIVE"; never executed: case 4: | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
750 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
751 | return "ERROR"; never executed: return "ERROR"; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
752 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
753 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
754 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
755 | #ifdef SQLITE_LOCK_TRACE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
756 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
757 | ** Print out information about all locking operations. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
758 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
759 | ** This routine is used for troubleshooting locks on multithreaded | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
760 | ** platforms. Enable by compiling with the -DSQLITE_LOCK_TRACE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
761 | ** command-line option on the compiler. This code is normally | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
762 | ** turned off. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
763 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
764 | static int lockTrace(int fd, int op, struct flock *p){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
765 | char *zOpName, *zType; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
766 | int s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
767 | int savedErrno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
768 | if( op==F_GETLK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
769 | zOpName = "GETLK"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
770 | }else if( op==F_SETLK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
771 | zOpName = "SETLK"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
772 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
773 | s = osFcntl(fd, op, p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
774 | sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
775 | return s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
776 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
777 | if( p->l_type==F_RDLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
778 | zType = "RDLCK"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
779 | }else if( p->l_type==F_WRLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
780 | zType = "WRLCK"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
781 | }else if( p->l_type==F_UNLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
782 | zType = "UNLCK"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
783 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
784 | assert( 0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
785 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
786 | assert( p->l_whence==SEEK_SET ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
787 | s = osFcntl(fd, op, p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
788 | savedErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
789 | sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
790 | threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
791 | (int)p->l_pid, s); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
792 | if( s==(-1) && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
793 | struct flock l2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
794 | l2 = *p; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
795 | osFcntl(fd, F_GETLK, &l2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
796 | if( l2.l_type==F_RDLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
797 | zType = "RDLCK"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
798 | }else if( l2.l_type==F_WRLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
799 | zType = "WRLCK"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
800 | }else if( l2.l_type==F_UNLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
801 | zType = "UNLCK"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
802 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
803 | assert( 0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
804 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
805 | sqlite3DebugPrintf("fcntl-failure-reason: %s %d %d %d\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
806 | zType, (int)l2.l_start, (int)l2.l_len, (int)l2.l_pid); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
807 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
808 | errno = savedErrno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
809 | return s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
810 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
811 | #undef osFcntl | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
812 | #define osFcntl lockTrace | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
813 | #endif /* SQLITE_LOCK_TRACE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
814 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
815 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
816 | ** Retry ftruncate() calls that fail due to EINTR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
817 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
818 | ** All calls to ftruncate() within this file should be made through | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
819 | ** this wrapper. On the Android platform, bypassing the logic below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
820 | ** could lead to a corrupt database. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
821 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
822 | static int robust_ftruncate(int h, sqlite3_int64 sz){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
823 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
824 | #ifdef __ANDROID__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
825 | /* On Android, ftruncate() always uses 32-bit offsets, even if | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
826 | ** _FILE_OFFSET_BITS=64 is defined. This means it is unsafe to attempt to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
827 | ** truncate a file to any size larger than 2GiB. Silently ignore any | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
828 | ** such attempts. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
829 | if( sz>(sqlite3_int64)0x7FFFFFFF ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
830 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
831 | }else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
832 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
833 | do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR ); executed 7331 times by 36 tests: end of block Executed by:
| 0-7331 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
834 | return rc; executed 7331 times by 36 tests: return rc; Executed by:
| 7331 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
835 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
836 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
837 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
838 | ** This routine translates a standard POSIX errno code into something | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
839 | ** useful to the clients of the sqlite3 functions. Specifically, it is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
840 | ** intended to translate a variety of "try again" errors into SQLITE_BUSY | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
841 | ** and a variety of "please close the file descriptor NOW" errors into | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
842 | ** SQLITE_IOERR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
843 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
844 | ** Errors during initialization of locks, or file system support for locks, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
845 | ** should handle ENOLCK, ENOTSUP, EOPNOTSUPP separately. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
846 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
847 | static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
848 | assert( (sqliteIOErr == SQLITE_IOERR_LOCK) || | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
849 | (sqliteIOErr == SQLITE_IOERR_UNLOCK) || | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
850 | (sqliteIOErr == SQLITE_IOERR_RDLOCK) || | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
851 | (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
852 | switch (posixError) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
853 | case EACCES: never executed: case 13 : | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
854 | case EAGAIN: executed 87 times by 44 tests: case 11 : Executed by:
| 87 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
855 | case ETIMEDOUT: never executed: case 110 : | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
856 | case EBUSY: never executed: case 16 : | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
857 | case EINTR: never executed: case 4 : | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
858 | case ENOLCK: never executed: case 37 : | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
859 | /* random NFS retry error, unless during file system support | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
860 | * introspection, in which it actually means what it says */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
861 | return SQLITE_BUSY; executed 87 times by 44 tests: return 5; Executed by:
| 87 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
862 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
863 | case EPERM: never executed: case 1 : | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
864 | return SQLITE_PERM; never executed: return 3; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
865 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
866 | default: executed 3 times by 1 test: default: Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
867 | return sqliteIOErr; executed 3 times by 1 test: return sqliteIOErr; Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
868 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
869 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
871 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
872 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
873 | ****************** Begin Unique File ID Utility Used By VxWorks *************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
874 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
875 | ** On most versions of unix, we can get a unique ID for a file by concatenating | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
876 | ** the device number and the inode number. But this does not work on VxWorks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
877 | ** On VxWorks, a unique file id must be based on the canonical filename. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
878 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
879 | ** A pointer to an instance of the following structure can be used as a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
880 | ** unique file ID in VxWorks. Each instance of this structure contains | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
881 | ** a copy of the canonical filename. There is also a reference count. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
882 | ** The structure is reclaimed when the number of pointers to it drops to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
883 | ** zero. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
884 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
885 | ** There are never very many files open at one time and lookups are not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
886 | ** a performance-critical path, so it is sufficient to put these | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
887 | ** structures on a linked list. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
888 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
889 | struct vxworksFileId { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
890 | struct vxworksFileId *pNext; /* Next in a list of them all */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
891 | int nRef; /* Number of references to this one */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
892 | int nName; /* Length of the zCanonicalName[] string */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
893 | char *zCanonicalName; /* Canonical filename */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
894 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
895 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
896 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
897 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
898 | ** All unique filenames are held on a linked list headed by this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
899 | ** variable: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
900 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
901 | static struct vxworksFileId *vxworksFileList = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
902 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
903 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
904 | ** Simplify a filename into its canonical form | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
905 | ** by making the following changes: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
906 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
907 | ** * removing any trailing and duplicate / | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
908 | ** * convert /./ into just / | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
909 | ** * convert /A/../ where A is any simple name into just / | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
910 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
911 | ** Changes are made in-place. Return the new name length. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
912 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
913 | ** The original filename is in z[0..n-1]. Return the number of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
914 | ** characters in the simplified name. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
915 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
916 | static int vxworksSimplifyName(char *z, int n){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
917 | int i, j; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
918 | while( n>1 && z[n-1]=='/' ){ n--; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
919 | for(i=j=0; i<n; i++){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
920 | if( z[i]=='/' ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
921 | if( z[i+1]=='/' ) continue; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
922 | if( z[i+1]=='.' && i+2<n && z[i+2]=='/' ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
923 | i += 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
924 | continue; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
925 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
926 | if( z[i+1]=='.' && i+3<n && z[i+2]=='.' && z[i+3]=='/' ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
927 | while( j>0 && z[j-1]!='/' ){ j--; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
928 | if( j>0 ){ j--; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
929 | i += 2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
930 | continue; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
931 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
932 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
933 | z[j++] = z[i]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
934 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
935 | z[j] = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
936 | return j; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
937 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
938 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
939 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
940 | ** Find a unique file ID for the given absolute pathname. Return | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
941 | ** a pointer to the vxworksFileId object. This pointer is the unique | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
942 | ** file ID. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
943 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
944 | ** The nRef field of the vxworksFileId object is incremented before | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
945 | ** the object is returned. A new vxworksFileId object is created | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
946 | ** and added to the global list if necessary. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
947 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
948 | ** If a memory allocation error occurs, return NULL. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
949 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
950 | static struct vxworksFileId *vxworksFindFileId(const char *zAbsoluteName){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
951 | struct vxworksFileId *pNew; /* search key and new file ID */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
952 | struct vxworksFileId *pCandidate; /* For looping over existing file IDs */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
953 | int n; /* Length of zAbsoluteName string */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
954 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
955 | assert( zAbsoluteName[0]=='/' ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
956 | n = (int)strlen(zAbsoluteName); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
957 | pNew = sqlite3_malloc64( sizeof(*pNew) + (n+1) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
958 | if( pNew==0 ) return 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
959 | pNew->zCanonicalName = (char*)&pNew[1]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
960 | memcpy(pNew->zCanonicalName, zAbsoluteName, n+1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
961 | n = vxworksSimplifyName(pNew->zCanonicalName, n); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
962 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
963 | /* Search for an existing entry that matching the canonical name. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
964 | ** If found, increment the reference count and return a pointer to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
965 | ** the existing file ID. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
966 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
967 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
968 | for(pCandidate=vxworksFileList; pCandidate; pCandidate=pCandidate->pNext){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
969 | if( pCandidate->nName==n | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
970 | && memcmp(pCandidate->zCanonicalName, pNew->zCanonicalName, n)==0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
971 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
972 | sqlite3_free(pNew); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
973 | pCandidate->nRef++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
974 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
975 | return pCandidate; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
976 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
977 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
978 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
979 | /* No match was found. We will make a new file ID */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
980 | pNew->nRef = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
981 | pNew->nName = n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
982 | pNew->pNext = vxworksFileList; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
983 | vxworksFileList = pNew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
984 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
985 | return pNew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
986 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
987 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
988 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
989 | ** Decrement the reference count on a vxworksFileId object. Free | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
990 | ** the object when the reference count reaches zero. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
991 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
992 | static void vxworksReleaseFileId(struct vxworksFileId *pId){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
993 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
994 | assert( pId->nRef>0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
995 | pId->nRef--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
996 | if( pId->nRef==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
997 | struct vxworksFileId **pp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
998 | for(pp=&vxworksFileList; *pp && *pp!=pId; pp = &((*pp)->pNext)){} | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
999 | assert( *pp==pId ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1000 | *pp = pId->pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1001 | sqlite3_free(pId); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1002 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1003 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1004 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1005 | #endif /* OS_VXWORKS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1006 | /*************** End of Unique File ID Utility Used By VxWorks **************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1007 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1008 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1009 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1010 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1011 | *************************** Posix Advisory Locking **************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1012 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1013 | ** POSIX advisory locks are broken by design. ANSI STD 1003.1 (1996) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1014 | ** section 6.5.2.2 lines 483 through 490 specify that when a process | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1015 | ** sets or clears a lock, that operation overrides any prior locks set | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1016 | ** by the same process. It does not explicitly say so, but this implies | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1017 | ** that it overrides locks set by the same process using a different | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1018 | ** file descriptor. Consider this test case: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1019 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1020 | ** int fd1 = open("./file1", O_RDWR|O_CREAT, 0644); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1021 | ** int fd2 = open("./file2", O_RDWR|O_CREAT, 0644); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1022 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1023 | ** Suppose ./file1 and ./file2 are really the same file (because | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1024 | ** one is a hard or symbolic link to the other) then if you set | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1025 | ** an exclusive lock on fd1, then try to get an exclusive lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1026 | ** on fd2, it works. I would have expected the second lock to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1027 | ** fail since there was already a lock on the file due to fd1. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1028 | ** But not so. Since both locks came from the same process, the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1029 | ** second overrides the first, even though they were on different | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1030 | ** file descriptors opened on different file names. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1031 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1032 | ** This means that we cannot use POSIX locks to synchronize file access | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1033 | ** among competing threads of the same process. POSIX locks will work fine | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1034 | ** to synchronize access for threads in separate processes, but not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1035 | ** threads within the same process. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1036 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1037 | ** To work around the problem, SQLite has to manage file locks internally | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1038 | ** on its own. Whenever a new database is opened, we have to find the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1039 | ** specific inode of the database file (the inode is determined by the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1040 | ** st_dev and st_ino fields of the stat structure that fstat() fills in) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1041 | ** and check for locks already existing on that inode. When locks are | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1042 | ** created or removed, we have to look at our own internal record of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1043 | ** locks to see if another thread has previously set a lock on that same | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1044 | ** inode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1045 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1046 | ** (Aside: The use of inode numbers as unique IDs does not work on VxWorks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1047 | ** For VxWorks, we have to use the alternative unique ID system based on | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1048 | ** canonical filename and implemented in the previous division.) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1049 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1050 | ** The sqlite3_file structure for POSIX is no longer just an integer file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1051 | ** descriptor. It is now a structure that holds the integer file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1052 | ** descriptor and a pointer to a structure that describes the internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1053 | ** locks on the corresponding inode. There is one locking structure | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1054 | ** per inode, so if the same inode is opened twice, both unixFile structures | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1055 | ** point to the same locking structure. The locking structure keeps | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1056 | ** a reference count (so we will know when to delete it) and a "cnt" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1057 | ** field that tells us its internal lock status. cnt==0 means the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1058 | ** file is unlocked. cnt==-1 means the file has an exclusive lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1059 | ** cnt>0 means there are cnt shared locks on the file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1060 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1061 | ** Any attempt to lock or unlock a file first checks the locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1062 | ** structure. The fcntl() system call is only invoked to set a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1063 | ** POSIX lock if the internal lock structure transitions between | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1064 | ** a locked and an unlocked state. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1065 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1066 | ** But wait: there are yet more problems with POSIX advisory locks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1067 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1068 | ** If you close a file descriptor that points to a file that has locks, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1069 | ** all locks on that file that are owned by the current process are | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1070 | ** released. To work around this problem, each unixInodeInfo object | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1071 | ** maintains a count of the number of pending locks on tha inode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1072 | ** When an attempt is made to close an unixFile, if there are | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1073 | ** other unixFile open on the same inode that are holding locks, the call | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1074 | ** to close() the file descriptor is deferred until all of the locks clear. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1075 | ** The unixInodeInfo structure keeps a list of file descriptors that need to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1076 | ** be closed and that list is walked (and cleared) when the last lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1077 | ** clears. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1078 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1079 | ** Yet another problem: LinuxThreads do not play well with posix locks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1080 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1081 | ** Many older versions of linux use the LinuxThreads library which is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1082 | ** not posix compliant. Under LinuxThreads, a lock created by thread | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1083 | ** A cannot be modified or overridden by a different thread B. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1084 | ** Only thread A can modify the lock. Locking behavior is correct | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1085 | ** if the appliation uses the newer Native Posix Thread Library (NPTL) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1086 | ** on linux - with NPTL a lock created by thread A can override locks | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1087 | ** in thread B. But there is no way to know at compile-time which | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1088 | ** threading library is being used. So there is no way to know at | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1089 | ** compile-time whether or not thread A can override locks on thread B. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1090 | ** One has to do a run-time check to discover the behavior of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1091 | ** current process. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1092 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1093 | ** SQLite used to support LinuxThreads. But support for LinuxThreads | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1094 | ** was dropped beginning with version 3.7.0. SQLite will still work with | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1095 | ** LinuxThreads provided that (1) there is no more than one connection | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1096 | ** per database file in the same process and (2) database connections | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1097 | ** do not move across threads. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1098 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1099 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1100 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1101 | ** An instance of the following structure serves as the key used | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1102 | ** to locate a particular unixInodeInfo object. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1103 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1104 | struct unixFileId { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1105 | dev_t dev; /* Device number */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1106 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1107 | struct vxworksFileId *pId; /* Unique file ID for vxworks. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1108 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1109 | /* We are told that some versions of Android contain a bug that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1110 | ** sizes ino_t at only 32-bits instead of 64-bits. (See | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1111 | ** https://android-review.googlesource.com/#/c/115351/3/dist/sqlite3.c) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1112 | ** To work around this, always allocate 64-bits for the inode number. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1113 | ** On small machines that only have 32-bit inodes, this wastes 4 bytes, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1114 | ** but that should not be a big deal. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1115 | /* WAS: ino_t ino; */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1116 | u64 ino; /* Inode number */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1117 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1118 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1119 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1120 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1121 | ** An instance of the following structure is allocated for each open | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1122 | ** inode. Or, on LinuxThreads, there is one of these structures for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1123 | ** each inode opened by each thread. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1124 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1125 | ** A single inode can have multiple file descriptors, so each unixFile | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1126 | ** structure contains a pointer to an instance of this object and this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1127 | ** object keeps a count of the number of unixFile pointing to it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1128 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1129 | ** Mutex rules: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1130 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1131 | ** (1) Only the pLockMutex mutex must be held in order to read or write | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1132 | ** any of the locking fields: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1133 | ** nShared, nLock, eFileLock, bProcessLock, pUnused | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1134 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1135 | ** (2) When nRef>0, then the following fields are unchanging and can | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1136 | ** be read (but not written) without holding any mutex: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1137 | ** fileId, pLockMutex | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1138 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1139 | ** (3) With the exceptions above, all the fields may only be read | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1140 | ** or written while holding the global unixBigLock mutex. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1141 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1142 | ** Deadlock prevention: The global unixBigLock mutex may not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1143 | ** be acquired while holding the pLockMutex mutex. If both unixBigLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1144 | ** and pLockMutex are needed, then unixBigLock must be acquired first. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1145 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1146 | struct unixInodeInfo { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1147 | struct unixFileId fileId; /* The lookup key */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1148 | sqlite3_mutex *pLockMutex; /* Hold this mutex for... */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1149 | int nShared; /* Number of SHARED locks held */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1150 | int nLock; /* Number of outstanding file locks */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1151 | unsigned char eFileLock; /* One of SHARED_LOCK, RESERVED_LOCK etc. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1152 | unsigned char bProcessLock; /* An exclusive process lock is held */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1153 | UnixUnusedFd *pUnused; /* Unused file descriptors to close */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1154 | int nRef; /* Number of pointers to this structure */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1155 | unixShmNode *pShmNode; /* Shared memory associated with this inode */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1156 | unixInodeInfo *pNext; /* List of all unixInodeInfo objects */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1157 | unixInodeInfo *pPrev; /* .... doubly linked */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1158 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1159 | unsigned long long sharedByte; /* for AFP simulated shared lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1160 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1161 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1162 | sem_t *pSem; /* Named POSIX semaphore */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1163 | char aSemName[MAX_PATHNAME+2]; /* Name of that semaphore */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1164 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1165 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1166 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1167 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1168 | ** A lists of all unixInodeInfo objects. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1169 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1170 | static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1171 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1172 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1173 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1174 | ** True if the inode mutex is held, or not. Used only within assert() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1175 | ** to help verify correct mutex usage. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1176 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1177 | int unixFileMutexHeld(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1178 | assert( pFile->pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1179 | return sqlite3_mutex_held(pFile->pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1180 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1181 | int unixFileMutexNotheld(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1182 | assert( pFile->pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1183 | return sqlite3_mutex_notheld(pFile->pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1184 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1185 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1186 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1187 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1188 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1189 | ** This function - unixLogErrorAtLine(), is only ever called via the macro | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1190 | ** unixLogError(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1191 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1192 | ** It is invoked after an error occurs in an OS function and errno has been | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1193 | ** set. It logs a message using sqlite3_log() containing the current value of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1194 | ** errno and, if possible, the human-readable equivalent from strerror() or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1195 | ** strerror_r(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1196 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1197 | ** The first argument passed to the macro should be the error code that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1198 | ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1199 | ** The two subsequent arguments should be the name of the OS function that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1200 | ** failed (e.g. "unlink", "open") and the associated file-system path, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1201 | ** if any. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1202 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1203 | #define unixLogError(a,b,c) unixLogErrorAtLine(a,b,c,__LINE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1204 | static int unixLogErrorAtLine( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1205 | int errcode, /* SQLite error code */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1206 | const char *zFunc, /* Name of OS function that failed */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1207 | const char *zPath, /* File path associated with error */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1208 | int iLine /* Source line number where error occurred */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1209 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1210 | char *zErr; /* Message from strerror() or equivalent */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1211 | int iErrno = errno; /* Saved syscall error number */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1212 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1213 | /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1214 | ** the strerror() function to obtain the human-readable error message | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1215 | ** equivalent to errno. Otherwise, use strerror_r(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1216 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1217 | #if SQLITE_THREADSAFE && defined(HAVE_STRERROR_R) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1218 | char aErr[80]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1219 | memset(aErr, 0, sizeof(aErr)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1220 | zErr = aErr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1221 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1222 | /* If STRERROR_R_CHAR_P (set by autoconf scripts) or __USE_GNU is defined, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1223 | ** assume that the system provides the GNU version of strerror_r() that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1224 | ** returns a pointer to a buffer containing the error message. That pointer | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1225 | ** may point to aErr[], or it may point to some static storage somewhere. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1226 | ** Otherwise, assume that the system provides the POSIX version of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1227 | ** strerror_r(), which always writes an error message into aErr[]. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1228 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1229 | ** If the code incorrectly assumes that it is the POSIX version that is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1230 | ** available, the error message will often be an empty string. Not a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1231 | ** huge problem. Incorrectly concluding that the GNU version is available | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1232 | ** could lead to a segfault though. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1233 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1234 | #if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1235 | zErr = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1236 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1237 | strerror_r(iErrno, aErr, sizeof(aErr)-1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1238 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1239 | #elif SQLITE_THREADSAFE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1240 | /* This is a threadsafe build, but strerror_r() is not available. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1241 | zErr = ""; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1242 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1243 | /* Non-threadsafe build, use strerror(). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1244 | zErr = strerror(iErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1245 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1246 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1247 | if( zPath==0 ) zPath = ""; never executed: zPath = "";
| 0-516 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1248 | sqlite3_log(errcode, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1249 | "os_unix.c:%d: (%d) %s(%s) - %s", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1250 | iLine, iErrno, zFunc, zPath, zErr | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1251 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1252 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1253 | return errcode; executed 516 times by 1 test: return errcode; Executed by:
| 516 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1254 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1255 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1256 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1257 | ** Close a file descriptor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1258 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1259 | ** We assume that close() almost always works, since it is only in a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1260 | ** very sick application or on a very sick platform that it might fail. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1261 | ** If it does fail, simply leak the file descriptor, but do log the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1262 | ** error. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1263 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1264 | ** Note that it is not safe to retry close() after EINTR since the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1265 | ** file descriptor might have already been reused by another thread. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1266 | ** So we don't even try to recover from an EINTR. Just log the error | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1267 | ** and move on. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1268 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1269 | static void robust_close(unixFile *pFile, int h, int lineno){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1270 | if( osClose(h) ){
| 0-106261 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1271 | unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1272 | pFile ? pFile->zPath : 0, lineno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1273 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1274 | } executed 106261 times by 416 tests: end of block Executed by:
| 106261 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1275 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1276 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1277 | ** Set the pFile->lastErrno. Do this in a subroutine as that provides | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1278 | ** a convenient place to set a breakpoint. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1279 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1280 | static void storeLastErrno(unixFile *pFile, int error){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1281 | pFile->lastErrno = error; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1282 | } executed 140006 times by 438 tests: end of block Executed by:
| 140006 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1283 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1284 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1285 | ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1286 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1287 | static void closePendingFds(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1288 | unixInodeInfo *pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1289 | UnixUnusedFd *p; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1290 | UnixUnusedFd *pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1291 | assert( unixFileMutexHeld(pFile) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1292 | for(p=pInode->pUnused; p; p=pNext){
| 471-151101 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1293 | pNext = p->pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1294 | robust_close(pFile, p->fd, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1295 | sqlite3_free(p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1296 | } executed 471 times by 1 test: end of block Executed by:
| 471 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1297 | pInode->pUnused = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1298 | } executed 151101 times by 427 tests: end of block Executed by:
| 151101 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1299 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1300 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1301 | ** Release a unixInodeInfo structure previously allocated by findInodeInfo(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1302 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1303 | ** The mutex entered using the unixEnterMutex() function must be held | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1304 | ** when this function is called. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1305 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1306 | static void releaseInodeInfo(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1307 | unixInodeInfo *pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1308 | assert( unixMutexHeld() ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1309 | assert( unixFileMutexNotheld(pFile) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1310 | if( ALWAYS(pInode) ){
| 0-31857 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1311 | pInode->nRef--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1312 | if( pInode->nRef==0 ){
| 12115-19742 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1313 | assert( pInode->pShmNode==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1314 | sqlite3_mutex_enter(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1315 | closePendingFds(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1316 | sqlite3_mutex_leave(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1317 | if( pInode->pPrev ){
| 9326-10416 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1318 | assert( pInode->pPrev->pNext==pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1319 | pInode->pPrev->pNext = pInode->pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1320 | }else{ executed 9326 times by 10 tests: end of block Executed by:
| 9326 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1321 | assert( inodeList==pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1322 | inodeList = pInode->pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1323 | } executed 10416 times by 66 tests: end of block Executed by:
| 10416 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1324 | if( pInode->pNext ){
| 9541-10201 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1325 | assert( pInode->pNext->pPrev==pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1326 | pInode->pNext->pPrev = pInode->pPrev; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1327 | } executed 9541 times by 2 tests: end of block Executed by:
| 9541 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1328 | sqlite3_mutex_free(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1329 | sqlite3_free(pInode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1330 | } executed 19742 times by 66 tests: end of block Executed by:
| 19742 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1331 | } executed 31857 times by 66 tests: end of block Executed by:
| 31857 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1332 | } executed 31857 times by 66 tests: end of block Executed by:
| 31857 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1333 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1334 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1335 | ** Given a file descriptor, locate the unixInodeInfo object that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1336 | ** describes that file descriptor. Create a new one if necessary. The | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1337 | ** return value might be uninitialized if an error occurs. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1338 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1339 | ** The mutex entered using the unixEnterMutex() function must be held | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1340 | ** when this function is called. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1341 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1342 | ** Return an appropriate error code. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1343 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1344 | static int findInodeInfo( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1345 | unixFile *pFile, /* Unix file with file desc used in the key */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1346 | unixInodeInfo **ppInode /* Return the unixInodeInfo object here */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1347 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1348 | int rc; /* System call return code */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1349 | int fd; /* The file descriptor for pFile */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1350 | struct unixFileId fileId; /* Lookup key for the unixInodeInfo */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1351 | struct stat statbuf; /* Low-level file information */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1352 | unixInodeInfo *pInode = 0; /* Candidate unixInodeInfo object */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1353 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1354 | assert( unixMutexHeld() ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1355 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1356 | /* Get low-level information about the file that we can used to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1357 | ** create a unique name for the file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1358 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1359 | fd = pFile->h; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1360 | rc = osFstat(fd, &statbuf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1361 | if( rc!=0 ){
| 0-32248 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1362 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1363 | #if defined(EOVERFLOW) && defined(SQLITE_DISABLE_LFS) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1364 | if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1365 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1366 | return SQLITE_IOERR; never executed: return 10; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1367 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1368 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1369 | #ifdef __APPLE__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1370 | /* On OS X on an msdos filesystem, the inode number is reported | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1371 | ** incorrectly for zero-size files. See ticket #3260. To work | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1372 | ** around this problem (we consider it a bug in OS X, not SQLite) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1373 | ** we always increase the file size to 1 by writing a single byte | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1374 | ** prior to accessing the inode number. The one byte written is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1375 | ** an ASCII 'S' character which also happens to be the first byte | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1376 | ** in the header of every SQLite database. In this way, if there | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1377 | ** is a race condition such that another thread has already populated | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1378 | ** the first page of the database, no damage is done. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1379 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1380 | if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1381 | do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1382 | if( rc!=1 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1383 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1384 | return SQLITE_IOERR; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1385 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1386 | rc = osFstat(fd, &statbuf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1387 | if( rc!=0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1388 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1389 | return SQLITE_IOERR; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1390 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1391 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1392 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1393 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1394 | memset(&fileId, 0, sizeof(fileId)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1395 | fileId.dev = statbuf.st_dev; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1396 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1397 | fileId.pId = pFile->pId; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1398 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1399 | fileId.ino = (u64)statbuf.st_ino; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1400 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1401 | pInode = inodeList; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1402 | while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
| 12115-133079 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1403 | pInode = pInode->pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1404 | } executed 120964 times by 13 tests: end of block Executed by:
| 120964 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1405 | if( pInode==0 ){
| 12115-20133 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1406 | pInode = sqlite3_malloc64( sizeof(*pInode) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1407 | if( pInode==0 ){
| 8-20125 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1408 | return SQLITE_NOMEM_BKPT; executed 8 times by 1 test: return 7; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1409 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1410 | memset(pInode, 0, sizeof(*pInode)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1411 | memcpy(&pInode->fileId, &fileId, sizeof(fileId)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1412 | if( sqlite3GlobalConfig.bCoreMutex ){
| 9-20116 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1413 | pInode->pLockMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1414 | if( pInode->pLockMutex==0 ){
| 8-20108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1415 | sqlite3_free(pInode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1416 | return SQLITE_NOMEM_BKPT; executed 8 times by 1 test: return 7; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1417 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1418 | } executed 20108 times by 438 tests: end of block Executed by:
| 20108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1419 | pInode->nRef = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1420 | pInode->pNext = inodeList; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1421 | pInode->pPrev = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1422 | if( inodeList ) inodeList->pPrev = pInode; executed 10164 times by 13 tests: inodeList->pPrev = pInode; Executed by:
| 9953-10164 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1423 | inodeList = pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1424 | }else{ executed 20117 times by 438 tests: end of block Executed by:
| 20117 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1425 | pInode->nRef++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1426 | } executed 12115 times by 1 test: end of block Executed by:
| 12115 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1427 | *ppInode = pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1428 | return SQLITE_OK; executed 32232 times by 438 tests: return 0; Executed by:
| 32232 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1429 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1430 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1431 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1432 | ** Return TRUE if pFile has been renamed or unlinked since it was first opened. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1433 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1434 | static int fileHasMoved(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1435 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1436 | return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1437 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1438 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1439 | return pFile->pInode!=0 && executed 119153 times by 438 tests: return pFile->pInode!=0 && (((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)(pFile->zPath, &buf)!=0 || (u64)buf.st_ino!=pFile->pInode->fileId.ino); Executed by:
| 9-119153 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1440 | (osStat(pFile->zPath, &buf)!=0 executed 119153 times by 438 tests: return pFile->pInode!=0 && (((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)(pFile->zPath, &buf)!=0 || (u64)buf.st_ino!=pFile->pInode->fileId.ino); Executed by:
| 7-119153 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1441 | || (u64)buf.st_ino!=pFile->pInode->fileId.ino); executed 119153 times by 438 tests: return pFile->pInode!=0 && (((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)(pFile->zPath, &buf)!=0 || (u64)buf.st_ino!=pFile->pInode->fileId.ino); Executed by:
| 11-119153 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1442 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1443 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1444 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1445 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1446 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1447 | ** Check a unixFile that is a database. Verify the following: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1448 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1449 | ** (1) There is exactly one hard link on the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1450 | ** (2) The file is not a symbolic link | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1451 | ** (3) The file has not been renamed or unlinked | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1452 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1453 | ** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1454 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1455 | static void verifyDbFile(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1456 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1457 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1458 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1459 | /* These verifications occurs for the main database only */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1460 | if( pFile->ctrlFlags & UNIXFILE_NOLOCK ) return; executed 45003 times by 425 tests: return; Executed by:
| 45003-64093 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1461 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1462 | rc = osFstat(pFile->h, &buf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1463 | if( rc!=0 ){
| 0-64093 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1464 | sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1465 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1466 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1467 | if( buf.st_nlink==0 ){
| 11-64082 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1468 | sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1469 | return; executed 11 times by 1 test: return; Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1470 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1471 | if( buf.st_nlink>1 ){
| 2-64080 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1472 | sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1473 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1474 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1475 | if( fileHasMoved(pFile) ){
| 1-64079 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1476 | sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1477 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1478 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1479 | } executed 64079 times by 438 tests: end of block Executed by:
| 64079 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1480 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1481 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1482 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1483 | ** This routine checks if there is a RESERVED lock held on the specified | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1484 | ** file by this or any other process. If such a lock is held, set *pResOut | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1485 | ** to a non-zero value otherwise *pResOut is set to zero. The return value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1486 | ** is set to SQLITE_OK unless an I/O error occurs during lock checking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1487 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1488 | static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1489 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1490 | int reserved = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1491 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1492 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1493 | SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); never executed: return (10 | (14<<8));
| 0-2588 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1494 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1495 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1496 | assert( pFile->eFileLock<=SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1497 | sqlite3_mutex_enter(pFile->pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1498 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1499 | /* Check if a thread in this process holds such a lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1500 | if( pFile->pInode->eFileLock>SHARED_LOCK ){
| 67-2521 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1501 | reserved = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1502 | } executed 67 times by 1 test: end of block Executed by:
| 67 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1503 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1504 | /* Otherwise see if some other process holds it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1505 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1506 | #ifndef __DJGPP__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1507 | if( !reserved && !pFile->pInode->bProcessLock ){
| 0-2521 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1508 | struct flock lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1509 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1510 | lock.l_start = RESERVED_BYTE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1511 | lock.l_len = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1512 | lock.l_type = F_WRLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1513 | if( osFcntl(pFile->h, F_GETLK, &lock) ){
| 0-2521 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1514 | rc = SQLITE_IOERR_CHECKRESERVEDLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1515 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1516 | } else if( lock.l_type!=F_UNLCK ){ never executed: end of block
| 0-2506 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1517 | reserved = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1518 | } executed 15 times by 6 tests: end of block Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1519 | } executed 2521 times by 258 tests: end of block Executed by:
| 2521 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1520 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1521 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1522 | sqlite3_mutex_leave(pFile->pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1523 | OSTRACE(("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved)); never executed: sqlite3DebugPrintf ("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved);
| 0-2588 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1524 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1525 | *pResOut = reserved; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1526 | return rc; executed 2588 times by 258 tests: return rc; Executed by:
| 2588 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1527 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1528 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1529 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1530 | ** Set a posix-advisory-lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1531 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1532 | ** There are two versions of this routine. If compiled with | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1533 | ** SQLITE_ENABLE_SETLK_TIMEOUT then the routine has an extra parameter | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1534 | ** which is a pointer to a unixFile. If the unixFile->iBusyTimeout | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1535 | ** value is set, then it is the number of milliseconds to wait before | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1536 | ** failing the lock. The iBusyTimeout value is always reset back to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1537 | ** zero on each call. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1538 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1539 | ** If SQLITE_ENABLE_SETLK_TIMEOUT is not defined, then do a non-blocking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1540 | ** attempt to set the lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1541 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1542 | #ifndef SQLITE_ENABLE_SETLK_TIMEOUT | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1543 | # define osSetPosixAdvisoryLock(h,x,t) osFcntl(h,F_SETLK,x) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1544 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1545 | static int osSetPosixAdvisoryLock( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1546 | int h, /* The file descriptor on which to take the lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1547 | struct flock *pLock, /* The description of the lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1548 | unixFile *pFile /* Structure holding timeout value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1549 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1550 | int rc = osFcntl(h,F_SETLK,pLock); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1551 | while( rc<0 && pFile->iBusyTimeout>0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1552 | /* On systems that support some kind of blocking file lock with a timeout, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1553 | ** make appropriate changes here to invoke that blocking file lock. On | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1554 | ** generic posix, however, there is no such API. So we simply try the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1555 | ** lock once every millisecond until either the timeout expires, or until | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1556 | ** the lock is obtained. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1557 | usleep(1000); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1558 | rc = osFcntl(h,F_SETLK,pLock); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1559 | pFile->iBusyTimeout--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1560 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1561 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1562 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1563 | #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1564 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1565 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1566 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1567 | ** Attempt to set a system-lock on the file pFile. The lock is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1568 | ** described by pLock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1569 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1570 | ** If the pFile was opened read/write from unix-excl, then the only lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1571 | ** ever obtained is an exclusive lock, and it is obtained exactly once | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1572 | ** the first time any lock is attempted. All subsequent system locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1573 | ** operations become no-ops. Locking operations still happen internally, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1574 | ** in order to coordinate access between separate database connections | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1575 | ** within this process, but all of that is handled in memory and the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1576 | ** operating system does not participate. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1577 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1578 | ** This function is a pass-through to fcntl(F_SETLK) if pFile is using | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1579 | ** any VFS other than "unix-excl" or if pFile is opened on "unix-excl" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1580 | ** and is read-only. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1581 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1582 | ** Zero is returned if the call completes successfully, or -1 if a call | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1583 | ** to fcntl() fails. In this case, errno is set appropriately (by fcntl()). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1584 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1585 | static int unixFileLock(unixFile *pFile, struct flock *pLock){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1586 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1587 | unixInodeInfo *pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1588 | assert( pInode!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1589 | assert( sqlite3_mutex_held(pInode->pLockMutex) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1590 | if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){
| 59-739518 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1591 | if( pInode->bProcessLock==0 ){
| 5-54 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1592 | struct flock lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1593 | assert( pInode->nLock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1594 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1595 | lock.l_start = SHARED_FIRST; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1596 | lock.l_len = SHARED_SIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1597 | lock.l_type = F_WRLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1598 | rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1599 | if( rc<0 ) return rc; executed 1 time by 1 test: return rc; Executed by:
| 1-4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1600 | pInode->bProcessLock = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1601 | pInode->nLock++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1602 | }else{ executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1603 | rc = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1604 | } executed 54 times by 1 test: end of block Executed by:
| 54 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1605 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1606 | rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1607 | } executed 739518 times by 435 tests: end of block Executed by:
| 739518 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1608 | return rc; executed 739576 times by 435 tests: return rc; Executed by:
| 739576 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1609 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1610 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1611 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1612 | ** Lock the file with the lock specified by parameter eFileLock - one | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1613 | ** of the following: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1614 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1615 | ** (1) SHARED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1616 | ** (2) RESERVED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1617 | ** (3) PENDING_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1618 | ** (4) EXCLUSIVE_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1619 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1620 | ** Sometimes when requesting one lock state, additional lock states | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1621 | ** are inserted in between. The locking might fail on one of the later | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1622 | ** transitions leaving the lock state different from what it started but | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1623 | ** still short of its goal. The following chart shows the allowed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1624 | ** transitions and the inserted intermediate states: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1625 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1626 | ** UNLOCKED -> SHARED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1627 | ** SHARED -> RESERVED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1628 | ** SHARED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1629 | ** RESERVED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1630 | ** PENDING -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1631 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1632 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1633 | ** routine to lower a locking level. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1634 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1635 | static int unixLock(sqlite3_file *id, int eFileLock){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1636 | /* The following describes the implementation of the various locks and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1637 | ** lock transitions in terms of the POSIX advisory shared and exclusive | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1638 | ** lock primitives (called read-locks and write-locks below, to avoid | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1639 | ** confusion with SQLite lock names). The algorithms are complicated | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1640 | ** slightly in order to be compatible with Windows95 systems simultaneously | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1641 | ** accessing the same database file, in case that is ever required. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1642 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1643 | ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1644 | ** byte', each single bytes at well known offsets, and the 'shared byte | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1645 | ** range', a range of 510 bytes at a well known offset. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1646 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1647 | ** To obtain a SHARED lock, a read-lock is obtained on the 'pending | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1648 | ** byte'. If this is successful, 'shared byte range' is read-locked | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1649 | ** and the lock on the 'pending byte' released. (Legacy note: When | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1650 | ** SQLite was first developed, Windows95 systems were still very common, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1651 | ** and Widnows95 lacks a shared-lock capability. So on Windows95, a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1652 | ** single randomly selected by from the 'shared byte range' is locked. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1653 | ** Windows95 is now pretty much extinct, but this work-around for the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1654 | ** lack of shared-locks on Windows95 lives on, for backwards | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1655 | ** compatibility.) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1656 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1657 | ** A process may only obtain a RESERVED lock after it has a SHARED lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1658 | ** A RESERVED lock is implemented by grabbing a write-lock on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1659 | ** 'reserved byte'. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1660 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1661 | ** A process may only obtain a PENDING lock after it has obtained a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1662 | ** SHARED lock. A PENDING lock is implemented by obtaining a write-lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1663 | ** on the 'pending byte'. This ensures that no new SHARED locks can be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1664 | ** obtained, but existing SHARED locks are allowed to persist. A process | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1665 | ** does not have to obtain a RESERVED lock on the way to a PENDING lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1666 | ** This property is used by the algorithm for rolling back a journal file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1667 | ** after a crash. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1668 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1669 | ** An EXCLUSIVE lock, obtained after a PENDING lock is held, is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1670 | ** implemented by obtaining a write-lock on the entire 'shared byte | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1671 | ** range'. Since all other locks require a read-lock on one of the bytes | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1672 | ** within this range, this ensures that no other locks are held on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1673 | ** database. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1674 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1675 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1676 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1677 | unixInodeInfo *pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1678 | struct flock lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1679 | int tErrno = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1680 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1681 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1682 | OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, never executed: sqlite3DebugPrintf ("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, azFileLock(eFileLock), azFileLock(pFile->eFileLock), azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared, (pid_t)getpid()) ;
| 0-219936 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1683 | azFileLock(eFileLock), azFileLock(pFile->eFileLock), never executed: sqlite3DebugPrintf ("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, azFileLock(eFileLock), azFileLock(pFile->eFileLock), azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared, (pid_t)getpid()) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1684 | azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared, never executed: sqlite3DebugPrintf ("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, azFileLock(eFileLock), azFileLock(pFile->eFileLock), azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared, (pid_t)getpid()) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1685 | osGetpid(0))); never executed: sqlite3DebugPrintf ("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, azFileLock(eFileLock), azFileLock(pFile->eFileLock), azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared, (pid_t)getpid()) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1686 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1687 | /* If there is already a lock of this type or more restrictive on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1688 | ** unixFile, do nothing. Don't use the end_lock: exit path, as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1689 | ** unixEnterMutex() hasn't been called yet. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1690 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1691 | if( pFile->eFileLock>=eFileLock ){
| 29-219907 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1692 | OSTRACE(("LOCK %d %s ok (already held) (unix)\n", pFile->h, never executed: sqlite3DebugPrintf ("LOCK %d %s ok (already held) (unix)\n", pFile->h, azFileLock(eFileLock)) ;
| 0-29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1693 | azFileLock(eFileLock))); never executed: sqlite3DebugPrintf ("LOCK %d %s ok (already held) (unix)\n", pFile->h, azFileLock(eFileLock)) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1694 | return SQLITE_OK; executed 29 times by 1 test: return 0; Executed by:
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1695 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1696 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1697 | /* Make sure the locking sequence is correct. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1698 | ** (1) We never move from unlocked to anything higher than shared lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1699 | ** (2) SQLite never explicitly requests a pendig lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1700 | ** (3) A shared lock is always held when a reserve lock is requested. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1701 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1702 | assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1703 | assert( eFileLock!=PENDING_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1704 | assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1705 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1706 | /* This mutex is needed because pFile->pInode is shared across threads | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1707 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1708 | pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1709 | sqlite3_mutex_enter(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1710 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1711 | /* If some thread using this PID has a lock via a different unixFile* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1712 | ** handle that precludes the requested lock, return BUSY. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1713 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1714 | if( (pFile->eFileLock!=pInode->eFileLock &&
| 1767-218140 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1715 | (pInode->eFileLock>=PENDING_LOCK || eFileLock>SHARED_LOCK))
| 64-1037 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1716 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1717 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1718 | goto end_lock; executed 1101 times by 1 test: goto end_lock; Executed by:
| 1101 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1719 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1720 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1721 | /* If a SHARED lock is requested, and some thread using this PID already | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1722 | ** has a SHARED or RESERVED lock, then increment reference counts and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1723 | ** return SQLITE_OK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1724 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1725 | if( eFileLock==SHARED_LOCK &&
| 86396-132410 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1726 | (pInode->eFileLock==SHARED_LOCK || pInode->eFileLock==RESERVED_LOCK) ){
| 140-131884 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1727 | assert( eFileLock==SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1728 | assert( pFile->eFileLock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1729 | assert( pInode->nShared>0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1730 | pFile->eFileLock = SHARED_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1731 | pInode->nShared++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1732 | pInode->nLock++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1733 | goto end_lock; executed 666 times by 1 test: goto end_lock; Executed by:
| 666 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1734 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1735 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1736 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1737 | /* A PENDING lock is needed before acquiring a SHARED lock and before | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1738 | ** acquiring an EXCLUSIVE lock. For the SHARED lock, the PENDING will | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1739 | ** be released. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1740 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1741 | lock.l_len = 1L; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1742 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1743 | if( eFileLock==SHARED_LOCK
| 86396-131744 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1744 | || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
| 1854-43293 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1745 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1746 | lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
| 41439-131744 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1747 | lock.l_start = PENDING_BYTE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1748 | if( unixFileLock(pFile, &lock) ){
| 11-173172 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1749 | tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1750 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1751 | if( rc!=SQLITE_BUSY ){
| 3-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1752 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1753 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1754 | goto end_lock; executed 11 times by 7 tests: goto end_lock; Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1755 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1756 | } executed 173172 times by 435 tests: end of block Executed by:
| 173172 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1757 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1758 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1759 | /* If control gets to this point, then actually go ahead and make | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1760 | ** operating system calls for the specified lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1761 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1762 | if( eFileLock==SHARED_LOCK ){
| 86392-131737 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1763 | assert( pInode->nShared==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1764 | assert( pInode->eFileLock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1765 | assert( rc==SQLITE_OK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1766 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1767 | /* Now get the read-lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1768 | lock.l_start = SHARED_FIRST; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1769 | lock.l_len = SHARED_SIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1770 | if( unixFileLock(pFile, &lock) ){
| 1-131736 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1771 | tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1772 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1773 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1774 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1775 | /* Drop the temporary PENDING lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1776 | lock.l_start = PENDING_BYTE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1777 | lock.l_len = 1L; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1778 | lock.l_type = F_UNLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1779 | if( unixFileLock(pFile, &lock) && rc==SQLITE_OK ){
| 0-131737 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1780 | /* This could happen with a network mount */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1781 | tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1782 | rc = SQLITE_IOERR_UNLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1783 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1784 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1785 | if( rc ){
| 1-131736 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1786 | if( rc!=SQLITE_BUSY ){
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1787 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1788 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1789 | goto end_lock; executed 1 time by 1 test: goto end_lock; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1790 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1791 | pFile->eFileLock = SHARED_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1792 | pInode->nLock++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1793 | pInode->nShared = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1794 | } executed 131736 times by 435 tests: end of block Executed by:
| 131736 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1795 | }else if( eFileLock==EXCLUSIVE_LOCK && pInode->nShared>1 ){
| 2304-43289 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1796 | /* We are trying for an exclusive lock but another thread in this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1797 | ** same process is still holding a shared lock. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1798 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1799 | }else{ executed 2304 times by 1 test: end of block Executed by:
| 2304 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1800 | /* The request was for a RESERVED or EXCLUSIVE lock. It is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1801 | ** assumed that there is a SHARED or greater lock on the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1802 | ** already. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1803 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1804 | assert( 0!=pFile->eFileLock ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1805 | lock.l_type = F_WRLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1806 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1807 | assert( eFileLock==RESERVED_LOCK || eFileLock==EXCLUSIVE_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1808 | if( eFileLock==RESERVED_LOCK ){
| 40985-43103 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1809 | lock.l_start = RESERVED_BYTE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1810 | lock.l_len = 1L; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1811 | }else{ executed 43103 times by 382 tests: end of block Executed by:
| 43103 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1812 | lock.l_start = SHARED_FIRST; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1813 | lock.l_len = SHARED_SIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1814 | } executed 40985 times by 166 tests: end of block Executed by:
| 40985 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1815 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1816 | if( unixFileLock(pFile, &lock) ){
| 78-84010 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1817 | tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1818 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1819 | if( rc!=SQLITE_BUSY ){
| 0-78 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1820 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1821 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1822 | } executed 78 times by 39 tests: end of block Executed by:
| 78 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1823 | } executed 84088 times by 415 tests: end of block Executed by:
| 84088 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1824 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1825 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1826 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1827 | /* Set up the transaction-counter change checking flags when | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1828 | ** transitioning from a SHARED to a RESERVED lock. The change | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1829 | ** from SHARED to RESERVED marks the beginning of a normal | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1830 | ** write operation (not a hot journal rollback). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1831 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1832 | if( rc==SQLITE_OK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1833 | && pFile->eFileLock<=SHARED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1834 | && eFileLock==RESERVED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1835 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1836 | pFile->transCntrChng = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1837 | pFile->dbUpdate = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1838 | pFile->inNormalWrite = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1839 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1840 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1841 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1842 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1843 | if( rc==SQLITE_OK ){
| 2382-215746 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1844 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1845 | pInode->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1846 | }else if( eFileLock==EXCLUSIVE_LOCK ){ executed 215746 times by 435 tests: end of block Executed by:
| 8-215746 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1847 | pFile->eFileLock = PENDING_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1848 | pInode->eFileLock = PENDING_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1849 | } executed 2374 times by 36 tests: end of block Executed by:
| 2374 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1850 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1851 | end_lock: code before this statement executed 218128 times by 435 tests: end_lock: Executed by:
| 218128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1852 | sqlite3_mutex_leave(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1853 | OSTRACE(("LOCK %d %s %s (unix)\n", pFile->h, azFileLock(eFileLock), never executed: sqlite3DebugPrintf ("LOCK %d %s %s (unix)\n", pFile->h, azFileLock(eFileLock), rc==0 ? "ok" : "failed") ;
| 0-219907 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1854 | rc==SQLITE_OK ? "ok" : "failed")); never executed: sqlite3DebugPrintf ("LOCK %d %s %s (unix)\n", pFile->h, azFileLock(eFileLock), rc==0 ? "ok" : "failed") ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1855 | return rc; executed 219907 times by 436 tests: return rc; Executed by:
| 219907 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1856 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1857 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1858 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1859 | ** Add the file descriptor used by file handle pFile to the corresponding | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1860 | ** pUnused list. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1861 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1862 | static void setPendingFd(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1863 | unixInodeInfo *pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1864 | UnixUnusedFd *p = pFile->pPreallocatedUnused; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1865 | assert( unixFileMutexHeld(pFile) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1866 | p->pNext = pInode->pUnused; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1867 | pInode->pUnused = p; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1868 | pFile->h = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1869 | pFile->pPreallocatedUnused = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1870 | } executed 10551 times by 1 test: end of block Executed by:
| 10551 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1871 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1872 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1873 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1874 | ** must be either NO_LOCK or SHARED_LOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1875 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1876 | ** If the locking level of the file descriptor is already at or below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1877 | ** the requested locking level, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1878 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1879 | ** If handleNFSUnlock is true, then on downgrading an EXCLUSIVE_LOCK to SHARED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1880 | ** the byte range is divided into 2 parts and the first part is unlocked then | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1881 | ** set to a read lock, then the other part is simply unlocked. This works | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1882 | ** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1883 | ** remove the write lock on a region when a read lock is set. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1884 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1885 | static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1886 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1887 | unixInodeInfo *pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1888 | struct flock lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1889 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1890 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1891 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1892 | OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, never executed: sqlite3DebugPrintf ("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, (pid_t)getpid()) ;
| 0-237194 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1893 | pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, never executed: sqlite3DebugPrintf ("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, (pid_t)getpid()) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1894 | osGetpid(0))); never executed: sqlite3DebugPrintf ("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, (pid_t)getpid()) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1895 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1896 | assert( eFileLock<=SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1897 | if( pFile->eFileLock<=eFileLock ){
| 62228-174966 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1898 | return SQLITE_OK; executed 62228 times by 66 tests: return 0; Executed by:
| 62228 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1899 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1900 | pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1901 | sqlite3_mutex_enter(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1902 | assert( pInode->nShared!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1903 | if( pFile->eFileLock>SHARED_LOCK ){
| 44532-130434 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1904 | assert( pInode->eFileLock==pFile->eFileLock ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1905 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1906 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1907 | /* When reducing a lock such that other processes can start | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1908 | ** reading the database file again, make sure that the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1909 | ** transaction counter was updated if any part of the database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1910 | ** file changed. If the transaction counter is not updated, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1911 | ** other connections to the same file might not realize that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1912 | ** the file has changed and hence might not know to flush their | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1913 | ** cache. The use of a stale cache can lead to database corruption. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1914 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1915 | pFile->inNormalWrite = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1916 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1917 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1918 | /* downgrading to a shared lock on NFS involves clearing the write lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1919 | ** before establishing the readlock - to avoid a race condition we downgrade | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1920 | ** the lock in 2 blocks, so that part of the range will be covered by a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1921 | ** write lock until the rest is covered by a read lock: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1922 | ** 1: [WWWWW] | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1923 | ** 2: [....W] | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1924 | ** 3: [RRRRW] | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1925 | ** 4: [RRRR.] | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1926 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1927 | if( eFileLock==SHARED_LOCK ){
| 1602-42930 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1928 | #if !defined(__APPLE__) || !SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1929 | (void)handleNFSUnlock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1930 | assert( handleNFSUnlock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1931 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1932 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1933 | if( handleNFSUnlock ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1934 | int tErrno; /* Error code from system call errors */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1935 | off_t divSize = SHARED_SIZE - 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1936 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1937 | lock.l_type = F_UNLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1938 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1939 | lock.l_start = SHARED_FIRST; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1940 | lock.l_len = divSize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1941 | if( unixFileLock(pFile, &lock)==(-1) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1942 | tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1943 | rc = SQLITE_IOERR_UNLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1944 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1945 | goto end_unlock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1946 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1947 | lock.l_type = F_RDLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1948 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1949 | lock.l_start = SHARED_FIRST; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1950 | lock.l_len = divSize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1951 | if( unixFileLock(pFile, &lock)==(-1) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1952 | tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1953 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1954 | if( IS_LOCK_ERROR(rc) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1955 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1956 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1957 | goto end_unlock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1958 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1959 | lock.l_type = F_UNLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1960 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1961 | lock.l_start = SHARED_FIRST+divSize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1962 | lock.l_len = SHARED_SIZE-divSize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1963 | if( unixFileLock(pFile, &lock)==(-1) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1964 | tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1965 | rc = SQLITE_IOERR_UNLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1966 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1967 | goto end_unlock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1968 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1969 | }else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1970 | #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1971 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1972 | lock.l_type = F_RDLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1973 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1974 | lock.l_start = SHARED_FIRST; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1975 | lock.l_len = SHARED_SIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1976 | if( unixFileLock(pFile, &lock) ){
| 0-42930 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1977 | /* In theory, the call to unixFileLock() cannot fail because another | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1978 | ** process is holding an incompatible lock. If it does, this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1979 | ** indicates that the other process is not following the locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1980 | ** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1981 | ** SQLITE_BUSY would confuse the upper layer (in practice it causes | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1982 | ** an assert to fail). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1983 | rc = SQLITE_IOERR_RDLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1984 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1985 | goto end_unlock; never executed: goto end_unlock; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1986 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1987 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1988 | } executed 42930 times by 38 tests: end of block Executed by:
| 42930 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1989 | lock.l_type = F_UNLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1990 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1991 | lock.l_start = PENDING_BYTE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1992 | lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1993 | if( unixFileLock(pFile, &lock)==0 ){
| 0-44532 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1994 | pInode->eFileLock = SHARED_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1995 | }else{ executed 44532 times by 71 tests: end of block Executed by:
| 44532 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1996 | rc = SQLITE_IOERR_UNLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1997 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1998 | goto end_unlock; never executed: goto end_unlock; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1999 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2000 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2001 | if( eFileLock==NO_LOCK ){
| 42930-132036 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2002 | /* Decrement the shared lock counter. Release the lock using an | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2003 | ** OS call only when all threads in this same process have released | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2004 | ** the lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2005 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2006 | pInode->nShared--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2007 | if( pInode->nShared==0 ){
| 666-131370 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2008 | lock.l_type = F_UNLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2009 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2010 | lock.l_start = lock.l_len = 0L; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2011 | if( unixFileLock(pFile, &lock)==0 ){
| 0-131370 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2012 | pInode->eFileLock = NO_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2013 | }else{ executed 131370 times by 424 tests: end of block Executed by:
| 131370 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2014 | rc = SQLITE_IOERR_UNLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2015 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2016 | pInode->eFileLock = NO_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2017 | pFile->eFileLock = NO_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2018 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2019 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2020 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2021 | /* Decrement the count of locks against this same file. When the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2022 | ** count reaches zero, close any other file descriptors whose close | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2023 | ** was deferred because of outstanding locks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2024 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2025 | pInode->nLock--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2026 | assert( pInode->nLock>=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2027 | if( pInode->nLock==0 ) closePendingFds(pFile); executed 131359 times by 424 tests: closePendingFds(pFile); Executed by:
| 677-131359 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2028 | } executed 132036 times by 424 tests: end of block Executed by:
| 132036 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2029 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2030 | end_unlock: code before this statement executed 174966 times by 424 tests: end_unlock: Executed by:
| 174966 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2031 | sqlite3_mutex_leave(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2032 | if( rc==SQLITE_OK ){
| 0-174966 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2033 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2034 | } executed 174966 times by 424 tests: end of block Executed by:
| 174966 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2035 | return rc; executed 174966 times by 424 tests: return rc; Executed by:
| 174966 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2036 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2037 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2038 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2039 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2040 | ** must be either NO_LOCK or SHARED_LOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2041 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2042 | ** If the locking level of the file descriptor is already at or below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2043 | ** the requested locking level, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2044 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2045 | static int unixUnlock(sqlite3_file *id, int eFileLock){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2046 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2047 | assert( eFileLock==SHARED_LOCK || ((unixFile *)id)->nFetchOut==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2048 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2049 | return posixUnlock(id, eFileLock, 0); executed 237194 times by 427 tests: return posixUnlock(id, eFileLock, 0); Executed by:
| 237194 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2050 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2051 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2052 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2053 | static int unixMapfile(unixFile *pFd, i64 nByte); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2054 | static void unixUnmapfile(unixFile *pFd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2055 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2056 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2057 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2058 | ** This function performs the parts of the "close file" operation | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2059 | ** common to all locking schemes. It closes the directory and file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2060 | ** handles, if they are valid, and sets all fields of the unixFile | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2061 | ** structure to 0. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2062 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2063 | ** It is *not* necessary to hold the mutex when this routine is called, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2064 | ** even on VxWorks. A mutex will be acquired on VxWorks by the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2065 | ** vxworksReleaseFileId() routine. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2066 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2067 | static int closeUnixFile(sqlite3_file *id){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2068 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2069 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2070 | unixUnmapfile(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2071 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2072 | if( pFile->h>=0 ){
| 10551-65945 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2073 | robust_close(pFile, pFile->h, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2074 | pFile->h = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2075 | } executed 65945 times by 334 tests: end of block Executed by:
| 65945 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2076 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2077 | if( pFile->pId ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2078 | if( pFile->ctrlFlags & UNIXFILE_DELETE ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2079 | osUnlink(pFile->pId->zCanonicalName); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2080 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2081 | vxworksReleaseFileId(pFile->pId); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2082 | pFile->pId = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2083 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2084 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2085 | #ifdef SQLITE_UNLINK_AFTER_CLOSE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2086 | if( pFile->ctrlFlags & UNIXFILE_DELETE ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2087 | osUnlink(pFile->zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2088 | sqlite3_free(*(char**)&pFile->zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2089 | pFile->zPath = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2090 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2091 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2092 | OSTRACE(("CLOSE %-3d\n", pFile->h)); never executed: sqlite3DebugPrintf ("CLOSE %-3d\n", pFile->h);
| 0-76496 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2093 | OpenCounter(-1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2094 | sqlite3_free(pFile->pPreallocatedUnused); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2095 | memset(pFile, 0, sizeof(unixFile)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2096 | return SQLITE_OK; executed 76496 times by 334 tests: return 0; Executed by:
| 76496 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2097 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2098 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2099 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2100 | ** Close a file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2101 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2102 | static int unixClose(sqlite3_file *id){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2103 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2104 | unixFile *pFile = (unixFile *)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2105 | unixInodeInfo *pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2106 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2107 | assert( pInode!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2108 | verifyDbFile(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2109 | unixUnlock(id, NO_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2110 | assert( unixFileMutexNotheld(pFile) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2111 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2112 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2113 | /* unixFile.pInode is always valid here. Otherwise, a different close | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2114 | ** routine (e.g. nolockClose()) would be called instead. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2115 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2116 | assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2117 | sqlite3_mutex_enter(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2118 | if( pInode->nLock ){
| 10551-21306 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2119 | /* If there are outstanding locks, do not actually close the file just | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2120 | ** yet because that would clear those locks. Instead, add the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2121 | ** descriptor to pInode->pUnused list. It will be automatically closed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2122 | ** when the last lock is cleared. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2123 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2124 | setPendingFd(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2125 | } executed 10551 times by 1 test: end of block Executed by:
| 10551 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2126 | sqlite3_mutex_leave(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2127 | releaseInodeInfo(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2128 | rc = closeUnixFile(id); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2129 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2130 | return rc; executed 31857 times by 66 tests: return rc; Executed by:
| 31857 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2131 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2132 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2133 | /************** End of the posix advisory lock implementation ***************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2134 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2135 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2136 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2137 | ****************************** No-op Locking ********************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2138 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2139 | ** Of the various locking implementations available, this is by far the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2140 | ** simplest: locking is ignored. No attempt is made to lock the database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2141 | ** file for reading or writing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2142 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2143 | ** This locking mode is appropriate for use on read-only databases | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2144 | ** (ex: databases that are burned into CD-ROM, for example.) It can | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2145 | ** also be used if the application employs some external mechanism to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2146 | ** prevent simultaneous access of the same database by two or more | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2147 | ** database connections. But there is a serious risk of database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2148 | ** corruption if this locking mode is used in situations where multiple | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2149 | ** database connections are accessing the same database file at the same | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2150 | ** time and one or more of those connections are writing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2151 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2152 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2153 | static int nolockCheckReservedLock(sqlite3_file *NotUsed, int *pResOut){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2154 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2155 | *pResOut = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2156 | return SQLITE_OK; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2157 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2158 | static int nolockLock(sqlite3_file *NotUsed, int NotUsed2){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2159 | UNUSED_PARAMETER2(NotUsed, NotUsed2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2160 | return SQLITE_OK; executed 5 times by 1 test: return 0; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2161 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2162 | static int nolockUnlock(sqlite3_file *NotUsed, int NotUsed2){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2163 | UNUSED_PARAMETER2(NotUsed, NotUsed2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2164 | return SQLITE_OK; executed 6 times by 1 test: return 0; Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2165 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2166 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2167 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2168 | ** Close the file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2169 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2170 | static int nolockClose(sqlite3_file *id) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2171 | return closeUnixFile(id); executed 44637 times by 322 tests: return closeUnixFile(id); Executed by:
| 44637 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2172 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2173 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2174 | /******************* End of the no-op lock implementation ********************* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2175 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2176 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2177 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2178 | ************************* Begin dot-file Locking ****************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2179 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2180 | ** The dotfile locking implementation uses the existence of separate lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2181 | ** files (really a directory) to control access to the database. This works | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2182 | ** on just about every filesystem imaginable. But there are serious downsides: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2183 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2184 | ** (1) There is zero concurrency. A single reader blocks all other | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2185 | ** connections from reading or writing the database. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2186 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2187 | ** (2) An application crash or power loss can leave stale lock files | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2188 | ** sitting around that need to be cleared manually. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2189 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2190 | ** Nevertheless, a dotlock is an appropriate locking mode for use if no | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2191 | ** other locking strategy is available. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2192 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2193 | ** Dotfile locking works by creating a subdirectory in the same directory as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2194 | ** the database and with the same name but with a ".lock" extension added. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2195 | ** The existence of a lock directory implies an EXCLUSIVE lock. All other | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2196 | ** lock types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2197 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2198 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2199 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2200 | ** The file suffix added to the data base filename in order to create the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2201 | ** lock directory. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2202 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2203 | #define DOTLOCK_SUFFIX ".lock" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2204 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2205 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2206 | ** This routine checks if there is a RESERVED lock held on the specified | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2207 | ** file by this or any other process. If such a lock is held, set *pResOut | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2208 | ** to a non-zero value otherwise *pResOut is set to zero. The return value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2209 | ** is set to SQLITE_OK unless an I/O error occurs during lock checking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2210 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2211 | ** In dotfile locking, either a lock exists or it does not. So in this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2212 | ** variation of CheckReservedLock(), *pResOut is set to true if any lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2213 | ** is held on the file and false if the file is unlocked. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2214 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2215 | static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2216 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2217 | int reserved = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2218 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2219 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2220 | SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); never executed: return (10 | (14<<8));
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2221 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2222 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2223 | reserved = osAccess((const char*)pFile->lockingContext, 0)==0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2224 | OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved)); never executed: sqlite3DebugPrintf ("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved);
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2225 | *pResOut = reserved; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2226 | return rc; never executed: return rc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2227 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2228 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2229 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2230 | ** Lock the file with the lock specified by parameter eFileLock - one | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2231 | ** of the following: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2232 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2233 | ** (1) SHARED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2234 | ** (2) RESERVED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2235 | ** (3) PENDING_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2236 | ** (4) EXCLUSIVE_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2237 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2238 | ** Sometimes when requesting one lock state, additional lock states | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2239 | ** are inserted in between. The locking might fail on one of the later | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2240 | ** transitions leaving the lock state different from what it started but | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2241 | ** still short of its goal. The following chart shows the allowed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2242 | ** transitions and the inserted intermediate states: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2243 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2244 | ** UNLOCKED -> SHARED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2245 | ** SHARED -> RESERVED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2246 | ** SHARED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2247 | ** RESERVED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2248 | ** PENDING -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2249 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2250 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2251 | ** routine to lower a locking level. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2252 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2253 | ** With dotfile locking, we really only support state (4): EXCLUSIVE. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2254 | ** But we track the other locking levels internally. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2255 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2256 | static int dotlockLock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2257 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2258 | char *zLockFile = (char *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2259 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2260 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2261 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2262 | /* If we have any lock, then the lock file already exists. All we have | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2263 | ** to do is adjust our internal record of the lock level. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2264 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2265 | if( pFile->eFileLock > NO_LOCK ){
| 6-9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2266 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2267 | /* Always update the timestamp on the old file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2268 | #ifdef HAVE_UTIME | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2269 | utime(zLockFile, NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2270 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2271 | utimes(zLockFile, NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2272 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2273 | return SQLITE_OK; executed 6 times by 1 test: return 0; Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2274 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2275 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2276 | /* grab an exclusive lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2277 | rc = osMkdir(zLockFile, 0777); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2278 | if( rc<0 ){
| 1-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2279 | /* failed to open/create the lock directory */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2280 | int tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2281 | if( EEXIST == tErrno ){
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2282 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2283 | } else { executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2284 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2285 | if( rc!=SQLITE_BUSY ){
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2286 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2287 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2288 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2289 | return rc; executed 1 time by 1 test: return rc; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2290 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2291 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2292 | /* got it, set the type and return ok */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2293 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2294 | return rc; executed 8 times by 1 test: return rc; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2295 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2296 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2297 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2298 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2299 | ** must be either NO_LOCK or SHARED_LOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2300 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2301 | ** If the locking level of the file descriptor is already at or below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2302 | ** the requested locking level, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2303 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2304 | ** When the locking level reaches NO_LOCK, delete the lock file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2305 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2306 | static int dotlockUnlock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2307 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2308 | char *zLockFile = (char *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2309 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2310 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2311 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2312 | OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock, never executed: sqlite3DebugPrintf ("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock, pFile->eFileLock, (pid_t)getpid()) ;
| 0-16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2313 | pFile->eFileLock, osGetpid(0))); never executed: sqlite3DebugPrintf ("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock, pFile->eFileLock, (pid_t)getpid()) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2314 | assert( eFileLock<=SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2315 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2316 | /* no-op if possible */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2317 | if( pFile->eFileLock==eFileLock ){
| 5-11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2318 | return SQLITE_OK; executed 5 times by 1 test: return 0; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2319 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2320 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2321 | /* To downgrade to shared, simply update our internal notion of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2322 | ** lock state. No need to mess with the file on disk. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2323 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2324 | if( eFileLock==SHARED_LOCK ){
| 3-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2325 | pFile->eFileLock = SHARED_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2326 | return SQLITE_OK; executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2327 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2328 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2329 | /* To fully unlock the database, delete the lock file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2330 | assert( eFileLock==NO_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2331 | rc = osRmdir(zLockFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2332 | if( rc<0 ){
| 0-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2333 | int tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2334 | if( tErrno==ENOENT ){
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2335 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2336 | }else{ never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2337 | rc = SQLITE_IOERR_UNLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2338 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2339 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2340 | return rc; never executed: return rc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2341 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2342 | pFile->eFileLock = NO_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2343 | return SQLITE_OK; executed 8 times by 1 test: return 0; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2344 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2345 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2346 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2347 | ** Close a file. Make sure the lock has been released before closing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2348 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2349 | static int dotlockClose(sqlite3_file *id) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2350 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2351 | assert( id!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2352 | dotlockUnlock(id, NO_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2353 | sqlite3_free(pFile->lockingContext); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2354 | return closeUnixFile(id); executed 2 times by 1 test: return closeUnixFile(id); Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2355 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2356 | /****************** End of the dot-file lock implementation ******************* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2357 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2358 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2359 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2360 | ************************** Begin flock Locking ******************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2361 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2362 | ** Use the flock() system call to do file locking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2363 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2364 | ** flock() locking is like dot-file locking in that the various | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2365 | ** fine-grain locking levels supported by SQLite are collapsed into | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2366 | ** a single exclusive lock. In other words, SHARED, RESERVED, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2367 | ** PENDING locks are the same thing as an EXCLUSIVE lock. SQLite | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2368 | ** still works when you do this, but concurrency is reduced since | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2369 | ** only a single process can be reading the database at a time. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2370 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2371 | ** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2372 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2373 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2374 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2375 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2376 | ** Retry flock() calls that fail with EINTR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2377 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2378 | #ifdef EINTR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2379 | static int robust_flock(int fd, int op){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2380 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2381 | do{ rc = flock(fd,op); }while( rc<0 && errno==EINTR ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2382 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2383 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2384 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2385 | # define robust_flock(a,b) flock(a,b) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2386 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2387 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2388 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2389 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2390 | ** This routine checks if there is a RESERVED lock held on the specified | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2391 | ** file by this or any other process. If such a lock is held, set *pResOut | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2392 | ** to a non-zero value otherwise *pResOut is set to zero. The return value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2393 | ** is set to SQLITE_OK unless an I/O error occurs during lock checking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2394 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2395 | static int flockCheckReservedLock(sqlite3_file *id, int *pResOut){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2396 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2397 | int reserved = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2398 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2399 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2400 | SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2401 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2402 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2403 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2404 | /* Check if a thread in this process holds such a lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2405 | if( pFile->eFileLock>SHARED_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2406 | reserved = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2407 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2408 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2409 | /* Otherwise see if some other process holds it. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2410 | if( !reserved ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2411 | /* attempt to get the lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2412 | int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2413 | if( !lrc ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2414 | /* got the lock, unlock it */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2415 | lrc = robust_flock(pFile->h, LOCK_UN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2416 | if ( lrc ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2417 | int tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2418 | /* unlock failed with an error */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2419 | lrc = SQLITE_IOERR_UNLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2420 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2421 | rc = lrc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2422 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2423 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2424 | int tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2425 | reserved = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2426 | /* someone else might have it reserved */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2427 | lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2428 | if( IS_LOCK_ERROR(lrc) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2429 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2430 | rc = lrc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2431 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2432 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2433 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2434 | OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2435 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2436 | #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2437 | if( (rc & 0xff) == SQLITE_IOERR ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2438 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2439 | reserved=1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2440 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2441 | #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2442 | *pResOut = reserved; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2443 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2444 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2445 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2446 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2447 | ** Lock the file with the lock specified by parameter eFileLock - one | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2448 | ** of the following: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2449 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2450 | ** (1) SHARED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2451 | ** (2) RESERVED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2452 | ** (3) PENDING_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2453 | ** (4) EXCLUSIVE_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2454 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2455 | ** Sometimes when requesting one lock state, additional lock states | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2456 | ** are inserted in between. The locking might fail on one of the later | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2457 | ** transitions leaving the lock state different from what it started but | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2458 | ** still short of its goal. The following chart shows the allowed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2459 | ** transitions and the inserted intermediate states: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2460 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2461 | ** UNLOCKED -> SHARED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2462 | ** SHARED -> RESERVED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2463 | ** SHARED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2464 | ** RESERVED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2465 | ** PENDING -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2466 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2467 | ** flock() only really support EXCLUSIVE locks. We track intermediate | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2468 | ** lock states in the sqlite3_file structure, but all locks SHARED or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2469 | ** above are really EXCLUSIVE locks and exclude all other processes from | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2470 | ** access the file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2471 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2472 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2473 | ** routine to lower a locking level. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2474 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2475 | static int flockLock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2476 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2477 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2478 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2479 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2480 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2481 | /* if we already have a lock, it is exclusive. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2482 | ** Just adjust level and punt on outta here. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2483 | if (pFile->eFileLock > NO_LOCK) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2484 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2485 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2486 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2487 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2488 | /* grab an exclusive lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2489 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2490 | if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2491 | int tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2492 | /* didn't get, must be busy */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2493 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2494 | if( IS_LOCK_ERROR(rc) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2495 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2496 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2497 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2498 | /* got it, set the type and return ok */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2499 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2500 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2501 | OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2502 | rc==SQLITE_OK ? "ok" : "failed")); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2503 | #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2504 | if( (rc & 0xff) == SQLITE_IOERR ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2505 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2506 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2507 | #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2508 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2509 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2510 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2511 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2512 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2513 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2514 | ** must be either NO_LOCK or SHARED_LOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2515 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2516 | ** If the locking level of the file descriptor is already at or below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2517 | ** the requested locking level, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2518 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2519 | static int flockUnlock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2520 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2521 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2522 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2523 | OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2524 | pFile->eFileLock, osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2525 | assert( eFileLock<=SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2526 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2527 | /* no-op if possible */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2528 | if( pFile->eFileLock==eFileLock ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2529 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2530 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2531 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2532 | /* shared can just be set because we always have an exclusive */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2533 | if (eFileLock==SHARED_LOCK) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2534 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2535 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2536 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2537 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2538 | /* no, really, unlock. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2539 | if( robust_flock(pFile->h, LOCK_UN) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2540 | #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2541 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2542 | #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2543 | return SQLITE_IOERR_UNLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2544 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2545 | pFile->eFileLock = NO_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2546 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2547 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2548 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2549 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2550 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2551 | ** Close a file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2552 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2553 | static int flockClose(sqlite3_file *id) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2554 | assert( id!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2555 | flockUnlock(id, NO_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2556 | return closeUnixFile(id); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2557 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2558 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2559 | #endif /* SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORK */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2560 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2561 | /******************* End of the flock lock implementation ********************* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2562 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2563 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2564 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2565 | ************************ Begin Named Semaphore Locking ************************ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2566 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2567 | ** Named semaphore locking is only supported on VxWorks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2568 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2569 | ** Semaphore locking is like dot-lock and flock in that it really only | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2570 | ** supports EXCLUSIVE locking. Only a single process can read or write | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2571 | ** the database file at a time. This reduces potential concurrency, but | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2572 | ** makes the lock implementation much easier. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2573 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2574 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2575 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2576 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2577 | ** This routine checks if there is a RESERVED lock held on the specified | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2578 | ** file by this or any other process. If such a lock is held, set *pResOut | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2579 | ** to a non-zero value otherwise *pResOut is set to zero. The return value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2580 | ** is set to SQLITE_OK unless an I/O error occurs during lock checking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2581 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2582 | static int semXCheckReservedLock(sqlite3_file *id, int *pResOut) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2583 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2584 | int reserved = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2585 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2586 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2587 | SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2588 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2589 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2590 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2591 | /* Check if a thread in this process holds such a lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2592 | if( pFile->eFileLock>SHARED_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2593 | reserved = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2594 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2595 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2596 | /* Otherwise see if some other process holds it. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2597 | if( !reserved ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2598 | sem_t *pSem = pFile->pInode->pSem; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2599 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2600 | if( sem_trywait(pSem)==-1 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2601 | int tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2602 | if( EAGAIN != tErrno ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2603 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2604 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2605 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2606 | /* someone else has the lock when we are in NO_LOCK */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2607 | reserved = (pFile->eFileLock < SHARED_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2608 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2609 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2610 | /* we could have it if we want it */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2611 | sem_post(pSem); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2612 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2613 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2614 | OSTRACE(("TEST WR-LOCK %d %d %d (sem)\n", pFile->h, rc, reserved)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2615 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2616 | *pResOut = reserved; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2617 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2618 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2619 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2620 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2621 | ** Lock the file with the lock specified by parameter eFileLock - one | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2622 | ** of the following: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2623 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2624 | ** (1) SHARED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2625 | ** (2) RESERVED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2626 | ** (3) PENDING_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2627 | ** (4) EXCLUSIVE_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2628 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2629 | ** Sometimes when requesting one lock state, additional lock states | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2630 | ** are inserted in between. The locking might fail on one of the later | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2631 | ** transitions leaving the lock state different from what it started but | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2632 | ** still short of its goal. The following chart shows the allowed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2633 | ** transitions and the inserted intermediate states: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2634 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2635 | ** UNLOCKED -> SHARED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2636 | ** SHARED -> RESERVED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2637 | ** SHARED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2638 | ** RESERVED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2639 | ** PENDING -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2640 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2641 | ** Semaphore locks only really support EXCLUSIVE locks. We track intermediate | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2642 | ** lock states in the sqlite3_file structure, but all locks SHARED or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2643 | ** above are really EXCLUSIVE locks and exclude all other processes from | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2644 | ** access the file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2645 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2646 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2647 | ** routine to lower a locking level. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2648 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2649 | static int semXLock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2650 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2651 | sem_t *pSem = pFile->pInode->pSem; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2652 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2653 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2654 | /* if we already have a lock, it is exclusive. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2655 | ** Just adjust level and punt on outta here. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2656 | if (pFile->eFileLock > NO_LOCK) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2657 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2658 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2659 | goto sem_end_lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2660 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2661 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2662 | /* lock semaphore now but bail out when already locked. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2663 | if( sem_trywait(pSem)==-1 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2664 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2665 | goto sem_end_lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2666 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2667 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2668 | /* got it, set the type and return ok */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2669 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2670 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2671 | sem_end_lock: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2672 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2673 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2674 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2675 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2676 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2677 | ** must be either NO_LOCK or SHARED_LOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2678 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2679 | ** If the locking level of the file descriptor is already at or below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2680 | ** the requested locking level, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2681 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2682 | static int semXUnlock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2683 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2684 | sem_t *pSem = pFile->pInode->pSem; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2685 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2686 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2687 | assert( pSem ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2688 | OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2689 | pFile->eFileLock, osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2690 | assert( eFileLock<=SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2691 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2692 | /* no-op if possible */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2693 | if( pFile->eFileLock==eFileLock ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2694 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2695 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2696 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2697 | /* shared can just be set because we always have an exclusive */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2698 | if (eFileLock==SHARED_LOCK) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2699 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2700 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2701 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2702 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2703 | /* no, really unlock. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2704 | if ( sem_post(pSem)==-1 ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2705 | int rc, tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2706 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2707 | if( IS_LOCK_ERROR(rc) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2708 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2709 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2710 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2711 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2712 | pFile->eFileLock = NO_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2713 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2714 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2715 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2716 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2717 | ** Close a file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2718 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2719 | static int semXClose(sqlite3_file *id) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2720 | if( id ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2721 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2722 | semXUnlock(id, NO_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2723 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2724 | assert( unixFileMutexNotheld(pFile) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2725 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2726 | releaseInodeInfo(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2727 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2728 | closeUnixFile(id); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2729 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2730 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2731 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2732 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2733 | #endif /* OS_VXWORKS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2734 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2735 | ** Named semaphore locking is only available on VxWorks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2736 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2737 | *************** End of the named semaphore lock implementation **************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2738 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2739 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2740 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2741 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2742 | *************************** Begin AFP Locking ********************************* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2743 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2744 | ** AFP is the Apple Filing Protocol. AFP is a network filesystem found | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2745 | ** on Apple Macintosh computers - both OS9 and OSX. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2746 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2747 | ** Third-party implementations of AFP are available. But this code here | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2748 | ** only works on OSX. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2749 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2750 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2751 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2752 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2753 | ** The afpLockingContext structure contains all afp lock specific state | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2754 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2755 | typedef struct afpLockingContext afpLockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2756 | struct afpLockingContext { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2757 | int reserved; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2758 | const char *dbPath; /* Name of the open file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2759 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2760 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2761 | struct ByteRangeLockPB2 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2762 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2763 | unsigned long long offset; /* offset to first byte to lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2764 | unsigned long long length; /* nbr of bytes to lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2765 | unsigned long long retRangeStart; /* nbr of 1st byte locked if successful */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2766 | unsigned char unLockFlag; /* 1 = unlock, 0 = lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2767 | unsigned char startEndFlag; /* 1=rel to end of fork, 0=rel to start */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2768 | int fd; /* file desc to assoc this lock with */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2769 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2770 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2771 | #define afpfsByteRangeLock2FSCTL _IOWR('z', 23, struct ByteRangeLockPB2) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2772 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2773 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2774 | ** This is a utility for setting or clearing a bit-range lock on an | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2775 | ** AFP filesystem. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2776 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2777 | ** Return SQLITE_OK on success, SQLITE_BUSY on failure. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2778 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2779 | static int afpSetLock( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2780 | const char *path, /* Name of the file to be locked or unlocked */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2781 | unixFile *pFile, /* Open file descriptor on path */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2782 | unsigned long long offset, /* First byte to be locked */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2783 | unsigned long long length, /* Number of bytes to lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2784 | int setLockFlag /* True to set lock. False to clear lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2785 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2786 | struct ByteRangeLockPB2 pb; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2787 | int err; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2788 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2789 | pb.unLockFlag = setLockFlag ? 0 : 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2790 | pb.startEndFlag = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2791 | pb.offset = offset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2792 | pb.length = length; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2793 | pb.fd = pFile->h; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2794 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2795 | OSTRACE(("AFPSETLOCK [%s] for %d%s in range %llx:%llx\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2796 | (setLockFlag?"ON":"OFF"), pFile->h, (pb.fd==-1?"[testval-1]":""), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2797 | offset, length)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2798 | err = fsctl(path, afpfsByteRangeLock2FSCTL, &pb, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2799 | if ( err==-1 ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2800 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2801 | int tErrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2802 | OSTRACE(("AFPSETLOCK failed to fsctl() '%s' %d %s\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2803 | path, tErrno, strerror(tErrno))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2804 | #ifdef SQLITE_IGNORE_AFP_LOCK_ERRORS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2805 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2806 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2807 | rc = sqliteErrorFromPosixError(tErrno, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2808 | setLockFlag ? SQLITE_IOERR_LOCK : SQLITE_IOERR_UNLOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2809 | #endif /* SQLITE_IGNORE_AFP_LOCK_ERRORS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2810 | if( IS_LOCK_ERROR(rc) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2811 | storeLastErrno(pFile, tErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2812 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2813 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2814 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2815 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2816 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2817 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2818 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2819 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2820 | ** This routine checks if there is a RESERVED lock held on the specified | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2821 | ** file by this or any other process. If such a lock is held, set *pResOut | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2822 | ** to a non-zero value otherwise *pResOut is set to zero. The return value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2823 | ** is set to SQLITE_OK unless an I/O error occurs during lock checking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2824 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2825 | static int afpCheckReservedLock(sqlite3_file *id, int *pResOut){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2826 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2827 | int reserved = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2828 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2829 | afpLockingContext *context; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2830 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2831 | SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2832 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2833 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2834 | context = (afpLockingContext *) pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2835 | if( context->reserved ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2836 | *pResOut = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2837 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2838 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2839 | sqlite3_mutex_enter(pFile->pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2840 | /* Check if a thread in this process holds such a lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2841 | if( pFile->pInode->eFileLock>SHARED_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2842 | reserved = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2843 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2844 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2845 | /* Otherwise see if some other process holds it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2846 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2847 | if( !reserved ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2848 | /* lock the RESERVED byte */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2849 | int lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2850 | if( SQLITE_OK==lrc ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2851 | /* if we succeeded in taking the reserved lock, unlock it to restore | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2852 | ** the original state */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2853 | lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2854 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2855 | /* if we failed to get the lock then someone else must have it */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2856 | reserved = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2857 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2858 | if( IS_LOCK_ERROR(lrc) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2859 | rc=lrc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2860 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2861 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2862 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2863 | sqlite3_mutex_leave(pFile->pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2864 | OSTRACE(("TEST WR-LOCK %d %d %d (afp)\n", pFile->h, rc, reserved)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2865 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2866 | *pResOut = reserved; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2867 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2868 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2869 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2870 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2871 | ** Lock the file with the lock specified by parameter eFileLock - one | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2872 | ** of the following: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2873 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2874 | ** (1) SHARED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2875 | ** (2) RESERVED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2876 | ** (3) PENDING_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2877 | ** (4) EXCLUSIVE_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2878 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2879 | ** Sometimes when requesting one lock state, additional lock states | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2880 | ** are inserted in between. The locking might fail on one of the later | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2881 | ** transitions leaving the lock state different from what it started but | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2882 | ** still short of its goal. The following chart shows the allowed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2883 | ** transitions and the inserted intermediate states: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2884 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2885 | ** UNLOCKED -> SHARED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2886 | ** SHARED -> RESERVED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2887 | ** SHARED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2888 | ** RESERVED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2889 | ** PENDING -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2890 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2891 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2892 | ** routine to lower a locking level. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2893 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2894 | static int afpLock(sqlite3_file *id, int eFileLock){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2895 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2896 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2897 | unixInodeInfo *pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2898 | afpLockingContext *context = (afpLockingContext *) pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2899 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2900 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2901 | OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2902 | azFileLock(eFileLock), azFileLock(pFile->eFileLock), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2903 | azFileLock(pInode->eFileLock), pInode->nShared , osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2904 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2905 | /* If there is already a lock of this type or more restrictive on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2906 | ** unixFile, do nothing. Don't use the afp_end_lock: exit path, as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2907 | ** unixEnterMutex() hasn't been called yet. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2908 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2909 | if( pFile->eFileLock>=eFileLock ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2910 | OSTRACE(("LOCK %d %s ok (already held) (afp)\n", pFile->h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2911 | azFileLock(eFileLock))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2912 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2913 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2914 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2915 | /* Make sure the locking sequence is correct | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2916 | ** (1) We never move from unlocked to anything higher than shared lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2917 | ** (2) SQLite never explicitly requests a pendig lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2918 | ** (3) A shared lock is always held when a reserve lock is requested. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2919 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2920 | assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2921 | assert( eFileLock!=PENDING_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2922 | assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2923 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2924 | /* This mutex is needed because pFile->pInode is shared across threads | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2925 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2926 | pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2927 | sqlite3_mutex_enter(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2928 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2929 | /* If some thread using this PID has a lock via a different unixFile* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2930 | ** handle that precludes the requested lock, return BUSY. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2931 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2932 | if( (pFile->eFileLock!=pInode->eFileLock && | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2933 | (pInode->eFileLock>=PENDING_LOCK || eFileLock>SHARED_LOCK)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2934 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2935 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2936 | goto afp_end_lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2937 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2938 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2939 | /* If a SHARED lock is requested, and some thread using this PID already | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2940 | ** has a SHARED or RESERVED lock, then increment reference counts and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2941 | ** return SQLITE_OK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2942 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2943 | if( eFileLock==SHARED_LOCK && | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2944 | (pInode->eFileLock==SHARED_LOCK || pInode->eFileLock==RESERVED_LOCK) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2945 | assert( eFileLock==SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2946 | assert( pFile->eFileLock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2947 | assert( pInode->nShared>0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2948 | pFile->eFileLock = SHARED_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2949 | pInode->nShared++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2950 | pInode->nLock++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2951 | goto afp_end_lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2952 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2953 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2954 | /* A PENDING lock is needed before acquiring a SHARED lock and before | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2955 | ** acquiring an EXCLUSIVE lock. For the SHARED lock, the PENDING will | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2956 | ** be released. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2957 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2958 | if( eFileLock==SHARED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2959 | || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2960 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2961 | int failed; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2962 | failed = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2963 | if (failed) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2964 | rc = failed; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2965 | goto afp_end_lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2966 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2967 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2968 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2969 | /* If control gets to this point, then actually go ahead and make | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2970 | ** operating system calls for the specified lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2971 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2972 | if( eFileLock==SHARED_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2973 | int lrc1, lrc2, lrc1Errno = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2974 | long lk, mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2975 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2976 | assert( pInode->nShared==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2977 | assert( pInode->eFileLock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2978 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2979 | mask = (sizeof(long)==8) ? LARGEST_INT64 : 0x7fffffff; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2980 | /* Now get the read-lock SHARED_LOCK */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2981 | /* note that the quality of the randomness doesn't matter that much */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2982 | lk = random(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2983 | pInode->sharedByte = (lk & mask)%(SHARED_SIZE - 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2984 | lrc1 = afpSetLock(context->dbPath, pFile, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2985 | SHARED_FIRST+pInode->sharedByte, 1, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2986 | if( IS_LOCK_ERROR(lrc1) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2987 | lrc1Errno = pFile->lastErrno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2988 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2989 | /* Drop the temporary PENDING lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2990 | lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2991 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2992 | if( IS_LOCK_ERROR(lrc1) ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2993 | storeLastErrno(pFile, lrc1Errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2994 | rc = lrc1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2995 | goto afp_end_lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2996 | } else if( IS_LOCK_ERROR(lrc2) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2997 | rc = lrc2; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2998 | goto afp_end_lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2999 | } else if( lrc1 != SQLITE_OK ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3000 | rc = lrc1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3001 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3002 | pFile->eFileLock = SHARED_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3003 | pInode->nLock++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3004 | pInode->nShared = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3005 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3006 | }else if( eFileLock==EXCLUSIVE_LOCK && pInode->nShared>1 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3007 | /* We are trying for an exclusive lock but another thread in this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3008 | ** same process is still holding a shared lock. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3009 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3010 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3011 | /* The request was for a RESERVED or EXCLUSIVE lock. It is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3012 | ** assumed that there is a SHARED or greater lock on the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3013 | ** already. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3014 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3015 | int failed = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3016 | assert( 0!=pFile->eFileLock ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3017 | if (eFileLock >= RESERVED_LOCK && pFile->eFileLock < RESERVED_LOCK) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3018 | /* Acquire a RESERVED lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3019 | failed = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3020 | if( !failed ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3021 | context->reserved = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3022 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3023 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3024 | if (!failed && eFileLock == EXCLUSIVE_LOCK) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3025 | /* Acquire an EXCLUSIVE lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3026 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3027 | /* Remove the shared lock before trying the range. we'll need to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3028 | ** reestablish the shared lock if we can't get the afpUnlock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3029 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3030 | if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST + | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3031 | pInode->sharedByte, 1, 0)) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3032 | int failed2 = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3033 | /* now attemmpt to get the exclusive lock range */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3034 | failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3035 | SHARED_SIZE, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3036 | if( failed && (failed2 = afpSetLock(context->dbPath, pFile, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3037 | SHARED_FIRST + pInode->sharedByte, 1, 1)) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3038 | /* Can't reestablish the shared lock. Sqlite can't deal, this is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3039 | ** a critical I/O error | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3040 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3041 | rc = ((failed & 0xff) == SQLITE_IOERR) ? failed2 : | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3042 | SQLITE_IOERR_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3043 | goto afp_end_lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3044 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3045 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3046 | rc = failed; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3047 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3048 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3049 | if( failed ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3050 | rc = failed; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3051 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3052 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3053 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3054 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3055 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3056 | pInode->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3057 | }else if( eFileLock==EXCLUSIVE_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3058 | pFile->eFileLock = PENDING_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3059 | pInode->eFileLock = PENDING_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3060 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3061 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3062 | afp_end_lock: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3063 | sqlite3_mutex_leave(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3064 | OSTRACE(("LOCK %d %s %s (afp)\n", pFile->h, azFileLock(eFileLock), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3065 | rc==SQLITE_OK ? "ok" : "failed")); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3066 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3067 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3068 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3069 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3070 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3071 | ** must be either NO_LOCK or SHARED_LOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3072 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3073 | ** If the locking level of the file descriptor is already at or below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3074 | ** the requested locking level, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3075 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3076 | static int afpUnlock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3077 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3078 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3079 | unixInodeInfo *pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3080 | afpLockingContext *context = (afpLockingContext *) pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3081 | int skipShared = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3082 | #ifdef SQLITE_TEST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3083 | int h = pFile->h; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3084 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3085 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3086 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3087 | OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3088 | pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3089 | osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3090 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3091 | assert( eFileLock<=SHARED_LOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3092 | if( pFile->eFileLock<=eFileLock ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3093 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3094 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3095 | pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3096 | sqlite3_mutex_enter(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3097 | assert( pInode->nShared!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3098 | if( pFile->eFileLock>SHARED_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3099 | assert( pInode->eFileLock==pFile->eFileLock ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3100 | SimulateIOErrorBenign(1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3101 | SimulateIOError( h=(-1) ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3102 | SimulateIOErrorBenign(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3103 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3104 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3105 | /* When reducing a lock such that other processes can start | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3106 | ** reading the database file again, make sure that the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3107 | ** transaction counter was updated if any part of the database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3108 | ** file changed. If the transaction counter is not updated, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3109 | ** other connections to the same file might not realize that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3110 | ** the file has changed and hence might not know to flush their | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3111 | ** cache. The use of a stale cache can lead to database corruption. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3112 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3113 | assert( pFile->inNormalWrite==0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3114 | || pFile->dbUpdate==0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3115 | || pFile->transCntrChng==1 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3116 | pFile->inNormalWrite = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3117 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3118 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3119 | if( pFile->eFileLock==EXCLUSIVE_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3120 | rc = afpSetLock(context->dbPath, pFile, SHARED_FIRST, SHARED_SIZE, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3121 | if( rc==SQLITE_OK && (eFileLock==SHARED_LOCK || pInode->nShared>1) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3122 | /* only re-establish the shared lock if necessary */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3123 | int sharedLockByte = SHARED_FIRST+pInode->sharedByte; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3124 | rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3125 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3126 | skipShared = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3127 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3128 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3129 | if( rc==SQLITE_OK && pFile->eFileLock>=PENDING_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3130 | rc = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3131 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3132 | if( rc==SQLITE_OK && pFile->eFileLock>=RESERVED_LOCK && context->reserved ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3133 | rc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3134 | if( !rc ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3135 | context->reserved = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3136 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3137 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3138 | if( rc==SQLITE_OK && (eFileLock==SHARED_LOCK || pInode->nShared>1)){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3139 | pInode->eFileLock = SHARED_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3140 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3141 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3142 | if( rc==SQLITE_OK && eFileLock==NO_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3143 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3144 | /* Decrement the shared lock counter. Release the lock using an | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3145 | ** OS call only when all threads in this same process have released | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3146 | ** the lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3147 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3148 | unsigned long long sharedLockByte = SHARED_FIRST+pInode->sharedByte; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3149 | pInode->nShared--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3150 | if( pInode->nShared==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3151 | SimulateIOErrorBenign(1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3152 | SimulateIOError( h=(-1) ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3153 | SimulateIOErrorBenign(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3154 | if( !skipShared ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3155 | rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3156 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3157 | if( !rc ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3158 | pInode->eFileLock = NO_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3159 | pFile->eFileLock = NO_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3160 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3161 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3162 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3163 | pInode->nLock--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3164 | assert( pInode->nLock>=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3165 | if( pInode->nLock==0 ) closePendingFds(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3166 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3167 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3168 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3169 | sqlite3_mutex_leave(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3170 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3171 | pFile->eFileLock = eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3172 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3173 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3174 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3175 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3176 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3177 | ** Close a file & cleanup AFP specific locking context | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3178 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3179 | static int afpClose(sqlite3_file *id) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3180 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3181 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3182 | assert( id!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3183 | afpUnlock(id, NO_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3184 | assert( unixFileMutexNotheld(pFile) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3185 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3186 | if( pFile->pInode ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3187 | unixInodeInfo *pInode = pFile->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3188 | sqlite3_mutex_enter(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3189 | if( pInode->nLock ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3190 | /* If there are outstanding locks, do not actually close the file just | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3191 | ** yet because that would clear those locks. Instead, add the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3192 | ** descriptor to pInode->aPending. It will be automatically closed when | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3193 | ** the last lock is cleared. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3194 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3195 | setPendingFd(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3196 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3197 | sqlite3_mutex_leave(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3198 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3199 | releaseInodeInfo(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3200 | sqlite3_free(pFile->lockingContext); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3201 | rc = closeUnixFile(id); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3202 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3203 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3204 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3205 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3206 | #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3207 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3208 | ** The code above is the AFP lock implementation. The code is specific | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3209 | ** to MacOSX and does not work on other unix platforms. No alternative | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3210 | ** is available. If you don't compile for a mac, then the "unix-afp" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3211 | ** VFS is not available. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3212 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3213 | ********************* End of the AFP lock implementation ********************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3214 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3215 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3216 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3217 | *************************** Begin NFS Locking ********************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3218 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3219 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3220 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3221 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3222 | ** must be either NO_LOCK or SHARED_LOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3223 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3224 | ** If the locking level of the file descriptor is already at or below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3225 | ** the requested locking level, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3226 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3227 | static int nfsUnlock(sqlite3_file *id, int eFileLock){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3228 | return posixUnlock(id, eFileLock, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3229 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3230 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3231 | #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3232 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3233 | ** The code above is the NFS lock implementation. The code is specific | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3234 | ** to MacOSX and does not work on other unix platforms. No alternative | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3235 | ** is available. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3236 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3237 | ********************* End of the NFS lock implementation ********************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3238 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3239 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3240 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3241 | **************** Non-locking sqlite3_file methods ***************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3242 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3243 | ** The next division contains implementations for all methods of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3244 | ** sqlite3_file object other than the locking methods. The locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3245 | ** methods were defined in divisions above (one locking method per | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3246 | ** division). Those methods that are common to all locking modes | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3247 | ** are gather together into this division. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3248 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3249 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3250 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3251 | ** Seek to the offset passed as the second argument, then read cnt | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3252 | ** bytes into pBuf. Return the number of bytes actually read. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3253 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3254 | ** NB: If you define USE_PREAD or USE_PREAD64, then it might also | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3255 | ** be necessary to define _XOPEN_SOURCE to be 500. This varies from | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3256 | ** one system to another. Since SQLite does not define USE_PREAD | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3257 | ** in any form by default, we will not attempt to define _XOPEN_SOURCE. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3258 | ** See tickets #2741 and #2681. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3259 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3260 | ** To avoid stomping the errno value on a failed read the lastErrno value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3261 | ** is set before returning. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3262 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3263 | static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3264 | int got; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3265 | int prior = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3266 | #if (!defined(USE_PREAD) && !defined(USE_PREAD64)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3267 | i64 newOffset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3268 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3269 | TIMER_START; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3270 | assert( cnt==(cnt&0x1ffff) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3271 | assert( id->h>2 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3272 | do{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3273 | #if defined(USE_PREAD) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3274 | got = osPread(id->h, pBuf, cnt, offset); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3275 | SimulateIOError( got = -1 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3276 | #elif defined(USE_PREAD64) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3277 | got = osPread64(id->h, pBuf, cnt, offset); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3278 | SimulateIOError( got = -1 ); executed 47 times by 1 test: end of block Executed by:
| 0-7338672 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3279 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3280 | newOffset = lseek(id->h, offset, SEEK_SET); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3281 | SimulateIOError( newOffset = -1 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3282 | if( newOffset<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3283 | storeLastErrno((unixFile*)id, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3284 | return -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3285 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3286 | got = osRead(id->h, pBuf, cnt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3287 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3288 | if( got==cnt ) break; executed 7276515 times by 433 tests: break; Executed by:
| 62204-7276515 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3289 | if( got<0 ){
| 48-62156 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3290 | if( errno==EINTR ){ got = 1; continue; } never executed: continue;
| 0-48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3291 | prior = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3292 | storeLastErrno((unixFile*)id, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3293 | break; executed 48 times by 1 test: break; Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3294 | }else if( got>0 ){
| 17-62139 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3295 | cnt -= got; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3296 | offset += got; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3297 | prior += got; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3298 | pBuf = (void*)(got + (char*)pBuf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3299 | } executed 17 times by 1 test: end of block Executed by:
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3300 | }while( got>0 ); executed 62156 times by 156 tests: end of block Executed by:
| 17-62156 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3301 | TIMER_END; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3302 | OSTRACE(("READ %-3d %5d %7lld %llu\n", never executed: sqlite3DebugPrintf ("READ %-3d %5d %7lld %llu\n", id->h, got+prior, offset-prior, ((sqlite_uint64)0)) ;
| 0-7338702 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3303 | id->h, got+prior, offset-prior, TIMER_ELAPSED)); never executed: sqlite3DebugPrintf ("READ %-3d %5d %7lld %llu\n", id->h, got+prior, offset-prior, ((sqlite_uint64)0)) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3304 | return got+prior; executed 7338702 times by 438 tests: return got+prior; Executed by:
| 7338702 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3305 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3306 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3307 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3308 | ** Read data from a file into a buffer. Return SQLITE_OK if all | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3309 | ** bytes were read successfully and SQLITE_IOERR if anything goes | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3310 | ** wrong. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3311 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3312 | static int unixRead( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3313 | sqlite3_file *id, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3314 | void *pBuf, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3315 | int amt, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3316 | sqlite3_int64 offset | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3317 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3318 | unixFile *pFile = (unixFile *)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3319 | int got; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3320 | assert( id ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3321 | assert( offset>=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3322 | assert( amt>0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3323 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3324 | /* If this is a database file (not a journal, master-journal or temp | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3325 | ** file), the bytes in the locking range should never be read or written. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3326 | #if 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3327 | assert( pFile->pPreallocatedUnused==0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3328 | || offset>=PENDING_BYTE+512 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3329 | || offset+amt<=PENDING_BYTE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3330 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3331 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3332 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3333 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3334 | /* Deal with as much of this read request as possible by transfering | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3335 | ** data from the memory mapping using memcpy(). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3336 | if( offset<pFile->mmapSize ){
| 467-7338702 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3337 | if( offset+amt <= pFile->mmapSize ){
| 0-467 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3338 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3339 | return SQLITE_OK; executed 467 times by 2 tests: return 0; Executed by:
| 467 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3340 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3341 | int nCopy = pFile->mmapSize - offset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3342 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3343 | pBuf = &((u8 *)pBuf)[nCopy]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3344 | amt -= nCopy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3345 | offset += nCopy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3346 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3347 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3348 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3349 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3350 | got = seekAndRead(pFile, offset, pBuf, amt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3351 | if( got==amt ){
| 62187-7276515 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3352 | return SQLITE_OK; executed 7276515 times by 433 tests: return 0; Executed by:
| 7276515 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3353 | }else if( got<0 ){
| 48-62139 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3354 | /* lastErrno set by seekAndRead */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3355 | return SQLITE_IOERR_READ; executed 48 times by 1 test: return (10 | (1<<8)); Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3356 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3357 | storeLastErrno(pFile, 0); /* not a system error */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3358 | /* Unread parts of the buffer must be zero-filled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3359 | memset(&((char*)pBuf)[got], 0, amt-got); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3360 | return SQLITE_IOERR_SHORT_READ; executed 62139 times by 156 tests: return (10 | (2<<8)); Executed by:
| 62139 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3361 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3362 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3363 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3364 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3365 | ** Attempt to seek the file-descriptor passed as the first argument to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3366 | ** absolute offset iOff, then attempt to write nBuf bytes of data from | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3367 | ** pBuf to it. If an error occurs, return -1 and set *piErrno. Otherwise, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3368 | ** return the actual number of bytes written (which may be less than | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3369 | ** nBuf). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3370 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3371 | static int seekAndWriteFd( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3372 | int fd, /* File descriptor to write to */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3373 | i64 iOff, /* File offset to begin writing at */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3374 | const void *pBuf, /* Copy data from this buffer to the file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3375 | int nBuf, /* Size of buffer pBuf in bytes */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3376 | int *piErrno /* OUT: Error number if error occurs */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3377 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3378 | int rc = 0; /* Value returned by system call */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3379 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3380 | assert( nBuf==(nBuf&0x1ffff) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3381 | assert( fd>2 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3382 | assert( piErrno!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3383 | nBuf &= 0x1ffff; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3384 | TIMER_START; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3385 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3386 | #if defined(USE_PREAD) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3387 | do{ rc = (int)osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3388 | #elif defined(USE_PREAD64) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3389 | do{ rc = (int)osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR); executed 3921977 times by 407 tests: end of block Executed by:
| 0-3921977 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3390 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3391 | do{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3392 | i64 iSeek = lseek(fd, iOff, SEEK_SET); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3393 | SimulateIOError( iSeek = -1 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3394 | if( iSeek<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3395 | rc = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3396 | break; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3397 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3398 | rc = osWrite(fd, pBuf, nBuf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3399 | }while( rc<0 && errno==EINTR ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3400 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3401 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3402 | TIMER_END; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3403 | OSTRACE(("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED)); never executed: sqlite3DebugPrintf ("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, ((sqlite_uint64)0));
| 0-3921966 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3404 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3405 | if( rc<0 ) *piErrno = errno; never executed: *piErrno = (*__errno_location ()) ;
| 0-3921974 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3406 | return rc; executed 3921972 times by 407 tests: return rc; Executed by:
| 3921972 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3407 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3408 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3409 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3410 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3411 | ** Seek to the offset in id->offset then read cnt bytes into pBuf. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3412 | ** Return the number of bytes actually read. Update the offset. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3413 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3414 | ** To avoid stomping the errno value on a failed write the lastErrno value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3415 | ** is set before returning. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3416 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3417 | static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3418 | return seekAndWriteFd(id->h, offset, pBuf, cnt, &id->lastErrno); executed 3915217 times by 404 tests: return seekAndWriteFd(id->h, offset, pBuf, cnt, &id->lastErrno); Executed by:
| 3915217 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3419 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3420 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3421 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3422 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3423 | ** Write data from a buffer into a file. Return SQLITE_OK on success | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3424 | ** or some other error code on failure. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3425 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3426 | static int unixWrite( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3427 | sqlite3_file *id, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3428 | const void *pBuf, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3429 | int amt, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3430 | sqlite3_int64 offset | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3431 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3432 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3433 | int wrote = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3434 | assert( id ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3435 | assert( amt>0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3436 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3437 | /* If this is a database file (not a journal, master-journal or temp | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3438 | ** file), the bytes in the locking range should never be read or written. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3439 | #if 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3440 | assert( pFile->pPreallocatedUnused==0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3441 | || offset>=PENDING_BYTE+512 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3442 | || offset+amt<=PENDING_BYTE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3443 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3444 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3445 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3446 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3447 | /* If we are doing a normal write to a database file (as opposed to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3448 | ** doing a hot-journal rollback or a write to some file other than a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3449 | ** normal database file) then record the fact that the database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3450 | ** has changed. If the transaction counter is modified, record that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3451 | ** fact too. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3452 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3453 | if( pFile->inNormalWrite ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3454 | pFile->dbUpdate = 1; /* The database has been modified */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3455 | if( offset<=24 && offset+amt>=27 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3456 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3457 | char oldCntr[4]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3458 | SimulateIOErrorBenign(1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3459 | rc = seekAndRead(pFile, 24, oldCntr, 4); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3460 | SimulateIOErrorBenign(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3461 | if( rc!=4 || memcmp(oldCntr, &((char*)pBuf)[24-offset], 4)!=0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3462 | pFile->transCntrChng = 1; /* The transaction counter has changed */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3463 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3464 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3465 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3466 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3467 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3468 | #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3469 | /* Deal with as much of this write request as possible by transfering | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3470 | ** data from the memory mapping using memcpy(). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3471 | if( offset<pFile->mmapSize ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3472 | if( offset+amt <= pFile->mmapSize ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3473 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3474 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3475 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3476 | int nCopy = pFile->mmapSize - offset; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3477 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3478 | pBuf = &((u8 *)pBuf)[nCopy]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3479 | amt -= nCopy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3480 | offset += nCopy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3481 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3482 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3483 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3484 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3485 | while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
| 0-3881847 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3486 | amt -= wrote; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3487 | offset += wrote; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3488 | pBuf = &((char*)pBuf)[wrote]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3489 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3490 | SimulateIOError(( wrote=(-1), amt=1 )); executed 75 times by 1 test: end of block Executed by:
| 0-3881770 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3491 | SimulateDiskfullError(( wrote=0, amt=1 )); executed 459 times by 1 test: end of block Executed by:
executed 68076 times by 1 test: end of block Executed by:
| 459-3813306 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3492 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3493 | if( amt>wrote ){
| 534-3881307 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3494 | if( wrote<0 && pFile->lastErrno!=ENOSPC ){
| 0-459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3495 | /* lastErrno set by seekAndWrite */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3496 | return SQLITE_IOERR_WRITE; executed 75 times by 1 test: return (10 | (3<<8)); Executed by:
| 75 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3497 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3498 | storeLastErrno(pFile, 0); /* not a system error */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3499 | return SQLITE_FULL; executed 459 times by 1 test: return 13; Executed by:
| 459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3500 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3501 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3502 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3503 | return SQLITE_OK; executed 3881307 times by 404 tests: return 0; Executed by:
| 3881307 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3504 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3505 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3506 | #ifdef SQLITE_TEST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3507 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3508 | ** Count the number of fullsyncs and normal syncs. This is used to test | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3509 | ** that syncs and fullsyncs are occurring at the right times. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3510 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3511 | int sqlite3_sync_count = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3512 | int sqlite3_fullsync_count = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3513 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3514 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3515 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3516 | ** We do not trust systems to provide a working fdatasync(). Some do. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3517 | ** Others do no. To be safe, we will stick with the (slightly slower) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3518 | ** fsync(). If you know that your system does support fdatasync() correctly, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3519 | ** then simply compile with -Dfdatasync=fdatasync or -DHAVE_FDATASYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3520 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3521 | #if !defined(fdatasync) && !HAVE_FDATASYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3522 | # define fdatasync fsync | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3523 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3524 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3525 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3526 | ** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3527 | ** the F_FULLFSYNC macro is defined. F_FULLFSYNC is currently | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3528 | ** only available on Mac OS X. But that could change. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3529 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3530 | #ifdef F_FULLFSYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3531 | # define HAVE_FULLFSYNC 1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3532 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3533 | # define HAVE_FULLFSYNC 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3534 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3535 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3536 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3537 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3538 | ** The fsync() system call does not work as advertised on many | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3539 | ** unix systems. The following procedure is an attempt to make | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3540 | ** it work better. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3541 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3542 | ** The SQLITE_NO_SYNC macro disables all fsync()s. This is useful | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3543 | ** for testing when we want to run through the test suite quickly. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3544 | ** You are strongly advised *not* to deploy with SQLITE_NO_SYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3545 | ** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3546 | ** or power failure will likely corrupt the database file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3547 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3548 | ** SQLite sets the dataOnly flag if the size of the file is unchanged. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3549 | ** The idea behind dataOnly is that it should only write the file content | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3550 | ** to disk, not the inode. We only set dataOnly if the file size is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3551 | ** unchanged since the file size is part of the inode. However, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3552 | ** Ted Ts'o tells us that fdatasync() will also write the inode if the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3553 | ** file size has changed. The only real difference between fdatasync() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3554 | ** and fsync(), Ted tells us, is that fdatasync() will not flush the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3555 | ** inode if the mtime or owner or other inode attributes have changed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3556 | ** We only care about the file size, not the other file attributes, so | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3557 | ** as far as SQLite is concerned, an fdatasync() is always adequate. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3558 | ** So, we always use fdatasync() if it is available, regardless of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3559 | ** the value of the dataOnly flag. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3560 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3561 | static int full_fsync(int fd, int fullSync, int dataOnly){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3562 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3563 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3564 | /* The following "ifdef/elif/else/" block has the same structure as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3565 | ** the one below. It is replicated here solely to avoid cluttering | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3566 | ** up the real code with the UNUSED_PARAMETER() macros. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3567 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3568 | #ifdef SQLITE_NO_SYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3569 | UNUSED_PARAMETER(fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3570 | UNUSED_PARAMETER(fullSync); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3571 | UNUSED_PARAMETER(dataOnly); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3572 | #elif HAVE_FULLFSYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3573 | UNUSED_PARAMETER(dataOnly); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3574 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3575 | UNUSED_PARAMETER(fullSync); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3576 | UNUSED_PARAMETER(dataOnly); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3577 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3578 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3579 | /* Record the number of times that we do a normal fsync() and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3580 | ** FULLSYNC. This is used during testing to verify that this procedure | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3581 | ** gets called with the correct arguments. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3582 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3583 | #ifdef SQLITE_TEST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3584 | if( fullSync ) sqlite3_fullsync_count++; executed 5570 times by 1 test: sqlite3_fullsync_count++; Executed by:
| 5570-249754 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3585 | sqlite3_sync_count++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3586 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3587 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3588 | /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3589 | ** no-op. But go ahead and call fstat() to validate the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3590 | ** descriptor as we need a method to provoke a failure during | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3591 | ** coverate testing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3592 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3593 | #ifdef SQLITE_NO_SYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3594 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3595 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3596 | rc = osFstat(fd, &buf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3597 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3598 | #elif HAVE_FULLFSYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3599 | if( fullSync ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3600 | rc = osFcntl(fd, F_FULLFSYNC, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3601 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3602 | rc = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3603 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3604 | /* If the FULLFSYNC failed, fall back to attempting an fsync(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3605 | ** It shouldn't be possible for fullfsync to fail on the local | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3606 | ** file system (on OSX), so failure indicates that FULLFSYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3607 | ** isn't supported for this file system. So, attempt an fsync | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3608 | ** and (for now) ignore the overhead of a superfluous fcntl call. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3609 | ** It'd be better to detect fullfsync support once and avoid | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3610 | ** the fcntl call every time sync is called. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3611 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3612 | if( rc ) rc = fsync(fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3613 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3614 | #elif defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3615 | /* fdatasync() on HFS+ doesn't yet flush the file size if it changed correctly | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3616 | ** so currently we default to the macro that redefines fdatasync to fsync | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3617 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3618 | rc = fsync(fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3619 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3620 | rc = fdatasync(fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3621 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3622 | if( rc==-1 && errno==ENOTSUP ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3623 | rc = fsync(fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3624 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3625 | #endif /* OS_VXWORKS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3626 | #endif /* ifdef SQLITE_NO_SYNC elif HAVE_FULLFSYNC */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3627 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3628 | if( OS_VXWORKS && rc!= -1 ){ dead code: rc!= -1 dead code: { rc = 0; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3629 | rc = 0; dead code: { rc = 0; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3630 | } dead code: { rc = 0; } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3631 | return rc; executed 255324 times by 125 tests: return rc; Executed by:
| 255324 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3632 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3633 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3634 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3635 | ** Open a file descriptor to the directory containing file zFilename. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3636 | ** If successful, *pFd is set to the opened file descriptor and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3637 | ** SQLITE_OK is returned. If an error occurs, either SQLITE_NOMEM | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3638 | ** or SQLITE_CANTOPEN is returned and *pFd is set to an undefined | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3639 | ** value. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3640 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3641 | ** The directory file descriptor is used for only one thing - to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3642 | ** fsync() a directory to make sure file creation and deletion events | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3643 | ** are flushed to disk. Such fsyncs are not needed on newer | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3644 | ** journaling filesystems, but are required on older filesystems. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3645 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3646 | ** This routine can be overridden using the xSetSysCall interface. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3647 | ** The ability to override this routine was added in support of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3648 | ** chromium sandbox. Opening a directory is a security risk (we are | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3649 | ** told) so making it overrideable allows the chromium sandbox to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3650 | ** replace this routine with a harmless no-op. To make this routine | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3651 | ** a no-op, replace it with a stub that returns SQLITE_OK but leaves | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3652 | ** *pFd set to a negative number. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3653 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3654 | ** If SQLITE_OK is returned, the caller is responsible for closing | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3655 | ** the file descriptor *pFd using close(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3656 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3657 | static int openDirectory(const char *zFilename, int *pFd){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3658 | int ii; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3659 | int fd = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3660 | char zDirname[MAX_PATHNAME+1]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3661 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3662 | sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3663 | for(ii=(int)strlen(zDirname); ii>0 && zDirname[ii]!='/'; ii--); executed 634037 times by 125 tests: ; Executed by:
| 0-673049 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3664 | if( ii>0 ){
| 0-39012 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3665 | zDirname[ii] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3666 | }else{ executed 39012 times by 125 tests: end of block Executed by:
| 39012 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3667 | if( zDirname[0]!='/' ) zDirname[0] = '.'; never executed: zDirname[0] = '.';
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3668 | zDirname[1] = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3669 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3670 | fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3671 | if( fd>=0 ){
| 0-39012 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3672 | OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname)); never executed: sqlite3DebugPrintf ("OPENDIR %-3d %s\n", fd, zDirname);
| 0-39012 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3673 | } executed 39012 times by 125 tests: end of block Executed by:
| 39012 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3674 | *pFd = fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3675 | if( fd>=0 ) return SQLITE_OK; executed 39012 times by 125 tests: return 0; Executed by:
| 0-39012 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3676 | return unixLogError(SQLITE_CANTOPEN_BKPT, "openDirectory", zDirname); never executed: return unixLogErrorAtLine(sqlite3CantopenError(3676),"openDirectory",zDirname,3676); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3677 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3678 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3679 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3680 | ** Make sure all writes to a particular file are committed to disk. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3681 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3682 | ** If dataOnly==0 then both the file itself and its metadata (file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3683 | ** size, access time, etc) are synced. If dataOnly!=0 then only the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3684 | ** file data is synced. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3685 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3686 | ** Under Unix, also make sure that the directory entry for the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3687 | ** has been created by fsync-ing the directory that contains the file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3688 | ** If we do not do this and we encounter a power failure, the directory | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3689 | ** entry for the journal might not exist after we reboot. The next | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3690 | ** SQLite to access the file will not know that the journal exists (because | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3691 | ** the directory entry for the journal was never created) and the transaction | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3692 | ** will not roll back - possibly leading to database corruption. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3693 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3694 | static int unixSync(sqlite3_file *id, int flags){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3695 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3696 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3697 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3698 | int isDataOnly = (flags&SQLITE_SYNC_DATAONLY); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3699 | int isFullsync = (flags&0x0F)==SQLITE_SYNC_FULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3700 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3701 | /* Check that one of SQLITE_SYNC_NORMAL or FULL was passed */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3702 | assert((flags&0x0F)==SQLITE_SYNC_NORMAL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3703 | || (flags&0x0F)==SQLITE_SYNC_FULL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3704 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3705 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3706 | /* Unix cannot, but some systems may return SQLITE_FULL from here. This | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3707 | ** line is to test that doing so does not cause any problems. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3708 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3709 | SimulateDiskfullError( return SQLITE_FULL ); executed 3 times by 1 test: return 13; Executed by:
executed 189 times by 1 test: end of block Executed by:
| 3-216123 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3710 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3711 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3712 | OSTRACE(("SYNC %-3d\n", pFile->h)); never executed: sqlite3DebugPrintf ("SYNC %-3d\n", pFile->h);
| 0-216312 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3713 | rc = full_fsync(pFile->h, isFullsync, isDataOnly); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3714 | SimulateIOError( rc=1 ); executed 16 times by 1 test: end of block Executed by:
| 0-216296 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3715 | if( rc ){
| 16-216296 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3716 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3717 | return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath); executed 16 times by 1 test: return unixLogErrorAtLine((10 | (4<<8)),"full_fsync",pFile->zPath,3717); Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3718 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3719 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3720 | /* Also fsync the directory containing the file if the DIRSYNC flag | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3721 | ** is set. This is a one-time occurrence. Many systems (examples: AIX) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3722 | ** are unable to fsync a directory, so ignore errors on the fsync. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3723 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3724 | if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
| 38952-177344 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3725 | int dirfd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3726 | OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath, never executed: sqlite3DebugPrintf ("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath, 0, isFullsync) ;
| 0-38952 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3727 | HAVE_FULLFSYNC, isFullsync)); never executed: sqlite3DebugPrintf ("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath, 0, isFullsync) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3728 | rc = osOpenDirectory(pFile->zPath, &dirfd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3729 | if( rc==SQLITE_OK ){
| 0-38952 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3730 | full_fsync(dirfd, 0, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3731 | robust_close(pFile, dirfd, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3732 | }else{ executed 38952 times by 125 tests: end of block Executed by:
| 38952 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3733 | assert( rc==SQLITE_CANTOPEN ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3734 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3735 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3736 | pFile->ctrlFlags &= ~UNIXFILE_DIRSYNC; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3737 | } executed 38952 times by 125 tests: end of block Executed by:
| 38952 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3738 | return rc; executed 216296 times by 125 tests: return rc; Executed by:
| 216296 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3739 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3740 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3741 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3742 | ** Truncate an open file to a specified size | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3743 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3744 | static int unixTruncate(sqlite3_file *id, i64 nByte){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3745 | unixFile *pFile = (unixFile *)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3746 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3747 | assert( pFile ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3748 | SimulateIOError( return SQLITE_IOERR_TRUNCATE ); executed 4 times by 1 test: return (10 | (6<<8)); Executed by:
| 0-6227 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3749 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3750 | /* If the user has configured a chunk-size for this file, truncate the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3751 | ** file so that it consists of an integer number of chunks (i.e. the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3752 | ** actual file size after the operation may be larger than the requested | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3753 | ** size). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3754 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3755 | if( pFile->szChunk>0 ){
| 6-6221 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3756 | nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3757 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3758 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3759 | rc = robust_ftruncate(pFile->h, nByte); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3760 | if( rc ){
| 0-6227 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3761 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3762 | return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); never executed: return unixLogErrorAtLine((10 | (6<<8)),"ftruncate",pFile->zPath,3762); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3763 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3764 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3765 | /* If we are doing a normal write to a database file (as opposed to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3766 | ** doing a hot-journal rollback or a write to some file other than a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3767 | ** normal database file) and we truncate the file to zero length, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3768 | ** that effectively updates the change counter. This might happen | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3769 | ** when restoring a database using the backup API from a zero-length | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3770 | ** source. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3771 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3772 | if( pFile->inNormalWrite && nByte==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3773 | pFile->transCntrChng = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3774 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3775 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3776 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3777 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3778 | /* If the file was just truncated to a size smaller than the currently | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3779 | ** mapped region, reduce the effective mapping size as well. SQLite will | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3780 | ** use read() and write() to access data beyond this point from now on. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3781 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3782 | if( nByte<pFile->mmapSize ){
| 6-6221 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3783 | pFile->mmapSize = nByte; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3784 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3785 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3786 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3787 | return SQLITE_OK; executed 6227 times by 20 tests: return 0; Executed by:
| 6227 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3788 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3789 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3790 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3791 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3792 | ** Determine the current size of a file in bytes | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3793 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3794 | static int unixFileSize(sqlite3_file *id, i64 *pSize){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3795 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3796 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3797 | assert( id ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3798 | rc = osFstat(((unixFile*)id)->h, &buf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3799 | SimulateIOError( rc=1 ); executed 86 times by 1 test: end of block Executed by:
| 32-152691 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3800 | if( rc!=0 ){
| 86-152691 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3801 | storeLastErrno((unixFile*)id, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3802 | return SQLITE_IOERR_FSTAT; executed 86 times by 1 test: return (10 | (7<<8)); Executed by:
| 86 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3803 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3804 | *pSize = buf.st_size; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3805 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3806 | /* When opening a zero-size database, the findInodeInfo() procedure | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3807 | ** writes a single byte into that file in order to work around a bug | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3808 | ** in the OS-X msdos filesystem. In order to avoid problems with upper | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3809 | ** layers, we need to report this file size as zero even though it is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3810 | ** really 1. Ticket #3260. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3811 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3812 | if( *pSize==1 ) *pSize = 0; executed 2 times by 1 test: *pSize = 0; Executed by:
| 2-152689 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3813 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3814 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3815 | return SQLITE_OK; executed 152691 times by 435 tests: return 0; Executed by:
| 152691 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3816 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3817 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3818 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3819 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3820 | ** Handler for proxy-locking file-control verbs. Defined below in the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3821 | ** proxying locking division. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3822 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3823 | static int proxyFileControl(sqlite3_file*,int,void*); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3824 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3825 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3826 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3827 | ** This function is called to handle the SQLITE_FCNTL_SIZE_HINT | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3828 | ** file-control operation. Enlarge the database to nBytes in size | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3829 | ** (rounded up to the next chunk-size). If the database is already | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3830 | ** nBytes or larger, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3831 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3832 | static int fcntlSizeHint(unixFile *pFile, i64 nByte){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3833 | if( pFile->szChunk>0 ){
| 3303-31018 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3834 | i64 nSize; /* Required file size */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3835 | struct stat buf; /* Used to hold return values of fstat() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3836 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3837 | if( osFstat(pFile->h, &buf) ){
| 0-3303 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3838 | return SQLITE_IOERR_FSTAT; never executed: return (10 | (7<<8)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3839 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3840 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3841 | nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3842 | if( nSize>(i64)buf.st_size ){
| 157-3146 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3843 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3844 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3845 | /* The code below is handling the return value of osFallocate() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3846 | ** correctly. posix_fallocate() is defined to "returns zero on success, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3847 | ** or an error number on failure". See the manpage for details. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3848 | int err; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3849 | do{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3850 | err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3851 | }while( err==EINTR ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3852 | if( err && err!=EINVAL ) return SQLITE_IOERR_WRITE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3853 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3854 | /* If the OS does not have posix_fallocate(), fake it. Write a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3855 | ** single byte to the last byte in each block that falls entirely | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3856 | ** within the extended region. Then, if required, a single byte | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3857 | ** at offset (nSize-1), to set the size of the file correctly. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3858 | ** This is a similar technique to that used by glibc on systems | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3859 | ** that do not have a real fallocate() call. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3860 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3861 | int nBlk = buf.st_blksize; /* File-system block size */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3862 | int nWrite = 0; /* Number of bytes written by seekAndWrite */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3863 | i64 iWrite; /* Next offset to write to */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3864 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3865 | iWrite = (buf.st_size/nBlk)*nBlk + nBlk - 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3866 | assert( iWrite>=buf.st_size ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3867 | assert( ((iWrite+1)%nBlk)==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3868 | for(/*no-op*/; iWrite<nSize+nBlk-1; iWrite+=nBlk ){
| 3146-33370 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3869 | if( iWrite>=nSize ) iWrite = nSize - 1; executed 3 times by 1 test: iWrite = nSize - 1; Executed by:
| 3-33368 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3870 | nWrite = seekAndWrite(pFile, iWrite, "", 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3871 | if( nWrite!=1 ) return SQLITE_IOERR_WRITE; never executed: return (10 | (3<<8));
| 0-33371 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3872 | } executed 33370 times by 1 test: end of block Executed by:
| 33370 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3873 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3874 | } executed 3146 times by 1 test: end of block Executed by:
| 3146 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3875 | } executed 3303 times by 1 test: end of block Executed by:
| 3303 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3876 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3877 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3878 | if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
| 0-30777 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3879 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3880 | if( pFile->szChunk<=0 ){
| 335-3209 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3881 | if( robust_ftruncate(pFile->h, nByte) ){
| 0-335 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3882 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3883 | return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); never executed: return unixLogErrorAtLine((10 | (6<<8)),"ftruncate",pFile->zPath,3883); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3884 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3885 | } executed 335 times by 2 tests: end of block Executed by:
| 335 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3886 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3887 | rc = unixMapfile(pFile, nByte); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3888 | return rc; executed 3544 times by 2 tests: return rc; Executed by:
| 3544 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3889 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3890 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3891 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3892 | return SQLITE_OK; executed 30777 times by 107 tests: return 0; Executed by:
| 30777 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3893 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3894 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3895 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3896 | ** If *pArg is initially negative then this is a query. Set *pArg to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3897 | ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3898 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3899 | ** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3900 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3901 | static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3902 | if( *pArg<0 ){
| 9-848 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3903 | *pArg = (pFile->ctrlFlags & mask)!=0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3904 | }else if( (*pArg)==0 ){ executed 848 times by 10 tests: end of block Executed by:
| 2-848 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3905 | pFile->ctrlFlags &= ~mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3906 | }else{ executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3907 | pFile->ctrlFlags |= mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3908 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3909 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3910 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3911 | /* Forward declaration */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3912 | static int unixGetTempname(int nBuf, char *zBuf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3913 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3914 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3915 | ** Information and control of an open file handle. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3916 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3917 | static int unixFileControl(sqlite3_file *id, int op, void *pArg){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3918 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3919 | switch( op ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3920 | #if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3921 | case SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3922 | int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3923 | return rc ? SQLITE_IOERR_BEGIN_ATOMIC : SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3924 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3925 | case SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3926 | int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3927 | return rc ? SQLITE_IOERR_COMMIT_ATOMIC : SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3928 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3929 | case SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3930 | int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3931 | return rc ? SQLITE_IOERR_ROLLBACK_ATOMIC : SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3932 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3933 | #endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3934 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3935 | case SQLITE_FCNTL_LOCKSTATE: { executed 144 times by 2 tests: case 1: Executed by:
| 144 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3936 | *(int*)pArg = pFile->eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3937 | return SQLITE_OK; executed 144 times by 2 tests: return 0; Executed by:
| 144 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3938 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3939 | case SQLITE_FCNTL_LAST_ERRNO: { executed 1 time by 1 test: case 4: Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3940 | *(int*)pArg = pFile->lastErrno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3941 | return SQLITE_OK; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3942 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3943 | case SQLITE_FCNTL_CHUNK_SIZE: { executed 3214 times by 1 test: case 6: Executed by:
| 3214 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3944 | pFile->szChunk = *(int *)pArg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3945 | return SQLITE_OK; executed 3214 times by 1 test: return 0; Executed by:
| 3214 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3946 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3947 | case SQLITE_FCNTL_SIZE_HINT: { executed 34321 times by 108 tests: case 5: Executed by:
| 34321 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3948 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3949 | SimulateIOErrorBenign(1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3950 | rc = fcntlSizeHint(pFile, *(i64 *)pArg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3951 | SimulateIOErrorBenign(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3952 | return rc; executed 34321 times by 108 tests: return rc; Executed by:
| 34321 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3953 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3954 | case SQLITE_FCNTL_PERSIST_WAL: { executed 850 times by 10 tests: case 10: Executed by:
| 850 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3955 | unixModeBit(pFile, UNIXFILE_PERSIST_WAL, (int*)pArg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3956 | return SQLITE_OK; executed 850 times by 10 tests: return 0; Executed by:
| 850 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3957 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3958 | case SQLITE_FCNTL_POWERSAFE_OVERWRITE: { executed 7 times by 1 test: case 13: Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3959 | unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3960 | return SQLITE_OK; executed 7 times by 1 test: return 0; Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3961 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3962 | case SQLITE_FCNTL_VFSNAME: { executed 2 times by 1 test: case 12: Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3963 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3964 | return SQLITE_OK; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3965 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3966 | case SQLITE_FCNTL_TEMPFILENAME: { executed 1 time by 1 test: case 16: Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3967 | char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3968 | if( zTFile ){
| 0-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3969 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3970 | *(char**)pArg = zTFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3971 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3972 | return SQLITE_OK; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3973 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3974 | case SQLITE_FCNTL_HAS_MOVED: { executed 55073 times by 422 tests: case 20: Executed by:
| 55073 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3975 | *(int*)pArg = fileHasMoved(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3976 | return SQLITE_OK; executed 55073 times by 422 tests: return 0; Executed by:
| 55073 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3977 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3978 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3979 | case SQLITE_FCNTL_LOCK_TIMEOUT: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3980 | pFile->iBusyTimeout = *(int*)pArg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3981 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3982 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3983 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3984 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3985 | case SQLITE_FCNTL_MMAP_SIZE: { executed 98479 times by 74 tests: case 18: Executed by:
| 98479 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3986 | i64 newLimit = *(i64*)pArg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3987 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3988 | if( newLimit>sqlite3GlobalConfig.mxMmap ){
| 0-98479 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3989 | newLimit = sqlite3GlobalConfig.mxMmap; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3990 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3991 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3992 | /* The value of newLimit may be eventually cast to (size_t) and passed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3993 | ** to mmap(). Restrict its value to 2GB if (size_t) is not at least a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3994 | ** 64-bit type. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3995 | if( newLimit>0 && sizeof(size_t)<8 ){
| 0-98074 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3996 | newLimit = (newLimit & 0x7FFFFFFF); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3997 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3998 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3999 | *(i64*)pArg = pFile->mmapSizeMax; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4000 | if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
| 12-98217 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4001 | pFile->mmapSizeMax = newLimit; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4002 | if( pFile->mmapSize>0 ){
| 3-383 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4003 | unixUnmapfile(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4004 | rc = unixMapfile(pFile, -1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4005 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4006 | } executed 386 times by 2 tests: end of block Executed by:
| 386 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4007 | return rc; executed 98479 times by 74 tests: return rc; Executed by:
| 98479 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4008 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4009 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4010 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4011 | /* The pager calls this method to signal that it has done | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4012 | ** a rollback and that the database is therefore unchanged and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4013 | ** it hence it is OK for the transaction change counter to be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4014 | ** unchanged. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4015 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4016 | case SQLITE_FCNTL_DB_UNCHANGED: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4017 | ((unixFile*)id)->dbUpdate = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4018 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4019 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4020 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4021 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4022 | case SQLITE_FCNTL_SET_LOCKPROXYFILE: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4023 | case SQLITE_FCNTL_GET_LOCKPROXYFILE: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4024 | return proxyFileControl(id,op,pArg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4025 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4026 | #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4027 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4028 | return SQLITE_NOTFOUND; executed 236976 times by 438 tests: return 12; Executed by:
| 236976 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4029 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4030 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4031 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4032 | ** If pFd->sectorSize is non-zero when this function is called, it is a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4033 | ** no-op. Otherwise, the values of pFd->sectorSize and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4034 | ** pFd->deviceCharacteristics are set according to the file-system | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4035 | ** characteristics. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4036 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4037 | ** There are two versions of this function. One for QNX and one for all | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4038 | ** other systems. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4039 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4040 | #ifndef __QNXNTO__ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4041 | static void setDeviceCharacteristics(unixFile *pFd){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4042 | assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4043 | if( pFd->sectorSize==0 ){
| 31947-327376 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4044 | #if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4045 | int res; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4046 | u32 f = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4047 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4048 | /* Check for support for F2FS atomic batch writes. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4049 | res = osIoctl(pFd->h, F2FS_IOC_GET_FEATURES, &f); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4050 | if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4051 | pFd->deviceCharacteristics = SQLITE_IOCAP_BATCH_ATOMIC; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4052 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4053 | #endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4054 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4055 | /* Set the POWERSAFE_OVERWRITE flag if requested. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4056 | if( pFd->ctrlFlags & UNIXFILE_PSOW ){
| 6-31941 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4057 | pFd->deviceCharacteristics |= SQLITE_IOCAP_POWERSAFE_OVERWRITE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4058 | } executed 31941 times by 406 tests: end of block Executed by:
| 31941 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4059 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4060 | pFd->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4061 | } executed 31947 times by 406 tests: end of block Executed by:
| 31947 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4062 | } executed 359323 times by 406 tests: end of block Executed by:
| 359323 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4063 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4064 | #include <sys/dcmd_blk.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4065 | #include <sys/statvfs.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4066 | static void setDeviceCharacteristics(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4067 | if( pFile->sectorSize == 0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4068 | struct statvfs fsInfo; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4069 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4070 | /* Set defaults for non-supported filesystems */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4071 | pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4072 | pFile->deviceCharacteristics = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4073 | if( fstatvfs(pFile->h, &fsInfo) == -1 ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4074 | return; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4075 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4076 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4077 | if( !strcmp(fsInfo.f_basetype, "tmp") ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4078 | pFile->sectorSize = fsInfo.f_bsize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4079 | pFile->deviceCharacteristics = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4080 | SQLITE_IOCAP_ATOMIC4K | /* All ram filesystem writes are atomic */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4081 | SQLITE_IOCAP_SAFE_APPEND | /* growing the file does not occur until | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4082 | ** the write succeeds */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4083 | SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4084 | ** so it is ordered */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4085 | 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4086 | }else if( strstr(fsInfo.f_basetype, "etfs") ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4087 | pFile->sectorSize = fsInfo.f_bsize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4088 | pFile->deviceCharacteristics = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4089 | /* etfs cluster size writes are atomic */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4090 | (pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) | | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4091 | SQLITE_IOCAP_SAFE_APPEND | /* growing the file does not occur until | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4092 | ** the write succeeds */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4093 | SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4094 | ** so it is ordered */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4095 | 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4096 | }else if( !strcmp(fsInfo.f_basetype, "qnx6") ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4097 | pFile->sectorSize = fsInfo.f_bsize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4098 | pFile->deviceCharacteristics = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4099 | SQLITE_IOCAP_ATOMIC | /* All filesystem writes are atomic */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4100 | SQLITE_IOCAP_SAFE_APPEND | /* growing the file does not occur until | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4101 | ** the write succeeds */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4102 | SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4103 | ** so it is ordered */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4104 | 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4105 | }else if( !strcmp(fsInfo.f_basetype, "qnx4") ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4106 | pFile->sectorSize = fsInfo.f_bsize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4107 | pFile->deviceCharacteristics = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4108 | /* full bitset of atomics from max sector size and smaller */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4109 | ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 | | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4110 | SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4111 | ** so it is ordered */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4112 | 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4113 | }else if( strstr(fsInfo.f_basetype, "dos") ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4114 | pFile->sectorSize = fsInfo.f_bsize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4115 | pFile->deviceCharacteristics = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4116 | /* full bitset of atomics from max sector size and smaller */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4117 | ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 | | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4118 | SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4119 | ** so it is ordered */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4120 | 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4121 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4122 | pFile->deviceCharacteristics = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4123 | SQLITE_IOCAP_ATOMIC512 | /* blocks are atomic */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4124 | SQLITE_IOCAP_SAFE_APPEND | /* growing the file does not occur until | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4125 | ** the write succeeds */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4126 | 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4127 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4128 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4129 | /* Last chance verification. If the sector size isn't a multiple of 512 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4130 | ** then it isn't valid.*/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4131 | if( pFile->sectorSize % 512 != 0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4132 | pFile->deviceCharacteristics = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4133 | pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4134 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4135 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4136 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4137 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4138 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4139 | ** Return the sector size in bytes of the underlying block device for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4140 | ** the specified file. This is almost always 512 bytes, but may be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4141 | ** larger for some devices. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4142 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4143 | ** SQLite code assumes this function cannot fail. It also assumes that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4144 | ** if two files are created in the same file-system directory (i.e. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4145 | ** a database and its journal file) that the sector size will be the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4146 | ** same for both. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4147 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4148 | static int unixSectorSize(sqlite3_file *id){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4149 | unixFile *pFd = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4150 | setDeviceCharacteristics(pFd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4151 | return pFd->sectorSize; executed 20 times by 2 tests: return pFd->sectorSize; Executed by:
| 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4152 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4153 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4154 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4155 | ** Return the device characteristics for the file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4156 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4157 | ** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4158 | ** However, that choice is controversial since technically the underlying | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4159 | ** file system does not always provide powersafe overwrites. (In other | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4160 | ** words, after a power-loss event, parts of the file that were never | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4161 | ** written might end up being altered.) However, non-PSOW behavior is very, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4162 | ** very rare. And asserting PSOW makes a large reduction in the amount | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4163 | ** of required I/O for journaling, since a lot of padding is eliminated. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4164 | ** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4165 | ** available to turn it off and URI query parameter available to turn it off. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4166 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4167 | static int unixDeviceCharacteristics(sqlite3_file *id){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4168 | unixFile *pFd = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4169 | setDeviceCharacteristics(pFd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4170 | return pFd->deviceCharacteristics; executed 359303 times by 406 tests: return pFd->deviceCharacteristics; Executed by:
| 359303 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4171 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4172 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4173 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4174 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4175 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4176 | ** Return the system page size. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4177 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4178 | ** This function should not be called directly by other code in this file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4179 | ** Instead, it should be called via macro osGetpagesize(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4180 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4181 | static int unixGetpagesize(void){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4182 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4183 | return 1024; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4184 | #elif defined(_BSD_SOURCE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4185 | return getpagesize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4186 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4187 | return (int)sysconf(_SC_PAGESIZE); executed 2924 times by 49 tests: return (int)sysconf( _SC_PAGESIZE ); Executed by:
| 2924 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4188 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4189 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4190 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4191 | #endif /* !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4192 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4193 | #ifndef SQLITE_OMIT_WAL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4194 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4195 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4196 | ** Object used to represent an shared memory buffer. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4197 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4198 | ** When multiple threads all reference the same wal-index, each thread | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4199 | ** has its own unixShm object, but they all point to a single instance | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4200 | ** of this unixShmNode object. In other words, each wal-index is opened | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4201 | ** only once per process. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4202 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4203 | ** Each unixShmNode object is connected to a single unixInodeInfo object. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4204 | ** We could coalesce this object into unixInodeInfo, but that would mean | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4205 | ** every open file that does not use shared memory (in other words, most | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4206 | ** open files) would have to carry around this extra information. So | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4207 | ** the unixInodeInfo object contains a pointer to this unixShmNode object | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4208 | ** and the unixShmNode object is created only when needed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4209 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4210 | ** unixMutexHeld() must be true when creating or destroying | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4211 | ** this object or while reading or writing the following fields: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4212 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4213 | ** nRef | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4214 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4215 | ** The following fields are read-only after the object is created: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4216 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4217 | ** fid | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4218 | ** zFilename | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4219 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4220 | ** Either unixShmNode.mutex must be held or unixShmNode.nRef==0 and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4221 | ** unixMutexHeld() is true when reading or writing any other field | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4222 | ** in this structure. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4223 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4224 | struct unixShmNode { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4225 | unixInodeInfo *pInode; /* unixInodeInfo that owns this SHM node */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4226 | sqlite3_mutex *mutex; /* Mutex to access this object */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4227 | char *zFilename; /* Name of the mmapped file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4228 | int h; /* Open file descriptor */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4229 | int szRegion; /* Size of shared-memory regions */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4230 | u16 nRegion; /* Size of array apRegion */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4231 | u8 isReadonly; /* True if read-only */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4232 | u8 isUnlocked; /* True if no DMS lock held */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4233 | char **apRegion; /* Array of mapped shared-memory regions */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4234 | int nRef; /* Number of unixShm objects pointing to this */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4235 | unixShm *pFirst; /* All unixShm objects pointing to this */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4236 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4237 | u8 exclMask; /* Mask of exclusive locks held */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4238 | u8 sharedMask; /* Mask of shared locks held */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4239 | u8 nextShmId; /* Next available unixShm.id value */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4240 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4241 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4242 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4243 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4244 | ** Structure used internally by this VFS to record the state of an | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4245 | ** open shared memory connection. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4246 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4247 | ** The following fields are initialized when this object is created and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4248 | ** are read-only thereafter: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4249 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4250 | ** unixShm.pFile | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4251 | ** unixShm.id | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4252 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4253 | ** All other fields are read/write. The unixShm.pFile->mutex must be held | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4254 | ** while accessing any read/write fields. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4255 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4256 | struct unixShm { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4257 | unixShmNode *pShmNode; /* The underlying unixShmNode object */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4258 | unixShm *pNext; /* Next unixShm with the same unixShmNode */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4259 | u8 hasMutex; /* True if holding the unixShmNode mutex */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4260 | u8 id; /* Id of this connection within its unixShmNode */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4261 | u16 sharedMask; /* Mask of shared locks held */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4262 | u16 exclMask; /* Mask of exclusive locks held */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4263 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4264 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4265 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4266 | ** Constants used for locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4267 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4268 | #define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4269 | #define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4270 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4271 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4272 | ** Apply posix advisory locks for all bytes from ofst through ofst+n-1. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4273 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4274 | ** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4275 | ** otherwise. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4276 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4277 | static int unixShmSystemLock( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4278 | unixFile *pFile, /* Open connection to the WAL file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4279 | int lockType, /* F_UNLCK, F_RDLCK, or F_WRLCK */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4280 | int ofst, /* First byte of the locking range */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4281 | int n /* Number of bytes to lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4282 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4283 | unixShmNode *pShmNode; /* Apply locks to this open shared-memory segment */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4284 | struct flock f; /* The posix advisory locking structure */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4285 | int rc = SQLITE_OK; /* Result code form fcntl() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4286 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4287 | /* Access to the unixShmNode object is serialized by the caller */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4288 | pShmNode = pFile->pInode->pShmNode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4289 | assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->mutex) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4290 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4291 | /* Shared locks never span more than one byte */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4292 | assert( n==1 || lockType!=F_RDLCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4293 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4294 | /* Locks are within range */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4295 | assert( n>=1 && n<=SQLITE_SHM_NLOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4296 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4297 | if( pShmNode->h>=0 ){
| 68-382155 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4298 | /* Initialize the locking parameters */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4299 | f.l_type = lockType; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4300 | f.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4301 | f.l_start = ofst; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4302 | f.l_len = n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4303 | rc = osSetPosixAdvisoryLock(pShmNode->h, &f, pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4304 | rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
| 154-382001 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4305 | } executed 382155 times by 49 tests: end of block Executed by:
| 382155 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4306 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4307 | /* Update the global lock state and do debug tracing */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4308 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4309 | { u16 mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4310 | OSTRACE(("SHM-LOCK ")); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4311 | mask = ofst>31 ? 0xffff : (1<<(ofst+n)) - (1<<ofst); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4312 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4313 | if( lockType==F_UNLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4314 | OSTRACE(("unlock %d ok", ofst)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4315 | pShmNode->exclMask &= ~mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4316 | pShmNode->sharedMask &= ~mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4317 | }else if( lockType==F_RDLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4318 | OSTRACE(("read-lock %d ok", ofst)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4319 | pShmNode->exclMask &= ~mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4320 | pShmNode->sharedMask |= mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4321 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4322 | assert( lockType==F_WRLCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4323 | OSTRACE(("write-lock %d ok", ofst)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4324 | pShmNode->exclMask |= mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4325 | pShmNode->sharedMask &= ~mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4326 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4327 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4328 | if( lockType==F_UNLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4329 | OSTRACE(("unlock %d failed", ofst)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4330 | }else if( lockType==F_RDLCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4331 | OSTRACE(("read-lock failed")); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4332 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4333 | assert( lockType==F_WRLCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4334 | OSTRACE(("write-lock %d failed", ofst)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4335 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4336 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4337 | OSTRACE((" - afterwards %03x,%03x\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4338 | pShmNode->sharedMask, pShmNode->exclMask)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4339 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4340 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4341 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4342 | return rc; executed 382223 times by 49 tests: return rc; Executed by:
| 382223 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4343 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4344 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4345 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4346 | ** Return the minimum number of 32KB shm regions that should be mapped at | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4347 | ** a time, assuming that each mapping must be an integer multiple of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4348 | ** current system page-size. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4349 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4350 | ** Usually, this is 1. The exception seems to be systems that are configured | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4351 | ** to use 64KB pages - in this case each mapping must cover at least two | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4352 | ** shm regions. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4353 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4354 | static int unixShmRegionPerMap(void){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4355 | int shmsz = 32*1024; /* SHM region size */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4356 | int pgsz = osGetpagesize(); /* System page size */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4357 | assert( ((pgsz-1)&pgsz)==0 ); /* Page size must be a power of 2 */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4358 | if( pgsz<shmsz ) return 1; executed 2924 times by 49 tests: return 1; Executed by:
| 5-2924 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4359 | return pgsz/shmsz; executed 5 times by 1 test: return pgsz/shmsz; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4360 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4361 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4362 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4363 | ** Purge the unixShmNodeList list of all entries with unixShmNode.nRef==0. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4364 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4365 | ** This is not a VFS shared-memory method; it is a utility function called | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4366 | ** by VFS shared-memory methods. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4367 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4368 | static void unixShmPurge(unixFile *pFd){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4369 | unixShmNode *p = pFd->pInode->pShmNode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4370 | assert( unixMutexHeld() ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4371 | if( p && ALWAYS(p->nRef==0) ){
| 0-824 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4372 | int nShmPerMap = unixShmRegionPerMap(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4373 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4374 | assert( p->pInode==pFd->pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4375 | sqlite3_mutex_free(p->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4376 | for(i=0; i<p->nRegion; i+=nShmPerMap){
| 824-886 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4377 | if( p->h>=0 ){
| 2-884 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4378 | osMunmap(p->apRegion[i], p->szRegion); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4379 | }else{ executed 884 times by 38 tests: end of block Executed by:
| 884 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4380 | sqlite3_free(p->apRegion[i]); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4381 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4382 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4383 | sqlite3_free(p->apRegion); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4384 | if( p->h>=0 ){
| 7-817 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4385 | robust_close(pFd, p->h, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4386 | p->h = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4387 | } executed 817 times by 38 tests: end of block Executed by:
| 817 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4388 | p->pInode->pShmNode = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4389 | sqlite3_free(p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4390 | } executed 824 times by 38 tests: end of block Executed by:
| 824 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4391 | } executed 824 times by 38 tests: end of block Executed by:
| 824 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4392 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4393 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4394 | ** The DMS lock has not yet been taken on shm file pShmNode. Attempt to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4395 | ** take it now. Return SQLITE_OK if successful, or an SQLite error | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4396 | ** code otherwise. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4397 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4398 | ** If the DMS cannot be locked because this is a readonly_shm=1 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4399 | ** connection and no other process already holds a lock, return | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4400 | ** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4401 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4402 | static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4403 | struct flock lock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4404 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4405 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4406 | /* Use F_GETLK to determine the locks other processes are holding | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4407 | ** on the DMS byte. If it indicates that another process is holding | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4408 | ** a SHARED lock, then this process may also take a SHARED lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4409 | ** and proceed with opening the *-shm file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4410 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4411 | ** Or, if no other process is holding any lock, then this process | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4412 | ** is the first to open it. In this case take an EXCLUSIVE lock on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4413 | ** DMS byte and truncate the *-shm file to zero bytes in size. Then | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4414 | ** downgrade to a SHARED lock on the DMS byte. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4415 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4416 | ** If another process is holding an EXCLUSIVE lock on the DMS byte, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4417 | ** return SQLITE_BUSY to the caller (it will try again). An earlier | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4418 | ** version of this code attempted the SHARED lock at this point. But | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4419 | ** this introduced a subtle race condition: if the process holding | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4420 | ** EXCLUSIVE failed just before truncating the *-shm file, then this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4421 | ** process might open and use the *-shm file without truncating it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4422 | ** And if the *-shm file has been corrupted by a power failure or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4423 | ** system crash, the database itself may also become corrupt. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4424 | lock.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4425 | lock.l_start = UNIX_SHM_DMS; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4426 | lock.l_len = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4427 | lock.l_type = F_WRLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4428 | if( osFcntl(pShmNode->h, F_GETLK, &lock)!=0 ) {
| 0-885 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4429 | rc = SQLITE_IOERR_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4430 | }else if( lock.l_type==F_UNLCK ){ never executed: end of block
| 0-837 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4431 | if( pShmNode->isReadonly ){
| 68-769 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4432 | pShmNode->isUnlocked = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4433 | rc = SQLITE_READONLY_CANTINIT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4434 | }else{ executed 68 times by 2 tests: end of block Executed by:
| 68 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4435 | rc = unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4436 | if( rc==SQLITE_OK && robust_ftruncate(pShmNode->h, 0) ){
| 0-769 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4437 | rc = unixLogError(SQLITE_IOERR_SHMOPEN,"ftruncate",pShmNode->zFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4438 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4439 | } executed 769 times by 20 tests: end of block Executed by:
| 769 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4440 | }else if( lock.l_type==F_WRLCK ){
| 0-48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4441 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4442 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4443 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4444 | if( rc==SQLITE_OK ){
| 68-817 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4445 | assert( lock.l_type==F_UNLCK || lock.l_type==F_RDLCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4446 | rc = unixShmSystemLock(pDbFd, F_RDLCK, UNIX_SHM_DMS, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4447 | } executed 817 times by 49 tests: end of block Executed by:
| 817 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4448 | return rc; executed 885 times by 49 tests: return rc; Executed by:
| 885 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4449 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4450 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4451 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4452 | ** Open a shared-memory area associated with open database file pDbFd. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4453 | ** This particular implementation uses mmapped files. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4454 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4455 | ** The file used to implement shared-memory is in the same directory | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4456 | ** as the open database file and has the same name as the open database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4457 | ** file with the "-shm" suffix added. For example, if the database file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4458 | ** is "/home/user1/config.db" then the file that is created and mmapped | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4459 | ** for shared memory will be called "/home/user1/config.db-shm". | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4460 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4461 | ** Another approach to is to use files in /dev/shm or /dev/tmp or an | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4462 | ** some other tmpfs mount. But if a file in a different directory | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4463 | ** from the database file is used, then differing access permissions | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4464 | ** or a chroot() might cause two different processes on the same | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4465 | ** database to end up using different files for shared memory - | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4466 | ** meaning that their memory would not really be shared - resulting | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4467 | ** in database corruption. Nevertheless, this tmpfs file usage | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4468 | ** can be enabled at compile-time using -DSQLITE_SHM_DIRECTORY="/dev/shm" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4469 | ** or the equivalent. The use of the SQLITE_SHM_DIRECTORY compile-time | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4470 | ** option results in an incompatible build of SQLite; builds of SQLite | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4471 | ** that with differing SQLITE_SHM_DIRECTORY settings attempt to use the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4472 | ** same database file at the same time, database corruption will likely | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4473 | ** result. The SQLITE_SHM_DIRECTORY compile-time option is considered | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4474 | ** "unsupported" and may go away in a future SQLite release. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4475 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4476 | ** When opening a new shared-memory file, if no other instances of that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4477 | ** file are currently open, in this process or in other processes, then | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4478 | ** the file must be truncated to zero length or have its header cleared. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4479 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4480 | ** If the original database file (pDbFd) is using the "unix-excl" VFS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4481 | ** that means that an exclusive lock is held on the database file and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4482 | ** that no other processes are able to read or write the database. In | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4483 | ** that case, we do not really need shared memory. No shared memory | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4484 | ** file is created. The shared memory will be simulated with heap memory. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4485 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4486 | static int unixOpenSharedMemory(unixFile *pDbFd){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4487 | struct unixShm *p = 0; /* The connection to be opened */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4488 | struct unixShmNode *pShmNode; /* The underlying mmapped file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4489 | int rc = SQLITE_OK; /* Result code */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4490 | unixInodeInfo *pInode; /* The inode of fd */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4491 | char *zShm; /* Name of the file used for SHM */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4492 | int nShmFilename; /* Size of the SHM filename in bytes */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4493 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4494 | /* Allocate space for the new unixShm object. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4495 | p = sqlite3_malloc64( sizeof(*p) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4496 | if( p==0 ) return SQLITE_NOMEM_BKPT; never executed: return 7;
| 0-1123 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4497 | memset(p, 0, sizeof(*p)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4498 | assert( pDbFd->pShm==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4499 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4500 | /* Check to see if a unixShmNode object already exists. Reuse an existing | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4501 | ** one if present. Create a new one if necessary. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4502 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4503 | assert( unixFileMutexNotheld(pDbFd) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4504 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4505 | pInode = pDbFd->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4506 | pShmNode = pInode->pShmNode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4507 | if( pShmNode==0 ){
| 288-835 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4508 | struct stat sStat; /* fstat() info for database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4509 | #ifndef SQLITE_SHM_DIRECTORY | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4510 | const char *zBasePath = pDbFd->zPath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4511 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4512 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4513 | /* Call fstat() to figure out the permissions on the database file. If | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4514 | ** a new *-shm file is created, an attempt will be made to create it | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4515 | ** with the same permissions. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4516 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4517 | if( osFstat(pDbFd->h, &sStat) ){
| 0-835 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4518 | rc = SQLITE_IOERR_FSTAT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4519 | goto shm_open_err; never executed: goto shm_open_err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4520 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4521 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4522 | #ifdef SQLITE_SHM_DIRECTORY | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4523 | nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4524 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4525 | nShmFilename = 6 + (int)strlen(zBasePath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4526 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4527 | pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4528 | if( pShmNode==0 ){
| 0-835 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4529 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4530 | goto shm_open_err; never executed: goto shm_open_err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4531 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4532 | memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4533 | zShm = pShmNode->zFilename = (char*)&pShmNode[1]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4534 | #ifdef SQLITE_SHM_DIRECTORY | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4535 | sqlite3_snprintf(nShmFilename, zShm, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4536 | SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4537 | (u32)sStat.st_ino, (u32)sStat.st_dev); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4538 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4539 | sqlite3_snprintf(nShmFilename, zShm, "%s-shm", zBasePath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4540 | sqlite3FileSuffix3(pDbFd->zPath, zShm); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4541 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4542 | pShmNode->h = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4543 | pDbFd->pInode->pShmNode = pShmNode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4544 | pShmNode->pInode = pDbFd->pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4545 | if( sqlite3GlobalConfig.bCoreMutex ){
| 0-835 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4546 | pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4547 | if( pShmNode->mutex==0 ){
| 0-835 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4548 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4549 | goto shm_open_err; never executed: goto shm_open_err; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4550 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4551 | } executed 835 times by 49 tests: end of block Executed by:
| 835 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4552 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4553 | if( pInode->bProcessLock==0 ){
| 2-833 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4554 | if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
| 21-812 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4555 | pShmNode->h = robust_open(zShm, O_RDWR|O_CREAT, (sStat.st_mode&0777)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4556 | } executed 812 times by 48 tests: end of block Executed by:
| 812 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4557 | if( pShmNode->h<0 ){
| 26-807 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4558 | pShmNode->h = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4559 | if( pShmNode->h<0 ){
| 5-21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4560 | rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4561 | goto shm_open_err; executed 5 times by 1 test: goto shm_open_err; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4562 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4563 | pShmNode->isReadonly = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4564 | } executed 21 times by 3 tests: end of block Executed by:
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4565 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4566 | /* If this process is running as root, make sure that the SHM file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4567 | ** is owned by the same user that owns the original database. Otherwise, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4568 | ** the original owner will not be able to connect. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4569 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4570 | robustFchown(pShmNode->h, sStat.st_uid, sStat.st_gid); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4571 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4572 | rc = unixLockSharedMemory(pDbFd, pShmNode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4573 | if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err; never executed: goto shm_open_err;
| 0-811 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4574 | } executed 828 times by 49 tests: end of block Executed by:
| 828 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4575 | } executed 830 times by 49 tests: end of block Executed by:
| 830 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4576 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4577 | /* Make the new connection a child of the unixShmNode */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4578 | p->pShmNode = pShmNode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4579 | #ifdef SQLITE_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4580 | p->id = pShmNode->nextShmId++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4581 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4582 | pShmNode->nRef++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4583 | pDbFd->pShm = p; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4584 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4585 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4586 | /* The reference count on pShmNode has already been incremented under | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4587 | ** the cover of the unixEnterMutex() mutex and the pointer from the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4588 | ** new (struct unixShm) object to the pShmNode has been set. All that is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4589 | ** left to do is to link the new object into the linked list starting | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4590 | ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4591 | ** mutex. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4592 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4593 | sqlite3_mutex_enter(pShmNode->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4594 | p->pNext = pShmNode->pFirst; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4595 | pShmNode->pFirst = p; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4596 | sqlite3_mutex_leave(pShmNode->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4597 | return rc; executed 1118 times by 49 tests: return rc; Executed by:
| 1118 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4598 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4599 | /* Jump here on any error */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4600 | shm_open_err: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4601 | unixShmPurge(pDbFd); /* This call frees pShmNode if required */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4602 | sqlite3_free(p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4603 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4604 | return rc; executed 5 times by 1 test: return rc; Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4605 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4606 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4607 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4608 | ** This function is called to obtain a pointer to region iRegion of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4609 | ** shared-memory associated with the database file fd. Shared-memory regions | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4610 | ** are numbered starting from zero. Each shared-memory region is szRegion | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4611 | ** bytes in size. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4612 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4613 | ** If an error occurs, an error code is returned and *pp is set to NULL. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4614 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4615 | ** Otherwise, if the bExtend parameter is 0 and the requested shared-memory | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4616 | ** region has not been allocated (by any client, including one running in a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4617 | ** separate process), then *pp is set to NULL and SQLITE_OK returned. If | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4618 | ** bExtend is non-zero and the requested shared-memory region has not yet | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4619 | ** been allocated, it is allocated by this function. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4620 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4621 | ** If the shared-memory region has already been allocated or is allocated by | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4622 | ** this call as described above, then it is mapped into this processes | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4623 | ** address space (if it is not already), *pp is set to point to the mapped | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4624 | ** memory and SQLITE_OK returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4625 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4626 | static int unixShmMap( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4627 | sqlite3_file *fd, /* Handle open on database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4628 | int iRegion, /* Region to retrieve */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4629 | int szRegion, /* Size of regions */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4630 | int bExtend, /* True to extend file if necessary */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4631 | void volatile **pp /* OUT: Mapped memory */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4632 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4633 | unixFile *pDbFd = (unixFile*)fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4634 | unixShm *p; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4635 | unixShmNode *pShmNode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4636 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4637 | int nShmPerMap = unixShmRegionPerMap(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4638 | int nReqRegion; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4639 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4640 | /* If the shared-memory file has not yet been opened, open it now. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4641 | if( pDbFd->pShm==0 ){
| 982-1123 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4642 | rc = unixOpenSharedMemory(pDbFd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4643 | if( rc!=SQLITE_OK ) return rc; executed 22 times by 2 tests: return rc; Executed by:
| 22-1101 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4644 | } executed 1101 times by 49 tests: end of block Executed by:
| 1101 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4645 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4646 | p = pDbFd->pShm; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4647 | pShmNode = p->pShmNode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4648 | sqlite3_mutex_enter(pShmNode->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4649 | if( pShmNode->isUnlocked ){
| 57-2026 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4650 | rc = unixLockSharedMemory(pDbFd, pShmNode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4651 | if( rc!=SQLITE_OK ) goto shmpage_out; executed 51 times by 2 tests: goto shmpage_out; Executed by:
| 6-51 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4652 | pShmNode->isUnlocked = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4653 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4654 | assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4655 | assert( pShmNode->pInode==pDbFd->pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4656 | assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4657 | assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4658 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4659 | /* Minimum number of regions required to be mapped. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4660 | nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4661 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4662 | if( pShmNode->nRegion<nReqRegion ){
| 365-1667 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4663 | char **apNew; /* New apRegion[] array */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4664 | int nByte = nReqRegion*szRegion; /* Minimum required file size */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4665 | struct stat sStat; /* Used by fstat() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4666 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4667 | pShmNode->szRegion = szRegion; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4668 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4669 | if( pShmNode->h>=0 ){
| 2-1665 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4670 | /* The requested region is not mapped into this processes address space. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4671 | ** Check to see if it has been allocated (i.e. if the wal-index file is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4672 | ** large enough to contain the requested region). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4673 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4674 | if( osFstat(pShmNode->h, &sStat) ){
| 0-1665 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4675 | rc = SQLITE_IOERR_SHMSIZE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4676 | goto shmpage_out; never executed: goto shmpage_out; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4677 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4678 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4679 | if( sStat.st_size<nByte ){
| 53-1612 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4680 | /* The requested memory region does not exist. If bExtend is set to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4681 | ** false, exit early. *pp will be set to NULL and SQLITE_OK returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4682 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4683 | if( !bExtend ){
| 769-843 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4684 | goto shmpage_out; executed 769 times by 20 tests: goto shmpage_out; Executed by:
| 769 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4685 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4686 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4687 | /* Alternatively, if bExtend is true, extend the file. Do this by | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4688 | ** writing a single byte to the end of each (OS) page being | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4689 | ** allocated or extended. Technically, we need only write to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4690 | ** last page in order to extend the file. But writing to all new | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4691 | ** pages forces the OS to allocate them immediately, which reduces | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4692 | ** the chances of SIGBUS while accessing the mapped region later on. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4693 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4694 | else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4695 | static const int pgsz = 4096; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4696 | int iPg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4697 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4698 | /* Write to the last byte of each newly allocated or extended page */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4699 | assert( (nByte % pgsz)==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4700 | for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){
| 843-6760 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4701 | int x = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4702 | if( seekAndWriteFd(pShmNode->h, iPg*pgsz + pgsz-1, "", 1, &x)!=1 ){
| 0-6760 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4703 | const char *zFile = pShmNode->zFilename; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4704 | rc = unixLogError(SQLITE_IOERR_SHMSIZE, "write", zFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4705 | goto shmpage_out; never executed: goto shmpage_out; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4706 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4707 | } executed 6760 times by 21 tests: end of block Executed by:
| 6760 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4708 | } executed 843 times by 21 tests: end of block Executed by:
| 843 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4709 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4710 | } executed 896 times by 49 tests: end of block Executed by:
| 896 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4711 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4712 | /* Map the requested memory region into this processes address space. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4713 | apNew = (char **)sqlite3_realloc( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4714 | pShmNode->apRegion, nReqRegion*sizeof(char *) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4715 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4716 | if( !apNew ){
| 0-898 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4717 | rc = SQLITE_IOERR_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4718 | goto shmpage_out; never executed: goto shmpage_out; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4719 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4720 | pShmNode->apRegion = apNew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4721 | while( pShmNode->nRegion<nReqRegion ){
| 898-901 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4722 | int nMap = szRegion*nShmPerMap; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4723 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4724 | void *pMem; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4725 | if( pShmNode->h>=0 ){
| 2-899 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4726 | pMem = osMmap(0, nMap, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4727 | pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE,
| 10-889 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4728 | MAP_SHARED, pShmNode->h, szRegion*(i64)pShmNode->nRegion | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4729 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4730 | if( pMem==MAP_FAILED ){
| 0-899 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4731 | rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4732 | goto shmpage_out; never executed: goto shmpage_out; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4733 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4734 | }else{ executed 899 times by 49 tests: end of block Executed by:
| 899 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4735 | pMem = sqlite3_malloc64(szRegion); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4736 | if( pMem==0 ){
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4737 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4738 | goto shmpage_out; never executed: goto shmpage_out; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4739 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4740 | memset(pMem, 0, szRegion); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4741 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4742 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4743 | for(i=0; i<nShmPerMap; i++){
| 901-903 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4744 | pShmNode->apRegion[pShmNode->nRegion+i] = &((char*)pMem)[szRegion*i]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4745 | } executed 903 times by 49 tests: end of block Executed by:
| 903 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4746 | pShmNode->nRegion += nShmPerMap; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4747 | } executed 901 times by 49 tests: end of block Executed by:
| 901 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4748 | } executed 898 times by 49 tests: end of block Executed by:
| 898 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4749 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4750 | shmpage_out: code before this statement executed 1263 times by 49 tests: shmpage_out: Executed by:
| 1263 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4751 | if( pShmNode->nRegion>iRegion ){
| 820-1263 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4752 | *pp = pShmNode->apRegion[iRegion]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4753 | }else{ executed 1263 times by 49 tests: end of block Executed by:
| 1263 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4754 | *pp = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4755 | } executed 820 times by 20 tests: end of block Executed by:
| 820 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4756 | if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY; executed 13 times by 3 tests: rc = 8; Executed by:
| 13-2019 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4757 | sqlite3_mutex_leave(pShmNode->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4758 | return rc; executed 2083 times by 49 tests: return rc; Executed by:
| 2083 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4759 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4760 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4761 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4762 | ** Change the lock state for a shared-memory segment. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4763 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4764 | ** Note that the relationship between SHAREd and EXCLUSIVE locks is a little | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4765 | ** different here than in posix. In xShmLock(), one can go from unlocked | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4766 | ** to shared and back or from unlocked to exclusive and back. But one may | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4767 | ** not go from shared to exclusive or from exclusive to shared. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4768 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4769 | static int unixShmLock( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4770 | sqlite3_file *fd, /* Database file holding the shared memory */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4771 | int ofst, /* First lock to acquire or release */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4772 | int n, /* Number of locks to acquire or release */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4773 | int flags /* What to do with the lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4774 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4775 | unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4776 | unixShm *p = pDbFd->pShm; /* The shared memory being locked */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4777 | unixShm *pX; /* For looping over all siblings */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4778 | unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4779 | int rc = SQLITE_OK; /* Result code */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4780 | u16 mask; /* Mask of locks to take or release */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4781 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4782 | assert( pShmNode==pDbFd->pInode->pShmNode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4783 | assert( pShmNode->pInode==pDbFd->pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4784 | assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4785 | assert( n>=1 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4786 | assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4787 | || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4788 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4789 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4790 | assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4791 | assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4792 | assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4793 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4794 | mask = (1<<(ofst+n)) - (1<<ofst); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4795 | assert( n>1 || mask==(1<<ofst) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4796 | sqlite3_mutex_enter(pShmNode->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4797 | if( flags & SQLITE_SHM_UNLOCK ){
| 190525-195298 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4798 | u16 allMask = 0; /* Mask of locks held by siblings */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4799 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4800 | /* See if any siblings hold this same lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4801 | for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
| 190525-205499 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4802 | if( pX==p ) continue; executed 190525 times by 49 tests: continue; Executed by:
| 14974-190525 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4803 | assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4804 | allMask |= pX->sharedMask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4805 | } executed 14974 times by 1 test: end of block Executed by:
| 14974 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4806 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4807 | /* Unlock the system-level locks */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4808 | if( (mask & allMask)==0 ){
| 283-190242 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4809 | rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4810 | }else{ executed 190242 times by 49 tests: end of block Executed by:
| 190242 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4811 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4812 | } executed 283 times by 1 test: end of block Executed by:
| 283 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4813 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4814 | /* Undo the local locks */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4815 | if( rc==SQLITE_OK ){
| 0-190525 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4816 | p->exclMask &= ~mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4817 | p->sharedMask &= ~mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4818 | } executed 190525 times by 49 tests: end of block Executed by:
| 190525 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4819 | }else if( flags & SQLITE_SHM_SHARED ){ executed 190525 times by 49 tests: end of block Executed by:
| 62211-190525 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4820 | u16 allShared = 0; /* Union of locks held by connections other than "p" */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4821 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4822 | /* Find out which shared locks are already held by sibling connections. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4823 | ** If any sibling already holds an exclusive lock, go ahead and return | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4824 | ** SQLITE_BUSY. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4825 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4826 | for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
| 62203-69031 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4827 | if( (pX->exclMask & mask)!=0 ){
| 8-69023 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4828 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4829 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4830 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4831 | allShared |= pX->sharedMask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4832 | } executed 69023 times by 49 tests: end of block Executed by:
| 69023 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4833 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4834 | /* Get shared locks at the system level, if necessary */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4835 | if( rc==SQLITE_OK ){
| 8-62203 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4836 | if( (allShared & mask)==0 ){
| 282-61921 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4837 | rc = unixShmSystemLock(pDbFd, F_RDLCK, ofst+UNIX_SHM_BASE, n); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4838 | }else{ executed 61921 times by 49 tests: end of block Executed by:
| 61921 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4839 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4840 | } executed 282 times by 1 test: end of block Executed by:
| 282 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4841 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4842 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4843 | /* Get the local shared locks */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4844 | if( rc==SQLITE_OK ){
| 11-62200 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4845 | p->sharedMask |= mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4846 | } executed 62200 times by 49 tests: end of block Executed by:
| 62200 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4847 | }else{ executed 62211 times by 49 tests: end of block Executed by:
| 62211 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4848 | /* Make sure no sibling connections hold locks that will block this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4849 | ** lock. If any do, return SQLITE_BUSY right away. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4850 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4851 | for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
| 128474-151811 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4852 | if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){
| 71-151740 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4853 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4854 | break; executed 4613 times by 1 test: break; Executed by:
| 4613 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4855 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4856 | } executed 147198 times by 46 tests: end of block Executed by:
| 147198 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4857 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4858 | /* Get the exclusive locks at the system level. Then if successful | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4859 | ** also mark the local connection as being locked. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4860 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4861 | if( rc==SQLITE_OK ){
| 4613-128474 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4862 | rc = unixShmSystemLock(pDbFd, F_WRLCK, ofst+UNIX_SHM_BASE, n); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4863 | if( rc==SQLITE_OK ){
| 151-128323 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4864 | assert( (p->sharedMask & mask)==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4865 | p->exclMask |= mask; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4866 | } executed 128323 times by 46 tests: end of block Executed by:
| 128323 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4867 | } executed 128474 times by 46 tests: end of block Executed by:
| 128474 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4868 | } executed 133087 times by 46 tests: end of block Executed by:
| 133087 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4869 | sqlite3_mutex_leave(pShmNode->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4870 | OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n", never executed: sqlite3DebugPrintf ("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n", p->id, (pid_t)getpid(), p->sharedMask, p->exclMask) ;
| 0-385823 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4871 | p->id, osGetpid(0), p->sharedMask, p->exclMask)); never executed: sqlite3DebugPrintf ("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n", p->id, (pid_t)getpid(), p->sharedMask, p->exclMask) ; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4872 | return rc; executed 385823 times by 49 tests: return rc; Executed by:
| 385823 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4873 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4874 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4875 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4876 | ** Implement a memory barrier or memory fence on shared memory. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4877 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4878 | ** All loads and stores begun before the barrier must complete before | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4879 | ** any load or store begun after the barrier. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4880 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4881 | static void unixShmBarrier( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4882 | sqlite3_file *fd /* Database file holding the shared memory */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4883 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4884 | UNUSED_PARAMETER(fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4885 | sqlite3MemoryBarrier(); /* compiler-defined memory barrier */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4886 | assert( fd->pMethods->xLock==nolockLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4887 | || unixFileMutexNotheld((unixFile*)fd) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4888 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4889 | unixEnterMutex(); /* Also mutex, for redundancy */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4890 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4891 | } executed 187057 times by 49 tests: end of block Executed by:
| 187057 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4892 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4893 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4894 | ** Close a connection to shared-memory. Delete the underlying | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4895 | ** storage if deleteFlag is true. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4896 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4897 | ** If there is no shared memory associated with the connection then this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4898 | ** routine is a harmless no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4899 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4900 | static int unixShmUnmap( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4901 | sqlite3_file *fd, /* The underlying database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4902 | int deleteFlag /* Delete shared-memory if true */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4903 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4904 | unixShm *p; /* The connection to be closed */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4905 | unixShmNode *pShmNode; /* The underlying shared-memory file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4906 | unixShm **pp; /* For looping over sibling connections */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4907 | unixFile *pDbFd; /* The underlying database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4908 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4909 | pDbFd = (unixFile*)fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4910 | p = pDbFd->pShm; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4911 | if( p==0 ) return SQLITE_OK; executed 4 times by 1 test: return 0; Executed by:
| 4-1107 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4912 | pShmNode = p->pShmNode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4913 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4914 | assert( pShmNode==pDbFd->pInode->pShmNode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4915 | assert( pShmNode->pInode==pDbFd->pInode ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4916 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4917 | /* Remove connection p from the set of connections associated | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4918 | ** with pShmNode */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4919 | sqlite3_mutex_enter(pShmNode->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4920 | for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){} executed 1312 times by 1 test: end of block Executed by:
| 1107-1312 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4921 | *pp = p->pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4922 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4923 | /* Free the connection p */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4924 | sqlite3_free(p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4925 | pDbFd->pShm = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4926 | sqlite3_mutex_leave(pShmNode->mutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4927 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4928 | /* If pShmNode->nRef has reached 0, then close the underlying | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4929 | ** shared-memory file, too */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4930 | assert( unixFileMutexNotheld(pDbFd) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4931 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4932 | assert( pShmNode->nRef>0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4933 | pShmNode->nRef--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4934 | if( pShmNode->nRef==0 ){
| 288-819 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4935 | if( deleteFlag && pShmNode->h>=0 ){
| 2-717 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4936 | osUnlink(pShmNode->zFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4937 | } executed 715 times by 10 tests: end of block Executed by:
| 715 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4938 | unixShmPurge(pDbFd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4939 | } executed 819 times by 38 tests: end of block Executed by:
| 819 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4940 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4941 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4942 | return SQLITE_OK; executed 1107 times by 38 tests: return 0; Executed by:
| 1107 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4943 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4944 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4945 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4946 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4947 | # define unixShmMap 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4948 | # define unixShmLock 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4949 | # define unixShmBarrier 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4950 | # define unixShmUnmap 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4951 | #endif /* #ifndef SQLITE_OMIT_WAL */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4952 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4953 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4954 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4955 | ** If it is currently memory mapped, unmap file pFd. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4956 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4957 | static void unixUnmapfile(unixFile *pFd){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4958 | assert( pFd->nFetchOut==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4959 | if( pFd->pMapRegion ){
| 226-76490 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4960 | osMunmap(pFd->pMapRegion, pFd->mmapSizeActual); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4961 | pFd->pMapRegion = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4962 | pFd->mmapSize = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4963 | pFd->mmapSizeActual = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4964 | } executed 226 times by 2 tests: end of block Executed by:
| 226 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4965 | } executed 76716 times by 334 tests: end of block Executed by:
| 76716 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4966 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4967 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4968 | ** Attempt to set the size of the memory mapping maintained by file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4969 | ** descriptor pFd to nNew bytes. Any existing mapping is discarded. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4970 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4971 | ** If successful, this function sets the following variables: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4972 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4973 | ** unixFile.pMapRegion | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4974 | ** unixFile.mmapSize | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4975 | ** unixFile.mmapSizeActual | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4976 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4977 | ** If unsuccessful, an error message is logged via sqlite3_log() and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4978 | ** the three variables above are zeroed. In this case SQLite should | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4979 | ** continue accessing the database using the xRead() and xWrite() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4980 | ** methods. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4981 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4982 | static void unixRemapfile( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4983 | unixFile *pFd, /* File descriptor object */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4984 | i64 nNew /* Required mapping size */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4985 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4986 | const char *zErr = "mmap"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4987 | int h = pFd->h; /* File descriptor open on db file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4988 | u8 *pOrig = (u8 *)pFd->pMapRegion; /* Pointer to current file mapping */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4989 | i64 nOrig = pFd->mmapSizeActual; /* Size of pOrig region in bytes */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4990 | u8 *pNew = 0; /* Location of new mapping */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4991 | int flags = PROT_READ; /* Flags to pass to mmap() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4992 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4993 | assert( pFd->nFetchOut==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4994 | assert( nNew>pFd->mmapSize ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4995 | assert( nNew<=pFd->mmapSizeMax ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4996 | assert( nNew>0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4997 | assert( pFd->mmapSizeActual>=pFd->mmapSize ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4998 | assert( MAP_FAILED!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4999 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5000 | #ifdef SQLITE_MMAP_READWRITE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5001 | if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5002 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5003 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5004 | if( pOrig ){
| 234-3363 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5005 | #if HAVE_MREMAP | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5006 | i64 nReuse = pFd->mmapSize; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5007 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5008 | const int szSyspage = osGetpagesize(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5009 | i64 nReuse = (pFd->mmapSize & ~(szSyspage-1)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5010 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5011 | u8 *pReq = &pOrig[nReuse]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5012 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5013 | /* Unmap any pages of the existing mapping that cannot be reused. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5014 | if( nReuse!=nOrig ){
| 4-3359 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5015 | osMunmap(pReq, nOrig-nReuse); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5016 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5017 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5018 | #if HAVE_MREMAP | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5019 | pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5020 | zErr = "mremap"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5021 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5022 | pNew = osMmap(pReq, nNew-nReuse, flags, MAP_SHARED, h, nReuse); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5023 | if( pNew!=MAP_FAILED ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5024 | if( pNew!=pReq ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5025 | osMunmap(pNew, nNew - nReuse); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5026 | pNew = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5027 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5028 | pNew = pOrig; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5029 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5030 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5031 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5032 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5033 | /* The attempt to extend the existing mapping failed. Free it. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5034 | if( pNew==MAP_FAILED || pNew==0 ){
| 0-3356 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5035 | osMunmap(pOrig, nReuse); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5036 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5037 | } executed 3363 times by 2 tests: end of block Executed by:
| 3363 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5038 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5039 | /* If pNew is still NULL, try to create an entirely new mapping. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5040 | if( pNew==0 ){
| 234-3363 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5041 | pNew = osMmap(0, nNew, flags, MAP_SHARED, h, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5042 | } executed 234 times by 2 tests: end of block Executed by:
| 234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5043 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5044 | if( pNew==MAP_FAILED ){
| 8-3589 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5045 | pNew = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5046 | nNew = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5047 | unixLogError(SQLITE_OK, zErr, pFd->zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5048 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5049 | /* If the mmap() above failed, assume that all subsequent mmap() calls | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5050 | ** will probably fail too. Fall back to using xRead/xWrite exclusively | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5051 | ** in this case. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5052 | pFd->mmapSizeMax = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5053 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5054 | pFd->pMapRegion = (void *)pNew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5055 | pFd->mmapSize = pFd->mmapSizeActual = nNew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5056 | } executed 3597 times by 2 tests: end of block Executed by:
| 3597 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5057 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5058 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5059 | ** Memory map or remap the file opened by file-descriptor pFd (if the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5060 | ** is already mapped, the existing mapping is replaced by the new). Or, if | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5061 | ** there already exists a mapping for this file, and there are still | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5062 | ** outstanding xFetch() references to it, this function is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5063 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5064 | ** If parameter nByte is non-negative, then it is the requested size of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5065 | ** the mapping to create. Otherwise, if nByte is less than zero, then the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5066 | ** requested size is the size of the file on disk. The actual size of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5067 | ** created mapping is either the requested size or the value configured | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5068 | ** using SQLITE_FCNTL_MMAP_LIMIT, whichever is smaller. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5069 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5070 | ** SQLITE_OK is returned if no error occurs (even if the mapping is not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5071 | ** recreated as a result of outstanding references) or an SQLite error | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5072 | ** code otherwise. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5073 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5074 | static int unixMapfile(unixFile *pFd, i64 nMap){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5075 | assert( nMap>=0 || pFd->nFetchOut==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5076 | assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5077 | if( pFd->nFetchOut>0 ) return SQLITE_OK; never executed: return 0;
| 0-3599 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5078 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5079 | if( nMap<0 ){
| 55-3544 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5080 | struct stat statbuf; /* Low-level file information */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5081 | if( osFstat(pFd->h, &statbuf) ){
| 0-55 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5082 | return SQLITE_IOERR_FSTAT; never executed: return (10 | (7<<8)); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5083 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5084 | nMap = statbuf.st_size; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5085 | } executed 55 times by 1 test: end of block Executed by:
| 55 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5086 | if( nMap>pFd->mmapSizeMax ){
| 18-3581 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5087 | nMap = pFd->mmapSizeMax; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5088 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5089 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5090 | assert( nMap>0 || (pFd->mmapSize==0 && pFd->pMapRegion==0) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5091 | if( nMap!=pFd->mmapSize ){
| 2-3597 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5092 | unixRemapfile(pFd, nMap); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5093 | } executed 3597 times by 2 tests: end of block Executed by:
| 3597 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5094 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5095 | return SQLITE_OK; executed 3599 times by 2 tests: return 0; Executed by:
| 3599 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5096 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5097 | #endif /* SQLITE_MAX_MMAP_SIZE>0 */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5098 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5099 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5100 | ** If possible, return a pointer to a mapping of file fd starting at offset | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5101 | ** iOff. The mapping must be valid for at least nAmt bytes. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5102 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5103 | ** If such a pointer can be obtained, store it in *pp and return SQLITE_OK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5104 | ** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5105 | ** Finally, if an error does occur, return an SQLite error code. The final | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5106 | ** value of *pp is undefined in this case. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5107 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5108 | ** If this function does return a pointer, the caller must eventually | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5109 | ** release the reference by calling unixUnfetch(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5110 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5111 | static int unixFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5112 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5113 | unixFile *pFd = (unixFile *)fd; /* The underlying database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5114 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5115 | *pp = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5116 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5117 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5118 | if( pFd->mmapSizeMax>0 ){
| 15357-113867 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5119 | if( pFd->pMapRegion==0 ){
| 52-113815 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5120 | int rc = unixMapfile(pFd, -1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5121 | if( rc!=SQLITE_OK ) return rc; never executed: return rc;
| 0-52 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5122 | } executed 52 times by 1 test: end of block Executed by:
| 52 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5123 | if( pFd->mmapSize >= iOff+nAmt ){
| 14082-99785 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5124 | *pp = &((u8 *)pFd->pMapRegion)[iOff]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5125 | pFd->nFetchOut++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5126 | } executed 99784 times by 2 tests: end of block Executed by:
| 99784 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5127 | } executed 113867 times by 2 tests: end of block Executed by:
| 113867 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5128 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5129 | return SQLITE_OK; executed 129224 times by 2 tests: return 0; Executed by:
| 129224 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5130 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5131 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5132 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5133 | ** If the third argument is non-NULL, then this function releases a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5134 | ** reference obtained by an earlier call to unixFetch(). The second | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5135 | ** argument passed to this function must be the same as the corresponding | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5136 | ** argument that was passed to the unixFetch() invocation. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5137 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5138 | ** Or, if the third argument is NULL, then this function is being called | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5139 | ** to inform the VFS layer that, according to POSIX, any existing mapping | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5140 | ** may now be invalid and should be unmapped. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5141 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5142 | static int unixUnfetch(sqlite3_file *fd, i64 iOff, void *p){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5143 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5144 | unixFile *pFd = (unixFile *)fd; /* The underlying database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5145 | UNUSED_PARAMETER(iOff); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5146 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5147 | /* If p==0 (unmap the entire file) then there must be no outstanding | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5148 | ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5149 | ** then there must be at least one outstanding. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5150 | assert( (p==0)==(pFd->nFetchOut==0) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5151 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5152 | /* If p!=0, it must match the iOff value. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5153 | assert( p==0 || p==&((u8 *)pFd->pMapRegion)[iOff] ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5154 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5155 | if( p ){
| 217-99784 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5156 | pFd->nFetchOut--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5157 | }else{ executed 99784 times by 2 tests: end of block Executed by:
| 99784 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5158 | unixUnmapfile(pFd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5159 | } executed 217 times by 3 tests: end of block Executed by:
| 217 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5160 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5161 | assert( pFd->nFetchOut>=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5162 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5163 | UNUSED_PARAMETER(fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5164 | UNUSED_PARAMETER(p); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5165 | UNUSED_PARAMETER(iOff); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5166 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5167 | return SQLITE_OK; executed 100001 times by 4 tests: return 0; Executed by:
| 100001 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5168 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5169 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5170 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5171 | ** Here ends the implementation of all sqlite3_file methods. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5172 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5173 | ********************** End sqlite3_file Methods ******************************* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5174 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5175 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5176 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5177 | ** This division contains definitions of sqlite3_io_methods objects that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5178 | ** implement various file locking strategies. It also contains definitions | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5179 | ** of "finder" functions. A finder-function is used to locate the appropriate | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5180 | ** sqlite3_io_methods object for a particular database file. The pAppData | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5181 | ** field of the sqlite3_vfs VFS objects are initialized to be pointers to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5182 | ** the correct finder-function for that VFS. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5183 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5184 | ** Most finder functions return a pointer to a fixed sqlite3_io_methods | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5185 | ** object. The only interesting finder-function is autolockIoFinder, which | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5186 | ** looks at the filesystem type and tries to guess the best locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5187 | ** strategy from that. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5188 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5189 | ** For finder-function F, two objects are created: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5190 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5191 | ** (1) The real finder-function named "FImpt()". | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5192 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5193 | ** (2) A constant pointer to this function named just "F". | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5194 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5195 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5196 | ** A pointer to the F pointer is used as the pAppData value for VFS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5197 | ** objects. We have to do this instead of letting pAppData point | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5198 | ** directly at the finder-function since C90 rules prevent a void* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5199 | ** from be cast into a function pointer. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5200 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5201 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5202 | ** Each instance of this macro generates two objects: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5203 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5204 | ** * A constant sqlite3_io_methods object call METHOD that has locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5205 | ** methods CLOSE, LOCK, UNLOCK, CKRESLOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5206 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5207 | ** * An I/O method finder function called FINDER that returns a pointer | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5208 | ** to the METHOD object in the previous bullet. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5209 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5210 | #define IOMETHODS(FINDER,METHOD,VERSION,CLOSE,LOCK,UNLOCK,CKLOCK,SHMMAP) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5211 | static const sqlite3_io_methods METHOD = { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5212 | VERSION, /* iVersion */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5213 | CLOSE, /* xClose */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5214 | unixRead, /* xRead */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5215 | unixWrite, /* xWrite */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5216 | unixTruncate, /* xTruncate */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5217 | unixSync, /* xSync */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5218 | unixFileSize, /* xFileSize */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5219 | LOCK, /* xLock */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5220 | UNLOCK, /* xUnlock */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5221 | CKLOCK, /* xCheckReservedLock */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5222 | unixFileControl, /* xFileControl */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5223 | unixSectorSize, /* xSectorSize */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5224 | unixDeviceCharacteristics, /* xDeviceCapabilities */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5225 | SHMMAP, /* xShmMap */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5226 | unixShmLock, /* xShmLock */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5227 | unixShmBarrier, /* xShmBarrier */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5228 | unixShmUnmap, /* xShmUnmap */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5229 | unixFetch, /* xFetch */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5230 | unixUnfetch, /* xUnfetch */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5231 | }; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5232 | static const sqlite3_io_methods *FINDER##Impl(const char *z, unixFile *p){ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5233 | UNUSED_PARAMETER(z); UNUSED_PARAMETER(p); \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5234 | return &METHOD; \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5235 | } \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5236 | static const sqlite3_io_methods *(*const FINDER)(const char*,unixFile *p) \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5237 | = FINDER##Impl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5238 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5239 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5240 | ** Here are all of the sqlite3_io_methods objects for each of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5241 | ** locking strategies. Functions that return pointers to these methods | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5242 | ** are also created. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5243 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5244 | IOMETHODS( executed 32248 times by 438 tests: return &posixIoMethods; Executed by:
| 32248 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5245 | posixIoFinder, /* Finder function name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5246 | posixIoMethods, /* sqlite3_io_methods object name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5247 | 3, /* shared memory and mmap are enabled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5248 | unixClose, /* xClose method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5249 | unixLock, /* xLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5250 | unixUnlock, /* xUnlock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5251 | unixCheckReservedLock, /* xCheckReservedLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5252 | unixShmMap /* xShmMap method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5253 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5254 | IOMETHODS( executed 2 times by 1 test: return &nolockIoMethods; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5255 | nolockIoFinder, /* Finder function name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5256 | nolockIoMethods, /* sqlite3_io_methods object name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5257 | 3, /* shared memory and mmap are enabled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5258 | nolockClose, /* xClose method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5259 | nolockLock, /* xLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5260 | nolockUnlock, /* xUnlock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5261 | nolockCheckReservedLock, /* xCheckReservedLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5262 | 0 /* xShmMap method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5263 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5264 | IOMETHODS( executed 2 times by 1 test: return &dotlockIoMethods; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5265 | dotlockIoFinder, /* Finder function name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5266 | dotlockIoMethods, /* sqlite3_io_methods object name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5267 | 1, /* shared memory is disabled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5268 | dotlockClose, /* xClose method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5269 | dotlockLock, /* xLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5270 | dotlockUnlock, /* xUnlock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5271 | dotlockCheckReservedLock, /* xCheckReservedLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5272 | 0 /* xShmMap method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5273 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5274 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5275 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5276 | IOMETHODS( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5277 | flockIoFinder, /* Finder function name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5278 | flockIoMethods, /* sqlite3_io_methods object name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5279 | 1, /* shared memory is disabled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5280 | flockClose, /* xClose method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5281 | flockLock, /* xLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5282 | flockUnlock, /* xUnlock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5283 | flockCheckReservedLock, /* xCheckReservedLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5284 | 0 /* xShmMap method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5285 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5286 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5287 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5288 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5289 | IOMETHODS( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5290 | semIoFinder, /* Finder function name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5291 | semIoMethods, /* sqlite3_io_methods object name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5292 | 1, /* shared memory is disabled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5293 | semXClose, /* xClose method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5294 | semXLock, /* xLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5295 | semXUnlock, /* xUnlock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5296 | semXCheckReservedLock, /* xCheckReservedLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5297 | 0 /* xShmMap method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5298 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5299 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5300 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5301 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5302 | IOMETHODS( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5303 | afpIoFinder, /* Finder function name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5304 | afpIoMethods, /* sqlite3_io_methods object name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5305 | 1, /* shared memory is disabled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5306 | afpClose, /* xClose method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5307 | afpLock, /* xLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5308 | afpUnlock, /* xUnlock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5309 | afpCheckReservedLock, /* xCheckReservedLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5310 | 0 /* xShmMap method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5311 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5312 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5313 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5314 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5315 | ** The proxy locking method is a "super-method" in the sense that it | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5316 | ** opens secondary file descriptors for the conch and lock files and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5317 | ** it uses proxy, dot-file, AFP, and flock() locking methods on those | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5318 | ** secondary files. For this reason, the division that implements | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5319 | ** proxy locking is located much further down in the file. But we need | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5320 | ** to go ahead and define the sqlite3_io_methods and finder function | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5321 | ** for proxy locking here. So we forward declare the I/O methods. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5322 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5323 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5324 | static int proxyClose(sqlite3_file*); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5325 | static int proxyLock(sqlite3_file*, int); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5326 | static int proxyUnlock(sqlite3_file*, int); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5327 | static int proxyCheckReservedLock(sqlite3_file*, int*); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5328 | IOMETHODS( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5329 | proxyIoFinder, /* Finder function name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5330 | proxyIoMethods, /* sqlite3_io_methods object name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5331 | 1, /* shared memory is disabled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5332 | proxyClose, /* xClose method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5333 | proxyLock, /* xLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5334 | proxyUnlock, /* xUnlock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5335 | proxyCheckReservedLock, /* xCheckReservedLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5336 | 0 /* xShmMap method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5337 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5338 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5339 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5340 | /* nfs lockd on OSX 10.3+ doesn't clear write locks when a read lock is set */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5341 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5342 | IOMETHODS( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5343 | nfsIoFinder, /* Finder function name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5344 | nfsIoMethods, /* sqlite3_io_methods object name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5345 | 1, /* shared memory is disabled */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5346 | unixClose, /* xClose method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5347 | unixLock, /* xLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5348 | nfsUnlock, /* xUnlock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5349 | unixCheckReservedLock, /* xCheckReservedLock method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5350 | 0 /* xShmMap method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5351 | ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5352 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5353 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5354 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5355 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5356 | ** This "finder" function attempts to determine the best locking strategy | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5357 | ** for the database file "filePath". It then returns the sqlite3_io_methods | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5358 | ** object that implements that strategy. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5359 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5360 | ** This is for MacOSX only. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5361 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5362 | static const sqlite3_io_methods *autolockIoFinderImpl( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5363 | const char *filePath, /* name of the database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5364 | unixFile *pNew /* open file object for the database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5365 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5366 | static const struct Mapping { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5367 | const char *zFilesystem; /* Filesystem type name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5368 | const sqlite3_io_methods *pMethods; /* Appropriate locking method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5369 | } aMap[] = { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5370 | { "hfs", &posixIoMethods }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5371 | { "ufs", &posixIoMethods }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5372 | { "afpfs", &afpIoMethods }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5373 | { "smbfs", &afpIoMethods }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5374 | { "webdav", &nolockIoMethods }, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5375 | { 0, 0 } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5376 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5377 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5378 | struct statfs fsInfo; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5379 | struct flock lockInfo; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5380 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5381 | if( !filePath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5382 | /* If filePath==NULL that means we are dealing with a transient file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5383 | ** that does not need to be locked. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5384 | return &nolockIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5385 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5386 | if( statfs(filePath, &fsInfo) != -1 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5387 | if( fsInfo.f_flags & MNT_RDONLY ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5388 | return &nolockIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5389 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5390 | for(i=0; aMap[i].zFilesystem; i++){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5391 | if( strcmp(fsInfo.f_fstypename, aMap[i].zFilesystem)==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5392 | return aMap[i].pMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5393 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5394 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5395 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5396 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5397 | /* Default case. Handles, amongst others, "nfs". | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5398 | ** Test byte-range lock using fcntl(). If the call succeeds, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5399 | ** assume that the file-system supports POSIX style locks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5400 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5401 | lockInfo.l_len = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5402 | lockInfo.l_start = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5403 | lockInfo.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5404 | lockInfo.l_type = F_RDLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5405 | if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5406 | if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5407 | return &nfsIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5408 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5409 | return &posixIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5410 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5411 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5412 | return &dotlockIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5413 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5414 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5415 | static const sqlite3_io_methods | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5416 | *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5417 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5418 | #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5419 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5420 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5421 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5422 | ** This "finder" function for VxWorks checks to see if posix advisory | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5423 | ** locking works. If it does, then that is what is used. If it does not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5424 | ** work, then fallback to named semaphore locking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5425 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5426 | static const sqlite3_io_methods *vxworksIoFinderImpl( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5427 | const char *filePath, /* name of the database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5428 | unixFile *pNew /* the open file object */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5429 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5430 | struct flock lockInfo; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5431 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5432 | if( !filePath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5433 | /* If filePath==NULL that means we are dealing with a transient file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5434 | ** that does not need to be locked. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5435 | return &nolockIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5436 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5437 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5438 | /* Test if fcntl() is supported and use POSIX style locks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5439 | ** Otherwise fall back to the named semaphore method. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5440 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5441 | lockInfo.l_len = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5442 | lockInfo.l_start = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5443 | lockInfo.l_whence = SEEK_SET; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5444 | lockInfo.l_type = F_RDLCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5445 | if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5446 | return &posixIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5447 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5448 | return &semIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5449 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5450 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5451 | static const sqlite3_io_methods | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5452 | *(*const vxworksIoFinder)(const char*,unixFile*) = vxworksIoFinderImpl; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5453 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5454 | #endif /* OS_VXWORKS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5455 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5456 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5457 | ** An abstract type for a pointer to an IO method finder function: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5458 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5459 | typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5460 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5461 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5462 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5463 | **************************** sqlite3_vfs methods **************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5464 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5465 | ** This division contains the implementation of methods on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5466 | ** sqlite3_vfs object. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5467 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5468 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5469 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5470 | ** Initialize the contents of the unixFile structure pointed to by pId. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5471 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5472 | static int fillInUnixFile( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5473 | sqlite3_vfs *pVfs, /* Pointer to vfs object */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5474 | int h, /* Open file descriptor of file being opened */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5475 | sqlite3_file *pId, /* Write to the unixFile structure here */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5476 | const char *zFilename, /* Name of the file being opened */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5477 | int ctrlFlags /* Zero or more UNIXFILE_* values */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5478 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5479 | const sqlite3_io_methods *pLockingStyle; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5480 | unixFile *pNew = (unixFile *)pId; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5481 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5482 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5483 | assert( pNew->pInode==NULL ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5484 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5485 | /* No locking occurs in temporary files */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5486 | assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5487 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5488 | OSTRACE(("OPEN %-3d %s\n", h, zFilename)); never executed: sqlite3DebugPrintf ("OPEN %-3d %s\n", h, zFilename);
| 0-77255 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5489 | pNew->h = h; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5490 | pNew->pVfs = pVfs; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5491 | pNew->zPath = zFilename; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5492 | pNew->ctrlFlags = (u8)ctrlFlags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5493 | #if SQLITE_MAX_MMAP_SIZE>0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5494 | pNew->mmapSizeMax = sqlite3GlobalConfig.szMmap; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5495 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5496 | if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
| 6-77249 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5497 | "psow", SQLITE_POWERSAFE_OVERWRITE) ){
| 6-77249 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5498 | pNew->ctrlFlags |= UNIXFILE_PSOW; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5499 | } executed 77249 times by 438 tests: end of block Executed by:
| 77249 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5500 | if( strcmp(pVfs->zName,"unix-excl")==0 ){ never executed: __result = (((const unsigned char *) (const char *) ( pVfs->zName ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( "unix-excl" ))[3] - __s2[3]); never executed: end of block never executed: end of block
| 0-77242 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5501 | pNew->ctrlFlags |= UNIXFILE_EXCL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5502 | } executed 13 times by 2 tests: end of block Executed by:
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5503 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5504 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5505 | pNew->pId = vxworksFindFileId(zFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5506 | if( pNew->pId==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5507 | ctrlFlags |= UNIXFILE_NOLOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5508 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5509 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5510 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5511 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5512 | if( ctrlFlags & UNIXFILE_NOLOCK ){
| 32252-45003 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5513 | pLockingStyle = &nolockIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5514 | }else{ executed 45003 times by 425 tests: end of block Executed by:
| 45003 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5515 | pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5516 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5517 | /* Cache zFilename in the locking context (AFP and dotlock override) for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5518 | ** proxyLock activation is possible (remote proxy is based on db name) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5519 | ** zFilename remains valid until file is closed, to support */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5520 | pNew->lockingContext = (void*)zFilename; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5521 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5522 | } executed 32252 times by 438 tests: end of block Executed by:
| 32252 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5523 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5524 | if( pLockingStyle == &posixIoMethods
| 32248-45007 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5525 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5526 | || pLockingStyle == &nfsIoMethods | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5527 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5528 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5529 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5530 | rc = findInodeInfo(pNew, &pNew->pInode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5531 | if( rc!=SQLITE_OK ){
| 16-32232 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5532 | /* If an error occurred in findInodeInfo(), close the file descriptor | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5533 | ** immediately, before releasing the mutex. findInodeInfo() may fail | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5534 | ** in two scenarios: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5535 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5536 | ** (a) A call to fstat() failed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5537 | ** (b) A malloc failed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5538 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5539 | ** Scenario (b) may only occur if the process is holding no other | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5540 | ** file descriptors open on the same file. If there were other file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5541 | ** descriptors on this file, then no malloc would be required by | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5542 | ** findInodeInfo(). If this is the case, it is quite safe to close | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5543 | ** handle h - as it is guaranteed that no posix locks will be released | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5544 | ** by doing so. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5545 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5546 | ** If scenario (a) caused the error then things are not so safe. The | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5547 | ** implicit assumption here is that if fstat() fails, things are in | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5548 | ** such bad shape that dropping a lock or two doesn't matter much. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5549 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5550 | robust_close(pNew, h, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5551 | h = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5552 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5553 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5554 | } executed 32248 times by 438 tests: end of block Executed by:
| 32248 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5555 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5556 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5557 | else if( pLockingStyle == &afpIoMethods ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5558 | /* AFP locking uses the file path so it needs to be included in | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5559 | ** the afpLockingContext. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5560 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5561 | afpLockingContext *pCtx; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5562 | pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5563 | if( pCtx==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5564 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5565 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5566 | /* NB: zFilename exists and remains valid until the file is closed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5567 | ** according to requirement F11141. So we do not need to make a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5568 | ** copy of the filename. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5569 | pCtx->dbPath = zFilename; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5570 | pCtx->reserved = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5571 | srandomdev(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5572 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5573 | rc = findInodeInfo(pNew, &pNew->pInode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5574 | if( rc!=SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5575 | sqlite3_free(pNew->lockingContext); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5576 | robust_close(pNew, h, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5577 | h = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5578 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5579 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5580 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5581 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5582 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5583 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5584 | else if( pLockingStyle == &dotlockIoMethods ){
| 2-45005 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5585 | /* Dotfile locking uses the file path so it needs to be included in | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5586 | ** the dotlockLockingContext | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5587 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5588 | char *zLockFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5589 | int nFilename; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5590 | assert( zFilename!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5591 | nFilename = (int)strlen(zFilename) + 6; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5592 | zLockFile = (char *)sqlite3_malloc64(nFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5593 | if( zLockFile==0 ){
| 0-2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5594 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5595 | }else{ never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5596 | sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5597 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5598 | pNew->lockingContext = zLockFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5599 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5600 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5601 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5602 | else if( pLockingStyle == &semIoMethods ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5603 | /* Named semaphore locking uses the file path so it needs to be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5604 | ** included in the semLockingContext | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5605 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5606 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5607 | rc = findInodeInfo(pNew, &pNew->pInode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5608 | if( (rc==SQLITE_OK) && (pNew->pInode->pSem==NULL) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5609 | char *zSemName = pNew->pInode->aSemName; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5610 | int n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5611 | sqlite3_snprintf(MAX_PATHNAME, zSemName, "/%s.sem", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5612 | pNew->pId->zCanonicalName); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5613 | for( n=1; zSemName[n]; n++ ) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5614 | if( zSemName[n]=='/' ) zSemName[n] = '_'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5615 | pNew->pInode->pSem = sem_open(zSemName, O_CREAT, 0666, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5616 | if( pNew->pInode->pSem == SEM_FAILED ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5617 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5618 | pNew->pInode->aSemName[0] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5619 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5620 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5621 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5622 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5623 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5624 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5625 | storeLastErrno(pNew, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5626 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5627 | if( rc!=SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5628 | if( h>=0 ) robust_close(pNew, h, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5629 | h = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5630 | osUnlink(zFilename); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5631 | pNew->ctrlFlags |= UNIXFILE_DELETE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5632 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5633 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5634 | if( rc!=SQLITE_OK ){
| 16-77239 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5635 | if( h>=0 ) robust_close(pNew, h, __LINE__); never executed: robust_close(pNew, h, 5635);
| 0-16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5636 | }else{ executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5637 | pNew->pMethod = pLockingStyle; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5638 | OpenCounter(+1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5639 | verifyDbFile(pNew); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5640 | } executed 77239 times by 438 tests: end of block Executed by:
| 77239 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5641 | return rc; executed 77255 times by 438 tests: return rc; Executed by:
| 77255 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5642 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5643 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5644 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5645 | ** Return the name of a directory in which to put temporary files. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5646 | ** If no suitable temporary file directory can be found, return NULL. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5647 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5648 | static const char *unixTempFileDir(void){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5649 | static const char *azDirs[] = { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5650 | 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5651 | 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5652 | "/var/tmp", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5653 | "/usr/tmp", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5654 | "/tmp", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5655 | "." | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5656 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5657 | unsigned int i = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5658 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5659 | const char *zDir = sqlite3_temp_directory; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5660 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5661 | if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR"); executed 279 times by 3 tests: azDirs[0] = getenv("SQLITE_TMPDIR"); Executed by:
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5662 | if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); executed 279 times by 3 tests: azDirs[1] = getenv("TMPDIR"); Executed by:
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5663 | while(1){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5664 | if( zDir!=0
| 279-837 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5665 | && osStat(zDir, &buf)==0
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5666 | && S_ISDIR(buf.st_mode)
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5667 | && osAccess(zDir, 03)==0
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5668 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5669 | return zDir; executed 279 times by 3 tests: return zDir; Executed by:
| 279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5670 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5671 | if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break; never executed: break;
| 0-837 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5672 | zDir = azDirs[i++]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5673 | } executed 837 times by 3 tests: end of block Executed by:
| 837 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5674 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5675 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5676 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5677 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5678 | ** Create a temporary file name in zBuf. zBuf must be allocated | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5679 | ** by the calling process and must be big enough to hold at least | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5680 | ** pVfs->mxPathname bytes. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5681 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5682 | static int unixGetTempname(int nBuf, char *zBuf){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5683 | const char *zDir; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5684 | int iLimit = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5685 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5686 | /* It's odd to simulate an io-error here, but really this is just | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5687 | ** using the io-error infrastructure to test that SQLite handles this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5688 | ** function failing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5689 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5690 | zBuf[0] = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5691 | SimulateIOError( return SQLITE_IOERR ); never executed: return 10;
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5692 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5693 | zDir = unixTempFileDir(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5694 | if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH; never executed: return (10 | (25<<8));
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5695 | do{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5696 | u64 r; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5697 | sqlite3_randomness(sizeof(r), &r); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5698 | assert( nBuf>2 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5699 | zBuf[nBuf-2] = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5700 | sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5701 | zDir, r, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5702 | if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR; never executed: return 1;
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5703 | }while( osAccess(zBuf,0)==0 ); executed 279 times by 3 tests: end of block Executed by:
| 0-279 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5704 | return SQLITE_OK; executed 278 times by 3 tests: return 0; Executed by:
| 278 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5705 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5706 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5707 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5708 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5709 | ** Routine to transform a unixFile into a proxy-locking unixFile. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5710 | ** Implementation in the proxy-lock division, but used by unixOpen() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5711 | ** if SQLITE_PREFER_PROXY_LOCKING is defined. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5712 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5713 | static int proxyTransformUnixFile(unixFile*, const char*); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5714 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5715 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5716 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5717 | ** Search for an unused file descriptor that was opened on the database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5718 | ** file (not a journal or master-journal file) identified by pathname | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5719 | ** zPath with SQLITE_OPEN_XXX flags matching those passed as the second | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5720 | ** argument to this function. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5721 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5722 | ** Such a file descriptor may exist if a database connection was closed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5723 | ** but the associated file descriptor could not be closed because some | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5724 | ** other file descriptor open on the same file is holding a file-lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5725 | ** Refer to comments in the unixClose() function and the lengthy comment | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5726 | ** describing "Posix Advisory Locking" at the start of this file for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5727 | ** further details. Also, ticket #4018. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5728 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5729 | ** If a suitable file descriptor is found, then it is returned. If no | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5730 | ** such file descriptor is located, -1 is returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5731 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5732 | static UnixUnusedFd *findReusableFd(const char *zPath, int flags){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5733 | UnixUnusedFd *pUnused = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5734 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5735 | /* Do not search for an unused file descriptor on vxworks. Not because | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5736 | ** vxworks would not benefit from the change (it might, we're not sure), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5737 | ** but because no way to test it is currently available. It is better | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5738 | ** not to risk breaking vxworks support for the sake of such an obscure | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5739 | ** feature. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5740 | #if !OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5741 | struct stat sStat; /* Results of stat() call */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5742 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5743 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5744 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5745 | /* A stat() call may fail for various reasons. If this happens, it is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5746 | ** almost certain that an open() call on the same path will also fail. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5747 | ** For this reason, if an error occurs in the stat() call here, it is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5748 | ** ignored and -1 is returned. The caller will try to open a new file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5749 | ** descriptor on the same path, fail, and return an error to SQLite. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5750 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5751 | ** Even if a subsequent open() call does succeed, the consequences of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5752 | ** not searching for a reusable file descriptor are not dire. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5753 | if( inodeList!=0 && 0==osStat(zPath, &sStat) ){
| 1566-22737 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5754 | unixInodeInfo *pInode; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5755 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5756 | pInode = inodeList; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5757 | while( pInode && (pInode->fileId.dev!=sStat.st_dev
| 0-87020 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5758 | || pInode->fileId.ino!=(u64)sStat.st_ino) ){
| 12116-74904 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5759 | pInode = pInode->pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5760 | } executed 74904 times by 13 tests: end of block Executed by:
| 74904 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5761 | if( pInode ){
| 9055-12116 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5762 | UnixUnusedFd **pp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5763 | assert( sqlite3_mutex_notheld(pInode->pLockMutex) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5764 | sqlite3_mutex_enter(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5765 | for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext)); executed 1 time by 1 test: ; Executed by:
| 1-10081 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5766 | pUnused = *pp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5767 | if( pUnused ){
| 2036-10080 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5768 | *pp = pUnused->pNext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5769 | } executed 10080 times by 1 test: end of block Executed by:
| 10080 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5770 | sqlite3_mutex_leave(pInode->pLockMutex); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5771 | } executed 12116 times by 1 test: end of block Executed by:
| 12116 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5772 | } executed 21171 times by 13 tests: end of block Executed by:
| 21171 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5773 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5774 | #endif /* if !OS_VXWORKS */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5775 | return pUnused; executed 32737 times by 438 tests: return pUnused; Executed by:
| 32737 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5776 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5777 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5778 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5779 | ** Find the mode, uid and gid of file zFile. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5780 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5781 | static int getFileMode( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5782 | const char *zFile, /* File name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5783 | mode_t *pMode, /* OUT: Permissions of zFile */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5784 | uid_t *pUid, /* OUT: uid of zFile. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5785 | gid_t *pGid /* OUT: gid of zFile. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5786 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5787 | struct stat sStat; /* Output of stat() on database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5788 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5789 | if( 0==osStat(zFile, &sStat) ){
| 0-44639 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5790 | *pMode = sStat.st_mode & 0777; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5791 | *pUid = sStat.st_uid; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5792 | *pGid = sStat.st_gid; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5793 | }else{ executed 44639 times by 425 tests: end of block Executed by:
| 44639 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5794 | rc = SQLITE_IOERR_FSTAT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5795 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5796 | return rc; executed 44639 times by 425 tests: return rc; Executed by:
| 44639 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5797 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5798 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5799 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5800 | ** This function is called by unixOpen() to determine the unix permissions | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5801 | ** to create new files with. If no error occurs, then SQLITE_OK is returned | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5802 | ** and a value suitable for passing as the third argument to open(2) is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5803 | ** written to *pMode. If an IO error occurs, an SQLite error code is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5804 | ** returned and the value of *pMode is not modified. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5805 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5806 | ** In most cases, this routine sets *pMode to 0, which will become | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5807 | ** an indication to robust_open() to create the file using | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5808 | ** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5809 | ** But if the file being opened is a WAL or regular journal file, then | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5810 | ** this function queries the file-system for the permissions on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5811 | ** corresponding database file and sets *pMode to this value. Whenever | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5812 | ** possible, WAL and journal files are created using the same permissions | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5813 | ** as the associated database file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5814 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5815 | ** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5816 | ** original filename is unavailable. But 8_3_NAMES is only used for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5817 | ** FAT filesystems and permissions do not matter there, so just use | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5818 | ** the default permissions. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5819 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5820 | static int findCreateFileMode( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5821 | const char *zPath, /* Path of file (possibly) being created */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5822 | int flags, /* Flags passed as 4th argument to xOpen() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5823 | mode_t *pMode, /* OUT: Permissions to open file with */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5824 | uid_t *pUid, /* OUT: uid to set on the file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5825 | gid_t *pGid /* OUT: gid to set on the file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5826 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5827 | int rc = SQLITE_OK; /* Return Code */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5828 | *pMode = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5829 | *pUid = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5830 | *pGid = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5831 | if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
| 23015-44640 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5832 | char zDb[MAX_PATHNAME+1]; /* Database file path */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5833 | int nDb; /* Number of valid bytes in zDb */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5834 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5835 | /* zPath is a path to a WAL or journal file. The following block derives | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5836 | ** the path to the associated database file from zPath. This block handles | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5837 | ** the following naming conventions: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5838 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5839 | ** "<path to db>-journal" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5840 | ** "<path to db>-wal" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5841 | ** "<path to db>-journalNN" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5842 | ** "<path to db>-walNN" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5843 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5844 | ** where NN is a decimal number. The NN naming schemes are | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5845 | ** used by the test_multiplex.c module. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5846 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5847 | nDb = sqlite3Strlen30(zPath) - 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5848 | while( zPath[nDb]!='-' ){
| 44639-306910 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5849 | /* In normal operation, the journal file name will always contain | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5850 | ** a '-' character. However in 8+3 filename mode, or if a corrupt | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5851 | ** rollback journal specifies a master journal with a goofy name, then | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5852 | ** the '-' might be missing. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5853 | if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK; executed 1 time by 1 test: return 0; Executed by:
| 0-306909 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5854 | nDb--; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5855 | } executed 306909 times by 425 tests: end of block Executed by:
| 306909 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5856 | memcpy(zDb, zPath, nDb); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5857 | zDb[nDb] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5858 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5859 | rc = getFileMode(zDb, pMode, pUid, pGid); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5860 | }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ executed 44639 times by 425 tests: end of block Executed by:
| 275-44639 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5861 | *pMode = 0600; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5862 | }else if( flags & SQLITE_OPEN_URI ){ executed 275 times by 3 tests: end of block Executed by:
| 165-22575 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5863 | /* If this is a main database file and the file was opened using a URI | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5864 | ** filename, check for the "modeof" parameter. If present, interpret | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5865 | ** its value as a filename and try to copy the mode, uid and gid from | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5866 | ** that file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5867 | const char *z = sqlite3_uri_parameter(zPath, "modeof"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5868 | if( z ){
| 0-165 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5869 | rc = getFileMode(z, pMode, pUid, pGid); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5870 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5871 | } executed 165 times by 4 tests: end of block Executed by:
| 165 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5872 | return rc; executed 67655 times by 438 tests: return rc; Executed by:
| 67655 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5873 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5874 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5875 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5876 | ** Open the file zPath. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5877 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5878 | ** Previously, the SQLite OS layer used three functions in place of this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5879 | ** one: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5880 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5881 | ** sqlite3OsOpenReadWrite(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5882 | ** sqlite3OsOpenReadOnly(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5883 | ** sqlite3OsOpenExclusive(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5884 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5885 | ** These calls correspond to the following combinations of flags: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5886 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5887 | ** ReadWrite() -> (READWRITE | CREATE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5888 | ** ReadOnly() -> (READONLY) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5889 | ** OpenExclusive() -> (READWRITE | CREATE | EXCLUSIVE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5890 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5891 | ** The old OpenExclusive() accepted a boolean argument - "delFlag". If | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5892 | ** true, the file was configured to be automatically deleted when the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5893 | ** file handle closed. To achieve the same effect using this new | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5894 | ** interface, add the DELETEONCLOSE flag to those specified above for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5895 | ** OpenExclusive(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5896 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5897 | static int unixOpen( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5898 | sqlite3_vfs *pVfs, /* The VFS for which this is the xOpen method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5899 | const char *zPath, /* Pathname of file to be opened */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5900 | sqlite3_file *pFile, /* The file descriptor to be filled in */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5901 | int flags, /* Input flags to control the opening */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5902 | int *pOutFlags /* Output flags returned to SQLite core */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5903 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5904 | unixFile *p = (unixFile *)pFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5905 | int fd = -1; /* File descriptor returned by open() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5906 | int openFlags = 0; /* Flags to pass to open() */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5907 | int eType = flags&0xFFFFFF00; /* Type of file to open */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5908 | int noLock; /* True to omit locking primitives */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5909 | int rc = SQLITE_OK; /* Function Return Code */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5910 | int ctrlFlags = 0; /* UNIXFILE_* flags */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5911 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5912 | int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5913 | int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5914 | int isCreate = (flags & SQLITE_OPEN_CREATE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5915 | int isReadonly = (flags & SQLITE_OPEN_READONLY); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5916 | int isReadWrite = (flags & SQLITE_OPEN_READWRITE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5917 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5918 | int isAutoProxy = (flags & SQLITE_OPEN_AUTOPROXY); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5919 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5920 | #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5921 | struct statfs fsInfo; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5922 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5923 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5924 | /* If creating a master or main-file journal, this function will open | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5925 | ** a file-descriptor on the directory too. The first time unixSync() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5926 | ** is called the directory file descriptor will be fsync()ed and close()d. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5927 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5928 | int isNewJrnl = (isCreate && (
| 12990-64756 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5929 | eType==SQLITE_OPEN_MASTER_JOURNAL
| 62-64694 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5930 | || eType==SQLITE_OPEN_MAIN_JOURNAL
| 24362-40332 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5931 | || eType==SQLITE_OPEN_WAL
| 1392-22970 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5932 | )); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5933 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5934 | /* If argument zPath is a NULL pointer, this function is required to open | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5935 | ** a temporary file. Use this buffer to store the file name in. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5936 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5937 | char zTmpname[MAX_PATHNAME+2]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5938 | const char *zName = zPath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5939 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5940 | /* Check the following statements are true: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5941 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5942 | ** (a) Exactly one of the READWRITE and READONLY flags must be set, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5943 | ** (b) if CREATE is set, then READWRITE must also be set, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5944 | ** (c) if EXCLUSIVE is set, then CREATE must also be set. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5945 | ** (d) if DELETEONCLOSE is set, then CREATE must also be set. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5946 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5947 | assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5948 | assert(isCreate==0 || isReadWrite); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5949 | assert(isExclusive==0 || isCreate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5950 | assert(isDelete==0 || isCreate); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5951 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5952 | /* The main DB, main journal, WAL file and master journal are never | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5953 | ** automatically deleted. Nor are they ever temporary files. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5954 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5955 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5956 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5957 | assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5958 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5959 | /* Assert that the upper layer has set one of the "file-type" flags. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5960 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5961 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5962 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5963 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5964 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5965 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5966 | /* Detect a pid change and reset the PRNG. There is a race condition | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5967 | ** here such that two or more threads all trying to open databases at | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5968 | ** the same instant might all reset the PRNG. But multiple resets | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5969 | ** are harmless. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5970 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5971 | if( randomnessPid!=osGetpid(0) ){
| 438-77308 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5972 | randomnessPid = osGetpid(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5973 | sqlite3_randomness(0,0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5974 | } executed 438 times by 438 tests: end of block Executed by:
| 438 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5975 | memset(p, 0, sizeof(unixFile)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5976 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5977 | if( eType==SQLITE_OPEN_MAIN_DB ){
| 32737-45009 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5978 | UnixUnusedFd *pUnused; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5979 | pUnused = findReusableFd(zName, flags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5980 | if( pUnused ){
| 10080-22657 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5981 | fd = pUnused->fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5982 | }else{ executed 10080 times by 1 test: end of block Executed by:
| 10080 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5983 | pUnused = sqlite3_malloc64(sizeof(*pUnused)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5984 | if( !pUnused ){
| 8-22649 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5985 | return SQLITE_NOMEM_BKPT; executed 8 times by 1 test: return 7; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5986 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5987 | } executed 22649 times by 438 tests: end of block Executed by:
| 22649 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5988 | p->pPreallocatedUnused = pUnused; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5989 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5990 | /* Database filenames are double-zero terminated if they are not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5991 | ** URIs with parameters. Hence, they can always be passed into | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5992 | ** sqlite3_uri_parameter(). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5993 | assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5994 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5995 | }else if( !zName ){ executed 32729 times by 438 tests: end of block Executed by:
| 278-44731 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5996 | /* If zName is NULL, the upper layer is requesting a temp file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5997 | assert(isDelete && !isNewJrnl); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5998 | rc = unixGetTempname(pVfs->mxPathname, zTmpname); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5999 | if( rc!=SQLITE_OK ){
| 0-275 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6000 | return rc; never executed: return rc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6001 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6002 | zName = zTmpname; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6003 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6004 | /* Generated temporary filenames are always double-zero terminated | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6005 | ** for use by sqlite3_uri_parameter(). */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6006 | assert( zName[strlen(zName)+1]==0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6007 | } executed 275 times by 3 tests: end of block Executed by:
| 275 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6008 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6009 | /* Determine the value of the flags parameter passed to POSIX function | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6010 | ** open(). These must be calculated even if open() is not called, as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6011 | ** they may be stored as part of the file handle and used by the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6012 | ** 'conch file' locking functions later on. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6013 | if( isReadonly ) openFlags |= O_RDONLY; executed 12562 times by 253 tests: openFlags |= 00 ; Executed by:
| 12562-65173 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6014 | if( isReadWrite ) openFlags |= O_RDWR; executed 65173 times by 438 tests: openFlags |= 02 ; Executed by:
| 12562-65173 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6015 | if( isCreate ) openFlags |= O_CREAT; executed 64745 times by 438 tests: openFlags |= 0100 ; Executed by:
| 12990-64745 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6016 | if( isExclusive ) openFlags |= (O_EXCL|O_NOFOLLOW); executed 330 times by 5 tests: openFlags |= ( 0200 | 0400000 ); Executed by:
| 330-77405 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6017 | openFlags |= (O_LARGEFILE|O_BINARY); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6018 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6019 | if( fd<0 ){
| 10080-67655 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6020 | mode_t openMode; /* Permissions to create file with */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6021 | uid_t uid; /* Userid for the file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6022 | gid_t gid; /* Groupid for the file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6023 | rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6024 | if( rc!=SQLITE_OK ){
| 0-67656 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6025 | assert( !p->pPreallocatedUnused ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6026 | assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6027 | return rc; never executed: return rc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6028 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6029 | fd = robust_open(zName, openFlags, openMode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6030 | OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags)); never executed: sqlite3DebugPrintf ("OPENX %-3d %s 0%o\n", fd, zName, openFlags);
| 0-67658 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6031 | assert( !isExclusive || (openFlags & O_CREAT)!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6032 | if( fd<0 ){
| 492-67166 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6033 | if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
| 0-489 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6034 | /* If unable to create a journal because the directory is not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6035 | ** writable, change the error code to indicate that. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6036 | rc = SQLITE_READONLY_DIRECTORY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6037 | }else if( errno!=EISDIR && isReadWrite ){ never executed: end of block
| 0-489 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6038 | /* Failed to open the file for read/write access. Try read-only. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6039 | flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6040 | openFlags &= ~(O_RDWR|O_CREAT); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6041 | flags |= SQLITE_OPEN_READONLY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6042 | openFlags |= O_RDONLY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6043 | isReadonly = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6044 | fd = robust_open(zName, openFlags, openMode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6045 | } executed 33 times by 1 test: end of block Executed by:
| 33 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6046 | } executed 492 times by 1 test: end of block Executed by:
| 492 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6047 | if( fd<0 ){
| 483-67175 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6048 | int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6049 | if( rc==SQLITE_OK ) rc = rc2; executed 483 times by 1 test: rc = rc2; Executed by:
| 0-483 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6050 | goto open_finished; executed 483 times by 1 test: goto open_finished; Executed by:
| 483 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6051 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6052 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6053 | /* If this process is running as root and if creating a new rollback | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6054 | ** journal or WAL file, set the ownership of the journal or WAL to be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6055 | ** the same as the original database. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6056 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6057 | if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
| 22541-44634 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6058 | robustFchown(fd, uid, gid); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6059 | } executed 44634 times by 425 tests: end of block Executed by:
| 44634 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6060 | } executed 67175 times by 438 tests: end of block Executed by:
| 67175 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6061 | assert( fd>=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6062 | if( pOutFlags ){
| 36606-40649 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6063 | *pOutFlags = flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6064 | } executed 36606 times by 438 tests: end of block Executed by:
| 36606 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6065 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6066 | if( p->pPreallocatedUnused ){
| 32252-45003 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6067 | p->pPreallocatedUnused->fd = fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6068 | p->pPreallocatedUnused->flags = flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6069 | } executed 32252 times by 438 tests: end of block Executed by:
| 32252 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6070 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6071 | if( isDelete ){
| 278-76977 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6072 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6073 | zPath = zName; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6074 | #elif defined(SQLITE_UNLINK_AFTER_CLOSE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6075 | zPath = sqlite3_mprintf("%s", zName); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6076 | if( zPath==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6077 | robust_close(p, fd, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6078 | return SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6079 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6080 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6081 | osUnlink(zName); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6082 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6083 | } executed 278 times by 3 tests: end of block Executed by:
| 278 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6084 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6085 | else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6086 | p->openFlags = openFlags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6087 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6088 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6089 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6090 | #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6091 | if( fstatfs(fd, &fsInfo) == -1 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6092 | storeLastErrno(p, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6093 | robust_close(p, fd, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6094 | return SQLITE_IOERR_ACCESS; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6095 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6096 | if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6097 | ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6098 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6099 | if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6100 | ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6101 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6102 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6103 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6104 | /* Set up appropriate ctrlFlags */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6105 | if( isDelete ) ctrlFlags |= UNIXFILE_DELETE; executed 278 times by 3 tests: ctrlFlags |= 0x20; Executed by:
| 278-76977 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6106 | if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY; executed 12115 times by 253 tests: ctrlFlags |= 0x02; Executed by:
| 12115-65140 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6107 | noLock = eType!=SQLITE_OPEN_MAIN_DB; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6108 | if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK; executed 45003 times by 425 tests: ctrlFlags |= 0x80; Executed by:
| 32252-45003 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6109 | if( isNewJrnl ) ctrlFlags |= UNIXFILE_DIRSYNC; executed 41784 times by 425 tests: ctrlFlags |= 0x08; Executed by:
| 35471-41784 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6110 | if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI; executed 152 times by 4 tests: ctrlFlags |= 0x40; Executed by:
| 152-77103 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6111 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6112 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6113 | #if SQLITE_PREFER_PROXY_LOCKING | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6114 | isAutoProxy = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6115 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6116 | if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6117 | char *envforce = getenv("SQLITE_FORCE_PROXY_LOCKING"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6118 | int useProxy = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6119 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6120 | /* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6121 | ** never use proxy, NULL means use proxy for non-local files only. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6122 | if( envforce!=NULL ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6123 | useProxy = atoi(envforce)>0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6124 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6125 | useProxy = !(fsInfo.f_flags&MNT_LOCAL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6126 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6127 | if( useProxy ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6128 | rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6129 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6130 | rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6131 | if( rc!=SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6132 | /* Use unixClose to clean up the resources added in fillInUnixFile | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6133 | ** and clear all the structure's references. Specifically, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6134 | ** pFile->pMethods will be NULL so sqlite3OsClose will be a no-op | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6135 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6136 | unixClose(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6137 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6138 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6139 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6140 | goto open_finished; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6141 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6142 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6143 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6144 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6145 | assert( zPath==0 || zPath[0]=='/' | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6146 | || eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6147 | ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6148 | rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6149 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6150 | open_finished: code before this statement executed 77255 times by 438 tests: open_finished: Executed by:
| 77255 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6151 | if( rc!=SQLITE_OK ){
| 499-77239 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6152 | sqlite3_free(p->pPreallocatedUnused); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6153 | } executed 499 times by 1 test: end of block Executed by:
| 499 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6154 | return rc; executed 77738 times by 438 tests: return rc; Executed by:
| 77738 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6155 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6156 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6157 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6158 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6159 | ** Delete the file at zPath. If the dirSync argument is true, fsync() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6160 | ** the directory after deleting the file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6161 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6162 | static int unixDelete( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6163 | sqlite3_vfs *NotUsed, /* VFS containing this as the xDelete method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6164 | const char *zPath, /* Name of file to be deleted */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6165 | int dirSync /* If true, fsync() directory after deleting file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6166 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6167 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6168 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6169 | SimulateIOError(return SQLITE_IOERR_DELETE); executed 8 times by 1 test: return (10 | (10<<8)); Executed by:
| 2-40722 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6170 | if( osUnlink(zPath)==(-1) ){
| 6-40716 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6171 | if( errno==ENOENT
| 1-5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6172 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6173 | || osAccess(zPath,0)!=0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6174 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6175 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6176 | rc = SQLITE_IOERR_DELETE_NOENT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6177 | }else{ executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6178 | rc = unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6179 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6180 | return rc; executed 6 times by 1 test: return rc; Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6181 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6182 | #ifndef SQLITE_DISABLE_DIRSYNC | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6183 | if( (dirSync & 1)!=0 ){
| 60-40656 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6184 | int fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6185 | rc = osOpenDirectory(zPath, &fd); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6186 | if( rc==SQLITE_OK ){
| 0-60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6187 | if( full_fsync(fd,0,0) ){
| 0-60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6188 | rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6189 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6190 | robust_close(0, fd, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6191 | }else{ executed 60 times by 1 test: end of block Executed by:
| 60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6192 | assert( rc==SQLITE_CANTOPEN ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6193 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6194 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6195 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6196 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6197 | return rc; executed 40716 times by 43 tests: return rc; Executed by:
| 40716 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6198 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6199 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6200 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6201 | ** Test the existence of or access permissions of file zPath. The | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6202 | ** test performed depends on the value of flags: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6203 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6204 | ** SQLITE_ACCESS_EXISTS: Return 1 if the file exists | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6205 | ** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6206 | ** SQLITE_ACCESS_READONLY: Return 1 if the file is readable. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6207 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6208 | ** Otherwise return 0. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6209 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6210 | static int unixAccess( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6211 | sqlite3_vfs *NotUsed, /* The VFS containing this xAccess method */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6212 | const char *zPath, /* Path of the file to examine */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6213 | int flags, /* What do we want to learn about the zPath file? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6214 | int *pResOut /* Write result boolean here */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6215 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6216 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6217 | SimulateIOError( return SQLITE_IOERR_ACCESS; ); executed 62 times by 1 test: return (10 | (13<<8)); Executed by:
| 0-268661 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6218 | assert( pResOut!=0 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6219 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6220 | /* The spec says there are three possible values for flags. But only | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6221 | ** two of them are actually used */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6222 | assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6223 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6224 | if( flags==SQLITE_ACCESS_EXISTS ){
| 3-268658 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6225 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6226 | *pResOut = (0==osStat(zPath, &buf) && buf.st_size>0);
| 218-264540 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6227 | }else{ executed 268658 times by 435 tests: end of block Executed by:
| 268658 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6228 | *pResOut = osAccess(zPath, W_OK|R_OK)==0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6229 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6230 | return SQLITE_OK; executed 268661 times by 435 tests: return 0; Executed by:
| 268661 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6231 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6232 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6233 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6234 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6235 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6236 | static int mkFullPathname( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6237 | const char *zPath, /* Input path */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6238 | char *zOut, /* Output buffer */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6239 | int nOut /* Allocated size of buffer zOut */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6240 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6241 | int nPath = sqlite3Strlen30(zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6242 | int iOff = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6243 | if( zPath[0]!='/' ){
| 255-33048 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6244 | if( osGetcwd(zOut, nOut-2)==0 ){
| 0-33048 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6245 | return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath); never executed: return unixLogErrorAtLine(sqlite3CantopenError(6245),"getcwd",zPath,6245); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6246 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6247 | iOff = sqlite3Strlen30(zOut); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6248 | zOut[iOff++] = '/'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6249 | } executed 33048 times by 438 tests: end of block Executed by:
| 33048 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6250 | if( (iOff+nPath+1)>nOut ){
| 6-33297 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6251 | /* SQLite assumes that xFullPathname() nul-terminates the output buffer | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6252 | ** even if it returns an error. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6253 | zOut[iOff] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6254 | return SQLITE_CANTOPEN_BKPT; executed 6 times by 1 test: return sqlite3CantopenError(6254); Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6255 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6256 | sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6257 | return SQLITE_OK; executed 33297 times by 438 tests: return 0; Executed by:
| 33297 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6258 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6259 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6260 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6261 | ** Turn a relative pathname into a full pathname. The relative path | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6262 | ** is stored as a nul-terminated string in the buffer pointed to by | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6263 | ** zPath. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6264 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6265 | ** zOut points to a buffer of at least sqlite3_vfs.mxPathname bytes | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6266 | ** (in this case, MAX_PATHNAME bytes). The full-path is written to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6267 | ** this buffer before returning. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6268 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6269 | static int unixFullPathname( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6270 | sqlite3_vfs *pVfs, /* Pointer to vfs object */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6271 | const char *zPath, /* Possibly relative input path */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6272 | int nOut, /* Size of output buffer in bytes */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6273 | char *zOut /* Output buffer */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6274 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6275 | #if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6276 | return mkFullPathname(zPath, zOut, nOut); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6277 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6278 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6279 | int nByte; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6280 | int nLink = 1; /* Number of symbolic links followed so far */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6281 | const char *zIn = zPath; /* Input path for each iteration of loop */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6282 | char *zDel = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6283 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6284 | assert( pVfs->mxPathname==MAX_PATHNAME ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6285 | UNUSED_PARAMETER(pVfs); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6286 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6287 | /* It's odd to simulate an io-error here, but really this is just | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6288 | ** using the io-error infrastructure to test that SQLite handles this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6289 | ** function failing. This function could fail if, for example, the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6290 | ** current working directory has been unlinked. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6291 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6292 | SimulateIOError( return SQLITE_ERROR ); executed 8 times by 1 test: return 1; Executed by:
| 1-33205 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6293 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6294 | do { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6295 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6296 | /* Call stat() on path zIn. Set bLink to true if the path is a symbolic | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6297 | ** link, or false otherwise. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6298 | int bLink = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6299 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6300 | if( osLstat(zIn, &buf)!=0 ){
| 5220-28094 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6301 | if( errno!=ENOENT ){
| 3-5217 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6302 | rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6303 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6304 | }else{ executed 5220 times by 3 tests: end of block Executed by:
| 5220 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6305 | bLink = S_ISLNK(buf.st_mode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6306 | } executed 28094 times by 438 tests: end of block Executed by:
| 28094 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6307 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6308 | if( bLink ){
| 110-33204 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6309 | if( zDel==0 ){
| 8-102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6310 | zDel = sqlite3_malloc(nOut); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6311 | if( zDel==0 ) rc = SQLITE_NOMEM_BKPT; never executed: rc = 7;
| 0-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6312 | }else if( ++nLink>SQLITE_MAX_SYMLINKS ){ executed 8 times by 1 test: end of block Executed by:
| 1-101 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6313 | rc = SQLITE_CANTOPEN_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6314 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6315 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6316 | if( rc==SQLITE_OK ){
| 1-109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6317 | nByte = osReadlink(zIn, zDel, nOut-1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6318 | if( nByte<0 ){
| 0-109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6319 | rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6320 | }else{ never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6321 | if( zDel[0]!='/' ){
| 1-108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6322 | int n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6323 | for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--); executed 811 times by 1 test: ; Executed by:
| 5-914 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6324 | if( nByte+n+1>nOut ){
| 0-108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6325 | rc = SQLITE_CANTOPEN_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6326 | }else{ never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6327 | memmove(&zDel[n], zDel, nByte+1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6328 | memcpy(zDel, zIn, n); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6329 | nByte += n; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6330 | } executed 108 times by 1 test: end of block Executed by:
| 108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6331 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6332 | zDel[nByte] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6333 | } executed 109 times by 1 test: end of block Executed by:
| 109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6334 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6335 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6336 | zIn = zDel; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6337 | } executed 110 times by 1 test: end of block Executed by:
| 110 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6338 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6339 | assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6340 | if( rc==SQLITE_OK && zIn!=zOut ){
| 4-33310 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6341 | rc = mkFullPathname(zIn, zOut, nOut); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6342 | } executed 33303 times by 438 tests: end of block Executed by:
| 33303 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6343 | if( bLink==0 ) break; executed 33204 times by 438 tests: break; Executed by:
| 110-33204 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6344 | zIn = zOut; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6345 | }while( rc==SQLITE_OK ); executed 110 times by 1 test: end of block Executed by:
| 1-110 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6346 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6347 | sqlite3_free(zDel); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6348 | return rc; executed 33205 times by 438 tests: return rc; Executed by:
| 33205 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6349 | #endif /* HAVE_READLINK && HAVE_LSTAT */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6350 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6351 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6352 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6353 | #ifndef SQLITE_OMIT_LOAD_EXTENSION | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6354 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6355 | ** Interfaces for opening a shared library, finding entry points | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6356 | ** within the shared library, and closing the shared library. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6357 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6358 | #include <dlfcn.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6359 | static void *unixDlOpen(sqlite3_vfs *NotUsed, const char *zFilename){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6360 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6361 | return dlopen(zFilename, RTLD_NOW | RTLD_GLOBAL); never executed: return dlopen(zFilename, 0x00002 | 0x00100 ); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6362 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6363 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6364 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6365 | ** SQLite calls this function immediately after a call to unixDlSym() or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6366 | ** unixDlOpen() fails (returns a null pointer). If a more detailed error | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6367 | ** message is available, it is written to zBufOut. If no error message | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6368 | ** is available, zBufOut is left unmodified and SQLite uses a default | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6369 | ** error message. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6370 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6371 | static void unixDlError(sqlite3_vfs *NotUsed, int nBuf, char *zBufOut){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6372 | const char *zErr; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6373 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6374 | unixEnterMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6375 | zErr = dlerror(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6376 | if( zErr ){
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6377 | sqlite3_snprintf(nBuf, zBufOut, "%s", zErr); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6378 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6379 | unixLeaveMutex(); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6380 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6381 | static void (*unixDlSym(sqlite3_vfs *NotUsed, void *p, const char*zSym))(void){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6382 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6383 | ** GCC with -pedantic-errors says that C90 does not allow a void* to be | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6384 | ** cast into a pointer to a function. And yet the library dlsym() routine | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6385 | ** returns a void* which is really a pointer to a function. So how do we | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6386 | ** use dlsym() with -pedantic-errors? | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6387 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6388 | ** Variable x below is defined to be a pointer to a function taking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6389 | ** parameters void* and const char* and returning a pointer to a function. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6390 | ** We initialize x by assigning it a pointer to the dlsym() function. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6391 | ** (That assignment requires a cast.) Then we call the function that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6392 | ** x points to. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6393 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6394 | ** This work-around is unlikely to work correctly on any system where | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6395 | ** you really cannot cast a function pointer into void*. But then, on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6396 | ** other hand, dlsym() will not work on such a system either, so we have | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6397 | ** not really lost anything. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6398 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6399 | void (*(*x)(void*,const char*))(void); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6400 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6401 | x = (void(*(*)(void*,const char*))(void))dlsym; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6402 | return (*x)(p, zSym); never executed: return (*x)(p, zSym); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6403 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6404 | static void unixDlClose(sqlite3_vfs *NotUsed, void *pHandle){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6405 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6406 | dlclose(pHandle); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6407 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6408 | #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6409 | #define unixDlOpen 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6410 | #define unixDlError 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6411 | #define unixDlSym 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6412 | #define unixDlClose 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6413 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6414 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6415 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6416 | ** Write nBuf bytes of random data to the supplied buffer zBuf. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6417 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6418 | static int unixRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6419 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6420 | assert((size_t)nBuf>=(sizeof(time_t)+sizeof(int))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6421 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6422 | /* We have to initialize zBuf to prevent valgrind from reporting | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6423 | ** errors. The reports issued by valgrind are incorrect - we would | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6424 | ** prefer that the randomness be increased by making use of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6425 | ** uninitialized space in zBuf - but valgrind errors tend to worry | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6426 | ** some users. Rather than argue, it seems easier just to initialize | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6427 | ** the whole array and silence valgrind, even if that means less randomness | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6428 | ** in the random seed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6429 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6430 | ** When testing, initializing zBuf[] to zero is all we do. That means | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6431 | ** that we always use the same random number sequence. This makes the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6432 | ** tests repeatable. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6433 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6434 | memset(zBuf, 0, nBuf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6435 | randomnessPid = osGetpid(0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6436 | #if !defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6437 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6438 | int fd, got; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6439 | fd = robust_open("/dev/urandom", O_RDONLY, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6440 | if( fd<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6441 | time_t t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6442 | time(&t); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6443 | memcpy(zBuf, &t, sizeof(t)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6444 | memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6445 | assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6446 | nBuf = sizeof(t) + sizeof(randomnessPid); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6447 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6448 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6449 | robust_close(0, fd, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6450 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6451 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6452 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6453 | return nBuf; executed 1074 times by 396 tests: return nBuf; Executed by:
| 1074 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6454 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6455 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6456 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6457 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6458 | ** Sleep for a little while. Return the amount of time slept. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6459 | ** The argument is the number of microseconds we want to sleep. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6460 | ** The return value is the number of microseconds of sleep actually | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6461 | ** requested from the underlying operating system, a number which | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6462 | ** might be greater than or equal to the argument, but not less | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6463 | ** than the argument. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6464 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6465 | static int unixSleep(sqlite3_vfs *NotUsed, int microseconds){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6466 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6467 | struct timespec sp; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6468 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6469 | sp.tv_sec = microseconds / 1000000; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6470 | sp.tv_nsec = (microseconds % 1000000) * 1000; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6471 | nanosleep(&sp, NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6472 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6473 | return microseconds; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6474 | #elif defined(HAVE_USLEEP) && HAVE_USLEEP | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6475 | usleep(microseconds); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6476 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6477 | return microseconds; executed 34 times by 2 tests: return microseconds; Executed by:
| 34 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6478 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6479 | int seconds = (microseconds+999999)/1000000; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6480 | sleep(seconds); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6481 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6482 | return seconds*1000000; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6483 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6484 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6485 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6486 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6487 | ** The following variable, if set to a non-zero value, is interpreted as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6488 | ** the number of seconds since 1970 and is used to set the result of | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6489 | ** sqlite3OsCurrentTime() during testing. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6490 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6491 | #ifdef SQLITE_TEST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6492 | int sqlite3_current_time = 0; /* Fake system time in seconds since 1970. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6493 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6494 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6495 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6496 | ** Find the current time (in Universal Coordinated Time). Write into *piNow | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6497 | ** the current time and date as a Julian Day number times 86_400_000. In | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6498 | ** other words, write into *piNow the number of milliseconds since the Julian | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6499 | ** epoch of noon in Greenwich on November 24, 4714 B.C according to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6500 | ** proleptic Gregorian calendar. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6501 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6502 | ** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6503 | ** cannot be found. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6504 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6505 | static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6506 | static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6507 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6508 | #if defined(NO_GETTOD) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6509 | time_t t; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6510 | time(&t); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6511 | *piNow = ((sqlite3_int64)t)*1000 + unixEpoch; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6512 | #elif OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6513 | struct timespec sNow; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6514 | clock_gettime(CLOCK_REALTIME, &sNow); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6515 | *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6516 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6517 | struct timeval sNow; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6518 | (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6519 | *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6520 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6521 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6522 | #ifdef SQLITE_TEST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6523 | if( sqlite3_current_time ){
| 41-93 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6524 | *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6525 | } executed 41 times by 1 test: end of block Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6526 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6527 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6528 | return rc; executed 134 times by 1 test: return rc; Executed by:
| 134 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6529 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6530 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6531 | #ifndef SQLITE_OMIT_DEPRECATED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6532 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6533 | ** Find the current time (in Universal Coordinated Time). Write the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6534 | ** current time and date as a Julian Day number into *prNow and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6535 | ** return 0. Return 1 if the time and date cannot be found. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6536 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6537 | static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6538 | sqlite3_int64 i = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6539 | int rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6540 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6541 | rc = unixCurrentTimeInt64(0, &i); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6542 | *prNow = i/86400000.0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6543 | return rc; never executed: return rc; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6544 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6545 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6546 | # define unixCurrentTime 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6547 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6548 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6549 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6550 | ** The xGetLastError() method is designed to return a better | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6551 | ** low-level error message when operating-system problems come up | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6552 | ** during SQLite operation. Only the integer return code is currently | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6553 | ** used. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6554 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6555 | static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6556 | UNUSED_PARAMETER(NotUsed); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6557 | UNUSED_PARAMETER(NotUsed2); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6558 | UNUSED_PARAMETER(NotUsed3); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6559 | return errno; executed 664 times by 1 test: return (*__errno_location ()) ; Executed by:
| 664 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6560 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6561 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6562 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6563 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6564 | ************************ End of sqlite3_vfs methods *************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6565 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6566 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6567 | /****************************************************************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6568 | ************************** Begin Proxy Locking ******************************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6569 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6570 | ** Proxy locking is a "uber-locking-method" in this sense: It uses the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6571 | ** other locking methods on secondary lock files. Proxy locking is a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6572 | ** meta-layer over top of the primitive locking implemented above. For | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6573 | ** this reason, the division that implements of proxy locking is deferred | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6574 | ** until late in the file (here) after all of the other I/O methods have | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6575 | ** been defined - so that the primitive locking methods are available | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6576 | ** as services to help with the implementation of proxy locking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6577 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6578 | **** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6579 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6580 | ** The default locking schemes in SQLite use byte-range locks on the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6581 | ** database file to coordinate safe, concurrent access by multiple readers | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6582 | ** and writers [http://sqlite.org/lockingv3.html]. The five file locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6583 | ** states (UNLOCKED, PENDING, SHARED, RESERVED, EXCLUSIVE) are implemented | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6584 | ** as POSIX read & write locks over fixed set of locations (via fsctl), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6585 | ** on AFP and SMB only exclusive byte-range locks are available via fsctl | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6586 | ** with _IOWR('z', 23, struct ByteRangeLockPB2) to track the same 5 states. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6587 | ** To simulate a F_RDLCK on the shared range, on AFP a randomly selected | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6588 | ** address in the shared range is taken for a SHARED lock, the entire | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6589 | ** shared range is taken for an EXCLUSIVE lock): | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6590 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6591 | ** PENDING_BYTE 0x40000000 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6592 | ** RESERVED_BYTE 0x40000001 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6593 | ** SHARED_RANGE 0x40000002 -> 0x40000200 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6594 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6595 | ** This works well on the local file system, but shows a nearly 100x | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6596 | ** slowdown in read performance on AFP because the AFP client disables | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6597 | ** the read cache when byte-range locks are present. Enabling the read | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6598 | ** cache exposes a cache coherency problem that is present on all OS X | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6599 | ** supported network file systems. NFS and AFP both observe the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6600 | ** close-to-open semantics for ensuring cache coherency | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6601 | ** [http://nfs.sourceforge.net/#faq_a8], which does not effectively | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6602 | ** address the requirements for concurrent database access by multiple | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6603 | ** readers and writers | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6604 | ** [http://www.nabble.com/SQLite-on-NFS-cache-coherency-td15655701.html]. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6605 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6606 | ** To address the performance and cache coherency issues, proxy file locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6607 | ** changes the way database access is controlled by limiting access to a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6608 | ** single host at a time and moving file locks off of the database file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6609 | ** and onto a proxy file on the local file system. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6610 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6611 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6612 | ** Using proxy locks | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6613 | ** ----------------- | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6614 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6615 | ** C APIs | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6616 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6617 | ** sqlite3_file_control(db, dbname, SQLITE_FCNTL_SET_LOCKPROXYFILE, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6618 | ** <proxy_path> | ":auto:"); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6619 | ** sqlite3_file_control(db, dbname, SQLITE_FCNTL_GET_LOCKPROXYFILE, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6620 | ** &<proxy_path>); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6621 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6622 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6623 | ** SQL pragmas | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6624 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6625 | ** PRAGMA [database.]lock_proxy_file=<proxy_path> | :auto: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6626 | ** PRAGMA [database.]lock_proxy_file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6627 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6628 | ** Specifying ":auto:" means that if there is a conch file with a matching | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6629 | ** host ID in it, the proxy path in the conch file will be used, otherwise | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6630 | ** a proxy path based on the user's temp dir | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6631 | ** (via confstr(_CS_DARWIN_USER_TEMP_DIR,...)) will be used and the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6632 | ** actual proxy file name is generated from the name and path of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6633 | ** database file. For example: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6634 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6635 | ** For database path "/Users/me/foo.db" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6636 | ** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:") | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6637 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6638 | ** Once a lock proxy is configured for a database connection, it can not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6639 | ** be removed, however it may be switched to a different proxy path via | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6640 | ** the above APIs (assuming the conch file is not being held by another | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6641 | ** connection or process). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6642 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6643 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6644 | ** How proxy locking works | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6645 | ** ----------------------- | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6646 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6647 | ** Proxy file locking relies primarily on two new supporting files: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6648 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6649 | ** * conch file to limit access to the database file to a single host | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6650 | ** at a time | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6651 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6652 | ** * proxy file to act as a proxy for the advisory locks normally | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6653 | ** taken on the database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6654 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6655 | ** The conch file - to use a proxy file, sqlite must first "hold the conch" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6656 | ** by taking an sqlite-style shared lock on the conch file, reading the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6657 | ** contents and comparing the host's unique host ID (see below) and lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6658 | ** proxy path against the values stored in the conch. The conch file is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6659 | ** stored in the same directory as the database file and the file name | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6660 | ** is patterned after the database file name as ".<databasename>-conch". | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6661 | ** If the conch file does not exist, or its contents do not match the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6662 | ** host ID and/or proxy path, then the lock is escalated to an exclusive | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6663 | ** lock and the conch file contents is updated with the host ID and proxy | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6664 | ** path and the lock is downgraded to a shared lock again. If the conch | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6665 | ** is held by another process (with a shared lock), the exclusive lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6666 | ** will fail and SQLITE_BUSY is returned. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6667 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6668 | ** The proxy file - a single-byte file used for all advisory file locks | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6669 | ** normally taken on the database file. This allows for safe sharing | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6670 | ** of the database file for multiple readers and writers on the same | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6671 | ** host (the conch ensures that they all use the same local lock file). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6672 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6673 | ** Requesting the lock proxy does not immediately take the conch, it is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6674 | ** only taken when the first request to lock database file is made. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6675 | ** This matches the semantics of the traditional locking behavior, where | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6676 | ** opening a connection to a database file does not take a lock on it. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6677 | ** The shared lock and an open file descriptor are maintained until | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6678 | ** the connection to the database is closed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6679 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6680 | ** The proxy file and the lock file are never deleted so they only need | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6681 | ** to be created the first time they are used. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6682 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6683 | ** Configuration options | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6684 | ** --------------------- | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6685 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6686 | ** SQLITE_PREFER_PROXY_LOCKING | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6687 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6688 | ** Database files accessed on non-local file systems are | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6689 | ** automatically configured for proxy locking, lock files are | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6690 | ** named automatically using the same logic as | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6691 | ** PRAGMA lock_proxy_file=":auto:" | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6692 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6693 | ** SQLITE_PROXY_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6694 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6695 | ** Enables the logging of error messages during host id file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6696 | ** retrieval and creation | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6697 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6698 | ** LOCKPROXYDIR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6699 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6700 | ** Overrides the default directory used for lock proxy files that | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6701 | ** are named automatically via the ":auto:" setting | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6702 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6703 | ** SQLITE_DEFAULT_PROXYDIR_PERMISSIONS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6704 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6705 | ** Permissions to use when creating a directory for storing the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6706 | ** lock proxy files, only used when LOCKPROXYDIR is not set. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6707 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6708 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6709 | ** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6710 | ** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6711 | ** force proxy locking to be used for every database file opened, and 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6712 | ** will force automatic proxy locking to be disabled for all database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6713 | ** files (explicitly calling the SQLITE_FCNTL_SET_LOCKPROXYFILE pragma or | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6714 | ** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6715 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6716 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6717 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6718 | ** Proxy locking is only available on MacOSX | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6719 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6720 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6721 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6722 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6723 | ** The proxyLockingContext has the path and file structures for the remote | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6724 | ** and local proxy files in it | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6725 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6726 | typedef struct proxyLockingContext proxyLockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6727 | struct proxyLockingContext { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6728 | unixFile *conchFile; /* Open conch file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6729 | char *conchFilePath; /* Name of the conch file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6730 | unixFile *lockProxy; /* Open proxy lock file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6731 | char *lockProxyPath; /* Name of the proxy lock file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6732 | char *dbPath; /* Name of the open file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6733 | int conchHeld; /* 1 if the conch is held, -1 if lockless */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6734 | int nFails; /* Number of conch taking failures */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6735 | void *oldLockingContext; /* Original lockingcontext to restore on close */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6736 | sqlite3_io_methods const *pOldMethod; /* Original I/O methods for close */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6737 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6738 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6739 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6740 | ** The proxy lock file path for the database at dbPath is written into lPath, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6741 | ** which must point to valid, writable memory large enough for a maxLen length | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6742 | ** file path. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6743 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6744 | static int proxyGetLockPath(const char *dbPath, char *lPath, size_t maxLen){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6745 | int len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6746 | int dbLen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6747 | int i; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6748 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6749 | #ifdef LOCKPROXYDIR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6750 | len = strlcpy(lPath, LOCKPROXYDIR, maxLen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6751 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6752 | # ifdef _CS_DARWIN_USER_TEMP_DIR | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6753 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6754 | if( !confstr(_CS_DARWIN_USER_TEMP_DIR, lPath, maxLen) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6755 | OSTRACE(("GETLOCKPATH failed %s errno=%d pid=%d\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6756 | lPath, errno, osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6757 | return SQLITE_IOERR_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6758 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6759 | len = strlcat(lPath, "sqliteplocks", maxLen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6760 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6761 | # else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6762 | len = strlcpy(lPath, "/tmp/", maxLen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6763 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6764 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6765 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6766 | if( lPath[len-1]!='/' ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6767 | len = strlcat(lPath, "/", maxLen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6768 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6769 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6770 | /* transform the db path to a unique cache name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6771 | dbLen = (int)strlen(dbPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6772 | for( i=0; i<dbLen && (i+len+7)<(int)maxLen; i++){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6773 | char c = dbPath[i]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6774 | lPath[i+len] = (c=='/')?'_':c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6775 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6776 | lPath[i+len]='\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6777 | strlcat(lPath, ":auto:", maxLen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6778 | OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6779 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6780 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6781 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6782 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6783 | ** Creates the lock file and any missing directories in lockPath | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6784 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6785 | static int proxyCreateLockPath(const char *lockPath){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6786 | int i, len; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6787 | char buf[MAXPATHLEN]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6788 | int start = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6789 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6790 | assert(lockPath!=NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6791 | /* try to create all the intermediate directories */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6792 | len = (int)strlen(lockPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6793 | buf[0] = lockPath[0]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6794 | for( i=1; i<len; i++ ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6795 | if( lockPath[i] == '/' && (i - start > 0) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6796 | /* only mkdir if leaf dir != "." or "/" or ".." */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6797 | if( i-start>2 || (i-start==1 && buf[start] != '.' && buf[start] != '/') | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6798 | || (i-start==2 && buf[start] != '.' && buf[start+1] != '.') ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6799 | buf[i]='\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6800 | if( osMkdir(buf, SQLITE_DEFAULT_PROXYDIR_PERMISSIONS) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6801 | int err=errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6802 | if( err!=EEXIST ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6803 | OSTRACE(("CREATELOCKPATH FAILED creating %s, " | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6804 | "'%s' proxy lock path=%s pid=%d\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6805 | buf, strerror(err), lockPath, osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6806 | return err; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6807 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6808 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6809 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6810 | start=i+1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6811 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6812 | buf[i] = lockPath[i]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6813 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6814 | OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n",lockPath,osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6815 | return 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6816 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6817 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6818 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6819 | ** Create a new VFS file descriptor (stored in memory obtained from | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6820 | ** sqlite3_malloc) and open the file named "path" in the file descriptor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6821 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6822 | ** The caller is responsible not only for closing the file descriptor | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6823 | ** but also for freeing the memory associated with the file descriptor. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6824 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6825 | static int proxyCreateUnixFile( | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6826 | const char *path, /* path for the new unixFile */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6827 | unixFile **ppFile, /* unixFile created and returned by ref */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6828 | int islockfile /* if non zero missing dirs will be created */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6829 | ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6830 | int fd = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6831 | unixFile *pNew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6832 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6833 | int openFlags = O_RDWR | O_CREAT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6834 | sqlite3_vfs dummyVfs; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6835 | int terrno = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6836 | UnixUnusedFd *pUnused = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6837 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6838 | /* 1. first try to open/create the file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6839 | ** 2. if that fails, and this is a lock file (not-conch), try creating | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6840 | ** the parent directories and then try again. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6841 | ** 3. if that fails, try to open the file read-only | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6842 | ** otherwise return BUSY (if lock file) or CANTOPEN for the conch file | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6843 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6844 | pUnused = findReusableFd(path, openFlags); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6845 | if( pUnused ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6846 | fd = pUnused->fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6847 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6848 | pUnused = sqlite3_malloc64(sizeof(*pUnused)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6849 | if( !pUnused ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6850 | return SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6851 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6852 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6853 | if( fd<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6854 | fd = robust_open(path, openFlags, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6855 | terrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6856 | if( fd<0 && errno==ENOENT && islockfile ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6857 | if( proxyCreateLockPath(path) == SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6858 | fd = robust_open(path, openFlags, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6859 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6860 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6861 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6862 | if( fd<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6863 | openFlags = O_RDONLY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6864 | fd = robust_open(path, openFlags, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6865 | terrno = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6866 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6867 | if( fd<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6868 | if( islockfile ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6869 | return SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6870 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6871 | switch (terrno) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6872 | case EACCES: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6873 | return SQLITE_PERM; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6874 | case EIO: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6875 | return SQLITE_IOERR_LOCK; /* even though it is the conch */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6876 | default: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6877 | return SQLITE_CANTOPEN_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6878 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6879 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6880 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6881 | pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6882 | if( pNew==NULL ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6883 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6884 | goto end_create_proxy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6885 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6886 | memset(pNew, 0, sizeof(unixFile)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6887 | pNew->openFlags = openFlags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6888 | memset(&dummyVfs, 0, sizeof(dummyVfs)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6889 | dummyVfs.pAppData = (void*)&autolockIoFinder; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6890 | dummyVfs.zName = "dummy"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6891 | pUnused->fd = fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6892 | pUnused->flags = openFlags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6893 | pNew->pPreallocatedUnused = pUnused; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6894 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6895 | rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6896 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6897 | *ppFile = pNew; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6898 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6899 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6900 | end_create_proxy: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6901 | robust_close(pNew, fd, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6902 | sqlite3_free(pNew); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6903 | sqlite3_free(pUnused); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6904 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6905 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6906 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6907 | #ifdef SQLITE_TEST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6908 | /* simulate multiple hosts by creating unique hostid file paths */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6909 | int sqlite3_hostid_num = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6910 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6911 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6912 | #define PROXY_HOSTIDLEN 16 /* conch file host id length */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6913 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6914 | #ifdef HAVE_GETHOSTUUID | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6915 | /* Not always defined in the headers as it ought to be */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6916 | extern int gethostuuid(uuid_t id, const struct timespec *wait); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6917 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6918 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6919 | /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6920 | ** bytes of writable memory. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6921 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6922 | static int proxyGetHostID(unsigned char *pHostID, int *pError){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6923 | assert(PROXY_HOSTIDLEN == sizeof(uuid_t)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6924 | memset(pHostID, 0, PROXY_HOSTIDLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6925 | #ifdef HAVE_GETHOSTUUID | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6926 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6927 | struct timespec timeout = {1, 0}; /* 1 sec timeout */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6928 | if( gethostuuid(pHostID, &timeout) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6929 | int err = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6930 | if( pError ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6931 | *pError = err; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6932 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6933 | return SQLITE_IOERR; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6934 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6935 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6936 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6937 | UNUSED_PARAMETER(pError); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6938 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6939 | #ifdef SQLITE_TEST | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6940 | /* simulate multiple hosts by creating unique hostid file paths */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6941 | if( sqlite3_hostid_num != 0){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6942 | pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6943 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6944 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6945 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6946 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6947 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6948 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6949 | /* The conch file contains the header, host id and lock file path | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6950 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6951 | #define PROXY_CONCHVERSION 2 /* 1-byte header, 16-byte host id, path */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6952 | #define PROXY_HEADERLEN 1 /* conch file header length */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6953 | #define PROXY_PATHINDEX (PROXY_HEADERLEN+PROXY_HOSTIDLEN) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6954 | #define PROXY_MAXCONCHLEN (PROXY_HEADERLEN+PROXY_HOSTIDLEN+MAXPATHLEN) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6955 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6956 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6957 | ** Takes an open conch file, copies the contents to a new path and then moves | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6958 | ** it back. The newly created file's file descriptor is assigned to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6959 | ** conch file structure and finally the original conch file descriptor is | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6960 | ** closed. Returns zero if successful. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6961 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6962 | static int proxyBreakConchLock(unixFile *pFile, uuid_t myHostID){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6963 | proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6964 | unixFile *conchFile = pCtx->conchFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6965 | char tPath[MAXPATHLEN]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6966 | char buf[PROXY_MAXCONCHLEN]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6967 | char *cPath = pCtx->conchFilePath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6968 | size_t readLen = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6969 | size_t pathLen = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6970 | char errmsg[64] = ""; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6971 | int fd = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6972 | int rc = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6973 | UNUSED_PARAMETER(myHostID); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6974 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6975 | /* create a new path by replace the trailing '-conch' with '-break' */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6976 | pathLen = strlcpy(tPath, cPath, MAXPATHLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6977 | if( pathLen>MAXPATHLEN || pathLen<6 || | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6978 | (strlcpy(&tPath[pathLen-5], "break", 6) != 5) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6979 | sqlite3_snprintf(sizeof(errmsg),errmsg,"path error (len %d)",(int)pathLen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6980 | goto end_breaklock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6981 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6982 | /* read the conch content */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6983 | readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6984 | if( readLen<PROXY_PATHINDEX ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6985 | sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6986 | goto end_breaklock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6987 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6988 | /* write it out to the temporary break file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6989 | fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL), 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6990 | if( fd<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6991 | sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6992 | goto end_breaklock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6993 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6994 | if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6995 | sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6996 | goto end_breaklock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6997 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6998 | if( rename(tPath, cPath) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6999 | sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7000 | goto end_breaklock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7001 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7002 | rc = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7003 | fprintf(stderr, "broke stale lock on %s\n", cPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7004 | robust_close(pFile, conchFile->h, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7005 | conchFile->h = fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7006 | conchFile->openFlags = O_RDWR | O_CREAT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7007 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7008 | end_breaklock: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7009 | if( rc ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7010 | if( fd>=0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7011 | osUnlink(tPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7012 | robust_close(pFile, fd, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7013 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7014 | fprintf(stderr, "failed to break stale lock on %s, %s\n", cPath, errmsg); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7015 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7016 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7017 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7018 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7019 | /* Take the requested lock on the conch file and break a stale lock if the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7020 | ** host id matches. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7021 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7022 | static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7023 | proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7024 | unixFile *conchFile = pCtx->conchFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7025 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7026 | int nTries = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7027 | struct timespec conchModTime; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7028 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7029 | memset(&conchModTime, 0, sizeof(conchModTime)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7030 | do { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7031 | rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, lockType); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7032 | nTries ++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7033 | if( rc==SQLITE_BUSY ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7034 | /* If the lock failed (busy): | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7035 | * 1st try: get the mod time of the conch, wait 0.5s and try again. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7036 | * 2nd try: fail if the mod time changed or host id is different, wait | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7037 | * 10 sec and try again | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7038 | * 3rd try: break the lock unless the mod time has changed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7039 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7040 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7041 | if( osFstat(conchFile->h, &buf) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7042 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7043 | return SQLITE_IOERR_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7044 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7045 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7046 | if( nTries==1 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7047 | conchModTime = buf.st_mtimespec; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7048 | usleep(500000); /* wait 0.5 sec and try the lock again*/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7049 | continue; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7050 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7051 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7052 | assert( nTries>1 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7053 | if( conchModTime.tv_sec != buf.st_mtimespec.tv_sec || | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7054 | conchModTime.tv_nsec != buf.st_mtimespec.tv_nsec ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7055 | return SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7056 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7057 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7058 | if( nTries==2 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7059 | char tBuf[PROXY_MAXCONCHLEN]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7060 | int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7061 | if( len<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7062 | storeLastErrno(pFile, errno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7063 | return SQLITE_IOERR_LOCK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7064 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7065 | if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7066 | /* don't break the lock if the host id doesn't match */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7067 | if( 0!=memcmp(&tBuf[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7068 | return SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7069 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7070 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7071 | /* don't break the lock on short read or a version mismatch */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7072 | return SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7073 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7074 | usleep(10000000); /* wait 10 sec and try the lock again */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7075 | continue; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7076 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7077 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7078 | assert( nTries==3 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7079 | if( 0==proxyBreakConchLock(pFile, myHostID) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7080 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7081 | if( lockType==EXCLUSIVE_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7082 | rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, SHARED_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7083 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7084 | if( !rc ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7085 | rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, lockType); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7086 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7087 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7088 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7089 | } while( rc==SQLITE_BUSY && nTries<3 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7090 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7091 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7092 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7093 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7094 | /* Takes the conch by taking a shared lock and read the contents conch, if | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7095 | ** lockPath is non-NULL, the host ID and lock file path must match. A NULL | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7096 | ** lockPath means that the lockPath in the conch file will be used if the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7097 | ** host IDs match, or a new lock path will be generated automatically | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7098 | ** and written to the conch file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7099 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7100 | static int proxyTakeConch(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7101 | proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7102 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7103 | if( pCtx->conchHeld!=0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7104 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7105 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7106 | unixFile *conchFile = pCtx->conchFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7107 | uuid_t myHostID; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7108 | int pError = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7109 | char readBuf[PROXY_MAXCONCHLEN]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7110 | char lockPath[MAXPATHLEN]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7111 | char *tempLockPath = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7112 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7113 | int createConch = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7114 | int hostIdMatch = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7115 | int readLen = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7116 | int tryOldLockPath = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7117 | int forceNewLockPath = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7118 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7119 | OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7120 | (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7121 | osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7122 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7123 | rc = proxyGetHostID(myHostID, &pError); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7124 | if( (rc&0xff)==SQLITE_IOERR ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7125 | storeLastErrno(pFile, pError); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7126 | goto end_takeconch; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7127 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7128 | rc = proxyConchLock(pFile, myHostID, SHARED_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7129 | if( rc!=SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7130 | goto end_takeconch; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7131 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7132 | /* read the existing conch file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7133 | readLen = seekAndRead((unixFile*)conchFile, 0, readBuf, PROXY_MAXCONCHLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7134 | if( readLen<0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7135 | /* I/O error: lastErrno set by seekAndRead */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7136 | storeLastErrno(pFile, conchFile->lastErrno); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7137 | rc = SQLITE_IOERR_READ; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7138 | goto end_takeconch; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7139 | }else if( readLen<=(PROXY_HEADERLEN+PROXY_HOSTIDLEN) || | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7140 | readBuf[0]!=(char)PROXY_CONCHVERSION ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7141 | /* a short read or version format mismatch means we need to create a new | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7142 | ** conch file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7143 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7144 | createConch = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7145 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7146 | /* if the host id matches and the lock path already exists in the conch | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7147 | ** we'll try to use the path there, if we can't open that path, we'll | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7148 | ** retry with a new auto-generated path | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7149 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7150 | do { /* in case we need to try again for an :auto: named lock file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7151 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7152 | if( !createConch && !forceNewLockPath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7153 | hostIdMatch = !memcmp(&readBuf[PROXY_HEADERLEN], myHostID, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7154 | PROXY_HOSTIDLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7155 | /* if the conch has data compare the contents */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7156 | if( !pCtx->lockProxyPath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7157 | /* for auto-named local lock file, just check the host ID and we'll | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7158 | ** use the local lock file path that's already in there | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7159 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7160 | if( hostIdMatch ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7161 | size_t pathLen = (readLen - PROXY_PATHINDEX); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7162 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7163 | if( pathLen>=MAXPATHLEN ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7164 | pathLen=MAXPATHLEN-1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7165 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7166 | memcpy(lockPath, &readBuf[PROXY_PATHINDEX], pathLen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7167 | lockPath[pathLen] = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7168 | tempLockPath = lockPath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7169 | tryOldLockPath = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7170 | /* create a copy of the lock path if the conch is taken */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7171 | goto end_takeconch; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7172 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7173 | }else if( hostIdMatch | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7174 | && !strncmp(pCtx->lockProxyPath, &readBuf[PROXY_PATHINDEX], | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7175 | readLen-PROXY_PATHINDEX) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7176 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7177 | /* conch host and lock path match */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7178 | goto end_takeconch; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7179 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7180 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7181 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7182 | /* if the conch isn't writable and doesn't match, we can't take it */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7183 | if( (conchFile->openFlags&O_RDWR) == 0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7184 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7185 | goto end_takeconch; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7186 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7187 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7188 | /* either the conch didn't match or we need to create a new one */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7189 | if( !pCtx->lockProxyPath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7190 | proxyGetLockPath(pCtx->dbPath, lockPath, MAXPATHLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7191 | tempLockPath = lockPath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7192 | /* create a copy of the lock path _only_ if the conch is taken */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7193 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7194 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7195 | /* update conch with host and path (this will fail if other process | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7196 | ** has a shared lock already), if the host id matches, use the big | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7197 | ** stick. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7198 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7199 | futimes(conchFile->h, NULL); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7200 | if( hostIdMatch && !createConch ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7201 | if( conchFile->pInode && conchFile->pInode->nShared>1 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7202 | /* We are trying for an exclusive lock but another thread in this | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7203 | ** same process is still holding a shared lock. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7204 | rc = SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7205 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7206 | rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7207 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7208 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7209 | rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7210 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7211 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7212 | char writeBuffer[PROXY_MAXCONCHLEN]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7213 | int writeSize = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7214 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7215 | writeBuffer[0] = (char)PROXY_CONCHVERSION; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7216 | memcpy(&writeBuffer[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7217 | if( pCtx->lockProxyPath!=NULL ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7218 | strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7219 | MAXPATHLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7220 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7221 | strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7222 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7223 | writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7224 | robust_ftruncate(conchFile->h, writeSize); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7225 | rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7226 | full_fsync(conchFile->h,0,0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7227 | /* If we created a new conch file (not just updated the contents of a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7228 | ** valid conch file), try to match the permissions of the database | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7229 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7230 | if( rc==SQLITE_OK && createConch ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7231 | struct stat buf; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7232 | int err = osFstat(pFile->h, &buf); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7233 | if( err==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7234 | mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7235 | S_IROTH|S_IWOTH); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7236 | /* try to match the database file R/W permissions, ignore failure */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7237 | #ifndef SQLITE_PROXY_DEBUG | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7238 | osFchmod(conchFile->h, cmode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7239 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7240 | do{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7241 | rc = osFchmod(conchFile->h, cmode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7242 | }while( rc==(-1) && errno==EINTR ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7243 | if( rc!=0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7244 | int code = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7245 | fprintf(stderr, "fchmod %o FAILED with %d %s\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7246 | cmode, code, strerror(code)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7247 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7248 | fprintf(stderr, "fchmod %o SUCCEDED\n",cmode); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7249 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7250 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7251 | int code = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7252 | fprintf(stderr, "STAT FAILED[%d] with %d %s\n", | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7253 | err, code, strerror(code)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7254 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7255 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7256 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7257 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7258 | conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, SHARED_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7259 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7260 | end_takeconch: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7261 | OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7262 | if( rc==SQLITE_OK && pFile->openFlags ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7263 | int fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7264 | if( pFile->h>=0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7265 | robust_close(pFile, pFile->h, __LINE__); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7266 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7267 | pFile->h = -1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7268 | fd = robust_open(pCtx->dbPath, pFile->openFlags, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7269 | OSTRACE(("TRANSPROXY: OPEN %d\n", fd)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7270 | if( fd>=0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7271 | pFile->h = fd; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7272 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7273 | rc=SQLITE_CANTOPEN_BKPT; /* SQLITE_BUSY? proxyTakeConch called | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7274 | during locking */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7275 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7276 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7277 | if( rc==SQLITE_OK && !pCtx->lockProxy ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7278 | char *path = tempLockPath ? tempLockPath : pCtx->lockProxyPath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7279 | rc = proxyCreateUnixFile(path, &pCtx->lockProxy, 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7280 | if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM && tryOldLockPath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7281 | /* we couldn't create the proxy lock file with the old lock file path | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7282 | ** so try again via auto-naming | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7283 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7284 | forceNewLockPath = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7285 | tryOldLockPath = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7286 | continue; /* go back to the do {} while start point, try again */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7287 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7288 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7289 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7290 | /* Need to make a copy of path if we extracted the value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7291 | ** from the conch file or the path was allocated on the stack | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7292 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7293 | if( tempLockPath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7294 | pCtx->lockProxyPath = sqlite3DbStrDup(0, tempLockPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7295 | if( !pCtx->lockProxyPath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7296 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7297 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7298 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7299 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7300 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7301 | pCtx->conchHeld = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7302 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7303 | if( pCtx->lockProxy->pMethod == &afpIoMethods ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7304 | afpLockingContext *afpCtx; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7305 | afpCtx = (afpLockingContext *)pCtx->lockProxy->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7306 | afpCtx->dbPath = pCtx->lockProxyPath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7307 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7308 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7309 | conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, NO_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7310 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7311 | OSTRACE(("TAKECONCH %d %s\n", conchFile->h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7312 | rc==SQLITE_OK?"ok":"failed")); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7313 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7314 | } while (1); /* in case we need to retry the :auto: lock file - | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7315 | ** we should never get here except via the 'continue' call. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7316 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7317 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7318 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7319 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7320 | ** If pFile holds a lock on a conch file, then release that lock. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7321 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7322 | static int proxyReleaseConch(unixFile *pFile){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7323 | int rc = SQLITE_OK; /* Subroutine return code */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7324 | proxyLockingContext *pCtx; /* The locking context for the proxy lock */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7325 | unixFile *conchFile; /* Name of the conch file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7326 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7327 | pCtx = (proxyLockingContext *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7328 | conchFile = pCtx->conchFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7329 | OSTRACE(("RELEASECONCH %d for %s pid=%d\n", conchFile->h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7330 | (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7331 | osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7332 | if( pCtx->conchHeld>0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7333 | rc = conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, NO_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7334 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7335 | pCtx->conchHeld = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7336 | OSTRACE(("RELEASECONCH %d %s\n", conchFile->h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7337 | (rc==SQLITE_OK ? "ok" : "failed"))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7338 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7339 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7340 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7341 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7342 | ** Given the name of a database file, compute the name of its conch file. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7343 | ** Store the conch filename in memory obtained from sqlite3_malloc64(). | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7344 | ** Make *pConchPath point to the new name. Return SQLITE_OK on success | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7345 | ** or SQLITE_NOMEM if unable to obtain memory. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7346 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7347 | ** The caller is responsible for ensuring that the allocated memory | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7348 | ** space is eventually freed. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7349 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7350 | ** *pConchPath is set to NULL if a memory allocation error occurs. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7351 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7352 | static int proxyCreateConchPathname(char *dbPath, char **pConchPath){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7353 | int i; /* Loop counter */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7354 | int len = (int)strlen(dbPath); /* Length of database filename - dbPath */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7355 | char *conchPath; /* buffer in which to construct conch name */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7356 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7357 | /* Allocate space for the conch filename and initialize the name to | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7358 | ** the name of the original database file. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7359 | *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7360 | if( conchPath==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7361 | return SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7362 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7363 | memcpy(conchPath, dbPath, len+1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7364 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7365 | /* now insert a "." before the last / character */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7366 | for( i=(len-1); i>=0; i-- ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7367 | if( conchPath[i]=='/' ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7368 | i++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7369 | break; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7370 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7371 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7372 | conchPath[i]='.'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7373 | while ( i<len ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7374 | conchPath[i+1]=dbPath[i]; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7375 | i++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7376 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7377 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7378 | /* append the "-conch" suffix to the file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7379 | memcpy(&conchPath[i+1], "-conch", 7); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7380 | assert( (int)strlen(conchPath) == len+7 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7381 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7382 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7383 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7384 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7385 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7386 | /* Takes a fully configured proxy locking-style unix file and switches | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7387 | ** the local lock file path | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7388 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7389 | static int switchLockProxyPath(unixFile *pFile, const char *path) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7390 | proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7391 | char *oldPath = pCtx->lockProxyPath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7392 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7393 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7394 | if( pFile->eFileLock!=NO_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7395 | return SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7396 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7397 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7398 | /* nothing to do if the path is NULL, :auto: or matches the existing path */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7399 | if( !path || path[0]=='\0' || !strcmp(path, ":auto:") || | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7400 | (oldPath && !strncmp(oldPath, path, MAXPATHLEN)) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7401 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7402 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7403 | unixFile *lockProxy = pCtx->lockProxy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7404 | pCtx->lockProxy=NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7405 | pCtx->conchHeld = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7406 | if( lockProxy!=NULL ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7407 | rc=lockProxy->pMethod->xClose((sqlite3_file *)lockProxy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7408 | if( rc ) return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7409 | sqlite3_free(lockProxy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7410 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7411 | sqlite3_free(oldPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7412 | pCtx->lockProxyPath = sqlite3DbStrDup(0, path); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7413 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7414 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7415 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7416 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7417 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7418 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7419 | ** pFile is a file that has been opened by a prior xOpen call. dbPath | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7420 | ** is a string buffer at least MAXPATHLEN+1 characters in size. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7421 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7422 | ** This routine find the filename associated with pFile and writes it | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7423 | ** int dbPath. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7424 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7425 | static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7426 | #if defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7427 | if( pFile->pMethod == &afpIoMethods ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7428 | /* afp style keeps a reference to the db path in the filePath field | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7429 | ** of the struct */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7430 | assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7431 | strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7432 | MAXPATHLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7433 | } else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7434 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7435 | if( pFile->pMethod == &dotlockIoMethods ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7436 | /* dot lock style uses the locking context to store the dot lock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7437 | ** file path */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7438 | int len = strlen((char *)pFile->lockingContext) - strlen(DOTLOCK_SUFFIX); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7439 | memcpy(dbPath, (char *)pFile->lockingContext, len + 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7440 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7441 | /* all other styles use the locking context to store the db file path */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7442 | assert( strlen((char*)pFile->lockingContext)<=MAXPATHLEN ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7443 | strlcpy(dbPath, (char *)pFile->lockingContext, MAXPATHLEN); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7444 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7445 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7446 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7447 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7448 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7449 | ** Takes an already filled in unix file and alters it so all file locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7450 | ** will be performed on the local proxy lock file. The following fields | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7451 | ** are preserved in the locking context so that they can be restored and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7452 | ** the unix structure properly cleaned up at close time: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7453 | ** ->lockingContext | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7454 | ** ->pMethod | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7455 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7456 | static int proxyTransformUnixFile(unixFile *pFile, const char *path) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7457 | proxyLockingContext *pCtx; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7458 | char dbPath[MAXPATHLEN+1]; /* Name of the database file */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7459 | char *lockPath=NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7460 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7461 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7462 | if( pFile->eFileLock!=NO_LOCK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7463 | return SQLITE_BUSY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7464 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7465 | proxyGetDbPathForUnixFile(pFile, dbPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7466 | if( !path || path[0]=='\0' || !strcmp(path, ":auto:") ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7467 | lockPath=NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7468 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7469 | lockPath=(char *)path; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7470 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7471 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7472 | OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7473 | (lockPath ? lockPath : ":auto:"), osGetpid(0))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7474 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7475 | pCtx = sqlite3_malloc64( sizeof(*pCtx) ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7476 | if( pCtx==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7477 | return SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7478 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7479 | memset(pCtx, 0, sizeof(*pCtx)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7480 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7481 | rc = proxyCreateConchPathname(dbPath, &pCtx->conchFilePath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7482 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7483 | rc = proxyCreateUnixFile(pCtx->conchFilePath, &pCtx->conchFile, 0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7484 | if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7485 | /* if (a) the open flags are not O_RDWR, (b) the conch isn't there, and | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7486 | ** (c) the file system is read-only, then enable no-locking access. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7487 | ** Ugh, since O_RDONLY==0x0000 we test for !O_RDWR since unixOpen asserts | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7488 | ** that openFlags will have only one of O_RDONLY or O_RDWR. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7489 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7490 | struct statfs fsInfo; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7491 | struct stat conchInfo; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7492 | int goLockless = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7493 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7494 | if( osStat(pCtx->conchFilePath, &conchInfo) == -1 ) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7495 | int err = errno; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7496 | if( (err==ENOENT) && (statfs(dbPath, &fsInfo) != -1) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7497 | goLockless = (fsInfo.f_flags&MNT_RDONLY) == MNT_RDONLY; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7498 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7499 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7500 | if( goLockless ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7501 | pCtx->conchHeld = -1; /* read only FS/ lockless */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7502 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7503 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7504 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7505 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7506 | if( rc==SQLITE_OK && lockPath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7507 | pCtx->lockProxyPath = sqlite3DbStrDup(0, lockPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7508 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7509 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7510 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7511 | pCtx->dbPath = sqlite3DbStrDup(0, dbPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7512 | if( pCtx->dbPath==NULL ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7513 | rc = SQLITE_NOMEM_BKPT; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7514 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7515 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7516 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7517 | /* all memory is allocated, proxys are created and assigned, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7518 | ** switch the locking context and pMethod then return. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7519 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7520 | pCtx->oldLockingContext = pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7521 | pFile->lockingContext = pCtx; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7522 | pCtx->pOldMethod = pFile->pMethod; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7523 | pFile->pMethod = &proxyIoMethods; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7524 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7525 | if( pCtx->conchFile ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7526 | pCtx->conchFile->pMethod->xClose((sqlite3_file *)pCtx->conchFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7527 | sqlite3_free(pCtx->conchFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7528 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7529 | sqlite3DbFree(0, pCtx->lockProxyPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7530 | sqlite3_free(pCtx->conchFilePath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7531 | sqlite3_free(pCtx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7532 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7533 | OSTRACE(("TRANSPROXY %d %s\n", pFile->h, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7534 | (rc==SQLITE_OK ? "ok" : "failed"))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7535 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7536 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7537 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7538 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7539 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7540 | ** This routine handles sqlite3_file_control() calls that are specific | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7541 | ** to proxy locking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7542 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7543 | static int proxyFileControl(sqlite3_file *id, int op, void *pArg){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7544 | switch( op ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7545 | case SQLITE_FCNTL_GET_LOCKPROXYFILE: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7546 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7547 | if( pFile->pMethod == &proxyIoMethods ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7548 | proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7549 | proxyTakeConch(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7550 | if( pCtx->lockProxyPath ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7551 | *(const char **)pArg = pCtx->lockProxyPath; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7552 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7553 | *(const char **)pArg = ":auto: (not held)"; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7554 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7555 | } else { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7556 | *(const char **)pArg = NULL; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7557 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7558 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7559 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7560 | case SQLITE_FCNTL_SET_LOCKPROXYFILE: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7561 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7562 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7563 | int isProxyStyle = (pFile->pMethod == &proxyIoMethods); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7564 | if( pArg==NULL || (const char *)pArg==0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7565 | if( isProxyStyle ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7566 | /* turn off proxy locking - not supported. If support is added for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7567 | ** switching proxy locking mode off then it will need to fail if | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7568 | ** the journal mode is WAL mode. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7569 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7570 | rc = SQLITE_ERROR /*SQLITE_PROTOCOL? SQLITE_MISUSE?*/; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7571 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7572 | /* turn off proxy locking - already off - NOOP */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7573 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7574 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7575 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7576 | const char *proxyPath = (const char *)pArg; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7577 | if( isProxyStyle ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7578 | proxyLockingContext *pCtx = | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7579 | (proxyLockingContext*)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7580 | if( !strcmp(pArg, ":auto:") | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7581 | || (pCtx->lockProxyPath && | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7582 | !strncmp(pCtx->lockProxyPath, proxyPath, MAXPATHLEN)) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7583 | ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7584 | rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7585 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7586 | rc = switchLockProxyPath(pFile, proxyPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7587 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7588 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7589 | /* turn on proxy file locking */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7590 | rc = proxyTransformUnixFile(pFile, proxyPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7591 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7592 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7593 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7594 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7595 | default: { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7596 | assert( 0 ); /* The call assures that only valid opcodes are sent */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7597 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7598 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7599 | /*NOTREACHED*/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7600 | return SQLITE_ERROR; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7601 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7602 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7603 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7604 | ** Within this division (the proxying locking implementation) the procedures | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7605 | ** above this point are all utilities. The lock-related methods of the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7606 | ** proxy-locking sqlite3_io_method object follow. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7607 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7608 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7609 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7610 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7611 | ** This routine checks if there is a RESERVED lock held on the specified | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7612 | ** file by this or any other process. If such a lock is held, set *pResOut | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7613 | ** to a non-zero value otherwise *pResOut is set to zero. The return value | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7614 | ** is set to SQLITE_OK unless an I/O error occurs during lock checking. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7615 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7616 | static int proxyCheckReservedLock(sqlite3_file *id, int *pResOut) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7617 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7618 | int rc = proxyTakeConch(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7619 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7620 | proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7621 | if( pCtx->conchHeld>0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7622 | unixFile *proxy = pCtx->lockProxy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7623 | return proxy->pMethod->xCheckReservedLock((sqlite3_file*)proxy, pResOut); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7624 | }else{ /* conchHeld < 0 is lockless */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7625 | pResOut=0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7626 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7627 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7628 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7629 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7630 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7631 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7632 | ** Lock the file with the lock specified by parameter eFileLock - one | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7633 | ** of the following: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7634 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7635 | ** (1) SHARED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7636 | ** (2) RESERVED_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7637 | ** (3) PENDING_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7638 | ** (4) EXCLUSIVE_LOCK | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7639 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7640 | ** Sometimes when requesting one lock state, additional lock states | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7641 | ** are inserted in between. The locking might fail on one of the later | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7642 | ** transitions leaving the lock state different from what it started but | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7643 | ** still short of its goal. The following chart shows the allowed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7644 | ** transitions and the inserted intermediate states: | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7645 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7646 | ** UNLOCKED -> SHARED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7647 | ** SHARED -> RESERVED | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7648 | ** SHARED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7649 | ** RESERVED -> (PENDING) -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7650 | ** PENDING -> EXCLUSIVE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7651 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7652 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7653 | ** routine to lower a locking level. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7654 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7655 | static int proxyLock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7656 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7657 | int rc = proxyTakeConch(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7658 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7659 | proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7660 | if( pCtx->conchHeld>0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7661 | unixFile *proxy = pCtx->lockProxy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7662 | rc = proxy->pMethod->xLock((sqlite3_file*)proxy, eFileLock); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7663 | pFile->eFileLock = proxy->eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7664 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7665 | /* conchHeld < 0 is lockless */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7666 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7667 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7668 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7669 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7670 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7671 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7672 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7673 | ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7674 | ** must be either NO_LOCK or SHARED_LOCK. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7675 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7676 | ** If the locking level of the file descriptor is already at or below | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7677 | ** the requested locking level, this routine is a no-op. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7678 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7679 | static int proxyUnlock(sqlite3_file *id, int eFileLock) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7680 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7681 | int rc = proxyTakeConch(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7682 | if( rc==SQLITE_OK ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7683 | proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7684 | if( pCtx->conchHeld>0 ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7685 | unixFile *proxy = pCtx->lockProxy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7686 | rc = proxy->pMethod->xUnlock((sqlite3_file*)proxy, eFileLock); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7687 | pFile->eFileLock = proxy->eFileLock; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7688 | }else{ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7689 | /* conchHeld < 0 is lockless */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7690 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7691 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7692 | return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7693 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7694 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7695 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7696 | ** Close a file that uses proxy locks. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7697 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7698 | static int proxyClose(sqlite3_file *id) { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7699 | if( ALWAYS(id) ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7700 | unixFile *pFile = (unixFile*)id; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7701 | proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7702 | unixFile *lockProxy = pCtx->lockProxy; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7703 | unixFile *conchFile = pCtx->conchFile; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7704 | int rc = SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7705 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7706 | if( lockProxy ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7707 | rc = lockProxy->pMethod->xUnlock((sqlite3_file*)lockProxy, NO_LOCK); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7708 | if( rc ) return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7709 | rc = lockProxy->pMethod->xClose((sqlite3_file*)lockProxy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7710 | if( rc ) return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7711 | sqlite3_free(lockProxy); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7712 | pCtx->lockProxy = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7713 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7714 | if( conchFile ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7715 | if( pCtx->conchHeld ){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7716 | rc = proxyReleaseConch(pFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7717 | if( rc ) return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7718 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7719 | rc = conchFile->pMethod->xClose((sqlite3_file*)conchFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7720 | if( rc ) return rc; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7721 | sqlite3_free(conchFile); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7722 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7723 | sqlite3DbFree(0, pCtx->lockProxyPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7724 | sqlite3_free(pCtx->conchFilePath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7725 | sqlite3DbFree(0, pCtx->dbPath); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7726 | /* restore the original locking context and pMethod then close it */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7727 | pFile->lockingContext = pCtx->oldLockingContext; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7728 | pFile->pMethod = pCtx->pOldMethod; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7729 | sqlite3_free(pCtx); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7730 | return pFile->pMethod->xClose(id); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7731 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7732 | return SQLITE_OK; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7733 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7734 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7735 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7736 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7737 | #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7738 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7739 | ** The proxy locking style is intended for use with AFP filesystems. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7740 | ** And since AFP is only supported on MacOSX, the proxy locking is also | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7741 | ** restricted to MacOSX. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7742 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7743 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7744 | ******************* End of the proxy lock implementation ********************** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7745 | ******************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7746 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7747 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7748 | ** Initialize the operating system interface. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7749 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7750 | ** This routine registers all VFS implementations for unix-like operating | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7751 | ** systems. This routine, and the sqlite3_os_end() routine that follows, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7752 | ** should be the only routines in this file that are visible from other | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7753 | ** files. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7754 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7755 | ** This routine is called once during SQLite initialization and by a | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7756 | ** single thread. The memory allocation and mutex subsystems have not | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7757 | ** necessarily been initialized when this routine is called, and so they | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7758 | ** should not be used. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7759 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7760 | int sqlite3_os_init(void){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7761 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7762 | ** The following macro defines an initializer for an sqlite3_vfs object. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7763 | ** The name of the VFS is NAME. The pAppData is a pointer to a pointer | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7764 | ** to the "finder" function. (pAppData is a pointer to a pointer because | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7765 | ** silly C90 rules prohibit a void* from being cast to a function pointer | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7766 | ** and so we have to go through the intermediate pointer to avoid problems | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7767 | ** when compiling with -pedantic-errors on GCC.) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7768 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7769 | ** The FINDER parameter to this macro is the name of the pointer to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7770 | ** finder-function. The finder-function returns a pointer to the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7771 | ** sqlite_io_methods object that implements the desired locking | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7772 | ** behaviors. See the division above that contains the IOMETHODS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7773 | ** macro for addition information on finder-functions. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7774 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7775 | ** Most finders simply return a pointer to a fixed sqlite3_io_methods | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7776 | ** object. But the "autolockIoFinder" available on MacOSX does a little | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7777 | ** more than that; it looks at the filesystem type that hosts the | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7778 | ** database file and tries to choose an locking method appropriate for | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7779 | ** that filesystem time. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7780 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7781 | #define UNIXVFS(VFSNAME, FINDER) { \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7782 | 3, /* iVersion */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7783 | sizeof(unixFile), /* szOsFile */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7784 | MAX_PATHNAME, /* mxPathname */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7785 | 0, /* pNext */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7786 | VFSNAME, /* zName */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7787 | (void*)&FINDER, /* pAppData */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7788 | unixOpen, /* xOpen */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7789 | unixDelete, /* xDelete */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7790 | unixAccess, /* xAccess */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7791 | unixFullPathname, /* xFullPathname */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7792 | unixDlOpen, /* xDlOpen */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7793 | unixDlError, /* xDlError */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7794 | unixDlSym, /* xDlSym */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7795 | unixDlClose, /* xDlClose */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7796 | unixRandomness, /* xRandomness */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7797 | unixSleep, /* xSleep */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7798 | unixCurrentTime, /* xCurrentTime */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7799 | unixGetLastError, /* xGetLastError */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7800 | unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7801 | unixSetSystemCall, /* xSetSystemCall */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7802 | unixGetSystemCall, /* xGetSystemCall */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7803 | unixNextSystemCall, /* xNextSystemCall */ \ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7804 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7805 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7806 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7807 | ** All default VFSes for unix are contained in the following array. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7808 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7809 | ** Note that the sqlite3_vfs.pNext field of the VFS object is modified | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7810 | ** by the SQLite core when the VFS is registered. So the following | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7811 | ** array cannot be const. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7812 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7813 | static sqlite3_vfs aVfs[] = { | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7814 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7815 | UNIXVFS("unix", autolockIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7816 | #elif OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7817 | UNIXVFS("unix", vxworksIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7818 | #else | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7819 | UNIXVFS("unix", posixIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7820 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7821 | UNIXVFS("unix-none", nolockIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7822 | UNIXVFS("unix-dotfile", dotlockIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7823 | UNIXVFS("unix-excl", posixIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7824 | #if OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7825 | UNIXVFS("unix-namedsem", semIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7826 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7827 | #if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7828 | UNIXVFS("unix-posix", posixIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7829 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7830 | #if SQLITE_ENABLE_LOCKING_STYLE | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7831 | UNIXVFS("unix-flock", flockIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7832 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7833 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7834 | UNIXVFS("unix-afp", afpIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7835 | UNIXVFS("unix-nfs", nfsIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7836 | UNIXVFS("unix-proxy", proxyIoFinder ), | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7837 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7838 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7839 | unsigned int i; /* Loop counter */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7840 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7841 | /* Double-check that the aSyscall[] array has been constructed | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7842 | ** correctly. See ticket [bb3a86e890c8e96ab] */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7843 | assert( ArraySize(aSyscall)==29 ); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7844 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7845 | /* Register all VFSes defined in the aVfs[] array */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7846 | for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
| 530-2120 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7847 | sqlite3_vfs_register(&aVfs[i], i==0); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7848 | } executed 2120 times by 438 tests: end of block Executed by:
| 2120 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7849 | unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7850 | return SQLITE_OK; executed 530 times by 438 tests: return 0; Executed by:
| 530 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7851 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7852 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7853 | /* | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7854 | ** Shutdown the operating system interface. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7855 | ** | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7856 | ** Some operating systems might need to do some cleanup in this routine, | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7857 | ** to release dynamically allocated objects. But not on unix. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7858 | ** This routine is a no-op for unix. | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7859 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7860 | int sqlite3_os_end(void){ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7861 | unixBigLock = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7862 | return SQLITE_OK; executed 93 times by 6 tests: return 0; Executed by:
| 93 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7863 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7864 | - | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7865 | #endif /* SQLITE_OS_UNIX */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |