Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/sqlite/src/src/os_unix.c

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/src/os_setup.h ('k') | third_party/sqlite/src/src/os_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** 2004 May 22 2 ** 2004 May 22
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 ** where the database is located. 64 ** where the database is located.
65 */ 65 */
66 #if !defined(SQLITE_ENABLE_LOCKING_STYLE) 66 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
67 # if defined(__APPLE__) 67 # if defined(__APPLE__)
68 # define SQLITE_ENABLE_LOCKING_STYLE 1 68 # define SQLITE_ENABLE_LOCKING_STYLE 1
69 # else 69 # else
70 # define SQLITE_ENABLE_LOCKING_STYLE 0 70 # define SQLITE_ENABLE_LOCKING_STYLE 0
71 # endif 71 # endif
72 #endif 72 #endif
73 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
74 /* 87 /*
75 ** standard include files. 88 ** standard include files.
76 */ 89 */
77 #include <sys/types.h> 90 #include <sys/types.h>
78 #include <sys/stat.h> 91 #include <sys/stat.h>
79 #include <fcntl.h> 92 #include <fcntl.h>
80 #include <unistd.h> 93 #include <unistd.h>
81 #include <time.h> 94 #include <time.h>
82 #include <sys/time.h> 95 #include <sys/time.h>
83 #include <errno.h> 96 #include <errno.h>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 */ 155 */
143 #ifndef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS 156 #ifndef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS
144 # define SQLITE_DEFAULT_PROXYDIR_PERMISSIONS 0755 157 # define SQLITE_DEFAULT_PROXYDIR_PERMISSIONS 0755
145 #endif 158 #endif
146 159
147 /* 160 /*
148 ** Maximum supported path-length. 161 ** Maximum supported path-length.
149 */ 162 */
150 #define MAX_PATHNAME 512 163 #define MAX_PATHNAME 512
151 164
165 /*
166 ** Maximum supported symbolic links
167 */
168 #define SQLITE_MAX_SYMLINKS 100
169
152 /* Always cast the getpid() return type for compatibility with 170 /* Always cast the getpid() return type for compatibility with
153 ** kernel modules in VxWorks. */ 171 ** kernel modules in VxWorks. */
154 #define osGetpid(X) (pid_t)getpid() 172 #define osGetpid(X) (pid_t)getpid()
155 173
156 /* 174 /*
157 ** Only set the lastErrno if the error code is a real error and not 175 ** Only set the lastErrno if the error code is a real error and not
158 ** a normal expected return code of SQLITE_BUSY or SQLITE_OK 176 ** a normal expected return code of SQLITE_BUSY or SQLITE_OK
159 */ 177 */
160 #define IS_LOCK_ERROR(x) ((x != SQLITE_OK) && (x != SQLITE_BUSY)) 178 #define IS_LOCK_ERROR(x) ((x != SQLITE_OK) && (x != SQLITE_BUSY))
161 179
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 #else 398 #else
381 { "pread", (sqlite3_syscall_ptr)0, 0 }, 399 { "pread", (sqlite3_syscall_ptr)0, 0 },
382 #endif 400 #endif
383 #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) 401 #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
384 402
385 #if defined(USE_PREAD64) 403 #if defined(USE_PREAD64)
386 { "pread64", (sqlite3_syscall_ptr)pread64, 0 }, 404 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
387 #else 405 #else
388 { "pread64", (sqlite3_syscall_ptr)0, 0 }, 406 { "pread64", (sqlite3_syscall_ptr)0, 0 },
389 #endif 407 #endif
390 #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) 408 #define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
391 409
392 { "write", (sqlite3_syscall_ptr)write, 0 }, 410 { "write", (sqlite3_syscall_ptr)write, 0 },
393 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) 411 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
394 412
395 #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE 413 #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
396 { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 }, 414 { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
397 #else 415 #else
398 { "pwrite", (sqlite3_syscall_ptr)0, 0 }, 416 { "pwrite", (sqlite3_syscall_ptr)0, 0 },
399 #endif 417 #endif
400 #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ 418 #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
401 aSyscall[12].pCurrent) 419 aSyscall[12].pCurrent)
402 420
403 #if defined(USE_PREAD64) 421 #if defined(USE_PREAD64)
404 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 }, 422 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
405 #else 423 #else
406 { "pwrite64", (sqlite3_syscall_ptr)0, 0 }, 424 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
407 #endif 425 #endif
408 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ 426 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
409 aSyscall[13].pCurrent) 427 aSyscall[13].pCurrent)
410 428
411 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, 429 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
412 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) 430 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
413 431
414 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE 432 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
415 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, 433 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
416 #else 434 #else
417 { "fallocate", (sqlite3_syscall_ptr)0, 0 }, 435 { "fallocate", (sqlite3_syscall_ptr)0, 0 },
418 #endif 436 #endif
419 #define osFallocate ((int(*)(int,off_t,off_t))aSyscall[15].pCurrent) 437 #define osFallocate ((int(*)(int,off_t,off_t))aSyscall[15].pCurrent)
420 438
421 { "unlink", (sqlite3_syscall_ptr)unlink, 0 }, 439 { "unlink", (sqlite3_syscall_ptr)unlink, 0 },
422 #define osUnlink ((int(*)(const char*))aSyscall[16].pCurrent) 440 #define osUnlink ((int(*)(const char*))aSyscall[16].pCurrent)
423 441
424 { "openDirectory", (sqlite3_syscall_ptr)openDirectory, 0 }, 442 { "openDirectory", (sqlite3_syscall_ptr)openDirectory, 0 },
425 #define osOpenDirectory ((int(*)(const char*,int*))aSyscall[17].pCurrent) 443 #define osOpenDirectory ((int(*)(const char*,int*))aSyscall[17].pCurrent)
426 444
427 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 }, 445 { "mkdir", (sqlite3_syscall_ptr)mkdir, 0 },
428 #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent) 446 #define osMkdir ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)
429 447
430 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, 448 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 },
431 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) 449 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent)
432 450
451 #if defined(HAVE_FCHOWN)
433 { "fchown", (sqlite3_syscall_ptr)fchown, 0 }, 452 { "fchown", (sqlite3_syscall_ptr)fchown, 0 },
453 #else
454 { "fchown", (sqlite3_syscall_ptr)0, 0 },
455 #endif
434 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) 456 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
435 457
436 { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 }, 458 { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 },
437 #define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent) 459 #define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent)
438 460
439 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 461 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
440 { "mmap", (sqlite3_syscall_ptr)mmap, 0 }, 462 { "mmap", (sqlite3_syscall_ptr)mmap, 0 },
463 #else
464 { "mmap", (sqlite3_syscall_ptr)0, 0 },
465 #endif
441 #define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent) 466 #define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent)
442 467
468 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
443 { "munmap", (sqlite3_syscall_ptr)munmap, 0 }, 469 { "munmap", (sqlite3_syscall_ptr)munmap, 0 },
470 #else
471 { "munmap", (sqlite3_syscall_ptr)0, 0 },
472 #endif
444 #define osMunmap ((void*(*)(void*,size_t))aSyscall[23].pCurrent) 473 #define osMunmap ((void*(*)(void*,size_t))aSyscall[23].pCurrent)
445 474
446 #if HAVE_MREMAP 475 #if HAVE_MREMAP && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
447 { "mremap", (sqlite3_syscall_ptr)mremap, 0 }, 476 { "mremap", (sqlite3_syscall_ptr)mremap, 0 },
448 #else 477 #else
449 { "mremap", (sqlite3_syscall_ptr)0, 0 }, 478 { "mremap", (sqlite3_syscall_ptr)0, 0 },
450 #endif 479 #endif
451 #define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[24].pCurrent) 480 #define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[24].pCurrent)
452 481
482 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
453 { "getpagesize", (sqlite3_syscall_ptr)unixGetpagesize, 0 }, 483 { "getpagesize", (sqlite3_syscall_ptr)unixGetpagesize, 0 },
484 #else
485 { "getpagesize", (sqlite3_syscall_ptr)0, 0 },
486 #endif
454 #define osGetpagesize ((int(*)(void))aSyscall[25].pCurrent) 487 #define osGetpagesize ((int(*)(void))aSyscall[25].pCurrent)
455 488
489 #if defined(HAVE_READLINK)
456 { "readlink", (sqlite3_syscall_ptr)readlink, 0 }, 490 { "readlink", (sqlite3_syscall_ptr)readlink, 0 },
491 #else
492 { "readlink", (sqlite3_syscall_ptr)0, 0 },
493 #endif
457 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent) 494 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent)
458 495
496 #if defined(HAVE_LSTAT)
497 { "lstat", (sqlite3_syscall_ptr)lstat, 0 },
498 #else
499 { "lstat", (sqlite3_syscall_ptr)0, 0 },
459 #endif 500 #endif
501 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent)
460 502
461 }; /* End of the overrideable system calls */ 503 }; /* End of the overrideable system calls */
462 504
463 505
464 /* 506 /*
465 ** On some systems, calls to fchown() will trigger a message in a security 507 ** On some systems, calls to fchown() will trigger a message in a security
466 ** log if they come from non-root processes. So avoid calling fchown() if 508 ** log if they come from non-root processes. So avoid calling fchown() if
467 ** we are not running as root. 509 ** we are not running as root.
468 */ 510 */
469 static int robustFchown(int fd, uid_t uid, gid_t gid){ 511 static int robustFchown(int fd, uid_t uid, gid_t gid){
470 #if OS_VXWORKS 512 #if defined(HAVE_FCHOWN)
513 return osGeteuid() ? 0 : osFchown(fd,uid,gid);
514 #else
471 return 0; 515 return 0;
472 #else
473 return osGeteuid() ? 0 : osFchown(fd,uid,gid);
474 #endif 516 #endif
475 } 517 }
476 518
477 /* 519 /*
478 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the 520 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
479 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the 521 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the
480 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable 522 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
481 ** system call named zName. 523 ** system call named zName.
482 */ 524 */
483 static int unixSetSystemCall( 525 static int unixSetSystemCall(
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 1054
1013 /* 1055 /*
1014 ** An instance of the following structure serves as the key used 1056 ** An instance of the following structure serves as the key used
1015 ** to locate a particular unixInodeInfo object. 1057 ** to locate a particular unixInodeInfo object.
1016 */ 1058 */
1017 struct unixFileId { 1059 struct unixFileId {
1018 dev_t dev; /* Device number */ 1060 dev_t dev; /* Device number */
1019 #if OS_VXWORKS 1061 #if OS_VXWORKS
1020 struct vxworksFileId *pId; /* Unique file ID for vxworks. */ 1062 struct vxworksFileId *pId; /* Unique file ID for vxworks. */
1021 #else 1063 #else
1022 ino_t ino; /* Inode number */ 1064 /* We are told that some versions of Android contain a bug that
1065 ** sizes ino_t at only 32-bits instead of 64-bits. (See
1066 ** https://android-review.googlesource.com/#/c/115351/3/dist/sqlite3.c)
1067 ** To work around this, always allocate 64-bits for the inode number.
1068 ** On small machines that only have 32-bit inodes, this wastes 4 bytes,
1069 ** but that should not be a big deal. */
1070 /* WAS: ino_t ino; */
1071 u64 ino; /* Inode number */
1023 #endif 1072 #endif
1024 }; 1073 };
1025 1074
1026 /* 1075 /*
1027 ** An instance of the following structure is allocated for each open 1076 ** An instance of the following structure is allocated for each open
1028 ** inode. Or, on LinuxThreads, there is one of these structures for 1077 ** inode. Or, on LinuxThreads, there is one of these structures for
1029 ** each inode opened by each thread. 1078 ** each inode opened by each thread.
1030 ** 1079 **
1031 ** A single inode can have multiple file descriptors, so each unixFile 1080 ** A single inode can have multiple file descriptors, so each unixFile
1032 ** structure contains a pointer to an instance of this object and this 1081 ** structure contains a pointer to an instance of this object and this
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 return SQLITE_IOERR; 1306 return SQLITE_IOERR;
1258 } 1307 }
1259 } 1308 }
1260 #endif 1309 #endif
1261 1310
1262 memset(&fileId, 0, sizeof(fileId)); 1311 memset(&fileId, 0, sizeof(fileId));
1263 fileId.dev = statbuf.st_dev; 1312 fileId.dev = statbuf.st_dev;
1264 #if OS_VXWORKS 1313 #if OS_VXWORKS
1265 fileId.pId = pFile->pId; 1314 fileId.pId = pFile->pId;
1266 #else 1315 #else
1267 fileId.ino = statbuf.st_ino; 1316 fileId.ino = (u64)statbuf.st_ino;
1268 #endif 1317 #endif
1269 pInode = inodeList; 1318 pInode = inodeList;
1270 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ 1319 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
1271 pInode = pInode->pNext; 1320 pInode = pInode->pNext;
1272 } 1321 }
1273 if( pInode==0 ){ 1322 if( pInode==0 ){
1274 pInode = sqlite3_malloc64( sizeof(*pInode) ); 1323 pInode = sqlite3_malloc64( sizeof(*pInode) );
1275 if( pInode==0 ){ 1324 if( pInode==0 ){
1276 return SQLITE_NOMEM; 1325 return SQLITE_NOMEM_BKPT;
1277 } 1326 }
1278 memset(pInode, 0, sizeof(*pInode)); 1327 memset(pInode, 0, sizeof(*pInode));
1279 memcpy(&pInode->fileId, &fileId, sizeof(fileId)); 1328 memcpy(&pInode->fileId, &fileId, sizeof(fileId));
1280 pInode->nRef = 1; 1329 pInode->nRef = 1;
1281 pInode->pNext = inodeList; 1330 pInode->pNext = inodeList;
1282 pInode->pPrev = 0; 1331 pInode->pPrev = 0;
1283 if( inodeList ) inodeList->pPrev = pInode; 1332 if( inodeList ) inodeList->pPrev = pInode;
1284 inodeList = pInode; 1333 inodeList = pInode;
1285 }else{ 1334 }else{
1286 pInode->nRef++; 1335 pInode->nRef++;
(...skipping 10 matching lines...) Expand all
1297 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId; 1346 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
1298 #else 1347 #else
1299 struct stat buf; 1348 struct stat buf;
1300 1349
1301 /* TODO(shess): This check doesn't work when the Chromium's WebDB code is 1350 /* TODO(shess): This check doesn't work when the Chromium's WebDB code is
1302 ** running in the sandbox. 1351 ** running in the sandbox.
1303 */ 1352 */
1304 return 0; 1353 return 0;
1305 1354
1306 return pFile->pInode!=0 && 1355 return pFile->pInode!=0 &&
1307 (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); 1356 (osStat(pFile->zPath, &buf)!=0
1357 || (u64)buf.st_ino!=pFile->pInode->fileId.ino);
1308 #endif 1358 #endif
1309 } 1359 }
1310 1360
1311 1361
1312 /* 1362 /*
1313 ** Check a unixFile that is a database. Verify the following: 1363 ** Check a unixFile that is a database. Verify the following:
1314 ** 1364 **
1315 ** (1) There is exactly one hard link on the file 1365 ** (1) There is exactly one hard link on the file
1316 ** (2) The file is not a symbolic link 1366 ** (2) The file is not a symbolic link
1317 ** (3) The file has not been renamed or unlinked 1367 ** (3) The file has not been renamed or unlinked
1318 ** 1368 **
1319 ** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right. 1369 ** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right.
1320 */ 1370 */
1321 static void verifyDbFile(unixFile *pFile){ 1371 static void verifyDbFile(unixFile *pFile){
1322 struct stat buf; 1372 struct stat buf;
1323 int rc; 1373 int rc;
1374
1375 /* These verifications occurs for the main database only */
1376 if( pFile->ctrlFlags & UNIXFILE_NOLOCK ) return;
1377
1324 rc = osFstat(pFile->h, &buf); 1378 rc = osFstat(pFile->h, &buf);
1325 if( rc!=0 ){ 1379 if( rc!=0 ){
1326 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath); 1380 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
1327 return; 1381 return;
1328 } 1382 }
1329 if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){ 1383 if( buf.st_nlink==0 ){
1330 sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath); 1384 sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
1331 return; 1385 return;
1332 } 1386 }
1333 if( buf.st_nlink>1 ){ 1387 if( buf.st_nlink>1 ){
1334 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); 1388 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
1335 return; 1389 return;
1336 } 1390 }
1337 if( fileHasMoved(pFile) ){ 1391 if( fileHasMoved(pFile) ){
1338 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); 1392 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
1339 return; 1393 return;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 ** PENDING -> EXCLUSIVE 1509 ** PENDING -> EXCLUSIVE
1456 ** 1510 **
1457 ** This routine will only increase a lock. Use the sqlite3OsUnlock() 1511 ** This routine will only increase a lock. Use the sqlite3OsUnlock()
1458 ** routine to lower a locking level. 1512 ** routine to lower a locking level.
1459 */ 1513 */
1460 static int unixLock(sqlite3_file *id, int eFileLock){ 1514 static int unixLock(sqlite3_file *id, int eFileLock){
1461 /* The following describes the implementation of the various locks and 1515 /* The following describes the implementation of the various locks and
1462 ** lock transitions in terms of the POSIX advisory shared and exclusive 1516 ** lock transitions in terms of the POSIX advisory shared and exclusive
1463 ** lock primitives (called read-locks and write-locks below, to avoid 1517 ** lock primitives (called read-locks and write-locks below, to avoid
1464 ** confusion with SQLite lock names). The algorithms are complicated 1518 ** confusion with SQLite lock names). The algorithms are complicated
1465 ** slightly in order to be compatible with windows systems simultaneously 1519 ** slightly in order to be compatible with Windows95 systems simultaneously
1466 ** accessing the same database file, in case that is ever required. 1520 ** accessing the same database file, in case that is ever required.
1467 ** 1521 **
1468 ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved 1522 ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved
1469 ** byte', each single bytes at well known offsets, and the 'shared byte 1523 ** byte', each single bytes at well known offsets, and the 'shared byte
1470 ** range', a range of 510 bytes at a well known offset. 1524 ** range', a range of 510 bytes at a well known offset.
1471 ** 1525 **
1472 ** To obtain a SHARED lock, a read-lock is obtained on the 'pending 1526 ** To obtain a SHARED lock, a read-lock is obtained on the 'pending
1473 ** byte'. If this is successful, a random byte from the 'shared byte 1527 ** byte'. If this is successful, 'shared byte range' is read-locked
1474 ** range' is read-locked and the lock on the 'pending byte' released. 1528 ** and the lock on the 'pending byte' released. (Legacy note: When
1529 ** SQLite was first developed, Windows95 systems were still very common,
1530 ** and Widnows95 lacks a shared-lock capability. So on Windows95, a
1531 ** single randomly selected by from the 'shared byte range' is locked.
1532 ** Windows95 is now pretty much extinct, but this work-around for the
1533 ** lack of shared-locks on Windows95 lives on, for backwards
1534 ** compatibility.)
1475 ** 1535 **
1476 ** A process may only obtain a RESERVED lock after it has a SHARED lock. 1536 ** A process may only obtain a RESERVED lock after it has a SHARED lock.
1477 ** A RESERVED lock is implemented by grabbing a write-lock on the 1537 ** A RESERVED lock is implemented by grabbing a write-lock on the
1478 ** 'reserved byte'. 1538 ** 'reserved byte'.
1479 ** 1539 **
1480 ** A process may only obtain a PENDING lock after it has obtained a 1540 ** A process may only obtain a PENDING lock after it has obtained a
1481 ** SHARED lock. A PENDING lock is implemented by obtaining a write-lock 1541 ** SHARED lock. A PENDING lock is implemented by obtaining a write-lock
1482 ** on the 'pending byte'. This ensures that no new SHARED locks can be 1542 ** on the 'pending byte'. This ensures that no new SHARED locks can be
1483 ** obtained, but existing SHARED locks are allowed to persist. A process 1543 ** obtained, but existing SHARED locks are allowed to persist. A process
1484 ** does not have to obtain a RESERVED lock on the way to a PENDING lock. 1544 ** does not have to obtain a RESERVED lock on the way to a PENDING lock.
1485 ** This property is used by the algorithm for rolling back a journal file 1545 ** This property is used by the algorithm for rolling back a journal file
1486 ** after a crash. 1546 ** after a crash.
1487 ** 1547 **
1488 ** An EXCLUSIVE lock, obtained after a PENDING lock is held, is 1548 ** An EXCLUSIVE lock, obtained after a PENDING lock is held, is
1489 ** implemented by obtaining a write-lock on the entire 'shared byte 1549 ** implemented by obtaining a write-lock on the entire 'shared byte
1490 ** range'. Since all other locks require a read-lock on one of the bytes 1550 ** range'. Since all other locks require a read-lock on one of the bytes
1491 ** within this range, this ensures that no other locks are held on the 1551 ** within this range, this ensures that no other locks are held on the
1492 ** database. 1552 ** database.
1493 **
1494 ** The reason a single byte cannot be used instead of the 'shared byte
1495 ** range' is that some versions of windows do not support read-locks. By
1496 ** locking a random byte from a range, concurrent SHARED locks may exist
1497 ** even if the locking primitive used is always a write-lock.
1498 */ 1553 */
1499 int rc = SQLITE_OK; 1554 int rc = SQLITE_OK;
1500 unixFile *pFile = (unixFile*)id; 1555 unixFile *pFile = (unixFile*)id;
1501 unixInodeInfo *pInode; 1556 unixInodeInfo *pInode;
1502 struct flock lock; 1557 struct flock lock;
1503 int tErrno = 0; 1558 int tErrno = 0;
1504 1559
1505 assert( pFile ); 1560 assert( pFile );
1506 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, 1561 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
1507 azFileLock(eFileLock), azFileLock(pFile->eFileLock), 1562 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
(...skipping 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after
3134 3189
3135 /* If this is a database file (not a journal, master-journal or temp 3190 /* If this is a database file (not a journal, master-journal or temp
3136 ** file), the bytes in the locking range should never be read or written. */ 3191 ** file), the bytes in the locking range should never be read or written. */
3137 #if 0 3192 #if 0
3138 assert( pFile->pUnused==0 3193 assert( pFile->pUnused==0
3139 || offset>=PENDING_BYTE+512 3194 || offset>=PENDING_BYTE+512
3140 || offset+amt<=PENDING_BYTE 3195 || offset+amt<=PENDING_BYTE
3141 ); 3196 );
3142 #endif 3197 #endif
3143 3198
3144 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 3199 #if SQLITE_MAX_MMAP_SIZE>0
3145 /* Deal with as much of this read request as possible by transfering 3200 /* Deal with as much of this read request as possible by transfering
3146 ** data from the memory mapping using memcpy(). */ 3201 ** data from the memory mapping using memcpy(). */
3147 if( offset<pFile->mmapSize ){ 3202 if( offset<pFile->mmapSize ){
3148 if( offset+amt <= pFile->mmapSize ){ 3203 if( offset+amt <= pFile->mmapSize ){
3149 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); 3204 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
3150 return SQLITE_OK; 3205 return SQLITE_OK;
3151 }else{ 3206 }else{
3152 int nCopy = pFile->mmapSize - offset; 3207 int nCopy = pFile->mmapSize - offset;
3153 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy); 3208 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
3154 pBuf = &((u8 *)pBuf)[nCopy]; 3209 pBuf = &((u8 *)pBuf)[nCopy];
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after
4192 static int unixOpenSharedMemory(unixFile *pDbFd){ 4247 static int unixOpenSharedMemory(unixFile *pDbFd){
4193 struct unixShm *p = 0; /* The connection to be opened */ 4248 struct unixShm *p = 0; /* The connection to be opened */
4194 struct unixShmNode *pShmNode; /* The underlying mmapped file */ 4249 struct unixShmNode *pShmNode; /* The underlying mmapped file */
4195 int rc; /* Result code */ 4250 int rc; /* Result code */
4196 unixInodeInfo *pInode; /* The inode of fd */ 4251 unixInodeInfo *pInode; /* The inode of fd */
4197 char *zShmFilename; /* Name of the file used for SHM */ 4252 char *zShmFilename; /* Name of the file used for SHM */
4198 int nShmFilename; /* Size of the SHM filename in bytes */ 4253 int nShmFilename; /* Size of the SHM filename in bytes */
4199 4254
4200 /* Allocate space for the new unixShm object. */ 4255 /* Allocate space for the new unixShm object. */
4201 p = sqlite3_malloc64( sizeof(*p) ); 4256 p = sqlite3_malloc64( sizeof(*p) );
4202 if( p==0 ) return SQLITE_NOMEM; 4257 if( p==0 ) return SQLITE_NOMEM_BKPT;
4203 memset(p, 0, sizeof(*p)); 4258 memset(p, 0, sizeof(*p));
4204 assert( pDbFd->pShm==0 ); 4259 assert( pDbFd->pShm==0 );
4205 4260
4206 /* Check to see if a unixShmNode object already exists. Reuse an existing 4261 /* Check to see if a unixShmNode object already exists. Reuse an existing
4207 ** one if present. Create a new one if necessary. 4262 ** one if present. Create a new one if necessary.
4208 */ 4263 */
4209 unixEnterMutex(); 4264 unixEnterMutex();
4210 pInode = pDbFd->pInode; 4265 pInode = pDbFd->pInode;
4211 pShmNode = pInode->pShmNode; 4266 pShmNode = pInode->pShmNode;
4212 if( pShmNode==0 ){ 4267 if( pShmNode==0 ){
(...skipping 11 matching lines...) Expand all
4224 goto shm_open_err; 4279 goto shm_open_err;
4225 } 4280 }
4226 4281
4227 #ifdef SQLITE_SHM_DIRECTORY 4282 #ifdef SQLITE_SHM_DIRECTORY
4228 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; 4283 nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31;
4229 #else 4284 #else
4230 nShmFilename = 6 + (int)strlen(zBasePath); 4285 nShmFilename = 6 + (int)strlen(zBasePath);
4231 #endif 4286 #endif
4232 pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename ); 4287 pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
4233 if( pShmNode==0 ){ 4288 if( pShmNode==0 ){
4234 rc = SQLITE_NOMEM; 4289 rc = SQLITE_NOMEM_BKPT;
4235 goto shm_open_err; 4290 goto shm_open_err;
4236 } 4291 }
4237 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename); 4292 memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
4238 zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1]; 4293 zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
4239 #ifdef SQLITE_SHM_DIRECTORY 4294 #ifdef SQLITE_SHM_DIRECTORY
4240 sqlite3_snprintf(nShmFilename, zShmFilename, 4295 sqlite3_snprintf(nShmFilename, zShmFilename,
4241 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x", 4296 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
4242 (u32)sStat.st_ino, (u32)sStat.st_dev); 4297 (u32)sStat.st_ino, (u32)sStat.st_dev);
4243 #else 4298 #else
4244 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath); 4299 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath);
4245 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename); 4300 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
4246 #endif 4301 #endif
4247 pShmNode->h = -1; 4302 pShmNode->h = -1;
4248 pDbFd->pInode->pShmNode = pShmNode; 4303 pDbFd->pInode->pShmNode = pShmNode;
4249 pShmNode->pInode = pDbFd->pInode; 4304 pShmNode->pInode = pDbFd->pInode;
4250 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); 4305 if( sqlite3GlobalConfig.bCoreMutex ){
4251 if( pShmNode->mutex==0 ){ 4306 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
4252 rc = SQLITE_NOMEM; 4307 if( pShmNode->mutex==0 ){
4253 goto shm_open_err; 4308 rc = SQLITE_NOMEM_BKPT;
4309 goto shm_open_err;
4310 }
4254 } 4311 }
4255 4312
4256 if( pInode->bProcessLock==0 ){ 4313 if( pInode->bProcessLock==0 ){
4257 int openFlags = O_RDWR | O_CREAT; 4314 int openFlags = O_RDWR | O_CREAT;
4258 if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ 4315 if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
4259 openFlags = O_RDONLY; 4316 openFlags = O_RDONLY;
4260 pShmNode->isReadonly = 1; 4317 pShmNode->isReadonly = 1;
4261 } 4318 }
4262 pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777)); 4319 pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777));
4263 if( pShmNode->h<0 ){ 4320 if( pShmNode->h<0 ){
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
4415 } 4472 }
4416 } 4473 }
4417 } 4474 }
4418 } 4475 }
4419 4476
4420 /* Map the requested memory region into this processes address space. */ 4477 /* Map the requested memory region into this processes address space. */
4421 apNew = (char **)sqlite3_realloc( 4478 apNew = (char **)sqlite3_realloc(
4422 pShmNode->apRegion, nReqRegion*sizeof(char *) 4479 pShmNode->apRegion, nReqRegion*sizeof(char *)
4423 ); 4480 );
4424 if( !apNew ){ 4481 if( !apNew ){
4425 rc = SQLITE_IOERR_NOMEM; 4482 rc = SQLITE_IOERR_NOMEM_BKPT;
4426 goto shmpage_out; 4483 goto shmpage_out;
4427 } 4484 }
4428 pShmNode->apRegion = apNew; 4485 pShmNode->apRegion = apNew;
4429 while( pShmNode->nRegion<nReqRegion ){ 4486 while( pShmNode->nRegion<nReqRegion ){
4430 int nMap = szRegion*nShmPerMap; 4487 int nMap = szRegion*nShmPerMap;
4431 int i; 4488 int i;
4432 void *pMem; 4489 void *pMem;
4433 if( pShmNode->h>=0 ){ 4490 if( pShmNode->h>=0 ){
4434 pMem = osMmap(0, nMap, 4491 pMem = osMmap(0, nMap,
4435 pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE, 4492 pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE,
4436 MAP_SHARED, pShmNode->h, szRegion*(i64)pShmNode->nRegion 4493 MAP_SHARED, pShmNode->h, szRegion*(i64)pShmNode->nRegion
4437 ); 4494 );
4438 if( pMem==MAP_FAILED ){ 4495 if( pMem==MAP_FAILED ){
4439 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); 4496 rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename);
4440 goto shmpage_out; 4497 goto shmpage_out;
4441 } 4498 }
4442 }else{ 4499 }else{
4443 pMem = sqlite3_malloc64(szRegion); 4500 pMem = sqlite3_malloc64(szRegion);
4444 if( pMem==0 ){ 4501 if( pMem==0 ){
4445 rc = SQLITE_NOMEM; 4502 rc = SQLITE_NOMEM_BKPT;
4446 goto shmpage_out; 4503 goto shmpage_out;
4447 } 4504 }
4448 memset(pMem, 0, szRegion); 4505 memset(pMem, 0, szRegion);
4449 } 4506 }
4450 4507
4451 for(i=0; i<nShmPerMap; i++){ 4508 for(i=0; i<nShmPerMap; i++){
4452 pShmNode->apRegion[pShmNode->nRegion+i] = &((char*)pMem)[szRegion*i]; 4509 pShmNode->apRegion[pShmNode->nRegion+i] = &((char*)pMem)[szRegion*i];
4453 } 4510 }
4454 pShmNode->nRegion += nShmPerMap; 4511 pShmNode->nRegion += nShmPerMap;
4455 } 4512 }
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
5213 pNew->ctrlFlags |= UNIXFILE_PSOW; 5270 pNew->ctrlFlags |= UNIXFILE_PSOW;
5214 } 5271 }
5215 if( strcmp(pVfs->zName,"unix-excl")==0 ){ 5272 if( strcmp(pVfs->zName,"unix-excl")==0 ){
5216 pNew->ctrlFlags |= UNIXFILE_EXCL; 5273 pNew->ctrlFlags |= UNIXFILE_EXCL;
5217 } 5274 }
5218 5275
5219 #if OS_VXWORKS 5276 #if OS_VXWORKS
5220 pNew->pId = vxworksFindFileId(zFilename); 5277 pNew->pId = vxworksFindFileId(zFilename);
5221 if( pNew->pId==0 ){ 5278 if( pNew->pId==0 ){
5222 ctrlFlags |= UNIXFILE_NOLOCK; 5279 ctrlFlags |= UNIXFILE_NOLOCK;
5223 rc = SQLITE_NOMEM; 5280 rc = SQLITE_NOMEM_BKPT;
5224 } 5281 }
5225 #endif 5282 #endif
5226 5283
5227 if( ctrlFlags & UNIXFILE_NOLOCK ){ 5284 if( ctrlFlags & UNIXFILE_NOLOCK ){
5228 pLockingStyle = &nolockIoMethods; 5285 pLockingStyle = &nolockIoMethods;
5229 }else{ 5286 }else{
5230 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew); 5287 pLockingStyle = (**(finder_type*)pVfs->pAppData)(zFilename, pNew);
5231 #if SQLITE_ENABLE_LOCKING_STYLE 5288 #if SQLITE_ENABLE_LOCKING_STYLE
5232 /* Cache zFilename in the locking context (AFP and dotlock override) for 5289 /* Cache zFilename in the locking context (AFP and dotlock override) for
5233 ** proxyLock activation is possible (remote proxy is based on db name) 5290 ** proxyLock activation is possible (remote proxy is based on db name)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5269 } 5326 }
5270 5327
5271 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) 5328 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
5272 else if( pLockingStyle == &afpIoMethods ){ 5329 else if( pLockingStyle == &afpIoMethods ){
5273 /* AFP locking uses the file path so it needs to be included in 5330 /* AFP locking uses the file path so it needs to be included in
5274 ** the afpLockingContext. 5331 ** the afpLockingContext.
5275 */ 5332 */
5276 afpLockingContext *pCtx; 5333 afpLockingContext *pCtx;
5277 pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) ); 5334 pNew->lockingContext = pCtx = sqlite3_malloc64( sizeof(*pCtx) );
5278 if( pCtx==0 ){ 5335 if( pCtx==0 ){
5279 rc = SQLITE_NOMEM; 5336 rc = SQLITE_NOMEM_BKPT;
5280 }else{ 5337 }else{
5281 /* NB: zFilename exists and remains valid until the file is closed 5338 /* NB: zFilename exists and remains valid until the file is closed
5282 ** according to requirement F11141. So we do not need to make a 5339 ** according to requirement F11141. So we do not need to make a
5283 ** copy of the filename. */ 5340 ** copy of the filename. */
5284 pCtx->dbPath = zFilename; 5341 pCtx->dbPath = zFilename;
5285 pCtx->reserved = 0; 5342 pCtx->reserved = 0;
5286 srandomdev(); 5343 srandomdev();
5287 unixEnterMutex(); 5344 unixEnterMutex();
5288 rc = findInodeInfo(pNew, &pNew->pInode); 5345 rc = findInodeInfo(pNew, &pNew->pInode);
5289 if( rc!=SQLITE_OK ){ 5346 if( rc!=SQLITE_OK ){
5290 sqlite3_free(pNew->lockingContext); 5347 sqlite3_free(pNew->lockingContext);
5291 robust_close(pNew, h, __LINE__); 5348 robust_close(pNew, h, __LINE__);
5292 h = -1; 5349 h = -1;
5293 } 5350 }
5294 unixLeaveMutex(); 5351 unixLeaveMutex();
5295 } 5352 }
5296 } 5353 }
5297 #endif 5354 #endif
5298 5355
5299 else if( pLockingStyle == &dotlockIoMethods ){ 5356 else if( pLockingStyle == &dotlockIoMethods ){
5300 /* Dotfile locking uses the file path so it needs to be included in 5357 /* Dotfile locking uses the file path so it needs to be included in
5301 ** the dotlockLockingContext 5358 ** the dotlockLockingContext
5302 */ 5359 */
5303 char *zLockFile; 5360 char *zLockFile;
5304 int nFilename; 5361 int nFilename;
5305 assert( zFilename!=0 ); 5362 assert( zFilename!=0 );
5306 nFilename = (int)strlen(zFilename) + 6; 5363 nFilename = (int)strlen(zFilename) + 6;
5307 zLockFile = (char *)sqlite3_malloc64(nFilename); 5364 zLockFile = (char *)sqlite3_malloc64(nFilename);
5308 if( zLockFile==0 ){ 5365 if( zLockFile==0 ){
5309 rc = SQLITE_NOMEM; 5366 rc = SQLITE_NOMEM_BKPT;
5310 }else{ 5367 }else{
5311 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename); 5368 sqlite3_snprintf(nFilename, zLockFile, "%s" DOTLOCK_SUFFIX, zFilename);
5312 } 5369 }
5313 pNew->lockingContext = zLockFile; 5370 pNew->lockingContext = zLockFile;
5314 } 5371 }
5315 5372
5316 #if OS_VXWORKS 5373 #if OS_VXWORKS
5317 else if( pLockingStyle == &semIoMethods ){ 5374 else if( pLockingStyle == &semIoMethods ){
5318 /* Named semaphore locking uses the file path so it needs to be 5375 /* Named semaphore locking uses the file path so it needs to be
5319 ** included in the semLockingContext 5376 ** included in the semLockingContext
5320 */ 5377 */
5321 unixEnterMutex(); 5378 unixEnterMutex();
5322 rc = findInodeInfo(pNew, &pNew->pInode); 5379 rc = findInodeInfo(pNew, &pNew->pInode);
5323 if( (rc==SQLITE_OK) && (pNew->pInode->pSem==NULL) ){ 5380 if( (rc==SQLITE_OK) && (pNew->pInode->pSem==NULL) ){
5324 char *zSemName = pNew->pInode->aSemName; 5381 char *zSemName = pNew->pInode->aSemName;
5325 int n; 5382 int n;
5326 sqlite3_snprintf(MAX_PATHNAME, zSemName, "/%s.sem", 5383 sqlite3_snprintf(MAX_PATHNAME, zSemName, "/%s.sem",
5327 pNew->pId->zCanonicalName); 5384 pNew->pId->zCanonicalName);
5328 for( n=1; zSemName[n]; n++ ) 5385 for( n=1; zSemName[n]; n++ )
5329 if( zSemName[n]=='/' ) zSemName[n] = '_'; 5386 if( zSemName[n]=='/' ) zSemName[n] = '_';
5330 pNew->pInode->pSem = sem_open(zSemName, O_CREAT, 0666, 1); 5387 pNew->pInode->pSem = sem_open(zSemName, O_CREAT, 0666, 1);
5331 if( pNew->pInode->pSem == SEM_FAILED ){ 5388 if( pNew->pInode->pSem == SEM_FAILED ){
5332 rc = SQLITE_NOMEM; 5389 rc = SQLITE_NOMEM_BKPT;
5333 pNew->pInode->aSemName[0] = '\0'; 5390 pNew->pInode->aSemName[0] = '\0';
5334 } 5391 }
5335 } 5392 }
5336 unixLeaveMutex(); 5393 unixLeaveMutex();
5337 } 5394 }
5338 #endif 5395 #endif
5339 5396
5340 storeLastErrno(pNew, 0); 5397 storeLastErrno(pNew, 0);
5341 #if OS_VXWORKS 5398 #if OS_VXWORKS
5342 if( rc!=SQLITE_OK ){ 5399 if( rc!=SQLITE_OK ){
(...skipping 19 matching lines...) Expand all
5362 */ 5419 */
5363 static const char *unixTempFileDir(void){ 5420 static const char *unixTempFileDir(void){
5364 static const char *azDirs[] = { 5421 static const char *azDirs[] = {
5365 0, 5422 0,
5366 0, 5423 0,
5367 "/var/tmp", 5424 "/var/tmp",
5368 "/usr/tmp", 5425 "/usr/tmp",
5369 "/tmp", 5426 "/tmp",
5370 "." 5427 "."
5371 }; 5428 };
5372 unsigned int i; 5429 unsigned int i = 0;
5373 struct stat buf; 5430 struct stat buf;
5374 const char *zDir = sqlite3_temp_directory; 5431 const char *zDir = sqlite3_temp_directory;
5375 5432
5376 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR"); 5433 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
5377 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); 5434 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
5378 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){ 5435 while(1){
5379 if( zDir==0 ) continue; 5436 if( zDir!=0
5380 if( osStat(zDir, &buf) ) continue; 5437 && osStat(zDir, &buf)==0
5381 if( !S_ISDIR(buf.st_mode) ) continue; 5438 && S_ISDIR(buf.st_mode)
5382 if( osAccess(zDir, 07) ) continue; 5439 && osAccess(zDir, 03)==0
5383 break; 5440 ){
5441 return zDir;
5442 }
5443 if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
5444 zDir = azDirs[i++];
5384 } 5445 }
5385 return zDir; 5446 return 0;
5386 } 5447 }
5387 5448
5388 /* 5449 /*
5389 ** Create a temporary file name in zBuf. zBuf must be allocated 5450 ** Create a temporary file name in zBuf. zBuf must be allocated
5390 ** by the calling process and must be big enough to hold at least 5451 ** by the calling process and must be big enough to hold at least
5391 ** pVfs->mxPathname bytes. 5452 ** pVfs->mxPathname bytes.
5392 */ 5453 */
5393 static int unixGetTempname(int nBuf, char *zBuf){ 5454 static int unixGetTempname(int nBuf, char *zBuf){
5394 const char *zDir; 5455 const char *zDir;
5395 int iLimit = 0; 5456 int iLimit = 0;
5396 5457
5397 /* It's odd to simulate an io-error here, but really this is just 5458 /* It's odd to simulate an io-error here, but really this is just
5398 ** using the io-error infrastructure to test that SQLite handles this 5459 ** using the io-error infrastructure to test that SQLite handles this
5399 ** function failing. 5460 ** function failing.
5400 */ 5461 */
5462 zBuf[0] = 0;
5401 SimulateIOError( return SQLITE_IOERR ); 5463 SimulateIOError( return SQLITE_IOERR );
5402 5464
5403 zDir = unixTempFileDir(); 5465 zDir = unixTempFileDir();
5466 if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
5404 do{ 5467 do{
5405 u64 r; 5468 u64 r;
5406 sqlite3_randomness(sizeof(r), &r); 5469 sqlite3_randomness(sizeof(r), &r);
5407 assert( nBuf>2 ); 5470 assert( nBuf>2 );
5408 zBuf[nBuf-2] = 0; 5471 zBuf[nBuf-2] = 0;
5409 sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c", 5472 sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
5410 zDir, r, 0); 5473 zDir, r, 0);
5411 if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR; 5474 if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR;
5412 }while( osAccess(zBuf,0)==0 ); 5475 }while( osAccess(zBuf,0)==0 );
5413 return SQLITE_OK; 5476 return SQLITE_OK;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5456 ** descriptor on the same path, fail, and return an error to SQLite. 5519 ** descriptor on the same path, fail, and return an error to SQLite.
5457 ** 5520 **
5458 ** Even if a subsequent open() call does succeed, the consequences of 5521 ** Even if a subsequent open() call does succeed, the consequences of
5459 ** not searching for a reusable file descriptor are not dire. */ 5522 ** not searching for a reusable file descriptor are not dire. */
5460 if( 0==osStat(zPath, &sStat) ){ 5523 if( 0==osStat(zPath, &sStat) ){
5461 unixInodeInfo *pInode; 5524 unixInodeInfo *pInode;
5462 5525
5463 unixEnterMutex(); 5526 unixEnterMutex();
5464 pInode = inodeList; 5527 pInode = inodeList;
5465 while( pInode && (pInode->fileId.dev!=sStat.st_dev 5528 while( pInode && (pInode->fileId.dev!=sStat.st_dev
5466 || pInode->fileId.ino!=sStat.st_ino) ){ 5529 || pInode->fileId.ino!=(u64)sStat.st_ino) ){
5467 pInode = pInode->pNext; 5530 pInode = pInode->pNext;
5468 } 5531 }
5469 if( pInode ){ 5532 if( pInode ){
5470 UnixUnusedFd **pp; 5533 UnixUnusedFd **pp;
5471 for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext)); 5534 for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext));
5472 pUnused = *pp; 5535 pUnused = *pp;
5473 if( pUnused ){ 5536 if( pUnused ){
5474 *pp = pUnused->pNext; 5537 *pp = pUnused->pNext;
5475 } 5538 }
5476 } 5539 }
5477 unixLeaveMutex(); 5540 unixLeaveMutex();
5478 } 5541 }
5479 #endif /* if !OS_VXWORKS */ 5542 #endif /* if !OS_VXWORKS */
5480 return pUnused; 5543 return pUnused;
5481 } 5544 }
5482 5545
5483 /* 5546 /*
5547 ** Find the mode, uid and gid of file zFile.
5548 */
5549 static int getFileMode(
5550 const char *zFile, /* File name */
5551 mode_t *pMode, /* OUT: Permissions of zFile */
5552 uid_t *pUid, /* OUT: uid of zFile. */
5553 gid_t *pGid /* OUT: gid of zFile. */
5554 ){
5555 struct stat sStat; /* Output of stat() on database file */
5556 int rc = SQLITE_OK;
5557 if( 0==osStat(zFile, &sStat) ){
5558 *pMode = sStat.st_mode & 0777;
5559 *pUid = sStat.st_uid;
5560 *pGid = sStat.st_gid;
5561 }else{
5562 rc = SQLITE_IOERR_FSTAT;
5563 }
5564 return rc;
5565 }
5566
5567 /*
5484 ** This function is called by unixOpen() to determine the unix permissions 5568 ** This function is called by unixOpen() to determine the unix permissions
5485 ** to create new files with. If no error occurs, then SQLITE_OK is returned 5569 ** to create new files with. If no error occurs, then SQLITE_OK is returned
5486 ** and a value suitable for passing as the third argument to open(2) is 5570 ** and a value suitable for passing as the third argument to open(2) is
5487 ** written to *pMode. If an IO error occurs, an SQLite error code is 5571 ** written to *pMode. If an IO error occurs, an SQLite error code is
5488 ** returned and the value of *pMode is not modified. 5572 ** returned and the value of *pMode is not modified.
5489 ** 5573 **
5490 ** In most cases, this routine sets *pMode to 0, which will become 5574 ** In most cases, this routine sets *pMode to 0, which will become
5491 ** an indication to robust_open() to create the file using 5575 ** an indication to robust_open() to create the file using
5492 ** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask. 5576 ** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask.
5493 ** But if the file being opened is a WAL or regular journal file, then 5577 ** But if the file being opened is a WAL or regular journal file, then
(...skipping 14 matching lines...) Expand all
5508 uid_t *pUid, /* OUT: uid to set on the file */ 5592 uid_t *pUid, /* OUT: uid to set on the file */
5509 gid_t *pGid /* OUT: gid to set on the file */ 5593 gid_t *pGid /* OUT: gid to set on the file */
5510 ){ 5594 ){
5511 int rc = SQLITE_OK; /* Return Code */ 5595 int rc = SQLITE_OK; /* Return Code */
5512 *pMode = 0; 5596 *pMode = 0;
5513 *pUid = 0; 5597 *pUid = 0;
5514 *pGid = 0; 5598 *pGid = 0;
5515 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ 5599 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
5516 char zDb[MAX_PATHNAME+1]; /* Database file path */ 5600 char zDb[MAX_PATHNAME+1]; /* Database file path */
5517 int nDb; /* Number of valid bytes in zDb */ 5601 int nDb; /* Number of valid bytes in zDb */
5518 struct stat sStat; /* Output of stat() on database file */
5519 5602
5520 /* zPath is a path to a WAL or journal file. The following block derives 5603 /* zPath is a path to a WAL or journal file. The following block derives
5521 ** the path to the associated database file from zPath. This block handles 5604 ** the path to the associated database file from zPath. This block handles
5522 ** the following naming conventions: 5605 ** the following naming conventions:
5523 ** 5606 **
5524 ** "<path to db>-journal" 5607 ** "<path to db>-journal"
5525 ** "<path to db>-wal" 5608 ** "<path to db>-wal"
5526 ** "<path to db>-journalNN" 5609 ** "<path to db>-journalNN"
5527 ** "<path to db>-walNN" 5610 ** "<path to db>-walNN"
5528 ** 5611 **
(...skipping 10 matching lines...) Expand all
5539 #else 5622 #else
5540 /* If 8+3 names are possible, then the journal file might not contain 5623 /* If 8+3 names are possible, then the journal file might not contain
5541 ** a '-' character. So check for that case and return early. */ 5624 ** a '-' character. So check for that case and return early. */
5542 if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK; 5625 if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
5543 #endif 5626 #endif
5544 nDb--; 5627 nDb--;
5545 } 5628 }
5546 memcpy(zDb, zPath, nDb); 5629 memcpy(zDb, zPath, nDb);
5547 zDb[nDb] = '\0'; 5630 zDb[nDb] = '\0';
5548 5631
5549 if( 0==osStat(zDb, &sStat) ){ 5632 rc = getFileMode(zDb, pMode, pUid, pGid);
5550 *pMode = sStat.st_mode & 0777;
5551 *pUid = sStat.st_uid;
5552 *pGid = sStat.st_gid;
5553 }else{
5554 rc = SQLITE_IOERR_FSTAT;
5555 }
5556 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ 5633 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
5557 *pMode = 0600; 5634 *pMode = 0600;
5635 }else if( flags & SQLITE_OPEN_URI ){
5636 /* If this is a main database file and the file was opened using a URI
5637 ** filename, check for the "modeof" parameter. If present, interpret
5638 ** its value as a filename and try to copy the mode, uid and gid from
5639 ** that file. */
5640 const char *z = sqlite3_uri_parameter(zPath, "modeof");
5641 if( z ){
5642 rc = getFileMode(z, pMode, pUid, pGid);
5643 }
5558 } 5644 }
5559 return rc; 5645 return rc;
5560 } 5646 }
5561 5647
5562 /* 5648 /*
5563 ** Initialize |unixFile| internals of |file| on behalf of chromiumOpen() in 5649 ** Initialize |unixFile| internals of |file| on behalf of chromiumOpen() in
5564 ** WebDatabase SQLiteFileSystemPosix.cpp. Function is a subset of unixOpen(), 5650 ** WebDatabase SQLiteFileSystemPosix.cpp. Function is a subset of unixOpen(),
5565 ** each duplicated piece is marked by "Duplicated in" comment in unixOpen(). 5651 ** each duplicated piece is marked by "Duplicated in" comment in unixOpen().
5566 */ 5652 */
5567 CHROMIUM_SQLITE_API 5653 CHROMIUM_SQLITE_API
5568 int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs, 5654 int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs,
5569 int fd, 5655 int fd,
5570 sqlite3_file* pFile, 5656 sqlite3_file* pFile,
5571 const char* zPath, 5657 const char* zPath,
5572 int noLock, 5658 int noLock,
5573 int flags) { 5659 int flags) {
5574 unixFile *p = (unixFile *)pFile; 5660 unixFile *p = (unixFile *)pFile;
5575 const int eType = flags&0xFFFFFF00; /* Type of file to open */ 5661 const int eType = flags&0xFFFFFF00; /* Type of file to open */
5576 const int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0); 5662 const int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0);
5577 int rc; 5663 int rc;
5578 5664
5579 memset(p, 0, sizeof(unixFile)); 5665 memset(p, 0, sizeof(unixFile));
5580 5666
5581 /* osStat() will not work in the sandbox, so findReusableFd() will always 5667 /* osStat() will not work in the sandbox, so findReusableFd() will always
5582 ** fail, so directly include the failure-case setup then initialize pUnused. 5668 ** fail, so directly include the failure-case setup then initialize pUnused.
5583 */ 5669 */
5584 if( eType==SQLITE_OPEN_MAIN_DB ){ 5670 if( eType==SQLITE_OPEN_MAIN_DB ){
5585 p->pUnused = sqlite3_malloc(sizeof(*p->pUnused)); 5671 p->pUnused = sqlite3_malloc(sizeof(*p->pUnused));
5586 if (!p->pUnused) { 5672 if (!p->pUnused) {
5587 return SQLITE_NOMEM; 5673 return SQLITE_NOMEM_BKPT;
5588 } 5674 }
5589 p->pUnused->fd = fd; 5675 p->pUnused->fd = fd;
5590 p->pUnused->flags = flags; 5676 p->pUnused->flags = flags;
5591 } 5677 }
5592 5678
5593 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); 5679 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
5594 if( rc!=SQLITE_OK ){ 5680 if( rc!=SQLITE_OK ){
5595 sqlite3_free(p->pUnused); 5681 sqlite3_free(p->pUnused);
5596 } 5682 }
5597 return rc; 5683 return rc;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5703 5789
5704 if( eType==SQLITE_OPEN_MAIN_DB ){ 5790 if( eType==SQLITE_OPEN_MAIN_DB ){
5705 UnixUnusedFd *pUnused; 5791 UnixUnusedFd *pUnused;
5706 pUnused = findReusableFd(zName, flags); 5792 pUnused = findReusableFd(zName, flags);
5707 if( pUnused ){ 5793 if( pUnused ){
5708 fd = pUnused->fd; 5794 fd = pUnused->fd;
5709 }else{ 5795 }else{
5710 /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ 5796 /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */
5711 pUnused = sqlite3_malloc64(sizeof(*pUnused)); 5797 pUnused = sqlite3_malloc64(sizeof(*pUnused));
5712 if( !pUnused ){ 5798 if( !pUnused ){
5713 return SQLITE_NOMEM; 5799 return SQLITE_NOMEM_BKPT;
5714 } 5800 }
5715 } 5801 }
5716 p->pUnused = pUnused; 5802 p->pUnused = pUnused;
5717 5803
5718 /* Database filenames are double-zero terminated if they are not 5804 /* Database filenames are double-zero terminated if they are not
5719 ** URIs with parameters. Hence, they can always be passed into 5805 ** URIs with parameters. Hence, they can always be passed into
5720 ** sqlite3_uri_parameter(). */ 5806 ** sqlite3_uri_parameter(). */
5721 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); 5807 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
5722 5808
5723 }else if( !zName ){ 5809 }else if( !zName ){
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
5790 p->pUnused->flags = flags; 5876 p->pUnused->flags = flags;
5791 } 5877 }
5792 5878
5793 if( isDelete ){ 5879 if( isDelete ){
5794 #if OS_VXWORKS 5880 #if OS_VXWORKS
5795 zPath = zName; 5881 zPath = zName;
5796 #elif defined(SQLITE_UNLINK_AFTER_CLOSE) 5882 #elif defined(SQLITE_UNLINK_AFTER_CLOSE)
5797 zPath = sqlite3_mprintf("%s", zName); 5883 zPath = sqlite3_mprintf("%s", zName);
5798 if( zPath==0 ){ 5884 if( zPath==0 ){
5799 robust_close(p, fd, __LINE__); 5885 robust_close(p, fd, __LINE__);
5800 return SQLITE_NOMEM; 5886 return SQLITE_NOMEM_BKPT;
5801 } 5887 }
5802 #else 5888 #else
5803 osUnlink(zName); 5889 osUnlink(zName);
5804 #endif 5890 #endif
5805 } 5891 }
5806 #if SQLITE_ENABLE_LOCKING_STYLE 5892 #if SQLITE_ENABLE_LOCKING_STYLE
5807 else{ 5893 else{
5808 p->openFlags = openFlags; 5894 p->openFlags = openFlags;
5809 } 5895 }
5810 #endif 5896 #endif
5811
5812 noLock = eType!=SQLITE_OPEN_MAIN_DB;
5813
5814 5897
5815 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE 5898 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
5816 if( fstatfs(fd, &fsInfo) == -1 ){ 5899 if( fstatfs(fd, &fsInfo) == -1 ){
5817 storeLastErrno(p, errno); 5900 storeLastErrno(p, errno);
5818 robust_close(p, fd, __LINE__); 5901 robust_close(p, fd, __LINE__);
5819 return SQLITE_IOERR_ACCESS; 5902 return SQLITE_IOERR_ACCESS;
5820 } 5903 }
5821 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { 5904 if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) {
5822 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; 5905 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
5823 } 5906 }
5824 if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) { 5907 if (0 == strncmp("exfat", fsInfo.f_fstypename, 5)) {
5825 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; 5908 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
5826 } 5909 }
5827 #endif 5910 #endif
5828 5911
5829 /* Set up appropriate ctrlFlags */ 5912 /* Set up appropriate ctrlFlags */
5830 if( isDelete ) ctrlFlags |= UNIXFILE_DELETE; 5913 if( isDelete ) ctrlFlags |= UNIXFILE_DELETE;
5831 if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY; 5914 if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY;
5915 noLock = eType!=SQLITE_OPEN_MAIN_DB;
5832 if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK; 5916 if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK;
5833 if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC; 5917 if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC;
5834 if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI; 5918 if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI;
5835 5919
5836 #if SQLITE_ENABLE_LOCKING_STYLE 5920 #if SQLITE_ENABLE_LOCKING_STYLE
5837 #if SQLITE_PREFER_PROXY_LOCKING 5921 #if SQLITE_PREFER_PROXY_LOCKING
5838 isAutoProxy = 1; 5922 isAutoProxy = 1;
5839 #endif 5923 #endif
5840 if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){ 5924 if( isAutoProxy && (zPath!=NULL) && (!noLock) && pVfs->xOpen ){
5841 char *envforce = getenv("SQLITE_FORCE_PROXY_LOCKING"); 5925 char *envforce = getenv("SQLITE_FORCE_PROXY_LOCKING");
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
5900 }else{ 5984 }else{
5901 rc = unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath); 5985 rc = unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
5902 } 5986 }
5903 return rc; 5987 return rc;
5904 } 5988 }
5905 #ifndef SQLITE_DISABLE_DIRSYNC 5989 #ifndef SQLITE_DISABLE_DIRSYNC
5906 if( (dirSync & 1)!=0 ){ 5990 if( (dirSync & 1)!=0 ){
5907 int fd; 5991 int fd;
5908 rc = osOpenDirectory(zPath, &fd); 5992 rc = osOpenDirectory(zPath, &fd);
5909 if( rc==SQLITE_OK ){ 5993 if( rc==SQLITE_OK ){
5910 #if OS_VXWORKS 5994 if( full_fsync(fd,0,0) ){
5911 if( fsync(fd)==-1 )
5912 #else
5913 if( fsync(fd) )
5914 #endif
5915 {
5916 rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); 5995 rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath);
5917 } 5996 }
5918 robust_close(0, fd, __LINE__); 5997 robust_close(0, fd, __LINE__);
5919 }else{ 5998 }else{
5920 assert( rc==SQLITE_CANTOPEN ); 5999 assert( rc==SQLITE_CANTOPEN );
5921 rc = SQLITE_OK; 6000 rc = SQLITE_OK;
5922 } 6001 }
5923 } 6002 }
5924 #endif 6003 #endif
5925 return rc; 6004 return rc;
(...skipping 25 matching lines...) Expand all
5951 6030
5952 if( flags==SQLITE_ACCESS_EXISTS ){ 6031 if( flags==SQLITE_ACCESS_EXISTS ){
5953 struct stat buf; 6032 struct stat buf;
5954 *pResOut = (0==osStat(zPath, &buf) && buf.st_size>0); 6033 *pResOut = (0==osStat(zPath, &buf) && buf.st_size>0);
5955 }else{ 6034 }else{
5956 *pResOut = osAccess(zPath, W_OK|R_OK)==0; 6035 *pResOut = osAccess(zPath, W_OK|R_OK)==0;
5957 } 6036 }
5958 return SQLITE_OK; 6037 return SQLITE_OK;
5959 } 6038 }
5960 6039
6040 /*
6041 **
6042 */
6043 static int mkFullPathname(
6044 const char *zPath, /* Input path */
6045 char *zOut, /* Output buffer */
6046 int nOut /* Allocated size of buffer zOut */
6047 ){
6048 int nPath = sqlite3Strlen30(zPath);
6049 int iOff = 0;
6050 if( zPath[0]!='/' ){
6051 if( osGetcwd(zOut, nOut-2)==0 ){
6052 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
6053 }
6054 iOff = sqlite3Strlen30(zOut);
6055 zOut[iOff++] = '/';
6056 }
6057 if( (iOff+nPath+1)>nOut ){
6058 /* SQLite assumes that xFullPathname() nul-terminates the output buffer
6059 ** even if it returns an error. */
6060 zOut[iOff] = '\0';
6061 return SQLITE_CANTOPEN_BKPT;
6062 }
6063 sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
6064 return SQLITE_OK;
6065 }
5961 6066
5962 /* 6067 /*
5963 ** Turn a relative pathname into a full pathname. The relative path 6068 ** Turn a relative pathname into a full pathname. The relative path
5964 ** is stored as a nul-terminated string in the buffer pointed to by 6069 ** is stored as a nul-terminated string in the buffer pointed to by
5965 ** zPath. 6070 ** zPath.
5966 ** 6071 **
5967 ** zOut points to a buffer of at least sqlite3_vfs.mxPathname bytes 6072 ** zOut points to a buffer of at least sqlite3_vfs.mxPathname bytes
5968 ** (in this case, MAX_PATHNAME bytes). The full-path is written to 6073 ** (in this case, MAX_PATHNAME bytes). The full-path is written to
5969 ** this buffer before returning. 6074 ** this buffer before returning.
5970 */ 6075 */
5971 static int unixFullPathname( 6076 static int unixFullPathname(
5972 sqlite3_vfs *pVfs, /* Pointer to vfs object */ 6077 sqlite3_vfs *pVfs, /* Pointer to vfs object */
5973 const char *zPath, /* Possibly relative input path */ 6078 const char *zPath, /* Possibly relative input path */
5974 int nOut, /* Size of output buffer in bytes */ 6079 int nOut, /* Size of output buffer in bytes */
5975 char *zOut /* Output buffer */ 6080 char *zOut /* Output buffer */
5976 ){ 6081 ){
6082 #if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
6083 return mkFullPathname(zPath, zOut, nOut);
6084 #else
6085 int rc = SQLITE_OK;
5977 int nByte; 6086 int nByte;
6087 int nLink = 1; /* Number of symbolic links followed so far */
6088 const char *zIn = zPath; /* Input path for each iteration of loop */
6089 char *zDel = 0;
6090
6091 assert( pVfs->mxPathname==MAX_PATHNAME );
6092 UNUSED_PARAMETER(pVfs);
5978 6093
5979 /* It's odd to simulate an io-error here, but really this is just 6094 /* It's odd to simulate an io-error here, but really this is just
5980 ** using the io-error infrastructure to test that SQLite handles this 6095 ** using the io-error infrastructure to test that SQLite handles this
5981 ** function failing. This function could fail if, for example, the 6096 ** function failing. This function could fail if, for example, the
5982 ** current working directory has been unlinked. 6097 ** current working directory has been unlinked.
5983 */ 6098 */
5984 SimulateIOError( return SQLITE_ERROR ); 6099 SimulateIOError( return SQLITE_ERROR );
5985 6100
5986 assert( pVfs->mxPathname==MAX_PATHNAME ); 6101 do {
5987 UNUSED_PARAMETER(pVfs);
5988 6102
5989 /* Attempt to resolve the path as if it were a symbolic link. If it is 6103 /* Call stat() on path zIn. Set bLink to true if the path is a symbolic
5990 ** a symbolic link, the resolved path is stored in buffer zOut[]. Or, if 6104 ** link, or false otherwise. */
5991 ** the identified file is not a symbolic link or does not exist, then 6105 int bLink = 0;
5992 ** zPath is copied directly into zOut. Either way, nByte is left set to 6106 struct stat buf;
5993 ** the size of the string copied into zOut[] in bytes. */ 6107 if( osLstat(zIn, &buf)!=0 ){
5994 nByte = osReadlink(zPath, zOut, nOut-1); 6108 if( errno!=ENOENT ){
5995 if( nByte<0 ){ 6109 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
5996 if( errno!=EINVAL && errno!=ENOENT ){ 6110 }
5997 return unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zPath); 6111 }else{
6112 bLink = S_ISLNK(buf.st_mode);
5998 } 6113 }
5999 sqlite3_snprintf(nOut, zOut, "%s", zPath);
6000 nByte = sqlite3Strlen30(zOut);
6001 }else{
6002 zOut[nByte] = '\0';
6003 }
6004 6114
6005 /* If buffer zOut[] now contains an absolute path there is nothing more 6115 if( bLink ){
6006 ** to do. If it contains a relative path, do the following: 6116 if( zDel==0 ){
6007 ** 6117 zDel = sqlite3_malloc(nOut);
6008 ** * move the relative path string so that it is at the end of th 6118 if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
6009 ** zOut[] buffer. 6119 }else if( ++nLink>SQLITE_MAX_SYMLINKS ){
6010 ** * Call getcwd() to read the path of the current working directory 6120 rc = SQLITE_CANTOPEN_BKPT;
6011 ** into the start of the zOut[] buffer. 6121 }
6012 ** * Append a '/' character to the cwd string and move the 6122
6013 ** relative path back within the buffer so that it immediately 6123 if( rc==SQLITE_OK ){
6014 ** follows the '/'. 6124 nByte = osReadlink(zIn, zDel, nOut-1);
6015 ** 6125 if( nByte<0 ){
6016 ** This code is written so that if the combination of the CWD and relative 6126 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
6017 ** path are larger than the allocated size of zOut[] the CWD is silently 6127 }else{
6018 ** truncated to make it fit. This is Ok, as SQLite refuses to open any 6128 if( zDel[0]!='/' ){
6019 ** file for which this function returns a full path larger than (nOut-8) 6129 int n;
6020 ** bytes in size. */ 6130 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
6021 testcase( nByte==nOut-5 ); 6131 if( nByte+n+1>nOut ){
6022 testcase( nByte==nOut-4 ); 6132 rc = SQLITE_CANTOPEN_BKPT;
6023 if( zOut[0]!='/' && nByte<nOut-4 ){ 6133 }else{
6024 int nCwd; 6134 memmove(&zDel[n], zDel, nByte+1);
6025 int nRem = nOut-nByte-1; 6135 memcpy(zDel, zIn, n);
6026 memmove(&zOut[nRem], zOut, nByte+1); 6136 nByte += n;
6027 zOut[nRem-1] = '\0'; 6137 }
6028 if( osGetcwd(zOut, nRem-1)==0 ){ 6138 }
6029 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath); 6139 zDel[nByte] = '\0';
6140 }
6141 }
6142
6143 zIn = zDel;
6030 } 6144 }
6031 nCwd = sqlite3Strlen30(zOut);
6032 assert( nCwd<=nRem-1 );
6033 zOut[nCwd] = '/';
6034 memmove(&zOut[nCwd+1], &zOut[nRem], nByte+1);
6035 }
6036 6145
6037 return SQLITE_OK; 6146 assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' );
6147 if( rc==SQLITE_OK && zIn!=zOut ){
6148 rc = mkFullPathname(zIn, zOut, nOut);
6149 }
6150 if( bLink==0 ) break;
6151 zIn = zOut;
6152 }while( rc==SQLITE_OK );
6153
6154 sqlite3_free(zDel);
6155 return rc;
6156 #endif /* HAVE_READLINK && HAVE_LSTAT */
6038 } 6157 }
6039 6158
6040 6159
6041 #ifndef SQLITE_OMIT_LOAD_EXTENSION 6160 #ifndef SQLITE_OMIT_LOAD_EXTENSION
6042 /* 6161 /*
6043 ** Interfaces for opening a shared library, finding entry points 6162 ** Interfaces for opening a shared library, finding entry points
6044 ** within the shared library, and closing the shared library. 6163 ** within the shared library, and closing the shared library.
6045 */ 6164 */
6046 #include <dlfcn.h> 6165 #include <dlfcn.h>
6047 static void *unixDlOpen(sqlite3_vfs *NotUsed, const char *zFilename){ 6166 static void *unixDlOpen(sqlite3_vfs *NotUsed, const char *zFilename){
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
6227 int rc; 6346 int rc;
6228 UNUSED_PARAMETER(NotUsed); 6347 UNUSED_PARAMETER(NotUsed);
6229 rc = unixCurrentTimeInt64(0, &i); 6348 rc = unixCurrentTimeInt64(0, &i);
6230 *prNow = i/86400000.0; 6349 *prNow = i/86400000.0;
6231 return rc; 6350 return rc;
6232 } 6351 }
6233 #else 6352 #else
6234 # define unixCurrentTime 0 6353 # define unixCurrentTime 0
6235 #endif 6354 #endif
6236 6355
6237 #ifndef SQLITE_OMIT_DEPRECATED
6238 /* 6356 /*
6239 ** We added the xGetLastError() method with the intention of providing 6357 ** The xGetLastError() method is designed to return a better
6240 ** better low-level error messages when operating-system problems come up 6358 ** low-level error message when operating-system problems come up
6241 ** during SQLite operation. But so far, none of that has been implemented 6359 ** during SQLite operation. Only the integer return code is currently
6242 ** in the core. So this routine is never called. For now, it is merely 6360 ** used.
6243 ** a place-holder.
6244 */ 6361 */
6245 static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3){ 6362 static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3){
6246 UNUSED_PARAMETER(NotUsed); 6363 UNUSED_PARAMETER(NotUsed);
6247 UNUSED_PARAMETER(NotUsed2); 6364 UNUSED_PARAMETER(NotUsed2);
6248 UNUSED_PARAMETER(NotUsed3); 6365 UNUSED_PARAMETER(NotUsed3);
6249 return 0; 6366 return errno;
6250 } 6367 }
6251 #else
6252 # define unixGetLastError 0
6253 #endif
6254 6368
6255 6369
6256 /* 6370 /*
6257 ************************ End of sqlite3_vfs methods *************************** 6371 ************************ End of sqlite3_vfs methods ***************************
6258 ******************************************************************************/ 6372 ******************************************************************************/
6259 6373
6260 /****************************************************************************** 6374 /******************************************************************************
6261 ************************** Begin Proxy Locking ******************************** 6375 ************************** Begin Proxy Locking ********************************
6262 ** 6376 **
6263 ** Proxy locking is a "uber-locking-method" in this sense: It uses the 6377 ** Proxy locking is a "uber-locking-method" in this sense: It uses the
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
6533 ** the parent directories and then try again. 6647 ** the parent directories and then try again.
6534 ** 3. if that fails, try to open the file read-only 6648 ** 3. if that fails, try to open the file read-only
6535 ** otherwise return BUSY (if lock file) or CANTOPEN for the conch file 6649 ** otherwise return BUSY (if lock file) or CANTOPEN for the conch file
6536 */ 6650 */
6537 pUnused = findReusableFd(path, openFlags); 6651 pUnused = findReusableFd(path, openFlags);
6538 if( pUnused ){ 6652 if( pUnused ){
6539 fd = pUnused->fd; 6653 fd = pUnused->fd;
6540 }else{ 6654 }else{
6541 pUnused = sqlite3_malloc64(sizeof(*pUnused)); 6655 pUnused = sqlite3_malloc64(sizeof(*pUnused));
6542 if( !pUnused ){ 6656 if( !pUnused ){
6543 return SQLITE_NOMEM; 6657 return SQLITE_NOMEM_BKPT;
6544 } 6658 }
6545 } 6659 }
6546 if( fd<0 ){ 6660 if( fd<0 ){
6547 fd = robust_open(path, openFlags, 0); 6661 fd = robust_open(path, openFlags, 0);
6548 terrno = errno; 6662 terrno = errno;
6549 if( fd<0 && errno==ENOENT && islockfile ){ 6663 if( fd<0 && errno==ENOENT && islockfile ){
6550 if( proxyCreateLockPath(path) == SQLITE_OK ){ 6664 if( proxyCreateLockPath(path) == SQLITE_OK ){
6551 fd = robust_open(path, openFlags, 0); 6665 fd = robust_open(path, openFlags, 0);
6552 } 6666 }
6553 } 6667 }
(...skipping 12 matching lines...) Expand all
6566 return SQLITE_PERM; 6680 return SQLITE_PERM;
6567 case EIO: 6681 case EIO:
6568 return SQLITE_IOERR_LOCK; /* even though it is the conch */ 6682 return SQLITE_IOERR_LOCK; /* even though it is the conch */
6569 default: 6683 default:
6570 return SQLITE_CANTOPEN_BKPT; 6684 return SQLITE_CANTOPEN_BKPT;
6571 } 6685 }
6572 } 6686 }
6573 6687
6574 pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew)); 6688 pNew = (unixFile *)sqlite3_malloc64(sizeof(*pNew));
6575 if( pNew==NULL ){ 6689 if( pNew==NULL ){
6576 rc = SQLITE_NOMEM; 6690 rc = SQLITE_NOMEM_BKPT;
6577 goto end_create_proxy; 6691 goto end_create_proxy;
6578 } 6692 }
6579 memset(pNew, 0, sizeof(unixFile)); 6693 memset(pNew, 0, sizeof(unixFile));
6580 pNew->openFlags = openFlags; 6694 pNew->openFlags = openFlags;
6581 memset(&dummyVfs, 0, sizeof(dummyVfs)); 6695 memset(&dummyVfs, 0, sizeof(dummyVfs));
6582 dummyVfs.pAppData = (void*)&autolockIoFinder; 6696 dummyVfs.pAppData = (void*)&autolockIoFinder;
6583 dummyVfs.zName = "dummy"; 6697 dummyVfs.zName = "dummy";
6584 pUnused->fd = fd; 6698 pUnused->fd = fd;
6585 pUnused->flags = openFlags; 6699 pUnused->flags = openFlags;
6586 pNew->pUnused = pUnused; 6700 pNew->pUnused = pUnused;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
6909 memcpy(&writeBuffer[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN); 7023 memcpy(&writeBuffer[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN);
6910 if( pCtx->lockProxyPath!=NULL ){ 7024 if( pCtx->lockProxyPath!=NULL ){
6911 strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath, 7025 strlcpy(&writeBuffer[PROXY_PATHINDEX], pCtx->lockProxyPath,
6912 MAXPATHLEN); 7026 MAXPATHLEN);
6913 }else{ 7027 }else{
6914 strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN); 7028 strlcpy(&writeBuffer[PROXY_PATHINDEX], tempLockPath, MAXPATHLEN);
6915 } 7029 }
6916 writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]); 7030 writeSize = PROXY_PATHINDEX + strlen(&writeBuffer[PROXY_PATHINDEX]);
6917 robust_ftruncate(conchFile->h, writeSize); 7031 robust_ftruncate(conchFile->h, writeSize);
6918 rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0); 7032 rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0);
6919 fsync(conchFile->h); 7033 full_fsync(conchFile->h,0,0);
6920 /* If we created a new conch file (not just updated the contents of a 7034 /* If we created a new conch file (not just updated the contents of a
6921 ** valid conch file), try to match the permissions of the database 7035 ** valid conch file), try to match the permissions of the database
6922 */ 7036 */
6923 if( rc==SQLITE_OK && createConch ){ 7037 if( rc==SQLITE_OK && createConch ){
6924 struct stat buf; 7038 struct stat buf;
6925 int err = osFstat(pFile->h, &buf); 7039 int err = osFstat(pFile->h, &buf);
6926 if( err==0 ){ 7040 if( err==0 ){
6927 mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | 7041 mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
6928 S_IROTH|S_IWOTH); 7042 S_IROTH|S_IWOTH);
6929 /* try to match the database file R/W permissions, ignore failure */ 7043 /* try to match the database file R/W permissions, ignore failure */
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
6979 continue; /* go back to the do {} while start point, try again */ 7093 continue; /* go back to the do {} while start point, try again */
6980 } 7094 }
6981 } 7095 }
6982 if( rc==SQLITE_OK ){ 7096 if( rc==SQLITE_OK ){
6983 /* Need to make a copy of path if we extracted the value 7097 /* Need to make a copy of path if we extracted the value
6984 ** from the conch file or the path was allocated on the stack 7098 ** from the conch file or the path was allocated on the stack
6985 */ 7099 */
6986 if( tempLockPath ){ 7100 if( tempLockPath ){
6987 pCtx->lockProxyPath = sqlite3DbStrDup(0, tempLockPath); 7101 pCtx->lockProxyPath = sqlite3DbStrDup(0, tempLockPath);
6988 if( !pCtx->lockProxyPath ){ 7102 if( !pCtx->lockProxyPath ){
6989 rc = SQLITE_NOMEM; 7103 rc = SQLITE_NOMEM_BKPT;
6990 } 7104 }
6991 } 7105 }
6992 } 7106 }
6993 if( rc==SQLITE_OK ){ 7107 if( rc==SQLITE_OK ){
6994 pCtx->conchHeld = 1; 7108 pCtx->conchHeld = 1;
6995 7109
6996 if( pCtx->lockProxy->pMethod == &afpIoMethods ){ 7110 if( pCtx->lockProxy->pMethod == &afpIoMethods ){
6997 afpLockingContext *afpCtx; 7111 afpLockingContext *afpCtx;
6998 afpCtx = (afpLockingContext *)pCtx->lockProxy->lockingContext; 7112 afpCtx = (afpLockingContext *)pCtx->lockProxy->lockingContext;
6999 afpCtx->dbPath = pCtx->lockProxyPath; 7113 afpCtx->dbPath = pCtx->lockProxyPath;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
7044 */ 7158 */
7045 static int proxyCreateConchPathname(char *dbPath, char **pConchPath){ 7159 static int proxyCreateConchPathname(char *dbPath, char **pConchPath){
7046 int i; /* Loop counter */ 7160 int i; /* Loop counter */
7047 int len = (int)strlen(dbPath); /* Length of database filename - dbPath */ 7161 int len = (int)strlen(dbPath); /* Length of database filename - dbPath */
7048 char *conchPath; /* buffer in which to construct conch name */ 7162 char *conchPath; /* buffer in which to construct conch name */
7049 7163
7050 /* Allocate space for the conch filename and initialize the name to 7164 /* Allocate space for the conch filename and initialize the name to
7051 ** the name of the original database file. */ 7165 ** the name of the original database file. */
7052 *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8); 7166 *pConchPath = conchPath = (char *)sqlite3_malloc64(len + 8);
7053 if( conchPath==0 ){ 7167 if( conchPath==0 ){
7054 return SQLITE_NOMEM; 7168 return SQLITE_NOMEM_BKPT;
7055 } 7169 }
7056 memcpy(conchPath, dbPath, len+1); 7170 memcpy(conchPath, dbPath, len+1);
7057 7171
7058 /* now insert a "." before the last / character */ 7172 /* now insert a "." before the last / character */
7059 for( i=(len-1); i>=0; i-- ){ 7173 for( i=(len-1); i>=0; i-- ){
7060 if( conchPath[i]=='/' ){ 7174 if( conchPath[i]=='/' ){
7061 i++; 7175 i++;
7062 break; 7176 break;
7063 } 7177 }
7064 } 7178 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
7160 lockPath=NULL; 7274 lockPath=NULL;
7161 }else{ 7275 }else{
7162 lockPath=(char *)path; 7276 lockPath=(char *)path;
7163 } 7277 }
7164 7278
7165 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h, 7279 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
7166 (lockPath ? lockPath : ":auto:"), osGetpid(0))); 7280 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
7167 7281
7168 pCtx = sqlite3_malloc64( sizeof(*pCtx) ); 7282 pCtx = sqlite3_malloc64( sizeof(*pCtx) );
7169 if( pCtx==0 ){ 7283 if( pCtx==0 ){
7170 return SQLITE_NOMEM; 7284 return SQLITE_NOMEM_BKPT;
7171 } 7285 }
7172 memset(pCtx, 0, sizeof(*pCtx)); 7286 memset(pCtx, 0, sizeof(*pCtx));
7173 7287
7174 rc = proxyCreateConchPathname(dbPath, &pCtx->conchFilePath); 7288 rc = proxyCreateConchPathname(dbPath, &pCtx->conchFilePath);
7175 if( rc==SQLITE_OK ){ 7289 if( rc==SQLITE_OK ){
7176 rc = proxyCreateUnixFile(pCtx->conchFilePath, &pCtx->conchFile, 0); 7290 rc = proxyCreateUnixFile(pCtx->conchFilePath, &pCtx->conchFile, 0);
7177 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){ 7291 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){
7178 /* if (a) the open flags are not O_RDWR, (b) the conch isn't there, and 7292 /* if (a) the open flags are not O_RDWR, (b) the conch isn't there, and
7179 ** (c) the file system is read-only, then enable no-locking access. 7293 ** (c) the file system is read-only, then enable no-locking access.
7180 ** Ugh, since O_RDONLY==0x0000 we test for !O_RDWR since unixOpen asserts 7294 ** Ugh, since O_RDONLY==0x0000 we test for !O_RDWR since unixOpen asserts
(...skipping 15 matching lines...) Expand all
7196 } 7310 }
7197 } 7311 }
7198 } 7312 }
7199 if( rc==SQLITE_OK && lockPath ){ 7313 if( rc==SQLITE_OK && lockPath ){
7200 pCtx->lockProxyPath = sqlite3DbStrDup(0, lockPath); 7314 pCtx->lockProxyPath = sqlite3DbStrDup(0, lockPath);
7201 } 7315 }
7202 7316
7203 if( rc==SQLITE_OK ){ 7317 if( rc==SQLITE_OK ){
7204 pCtx->dbPath = sqlite3DbStrDup(0, dbPath); 7318 pCtx->dbPath = sqlite3DbStrDup(0, dbPath);
7205 if( pCtx->dbPath==NULL ){ 7319 if( pCtx->dbPath==NULL ){
7206 rc = SQLITE_NOMEM; 7320 rc = SQLITE_NOMEM_BKPT;
7207 } 7321 }
7208 } 7322 }
7209 if( rc==SQLITE_OK ){ 7323 if( rc==SQLITE_OK ){
7210 /* all memory is allocated, proxys are created and assigned, 7324 /* all memory is allocated, proxys are created and assigned,
7211 ** switch the locking context and pMethod then return. 7325 ** switch the locking context and pMethod then return.
7212 */ 7326 */
7213 pCtx->oldLockingContext = pFile->lockingContext; 7327 pCtx->oldLockingContext = pFile->lockingContext;
7214 pFile->lockingContext = pCtx; 7328 pFile->lockingContext = pCtx;
7215 pCtx->pOldMethod = pFile->pMethod; 7329 pCtx->pOldMethod = pFile->pMethod;
7216 pFile->pMethod = &proxyIoMethods; 7330 pFile->pMethod = &proxyIoMethods;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
7526 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) 7640 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
7527 UNIXVFS("unix-afp", afpIoFinder ), 7641 UNIXVFS("unix-afp", afpIoFinder ),
7528 UNIXVFS("unix-nfs", nfsIoFinder ), 7642 UNIXVFS("unix-nfs", nfsIoFinder ),
7529 UNIXVFS("unix-proxy", proxyIoFinder ), 7643 UNIXVFS("unix-proxy", proxyIoFinder ),
7530 #endif 7644 #endif
7531 }; 7645 };
7532 unsigned int i; /* Loop counter */ 7646 unsigned int i; /* Loop counter */
7533 7647
7534 /* Double-check that the aSyscall[] array has been constructed 7648 /* Double-check that the aSyscall[] array has been constructed
7535 ** correctly. See ticket [bb3a86e890c8e96ab] */ 7649 ** correctly. See ticket [bb3a86e890c8e96ab] */
7536 assert( ArraySize(aSyscall)==27 ); 7650 assert( ArraySize(aSyscall)==28 );
7537 7651
7538 /* Register all VFSes defined in the aVfs[] array */ 7652 /* Register all VFSes defined in the aVfs[] array */
7539 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ 7653 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
7540 sqlite3_vfs_register(&aVfs[i], i==0); 7654 sqlite3_vfs_register(&aVfs[i], i==0);
7541 } 7655 }
7542 return SQLITE_OK; 7656 return SQLITE_OK;
7543 } 7657 }
7544 7658
7545 /* 7659 /*
7546 ** Shutdown the operating system interface. 7660 ** Shutdown the operating system interface.
7547 ** 7661 **
7548 ** Some operating systems might need to do some cleanup in this routine, 7662 ** Some operating systems might need to do some cleanup in this routine,
7549 ** to release dynamically allocated objects. But not on unix. 7663 ** to release dynamically allocated objects. But not on unix.
7550 ** This routine is a no-op for unix. 7664 ** This routine is a no-op for unix.
7551 */ 7665 */
7552 int sqlite3_os_end(void){ 7666 int sqlite3_os_end(void){
7553 return SQLITE_OK; 7667 return SQLITE_OK;
7554 } 7668 }
7555 7669
7556 #endif /* SQLITE_OS_UNIX */ 7670 #endif /* SQLITE_OS_UNIX */
OLDNEW
« no previous file with comments | « third_party/sqlite/src/src/os_setup.h ('k') | third_party/sqlite/src/src/os_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698