/ Check-in [57a674fc]
Login

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

Overview
Comment:Add an OS method for making copies of file descriptors. This fixes the crash tests. (CVS 2786)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 57a674fc71512f11393b8eb595961ec9465ba4e1
User & Date: drh 2005-11-26 03:43:23
Context
2005-11-26
03:51
Remove some vestiges of the old OS_TEST driver. (CVS 2787) check-in: 008f676f user: drh tags: trunk
03:43
Add an OS method for making copies of file descriptors. This fixes the crash tests. (CVS 2786) check-in: 57a674fc user: drh tags: trunk
00:25
Modify the OS layer so that I/O routines are called through a virtual function table. The os_test.c module has been replaced by test6.c. The crash tests are busted now and need to be fixed. (CVS 2785) check-in: 1f69aec2 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os.h.

193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
212
  int (*xSync)(OsFile*, int);
  int (*xTruncate)(OsFile*, i64 size);
  int (*xFileSize)(OsFile*, i64 *pSize);
  char *(*xFullPathname)(const char*);
  int (*xLock)(OsFile*, int);
  int (*xUnlock)(OsFile*, int);
  int (*xCheckReservedLock)(OsFile *id);

} sqlite3Io;

/* The interface for file I/O is above.  Other miscellaneous functions
** are below */

int sqlite3OsRandomSeed(char*);
int sqlite3OsSleep(int ms);
int sqlite3OsCurrentTime(double*);
void sqlite3OsEnterMutex(void);
void sqlite3OsLeaveMutex(void);


#endif /* _SQLITE_OS_H_ */







>













193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  int (*xSync)(OsFile*, int);
  int (*xTruncate)(OsFile*, i64 size);
  int (*xFileSize)(OsFile*, i64 *pSize);
  char *(*xFullPathname)(const char*);
  int (*xLock)(OsFile*, int);
  int (*xUnlock)(OsFile*, int);
  int (*xCheckReservedLock)(OsFile *id);
  void (*xCopyOsFile)(OsFile *pDest, OsFile *pSrc);
} sqlite3Io;

/* The interface for file I/O is above.  Other miscellaneous functions
** are below */

int sqlite3OsRandomSeed(char*);
int sqlite3OsSleep(int ms);
int sqlite3OsCurrentTime(double*);
void sqlite3OsEnterMutex(void);
void sqlite3OsLeaveMutex(void);


#endif /* _SQLITE_OS_H_ */

Changes to src/os_unix.c.

1346
1347
1348
1349
1350
1351
1352






1353
1354
1355
1356
1357
1358
1359
....
1371
1372
1373
1374
1375
1376
1377

1378
1379
1380
1381
1382
1383
1384
    sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative,
                    (char*)0);
    sqliteFree(zBuf);
  }
  return zFull;
}








/*
** This is the structure that defines all of the I/O routines.
*/
struct sqlite3IoVtbl sqlite3Io = {
  unixDelete,
  unixFileExists,
................................................................................
  unixSync,
  unixTruncate,
  unixFileSize,
  unixFullPathname,
  unixLock,
  unixUnlock,
  unixCheckReservedLock,

};


#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
** Everything above deals with file I/O.  Everything that follows deals
** with other miscellanous aspects of the operating system interface







>
>
>
>
>
>







 







>







1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
....
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
    sqlite3SetString(&zFull, getcwd(zBuf, 5000), "/", zRelative,
                    (char*)0);
    sqliteFree(zBuf);
  }
  return zFull;
}

/*
** Make a copy of an OsFile object.
*/
static void unixCopyOsFile(OsFile *pDest, OsFile *pSrc){
  *pDest = *pSrc;
}

/*
** This is the structure that defines all of the I/O routines.
*/
struct sqlite3IoVtbl sqlite3Io = {
  unixDelete,
  unixFileExists,
................................................................................
  unixSync,
  unixTruncate,
  unixFileSize,
  unixFullPathname,
  unixLock,
  unixUnlock,
  unixCheckReservedLock,
  unixCopyOsFile,
};


#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
** Everything above deals with file I/O.  Everything that follows deals
** with other miscellanous aspects of the operating system interface

Changes to src/os_win.c.

824
825
826
827
828
829
830








831
832
833
834
835
836
837
...
849
850
851
852
853
854
855

856
857
858
859
860
861
862
    zFull = sqliteMalloc( nByte*sizeof(zFull[0]) );
    if( zFull==0 ) return 0;
    GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
  }
#endif
  return zFull;
}









/*
** This is the structure that defines all of the I/O routines.
*/
struct sqlite3IoVtbl sqlite3Io = {
  winDelete,
  winFileExists,
................................................................................
  winSync,
  winTruncate,
  winFileSize,
  winFullPathname,
  winLock,
  winUnlock,
  winCheckReservedLock,

};

#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
** Everything above deals with file I/O.  Everything that follows deals
** with other miscellanous aspects of the operating system interface
****************************************************************************/







>
>
>
>
>
>
>
>







 







>







824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
...
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
    zFull = sqliteMalloc( nByte*sizeof(zFull[0]) );
    if( zFull==0 ) return 0;
    GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
  }
#endif
  return zFull;
}

/*
** Make a copy of an OsFile object.
*/
static void winCopyOsFile(OsFile *pDest, OsFile *pSrc){
  *pDest = *pSrc;
}


/*
** This is the structure that defines all of the I/O routines.
*/
struct sqlite3IoVtbl sqlite3Io = {
  winDelete,
  winFileExists,
................................................................................
  winSync,
  winTruncate,
  winFileSize,
  winFullPathname,
  winLock,
  winUnlock,
  winCheckReservedLock,
  winCopyOsFile,
};

#endif /* SQLITE_OMIT_DISKIO */
/***************************************************************************
** Everything above deals with file I/O.  Everything that follows deals
** with other miscellanous aspects of the operating system interface
****************************************************************************/

Changes to src/pager.c.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
....
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.218 2005/11/26 00:25:03 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>
................................................................................
  strcpy(pPager->zFilename, zFullPathname);
  strcpy(pPager->zDirectory, zFullPathname);
  for(i=nameLen; i>0 && pPager->zDirectory[i-1]!='/'; i--){}
  if( i>0 ) pPager->zDirectory[i-1] = 0;
  strcpy(pPager->zJournal, zFullPathname);
  sqliteFree(zFullPathname);
  strcpy(&pPager->zJournal[nameLen], "-journal");
  pPager->fd = fd;
  pPager->journalOpen = 0;
  pPager->useJournal = useJournal && !memDb;
  pPager->noReadlock = noReadlock && readOnly;
  pPager->stmtOpen = 0;
  pPager->stmtInUse = 0;
  pPager->nRef = 0;
  pPager->dbSize = memDb-1;







|







 







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
....
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.219 2005/11/26 03:43:23 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
#include "os.h"
#include "pager.h"
#include <assert.h>
#include <string.h>
................................................................................
  strcpy(pPager->zFilename, zFullPathname);
  strcpy(pPager->zDirectory, zFullPathname);
  for(i=nameLen; i>0 && pPager->zDirectory[i-1]!='/'; i--){}
  if( i>0 ) pPager->zDirectory[i-1] = 0;
  strcpy(pPager->zJournal, zFullPathname);
  sqliteFree(zFullPathname);
  strcpy(&pPager->zJournal[nameLen], "-journal");
  sqlite3Io.xCopyOsFile(&pPager->fd,&fd);
  pPager->journalOpen = 0;
  pPager->useJournal = useJournal && !memDb;
  pPager->noReadlock = noReadlock && readOnly;
  pPager->stmtOpen = 0;
  pPager->stmtInUse = 0;
  pPager->nRef = 0;
  pPager->dbSize = memDb-1;

Changes to src/test6.c.

423
424
425
426
427
428
429








430
431
432
433
434
435
436
...
460
461
462
463
464
465
466

467
468
469
470
471
472
473
474
475
476
477
478
  initFile(id, zFilename);
  return origIo.xOpenExclusive(zFilename, id, delFlag);
}
static int crashOpenReadOnly(const char *zFilename, OsFile *id){
  initFile(id, zFilename);
  return origIo.xOpenReadOnly(zFilename, id);
}









/*
** tclcmd:   sqlite_crashparams DELAY CRASHFILE
**
** This procedure implements a TCL command that enables crash testing
** in testfixture.  Once enabled, crash testing cannot be disabled.
*/
................................................................................
  sqlite3Io.xClose = crashClose;
  sqlite3Io.xSync = crashSync;
  sqlite3Io.xTruncate = crashTruncate;
  sqlite3Io.xFileSize = crashFileSize;
  sqlite3Io.xOpenReadWrite = crashOpenReadWrite;
  sqlite3Io.xOpenExclusive = crashOpenExclusive;
  sqlite3Io.xOpenReadOnly = crashOpenReadOnly;

  return TCL_OK;
}

/*
** This procedure registers the TCL procedures defined in this file.
*/
int Sqlitetest6_Init(Tcl_Interp *interp){
  Tcl_CreateObjCommand(interp, "sqlite3_crashparams", crashParamsObjCmd, 0, 0);
  return TCL_OK;
}

#endif /* SQLITE_TEST */







>
>
>
>
>
>
>
>







 







>












423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
  initFile(id, zFilename);
  return origIo.xOpenExclusive(zFilename, id, delFlag);
}
static int crashOpenReadOnly(const char *zFilename, OsFile *id){
  initFile(id, zFilename);
  return origIo.xOpenReadOnly(zFilename, id);
}

/*
** Make a copy of an OsFile object
*/
static void crashCopyOsFile(OsFile *pDest, OsFile *pSrc){
  *pDest = *pSrc;
  ((OsTestFile*)(pDest->pAux))->pBase = pDest;
}

/*
** tclcmd:   sqlite_crashparams DELAY CRASHFILE
**
** This procedure implements a TCL command that enables crash testing
** in testfixture.  Once enabled, crash testing cannot be disabled.
*/
................................................................................
  sqlite3Io.xClose = crashClose;
  sqlite3Io.xSync = crashSync;
  sqlite3Io.xTruncate = crashTruncate;
  sqlite3Io.xFileSize = crashFileSize;
  sqlite3Io.xOpenReadWrite = crashOpenReadWrite;
  sqlite3Io.xOpenExclusive = crashOpenExclusive;
  sqlite3Io.xOpenReadOnly = crashOpenReadOnly;
  sqlite3Io.xCopyOsFile = crashCopyOsFile;
  return TCL_OK;
}

/*
** This procedure registers the TCL procedures defined in this file.
*/
int Sqlitetest6_Init(Tcl_Interp *interp){
  Tcl_CreateObjCommand(interp, "sqlite3_crashparams", crashParamsObjCmd, 0, 0);
  return TCL_OK;
}

#endif /* SQLITE_TEST */