| OLD | NEW | 
 | (Empty) | 
|    1 /* |  | 
|    2 ** 2001 September 16 |  | 
|    3 ** |  | 
|    4 ** The author disclaims copyright to this source code.  In place of |  | 
|    5 ** a legal notice, here is a blessing: |  | 
|    6 ** |  | 
|    7 **    May you do good and not evil. |  | 
|    8 **    May you find forgiveness for yourself and forgive others. |  | 
|    9 **    May you share freely, never taking more than you give. |  | 
|   10 ** |  | 
|   11 ****************************************************************************** |  | 
|   12 ** |  | 
|   13 ** This header file (together with is companion C source-code file |  | 
|   14 ** "os.c") attempt to abstract the underlying operating system so that |  | 
|   15 ** the SQLite library will work on both POSIX and windows systems. |  | 
|   16 ** |  | 
|   17 ** This header file is #include-ed by sqliteInt.h and thus ends up |  | 
|   18 ** being included by every source file. |  | 
|   19 ** |  | 
|   20 ** $Id: os.h,v 1.108 2009/02/05 16:31:46 drh Exp $ |  | 
|   21 */ |  | 
|   22 #ifndef _SQLITE_OS_H_ |  | 
|   23 #define _SQLITE_OS_H_ |  | 
|   24  |  | 
|   25 /* |  | 
|   26 ** Figure out if we are dealing with Unix, Windows, or some other |  | 
|   27 ** operating system.  After the following block of preprocess macros, |  | 
|   28 ** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER  |  | 
|   29 ** will defined to either 1 or 0.  One of the four will be 1.  The other  |  | 
|   30 ** three will be 0. |  | 
|   31 */ |  | 
|   32 #ifdef OS_SYMBIAN |  | 
|   33 # define SQLITE_OS_SYMBIAN 1 |  | 
|   34 # define SQLITE_OS_OTHER 1 |  | 
|   35 #endif |  | 
|   36 #if defined(SQLITE_OS_OTHER) |  | 
|   37 # if SQLITE_OS_OTHER==1 |  | 
|   38 #   undef SQLITE_OS_UNIX |  | 
|   39 #   define SQLITE_OS_UNIX 0 |  | 
|   40 #   undef SQLITE_OS_WIN |  | 
|   41 #   define SQLITE_OS_WIN 0 |  | 
|   42 #   undef SQLITE_OS_OS2 |  | 
|   43 #   define SQLITE_OS_OS2 0 |  | 
|   44 # else |  | 
|   45 #   undef SQLITE_OS_OTHER |  | 
|   46 # endif |  | 
|   47 #endif |  | 
|   48 #if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) |  | 
|   49 # define SQLITE_OS_OTHER 0 |  | 
|   50 # ifndef SQLITE_OS_WIN |  | 
|   51 #   if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MIN
     GW32__) || defined(__BORLANDC__) |  | 
|   52 #     define SQLITE_OS_WIN 1 |  | 
|   53 #     define SQLITE_OS_UNIX 0 |  | 
|   54 #     define SQLITE_OS_OS2 0 |  | 
|   55 #   elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || 
     defined(__OS2__) |  | 
|   56 #     define SQLITE_OS_WIN 0 |  | 
|   57 #     define SQLITE_OS_UNIX 0 |  | 
|   58 #     define SQLITE_OS_OS2 1 |  | 
|   59 #   else |  | 
|   60 #     define SQLITE_OS_WIN 0 |  | 
|   61 #     define SQLITE_OS_UNIX 1 |  | 
|   62 #     define SQLITE_OS_OS2 0 |  | 
|   63 #  endif |  | 
|   64 # else |  | 
|   65 #  define SQLITE_OS_UNIX 0 |  | 
|   66 #  define SQLITE_OS_OS2 0 |  | 
|   67 # endif |  | 
|   68 #else |  | 
|   69 # ifndef SQLITE_OS_WIN |  | 
|   70 #  define SQLITE_OS_WIN 0 |  | 
|   71 # endif |  | 
|   72 #endif |  | 
|   73  |  | 
|   74 /* |  | 
|   75 ** Determine if we are dealing with WindowsCE - which has a much |  | 
|   76 ** reduced API. |  | 
|   77 */ |  | 
|   78 #if defined(_WIN32_WCE) |  | 
|   79 # define SQLITE_OS_WINCE 1 |  | 
|   80 #else |  | 
|   81 # define SQLITE_OS_WINCE 0 |  | 
|   82 #endif |  | 
|   83  |  | 
|   84  |  | 
|   85 /* |  | 
|   86 ** Define the maximum size of a temporary filename |  | 
|   87 */ |  | 
|   88 #if SQLITE_OS_WIN |  | 
|   89 # include <windows.h> |  | 
|   90 # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50) |  | 
|   91 #elif SQLITE_OS_OS2 |  | 
|   92 # if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_
     MEMORY) |  | 
|   93 #  include <os2safe.h> /* has to be included before os2.h for linking to work */ |  | 
|   94 # endif |  | 
|   95 # define INCL_DOSDATETIME |  | 
|   96 # define INCL_DOSFILEMGR |  | 
|   97 # define INCL_DOSERRORS |  | 
|   98 # define INCL_DOSMISC |  | 
|   99 # define INCL_DOSPROCESS |  | 
|  100 # define INCL_DOSMODULEMGR |  | 
|  101 # define INCL_DOSSEMAPHORES |  | 
|  102 # include <os2.h> |  | 
|  103 # include <uconv.h> |  | 
|  104 # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP) |  | 
|  105 #else |  | 
|  106 # define SQLITE_TEMPNAME_SIZE 200 |  | 
|  107 #endif |  | 
|  108  |  | 
|  109 /* If the SET_FULLSYNC macro is not defined above, then make it |  | 
|  110 ** a no-op |  | 
|  111 */ |  | 
|  112 #ifndef SET_FULLSYNC |  | 
|  113 # define SET_FULLSYNC(x,y) |  | 
|  114 #endif |  | 
|  115  |  | 
|  116 /* |  | 
|  117 ** The default size of a disk sector |  | 
|  118 */ |  | 
|  119 #ifndef SQLITE_DEFAULT_SECTOR_SIZE |  | 
|  120 # define SQLITE_DEFAULT_SECTOR_SIZE 512 |  | 
|  121 #endif |  | 
|  122  |  | 
|  123 /* |  | 
|  124 ** Temporary files are named starting with this prefix followed by 16 random |  | 
|  125 ** alphanumeric characters, and no file extension. They are stored in the |  | 
|  126 ** OS's standard temporary file directory, and are deleted prior to exit. |  | 
|  127 ** If sqlite is being embedded in another program, you may wish to change the |  | 
|  128 ** prefix to reflect your program's name, so that if your program exits |  | 
|  129 ** prematurely, old temporary files can be easily identified. This can be done |  | 
|  130 ** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line. |  | 
|  131 ** |  | 
|  132 ** 2006-10-31:  The default prefix used to be "sqlite_".  But then |  | 
|  133 ** Mcafee started using SQLite in their anti-virus product and it |  | 
|  134 ** started putting files with the "sqlite" name in the c:/temp folder. |  | 
|  135 ** This annoyed many windows users.  Those users would then do a  |  | 
|  136 ** Google search for "sqlite", find the telephone numbers of the |  | 
|  137 ** developers and call to wake them up at night and complain. |  | 
|  138 ** For this reason, the default name prefix is changed to be "sqlite"  |  | 
|  139 ** spelled backwards.  So the temp files are still identified, but |  | 
|  140 ** anybody smart enough to figure out the code is also likely smart |  | 
|  141 ** enough to know that calling the developer will not help get rid |  | 
|  142 ** of the file. |  | 
|  143 */ |  | 
|  144 #ifndef SQLITE_TEMP_FILE_PREFIX |  | 
|  145 # define SQLITE_TEMP_FILE_PREFIX "etilqs_" |  | 
|  146 #endif |  | 
|  147  |  | 
|  148 /* |  | 
|  149 ** The following values may be passed as the second argument to |  | 
|  150 ** sqlite3OsLock(). The various locks exhibit the following semantics: |  | 
|  151 ** |  | 
|  152 ** SHARED:    Any number of processes may hold a SHARED lock simultaneously. |  | 
|  153 ** RESERVED:  A single process may hold a RESERVED lock on a file at |  | 
|  154 **            any time. Other processes may hold and obtain new SHARED locks. |  | 
|  155 ** PENDING:   A single process may hold a PENDING lock on a file at |  | 
|  156 **            any one time. Existing SHARED locks may persist, but no new |  | 
|  157 **            SHARED locks may be obtained by other processes. |  | 
|  158 ** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks. |  | 
|  159 ** |  | 
|  160 ** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a |  | 
|  161 ** process that requests an EXCLUSIVE lock may actually obtain a PENDING |  | 
|  162 ** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to |  | 
|  163 ** sqlite3OsLock(). |  | 
|  164 */ |  | 
|  165 #define NO_LOCK         0 |  | 
|  166 #define SHARED_LOCK     1 |  | 
|  167 #define RESERVED_LOCK   2 |  | 
|  168 #define PENDING_LOCK    3 |  | 
|  169 #define EXCLUSIVE_LOCK  4 |  | 
|  170  |  | 
|  171 /* |  | 
|  172 ** File Locking Notes:  (Mostly about windows but also some info for Unix) |  | 
|  173 ** |  | 
|  174 ** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because |  | 
|  175 ** those functions are not available.  So we use only LockFile() and |  | 
|  176 ** UnlockFile(). |  | 
|  177 ** |  | 
|  178 ** LockFile() prevents not just writing but also reading by other processes. |  | 
|  179 ** A SHARED_LOCK is obtained by locking a single randomly-chosen  |  | 
|  180 ** byte out of a specific range of bytes. The lock byte is obtained at  |  | 
|  181 ** random so two separate readers can probably access the file at the  |  | 
|  182 ** same time, unless they are unlucky and choose the same lock byte. |  | 
|  183 ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range. |  | 
|  184 ** There can only be one writer.  A RESERVED_LOCK is obtained by locking |  | 
|  185 ** a single byte of the file that is designated as the reserved lock byte. |  | 
|  186 ** A PENDING_LOCK is obtained by locking a designated byte different from |  | 
|  187 ** the RESERVED_LOCK byte. |  | 
|  188 ** |  | 
|  189 ** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available, |  | 
|  190 ** which means we can use reader/writer locks.  When reader/writer locks |  | 
|  191 ** are used, the lock is placed on the same range of bytes that is used |  | 
|  192 ** for probabilistic locking in Win95/98/ME.  Hence, the locking scheme |  | 
|  193 ** will support two or more Win95 readers or two or more WinNT readers. |  | 
|  194 ** But a single Win95 reader will lock out all WinNT readers and a single |  | 
|  195 ** WinNT reader will lock out all other Win95 readers. |  | 
|  196 ** |  | 
|  197 ** The following #defines specify the range of bytes used for locking. |  | 
|  198 ** SHARED_SIZE is the number of bytes available in the pool from which |  | 
|  199 ** a random byte is selected for a shared lock.  The pool of bytes for |  | 
|  200 ** shared locks begins at SHARED_FIRST.  |  | 
|  201 ** |  | 
|  202 ** The same locking strategy and |  | 
|  203 ** byte ranges are used for Unix.  This leaves open the possiblity of having |  | 
|  204 ** clients on win95, winNT, and unix all talking to the same shared file |  | 
|  205 ** and all locking correctly.  To do so would require that samba (or whatever |  | 
|  206 ** tool is being used for file sharing) implements locks correctly between |  | 
|  207 ** windows and unix.  I'm guessing that isn't likely to happen, but by |  | 
|  208 ** using the same locking range we are at least open to the possibility. |  | 
|  209 ** |  | 
|  210 ** Locking in windows is manditory.  For this reason, we cannot store |  | 
|  211 ** actual data in the bytes used for locking.  The pager never allocates |  | 
|  212 ** the pages involved in locking therefore.  SHARED_SIZE is selected so |  | 
|  213 ** that all locks will fit on a single page even at the minimum page size. |  | 
|  214 ** PENDING_BYTE defines the beginning of the locks.  By default PENDING_BYTE |  | 
|  215 ** is set high so that we don't have to allocate an unused page except |  | 
|  216 ** for very large databases.  But one should test the page skipping logic  |  | 
|  217 ** by setting PENDING_BYTE low and running the entire regression suite. |  | 
|  218 ** |  | 
|  219 ** Changing the value of PENDING_BYTE results in a subtly incompatible |  | 
|  220 ** file format.  Depending on how it is changed, you might not notice |  | 
|  221 ** the incompatibility right away, even running a full regression test. |  | 
|  222 ** The default location of PENDING_BYTE is the first byte past the |  | 
|  223 ** 1GB boundary. |  | 
|  224 ** |  | 
|  225 */ |  | 
|  226 #define PENDING_BYTE      sqlite3PendingByte |  | 
|  227 #define RESERVED_BYTE     (PENDING_BYTE+1) |  | 
|  228 #define SHARED_FIRST      (PENDING_BYTE+2) |  | 
|  229 #define SHARED_SIZE       510 |  | 
|  230  |  | 
|  231 /* |  | 
|  232 ** Wrapper around OS specific sqlite3_os_init() function. |  | 
|  233 */ |  | 
|  234 int sqlite3OsInit(void); |  | 
|  235  |  | 
|  236 /*  |  | 
|  237 ** Functions for accessing sqlite3_file methods  |  | 
|  238 */ |  | 
|  239 int sqlite3OsClose(sqlite3_file*); |  | 
|  240 int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset); |  | 
|  241 int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset); |  | 
|  242 int sqlite3OsTruncate(sqlite3_file*, i64 size); |  | 
|  243 int sqlite3OsSync(sqlite3_file*, int); |  | 
|  244 int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); |  | 
|  245 int sqlite3OsLock(sqlite3_file*, int); |  | 
|  246 int sqlite3OsUnlock(sqlite3_file*, int); |  | 
|  247 int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); |  | 
|  248 int sqlite3OsFileControl(sqlite3_file*,int,void*); |  | 
|  249 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0 |  | 
|  250 int sqlite3OsSectorSize(sqlite3_file *id); |  | 
|  251 int sqlite3OsDeviceCharacteristics(sqlite3_file *id); |  | 
|  252  |  | 
|  253 /*  |  | 
|  254 ** Functions for accessing sqlite3_vfs methods  |  | 
|  255 */ |  | 
|  256 int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); |  | 
|  257 int sqlite3OsDelete(sqlite3_vfs *, const char *, int); |  | 
|  258 int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut); |  | 
|  259 int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *); |  | 
|  260 #ifndef SQLITE_OMIT_LOAD_EXTENSION |  | 
|  261 void *sqlite3OsDlOpen(sqlite3_vfs *, const char *); |  | 
|  262 void sqlite3OsDlError(sqlite3_vfs *, int, char *); |  | 
|  263 void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void); |  | 
|  264 void sqlite3OsDlClose(sqlite3_vfs *, void *); |  | 
|  265 #endif /* SQLITE_OMIT_LOAD_EXTENSION */ |  | 
|  266 int sqlite3OsRandomness(sqlite3_vfs *, int, char *); |  | 
|  267 int sqlite3OsSleep(sqlite3_vfs *, int); |  | 
|  268 int sqlite3OsCurrentTime(sqlite3_vfs *, double*); |  | 
|  269  |  | 
|  270 /* |  | 
|  271 ** Convenience functions for opening and closing files using  |  | 
|  272 ** sqlite3_malloc() to obtain space for the file-handle structure. |  | 
|  273 */ |  | 
|  274 int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*); |  | 
|  275 int sqlite3OsCloseFree(sqlite3_file *); |  | 
|  276  |  | 
|  277 #endif /* _SQLITE_OS_H_ */ |  | 
| OLD | NEW |