Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Remove some old OsFile and IoMethod related code. Add the sqlite3OsLockState function. (CVS 4241) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
08a0f48028794abbeae1b4852652062b |
User & Date: | danielk1977 2007-08-17 16:50:38 |
Context
2007-08-18
| ||
10:59 | Further progress on migration to sqlite3_vfs. (CVS 4242) check-in: a258c4ec user: danielk1977 tags: trunk | |
2007-08-17
| ||
16:50 | Remove some old OsFile and IoMethod related code. Add the sqlite3OsLockState function. (CVS 4241) check-in: 08a0f480 user: danielk1977 tags: trunk | |
15:53 | Begin migration to using sqlite3_vfs interface. (CVS 4240) check-in: af3e3c7a user: danielk1977 tags: trunk | |
Changes
Changes to src/btree.c.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
....
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
|
** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** $Id: btree.c,v 1.400 2007/08/17 15:53:36 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. ** Including a description of file format and an overview of operation. */ #include "btreeInt.h" ................................................................................ ** existing BtShared object that we can share with */ if( (flags & BTREE_PRIVATE)==0 && isMemdb==0 && zFilename && zFilename[0] && sqlite3SharedCacheEnabled ){ char *zFullPathname = sqlite3OsFullPathname(zFilename); sqlite3_mutex *mutexShared; p->sharable = 1; if( !zFullPathname ){ sqlite3_free(p); return SQLITE_NOMEM; } mutexShared = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); sqlite3_mutex_enter(mutexShared); for(pBt=sqlite3SharedCacheList; pBt; pBt=pBt->pNext){ assert( pBt->nRef>0 ); if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager)) ){ p->pBt = pBt; pBt->nRef++; |
|
|
>
|
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
....
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
|
** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** $Id: btree.c,v 1.401 2007/08/17 16:50:38 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. ** Including a description of file format and an overview of operation. */ #include "btreeInt.h" ................................................................................ ** existing BtShared object that we can share with */ if( (flags & BTREE_PRIVATE)==0 && isMemdb==0 && zFilename && zFilename[0] && sqlite3SharedCacheEnabled ){ char *zFullPathname = (char *)sqlite3_malloc(pVfs->mxPathname); sqlite3_mutex *mutexShared; p->sharable = 1; if( !zFullPathname ){ sqlite3_free(p); return SQLITE_NOMEM; } sqlite3OsFullPathname(pVfs, zFilename, zFullPathname); mutexShared = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); sqlite3_mutex_enter(mutexShared); for(pBt=sqlite3SharedCacheList; pBt; pBt=pBt->pNext){ assert( pBt->nRef>0 ); if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager)) ){ p->pBt = pBt; pBt->nRef++; |
Changes to src/os.c.
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
} int sqlite3OsWrite(sqlite3_file *id, const void *pBuf, int amt, i64 offset){ return id->pMethods->xWrite(id, pBuf, amt, offset); } int sqlite3OsTruncate(sqlite3_file *id, i64 size){ return id->pMethods->xTruncate(id, size); } int sqlite3OsSync(sqlite3_file *id, int fullsync){ return id->pMethods->xSync(id, fullsync); } int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){ return id->pMethods->xFileSize(id, pSize); } int sqlite3OsLock(sqlite3_file *id, int lockType){ return id->pMethods->xLock(id, lockType); } ................................................................................ #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) /* These methods are currently only used for testing and debugging. */ int sqlite3OsFileHandle(sqlite3_file *id){ /* return id->pMethods->xFileHandle(id); */ return 0; } int sqlite3OsLockState(sqlite3_file *id){ /* return id->pMethods->xLockState(id); */ return 0; } #endif int sqlite3OsOpen( sqlite3_vfs *pVfs, const char *zPath, sqlite3_file *pFile, |
|
|
|
<
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
} int sqlite3OsWrite(sqlite3_file *id, const void *pBuf, int amt, i64 offset){ return id->pMethods->xWrite(id, pBuf, amt, offset); } int sqlite3OsTruncate(sqlite3_file *id, i64 size){ return id->pMethods->xTruncate(id, size); } int sqlite3OsSync(sqlite3_file *id, int flags){ return id->pMethods->xSync(id, flags); } int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){ return id->pMethods->xFileSize(id, pSize); } int sqlite3OsLock(sqlite3_file *id, int lockType){ return id->pMethods->xLock(id, lockType); } ................................................................................ #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) /* These methods are currently only used for testing and debugging. */ int sqlite3OsFileHandle(sqlite3_file *id){ /* return id->pMethods->xFileHandle(id); */ return 0; } int sqlite3OsLockState(sqlite3_file *id){ return id->pMethods->xLockState(id); } #endif int sqlite3OsOpen( sqlite3_vfs *pVfs, const char *zPath, sqlite3_file *pFile, |
Changes to src/os.h.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 ... 357 358 359 360 361 362 363 364 365 366 367 368 369 370 ... 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
** anybody smart enough to figure out the code is also likely smart ** enough to know that calling the developer will not help get rid ** of the file. */ #ifndef TEMP_FILE_PREFIX # define TEMP_FILE_PREFIX "etilqs_" #endif #if 0 /* ** Define the interfaces for Unix, Windows, and OS/2. */ #if OS_UNIX #define sqlite3OsOpenReadWrite sqlite3UnixOpenReadWrite #define sqlite3OsOpenExclusive sqlite3UnixOpenExclusive #define sqlite3OsOpenReadOnly sqlite3UnixOpenReadOnly #define sqlite3OsDelete sqlite3UnixDelete #define sqlite3OsFileExists sqlite3UnixFileExists #define sqlite3OsFullPathname sqlite3UnixFullPathname #define sqlite3OsIsDirWritable sqlite3UnixIsDirWritable #define sqlite3OsSyncDirectory sqlite3UnixSyncDirectory #define sqlite3OsTempFileName sqlite3UnixTempFileName #define sqlite3OsRandomSeed sqlite3UnixRandomSeed #define sqlite3OsSleep sqlite3UnixSleep #define sqlite3OsCurrentTime sqlite3UnixCurrentTime #define sqlite3OsEnterMutex sqlite3UnixEnterMutex #define sqlite3OsLeaveMutex sqlite3UnixLeaveMutex #define sqlite3OsInMutex sqlite3UnixInMutex #define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData #define sqlite3OsMalloc sqlite3GenericMalloc #define sqlite3OsRealloc sqlite3GenericRealloc #define sqlite3OsFree sqlite3GenericFree #define sqlite3OsAllocationSize sqlite3GenericAllocationSize #define sqlite3OsDlopen sqlite3UnixDlopen #define sqlite3OsDlsym sqlite3UnixDlsym #define sqlite3OsDlclose sqlite3UnixDlclose #endif #if OS_WIN #define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite #define sqlite3OsOpenExclusive sqlite3WinOpenExclusive #define sqlite3OsOpenReadOnly sqlite3WinOpenReadOnly #define sqlite3OsDelete sqlite3WinDelete #define sqlite3OsFileExists sqlite3WinFileExists #define sqlite3OsFullPathname sqlite3WinFullPathname #define sqlite3OsIsDirWritable sqlite3WinIsDirWritable #define sqlite3OsSyncDirectory sqlite3WinSyncDirectory #define sqlite3OsTempFileName sqlite3WinTempFileName #define sqlite3OsRandomSeed sqlite3WinRandomSeed #define sqlite3OsSleep sqlite3WinSleep #define sqlite3OsCurrentTime sqlite3WinCurrentTime #define sqlite3OsEnterMutex sqlite3WinEnterMutex #define sqlite3OsLeaveMutex sqlite3WinLeaveMutex #define sqlite3OsInMutex sqlite3WinInMutex #define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData #define sqlite3OsMalloc sqlite3GenericMalloc #define sqlite3OsRealloc sqlite3GenericRealloc #define sqlite3OsFree sqlite3GenericFree #define sqlite3OsAllocationSize sqlite3GenericAllocationSize #define sqlite3OsDlopen sqlite3WinDlopen #define sqlite3OsDlsym sqlite3WinDlsym #define sqlite3OsDlclose sqlite3WinDlclose #endif #if OS_OS2 #define sqlite3OsOpenReadWrite sqlite3Os2OpenReadWrite #define sqlite3OsOpenExclusive sqlite3Os2OpenExclusive #define sqlite3OsOpenReadOnly sqlite3Os2OpenReadOnly #define sqlite3OsDelete sqlite3Os2Delete #define sqlite3OsFileExists sqlite3Os2FileExists #define sqlite3OsFullPathname sqlite3Os2FullPathname #define sqlite3OsIsDirWritable sqlite3Os2IsDirWritable #define sqlite3OsSyncDirectory sqlite3Os2SyncDirectory #define sqlite3OsTempFileName sqlite3Os2TempFileName #define sqlite3OsRandomSeed sqlite3Os2RandomSeed #define sqlite3OsSleep sqlite3Os2Sleep #define sqlite3OsCurrentTime sqlite3Os2CurrentTime #define sqlite3OsEnterMutex sqlite3Os2EnterMutex #define sqlite3OsLeaveMutex sqlite3Os2LeaveMutex #define sqlite3OsInMutex sqlite3Os2InMutex #define sqlite3OsThreadSpecificData sqlite3Os2ThreadSpecificData #define sqlite3OsMalloc sqlite3GenericMalloc #define sqlite3OsRealloc sqlite3GenericRealloc #define sqlite3OsFree sqlite3GenericFree #define sqlite3OsAllocationSize sqlite3GenericAllocationSize #define sqlite3OsDlopen sqlite3Os2Dlopen #define sqlite3OsDlsym sqlite3Os2Dlsym #define sqlite3OsDlclose sqlite3Os2Dlclose #endif #endif /* ** If using an alternative OS interface, then we must have an "os_other.h" ** header file available for that interface. Presumably the "os_other.h" ** header file contains #defines similar to those above. */ #if OS_OTHER # include "os_other.h" #endif /* ** Forward declarations */ typedef struct OsFile OsFile; typedef struct IoMethod IoMethod; /* ** An instance of the following structure contains pointers to all ** methods on an OsFile object. */ struct IoMethod { int (*xClose)(OsFile**); int (*xOpenDirectory)(OsFile*, const char*); int (*xRead)(OsFile*, void*, int amt); int (*xWrite)(OsFile*, const void*, int amt); int (*xSeek)(OsFile*, i64 offset); int (*xTruncate)(OsFile*, i64 size); int (*xSync)(OsFile*, int); void (*xSetFullSync)(OsFile *id, int setting); int (*xFileHandle)(OsFile *id); int (*xFileSize)(OsFile*, i64 *pSize); int (*xLock)(OsFile*, int); int (*xUnlock)(OsFile*, int); int (*xLockState)(OsFile *id); int (*xCheckReservedLock)(OsFile *id); int (*xSectorSize)(OsFile *id); }; /* ** The OsFile object describes an open disk file in an OS-dependent way. ** The version of OsFile defined here is a generic version. Each OS ** implementation defines its own subclass of this structure that contains ** additional information needed to handle file I/O. But the pMethod ** entry (pointing to the virtual function table) always occurs first ** so that we can always find the appropriate methods. */ struct OsFile { IoMethod const *pMethod; }; /* ** The following values may be passed as the second argument to ** sqlite3OsLock(). The various locks exhibit the following semantics: ** ** SHARED: Any number of processes may hold a SHARED lock simultaneously. ** RESERVED: A single process may hold a RESERVED lock on a file at ** any time. Other processes may hold and obtain new SHARED locks. ................................................................................ int sqlite3OsTruncate(sqlite3_file*, i64 size); int sqlite3OsSync(sqlite3_file*, int); int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); int sqlite3OsLock(sqlite3_file*, int); int sqlite3OsUnlock(sqlite3_file*, int); int sqlite3OsBreakLock(sqlite3_file*); int sqlite3OsCheckReservedLock(sqlite3_file *id); int sqlite3OsSectorSize(sqlite3_file *id); int sqlite3OsDeviceCharacteristics(sqlite3_file *id); /* ** Functions for accessing sqlite3_vfs methods */ int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); ................................................................................ /* ** Convenience functions for opening and closing files using ** sqlite3_malloc() to obtain space for the file-handle structure. */ int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int); int sqlite3OsCloseFree(sqlite3_file *); #if 0 int sqlite3OsOpenReadWrite(const char*, sqlite3_file**, int*); int sqlite3OsOpenExclusive(const char*, sqlite3_file**, int); int sqlite3OsOpenReadOnly(const char*, sqlite3_file**); int sqlite3OsDelete(const char*); int sqlite3OsFileExists(const char*); char *sqlite3OsFullPathname(const char*); int sqlite3OsIsDirWritable(char*); int sqlite3OsSyncDirectory(const char*); int sqlite3OsTempFileName(char*); int sqlite3OsRandomSeed(char*); int sqlite3OsSleep(int ms); int sqlite3OsCurrentTime(double*); void sqlite3OsEnterMutex(void); void sqlite3OsLeaveMutex(void); int sqlite3OsInMutex(int); ThreadData *sqlite3OsThreadSpecificData(int); void *sqlite3OsMalloc(int); void *sqlite3OsRealloc(void *, int); void sqlite3OsFree(void *); int sqlite3OsAllocationSize(void *); void *sqlite3OsDlopen(const char*); void *sqlite3OsDlsym(void*, const char*); int sqlite3OsDlclose(void*); #endif #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) int sqlite3OsFileHandle(sqlite3_file *id); int sqlite3OsLockState(sqlite3_file *id); #endif /* ** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer ** interface routines are not called directly but are invoked using ** pointers to functions. This allows the implementation of various ** OS-layer interface routines to be modified at run-time. There are ** obscure but legitimate reasons for wanting to do this. But for ** most users, a direct call to the underlying interface is preferable ** so the the redefinable I/O interface is turned off by default. */ #ifdef SQLITE_ENABLE_REDEF_IO /* ** When redefinable I/O is enabled, a single global instance of the ** following structure holds pointers to the routines that SQLite ** uses to talk with the underlying operating system. Modify this ** structure (before using any SQLite API!) to accomodate perculiar ** operating system interfaces or behaviors. */ struct sqlite3OsVtbl { int (*xOpenReadWrite)(const char*, sqlite3_file**, int*); int (*xOpenExclusive)(const char*, sqlite3_file**, int); int (*xOpenReadOnly)(const char*, sqlite3_file**); int (*xDelete)(const char*); int (*xFileExists)(const char*); char *(*xFullPathname)(const char*); int (*xIsDirWritable)(char*); int (*xSyncDirectory)(const char*); int (*xTempFileName)(char*); int (*xRandomSeed)(char*); int (*xSleep)(int ms); int (*xCurrentTime)(double*); void (*xEnterMutex)(void); void (*xLeaveMutex)(void); int (*xInMutex)(int); ThreadData *(*xThreadSpecificData)(int); void *(*xMalloc)(int); void *(*xRealloc)(void *, int); void (*xFree)(void *); int (*xAllocationSize)(void *); void *(*xDlopen)(const char*); void *(*xDlsym)(void*, const char*); int (*xDlclose)(void*); }; /* Macro used to comment out routines that do not exists when there is ** no disk I/O or extension loading */ #ifdef SQLITE_OMIT_DISKIO # define IF_DISKIO(X) 0 #else # define IF_DISKIO(X) X #endif #ifdef SQLITE_OMIT_LOAD_EXTENSION # define IF_DLOPEN(X) 0 #else # define IF_DLOPEN(X) X #endif #if defined(_SQLITE_OS_C_) || defined(SQLITE_AMALGAMATION) /* ** The os.c file implements the global virtual function table. ** We have to put this file here because the initializers ** (ex: sqlite3OsRandomSeed) are macros that are about to be ** redefined. */ struct sqlite3OsVtbl sqlite3Os = { IF_DISKIO( sqlite3OsOpenReadWrite ), IF_DISKIO( sqlite3OsOpenExclusive ), IF_DISKIO( sqlite3OsOpenReadOnly ), IF_DISKIO( sqlite3OsDelete ), IF_DISKIO( sqlite3OsFileExists ), IF_DISKIO( sqlite3OsFullPathname ), IF_DISKIO( sqlite3OsIsDirWritable ), IF_DISKIO( sqlite3OsSyncDirectory ), IF_DISKIO( sqlite3OsTempFileName ), sqlite3OsRandomSeed, sqlite3OsSleep, sqlite3OsCurrentTime, sqlite3OsEnterMutex, sqlite3OsLeaveMutex, sqlite3OsInMutex, 0, sqlite3OsMalloc, sqlite3OsRealloc, sqlite3OsFree, sqlite3OsAllocationSize, IF_DLOPEN( sqlite3OsDlopen ), IF_DLOPEN( sqlite3OsDlsym ), IF_DLOPEN( sqlite3OsDlclose ), }; #else /* ** Files other than os.c just reference the global virtual function table. */ extern struct sqlite3OsVtbl sqlite3Os; #endif /* _SQLITE_OS_C_ */ /* This additional API routine is available with redefinable I/O */ struct sqlite3OsVtbl *sqlite3_os_switch(void); /* ** Redefine the OS interface to go through the virtual function table ** rather than calling routines directly. */ #undef sqlite3OsOpenReadWrite #undef sqlite3OsOpenExclusive #undef sqlite3OsOpenReadOnly #undef sqlite3OsDelete #undef sqlite3OsFileExists #undef sqlite3OsFullPathname #undef sqlite3OsIsDirWritable #undef sqlite3OsSyncDirectory #undef sqlite3OsTempFileName #undef sqlite3OsRandomSeed #undef sqlite3OsSleep #undef sqlite3OsCurrentTime #undef sqlite3OsEnterMutex #undef sqlite3OsLeaveMutex #undef sqlite3OsInMutex #undef sqlite3OsThreadSpecificData #undef sqlite3OsMalloc #undef sqlite3OsRealloc #undef sqlite3OsFree #undef sqlite3OsAllocationSize #define sqlite3OsOpenReadWrite sqlite3Os.xOpenReadWrite #define sqlite3OsOpenExclusive sqlite3Os.xOpenExclusive #define sqlite3OsOpenReadOnly sqlite3Os.xOpenReadOnly #define sqlite3OsDelete sqlite3Os.xDelete #define sqlite3OsFileExists sqlite3Os.xFileExists #define sqlite3OsFullPathname sqlite3Os.xFullPathname #define sqlite3OsIsDirWritable sqlite3Os.xIsDirWritable #define sqlite3OsSyncDirectory sqlite3Os.xSyncDirectory #define sqlite3OsTempFileName sqlite3Os.xTempFileName #define sqlite3OsRandomSeed sqlite3Os.xRandomSeed #define sqlite3OsSleep sqlite3Os.xSleep #define sqlite3OsCurrentTime sqlite3Os.xCurrentTime #define sqlite3OsEnterMutex sqlite3Os.xEnterMutex #define sqlite3OsLeaveMutex sqlite3Os.xLeaveMutex #define sqlite3OsInMutex sqlite3Os.xInMutex #define sqlite3OsThreadSpecificData sqlite3Os.xThreadSpecificData #define sqlite3OsMalloc sqlite3Os.xMalloc #define sqlite3OsRealloc sqlite3Os.xRealloc #define sqlite3OsFree sqlite3Os.xFree #define sqlite3OsAllocationSize sqlite3Os.xAllocationSize #endif /* SQLITE_ENABLE_REDEF_IO */ #endif /* _SQLITE_OS_H_ */ |
< < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 ... 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 ... 258 259 260 261 262 263 264 265 266 267 268 269 270 |
** anybody smart enough to figure out the code is also likely smart ** enough to know that calling the developer will not help get rid ** of the file. */ #ifndef TEMP_FILE_PREFIX # define TEMP_FILE_PREFIX "etilqs_" #endif /* ** If using an alternative OS interface, then we must have an "os_other.h" ** header file available for that interface. Presumably the "os_other.h" ** header file contains #defines similar to those above. */ #if OS_OTHER # include "os_other.h" #endif /* ** The following values may be passed as the second argument to ** sqlite3OsLock(). The various locks exhibit the following semantics: ** ** SHARED: Any number of processes may hold a SHARED lock simultaneously. ** RESERVED: A single process may hold a RESERVED lock on a file at ** any time. Other processes may hold and obtain new SHARED locks. ................................................................................ int sqlite3OsTruncate(sqlite3_file*, i64 size); int sqlite3OsSync(sqlite3_file*, int); int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); int sqlite3OsLock(sqlite3_file*, int); int sqlite3OsUnlock(sqlite3_file*, int); int sqlite3OsBreakLock(sqlite3_file*); int sqlite3OsCheckReservedLock(sqlite3_file *id); int sqlite3OsLockState(sqlite3_file *id); int sqlite3OsSectorSize(sqlite3_file *id); int sqlite3OsDeviceCharacteristics(sqlite3_file *id); /* ** Functions for accessing sqlite3_vfs methods */ int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); ................................................................................ /* ** Convenience functions for opening and closing files using ** sqlite3_malloc() to obtain space for the file-handle structure. */ int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int); int sqlite3OsCloseFree(sqlite3_file *); #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) int sqlite3OsFileHandle(sqlite3_file *id); int sqlite3OsLockState(sqlite3_file *id); #endif #endif /* _SQLITE_OS_H_ */ |
Changes to src/os_unix.c.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 ... 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 ... 929 930 931 932 933 934 935 936 937 938 939 940 941 942 ... 948 949 950 951 952 953 954 955 956 957 958 959 960 961 .... 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 .... 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 .... 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 .... 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 .... 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 .... 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 .... 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 .... 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 .... 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 |
struct lockInfo *pLock; /* Info about locks on this inode */ #ifdef SQLITE_ENABLE_LOCKING_STYLE void *lockingContext; /* Locking style specific state */ #endif /* SQLITE_ENABLE_LOCKING_STYLE */ int h; /* The file descriptor */ unsigned char locktype; /* The type of lock held on this fd */ unsigned char isOpen; /* True if needs to be closed */ unsigned char fullSync; /* Use F_FULLSYNC if available */ int dirfd; /* File descriptor for the directory */ i64 offset; /* Seek offset */ #ifdef SQLITE_UNIX_THREADS pthread_t tid; /* The thread that "owns" this OsFile */ #endif }; ................................................................................ /* ** Return TRUE if the named file exists. */ int sqlite3UnixFileExists(const char *zFilename){ return access(zFilename, 0)==0; } /* Forward declaration */ static int allocateUnixFile( int h, /* File descriptor of the open file */ sqlite3_file **pId, /* Write the real file descriptor here */ const char *zFilename, /* Name of the file being opened */ int delFlag /* If true, make sure the file deletes on close */ ); /* ** Attempt to open a file for both reading and writing. If that ** fails, try opening it read-only. If the file does not exist, ** try to create it. ** ** On success, a handle for the open file is written to *id ** and *pReadonly is set to 0 if the file was opened for reading and ................................................................................ ** On success, a handle for a previously open file at *id is ** updated with the new directory file descriptor and SQLITE_OK is ** returned. ** ** On failure, the function returns SQLITE_CANTOPEN and leaves ** *id unchanged. */ static int unixOpenDirectory( OsFile *id, const char *zDirname ){ int h; unixFile *pFile = (unixFile*)id; assert( pFile!=0 ); ................................................................................ } #ifdef FD_CLOEXEC fcntl(h, F_SETFD, fcntl(h, F_GETFD, 0) | FD_CLOEXEC); #endif OSTRACE3("OPENDIR %-3d %s\n", h, zDirname); return SQLITE_OK; } /* ** Check that a given pathname is a directory and is writable ** */ int sqlite3UnixIsDirWritable(char *zBuf){ #ifndef SQLITE_OMIT_PAGER_PRAGMAS ................................................................................ }else{ return SQLITE_FULL; } } return SQLITE_OK; } /* ** Move the read/write pointer in a file. */ static int unixSeek(OsFile *id, i64 offset){ assert( id ); #ifdef SQLITE_TEST if( offset ) SimulateDiskfullError(return SQLITE_FULL); #endif ((unixFile*)id)->offset = offset; return SQLITE_OK; } #ifdef SQLITE_TEST /* ** Count the number of fullsyncs and normal syncs. This is used to test ** that syncs and fullsyncs are occuring at the right times. */ int sqlite3_sync_count = 0; int sqlite3_fullsync_count = 0; ................................................................................ ** has been created by fsync-ing the directory that contains the file. ** If we do not do this and we encounter a power failure, the directory ** entry for the journal might not exist after we reboot. The next ** SQLite to access the file will not know that the journal exists (because ** the directory entry for the journal was never created) and the transaction ** will not roll back - possibly leading to database corruption. */ static int unixSync(sqlite3_file *id, int dataOnly){ int rc; unixFile *pFile = (unixFile*)id; assert( pFile ); OSTRACE2("SYNC %-3d\n", pFile->h); rc = full_fsync(pFile->h, pFile->fullSync, dataOnly); SimulateIOError( rc=1 ); if( rc ){ return SQLITE_IOERR_FSYNC; } if( pFile->dirfd>=0 ){ OSTRACE4("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, HAVE_FULLFSYNC, pFile->fullSync); #ifndef SQLITE_DISABLE_DIRSYNC /* The directory sync is only attempted if full_fsync is ** turned off or unavailable. If a full_fsync occurred above, ** then the directory sync is superfluous. */ if( (!HAVE_FULLFSYNC || !pFile->fullSync) && full_fsync(pFile->dirfd,0,0) ){ /* ** We have received multiple reports of fsync() returning ** errors when applied to directories on certain file systems. ** A failed directory sync is not a big deal. So it seems ** better to ignore the error. Ticket #1657 */ /* return SQLITE_IOERR; */ ................................................................................ sqlite3_free(id); *pId = 0; return SQLITE_OK; } #endif /* SQLITE_ENABLE_LOCKING_STYLE */ /* ** Change the value of the fullsync flag in the given file descriptor. */ static void unixSetFullSync(OsFile *id, int v){ ((unixFile*)id)->fullSync = v; } ................................................................................ /* ** Return the underlying file handle for an OsFile */ static int unixFileHandle(OsFile *id){ return ((unixFile*)id)->h; } /* ** Return an integer that indices the type of lock currently held ** by this handle. (Used for testing and analysis only.) */ static int unixLockState(OsFile *id){ return ((unixFile*)id)->locktype; } /* ** Return the sector size in bytes of the underlying block device for ** the specified file. This is almost always 512 bytes, but may be ** larger for some devices. ** ** SQLite code assumes this function cannot fail. It also assumes that ................................................................................ ** a database and it's journal file) that the sector size will be the ** same for both. */ static int unixSectorSize(sqlite3_file *id){ return SQLITE_DEFAULT_SECTOR_SIZE; } static int unixDeviceCharacteristics(sqlite3_file *id){ return 0; } static int unixBreakLock(sqlite3_file *id){ assert(!"TODO: unixBreakLock()"); return 0; } /* ** This vector defines all the methods that can operate on an OsFile ** for unix. */ static const sqlite3_io_methods sqlite3UnixIoMethod = { 1, /* iVersion */ ................................................................................ unixTruncate, unixSync, unixFileSize, unixLock, unixUnlock, unixCheckReservedLock, unixBreakLock, unixSectorSize, unixDeviceCharacteristics }; #ifdef SQLITE_ENABLE_LOCKING_STYLE /* ** This vector defines all the methods that can operate on an OsFile ................................................................................ */ static int unixDelete(void *pNotUsed, const char *zPath){ SimulateIOError(return SQLITE_IOERR_DELETE); unlink(zPath); return SQLITE_OK; } static int unixAccess(void *pNotUsed, const char *zPath, int flags){ int amode; switch( flags ){ case SQLITE_ACCESS_EXISTS: amode = F_OK; break; case SQLITE_ACCESS_READWRITE: ................................................................................ #define unixDlOpen 0 #define unixDlError 0 #define unixDlSym 0 #define unixDlClose 0 #endif /* ** Both arguments are integers. This macro returns the lowest of the ** two arguments. */ #define MIN(x,y) ((x)>(y)?(y):(x)) /* ** Get information to seed the random number generator. The seed ** is written into the buffer zBuf[256]. The calling function must ** supply a sufficiently large buffer. */ static int unixRandomness(void *pNotUsed, int nBuf, char *zBuf){ /* We have to initialize zBuf to prevent valgrind from reporting ** errors. The reports issued by valgrind are incorrect - we would ** prefer that the randomness be increased by making use of the ** uninitialized space in zBuf - but valgrind errors tend to worry ** some users. Rather than argue, it seems easier just to initialize ** the whole array and silence valgrind, even if that means less randomness ** in the random seed. ................................................................................ #if !defined(SQLITE_TEST) { int pid, fd; fd = open("/dev/urandom", O_RDONLY); if( fd<0 ){ time_t t; time(&t); memcpy(zBuf, &t, MIN(nBuf, sizeof(t))); if( (nBuf-sizeof(t))>0 ){ pid = getpid(); memcpy(&zBuf[sizeof(t)], &pid, MIN(nBuf-sizeof(t), sizeof(pid))); } }else{ read(fd, zBuf, nBuf); close(fd); } } #endif return SQLITE_OK; |
< < < < < < < < < > > < < < < < < < < < < < < | > > > > | | | > < < < < < < < > > > > > > > > > > > > > > > > > > > > > > > | < < < < < < < < > > > | < | | < |
91 92 93 94 95 96 97 98 99 100 101 102 103 104 ... 802 803 804 805 806 807 808 809 810 811 812 813 814 815 ... 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 ... 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 .... 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 .... 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 .... 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 .... 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 .... 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 .... 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 .... 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 .... 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 .... 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 |
struct lockInfo *pLock; /* Info about locks on this inode */ #ifdef SQLITE_ENABLE_LOCKING_STYLE void *lockingContext; /* Locking style specific state */ #endif /* SQLITE_ENABLE_LOCKING_STYLE */ int h; /* The file descriptor */ unsigned char locktype; /* The type of lock held on this fd */ unsigned char isOpen; /* True if needs to be closed */ int dirfd; /* File descriptor for the directory */ i64 offset; /* Seek offset */ #ifdef SQLITE_UNIX_THREADS pthread_t tid; /* The thread that "owns" this OsFile */ #endif }; ................................................................................ /* ** Return TRUE if the named file exists. */ int sqlite3UnixFileExists(const char *zFilename){ return access(zFilename, 0)==0; } /* ** Attempt to open a file for both reading and writing. If that ** fails, try opening it read-only. If the file does not exist, ** try to create it. ** ** On success, a handle for the open file is written to *id ** and *pReadonly is set to 0 if the file was opened for reading and ................................................................................ ** On success, a handle for a previously open file at *id is ** updated with the new directory file descriptor and SQLITE_OK is ** returned. ** ** On failure, the function returns SQLITE_CANTOPEN and leaves ** *id unchanged. */ #if 0 static int unixOpenDirectory( OsFile *id, const char *zDirname ){ int h; unixFile *pFile = (unixFile*)id; assert( pFile!=0 ); ................................................................................ } #ifdef FD_CLOEXEC fcntl(h, F_SETFD, fcntl(h, F_GETFD, 0) | FD_CLOEXEC); #endif OSTRACE3("OPENDIR %-3d %s\n", h, zDirname); return SQLITE_OK; } #endif /* ** Check that a given pathname is a directory and is writable ** */ int sqlite3UnixIsDirWritable(char *zBuf){ #ifndef SQLITE_OMIT_PAGER_PRAGMAS ................................................................................ }else{ return SQLITE_FULL; } } return SQLITE_OK; } #ifdef SQLITE_TEST /* ** Count the number of fullsyncs and normal syncs. This is used to test ** that syncs and fullsyncs are occuring at the right times. */ int sqlite3_sync_count = 0; int sqlite3_fullsync_count = 0; ................................................................................ ** has been created by fsync-ing the directory that contains the file. ** If we do not do this and we encounter a power failure, the directory ** entry for the journal might not exist after we reboot. The next ** SQLite to access the file will not know that the journal exists (because ** the directory entry for the journal was never created) and the transaction ** will not roll back - possibly leading to database corruption. */ static int unixSync(sqlite3_file *id, int flags){ int rc; unixFile *pFile = (unixFile*)id; int isDataOnly = (flags & SQLITE_SYNC_DATAONLY); int isFullsync = (flags & SQLITE_SYNC_FULL); assert( pFile ); OSTRACE2("SYNC %-3d\n", pFile->h); rc = full_fsync(pFile->h, isFullsync, isDataOnly); SimulateIOError( rc=1 ); if( rc ){ return SQLITE_IOERR_FSYNC; } if( pFile->dirfd>=0 ){ OSTRACE4("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, HAVE_FULLFSYNC, isFullsync); #ifndef SQLITE_DISABLE_DIRSYNC /* The directory sync is only attempted if full_fsync is ** turned off or unavailable. If a full_fsync occurred above, ** then the directory sync is superfluous. */ if( (!HAVE_FULLFSYNC || !isFullsync) && full_fsync(pFile->dirfd,0,0) ){ /* ** We have received multiple reports of fsync() returning ** errors when applied to directories on certain file systems. ** A failed directory sync is not a big deal. So it seems ** better to ignore the error. Ticket #1657 */ /* return SQLITE_IOERR; */ ................................................................................ sqlite3_free(id); *pId = 0; return SQLITE_OK; } #endif /* SQLITE_ENABLE_LOCKING_STYLE */ #if 0 /* ** Change the value of the fullsync flag in the given file descriptor. */ static void unixSetFullSync(OsFile *id, int v){ ((unixFile*)id)->fullSync = v; } ................................................................................ /* ** Return the underlying file handle for an OsFile */ static int unixFileHandle(OsFile *id){ return ((unixFile*)id)->h; } #endif /* ** Return the sector size in bytes of the underlying block device for ** the specified file. This is almost always 512 bytes, but may be ** larger for some devices. ** ** SQLite code assumes this function cannot fail. It also assumes that ................................................................................ ** a database and it's journal file) that the sector size will be the ** same for both. */ static int unixSectorSize(sqlite3_file *id){ return SQLITE_DEFAULT_SECTOR_SIZE; } /* ** Return the device characteristics for the file. This is always 0. */ static int unixDeviceCharacteristics(sqlite3_file *id){ return 0; } static int unixBreakLock(sqlite3_file *id){ assert(!"TODO: unixBreakLock()"); return 0; } /* ** Return an integer that indices the type of lock currently held ** by this handle. (Used for testing and analysis only.) */ static int unixLockState(sqlite3_file *id){ return ((unixFile*)id)->locktype; } /* ** This vector defines all the methods that can operate on an OsFile ** for unix. */ static const sqlite3_io_methods sqlite3UnixIoMethod = { 1, /* iVersion */ ................................................................................ unixTruncate, unixSync, unixFileSize, unixLock, unixUnlock, unixCheckReservedLock, unixBreakLock, unixLockState, unixSectorSize, unixDeviceCharacteristics }; #ifdef SQLITE_ENABLE_LOCKING_STYLE /* ** This vector defines all the methods that can operate on an OsFile ................................................................................ */ static int unixDelete(void *pNotUsed, const char *zPath){ SimulateIOError(return SQLITE_IOERR_DELETE); unlink(zPath); return SQLITE_OK; } /* ** Test the existance of or access permissions of file zPath. The ** test performed depends on the value of flags: ** ** SQLITE_ACCESS_EXISTS: Return 1 if the file exists ** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable. ** SQLITE_ACCESS_READONLY: Return 1 if the file is readable. ** ** Otherwise return 0. */ static int unixAccess(void *pNotUsed, const char *zPath, int flags){ int amode; switch( flags ){ case SQLITE_ACCESS_EXISTS: amode = F_OK; break; case SQLITE_ACCESS_READWRITE: ................................................................................ #define unixDlOpen 0 #define unixDlError 0 #define unixDlSym 0 #define unixDlClose 0 #endif /* ** Write nBuf bytes of random data to the supplied buffer zBuf. */ static int unixRandomness(void *pNotUsed, int nBuf, char *zBuf){ assert(nBuf>=(sizeof(time_t)+sizeof(int))); /* We have to initialize zBuf to prevent valgrind from reporting ** errors. The reports issued by valgrind are incorrect - we would ** prefer that the randomness be increased by making use of the ** uninitialized space in zBuf - but valgrind errors tend to worry ** some users. Rather than argue, it seems easier just to initialize ** the whole array and silence valgrind, even if that means less randomness ** in the random seed. ................................................................................ #if !defined(SQLITE_TEST) { int pid, fd; fd = open("/dev/urandom", O_RDONLY); if( fd<0 ){ time_t t; time(&t); memcpy(zBuf, &t, sizeof(t)); pid = getpid(); memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); }else{ read(fd, zBuf, nBuf); close(fd); } } #endif return SQLITE_OK; |
Changes to src/sqlite.h.in.
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
492
493
494
495
496
497
498
499
500
501
502
503
504
505
|
** on how SQLite interfaces are suppose to operate. ** ** The name of this file under configuration management is "sqlite.h.in". ** The makefile makes some minor changes to this file (such as inserting ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** ** @(#) $Id: sqlite.h.in,v 1.228 2007/08/17 15:53:37 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ #include <stdarg.h> /* Needed for the definition of va_list */ /* ** Make sure we can call this stuff from C++. ................................................................................ int (*xTruncate)(sqlite3_file*, sqlite_int64 size); int (*xSync)(sqlite3_file*, int flags); int (*xFileSize)(sqlite3_file*, sqlite_int64 *pSize); int (*xLock)(sqlite3_file*, int); int (*xUnlock)(sqlite3_file*, int); int (*xCheckReservedLock)(sqlite3_file*); int (*xBreakLock)(sqlite3_file*); int (*xSectorSize)(sqlite3_file*); int (*xDeviceCharacteristics)(sqlite3_file*); /* Additional methods may be added in future releases */ }; /* ** CAPI3REF: Mutex Handle |
|
>
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
** on how SQLite interfaces are suppose to operate. ** ** The name of this file under configuration management is "sqlite.h.in". ** The makefile makes some minor changes to this file (such as inserting ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** ** @(#) $Id: sqlite.h.in,v 1.229 2007/08/17 16:50:38 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ #include <stdarg.h> /* Needed for the definition of va_list */ /* ** Make sure we can call this stuff from C++. ................................................................................ int (*xTruncate)(sqlite3_file*, sqlite_int64 size); int (*xSync)(sqlite3_file*, int flags); int (*xFileSize)(sqlite3_file*, sqlite_int64 *pSize); int (*xLock)(sqlite3_file*, int); int (*xUnlock)(sqlite3_file*, int); int (*xCheckReservedLock)(sqlite3_file*); int (*xBreakLock)(sqlite3_file*); int (*xLockState)(sqlite3_file *); int (*xSectorSize)(sqlite3_file*); int (*xDeviceCharacteristics)(sqlite3_file*); /* Additional methods may be added in future releases */ }; /* ** CAPI3REF: Mutex Handle |