annotate sqlite/os_os2.c @ 1532:f74a6ba233c2 trunk

[svn] - allow configdb::pnxmms::preset to set what pn preset to load on start
author nenolod
date Tue, 08 Aug 2006 02:19:55 -0700
parents b6b61becdf4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1434
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2 ** 2006 Feb 14
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4 ** The author disclaims copyright to this source code. In place of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
5 ** a legal notice, here is a blessing:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
6 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
7 ** May you do good and not evil.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
8 ** May you find forgiveness for yourself and forgive others.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
9 ** May you share freely, never taking more than you give.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
10 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
11 ******************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
12 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
13 ** This file contains code that is specific to OS/2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
14 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
15 #include "sqliteInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
16 #include "os.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
17
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
18 #if OS_OS2
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
19
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
20 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
21 ** Macros used to determine whether or not to use threads.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
22 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
23 #if defined(THREADSAFE) && THREADSAFE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
24 # define SQLITE_OS2_THREADS 1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
25 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
26
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
27 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
28 ** Include code that is common to all os_*.c files
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
29 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
30 #include "os_common.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
31
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
32 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
33 ** The os2File structure is subclass of OsFile specific for the OS/2
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
34 ** protability layer.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
35 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
36 typedef struct os2File os2File;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
37 struct os2File {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
38 IoMethod const *pMethod; /* Always the first entry */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
39 HFILE h; /* Handle for accessing the file */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
40 int delOnClose; /* True if file is to be deleted on close */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
41 char* pathToDel; /* Name of file to delete on close */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
42 unsigned char locktype; /* Type of lock currently held on this file */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
43 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
44
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
45 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
46 ** Do not include any of the File I/O interface procedures if the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
47 ** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
48 ** will be in-memory only)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
49 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
50 #ifndef SQLITE_OMIT_DISKIO
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
51
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
52 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
53 ** Delete the named file
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
54 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
55 int sqlite3Os2Delete( const char *zFilename ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
56 DosDelete( (PSZ)zFilename );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
57 TRACE2( "DELETE \"%s\"\n", zFilename );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
58 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
59 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
60
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
61 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
62 ** Return TRUE if the named file exists.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
63 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
64 int sqlite3Os2FileExists( const char *zFilename ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
65 FILESTATUS3 fsts3ConfigInfo;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
66 memset(&fsts3ConfigInfo, 0, sizeof(fsts3ConfigInfo));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
67 return DosQueryPathInfo( (PSZ)zFilename, FIL_STANDARD,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
68 &fsts3ConfigInfo, sizeof(FILESTATUS3) ) == NO_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
69 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
70
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
71 /* Forward declaration */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
72 int allocateOs2File( os2File *pInit, OsFile **pld );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
73
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
74 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
75 ** Attempt to open a file for both reading and writing. If that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
76 ** fails, try opening it read-only. If the file does not exist,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
77 ** try to create it.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
78 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
79 ** On success, a handle for the open file is written to *id
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
80 ** and *pReadonly is set to 0 if the file was opened for reading and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
81 ** writing or 1 if the file was opened read-only. The function returns
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
82 ** SQLITE_OK.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
83 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
84 ** On failure, the function returns SQLITE_CANTOPEN and leaves
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
85 ** *id and *pReadonly unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
86 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
87 int sqlite3Os2OpenReadWrite(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
88 const char *zFilename,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
89 OsFile **pld,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
90 int *pReadonly
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
91 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
92 os2File f;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
93 HFILE hf;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
94 ULONG ulAction;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
95 APIRET rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
96
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
97 assert( *pld == 0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
98 rc = DosOpen( (PSZ)zFilename, &hf, &ulAction, 0L,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
99 FILE_ARCHIVED | FILE_NORMAL,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
100 OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
101 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_RANDOM |
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
102 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE, (PEAOP2)NULL );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
103 if( rc != NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
104 rc = DosOpen( (PSZ)zFilename, &hf, &ulAction, 0L,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
105 FILE_ARCHIVED | FILE_NORMAL,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
106 OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
107 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_RANDOM |
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
108 OPEN_SHARE_DENYWRITE | OPEN_ACCESS_READONLY, (PEAOP2)NULL );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
109 if( rc != NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
110 return SQLITE_CANTOPEN;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
111 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
112 *pReadonly = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
113 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
114 else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
115 *pReadonly = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
116 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
117 f.h = hf;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
118 f.locktype = NO_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
119 f.delOnClose = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
120 f.pathToDel = NULL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
121 OpenCounter(+1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
122 TRACE3( "OPEN R/W %d \"%s\"\n", hf, zFilename );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
123 return allocateOs2File( &f, pld );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
124 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
125
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
126
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
127 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
128 ** Attempt to open a new file for exclusive access by this process.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
129 ** The file will be opened for both reading and writing. To avoid
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
130 ** a potential security problem, we do not allow the file to have
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
131 ** previously existed. Nor do we allow the file to be a symbolic
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
132 ** link.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
133 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
134 ** If delFlag is true, then make arrangements to automatically delete
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
135 ** the file when it is closed.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
136 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
137 ** On success, write the file handle into *id and return SQLITE_OK.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
138 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
139 ** On failure, return SQLITE_CANTOPEN.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
140 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
141 int sqlite3Os2OpenExclusive( const char *zFilename, OsFile **pld, int delFlag ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
142 os2File f;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
143 HFILE hf;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
144 ULONG ulAction;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
145 APIRET rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
146
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
147 assert( *pld == 0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
148 rc = DosOpen( (PSZ)zFilename, &hf, &ulAction, 0L, FILE_NORMAL,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
149 OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
150 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_RANDOM |
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
151 OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE, (PEAOP2)NULL );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
152 if( rc != NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
153 return SQLITE_CANTOPEN;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
154 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
155
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
156 f.h = hf;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
157 f.locktype = NO_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
158 f.delOnClose = delFlag ? 1 : 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
159 f.pathToDel = delFlag ? sqlite3OsFullPathname( zFilename ) : NULL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
160 OpenCounter( +1 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
161 if( delFlag ) DosForceDelete( sqlite3OsFullPathname( zFilename ) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
162 TRACE3( "OPEN EX %d \"%s\"\n", hf, sqlite3OsFullPathname ( zFilename ) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
163 return allocateOs2File( &f, pld );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
164 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
165
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
166 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
167 ** Attempt to open a new file for read-only access.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
168 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
169 ** On success, write the file handle into *id and return SQLITE_OK.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
170 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
171 ** On failure, return SQLITE_CANTOPEN.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
172 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
173 int sqlite3Os2OpenReadOnly( const char *zFilename, OsFile **pld ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
174 os2File f;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
175 HFILE hf;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
176 ULONG ulAction;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
177 APIRET rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
178
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
179 assert( *pld == 0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
180 rc = DosOpen( (PSZ)zFilename, &hf, &ulAction, 0L,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
181 FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
182 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_RANDOM |
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
183 OPEN_SHARE_DENYWRITE | OPEN_ACCESS_READONLY, (PEAOP2)NULL );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
184 if( rc != NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
185 return SQLITE_CANTOPEN;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
186 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
187 f.h = hf;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
188 f.locktype = NO_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
189 f.delOnClose = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
190 f.pathToDel = NULL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
191 OpenCounter( +1 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
192 TRACE3( "OPEN RO %d \"%s\"\n", hf, zFilename );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
193 return allocateOs2File( &f, pld );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
194 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
195
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
196 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
197 ** Attempt to open a file descriptor for the directory that contains a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
198 ** file. This file descriptor can be used to fsync() the directory
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
199 ** in order to make sure the creation of a new file is actually written
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
200 ** to disk.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
201 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
202 ** This routine is only meaningful for Unix. It is a no-op under
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
203 ** OS/2 since OS/2 does not support hard links.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
204 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
205 ** On success, a handle for a previously open file is at *id is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
206 ** updated with the new directory file descriptor and SQLITE_OK is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
207 ** returned.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
208 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
209 ** On failure, the function returns SQLITE_CANTOPEN and leaves
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
210 ** *id unchanged.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
211 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
212 int os2OpenDirectory(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
213 OsFile *id,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
214 const char *zDirname
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
215 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
216 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
217 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
218
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
219 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
220 ** If the following global variable points to a string which is the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
221 ** name of a directory, then that directory will be used to store
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
222 ** temporary files.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
223 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
224 char *sqlite3_temp_directory = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
225
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
226 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
227 ** Create a temporary file name in zBuf. zBuf must be big enough to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
228 ** hold at least SQLITE_TEMPNAME_SIZE characters.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
229 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
230 int sqlite3Os2TempFileName( char *zBuf ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
231 static const unsigned char zChars[] =
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
232 "abcdefghijklmnopqrstuvwxyz"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
233 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
234 "0123456789";
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
235 int i, j;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
236 PSZ zTempPath = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
237 if( DosScanEnv( "TEMP", &zTempPath ) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
238 if( DosScanEnv( "TMP", &zTempPath ) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
239 if( DosScanEnv( "TMPDIR", &zTempPath ) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
240 ULONG ulDriveNum = 0, ulDriveMap = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
241 DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
242 sprintf( zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
243 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
244 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
245 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
246 for(;;){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
247 sprintf( zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
248 j = strlen( zBuf );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
249 sqlite3Randomness( 15, &zBuf[j] );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
250 for( i = 0; i < 15; i++, j++ ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
251 zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
252 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
253 zBuf[j] = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
254 if( !sqlite3OsFileExists( zBuf ) ) break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
255 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
256 TRACE2( "TEMP FILENAME: %s\n", zBuf );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
257 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
258 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
259
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
260 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
261 ** Close a file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
262 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
263 int os2Close( OsFile **pld ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
264 os2File *pFile;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
265 if( pld && (pFile = (os2File*)*pld)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
266 TRACE2( "CLOSE %d\n", pFile->h );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
267 DosClose( pFile->h );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
268 pFile->locktype = NO_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
269 if( pFile->delOnClose != 0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
270 DosForceDelete( pFile->pathToDel );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
271 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
272 *pld = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
273 OpenCounter( -1 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
274 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
275
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
276 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
277 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
278
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
279 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
280 ** Read data from a file into a buffer. Return SQLITE_OK if all
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
281 ** bytes were read successfully and SQLITE_IOERR if anything goes
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
282 ** wrong.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
283 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
284 int os2Read( OsFile *id, void *pBuf, int amt ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
285 ULONG got;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
286 assert( id!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
287 SimulateIOError( SQLITE_IOERR );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
288 TRACE3( "READ %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
289 DosRead( ((os2File*)id)->h, pBuf, amt, &got );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
290 return (got == (ULONG)amt) ? SQLITE_OK : SQLITE_IOERR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
291 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
292
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
293 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
294 ** Write data from a buffer into a file. Return SQLITE_OK on success
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
295 ** or some other error code on failure.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
296 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
297 int os2Write( OsFile *id, const void *pBuf, int amt ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
298 APIRET rc=NO_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
299 ULONG wrote;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
300 assert( id!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
301 SimulateIOError( SQLITE_IOERR );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
302 SimulateDiskfullError;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
303 TRACE3( "WRITE %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
304 while( amt > 0 &&
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
305 (rc = DosWrite( ((os2File*)id)->h, (PVOID)pBuf, amt, &wrote )) && wrote > 0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
306 amt -= wrote;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
307 pBuf = &((char*)pBuf)[wrote];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
308 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
309
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
310 return ( rc != NO_ERROR || amt > (int)wrote ) ? SQLITE_FULL : SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
311 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
312
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
313 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
314 ** Move the read/write pointer in a file.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
315 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
316 int os2Seek( OsFile *id, i64 offset ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
317 APIRET rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
318 ULONG filePointer = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
319 assert( id!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
320 rc = DosSetFilePtr( ((os2File*)id)->h, offset, FILE_BEGIN, &filePointer );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
321 TRACE3( "SEEK %d %lld\n", ((os2File*)id)->h, offset );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
322 return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
323 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
324
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
325 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
326 ** Make sure all writes to a particular file are committed to disk.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
327 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
328 int os2Sync( OsFile *id, int dataOnly ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
329 assert( id!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
330 TRACE3( "SYNC %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
331 return DosResetBuffer( ((os2File*)id)->h ) ? SQLITE_IOERR : SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
332 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
333
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
334 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
335 ** Sync the directory zDirname. This is a no-op on operating systems other
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
336 ** than UNIX.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
337 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
338 int sqlite3Os2SyncDirectory( const char *zDirname ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
339 SimulateIOError( SQLITE_IOERR );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
340 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
341 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
342
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
343 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
344 ** Truncate an open file to a specified size
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
345 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
346 int os2Truncate( OsFile *id, i64 nByte ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
347 APIRET rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
348 ULONG upperBits = nByte>>32;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
349 assert( id!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
350 TRACE3( "TRUNCATE %d %lld\n", ((os2File*)id)->h, nByte );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
351 SimulateIOError( SQLITE_IOERR );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
352 rc = DosSetFilePtr( ((os2File*)id)->h, nByte, FILE_BEGIN, &upperBits );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
353 if( rc != NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
354 return SQLITE_IOERR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
355 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
356 rc = DosSetFilePtr( ((os2File*)id)->h, 0L, FILE_END, &upperBits );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
357 return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
358 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
359
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
360 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
361 ** Determine the current size of a file in bytes
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
362 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
363 int os2FileSize( OsFile *id, i64 *pSize ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
364 APIRET rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
365 FILESTATUS3 fsts3FileInfo;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
366 memset(&fsts3FileInfo, 0, sizeof(fsts3FileInfo));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
367 assert( id!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
368 SimulateIOError( SQLITE_IOERR );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
369 rc = DosQueryFileInfo( ((os2File*)id)->h, FIL_STANDARD, &fsts3FileInfo, sizeof(FILESTATUS3) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
370 if( rc == NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
371 *pSize = fsts3FileInfo.cbFile;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
372 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
373 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
374 else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
375 return SQLITE_IOERR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
376 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
377 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
378
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
379 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
380 ** Acquire a reader lock.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
381 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
382 static int getReadLock( os2File *id ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
383 FILELOCK LockArea,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
384 UnlockArea;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
385 memset(&LockArea, 0, sizeof(LockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
386 memset(&UnlockArea, 0, sizeof(UnlockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
387 LockArea.lOffset = SHARED_FIRST;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
388 LockArea.lRange = SHARED_SIZE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
389 UnlockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
390 UnlockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
391 return DosSetFileLocks( id->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
392 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
393
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
394 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
395 ** Undo a readlock
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
396 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
397 static int unlockReadLock( os2File *id ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
398 FILELOCK LockArea,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
399 UnlockArea;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
400 memset(&LockArea, 0, sizeof(LockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
401 memset(&UnlockArea, 0, sizeof(UnlockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
402 LockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
403 LockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
404 UnlockArea.lOffset = SHARED_FIRST;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
405 UnlockArea.lRange = SHARED_SIZE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
406 return DosSetFileLocks( id->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
407 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
408
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
409 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
410 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
411 ** Check that a given pathname is a directory and is writable
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
412 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
413 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
414 int sqlite3Os2IsDirWritable( char *zDirname ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
415 FILESTATUS3 fsts3ConfigInfo;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
416 APIRET rc = NO_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
417 memset(&fsts3ConfigInfo, 0, sizeof(fsts3ConfigInfo));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
418 if( zDirname==0 ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
419 if( strlen(zDirname)>CCHMAXPATH ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
420 rc = DosQueryPathInfo( (PSZ)zDirname, FIL_STANDARD, &fsts3ConfigInfo, sizeof(FILESTATUS3) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
421 if( rc != NO_ERROR ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
422 if( (fsts3ConfigInfo.attrFile & FILE_DIRECTORY) != FILE_DIRECTORY ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
423
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
424 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
425 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
426 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
427
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
428 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
429 ** Lock the file with the lock specified by parameter locktype - one
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
430 ** of the following:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
431 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
432 ** (1) SHARED_LOCK
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
433 ** (2) RESERVED_LOCK
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
434 ** (3) PENDING_LOCK
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
435 ** (4) EXCLUSIVE_LOCK
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
436 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
437 ** Sometimes when requesting one lock state, additional lock states
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
438 ** are inserted in between. The locking might fail on one of the later
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
439 ** transitions leaving the lock state different from what it started but
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
440 ** still short of its goal. The following chart shows the allowed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
441 ** transitions and the inserted intermediate states:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
442 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
443 ** UNLOCKED -> SHARED
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
444 ** SHARED -> RESERVED
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
445 ** SHARED -> (PENDING) -> EXCLUSIVE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
446 ** RESERVED -> (PENDING) -> EXCLUSIVE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
447 ** PENDING -> EXCLUSIVE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
448 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
449 ** This routine will only increase a lock. The os2Unlock() routine
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
450 ** erases all locks at once and returns us immediately to locking level 0.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
451 ** It is not possible to lower the locking level one step at a time. You
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
452 ** must go straight to locking level 0.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
453 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
454 int os2Lock( OsFile *id, int locktype ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
455 APIRET rc = SQLITE_OK; /* Return code from subroutines */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
456 APIRET res = 1; /* Result of a windows lock call */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
457 int newLocktype; /* Set id->locktype to this value before exiting */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
458 int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
459 FILELOCK LockArea,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
460 UnlockArea;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
461 os2File *pFile = (os2File*)id;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
462 memset(&LockArea, 0, sizeof(LockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
463 memset(&UnlockArea, 0, sizeof(UnlockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
464 assert( pFile!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
465 TRACE4( "LOCK %d %d was %d\n", pFile->h, locktype, pFile->locktype );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
466
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
467 /* If there is already a lock of this type or more restrictive on the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
468 ** OsFile, do nothing. Don't use the end_lock: exit path, as
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
469 ** sqlite3OsEnterMutex() hasn't been called yet.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
470 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
471 if( pFile->locktype>=locktype ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
472 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
473 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
474
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
475 /* Make sure the locking sequence is correct
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
476 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
477 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
478 assert( locktype!=PENDING_LOCK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
479 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
480
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
481 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
482 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
483 ** the PENDING_LOCK byte is temporary.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
484 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
485 newLocktype = pFile->locktype;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
486 if( pFile->locktype==NO_LOCK
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
487 || (locktype==EXCLUSIVE_LOCK && pFile->locktype==RESERVED_LOCK)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
488 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
489 int cnt = 3;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
490
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
491 LockArea.lOffset = PENDING_BYTE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
492 LockArea.lRange = 1L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
493 UnlockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
494 UnlockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
495
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
496 while( cnt-->0 && (res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L) )!=NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
497 /* Try 3 times to get the pending lock. The pending lock might be
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
498 ** held by another reader process who will release it momentarily.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
499 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
500 TRACE2( "could not get a PENDING lock. cnt=%d\n", cnt );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
501 DosSleep(1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
502 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
503 gotPendingLock = res;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
504 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
505
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
506 /* Acquire a shared lock
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
507 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
508 if( locktype==SHARED_LOCK && res ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
509 assert( pFile->locktype==NO_LOCK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
510 res = getReadLock(pFile);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
511 if( res == NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
512 newLocktype = SHARED_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
513 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
514 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
515
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
516 /* Acquire a RESERVED lock
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
517 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
518 if( locktype==RESERVED_LOCK && res ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
519 assert( pFile->locktype==SHARED_LOCK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
520 LockArea.lOffset = RESERVED_BYTE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
521 LockArea.lRange = 1L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
522 UnlockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
523 UnlockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
524 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
525 if( res == NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
526 newLocktype = RESERVED_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
527 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
528 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
529
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
530 /* Acquire a PENDING lock
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
531 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
532 if( locktype==EXCLUSIVE_LOCK && res ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
533 newLocktype = PENDING_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
534 gotPendingLock = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
535 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
536
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
537 /* Acquire an EXCLUSIVE lock
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
538 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
539 if( locktype==EXCLUSIVE_LOCK && res ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
540 assert( pFile->locktype>=SHARED_LOCK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
541 res = unlockReadLock(pFile);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
542 TRACE2( "unreadlock = %d\n", res );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
543 LockArea.lOffset = SHARED_FIRST;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
544 LockArea.lRange = SHARED_SIZE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
545 UnlockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
546 UnlockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
547 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
548 if( res == NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
549 newLocktype = EXCLUSIVE_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
550 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
551 TRACE2( "error-code = %d\n", res );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
552 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
553 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
554
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
555 /* If we are holding a PENDING lock that ought to be released, then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
556 ** release it now.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
557 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
558 if( gotPendingLock && locktype==SHARED_LOCK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
559 LockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
560 LockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
561 UnlockArea.lOffset = PENDING_BYTE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
562 UnlockArea.lRange = 1L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
563 DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
564 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
565
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
566 /* Update the state of the lock has held in the file descriptor then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
567 ** return the appropriate result code.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
568 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
569 if( res == NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
570 rc = SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
571 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
572 TRACE4( "LOCK FAILED %d trying for %d but got %d\n", pFile->h,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
573 locktype, newLocktype );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
574 rc = SQLITE_BUSY;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
575 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
576 pFile->locktype = newLocktype;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
577 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
578 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
579
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
580 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
581 ** This routine checks if there is a RESERVED lock held on the specified
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
582 ** file by this or any other process. If such a lock is held, return
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
583 ** non-zero, otherwise zero.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
584 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
585 int os2CheckReservedLock( OsFile *id ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
586 APIRET rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
587 os2File *pFile = (os2File*)id;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
588 assert( pFile!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
589 if( pFile->locktype>=RESERVED_LOCK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
590 rc = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
591 TRACE3( "TEST WR-LOCK %d %d (local)\n", pFile->h, rc );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
592 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
593 FILELOCK LockArea,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
594 UnlockArea;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
595 memset(&LockArea, 0, sizeof(LockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
596 memset(&UnlockArea, 0, sizeof(UnlockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
597 LockArea.lOffset = RESERVED_BYTE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
598 LockArea.lRange = 1L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
599 UnlockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
600 UnlockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
601 rc = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
602 if( rc == NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
603 LockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
604 LockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
605 UnlockArea.lOffset = RESERVED_BYTE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
606 UnlockArea.lRange = 1L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
607 rc = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
608 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
609 TRACE3( "TEST WR-LOCK %d %d (remote)\n", pFile->h, rc );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
610 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
611 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
612 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
613
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
614 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
615 ** Lower the locking level on file descriptor id to locktype. locktype
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
616 ** must be either NO_LOCK or SHARED_LOCK.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
617 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
618 ** If the locking level of the file descriptor is already at or below
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
619 ** the requested locking level, this routine is a no-op.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
620 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
621 ** It is not possible for this routine to fail if the second argument
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
622 ** is NO_LOCK. If the second argument is SHARED_LOCK then this routine
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
623 ** might return SQLITE_IOERR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
624 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
625 int os2Unlock( OsFile *id, int locktype ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
626 int type;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
627 APIRET rc = SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
628 os2File *pFile = (os2File*)id;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
629 FILELOCK LockArea,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
630 UnlockArea;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
631 memset(&LockArea, 0, sizeof(LockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
632 memset(&UnlockArea, 0, sizeof(UnlockArea));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
633 assert( pFile!=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
634 assert( locktype<=SHARED_LOCK );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
635 TRACE4( "UNLOCK %d to %d was %d\n", pFile->h, locktype, pFile->locktype );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
636 type = pFile->locktype;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
637 if( type>=EXCLUSIVE_LOCK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
638 LockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
639 LockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
640 UnlockArea.lOffset = SHARED_FIRST;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
641 UnlockArea.lRange = SHARED_SIZE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
642 DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
643 if( locktype==SHARED_LOCK && getReadLock(pFile) != NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
644 /* This should never happen. We should always be able to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
645 ** reacquire the read lock */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
646 rc = SQLITE_IOERR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
647 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
648 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
649 if( type>=RESERVED_LOCK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
650 LockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
651 LockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
652 UnlockArea.lOffset = RESERVED_BYTE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
653 UnlockArea.lRange = 1L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
654 DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
655 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
656 if( locktype==NO_LOCK && type>=SHARED_LOCK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
657 unlockReadLock(pFile);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
658 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
659 if( type>=PENDING_LOCK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
660 LockArea.lOffset = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
661 LockArea.lRange = 0L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
662 UnlockArea.lOffset = PENDING_BYTE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
663 UnlockArea.lRange = 1L;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
664 DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 2000L, 1L );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
665 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
666 pFile->locktype = locktype;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
667 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
668 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
669
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
670 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
671 ** Turn a relative pathname into a full pathname. Return a pointer
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
672 ** to the full pathname stored in space obtained from sqliteMalloc().
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
673 ** The calling function is responsible for freeing this space once it
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
674 ** is no longer needed.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
675 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
676 char *sqlite3Os2FullPathname( const char *zRelative ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
677 char *zFull = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
678 if( strchr(zRelative, ':') ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
679 sqlite3SetString( &zFull, zRelative, (char*)0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
680 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
681 char zBuff[SQLITE_TEMPNAME_SIZE - 2] = {0};
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
682 char zDrive[1] = {0};
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
683 ULONG cbzFullLen = SQLITE_TEMPNAME_SIZE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
684 ULONG ulDriveNum = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
685 ULONG ulDriveMap = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
686 DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
687 DosQueryCurrentDir( 0L, zBuff, &cbzFullLen );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
688 zFull = sqliteMalloc( cbzFullLen );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
689 sprintf( zDrive, "%c", (char)('A' + ulDriveNum - 1) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
690 sqlite3SetString( &zFull, zDrive, ":\\", zBuff, "\\", zRelative, (char*)0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
691 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
692 return zFull;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
693 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
694
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
695 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
696 ** The fullSync option is meaningless on os2, or correct me if I'm wrong. This is a no-op.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
697 ** From os_unix.c: Change the value of the fullsync flag in the given file descriptor.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
698 ** From os_unix.c: ((unixFile*)id)->fullSync = v;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
699 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
700 static void os2SetFullSync( OsFile *id, int v ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
701 return;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
702 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
703
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
704 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
705 ** Return the underlying file handle for an OsFile
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
706 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
707 static int os2FileHandle( OsFile *id ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
708 return (int)((os2File*)id)->h;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
709 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
710
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
711 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
712 ** Return an integer that indices the type of lock currently held
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
713 ** by this handle. (Used for testing and analysis only.)
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
714 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
715 static int os2LockState( OsFile *id ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
716 return ((os2File*)id)->locktype;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
717 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
718
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
719 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
720 ** This vector defines all the methods that can operate on an OsFile
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
721 ** for os2.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
722 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
723 static const IoMethod sqlite3Os2IoMethod = {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
724 os2Close,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
725 os2OpenDirectory,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
726 os2Read,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
727 os2Write,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
728 os2Seek,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
729 os2Truncate,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
730 os2Sync,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
731 os2SetFullSync,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
732 os2FileHandle,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
733 os2FileSize,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
734 os2Lock,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
735 os2Unlock,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
736 os2LockState,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
737 os2CheckReservedLock,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
738 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
739
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
740 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
741 ** Allocate memory for an OsFile. Initialize the new OsFile
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
742 ** to the value given in pInit and return a pointer to the new
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
743 ** OsFile. If we run out of memory, close the file and return NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
744 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
745 int allocateOs2File( os2File *pInit, OsFile **pld ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
746 os2File *pNew;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
747 pNew = sqliteMalloc( sizeof(*pNew) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
748 if( pNew==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
749 DosClose( pInit->h );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
750 *pld = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
751 return SQLITE_NOMEM;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
752 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
753 *pNew = *pInit;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
754 pNew->pMethod = &sqlite3Os2IoMethod;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
755 pNew->locktype = NO_LOCK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
756 *pld = (OsFile*)pNew;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
757 OpenCounter(+1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
758 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
759 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
760 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
761
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
762 #endif /* SQLITE_OMIT_DISKIO */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
763 /***************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
764 ** Everything above deals with file I/O. Everything that follows deals
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
765 ** with other miscellanous aspects of the operating system interface
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
766 ****************************************************************************/
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
767
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
768 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
769 ** Get information to seed the random number generator. The seed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
770 ** is written into the buffer zBuf[256]. The calling function must
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
771 ** supply a sufficiently large buffer.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
772 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
773 int sqlite3Os2RandomSeed( char *zBuf ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
774 /* We have to initialize zBuf to prevent valgrind from reporting
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
775 ** errors. The reports issued by valgrind are incorrect - we would
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
776 ** prefer that the randomness be increased by making use of the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
777 ** uninitialized space in zBuf - but valgrind errors tend to worry
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
778 ** some users. Rather than argue, it seems easier just to initialize
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
779 ** the whole array and silence valgrind, even if that means less randomness
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
780 ** in the random seed.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
781 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
782 ** When testing, initializing zBuf[] to zero is all we do. That means
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
783 ** that we always use the same random number sequence.* This makes the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
784 ** tests repeatable.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
785 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
786 memset( zBuf, 0, 256 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
787 DosGetDateTime( (PDATETIME)zBuf );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
788 return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
789 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
790
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
791 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
792 ** Sleep for a little while. Return the amount of time slept.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
793 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
794 int sqlite3Os2Sleep( int ms ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
795 DosSleep( ms );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
796 return ms;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
797 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
798
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
799 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
800 ** Static variables used for thread synchronization
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
801 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
802 static int inMutex = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
803 #ifdef SQLITE_OS2_THREADS
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
804 static ULONG mutexOwner;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
805 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
806
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
807 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
808 ** The following pair of routines implement mutual exclusion for
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
809 ** multi-threaded processes. Only a single thread is allowed to
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
810 ** executed code that is surrounded by EnterMutex() and LeaveMutex().
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
811 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
812 ** SQLite uses only a single Mutex. There is not much critical
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
813 ** code and what little there is executes quickly and without blocking.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
814 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
815 void sqlite3Os2EnterMutex(){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
816 PTIB ptib;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
817 #ifdef SQLITE_OS2_THREADS
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
818 DosEnterCritSec();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
819 DosGetInfoBlocks( &ptib, NULL );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
820 mutexOwner = ptib->tib_ptib2->tib2_ultid;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
821 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
822 assert( !inMutex );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
823 inMutex = 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
824 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
825 void sqlite3Os2LeaveMutex(){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
826 PTIB ptib;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
827 assert( inMutex );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
828 inMutex = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
829 #ifdef SQLITE_OS2_THREADS
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
830 DosGetInfoBlocks( &ptib, NULL );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
831 assert( mutexOwner == ptib->tib_ptib2->tib2_ultid );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
832 DosExitCritSec();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
833 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
834 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
835
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
836 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
837 ** Return TRUE if the mutex is currently held.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
838 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
839 ** If the thisThreadOnly parameter is true, return true if and only if the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
840 ** calling thread holds the mutex. If the parameter is false, return
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
841 ** true if any thread holds the mutex.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
842 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
843 int sqlite3Os2InMutex( int thisThreadOnly ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
844 #ifdef SQLITE_OS2_THREADS
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
845 PTIB ptib;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
846 DosGetInfoBlocks( &ptib, NULL );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
847 return inMutex>0 && (thisThreadOnly==0 || mutexOwner==ptib->tib_ptib2->tib2_ultid);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
848 #else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
849 return inMutex>0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
850 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
851 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
852
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
853 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
854 ** The following variable, if set to a non-zero value, becomes the result
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
855 ** returned from sqlite3OsCurrentTime(). This is used for testing.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
856 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
857 #ifdef SQLITE_TEST
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
858 int sqlite3_current_time = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
859 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
860
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
861 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
862 ** Find the current time (in Universal Coordinated Time). Write the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
863 ** current time and date as a Julian Day number into *prNow and
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
864 ** return 0. Return 1 if the time and date cannot be found.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
865 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
866 int sqlite3Os2CurrentTime( double *prNow ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
867 double now;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
868 USHORT second, minute, hour,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
869 day, month, year;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
870 DATETIME dt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
871 DosGetDateTime( &dt );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
872 second = (USHORT)dt.seconds;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
873 minute = (USHORT)dt.minutes + dt.timezone;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
874 hour = (USHORT)dt.hours;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
875 day = (USHORT)dt.day;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
876 month = (USHORT)dt.month;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
877 year = (USHORT)dt.year;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
878
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
879 /* Calculations from http://www.astro.keele.ac.uk/~rno/Astronomy/hjd.html
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
880 http://www.astro.keele.ac.uk/~rno/Astronomy/hjd-0.1.c */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
881 /* Calculate the Julian days */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
882 now = day - 32076 +
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
883 1461*(year + 4800 + (month - 14)/12)/4 +
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
884 367*(month - 2 - (month - 14)/12*12)/12 -
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
885 3*((year + 4900 + (month - 14)/12)/100)/4;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
886
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
887 /* Add the fractional hours, mins and seconds */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
888 now += (hour + 12.0)/24.0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
889 now += minute/1440.0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
890 now += second/86400.0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
891 *prNow = now;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
892 #ifdef SQLITE_TEST
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
893 if( sqlite3_current_time ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
894 *prNow = sqlite3_current_time/86400.0 + 2440587.5;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
895 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
896 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
897 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
898 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
899
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
900 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
901 ** Remember the number of thread-specific-data blocks allocated.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
902 ** Use this to verify that we are not leaking thread-specific-data.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
903 ** Ticket #1601
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
904 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
905 #ifdef SQLITE_TEST
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
906 int sqlite3_tsd_count = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
907 # define TSD_COUNTER_INCR InterlockedIncrement( &sqlite3_tsd_count )
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
908 # define TSD_COUNTER_DECR InterlockedDecrement( &sqlite3_tsd_count )
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
909 #else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
910 # define TSD_COUNTER_INCR /* no-op */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
911 # define TSD_COUNTER_DECR /* no-op */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
912 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
913
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
914 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
915 ** If called with allocateFlag>1, then return a pointer to thread
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
916 ** specific data for the current thread. Allocate and zero the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
917 ** thread-specific data if it does not already exist necessary.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
918 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
919 ** If called with allocateFlag==0, then check the current thread
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
920 ** specific data. Return it if it exists. If it does not exist,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
921 ** then return NULL.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
922 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
923 ** If called with allocateFlag<0, check to see if the thread specific
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
924 ** data is allocated and is all zero. If it is then deallocate it.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
925 ** Return a pointer to the thread specific data or NULL if it is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
926 ** unallocated or gets deallocated.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
927 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
928 ThreadData *sqlite3Os2ThreadSpecificData( int allocateFlag ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
929 static ThreadData **s_ppTsd = NULL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
930 static const ThreadData zeroData = {0, 0, 0};
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
931 ThreadData *pTsd;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
932
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
933 if( !s_ppTsd ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
934 sqlite3OsEnterMutex();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
935 if( !s_ppTsd ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
936 PULONG pul;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
937 APIRET rc = DosAllocThreadLocalMemory(1, &pul);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
938 if( rc != NO_ERROR ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
939 sqlite3OsLeaveMutex();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
940 return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
941 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
942 s_ppTsd = (ThreadData **)pul;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
943 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
944 sqlite3OsLeaveMutex();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
945 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
946 pTsd = *s_ppTsd;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
947 if( allocateFlag>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
948 if( !pTsd ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
949 pTsd = sqlite3OsMalloc( sizeof(zeroData) );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
950 if( pTsd ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
951 *pTsd = zeroData;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
952 *s_ppTsd = pTsd;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
953 TSD_COUNTER_INCR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
954 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
955 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
956 }else if( pTsd!=0 && allocateFlag<0
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
957 && memcmp( pTsd, &zeroData, sizeof(ThreadData) )==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
958 sqlite3OsFree(pTsd);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
959 *s_ppTsd = NULL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
960 TSD_COUNTER_DECR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
961 pTsd = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
962 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
963 return pTsd;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
964 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
965 #endif /* OS_OS2 */