engine/sqlite/src/journal.cpp
author skip
Thu, 25 Feb 2010 14:29:19 +0000
changeset 2 29cda98b007e
permissions -rw-r--r--
Initial import of Podcatcher from the Bergamot project
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     1
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
** 2007 August 22
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     3
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     4
** The author disclaims copyright to this source code.  In place of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
** a legal notice, here is a blessing:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
**    May you do good and not evil.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
**    May you find forgiveness for yourself and forgive others.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
**    May you share freely, never taking more than you give.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
*************************************************************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
** @(#) $Id: journal.cpp 1282 2008-11-13 09:31:33Z LarsPson $
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    19
** This file implements a special kind of sqlite3_file object used
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
** by SQLite to create journal files if the atomic-write optimization
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
** is enabled.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
** The distinctive characteristic of this sqlite3_file is that the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
** actual on disk file is created lazily. When the file is created,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
** the caller specifies a buffer size for an in-memory buffer to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
** be used to service read() and write() requests. The actual file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
** on disk is not created or populated until either:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
**   1) The in-memory representation grows too large for the allocated 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
**      buffer, or
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
**   2) The xSync() method is called.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
#include "sqliteInt.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
** A JournalFile object is a subclass of sqlite3_file used by
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
** as an open file handle for journal files.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
struct JournalFile {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
  sqlite3_io_methods *pMethod;    /* I/O methods on journal files */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
  int nBuf;                       /* Size of zBuf[] in bytes */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
  char *zBuf;                     /* Space to buffer journal writes */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
  int iSize;                      /* Amount of zBuf[] currently used */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
  int flags;                      /* xOpen flags */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
  sqlite3_vfs *pVfs;              /* The "real" underlying VFS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
  sqlite3_file *pReal;            /* The "real" underlying file descriptor */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
  const char *zJournal;           /* Name of the journal file */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
};
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
typedef struct JournalFile JournalFile;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
** If it does not already exists, create and populate the on-disk file 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
** for JournalFile p.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
static int createFile(JournalFile *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
  if( !p->pReal ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
    sqlite3_file *pReal = (sqlite3_file *)&p[1];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
    rc = sqlite3OsOpen(p->pVfs, p->zJournal, pReal, p->flags, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
    if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
      p->pReal = pReal;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
      if( p->iSize>0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
        assert(p->iSize<=p->nBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
        rc = sqlite3OsWrite(p->pReal, p->zBuf, p->iSize, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
** Close the file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
static int jrnlClose(sqlite3_file *pJfd){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
  JournalFile *p = (JournalFile *)pJfd;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
  if( p->pReal ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
    sqlite3OsClose(p->pReal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
  sqlite3_free(p->zBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
** Read data from the file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
static int jrnlRead(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
  sqlite3_file *pJfd,    /* The journal file from which to read */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
  void *zBuf,            /* Put the results here */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
  int iAmt,              /* Number of bytes to read */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
  sqlite_int64 iOfst     /* Begin reading at this offset */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
  JournalFile *p = (JournalFile *)pJfd;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
  if( p->pReal ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
    rc = sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
    assert( iAmt+iOfst<=p->iSize );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
    memcpy(zBuf, &p->zBuf[iOfst], iAmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
** Write data to the file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
static int jrnlWrite(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
  sqlite3_file *pJfd,    /* The journal file into which to write */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
  const void *zBuf,      /* Take data to be written from here */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
  int iAmt,              /* Number of bytes to write */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
  sqlite_int64 iOfst     /* Begin writing at this offset into the file */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
  JournalFile *p = (JournalFile *)pJfd;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
  if( !p->pReal && (iOfst+iAmt)>p->nBuf ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
    rc = createFile(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
  if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
    if( p->pReal ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
      rc = sqlite3OsWrite(p->pReal, zBuf, iAmt, iOfst);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
      memcpy(&p->zBuf[iOfst], zBuf, iAmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
      if( p->iSize<(iOfst+iAmt) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
        p->iSize = (iOfst+iAmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
** Truncate the file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
static int jrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
  JournalFile *p = (JournalFile *)pJfd;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
  if( p->pReal ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
    rc = sqlite3OsTruncate(p->pReal, size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
  }else if( size<p->iSize ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
    p->iSize = size;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
** Sync the file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
static int jrnlSync(sqlite3_file *pJfd, int flags){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
  JournalFile *p = (JournalFile *)pJfd;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
  rc = createFile(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
  if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
    rc = sqlite3OsSync(p->pReal, flags);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
** Query the size of the file in bytes.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
static int jrnlFileSize(sqlite3_file *pJfd, sqlite_int64 *pSize){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
  JournalFile *p = (JournalFile *)pJfd;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
  if( p->pReal ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
    rc = sqlite3OsFileSize(p->pReal, pSize);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
    *pSize = (sqlite_int64) p->iSize;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
** Table of methods for JournalFile sqlite3_file object.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
static struct sqlite3_io_methods JournalFileMethods = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
  1,             /* iVersion */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
  jrnlClose,     /* xClose */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
  jrnlRead,      /* xRead */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
  jrnlWrite,     /* xWrite */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
  jrnlTruncate,  /* xTruncate */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
  jrnlSync,      /* xSync */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
  jrnlFileSize,  /* xFileSize */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
  0,             /* xLock */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
  0,             /* xUnlock */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
  0,             /* xCheckReservedLock */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
  0,             /* xFileControl */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
  0,             /* xSectorSize */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
  0              /* xDeviceCharacteristics */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
};
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
/* 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
** Open a journal file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
int sqlite3JournalOpen(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
  sqlite3_vfs *pVfs,         /* The VFS to use for actual file I/O */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
  const char *zName,         /* Name of the journal file */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
  sqlite3_file *pJfd,        /* Preallocated, blank file handle */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
  int flags,                 /* Opening flags */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
  int nBuf                   /* Bytes buffered before opening the file */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
  JournalFile *p = (JournalFile *)pJfd;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
  memset(p, 0, sqlite3JournalSize(pVfs));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
  if( nBuf>0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
    p->zBuf = sqlite3MallocZero(nBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
    if( !p->zBuf ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
      return SQLITE_NOMEM;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
    return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
  p->pMethod = &JournalFileMethods;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
  p->nBuf = nBuf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
  p->flags = flags;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
  p->zJournal = zName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
  p->pVfs = pVfs;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
** If the argument p points to a JournalFile structure, and the underlying
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
** file has not yet been created, create it now.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
int sqlite3JournalCreate(sqlite3_file *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
  if( p->pMethods!=&JournalFileMethods ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
    return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
  return createFile((JournalFile *)p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
/* 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
** Return the number of bytes required to store a JournalFile that uses vfs
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
** pVfs to create the underlying on-disk files.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
int sqlite3JournalSize(sqlite3_vfs *pVfs){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
  return (pVfs->szOsFile+sizeof(JournalFile));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
#endif