00001 /* 00002 ** 2001 September 16 00003 ** 00004 ** The author disclaims copyright to this source code. In place of 00005 ** a legal notice, here is a blessing: 00006 ** 00007 ** May you do good and not evil. 00008 ** May you find forgiveness for yourself and forgive others. 00009 ** May you share freely, never taking more than you give. 00010 ** 00011 ****************************************************************************** 00012 ** 00013 ** This header file (together with is companion C source-code file 00014 ** "os.c") attempt to abstract the underlying operating system so that 00015 ** the SQLite library will work on both POSIX and windows systems. 00016 ** 00017 ** This header file is #include-ed by sqliteInt.h and thus ends up 00018 ** being included by every source file. 00019 ** 00020 ** $Id: os.h,v 1.105 2008/06/26 10:41:19 danielk1977 Exp $ 00021 */ 00022 #ifndef _SQLITE_OS_H_ 00023 #define _SQLITE_OS_H_ 00024 00025 /* 00026 ** Figure out if we are dealing with Unix, Windows, or some other 00027 ** operating system. After the following block of preprocess macros, 00028 ** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER 00029 ** will defined to either 1 or 0. One of the four will be 1. The other 00030 ** three will be 0. 00031 */ 00032 #if defined(SQLITE_OS_OTHER) 00033 # if SQLITE_OS_OTHER==1 00034 # undef SQLITE_OS_UNIX 00035 # define SQLITE_OS_UNIX 0 00036 # undef SQLITE_OS_WIN 00037 # define SQLITE_OS_WIN 0 00038 # undef SQLITE_OS_OS2 00039 # define SQLITE_OS_OS2 0 00040 # else 00041 # undef SQLITE_OS_OTHER 00042 # endif 00043 #endif 00044 #if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) 00045 # define SQLITE_OS_OTHER 0 00046 # ifndef SQLITE_OS_WIN 00047 # if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__) 00048 # define SQLITE_OS_WIN 1 00049 # define SQLITE_OS_UNIX 0 00050 # define SQLITE_OS_OS2 0 00051 # elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__) 00052 # define SQLITE_OS_WIN 0 00053 # define SQLITE_OS_UNIX 0 00054 # define SQLITE_OS_OS2 1 00055 # else 00056 # define SQLITE_OS_WIN 0 00057 # define SQLITE_OS_UNIX 1 00058 # define SQLITE_OS_OS2 0 00059 # endif 00060 # else 00061 # define SQLITE_OS_UNIX 0 00062 # define SQLITE_OS_OS2 0 00063 # endif 00064 #else 00065 # ifndef SQLITE_OS_WIN 00066 # define SQLITE_OS_WIN 0 00067 # endif 00068 #endif 00069 00070 /* 00071 ** Determine if we are dealing with WindowsCE - which has a much 00072 ** reduced API. 00073 */ 00074 #if defined(_WIN32_WCE) 00075 # define SQLITE_OS_WINCE 1 00076 #else 00077 # define SQLITE_OS_WINCE 0 00078 #endif 00079 00080 00081 /* 00082 ** Define the maximum size of a temporary filename 00083 */ 00084 #if SQLITE_OS_WIN 00085 # include <windows.h> 00086 # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) 00087 #elif SQLITE_OS_OS2 00088 # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY) 00089 # include <os2safe.h> /* has to be included before os2.h for linking to work */ 00090 # endif 00091 # define INCL_DOSDATETIME 00092 # define INCL_DOSFILEMGR 00093 # define INCL_DOSERRORS 00094 # define INCL_DOSMISC 00095 # define INCL_DOSPROCESS 00096 # define INCL_DOSMODULEMGR 00097 # define INCL_DOSSEMAPHORES 00098 # include <os2.h> 00099 # include <uconv.h> 00100 # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP) 00101 #else 00102 # define SQLITE_TEMPNAME_SIZE 200 00103 #endif 00104 00105 /* If the SET_FULLSYNC macro is not defined above, then make it 00106 ** a no-op 00107 */ 00108 #ifndef SET_FULLSYNC 00109 # define SET_FULLSYNC(x,y) 00110 #endif 00111 00112 /* 00113 ** The default size of a disk sector 00114 */ 00115 #ifndef SQLITE_DEFAULT_SECTOR_SIZE 00116 # define SQLITE_DEFAULT_SECTOR_SIZE 512 00117 #endif 00118 00119 /* 00120 ** Temporary files are named starting with this prefix followed by 16 random 00121 ** alphanumeric characters, and no file extension. They are stored in the 00122 ** OS's standard temporary file directory, and are deleted prior to exit. 00123 ** If sqlite is being embedded in another program, you may wish to change the 00124 ** prefix to reflect your program's name, so that if your program exits 00125 ** prematurely, old temporary files can be easily identified. This can be done 00126 ** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line. 00127 ** 00128 ** 2006-10-31: The default prefix used to be "sqlite_". But then 00129 ** Mcafee started using SQLite in their anti-virus product and it 00130 ** started putting files with the "sqlite" name in the c:/temp folder. 00131 ** This annoyed many windows users. Those users would then do a 00132 ** Google search for "sqlite", find the telephone numbers of the 00133 ** developers and call to wake them up at night and complain. 00134 ** For this reason, the default name prefix is changed to be "sqlite" 00135 ** spelled backwards. So the temp files are still identified, but 00136 ** anybody smart enough to figure out the code is also likely smart 00137 ** enough to know that calling the developer will not help get rid 00138 ** of the file. 00139 */ 00140 #ifndef SQLITE_TEMP_FILE_PREFIX 00141 # define SQLITE_TEMP_FILE_PREFIX "etilqs_" 00142 #endif 00143 00144 /* 00145 ** The following values may be passed as the second argument to 00146 ** sqlite3OsLock(). The various locks exhibit the following semantics: 00147 ** 00148 ** SHARED: Any number of processes may hold a SHARED lock simultaneously. 00149 ** RESERVED: A single process may hold a RESERVED lock on a file at 00150 ** any time. Other processes may hold and obtain new SHARED locks. 00151 ** PENDING: A single process may hold a PENDING lock on a file at 00152 ** any one time. Existing SHARED locks may persist, but no new 00153 ** SHARED locks may be obtained by other processes. 00154 ** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks. 00155 ** 00156 ** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a 00157 ** process that requests an EXCLUSIVE lock may actually obtain a PENDING 00158 ** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to 00159 ** sqlite3OsLock(). 00160 */ 00161 #define NO_LOCK 0 00162 #define SHARED_LOCK 1 00163 #define RESERVED_LOCK 2 00164 #define PENDING_LOCK 3 00165 #define EXCLUSIVE_LOCK 4 00166 00167 /* 00168 ** File Locking Notes: (Mostly about windows but also some info for Unix) 00169 ** 00170 ** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because 00171 ** those functions are not available. So we use only LockFile() and 00172 ** UnlockFile(). 00173 ** 00174 ** LockFile() prevents not just writing but also reading by other processes. 00175 ** A SHARED_LOCK is obtained by locking a single randomly-chosen 00176 ** byte out of a specific range of bytes. The lock byte is obtained at 00177 ** random so two separate readers can probably access the file at the 00178 ** same time, unless they are unlucky and choose the same lock byte. 00179 ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range. 00180 ** There can only be one writer. A RESERVED_LOCK is obtained by locking 00181 ** a single byte of the file that is designated as the reserved lock byte. 00182 ** A PENDING_LOCK is obtained by locking a designated byte different from 00183 ** the RESERVED_LOCK byte. 00184 ** 00185 ** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available, 00186 ** which means we can use reader/writer locks. When reader/writer locks 00187 ** are used, the lock is placed on the same range of bytes that is used 00188 ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme 00189 ** will support two or more Win95 readers or two or more WinNT readers. 00190 ** But a single Win95 reader will lock out all WinNT readers and a single 00191 ** WinNT reader will lock out all other Win95 readers. 00192 ** 00193 ** The following #defines specify the range of bytes used for locking. 00194 ** SHARED_SIZE is the number of bytes available in the pool from which 00195 ** a random byte is selected for a shared lock. The pool of bytes for 00196 ** shared locks begins at SHARED_FIRST. 00197 ** 00198 ** These #defines are available in sqlite_aux.h so that adaptors for 00199 ** connecting SQLite to other operating systems can use the same byte 00200 ** ranges for locking. In particular, the same locking strategy and 00201 ** byte ranges are used for Unix. This leaves open the possiblity of having 00202 ** clients on win95, winNT, and unix all talking to the same shared file 00203 ** and all locking correctly. To do so would require that samba (or whatever 00204 ** tool is being used for file sharing) implements locks correctly between 00205 ** windows and unix. I'm guessing that isn't likely to happen, but by 00206 ** using the same locking range we are at least open to the possibility. 00207 ** 00208 ** Locking in windows is manditory. For this reason, we cannot store 00209 ** actual data in the bytes used for locking. The pager never allocates 00210 ** the pages involved in locking therefore. SHARED_SIZE is selected so 00211 ** that all locks will fit on a single page even at the minimum page size. 00212 ** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE 00213 ** is set high so that we don't have to allocate an unused page except 00214 ** for very large databases. But one should test the page skipping logic 00215 ** by setting PENDING_BYTE low and running the entire regression suite. 00216 ** 00217 ** Changing the value of PENDING_BYTE results in a subtly incompatible 00218 ** file format. Depending on how it is changed, you might not notice 00219 ** the incompatibility right away, even running a full regression test. 00220 ** The default location of PENDING_BYTE is the first byte past the 00221 ** 1GB boundary. 00222 ** 00223 */ 00224 #ifndef SQLITE_TEST 00225 #define PENDING_BYTE 0x40000000 /* First byte past the 1GB boundary */ 00226 #else 00227 extern unsigned int sqlite3_pending_byte; 00228 #define PENDING_BYTE sqlite3_pending_byte 00229 #endif 00230 00231 #define RESERVED_BYTE (PENDING_BYTE+1) 00232 #define SHARED_FIRST (PENDING_BYTE+2) 00233 #define SHARED_SIZE 510 00234 00235 /* 00236 ** Functions for accessing sqlite3_file methods 00237 */ 00238 int sqlite3OsClose(sqlite3_file*); 00239 int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset); 00240 int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset); 00241 int sqlite3OsTruncate(sqlite3_file*, i64 size); 00242 int sqlite3OsSync(sqlite3_file*, int); 00243 int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); 00244 int sqlite3OsLock(sqlite3_file*, int); 00245 int sqlite3OsUnlock(sqlite3_file*, int); 00246 int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); 00247 int sqlite3OsFileControl(sqlite3_file*,int,void*); 00248 int sqlite3OsSectorSize(sqlite3_file *id); 00249 int sqlite3OsDeviceCharacteristics(sqlite3_file *id); 00250 00251 /* 00252 ** Functions for accessing sqlite3_vfs methods 00253 */ 00254 int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); 00255 int sqlite3OsDelete(sqlite3_vfs *, const char *, int); 00256 int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut); 00257 int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *); 00258 #ifndef SQLITE_OMIT_LOAD_EXTENSION 00259 void *sqlite3OsDlOpen(sqlite3_vfs *, const char *); 00260 void sqlite3OsDlError(sqlite3_vfs *, int, char *); 00261 void *sqlite3OsDlSym(sqlite3_vfs *, void *, const char *); 00262 void sqlite3OsDlClose(sqlite3_vfs *, void *); 00263 #endif /* SQLITE_OMIT_LOAD_EXTENSION */ 00264 int sqlite3OsRandomness(sqlite3_vfs *, int, char *); 00265 int sqlite3OsSleep(sqlite3_vfs *, int); 00266 int sqlite3OsCurrentTime(sqlite3_vfs *, double*); 00267 00268 /* 00269 ** Convenience functions for opening and closing files using 00270 ** sqlite3_malloc() to obtain space for the file-handle structure. 00271 */ 00272 int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*); 00273 int sqlite3OsCloseFree(sqlite3_file *); 00274 00275 #endif /* _SQLITE_OS_H_ */
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:55 2011 by Doxygen 1.6.1