/ Check-in [1d30d0dd]
Login

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

Overview
Comment:Use the F_FULLFSYNC fctrl if it is available. Record the name of files that are opened in the OsFile structure. (CVS 1799)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1d30d0dd46c2bd12ce3f7dc06492f3e27ab6bcee
User & Date: drh 2004-07-17 21:44:57
Context
2004-07-17
21:56
mprintf() correctly handles "%s","". Fix for ticket #812. (CVS 1800) check-in: 4f56db11 user: drh tags: trunk
21:44
Use the F_FULLFSYNC fctrl if it is available. Record the name of files that are opened in the OsFile structure. (CVS 1799) check-in: 1d30d0dd user: drh tags: trunk
2004-07-15
20:08
Added tests for sqlite3_changes after a DELETE. (CVS 1798) check-in: c01f1326 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   649    649   */
   650    650   int sqlite3OsSeek(OsFile *id, off_t offset){
   651    651     assert( id->isOpen );
   652    652     SEEK(offset/1024 + 1);
   653    653     lseek(id->h, offset, SEEK_SET);
   654    654     return SQLITE_OK;
   655    655   }
          656  +
          657  +/*
          658  +** The fsync() system call does not work as advertised on many
          659  +** unix systems.  The following procedure is an attempt to make
          660  +** it work better.
          661  +*/
          662  +static int full_fsync(int fd){
          663  +  int rc;
          664  +#ifdef F_FULLFSYNC
          665  +  rc = fcntl(fd, F_FULLFSYNC, 0);
          666  +  if( rc ) rc = fsync(fd);
          667  +#else
          668  +  rc = fsync(fd);
          669  +#endif
          670  +  return rc;
          671  +}
   656    672   
   657    673   /*
   658    674   ** Make sure all writes to a particular file are committed to disk.
   659    675   **
   660    676   ** Under Unix, also make sure that the directory entry for the file
   661    677   ** has been created by fsync-ing the directory that contains the file.
   662    678   ** If we do not do this and we encounter a power failure, the directory
................................................................................
   665    681   ** the directory entry for the journal was never created) and the transaction
   666    682   ** will not roll back - possibly leading to database corruption.
   667    683   */
   668    684   int sqlite3OsSync(OsFile *id){
   669    685     assert( id->isOpen );
   670    686     SimulateIOError(SQLITE_IOERR);
   671    687     TRACE2("SYNC    %-3d\n", id->h);
   672         -  if( fsync(id->h) ){
          688  +  if( full_fsync(id->h) ){
   673    689       return SQLITE_IOERR;
   674    690     }
   675    691     if( id->dirfd>=0 ){
   676    692       TRACE2("DIRSYNC %-3d\n", id->dirfd);
   677         -    fsync(id->dirfd);
          693  +    full_fsync(id->dirfd);
   678    694       close(id->dirfd);  /* Only need to sync once, so close the directory */
   679    695       id->dirfd = -1;    /* when we are done. */
   680    696     }
   681    697     return SQLITE_OK;
   682    698   }
   683    699   
   684    700   /*
................................................................................
  1053   1069   }
  1054   1070   
  1055   1071   /*
  1056   1072   ** Close a file.
  1057   1073   */
  1058   1074   int sqlite3OsClose(OsFile *id){
  1059   1075     if( !id->isOpen ) return SQLITE_OK;
         1076  +  id->zFilename = 0;
  1060   1077     sqlite3OsUnlock(id, NO_LOCK);
  1061   1078     if( id->dirfd>=0 ) close(id->dirfd);
  1062   1079     id->dirfd = -1;
  1063   1080     sqlite3OsEnterMutex();
  1064   1081     if( id->pOpen->nLock ){
  1065   1082       /* If there are outstanding locks, do not actually close the file just
  1066   1083       ** yet because that would clear those locks.  Instead, add the file

Changes to src/os_unix.h.

    61     61   ** PENDING_LOCK or EXCLUSIVE_LOCK.
    62     62   */
    63     63   typedef struct OsFile OsFile;
    64     64   struct OsFile {
    65     65     struct openCnt *pOpen;    /* Info about all open fd's on this inode */
    66     66     struct lockInfo *pLock;   /* Info about locks on this inode */
    67     67     int h;                    /* The file descriptor */
           68  +  const char *zFilename;    /* Name passed to open() */
    68     69     unsigned char locktype;   /* The type of lock held on this fd */
    69     70     unsigned char isOpen;     /* True if needs to be closed */
    70     71     int dirfd;                /* File descriptor for the directory */
    71     72   };
    72     73   
    73     74   /*
    74     75   ** Maximum number of characters in a temporary file name