Annotation of embedaddon/sqlite3/src/os.h, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>