OLD | NEW |
1 From 25f1f784320aa0e32b69f78098b652b30df40865 Mon Sep 17 00:00:00 2001 | 1 From 67024286d2719aec049605896ef0afec6932f184 Mon Sep 17 00:00:00 2001 |
2 From: dumi <dumi@chromium.org> | 2 From: dumi <dumi@chromium.org> |
3 Date: Mon, 20 Jul 2009 23:40:51 +0000 | 3 Date: Mon, 20 Jul 2009 23:40:51 +0000 |
4 Subject: [PATCH 06/23] Modify default VFS to support WebDatabase. | 4 Subject: [PATCH 05/16] Modify default VFS to support WebDatabase. |
5 | 5 |
6 The renderer WebDatabase implementation needs to broker certain requests | 6 The renderer WebDatabase implementation needs to broker certain requests |
7 to the browser. This modifies SQLite to allow monkey-patching the VFS | 7 to the browser. This modifies SQLite to allow monkey-patching the VFS |
8 to support this. | 8 to support this. |
9 | 9 |
10 NOTE(shess): This patch relies on core SQLite implementation details | 10 NOTE(shess): This patch relies on core SQLite implementation details |
11 remaining unchanged. When importing a new version of SQLite, pay very | 11 remaining unchanged. When importing a new version of SQLite, pay very |
12 close attention to whether the change is still doing what is intended. | 12 close attention to whether the change is still doing what is intended. |
13 | 13 |
14 Original review URLs: | 14 Original review URLs: |
15 https://codereview.chromium.org/159044 | 15 https://codereview.chromium.org/159044 |
16 https://codereview.chromium.org/384075 | 16 https://codereview.chromium.org/384075 |
17 https://codereview.chromium.org/377039 | 17 https://codereview.chromium.org/377039 |
18 [Possibly not a complete list.] | 18 [Possibly not a complete list.] |
19 --- | 19 --- |
20 third_party/sqlite/src/src/os_unix.c | 98 +++++++++++++++++++++++++++++------- | 20 third_party/sqlite/src/src/os_unix.c | 95 ++++++++++++++++++++++++++++++------ |
21 third_party/sqlite/src/src/os_win.c | 7 +++ | 21 third_party/sqlite/src/src/os_win.c | 7 +++ |
22 2 files changed, 88 insertions(+), 17 deletions(-) | 22 2 files changed, 86 insertions(+), 16 deletions(-) |
23 | 23 |
24 diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/o
s_unix.c | 24 diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/o
s_unix.c |
25 index 998e353..766b52a 100644 | 25 index a9344ee..1624f6a 100644 |
26 --- a/third_party/sqlite/src/src/os_unix.c | 26 --- a/third_party/sqlite/src/src/os_unix.c |
27 +++ b/third_party/sqlite/src/src/os_unix.c | 27 +++ b/third_party/sqlite/src/src/os_unix.c |
28 @@ -4418,9 +4418,16 @@ typedef const sqlite3_io_methods *(*finder_type)(const ch
ar*,unixFile*); | 28 @@ -1321,6 +1321,12 @@ static int fileHasMoved(unixFile *pFile){ |
29 */ | 29 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId; |
30 | 30 #else |
31 /* | 31 struct stat buf; |
32 +** Initializes a unixFile structure with zeros. | |
33 +*/ | |
34 +void initUnixFile(sqlite3_file* file) { | |
35 + memset(file, 0, sizeof(unixFile)); | |
36 +} | |
37 + | 32 + |
38 +/* | 33 + /* TODO(shess): This check doesn't work when the Chromium's WebDB code is |
39 ** Initialize the contents of the unixFile structure pointed to by pId. | 34 + ** running in the sandbox. |
40 */ | 35 + */ |
41 -static int fillInUnixFile( | 36 + return 0; |
42 +int fillInUnixFile( | 37 + |
43 sqlite3_vfs *pVfs, /* Pointer to vfs object */ | 38 return pFile->pInode!=0 && |
44 int h, /* Open file descriptor of file being opened */ | 39 (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); |
45 int dirfd, /* Directory file descriptor */ | 40 #endif |
46 @@ -4834,6 +4841,73 @@ static int findCreateFileMode( | 41 @@ -5615,6 +5621,73 @@ static int findCreateFileMode( |
47 } | 42 } |
48 | 43 |
49 /* | 44 /* |
50 +** Initializes a unixFile structure with zeros. | 45 +** Initializes a unixFile structure with zeros. |
51 +*/ | 46 +*/ |
52 +void chromium_sqlite3_initialize_unix_sqlite3_file(sqlite3_file* file) { | 47 +void chromium_sqlite3_initialize_unix_sqlite3_file(sqlite3_file* file) { |
53 + memset(file, 0, sizeof(unixFile)); | 48 + memset(file, 0, sizeof(unixFile)); |
54 +} | 49 +} |
55 + | 50 + |
56 +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs, | 51 +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs, |
57 + int fd, | 52 + int fd, |
58 + int dirfd, | 53 + int dirfd, |
59 + sqlite3_file* file, | 54 + sqlite3_file* file, |
60 + const char* fileName, | 55 + const char* fileName, |
61 + int noLock, | 56 + int noLock) { |
62 + int isDelete) { | 57 + int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0); |
63 + return fillInUnixFile(vfs, fd, dirfd, file, fileName, noLock, isDelete, 0); | 58 + return fillInUnixFile(vfs, fd, file, fileName, ctrlFlags); |
64 +} | 59 +} |
65 + | 60 + |
66 +/* | 61 +/* |
67 +** Search for an unused file descriptor that was opened on the database file. | 62 +** Search for an unused file descriptor that was opened on the database file. |
68 +** If a suitable file descriptor if found, then it is stored in *fd; otherwise, | 63 +** If a suitable file descriptor if found, then it is stored in *fd; otherwise, |
69 +** *fd is not modified. | 64 +** *fd is not modified. |
70 +** | 65 +** |
71 +** If a reusable file descriptor is not found, and a new UnixUnusedFd cannot | 66 +** If a reusable file descriptor is not found, and a new UnixUnusedFd cannot |
72 +** be allocated, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK is returned. | 67 +** be allocated, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK is returned. |
73 +*/ | 68 +*/ |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 +*/ | 105 +*/ |
111 +void chromium_sqlite3_destroy_reusable_file_handle(sqlite3_file* file) { | 106 +void chromium_sqlite3_destroy_reusable_file_handle(sqlite3_file* file) { |
112 + unixFile* unixSQLite3File = (unixFile*)file; | 107 + unixFile* unixSQLite3File = (unixFile*)file; |
113 + sqlite3_free(unixSQLite3File->pUnused); | 108 + sqlite3_free(unixSQLite3File->pUnused); |
114 +} | 109 +} |
115 + | 110 + |
116 +/* | 111 +/* |
117 ** Open the file zPath. | 112 ** Open the file zPath. |
118 ** | 113 ** |
119 ** Previously, the SQLite OS layer used three functions in place of this | 114 ** Previously, the SQLite OS layer used three functions in place of this |
120 @@ -4921,20 +4995,13 @@ static int unixOpen( | 115 @@ -5715,20 +5788,13 @@ static int unixOpen( |
121 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL | 116 sqlite3_randomness(0,0); |
122 ); | 117 } |
123 | 118 |
124 - memset(p, 0, sizeof(unixFile)); | 119 - memset(p, 0, sizeof(unixFile)); |
125 + chromium_sqlite3_initialize_unix_sqlite3_file(pFile); | 120 + chromium_sqlite3_initialize_unix_sqlite3_file(pFile); |
126 | 121 |
127 if( eType==SQLITE_OPEN_MAIN_DB ){ | 122 if( eType==SQLITE_OPEN_MAIN_DB ){ |
128 - UnixUnusedFd *pUnused; | 123 - UnixUnusedFd *pUnused; |
129 - pUnused = findReusableFd(zName, flags); | 124 - pUnused = findReusableFd(zName, flags); |
130 - if( pUnused ){ | 125 - if( pUnused ){ |
131 - fd = pUnused->fd; | 126 - fd = pUnused->fd; |
132 - }else{ | 127 - }else{ |
133 - pUnused = sqlite3_malloc(sizeof(*pUnused)); | 128 - pUnused = sqlite3_malloc(sizeof(*pUnused)); |
134 - if( !pUnused ){ | 129 - if( !pUnused ){ |
135 - return SQLITE_NOMEM; | 130 - return SQLITE_NOMEM; |
136 - } | 131 - } |
137 + rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd); | 132 + rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd); |
138 + if( rc!=SQLITE_OK ){ | 133 + if( rc!=SQLITE_OK ){ |
139 + return rc; | 134 + return rc; |
140 } | 135 } |
141 - p->pUnused = pUnused; | 136 - p->pUnused = pUnused; |
142 }else if( !zName ){ | 137 |
143 /* If zName is NULL, the upper layer is requesting a temp file. */ | 138 /* Database filenames are double-zero terminated if they are not |
144 assert(isDelete && !isOpenDirectory); | 139 ** URIs with parameters. Hence, they can always be passed into |
145 @@ -4984,10 +5051,7 @@ static int unixOpen( | 140 @@ -5798,10 +5864,7 @@ static int unixOpen( |
146 *pOutFlags = flags; | 141 *pOutFlags = flags; |
147 } | 142 } |
148 | 143 |
149 - if( p->pUnused ){ | 144 - if( p->pUnused ){ |
150 - p->pUnused->fd = fd; | 145 - p->pUnused->fd = fd; |
151 - p->pUnused->flags = flags; | 146 - p->pUnused->flags = flags; |
152 - } | 147 - } |
153 + chromium_sqlite3_update_reusable_file_handle(pFile, fd, flags); | 148 + chromium_sqlite3_update_reusable_file_handle(pFile, fd, flags); |
154 | 149 |
155 if( isDelete ){ | 150 if( isDelete ){ |
156 #if OS_VXWORKS | 151 #if OS_VXWORKS |
157 @@ -5090,7 +5154,7 @@ static int unixOpen( | 152 @@ -5893,7 +5956,7 @@ static int unixOpen( |
158 isDelete, isReadonly); | 153 |
159 open_finished: | 154 open_finished: |
160 if( rc!=SQLITE_OK ){ | 155 if( rc!=SQLITE_OK ){ |
161 - sqlite3_free(p->pUnused); | 156 - sqlite3_free(p->pUnused); |
162 + chromium_sqlite3_destroy_reusable_file_handle(pFile); | 157 + chromium_sqlite3_destroy_reusable_file_handle(pFile); |
163 } | 158 } |
164 return rc; | 159 return rc; |
165 } | 160 } |
166 diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os
_win.c | 161 diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os
_win.c |
167 index c876833..78e58b5 100644 | 162 index 8ca2107..5b0a296 100644 |
168 --- a/third_party/sqlite/src/src/os_win.c | 163 --- a/third_party/sqlite/src/src/os_win.c |
169 +++ b/third_party/sqlite/src/src/os_win.c | 164 +++ b/third_party/sqlite/src/src/os_win.c |
170 @@ -2784,4 +2784,11 @@ int sqlite3_os_end(void){ | 165 @@ -5546,4 +5546,11 @@ int sqlite3_os_end(void){ |
171 return SQLITE_OK; | 166 return SQLITE_OK; |
172 } | 167 } |
173 | 168 |
174 +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE ha
ndle) { | 169 +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE ha
ndle) { |
175 + winFile* winSQLite3File = (winFile*)file; | 170 + winFile* winSQLite3File = (winFile*)file; |
176 + memset(file, 0, sizeof(*file)); | 171 + memset(file, 0, sizeof(*file)); |
177 + winSQLite3File->pMethod = &winIoMethod; | 172 + winSQLite3File->pMethod = &winIoMethod; |
178 + winSQLite3File->h = handle; | 173 + winSQLite3File->h = handle; |
179 +} | 174 +} |
180 + | 175 + |
181 #endif /* SQLITE_OS_WIN */ | 176 #endif /* SQLITE_OS_WIN */ |
182 -- | 177 -- |
183 2.2.1 | 178 2.2.1 |
184 | 179 |
OLD | NEW |