/ Check-in [ad7063aa]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixes to os_unix.c to support database (and other) files larger than 2GiB on Android.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ad7063aa1a0db32cdbe71815545b2edca57d3bcc
User & Date: dan 2014-09-06 17:06:13
Context
2014-09-11
17:27
Add the SQLITE_USER_AUTHENTICATION extension to the trunk. This extension is disabled by default. Special compilation procedures are need to enable it. check-in: 65884d4f user: drh tags: trunk
2014-09-09
17:27
Add new APIs that take 64-bit length parameters: sqlite3_malloc64(), sqlite3_realloc64(), sqlite3_bind_blob64(), sqlite3_bind_texte64(), sqlite3_result_blob64(), and sqlite3_result_texte64(). Internal memory allocation routines also now use 64-bit unsigned length parameters for safety. Also add the sqlite3_msize() interface. Fix the sqlite3_get_table() to use sqlite3_realloc64() to avoid a integer overflow problem. check-in: 94954850 user: drh tags: 64-bit-lengths
14:47
Non-working preliminary implementation attempts on user authentication. check-in: 8440f093 user: drh tags: user-auth
2014-09-08
15:04
Merge support for large files on Android from trunk. check-in: c2885c6b user: drh tags: sessions
2014-09-06
17:06
Fixes to os_unix.c to support database (and other) files larger than 2GiB on Android. check-in: ad7063aa user: dan tags: trunk
16:52
Merge latest trunk changes with this branch. Closed-Leaf check-in: 9dca7ce5 user: dan tags: android-large-filles
16:39
Fix typos in comments. No code changes. check-in: e62aab5e user: peter.d.reid tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   295    295   # if defined(__linux__) && defined(_GNU_SOURCE)
   296    296   #  define HAVE_MREMAP 1
   297    297   # else
   298    298   #  define HAVE_MREMAP 0
   299    299   # endif
   300    300   #endif
   301    301   
          302  +/*
          303  +** Explicitly call the 64-bit version of lseek() on Android. Otherwise, lseek()
          304  +** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined.
          305  +*/
          306  +#ifdef __ANDROID__
          307  +# define lseek lseek64
          308  +#endif
          309  +
   302    310   /*
   303    311   ** Different Unix systems declare open() in different ways.  Same use
   304    312   ** open(const char*,int,mode_t).  Others use open(const char*,int,...).
   305    313   ** The difference is important when using a pointer to the function.
   306    314   **
   307    315   ** The safest way to deal with the problem is to always use this wrapper
   308    316   ** which always has the same well-defined interface.
................................................................................
   704    712   }
   705    713   #undef osFcntl
   706    714   #define osFcntl lockTrace
   707    715   #endif /* SQLITE_LOCK_TRACE */
   708    716   
   709    717   /*
   710    718   ** Retry ftruncate() calls that fail due to EINTR
          719  +**
          720  +** All calls to ftruncate() within this file should be made through this wrapper.
          721  +** On the Android platform, bypassing the logic below could lead to a corrupt
          722  +** database.
   711    723   */
   712    724   static int robust_ftruncate(int h, sqlite3_int64 sz){
   713    725     int rc;
          726  +#ifdef __ANDROID__
          727  +  /* On Android, ftruncate() always uses 32-bit offsets, even if 
          728  +  ** _FILE_OFFSET_BITS=64 is defined. This means it is unsafe to attempt to
          729  +  ** truncate a file to any size larger than 2GiB. Silently ignore any
          730  +  ** such attempts.  */
          731  +  if( sz>(sqlite3_int64)0x7FFFFFFF ){
          732  +    rc = SQLITE_OK;
          733  +  }else
          734  +#endif
   714    735     do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR );
   715    736     return rc;
   716    737   }
   717    738   
   718    739   /*
   719    740   ** This routine translates a standard POSIX errno code into something
   720    741   ** useful to the clients of the sqlite3 functions.  Specifically, it is
................................................................................
  3591   3612     ** actual file size after the operation may be larger than the requested
  3592   3613     ** size).
  3593   3614     */
  3594   3615     if( pFile->szChunk>0 ){
  3595   3616       nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
  3596   3617     }
  3597   3618   
  3598         -  rc = robust_ftruncate(pFile->h, (off_t)nByte);
         3619  +  rc = robust_ftruncate(pFile->h, nByte);
  3599   3620     if( rc ){
  3600   3621       pFile->lastErrno = errno;
  3601   3622       return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
  3602   3623     }else{
  3603   3624   #ifdef SQLITE_DEBUG
  3604   3625       /* If we are doing a normal write to a database file (as opposed to
  3605   3626       ** doing a hot-journal rollback or a write to some file other than a