diff options
author | dan <dan@noemail.net> | 2014-09-06 17:06:13 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2014-09-06 17:06:13 +0000 |
commit | 524a733d89355f01eac235d926e97b5cd6836b98 (patch) | |
tree | be774555c82801a538802d06ef4189499b1e6e2f /src/os_unix.c | |
parent | 60ec914c74ec79e4b73c004d1c21330be7916c99 (diff) | |
parent | 3fdf46a16e592de482a81721ff32e85b6d50006a (diff) | |
download | sqlite-524a733d89355f01eac235d926e97b5cd6836b98.tar.gz sqlite-524a733d89355f01eac235d926e97b5cd6836b98.zip |
Fixes to os_unix.c to support database (and other) files larger than 2GiB on Android.
FossilOrigin-Name: ad7063aa1a0db32cdbe71815545b2edca57d3bcc
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index c4f1d40d4..5e820260a 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -300,6 +300,14 @@ static int randomnessPid = 0; #endif /* +** Explicitly call the 64-bit version of lseek() on Android. Otherwise, lseek() +** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined. +*/ +#ifdef __ANDROID__ +# define lseek lseek64 +#endif + +/* ** Different Unix systems declare open() in different ways. Same use ** open(const char*,int,mode_t). Others use open(const char*,int,...). ** The difference is important when using a pointer to the function. @@ -708,9 +716,22 @@ static int lockTrace(int fd, int op, struct flock *p){ /* ** Retry ftruncate() calls that fail due to EINTR +** +** All calls to ftruncate() within this file should be made through this wrapper. +** On the Android platform, bypassing the logic below could lead to a corrupt +** database. */ static int robust_ftruncate(int h, sqlite3_int64 sz){ int rc; +#ifdef __ANDROID__ + /* On Android, ftruncate() always uses 32-bit offsets, even if + ** _FILE_OFFSET_BITS=64 is defined. This means it is unsafe to attempt to + ** truncate a file to any size larger than 2GiB. Silently ignore any + ** such attempts. */ + if( sz>(sqlite3_int64)0x7FFFFFFF ){ + rc = SQLITE_OK; + }else +#endif do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR ); return rc; } @@ -3595,7 +3616,7 @@ static int unixTruncate(sqlite3_file *id, i64 nByte){ nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; } - rc = robust_ftruncate(pFile->h, (off_t)nByte); + rc = robust_ftruncate(pFile->h, nByte); if( rc ){ pFile->lastErrno = errno; return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); |