-C Improved\scomments\son\sthe\sserver\sand\sasynchronous\sI/O\sdemo\sprograms.\s(CVS\s2909)
-D 2006-01-10T20:01:19
+C Combine\smultiple\ssmall\scalls\sto\ssqlite3OsWrite\sinto\sone\slarger\scall.\s(CVS\s2910)
+D 2006-01-10T20:32:32
F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c 8ef250a0965a55dbcd8ef785e03f9f3292e6ade2
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c f84488fa616f1279761aaf06b0acc42af345d3a5
+F src/pager.c 0a59a320b0da6b22d2dd4411d16e300ff1b947c8
F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c
F src/pragma.c 711992e440ce78569322dd625d2cfe1cd696ccfb
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 1cf6855430352ffbf921a977186345d7272fe272
-R c77d71bb3bbb59cc1b67cf59dbab5a91
+P c0f47ccbc915f20d56f393383c21b4026785e6a5
+R 47f576a3900e4c28937875b78f472e44
U drh
-Z 85b6b185878e0427b46314ea83850303
+Z b4dc310261f3df513fff82ddf0ae5002
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.234 2006/01/09 23:40:25 drh Exp $
+** @(#) $Id: pager.c,v 1.235 2006/01/10 20:32:32 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
}
/*
-** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK
-** on success or an error code is something goes wrong.
+** Write a 32-bit integer into a string buffer in big-endian byte order.
*/
-static int write32bits(OsFile *fd, u32 val){
- unsigned char ac[4];
+static void put32bits(char *ac, u32 val){
ac[0] = (val>>24) & 0xff;
ac[1] = (val>>16) & 0xff;
ac[2] = (val>>8) & 0xff;
ac[3] = val & 0xff;
+}
+
+/*
+** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK
+** on success or an error code is something goes wrong.
+*/
+static int write32bits(OsFile *fd, u32 val){
+ unsigned char ac[4];
+ put32bits(ac, val);
return sqlite3OsWrite(fd, ac, 4);
}
static void store32bits(u32 val, PgHdr *p, int offset){
unsigned char *ac;
ac = &((unsigned char*)PGHDR_TO_DATA(p))[offset];
- ac[0] = (val>>24) & 0xff;
- ac[1] = (val>>16) & 0xff;
- ac[2] = (val>>8) & 0xff;
- ac[3] = val & 0xff;
+ put32bits(ac, val);
}
/*
** Followed by (JOURNAL_HDR_SZ - 24) bytes of unused space.
*/
static int writeJournalHdr(Pager *pPager){
+ char zHeader[sizeof(aJournalMagic)+16];
int rc = seekJournalHdr(pPager);
if( rc ) return rc;
** Actually maybe the whole journal header should be delayed until that
** point. Think about this.
*/
- rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
-
- if( rc==SQLITE_OK ){
- /* The nRec Field. 0xFFFFFFFF for no-sync journals. */
- rc = write32bits(pPager->jfd, pPager->noSync ? 0xffffffff : 0);
- }
- if( rc==SQLITE_OK ){
- /* The random check-hash initialiser */
- sqlite3Randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
- rc = write32bits(pPager->jfd, pPager->cksumInit);
- }
- if( rc==SQLITE_OK ){
- /* The initial database size */
- rc = write32bits(pPager->jfd, pPager->dbSize);
- }
- if( rc==SQLITE_OK ){
- /* The assumed sector size for this process */
- rc = write32bits(pPager->jfd, pPager->sectorSize);
- }
+ memcpy(zHeader, aJournalMagic, sizeof(aJournalMagic));
+ /* The nRec Field. 0xFFFFFFFF for no-sync journals. */
+ put32bits(&zHeader[sizeof(aJournalMagic)], pPager->noSync ? 0xffffffff : 0);
+ /* The random check-hash initialiser */
+ sqlite3Randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
+ put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
+ /* The initial database size */
+ put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbSize);
+ /* The assumed sector size for this process */
+ put32bits(&zHeader[sizeof(aJournalMagic)+12], pPager->sectorSize);
+ rc = sqlite3OsWrite(pPager->jfd, zHeader, sizeof(zHeader));
/* The journal header has been written successfully. Seek the journal
** file descriptor to the end of the journal header sector.
int rc;
int len;
int i;
- u32 cksum = 0;
+ u32 cksum = 0;
+ char zBuf[sizeof(aJournalMagic)+2*4];
if( !zMaster || pPager->setMaster) return SQLITE_OK;
pPager->setMaster = 1;
rc = sqlite3OsWrite(pPager->jfd, zMaster, len);
if( rc!=SQLITE_OK ) return rc;
- rc = write32bits(pPager->jfd, len);
- if( rc!=SQLITE_OK ) return rc;
-
- rc = write32bits(pPager->jfd, cksum);
- if( rc!=SQLITE_OK ) return rc;
-
- rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
+ put32bits(zBuf, len);
+ put32bits(&zBuf[4], cksum);
+ memcpy(&zBuf[8], aJournalMagic, sizeof(aJournalMagic));
+ rc = sqlite3OsWrite(pPager->jfd, zBuf, 8+sizeof(aJournalMagic));
pPager->needSync = !pPager->noSync;
return rc;
}