~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/sqlite/os.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#ifndef _SQLITE_OS_H_
 
18
#define _SQLITE_OS_H_
 
19
 
 
20
#include "config.h"
 
21
 
 
22
/*
 
23
** Figure out if we are dealing with Unix, Windows or MacOS.
 
24
**
 
25
** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
 
26
**      The MacOS build is designed to use CodeWarrior (tested with v8)
 
27
*/
 
28
#if !defined(OS_UNIX) && !defined(OS_TEST)
 
29
# ifndef OS_WIN
 
30
#   if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
 
31
#     define OS_WIN 1
 
32
#     define OS_UNIX 0
 
33
#   else
 
34
#     define OS_WIN 0
 
35
#     define OS_UNIX 1
 
36
#  endif
 
37
# else
 
38
#  define OS_UNIX 0
 
39
# endif
 
40
#else
 
41
# ifndef OS_WIN
 
42
#  define OS_WIN 0
 
43
# endif
 
44
#endif
 
45
 
 
46
/*
 
47
** Invoke the appropriate operating-system specific header file.
 
48
*/
 
49
#if OS_TEST
 
50
# include "os_test.h"
 
51
#endif
 
52
#if OS_UNIX
 
53
# include "os_unix.h"
 
54
#endif
 
55
#if OS_WIN
 
56
# include "os_win.h"
 
57
#endif
 
58
 
 
59
/* If the SET_FULLSYNC macro is not defined above, then make it
 
60
** a no-op
 
61
*/
 
62
#ifndef SET_FULLSYNC
 
63
# define SET_FULLSYNC(x,y)
 
64
#endif
 
65
 
 
66
/*
 
67
** Temporary files are named starting with this prefix followed by 16 random
 
68
** alphanumeric characters, and no file extension. They are stored in the
 
69
** OS's standard temporary file directory, and are deleted prior to exit.
 
70
** If sqlite is being embedded in another program, you may wish to change the
 
71
** prefix to reflect your program's name, so that if your program exits
 
72
** prematurely, old temporary files can be easily identified. This can be done
 
73
** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
 
74
*/
 
75
#ifndef TEMP_FILE_PREFIX
 
76
# define TEMP_FILE_PREFIX "sqlite_"
 
77
#endif
 
78
 
 
79
/*
 
80
** The following values may be passed as the second argument to
 
81
** sqlite3OsLock(). The various locks exhibit the following semantics:
 
82
**
 
83
** SHARED:    Any number of processes may hold a SHARED lock simultaneously.
 
84
** RESERVED:  A single process may hold a RESERVED lock on a file at
 
85
**            any time. Other processes may hold and obtain new SHARED locks.
 
86
** PENDING:   A single process may hold a PENDING lock on a file at
 
87
**            any one time. Existing SHARED locks may persist, but no new
 
88
**            SHARED locks may be obtained by other processes.
 
89
** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
 
90
**
 
91
** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
 
92
** process that requests an EXCLUSIVE lock may actually obtain a PENDING
 
93
** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
 
94
** sqlite3OsLock().
 
95
*/
 
96
#define NO_LOCK         0
 
97
#define SHARED_LOCK     1
 
98
#define RESERVED_LOCK   2
 
99
#define PENDING_LOCK    3
 
100
#define EXCLUSIVE_LOCK  4
 
101
 
 
102
/*
 
103
** File Locking Notes:  (Mostly about windows but also some info for Unix)
 
104
**
 
105
** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
 
106
** those functions are not available.  So we use only LockFile() and
 
107
** UnlockFile().
 
108
**
 
109
** LockFile() prevents not just writing but also reading by other processes.
 
110
** A SHARED_LOCK is obtained by locking a single randomly-chosen 
 
111
** byte out of a specific range of bytes. The lock byte is obtained at 
 
112
** random so two separate readers can probably access the file at the 
 
113
** same time, unless they are unlucky and choose the same lock byte.
 
114
** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
 
115
** There can only be one writer.  A RESERVED_LOCK is obtained by locking
 
116
** a single byte of the file that is designated as the reserved lock byte.
 
117
** A PENDING_LOCK is obtained by locking a designated byte different from
 
118
** the RESERVED_LOCK byte.
 
119
**
 
120
** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
 
121
** which means we can use reader/writer locks.  When reader/writer locks
 
122
** are used, the lock is placed on the same range of bytes that is used
 
123
** for probabilistic locking in Win95/98/ME.  Hence, the locking scheme
 
124
** will support two or more Win95 readers or two or more WinNT readers.
 
125
** But a single Win95 reader will lock out all WinNT readers and a single
 
126
** WinNT reader will lock out all other Win95 readers.
 
127
**
 
128
** The following #defines specify the range of bytes used for locking.
 
129
** SHARED_SIZE is the number of bytes available in the pool from which
 
130
** a random byte is selected for a shared lock.  The pool of bytes for
 
131
** shared locks begins at SHARED_FIRST. 
 
132
**
 
133
** These #defines are available in os.h so that Unix can use the same
 
134
** byte ranges for locking.  This leaves open the possiblity of having
 
135
** clients on win95, winNT, and unix all talking to the same shared file
 
136
** and all locking correctly.  To do so would require that samba (or whatever
 
137
** tool is being used for file sharing) implements locks correctly between
 
138
** windows and unix.  I'm guessing that isn't likely to happen, but by
 
139
** using the same locking range we are at least open to the possibility.
 
140
**
 
141
** Locking in windows is manditory.  For this reason, we cannot store
 
142
** actual data in the bytes used for locking.  The pager never allocates
 
143
** the pages involved in locking therefore.  SHARED_SIZE is selected so
 
144
** that all locks will fit on a single page even at the minimum page size.
 
145
** PENDING_BYTE defines the beginning of the locks.  By default PENDING_BYTE
 
146
** is set high so that we don't have to allocate an unused page except
 
147
** for very large databases.  But one should test the page skipping logic 
 
148
** by setting PENDING_BYTE low and running the entire regression suite.
 
149
**
 
150
** Changing the value of PENDING_BYTE results in a subtly incompatible
 
151
** file format.  Depending on how it is changed, you might not notice
 
152
** the incompatibility right away, even running a full regression test.
 
153
** The default location of PENDING_BYTE is the first byte past the
 
154
** 1GB boundary.
 
155
**
 
156
*/
 
157
#define PENDING_BYTE      0x40000000  /* First byte past the 1GB boundary */
 
158
/* #define PENDING_BYTE     0x5400   // Page 22 - for testing */
 
159
#define RESERVED_BYTE     (PENDING_BYTE+1)
 
160
#define SHARED_FIRST      (PENDING_BYTE+2)
 
161
#define SHARED_SIZE       510
 
162
 
 
163
 
 
164
int sqlite3OsDelete(const char*);
 
165
int sqlite3OsFileExists(const char*);
 
166
int sqlite3OsOpenReadWrite(const char*, OsFile*, int*);
 
167
int sqlite3OsOpenExclusive(const char*, OsFile*, int);
 
168
int sqlite3OsOpenReadOnly(const char*, OsFile*);
 
169
int sqlite3OsOpenDirectory(const char*, OsFile*);
 
170
int sqlite3OsSyncDirectory(const char*);
 
171
int sqlite3OsTempFileName(char*);
 
172
int sqlite3OsIsDirWritable(char*);
 
173
int sqlite3OsClose(OsFile*);
 
174
int sqlite3OsRead(OsFile*, void*, int amt);
 
175
int sqlite3OsWrite(OsFile*, const void*, int amt);
 
176
int sqlite3OsSeek(OsFile*, i64 offset);
 
177
int sqlite3OsSync(OsFile*);
 
178
int sqlite3OsTruncate(OsFile*, i64 size);
 
179
int sqlite3OsFileSize(OsFile*, i64 *pSize);
 
180
int sqlite3OsRandomSeed(char*);
 
181
int sqlite3OsSleep(int ms);
 
182
int sqlite3OsCurrentTime(double*);
 
183
int sqlite3OsFileModTime(OsFile*, double*);
 
184
void sqlite3OsEnterMutex(void);
 
185
void sqlite3OsLeaveMutex(void);
 
186
char *sqlite3OsFullPathname(const char*);
 
187
int sqlite3OsLock(OsFile*, int);
 
188
int sqlite3OsUnlock(OsFile*, int);
 
189
int sqlite3OsCheckReservedLock(OsFile *id);
 
190
 
 
191
#endif /* _SQLITE_OS_H_ */