/ Check-in [32984410]
Login

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

Overview
Comment:Updated comments on journal.c. No changes to code. (CVS 4408)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3298441086330d1d24c30b7c061dfec98e9ea3ac
User & Date: drh 2007-09-06 13:49:37
Context
2007-09-06
22:19
Allocate page cache headers and page cache data buffers separately. The data buffer will be a power of two in size and this gives some malloc implementation additional optimization opportunitites. (CVS 4409) check-in: 2b755def user: drh tags: trunk
13:49
Updated comments on journal.c. No changes to code. (CVS 4408) check-in: 32984410 user: drh tags: trunk
07:47
Add some extra comments to the header in test_async.c. (CVS 4407) check-in: 79cf4e88 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/journal.c.

     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13         -** @(#) $Id: journal.c,v 1.6 2007/09/03 15:19:35 drh Exp $
           13  +** @(#) $Id: journal.c,v 1.7 2007/09/06 13:49:37 drh Exp $
    14     14   */
    15     15   
    16     16   #ifdef SQLITE_ENABLE_ATOMIC_WRITE
    17     17   
    18     18   /*
    19     19   ** This file implements a special kind of sqlite3_file object used
    20     20   ** by SQLite to create journal files if the atomic-write optimization
................................................................................
    29     29   **   1) The in-memory representation grows too large for the allocated 
    30     30   **      buffer, or
    31     31   **   2) The xSync() method is called.
    32     32   */
    33     33   
    34     34   #include "sqliteInt.h"
    35     35   
           36  +
           37  +/*
           38  +** A JournalFile object is a subclass of sqlite3_file used by
           39  +** as an open file handle for journal files.
           40  +*/
    36     41   struct JournalFile {
    37         -  sqlite3_io_methods *pMethod;
    38         -
    39         -  int nBuf;
    40         -  char *zBuf;
    41         -  int iSize;
    42         -
    43         -  int flags;
    44         -  sqlite3_vfs *pVfs;
    45         -  sqlite3_file *pReal;
    46         -  const char *zJournal;
           42  +  sqlite3_io_methods *pMethod;    /* I/O methods on journal files */
           43  +  int nBuf;                       /* Size of zBuf[] in bytes */
           44  +  char *zBuf;                     /* Space to buffer journal writes */
           45  +  int iSize;                      /* Amount of zBuf[] currently used */
           46  +  int flags;                      /* xOpen flags */
           47  +  sqlite3_vfs *pVfs;              /* The "real" underlying VFS */
           48  +  sqlite3_file *pReal;            /* The "real" underlying file descriptor */
           49  +  const char *zJournal;           /* Name of the journal file */
    47     50   };
    48     51   typedef struct JournalFile JournalFile;
    49     52   
    50     53   /*
    51     54   ** If it does not already exists, create and populate the on-disk file 
    52     55   ** for JournalFile p.
    53     56   */
................................................................................
    79     82     return SQLITE_OK;
    80     83   }
    81     84   
    82     85   /*
    83     86   ** Read data from the file.
    84     87   */
    85     88   static int jrnlRead(
    86         -  sqlite3_file *pJfd, 
    87         -  void *zBuf, 
    88         -  int iAmt, 
    89         -  sqlite_int64 iOfst
           89  +  sqlite3_file *pJfd,    /* The journal file from which to read */
           90  +  void *zBuf,            /* Put the results here */
           91  +  int iAmt,              /* Number of bytes to read */
           92  +  sqlite_int64 iOfst     /* Begin reading at this offset */
    90     93   ){
    91     94     int rc = SQLITE_OK;
    92     95     JournalFile *p = (JournalFile *)pJfd;
    93     96     if( p->pReal ){
    94     97       rc = sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst);
    95     98     }else{
    96     99       assert( iAmt+iOfst<=p->iSize );
................................................................................
    99    102     return rc;
   100    103   }
   101    104   
   102    105   /*
   103    106   ** Write data to the file.
   104    107   */
   105    108   static int jrnlWrite(
   106         -  sqlite3_file *pJfd, 
   107         -  const void *zBuf, 
   108         -  int iAmt, 
   109         -  sqlite_int64 iOfst
          109  +  sqlite3_file *pJfd,    /* The journal file into which to write */
          110  +  const void *zBuf,      /* Take data to be written from here */
          111  +  int iAmt,              /* Number of bytes to write */
          112  +  sqlite_int64 iOfst     /* Begin writing at this offset into the file */
   110    113   ){
   111    114     int rc = SQLITE_OK;
   112    115     JournalFile *p = (JournalFile *)pJfd;
   113    116     if( !p->pReal && (iOfst+iAmt)>p->nBuf ){
   114    117       rc = createFile(p);
   115    118     }
   116    119     if( rc==SQLITE_OK ){
................................................................................
   186    189     0              /* xDeviceCharacteristics */
   187    190   };
   188    191   
   189    192   /* 
   190    193   ** Open a journal file.
   191    194   */
   192    195   int sqlite3JournalOpen(
   193         -  sqlite3_vfs *pVfs, 
   194         -  const char *zName, 
   195         -  sqlite3_file *pJfd,
   196         -  int flags,
   197         -  int nBuf
          196  +  sqlite3_vfs *pVfs,         /* The VFS to use for actual file I/O */
          197  +  const char *zName,         /* Name of the journal file */
          198  +  sqlite3_file *pJfd,        /* Preallocated, blank file handle */
          199  +  int flags,                 /* Opening flags */
          200  +  int nBuf                   /* Bytes buffered before opening the file */
   198    201   ){
   199    202     JournalFile *p = (JournalFile *)pJfd;
   200    203     memset(p, 0, sqlite3JournalSize(pVfs));
   201    204     if( nBuf>0 ){
   202    205       p->zBuf = sqlite3MallocZero(nBuf);
   203    206       if( !p->zBuf ){
   204    207         return SQLITE_NOMEM;