pager.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. ** 2001 September 15
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. ** This header file defines the interface that the sqlite page cache
  13. ** subsystem. The page cache subsystem reads and writes a file a page
  14. ** at a time and provides a journal for rollback.
  15. */
  16. #ifndef _PAGER_H_
  17. #define _PAGER_H_
  18. /*
  19. ** Default maximum size for persistent journal files. A negative
  20. ** value means no limit. This value may be overridden using the
  21. ** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
  22. */
  23. #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
  24. #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
  25. #endif
  26. /*
  27. ** The type used to represent a page number. The first page in a file
  28. ** is called page 1. 0 is used to represent "not a page".
  29. */
  30. typedef u32 Pgno;
  31. /*
  32. ** Each open file is managed by a separate instance of the "Pager" structure.
  33. */
  34. typedef struct Pager Pager;
  35. /*
  36. ** Handle type for pages.
  37. */
  38. typedef struct PgHdr DbPage;
  39. /*
  40. ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
  41. ** reserved for working around a windows/posix incompatibility). It is
  42. ** used in the journal to signify that the remainder of the journal file
  43. ** is devoted to storing a master journal name - there are no more pages to
  44. ** roll back. See comments for function writeMasterJournal() in pager.c
  45. ** for details.
  46. */
  47. #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
  48. /*
  49. ** Allowed values for the flags parameter to sqlite3PagerOpen().
  50. **
  51. ** NOTE: These values must match the corresponding BTREE_ values in btree.h.
  52. */
  53. #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
  54. #define PAGER_MEMORY 0x0002 /* In-memory database */
  55. /*
  56. ** Valid values for the second argument to sqlite3PagerLockingMode().
  57. */
  58. #define PAGER_LOCKINGMODE_QUERY -1
  59. #define PAGER_LOCKINGMODE_NORMAL 0
  60. #define PAGER_LOCKINGMODE_EXCLUSIVE 1
  61. /*
  62. ** Numeric constants that encode the journalmode.
  63. */
  64. #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
  65. #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
  66. #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
  67. #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
  68. #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */
  69. #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */
  70. #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */
  71. /*
  72. ** Flags that make up the mask passed to sqlite3PagerAcquire().
  73. */
  74. #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
  75. #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
  76. /*
  77. ** Flags for sqlite3PagerSetFlags()
  78. */
  79. #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
  80. #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
  81. #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
  82. #define PAGER_SYNCHRONOUS_MASK 0x03 /* Mask for three values above */
  83. #define PAGER_FULLFSYNC 0x04 /* PRAGMA fullfsync=ON */
  84. #define PAGER_CKPT_FULLFSYNC 0x08 /* PRAGMA checkpoint_fullfsync=ON */
  85. #define PAGER_CACHESPILL 0x10 /* PRAGMA cache_spill=ON */
  86. #define PAGER_FLAGS_MASK 0x1c /* All above except SYNCHRONOUS */
  87. /*
  88. ** The remainder of this file contains the declarations of the functions
  89. ** that make up the Pager sub-system API. See source code comments for
  90. ** a detailed description of each routine.
  91. */
  92. /* Open and close a Pager connection. */
  93. int sqlite3PagerOpen(
  94. sqlite3_vfs*,
  95. Pager **ppPager,
  96. const char*,
  97. int,
  98. int,
  99. int,
  100. void(*)(DbPage*)
  101. );
  102. int sqlite3PagerClose(Pager *pPager);
  103. int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
  104. /* Functions used to configure a Pager object. */
  105. void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
  106. int sqlite3PagerSetPagesize(Pager*, u32*, int);
  107. int sqlite3PagerMaxPageCount(Pager*, int);
  108. void sqlite3PagerSetCachesize(Pager*, int);
  109. void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64);
  110. void sqlite3PagerShrink(Pager*);
  111. void sqlite3PagerSetFlags(Pager*,unsigned);
  112. int sqlite3PagerLockingMode(Pager *, int);
  113. int sqlite3PagerSetJournalMode(Pager *, int);
  114. int sqlite3PagerGetJournalMode(Pager*);
  115. int sqlite3PagerOkToChangeJournalMode(Pager*);
  116. i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
  117. sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
  118. /* Functions used to obtain and release page references. */
  119. int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
  120. #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
  121. DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
  122. void sqlite3PagerRef(DbPage*);
  123. void sqlite3PagerUnref(DbPage*);
  124. /* Operations on page references. */
  125. int sqlite3PagerWrite(DbPage*);
  126. void sqlite3PagerDontWrite(DbPage*);
  127. int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
  128. int sqlite3PagerPageRefcount(DbPage*);
  129. void *sqlite3PagerGetData(DbPage *);
  130. void *sqlite3PagerGetExtra(DbPage *);
  131. /* Functions used to manage pager transactions and savepoints. */
  132. void sqlite3PagerPagecount(Pager*, int*);
  133. int sqlite3PagerBegin(Pager*, int exFlag, int);
  134. int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
  135. int sqlite3PagerExclusiveLock(Pager*);
  136. int sqlite3PagerSync(Pager *pPager);
  137. int sqlite3PagerCommitPhaseTwo(Pager*);
  138. int sqlite3PagerRollback(Pager*);
  139. int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
  140. int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
  141. int sqlite3PagerSharedLock(Pager *pPager);
  142. #ifndef SQLITE_OMIT_WAL
  143. int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*);
  144. int sqlite3PagerWalSupported(Pager *pPager);
  145. int sqlite3PagerWalCallback(Pager *pPager);
  146. int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
  147. int sqlite3PagerCloseWal(Pager *pPager);
  148. #endif
  149. #ifdef SQLITE_ENABLE_ZIPVFS
  150. int sqlite3PagerWalFramesize(Pager *pPager);
  151. #endif
  152. /* Functions used to query pager state and configuration. */
  153. u8 sqlite3PagerIsreadonly(Pager*);
  154. int sqlite3PagerRefcount(Pager*);
  155. int sqlite3PagerMemUsed(Pager*);
  156. const char *sqlite3PagerFilename(Pager*, int);
  157. const sqlite3_vfs *sqlite3PagerVfs(Pager*);
  158. sqlite3_file *sqlite3PagerFile(Pager*);
  159. const char *sqlite3PagerJournalname(Pager*);
  160. int sqlite3PagerNosync(Pager*);
  161. void *sqlite3PagerTempSpace(Pager*);
  162. int sqlite3PagerIsMemdb(Pager*);
  163. void sqlite3PagerCacheStat(Pager *, int, int, int *);
  164. void sqlite3PagerClearCache(Pager *);
  165. int sqlite3SectorSize(sqlite3_file *);
  166. /* Functions used to truncate the database file. */
  167. void sqlite3PagerTruncateImage(Pager*,Pgno);
  168. #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
  169. void *sqlite3PagerCodec(DbPage *);
  170. #endif
  171. /* Functions to support testing and debugging. */
  172. #if !defined(NDEBUG) || defined(SQLITE_TEST)
  173. Pgno sqlite3PagerPagenumber(DbPage*);
  174. int sqlite3PagerIswriteable(DbPage*);
  175. #endif
  176. #ifdef SQLITE_TEST
  177. int *sqlite3PagerStats(Pager*);
  178. void sqlite3PagerRefdump(Pager*);
  179. void disable_simulated_io_errors(void);
  180. void enable_simulated_io_errors(void);
  181. #else
  182. # define disable_simulated_io_errors()
  183. # define enable_simulated_io_errors()
  184. #endif
  185. #endif /* _PAGER_H_ */