OpenCoverage

os_unix.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/sqlite/src/src/os_unix.c
Source codeSwitch to Preprocessed file
LineSourceCount
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 */-
182typedef struct unixShm unixShm; /* Connection shared memory */-
183typedef struct unixShmNode unixShmNode; /* Shared memory instance */-
184typedef struct unixInodeInfo unixInodeInfo; /* An i-node */-
185typedef 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*/-
193struct 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*/-
203typedef struct unixFile unixFile;-
204struct 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*/-
264static 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*/-
355static 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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
107540
357}-
358-
359/* Forward reference */-
360static int openDirectory(const char*, int*);-
361static 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*/-
369static 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*/-
542static 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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
((uid_t(*)(voi...1].pCurrent)()Description
TRUEevaluated 45462 times by 425 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEnever evaluated
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*/-
556static 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 ){
zName==0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test (438)
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++){
i<sizeof(aSysc...f(aSyscall[0])Description
TRUEevaluated 174 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
6-174
571 if( aSyscall[i].pDefault ){
aSyscall[i].pDefaultDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 147 times by 1 test
Evaluated by:
  • Self test (438)
27-147
572 aSyscall[i].pCurrent = aSyscall[i].pDefault;-
573 }
executed 27 times by 1 test: end of block
Executed by:
  • Self test (438)
27
574 }
executed 174 times by 1 test: end of block
Executed by:
  • Self test (438)
174
575 }else{
executed 6 times by 1 test: end of block
Executed by:
  • Self test (438)
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++){
i<sizeof(aSysc...f(aSyscall[0])Description
TRUEevaluated 262 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
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
__extension__ ...e )))); }) ==0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 247 times by 1 test
Evaluated by:
  • Self test (438)
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-247
581 if( aSyscall[i].pDefault==0 ){
aSyscall[i].pDefault==0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test (438)
7-8
582 aSyscall[i].pDefault = aSyscall[i].pCurrent;-
583 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test (438)
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:
  • Self test (438)
pNewFunc==0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test (438)
5-10
586 aSyscall[i].pCurrent = pNewFunc;-
587 break;
executed 15 times by 1 test: break;
Executed by:
  • Self test (438)
15
588 }-
589 }
executed 247 times by 1 test: end of block
Executed by:
  • Self test (438)
247
590 }
executed 17 times by 1 test: end of block
Executed by:
  • Self test (438)
17
591 return rc;
executed 23 times by 1 test: return rc;
Executed by:
  • Self test (438)
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*/-
599static 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++){
i<sizeof(aSysc...f(aSyscall[0])Description
TRUEevaluated 636 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
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:
  • Self test (438)
__extension__ ...e )))); }) ==0Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 597 times by 1 test
Evaluated by:
  • Self test (438)
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-597
608 }
executed 597 times by 1 test: end of block
Executed by:
  • Self test (438)
597
609 return 0;
executed 3 times by 1 test: return 0;
Executed by:
  • Self test (438)
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*/-
618static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){-
619 int i = -1;-
620-
621 UNUSED_PARAMETER(p);-
622 if( zName ){
zNameDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
1-25
623 for(i=0; i<ArraySize(aSyscall)-1; i++){
i<((int)(sizeo...yscall[0])))-1Description
TRUEevaluated 367 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
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:
  • Self test (438)
__extension__ ...e )))); }) ==0Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 342 times by 1 test
Evaluated by:
  • Self test (438)
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-342
625 }
executed 342 times by 1 test: end of block
Executed by:
  • Self test (438)
342
626 }
executed 25 times by 1 test: end of block
Executed by:
  • Self test (438)
25
627 for(i++; i<ArraySize(aSyscall); i++){
i<((int)(sizeo...aSyscall[0])))Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
1-29
628 if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
executed 25 times by 1 test: return aSyscall[i].zName;
Executed by:
  • Self test (438)
aSyscall[i].pCurrent!=0Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
4-25
629 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test (438)
4
630 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • Self test (438)
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*/-
659static int robust_open(const char *z, int f, mode_t m){-
660 int fd;-
661 mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS;
mDescription
TRUEevaluated 45759 times by 425 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 61779 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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 ){
fd<0Description
TRUEevaluated 558 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 107015 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
558-107015
669 if( errno==EINTR ) continue;
executed 32 times by 1 test: continue;
Executed by:
  • Self test (438)
(*__errno_location ()) == 4Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 526 times by 1 test
Evaluated by:
  • Self test (438)
32-526
670 break;
executed 526 times by 1 test: break;
Executed by:
  • Self test (438)
526
671 }-
672 if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break;
executed 107015 times by 438 tests: break;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
fd>=3Description
TRUEevaluated 107015 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
FALSEnever evaluated
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;
((int(*)(const...null", f, m)<0Description
TRUEnever evaluated
FALSEnever evaluated
0
678 }
never executed: end of block
0
679 if( fd>=0 ){
fd>=0Description
TRUEevaluated 107015 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
FALSEevaluated 526 times by 1 test
Evaluated by:
  • Self test (438)
526-107015
680 if( m!=0 ){
m!=0Description
TRUEevaluated 45739 times by 425 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 61276 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
45739-61276
681 struct stat statbuf;-
682 if( osFstat(fd, &statbuf)==0
((int(*)(int,s..., &statbuf)==0Description
TRUEevaluated 45739 times by 425 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEnever evaluated
0-45739
683 && statbuf.st_size==0
statbuf.st_size==0Description
TRUEevaluated 41332 times by 153 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • ...
FALSEevaluated 4407 times by 290 tests
Evaluated by:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • ...
4407-41332
684 && (statbuf.st_mode&0777)!=m
(statbuf.st_mode&0777)!=mDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 41328 times by 153 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • ...
4-41328
685 ){-
686 osFchmod(fd, m);-
687 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test (438)
4
688 }
executed 45739 times by 425 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
107015
693 return fd;
executed 107541 times by 438 tests: return fd;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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*/-
721static sqlite3_mutex *unixBigLock = 0;-
722static 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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
286129
726static 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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
286129
730#ifdef SQLITE_DEBUG-
731static 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*/-
743static 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*/-
764static 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*/-
822static 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:
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (19)
  • Self test (20)
  • Self test (23)
  • Self test (28)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (7)
  • Self test (72)
  • Self test (75)
  • Self test (79)
  • Self test (8)
  • Self test (81)
  • Self test (83)
  • Self test (84)
  • Self test (85)
  • ...
rc<0Description
TRUEnever evaluated
FALSEevaluated 7331 times by 36 tests
Evaluated by:
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (19)
  • Self test (20)
  • Self test (23)
  • Self test (28)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (7)
  • Self test (72)
  • Self test (75)
  • Self test (79)
  • Self test (8)
  • Self test (81)
  • Self test (83)
  • Self test (84)
  • Self test (85)
  • ...
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEnever evaluated
0-7331
834 return rc;
executed 7331 times by 36 tests: return rc;
Executed by:
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (19)
  • Self test (20)
  • Self test (23)
  • Self test (28)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (7)
  • Self test (72)
  • Self test (75)
  • Self test (79)
  • Self test (8)
  • Self test (81)
  • Self test (83)
  • Self test (84)
  • Self test (85)
  • ...
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*/-
847static 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:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (52)
  • Self test (55)
  • Self test (59)
  • Self test (61)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • ...
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:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (52)
  • Self test (55)
  • Self test (59)
  • Self test (61)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • ...
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:
  • Self test (438)
3
867 return sqliteIOErr;
executed 3 times by 1 test: return sqliteIOErr;
Executed by:
  • Self test (438)
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*/-
889struct 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*/-
901static 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*/-
916static 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*/-
950static 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*/-
992static 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*/-
1104struct 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*/-
1146struct 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*/-
1170static 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*/-
1177int unixFileMutexHeld(unixFile *pFile){-
1178 assert( pFile->pInode );-
1179 return sqlite3_mutex_held(pFile->pInode->pLockMutex);-
1180}-
1181int 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__)-
1204static 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 = "";
zPath==0Description
TRUEnever evaluated
FALSEevaluated 516 times by 1 test
Evaluated by:
  • Self test (438)
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:
  • Self test (438)
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*/-
1269static void robust_close(unixFile *pFile, int h, int lineno){-
1270 if( osClose(h) ){
((int(*)(int))...].pCurrent)(h)Description
TRUEnever evaluated
FALSEevaluated 106261 times by 416 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
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*/-
1280static void storeLastErrno(unixFile *pFile, int error){-
1281 pFile->lastErrno = error;-
1282}
executed 140006 times by 438 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
140006
1283-
1284/*-
1285** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.-
1286*/ -
1287static 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){
pDescription
TRUEevaluated 471 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 151101 times by 427 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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:
  • Self test (438)
471
1297 pInode->pUnused = 0;-
1298}
executed 151101 times by 427 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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*/-
1306static void releaseInodeInfo(unixFile *pFile){-
1307 unixInodeInfo *pInode = pFile->pInode;-
1308 assert( unixMutexHeld() );-
1309 assert( unixFileMutexNotheld(pFile) );-
1310 if( ALWAYS(pInode) ){
(pInode)Description
TRUEevaluated 31857 times by 66 tests
Evaluated by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
FALSEnever evaluated
0-31857
1311 pInode->nRef--;-
1312 if( pInode->nRef==0 ){
pInode->nRef==0Description
TRUEevaluated 19742 times by 66 tests
Evaluated by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
FALSEevaluated 12115 times by 1 test
Evaluated by:
  • Self test (438)
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 ){
pInode->pPrevDescription
TRUEevaluated 9326 times by 10 tests
Evaluated by:
  • Self test (27)
  • Self test (34)
  • Self test (438)
  • Self test (77)
  • Self test (78)
  • Self test (79)
  • Self test (80)
  • Self test (81)
  • Self test (82)
  • Self test (83)
FALSEevaluated 10416 times by 66 tests
Evaluated by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
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:
  • Self test (27)
  • Self test (34)
  • Self test (438)
  • Self test (77)
  • Self test (78)
  • Self test (79)
  • Self test (80)
  • Self test (81)
  • Self test (82)
  • Self test (83)
9326
1321 assert( inodeList==pInode );-
1322 inodeList = pInode->pNext;-
1323 }
executed 10416 times by 66 tests: end of block
Executed by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
10416
1324 if( pInode->pNext ){
pInode->pNextDescription
TRUEevaluated 9541 times by 2 tests
Evaluated by:
  • Self test (31)
  • Self test (438)
FALSEevaluated 10201 times by 65 tests
Evaluated by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • Self test (438)
  • ...
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:
  • Self test (31)
  • Self test (438)
9541
1328 sqlite3_mutex_free(pInode->pLockMutex);-
1329 sqlite3_free(pInode);-
1330 }
executed 19742 times by 66 tests: end of block
Executed by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
19742
1331 }
executed 31857 times by 66 tests: end of block
Executed by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
31857
1332}
executed 31857 times by 66 tests: end of block
Executed by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
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*/-
1344static 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 ){
rc!=0Description
TRUEnever evaluated
FALSEevaluated 32248 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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)) ){
pInodeDescription
TRUEevaluated 133079 times by 13 tests
Evaluated by:
  • Self test (27)
  • Self test (31)
  • Self test (34)
  • Self test (4)
  • Self test (438)
  • Self test (5)
  • Self test (77)
  • Self test (78)
  • Self test (79)
  • Self test (80)
  • Self test (81)
  • Self test (82)
  • Self test (83)
FALSEevaluated 20133 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
memcmp(&fileId...izeof(fileId))Description
TRUEevaluated 120964 times by 13 tests
Evaluated by:
  • Self test (27)
  • Self test (31)
  • Self test (34)
  • Self test (4)
  • Self test (438)
  • Self test (5)
  • Self test (77)
  • Self test (78)
  • Self test (79)
  • Self test (80)
  • Self test (81)
  • Self test (82)
  • Self test (83)
FALSEevaluated 12115 times by 1 test
Evaluated by:
  • Self test (438)
12115-133079
1403 pInode = pInode->pNext;-
1404 }
executed 120964 times by 13 tests: end of block
Executed by:
  • Self test (27)
  • Self test (31)
  • Self test (34)
  • Self test (4)
  • Self test (438)
  • Self test (5)
  • Self test (77)
  • Self test (78)
  • Self test (79)
  • Self test (80)
  • Self test (81)
  • Self test (82)
  • Self test (83)
120964
1405 if( pInode==0 ){
pInode==0Description
TRUEevaluated 20133 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
FALSEevaluated 12115 times by 1 test
Evaluated by:
  • Self test (438)
12115-20133
1406 pInode = sqlite3_malloc64( sizeof(*pInode) );-
1407 if( pInode==0 ){
pInode==0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20125 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
8-20125
1408 return SQLITE_NOMEM_BKPT;
executed 8 times by 1 test: return 7;
Executed by:
  • Self test (438)
8
1409 }-
1410 memset(pInode, 0, sizeof(*pInode));-
1411 memcpy(&pInode->fileId, &fileId, sizeof(fileId));-
1412 if( sqlite3GlobalConfig.bCoreMutex ){
sqlite3Config.bCoreMutexDescription
TRUEevaluated 20116 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test (438)
9-20116
1413 pInode->pLockMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);-
1414 if( pInode->pLockMutex==0 ){
pInode->pLockMutex==0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20108 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
8-20108
1415 sqlite3_free(pInode);-
1416 return SQLITE_NOMEM_BKPT;
executed 8 times by 1 test: return 7;
Executed by:
  • Self test (438)
8
1417 }-
1418 }
executed 20108 times by 438 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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:
  • Self test (27)
  • Self test (31)
  • Self test (34)
  • Self test (4)
  • Self test (438)
  • Self test (5)
  • Self test (77)
  • Self test (78)
  • Self test (79)
  • Self test (80)
  • Self test (81)
  • Self test (82)
  • Self test (83)
inodeListDescription
TRUEevaluated 10164 times by 13 tests
Evaluated by:
  • Self test (27)
  • Self test (31)
  • Self test (34)
  • Self test (4)
  • Self test (438)
  • Self test (5)
  • Self test (77)
  • Self test (78)
  • Self test (79)
  • Self test (80)
  • Self test (81)
  • Self test (82)
  • Self test (83)
FALSEevaluated 9953 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
9953-10164
1423 inodeList = pInode;-
1424 }else{
executed 20117 times by 438 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
20117
1425 pInode->nRef++;-
1426 }
executed 12115 times by 1 test: end of block
Executed by:
  • Self test (438)
12115
1427 *ppInode = pInode;-
1428 return SQLITE_OK;
executed 32232 times by 438 tests: return 0;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
32232
1429}-
1430-
1431/*-
1432** Return TRUE if pFile has been renamed or unlinked since it was first opened.-
1433*/-
1434static 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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
pFile->pInode!=0Description
TRUEevaluated 119144 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test (438)
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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
((int(*)(const...Path, &buf)!=0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 119137 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
(u64)buf.st_in...de->fileId.inoDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 119126 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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*/-
1455static 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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
pFile->ctrlFlags & 0x80Description
TRUEevaluated 45003 times by 425 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 64093 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
45003-64093
1461-
1462 rc = osFstat(pFile->h, &buf);-
1463 if( rc!=0 ){
rc!=0Description
TRUEnever evaluated
FALSEevaluated 64093 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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 ){
buf.st_nlink==0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 64082 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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:
  • Self test (438)
11
1470 }-
1471 if( buf.st_nlink>1 ){
buf.st_nlink>1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 64080 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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:
  • Self test (438)
2
1474 }-
1475 if( fileHasMoved(pFile) ){
fileHasMoved(pFile)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 64079 times by 438 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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:
  • Self test (438)
1
1478 }-
1479}
executed 64079 times by 438 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • ...
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*/-
1488static 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));
sqlite3_io_error_persistDescription
TRUEnever evaluated
FALSEevaluated 2588 times by 258 tests
Evaluated by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
sqlite3_io_error_hitDescription
TRUEnever evaluated
FALSEnever evaluated
sqlite3_io_err...pending-- == 1Description
TRUEnever evaluated
FALSEevaluated 2588 times by 258 tests
Evaluated by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
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 ){
pFile->pInode->eFileLock>1Description
TRUEevaluated 67 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2521 times by 258 tests
Evaluated by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
67-2521
1501 reserved = 1;-
1502 }
executed 67 times by 1 test: end of block
Executed by:
  • Self test (438)
67
1503-
1504 /* Otherwise see if some other process holds it.-
1505 */-
1506#ifndef __DJGPP__-
1507 if( !reserved && !pFile->pInode->bProcessLock ){
!reservedDescription
TRUEevaluated 2521 times by 258 tests
Evaluated by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
FALSEevaluated 67 times by 1 test
Evaluated by:
  • Self test (438)
!pFile->pInode->bProcessLockDescription
TRUEevaluated 2521 times by 258 tests
Evaluated by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
FALSEnever evaluated
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) ){
((int(*)(int,i...>h, 5 , &lock)Description
TRUEnever evaluated
FALSEevaluated 2521 times by 258 tests
Evaluated by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
0-2521
1514 rc = SQLITE_IOERR_CHECKRESERVEDLOCK;-
1515 storeLastErrno(pFile, errno);-
1516 } else if( lock.l_type!=F_UNLCK ){
never executed: end of block
lock.l_type!= 2Description
TRUEevaluated 15 times by 6 tests
Evaluated by:
  • Self test (30)
  • Self test (35)
  • Self test (36)
  • Self test (438)
  • Self test (49)
  • Self test (52)
FALSEevaluated 2506 times by 253 tests
Evaluated by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
0-2506
1517 reserved = 1;-
1518 }
executed 15 times by 6 tests: end of block
Executed by:
  • Self test (30)
  • Self test (35)
  • Self test (36)
  • Self test (438)
  • Self test (49)
  • Self test (52)
15
1519 }
executed 2521 times by 258 tests: end of block
Executed by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
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);
sqlite3OSTraceDescription
TRUEnever evaluated
FALSEevaluated 2588 times by 258 tests
Evaluated by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
0-2588
1524-
1525 *pResOut = reserved;-
1526 return rc;
executed 2588 times by 258 tests: return rc;
Executed by:
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • Self test (131)
  • Self test (132)
  • ...
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-
1545static 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*/-
1585static 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 ){
(pFile->ctrlFl...1|0x02))==0x01Description
TRUEevaluated 59 times by 2 tests
Evaluated by:
  • Self test (438)
  • Self test (61)
FALSEevaluated 739518 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
59-739518
1591 if( pInode->bProcessLock==0 ){
pInode->bProcessLock==0Description
TRUEevaluated 5 times by 2 tests
Evaluated by:
  • Self test (438)
  • Self test (61)
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test (438)
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:
  • Self test (61)
rc<0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (61)
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
1-4
1600 pInode->bProcessLock = 1;-
1601 pInode->nLock++;-
1602 }else{
executed 4 times by 1 test: end of block
Executed by:
  • Self test (438)
4
1603 rc = 0;-
1604 }
executed 54 times by 1 test: end of block
Executed by:
  • Self test (438)
54
1605 }else{-
1606 rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile);-
1607 }
executed 739518 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
739518
1608 return rc;
executed 739576 times by 435 tests: return rc;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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*/-
1635static 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()) ;
sqlite3OSTraceDescription
TRUEnever evaluated
FALSEevaluated 219936 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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 ){
pFile->eFileLock>=eFileLockDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 219907 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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)) ;
sqlite3OSTraceDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test (438)
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:
  • Self test (438)
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 &&
pFile->eFileLo...ode->eFileLockDescription
TRUEevaluated 1767 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 218140 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
1767-218140
1715 (pInode->eFileLock>=PENDING_LOCK || eFileLock>SHARED_LOCK))
pInode->eFileLock>=3Description
TRUEevaluated 1037 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 730 times by 1 test
Evaluated by:
  • Self test (438)
eFileLock>1Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 666 times by 1 test
Evaluated by:
  • Self test (438)
64-1037
1716 ){-
1717 rc = SQLITE_BUSY;-
1718 goto end_lock;
executed 1101 times by 1 test: goto end_lock;
Executed by:
  • Self test (438)
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 &&
eFileLock==1Description
TRUEevaluated 132410 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 86396 times by 416 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
86396-132410
1726 (pInode->eFileLock==SHARED_LOCK || pInode->eFileLock==RESERVED_LOCK) ){
pInode->eFileLock==1Description
TRUEevaluated 526 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 131884 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
pInode->eFileLock==2Description
TRUEevaluated 140 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 131744 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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:
  • Self test (438)
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
eFileLock==1Description
TRUEevaluated 131744 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 86396 times by 416 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
86396-131744
1744 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
eFileLock==4Description
TRUEevaluated 43293 times by 167 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • ...
FALSEevaluated 43103 times by 382 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
pFile->eFileLock<3Description
TRUEevaluated 41439 times by 167 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • ...
FALSEevaluated 1854 times by 2 tests
Evaluated by:
  • Self test (38)
  • Self test (438)
1854-43293
1745 ){-
1746 lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
eFileLock==1Description
TRUEevaluated 131744 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 41439 times by 167 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • ...
41439-131744
1747 lock.l_start = PENDING_BYTE;-
1748 if( unixFileLock(pFile, &lock) ){
unixFileLock(pFile, &lock)Description
TRUEevaluated 11 times by 7 tests
Evaluated by:
  • Self test (30)
  • Self test (31)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (438)
  • Self test (61)
FALSEevaluated 173172 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
11-173172
1749 tErrno = errno;-
1750 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);-
1751 if( rc!=SQLITE_BUSY ){
rc!=5Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 8 times by 7 tests
Evaluated by:
  • Self test (30)
  • Self test (31)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (438)
  • Self test (61)
3-8
1752 storeLastErrno(pFile, tErrno);-
1753 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test (438)
3
1754 goto end_lock;
executed 11 times by 7 tests: goto end_lock;
Executed by:
  • Self test (30)
  • Self test (31)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (438)
  • Self test (61)
11
1755 }-
1756 }
executed 173172 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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 ){
eFileLock==1Description
TRUEevaluated 131737 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 86392 times by 415 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
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) ){
unixFileLock(pFile, &lock)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (59)
FALSEevaluated 131736 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
1-131736
1771 tErrno = errno;-
1772 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);-
1773 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test (59)
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 ){
unixFileLock(pFile, &lock)Description
TRUEnever evaluated
FALSEevaluated 131737 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
rc==0Description
TRUEnever evaluated
FALSEnever evaluated
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 ){
rcDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (59)
FALSEevaluated 131736 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
1-131736
1786 if( rc!=SQLITE_BUSY ){
rc!=5Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (59)
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:
  • Self test (59)
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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
131736
1795 }else if( eFileLock==EXCLUSIVE_LOCK && pInode->nShared>1 ){
eFileLock==4Description
TRUEevaluated 43289 times by 166 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • ...
FALSEevaluated 43103 times by 382 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
pInode->nShared>1Description
TRUEevaluated 2304 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 40985 times by 166 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • ...
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:
  • Self test (438)
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 ){
eFileLock==2Description
TRUEevaluated 43103 times by 382 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
FALSEevaluated 40985 times by 166 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • ...
40985
1815-
1816 if( unixFileLock(pFile, &lock) ){
unixFileLock(pFile, &lock)Description
TRUEevaluated 78 times by 39 tests
Evaluated by:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (35)
  • Self test (38)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (52)
  • Self test (55)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • Self test (68)
  • Self test (69)
  • Self test (70)
  • Self test (71)
  • Self test (72)
  • ...
FALSEevaluated 84010 times by 387 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • ...
78-84010
1817 tErrno = errno;-
1818 rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);-
1819 if( rc!=SQLITE_BUSY ){
rc!=5Description
TRUEnever evaluated
FALSEevaluated 78 times by 39 tests
Evaluated by:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (35)
  • Self test (38)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (52)
  • Self test (55)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • Self test (68)
  • Self test (69)
  • Self test (70)
  • Self test (71)
  • Self test (72)
  • ...
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:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (35)
  • Self test (38)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (52)
  • Self test (55)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • Self test (68)
  • Self test (69)
  • Self test (70)
  • Self test (71)
  • Self test (72)
  • ...
78
1823 }
executed 84088 times by 415 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
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 ){
rc==0Description
TRUEevaluated 215746 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 2382 times by 39 tests
Evaluated by:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (35)
  • Self test (38)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (52)
  • Self test (55)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • Self test (68)
  • Self test (69)
  • Self test (70)
  • Self test (71)
  • Self test (72)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
eFileLock==4Description
TRUEevaluated 2374 times by 36 tests
Evaluated by:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (38)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (55)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • Self test (68)
  • Self test (69)
  • Self test (70)
  • Self test (71)
  • Self test (72)
  • Self test (74)
  • Self test (75)
  • Self test (76)
  • ...
FALSEevaluated 8 times by 4 tests
Evaluated by:
  • Self test (30)
  • Self test (35)
  • Self test (438)
  • Self test (52)
8-215746
1847 pFile->eFileLock = PENDING_LOCK;-
1848 pInode->eFileLock = PENDING_LOCK;-
1849 }
executed 2374 times by 36 tests: end of block
Executed by:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (38)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (55)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • Self test (68)
  • Self test (69)
  • Self test (70)
  • Self test (71)
  • Self test (72)
  • Self test (74)
  • Self test (75)
  • Self test (76)
  • ...
2374
1850-
1851end_lock:
code before this statement executed 218128 times by 435 tests: end_lock:
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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") ;
sqlite3OSTraceDescription
TRUEnever evaluated
FALSEevaluated 219907 times by 436 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
219907
1856}-
1857-
1858/*-
1859** Add the file descriptor used by file handle pFile to the corresponding-
1860** pUnused list.-
1861*/-
1862static 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:
  • Self test (438)
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*/-
1885static 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()) ;
sqlite3OSTraceDescription
TRUEnever evaluated
FALSEevaluated 237194 times by 427 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
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 ){
pFile->eFileLock<=eFileLockDescription
TRUEevaluated 62228 times by 66 tests
Evaluated by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
FALSEevaluated 174966 times by 424 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
62228-174966
1898 return SQLITE_OK;
executed 62228 times by 66 tests: return 0;
Executed by:
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (24)
  • Self test (25)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (41)
  • Self test (42)
  • Self test (43)
  • ...
62228
1899 }-
1900 pInode = pFile->pInode;-
1901 sqlite3_mutex_enter(pInode->pLockMutex);-
1902 assert( pInode->nShared!=0 );-
1903 if( pFile->eFileLock>SHARED_LOCK ){
pFile->eFileLock>1Description
TRUEevaluated 44532 times by 71 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (38)
  • ...
FALSEevaluated 130434 times by 397 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
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 ){
eFileLock==1Description
TRUEevaluated 42930 times by 38 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (42)
  • ...
FALSEevaluated 1602 times by 37 tests
Evaluated by:
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (28)
  • Self test (29)
  • Self test (41)
  • Self test (438)
  • Self test (50)
  • Self test (51)
  • Self test (62)
  • Self test (63)
  • Self test (65)
  • Self test (66)
  • Self test (67)
  • Self test (68)
  • Self test (69)
  • Self test (70)
  • Self test (71)
  • Self test (72)
  • Self test (73)
  • Self test (74)
  • Self test (75)
  • Self test (76)
  • Self test (78)
  • ...
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) ){
unixFileLock(pFile, &lock)Description
TRUEnever evaluated
FALSEevaluated 42930 times by 38 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (42)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (42)
  • ...
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 ){
unixFileLock(pFile, &lock)==0Description
TRUEevaluated 44532 times by 71 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (38)
  • ...
FALSEnever evaluated
0-44532
1994 pInode->eFileLock = SHARED_LOCK;-
1995 }else{
executed 44532 times by 71 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (38)
  • ...
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 ){
eFileLock==0Description
TRUEevaluated 132036 times by 424 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
FALSEevaluated 42930 times by 38 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (11)
  • Self test (14)
  • Self test (15)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (38)
  • Self test (39)
  • Self test (40)
  • Self test (42)
  • ...
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 ){
pInode->nShared==0Description
TRUEevaluated 131370 times by 424 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
FALSEevaluated 666 times by 1 test
Evaluated by:
  • Self test (438)
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 ){
unixFileLock(pFile, &lock)==0Description
TRUEevaluated 131370 times by 424 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
FALSEnever evaluated
0-131370
2012 pInode->eFileLock = NO_LOCK;-
2013 }else{
executed 131370 times by 424 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
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:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
pInode->nLock==0Description
TRUEevaluated 131359 times by 424 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
FALSEevaluated 677 times by 1 test
Evaluated by:
  • Self test (438)
677-131359
2028 }
executed 132036 times by 424 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
132036
2029-
2030end_unlock:
code before this statement executed 174966 times by 424 tests: end_unlock:
Executed by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
174966
2031 sqlite3_mutex_leave(pInode->pLockMutex);-
2032 if( rc==SQLITE_OK ){
rc==0Description
TRUEevaluated 174966 times by 424 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
FALSEnever evaluated
0-174966
2033 pFile->eFileLock = eFileLock;-
2034 }
executed 174966 times by 424 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
174966
2035 return rc;
executed 174966 times by 424 tests: return rc;
Executed by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • ...
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*/-
2045static 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:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
237194
2050}-
2051-
2052#if SQLITE_MAX_MMAP_SIZE>0-
2053static int unixMapfile(unixFile *pFd, i64 nByte);-
2054static 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*/-
2067static 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 ){
pFile->h>=0Description
TRUEevaluated 65945 times by 334 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
FALSEevaluated 10551 times by 1 test
Evaluated by:
  • Self test (438)
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:
  • Self test
  • Self test (10)
  • Self test (101)
  • Self test (102)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
65945
2076#if OS_VXWORKS-
2077 if( pFile->pId ){-
2078 if( pFile->ctrlFlags & UNIXFILE_DELETE ){-
2079 osUnlink(pFile->pId->zCanonicalName);-