OLD | NEW |
1 /* | 1 /* |
2 ** 2004 April 6 | 2 ** 2004 April 6 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 /* | 252 /* |
253 ** Page type flags. An ORed combination of these flags appear as the | 253 ** Page type flags. An ORed combination of these flags appear as the |
254 ** first byte of on-disk image of every BTree page. | 254 ** first byte of on-disk image of every BTree page. |
255 */ | 255 */ |
256 #define PTF_INTKEY 0x01 | 256 #define PTF_INTKEY 0x01 |
257 #define PTF_ZERODATA 0x02 | 257 #define PTF_ZERODATA 0x02 |
258 #define PTF_LEAFDATA 0x04 | 258 #define PTF_LEAFDATA 0x04 |
259 #define PTF_LEAF 0x08 | 259 #define PTF_LEAF 0x08 |
260 | 260 |
261 /* | 261 /* |
262 ** As each page of the file is loaded into memory, an instance of the following | 262 ** An instance of this object stores information about each a single database |
263 ** structure is appended and initialized to zero. This structure stores | 263 ** page that has been loaded into memory. The information in this object |
264 ** information about the page that is decoded from the raw file page. | 264 ** is derived from the raw on-disk page content. |
265 ** | 265 ** |
266 ** The pParent field points back to the parent page. This allows us to | 266 ** As each database page is loaded into memory, the pager allocats an |
267 ** walk up the BTree from any leaf to the root. Care must be taken to | 267 ** instance of this object and zeros the first 8 bytes. (This is the |
268 ** unref() the parent page pointer when this page is no longer referenced. | 268 ** "extra" information associated with each page of the pager.) |
269 ** The pageDestructor() routine handles that chore. | |
270 ** | 269 ** |
271 ** Access to all fields of this structure is controlled by the mutex | 270 ** Access to all fields of this structure is controlled by the mutex |
272 ** stored in MemPage.pBt->mutex. | 271 ** stored in MemPage.pBt->mutex. |
273 */ | 272 */ |
274 struct MemPage { | 273 struct MemPage { |
275 u8 isInit; /* True if previously initialized. MUST BE FIRST! */ | 274 u8 isInit; /* True if previously initialized. MUST BE FIRST! */ |
276 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */ | 275 u8 bBusy; /* Prevent endless loops on corrupt database files */ |
277 u8 intKey; /* True if table b-trees. False for index b-trees */ | 276 u8 intKey; /* True if table b-trees. False for index b-trees */ |
278 u8 intKeyLeaf; /* True if the leaf of an intKey table */ | 277 u8 intKeyLeaf; /* True if the leaf of an intKey table */ |
279 u8 noPayload; /* True if internal intKey page (thus w/o data) */ | 278 Pgno pgno; /* Page number for this page */ |
| 279 /* Only the first 8 bytes (above) are zeroed by pager.c when a new page |
| 280 ** is allocated. All fields that follow must be initialized before use */ |
280 u8 leaf; /* True if a leaf page */ | 281 u8 leaf; /* True if a leaf page */ |
281 u8 hdrOffset; /* 100 for page 1. 0 otherwise */ | 282 u8 hdrOffset; /* 100 for page 1. 0 otherwise */ |
282 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */ | 283 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */ |
283 u8 max1bytePayload; /* min(maxLocal,127) */ | 284 u8 max1bytePayload; /* min(maxLocal,127) */ |
284 u8 bBusy; /* Prevent endless loops on corrupt database files */ | 285 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */ |
285 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */ | 286 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */ |
286 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */ | 287 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */ |
287 u16 cellOffset; /* Index in aData of first cell pointer */ | 288 u16 cellOffset; /* Index in aData of first cell pointer */ |
288 u16 nFree; /* Number of free bytes on the page */ | 289 u16 nFree; /* Number of free bytes on the page */ |
289 u16 nCell; /* Number of cells on this page, local and ovfl */ | 290 u16 nCell; /* Number of cells on this page, local and ovfl */ |
290 u16 maskPage; /* Mask for page offset */ | 291 u16 maskPage; /* Mask for page offset */ |
291 u16 aiOvfl[5]; /* Insert the i-th overflow cell before the aiOvfl-th | 292 u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th |
292 ** non-overflow cell */ | 293 ** non-overflow cell */ |
293 u8 *apOvfl[5]; /* Pointers to the body of overflow cells */ | 294 u8 *apOvfl[4]; /* Pointers to the body of overflow cells */ |
294 BtShared *pBt; /* Pointer to BtShared that this page is part of */ | 295 BtShared *pBt; /* Pointer to BtShared that this page is part of */ |
295 u8 *aData; /* Pointer to disk image of the page data */ | 296 u8 *aData; /* Pointer to disk image of the page data */ |
296 u8 *aDataEnd; /* One byte past the end of usable data */ | 297 u8 *aDataEnd; /* One byte past the end of usable data */ |
297 u8 *aCellIdx; /* The cell index area */ | 298 u8 *aCellIdx; /* The cell index area */ |
298 u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ | 299 u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ |
299 DbPage *pDbPage; /* Pager page handle */ | 300 DbPage *pDbPage; /* Pager page handle */ |
300 u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */ | 301 u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */ |
301 void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */ | 302 void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */ |
302 Pgno pgno; /* Page number for this page */ | |
303 }; | 303 }; |
304 | 304 |
305 /* | 305 /* |
306 ** The in-memory image of a disk page has the auxiliary information appended | |
307 ** to the end. EXTRA_SIZE is the number of bytes of space needed to hold | |
308 ** that extra information. | |
309 */ | |
310 #define EXTRA_SIZE sizeof(MemPage) | |
311 | |
312 /* | |
313 ** A linked list of the following structures is stored at BtShared.pLock. | 306 ** A linked list of the following structures is stored at BtShared.pLock. |
314 ** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor | 307 ** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor |
315 ** is opened on the table with root page BtShared.iTable. Locks are removed | 308 ** is opened on the table with root page BtShared.iTable. Locks are removed |
316 ** from this list when a transaction is committed or rolled back, or when | 309 ** from this list when a transaction is committed or rolled back, or when |
317 ** a btree handle is closed. | 310 ** a btree handle is closed. |
318 */ | 311 */ |
319 struct BtLock { | 312 struct BtLock { |
320 Btree *pBtree; /* Btree handle holding this lock */ | 313 Btree *pBtree; /* Btree handle holding this lock */ |
321 Pgno iTable; /* Root page of table */ | 314 Pgno iTable; /* Root page of table */ |
322 u8 eLock; /* READ_LOCK or WRITE_LOCK */ | 315 u8 eLock; /* READ_LOCK or WRITE_LOCK */ |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 #define get4byte sqlite3Get4byte | 685 #define get4byte sqlite3Get4byte |
693 #define put4byte sqlite3Put4byte | 686 #define put4byte sqlite3Put4byte |
694 | 687 |
695 /* | 688 /* |
696 ** get2byteAligned(), unlike get2byte(), requires that its argument point to a | 689 ** get2byteAligned(), unlike get2byte(), requires that its argument point to a |
697 ** two-byte aligned address. get2bytea() is only used for accessing the | 690 ** two-byte aligned address. get2bytea() is only used for accessing the |
698 ** cell addresses in a btree header. | 691 ** cell addresses in a btree header. |
699 */ | 692 */ |
700 #if SQLITE_BYTEORDER==4321 | 693 #if SQLITE_BYTEORDER==4321 |
701 # define get2byteAligned(x) (*(u16*)(x)) | 694 # define get2byteAligned(x) (*(u16*)(x)) |
702 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ | 695 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000 |
703 && GCC_VERSION>=4008000 | |
704 # define get2byteAligned(x) __builtin_bswap16(*(u16*)(x)) | 696 # define get2byteAligned(x) __builtin_bswap16(*(u16*)(x)) |
705 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ | 697 #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
706 && defined(_MSC_VER) && _MSC_VER>=1300 | |
707 # define get2byteAligned(x) _byteswap_ushort(*(u16*)(x)) | 698 # define get2byteAligned(x) _byteswap_ushort(*(u16*)(x)) |
708 #else | 699 #else |
709 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1]) | 700 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1]) |
710 #endif | 701 #endif |
OLD | NEW |