SQLite

Check-in [74d975c69a]
Login

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

Overview
Comment:Store 64-bit offset values in osinst log files.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | osinst
Files: files | file ages | folders
SHA3-256: 74d975c69abf1b8b8699e4f6539a4e411913196c90061e2c1246d25c16693ae0
User & Date: dan 2019-10-08 19:45:17.191
Context
2019-10-08
19:45
Store 64-bit offset values in osinst log files. (Leaf check-in: 74d975c69a user: dan tags: osinst)
2019-10-07
10:29
Avoid attempting to read 0 bytes from a file in the osinst vtab code. (check-in: 1fb76c3e7d user: dan tags: osinst)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/test_osinst.c.
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#else
static sqlite3_uint64 vfslog_time(){
  return 0;
}
#endif

static void vfslog_call(
sqlite3_vfs *, int, int, sqlite3_uint64, sqlite3_int64, int, int, int);
static void vfslog_string(sqlite3_vfs *, const char *);

/*
** Close an vfslog-file.
*/
static int vfslogClose(sqlite3_file *pFile){
  sqlite3_uint64 t, t2;







|







245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#else
static sqlite3_uint64 vfslog_time(){
  return 0;
}
#endif

static void vfslog_call(
sqlite3_vfs *, int, int, sqlite3_uint64, sqlite3_int64, int, int, sqlite_int64);
static void vfslog_string(sqlite3_vfs *, const char *);

/*
** Close an vfslog-file.
*/
static int vfslogClose(sqlite3_file *pFile){
  sqlite3_uint64 t, t2;
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
){
  int rc;
  sqlite3_uint64 t, t2;
  VfslogFile *p = (VfslogFile *)pFile;
  t = vfslog_time();
  rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
  t2 = vfslog_time() - t;
  vfslog_call(p->pVfslog, OS_READ, p->iFileId, t, t2, rc, iAmt, (int)iOfst);
  return rc;
}

/*
** Write data to an vfslog-file.
*/
static int vfslogWrite(
  sqlite3_file *pFile,
  const void *z,
  int iAmt,
  sqlite_int64 iOfst
){
  int rc;
  sqlite3_uint64 t, t2;
  VfslogFile *p = (VfslogFile *)pFile;
  t = vfslog_time();
  rc = p->pReal->pMethods->xWrite(p->pReal, z, iAmt, iOfst);
  t2 = vfslog_time() - t;
  vfslog_call(p->pVfslog, OS_WRITE, p->iFileId, t, t2, rc, iAmt, (int)iOfst);
  return rc;
}

/*
** Truncate an vfslog-file.
*/
static int vfslogTruncate(sqlite3_file *pFile, sqlite_int64 size){
  int rc;
  sqlite3_uint64 t, t2;
  VfslogFile *p = (VfslogFile *)pFile;
  t = vfslog_time();
  rc = p->pReal->pMethods->xTruncate(p->pReal, size);
  t2 = vfslog_time() - t;
  vfslog_call(p->pVfslog, OS_TRUNCATE, p->iFileId, t, t2, rc, 0, (int)size);
  return rc;
}

/*
** Sync an vfslog-file.
*/
static int vfslogSync(sqlite3_file *pFile, int flags){







|


















|













|







280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
){
  int rc;
  sqlite3_uint64 t, t2;
  VfslogFile *p = (VfslogFile *)pFile;
  t = vfslog_time();
  rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
  t2 = vfslog_time() - t;
  vfslog_call(p->pVfslog, OS_READ, p->iFileId, t, t2, rc, iAmt, iOfst);
  return rc;
}

/*
** Write data to an vfslog-file.
*/
static int vfslogWrite(
  sqlite3_file *pFile,
  const void *z,
  int iAmt,
  sqlite_int64 iOfst
){
  int rc;
  sqlite3_uint64 t, t2;
  VfslogFile *p = (VfslogFile *)pFile;
  t = vfslog_time();
  rc = p->pReal->pMethods->xWrite(p->pReal, z, iAmt, iOfst);
  t2 = vfslog_time() - t;
  vfslog_call(p->pVfslog, OS_WRITE, p->iFileId, t, t2, rc, iAmt, iOfst);
  return rc;
}

/*
** Truncate an vfslog-file.
*/
static int vfslogTruncate(sqlite3_file *pFile, sqlite_int64 size){
  int rc;
  sqlite3_uint64 t, t2;
  VfslogFile *p = (VfslogFile *)pFile;
  t = vfslog_time();
  rc = p->pReal->pMethods->xTruncate(p->pReal, size);
  t2 = vfslog_time() - t;
  vfslog_call(p->pVfslog, OS_TRUNCATE, p->iFileId, t, t2, rc, 0, size);
  return rc;
}

/*
** Sync an vfslog-file.
*/
static int vfslogSync(sqlite3_file *pFile, int flags){
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
static int vfslogFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
  int rc;
  sqlite3_uint64 t, t2;
  VfslogFile *p = (VfslogFile *)pFile;
  t = vfslog_time();
  rc = p->pReal->pMethods->xFileSize(p->pReal, pSize);
  t2 = vfslog_time() - t;
  vfslog_call(p->pVfslog, OS_FILESIZE, p->iFileId, t, t2, rc, 0, (int)*pSize);
  return rc;
}

/*
** Lock an vfslog-file.
*/
static int vfslogLock(sqlite3_file *pFile, int eLock){







|







341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
static int vfslogFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
  int rc;
  sqlite3_uint64 t, t2;
  VfslogFile *p = (VfslogFile *)pFile;
  t = vfslog_time();
  rc = p->pReal->pMethods->xFileSize(p->pReal, pSize);
  t2 = vfslog_time() - t;
  vfslog_call(p->pVfslog, OS_FILESIZE, p->iFileId, t, t2, rc, 0, *pSize);
  return rc;
}

/*
** Lock an vfslog-file.
*/
static int vfslogLock(sqlite3_file *pFile, int eLock){
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
  int *pResOut
){
  int rc;
  sqlite3_uint64 t, t2;
  t = vfslog_time();
  rc = REALVFS(pVfs)->xAccess(REALVFS(pVfs), zPath, flags, pResOut);
  t2 = vfslog_time() - t;
  vfslog_call(pVfs, OS_ACCESS, 0, t, t2, rc, flags, *pResOut);
  vfslog_string(pVfs, zPath);
  return rc;
}

/*
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer







|







533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
  int *pResOut
){
  int rc;
  sqlite3_uint64 t, t2;
  t = vfslog_time();
  rc = REALVFS(pVfs)->xAccess(REALVFS(pVfs), zPath, flags, pResOut);
  t2 = vfslog_time() - t;
  vfslog_call(pVfs, OS_ACCESS, 0, t, t2, rc, flags, (sqlite3_int64)*pResOut);
  vfslog_string(pVfs, zPath);
  return rc;
}

/*
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer
647
648
649
650
651
652
653







654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677

678
679
680
681
682
683
684
685
static void vfslogPut32bits(unsigned char *p, unsigned int v){
  p[0] = v>>24;
  p[1] = (unsigned char)(v>>16);
  p[2] = (unsigned char)(v>>8);
  p[3] = (unsigned char)v;
}








static void vfslog_call(
  sqlite3_vfs *pVfs,
  int eEvent,
  int iFileid,
  sqlite3_uint64 tStamp,
  sqlite3_int64 nClick,
  int return_code,
  int size,
  int offset
){
  VfslogVfs *p = (VfslogVfs *)pVfs;
  unsigned char *zRec;
  if( (32+p->nBuf)>sizeof(p->aBuf) ){
    vfslog_flush(p);
  }
  zRec = (unsigned char *)&p->aBuf[p->nBuf];
  vfslogPut32bits(&zRec[0], eEvent);
  vfslogPut32bits(&zRec[4], iFileid);
  vfslogPut32bits(&zRec[8], (unsigned int)((tStamp>>32)&0xffffffff));
  vfslogPut32bits(&zRec[12], (unsigned int)(tStamp&0xffffffff));
  vfslogPut32bits(&zRec[16], (unsigned int)(nClick&0xffffffff));
  vfslogPut32bits(&zRec[20], return_code);
  vfslogPut32bits(&zRec[24], size);
  vfslogPut32bits(&zRec[28], offset);

  p->nBuf += 32;
}

static void vfslog_string(sqlite3_vfs *pVfs, const char *zStr){
  VfslogVfs *p = (VfslogVfs *)pVfs;
  unsigned char *zRec;
  int nStr = zStr ? (int)strlen(zStr) : 0;
  if( (4+nStr+p->nBuf)>sizeof(p->aBuf) ){







>
>
>
>
>
>
>








|



|





|
<



|
>
|







647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679

680
681
682
683
684
685
686
687
688
689
690
691
692
static void vfslogPut32bits(unsigned char *p, unsigned int v){
  p[0] = v>>24;
  p[1] = (unsigned char)(v>>16);
  p[2] = (unsigned char)(v>>8);
  p[3] = (unsigned char)v;
}

static void vfslogPut64bits(unsigned char *p, sqlite3_int64 v){
  vfslogPut32bits(p, (v >> 32) & 0xFFFFFFFF);
  vfslogPut32bits(&p[4], v & 0xFFFFFFFF);
}

#define VFSLOG_RECORD_SIZE 36

static void vfslog_call(
  sqlite3_vfs *pVfs,
  int eEvent,
  int iFileid,
  sqlite3_uint64 tStamp,
  sqlite3_int64 nClick,
  int return_code,
  int size,
  sqlite3_int64 offset
){
  VfslogVfs *p = (VfslogVfs *)pVfs;
  unsigned char *zRec;
  if( (VFSLOG_RECORD_SIZE+p->nBuf)>sizeof(p->aBuf) ){
    vfslog_flush(p);
  }
  zRec = (unsigned char *)&p->aBuf[p->nBuf];
  vfslogPut32bits(&zRec[0], eEvent);
  vfslogPut32bits(&zRec[4], iFileid);
  vfslogPut64bits(&zRec[8], (sqlite3_int64)tStamp);

  vfslogPut32bits(&zRec[16], (unsigned int)(nClick&0xffffffff));
  vfslogPut32bits(&zRec[20], return_code);
  vfslogPut32bits(&zRec[24], size);
  vfslogPut64bits(&zRec[28], offset);

  p->nBuf += VFSLOG_RECORD_SIZE;
}

static void vfslog_string(sqlite3_vfs *pVfs, const char *zStr){
  VfslogVfs *p = (VfslogVfs *)pVfs;
  unsigned char *zRec;
  int nStr = zStr ? (int)strlen(zStr) : 0;
  if( (4+nStr+p->nBuf)>sizeof(p->aBuf) ){
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
  VfslogVtab *p = (VfslogVtab *)pCursor->pVtab;
  int rc = SQLITE_OK;
  int nRead;

  sqlite3_free(pCsr->zTransient);
  pCsr->zTransient = 0;

  nRead = 32;
  if( pCsr->iOffset+nRead<=p->nByte ){
    int eEvent;
    rc = p->pFd->pMethods->xRead(p->pFd, pCsr->aBuf, nRead, pCsr->iOffset);

    eEvent = get32bits(pCsr->aBuf);
    if( (rc==SQLITE_OK)
     && (eEvent==OS_OPEN || eEvent==OS_DELETE || eEvent==OS_ACCESS) 







|







982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
  VfslogVtab *p = (VfslogVtab *)pCursor->pVtab;
  int rc = SQLITE_OK;
  int nRead;

  sqlite3_free(pCsr->zTransient);
  pCsr->zTransient = 0;

  nRead = VFSLOG_RECORD_SIZE;
  if( pCsr->iOffset+nRead<=p->nByte ){
    int eEvent;
    rc = p->pFd->pMethods->xRead(p->pFd, pCsr->aBuf, nRead, pCsr->iOffset);

    eEvent = get32bits(pCsr->aBuf);
    if( (rc==SQLITE_OK)
     && (eEvent==OS_OPEN || eEvent==OS_DELETE || eEvent==OS_ACCESS) 
1063
1064
1065
1066
1067
1068
1069

1070









1071
1072
1073
1074
1075
1076
1077
      }
      sqlite3_result_text(ctx, zStr, -1, SQLITE_TRANSIENT);
      break;
    }
    case 2: {
      unsigned int v1 = get32bits(&pCsr->aBuf[8]);
      unsigned int v2 = get32bits(&pCsr->aBuf[12]);

      sqlite3_result_int64(ctx,(((sqlite3_int64)v1) << 32) + (sqlite3_int64)v2);









      break;
    }
    default: {
      unsigned int val = get32bits(&pCsr->aBuf[4*(i+1)]);
      sqlite3_result_int(ctx, val);
      break;
    }







>
|
>
>
>
>
>
>
>
>
>







1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
      }
      sqlite3_result_text(ctx, zStr, -1, SQLITE_TRANSIENT);
      break;
    }
    case 2: {
      unsigned int v1 = get32bits(&pCsr->aBuf[8]);
      unsigned int v2 = get32bits(&pCsr->aBuf[12]);
      sqlite3_result_int64(
        ctx,(((sqlite3_int64)v1) << 32) + (sqlite3_int64)v2
      );
      break;
    }
    case 6: {
      unsigned int v1 = get32bits(&pCsr->aBuf[28]);
      unsigned int v2 = get32bits(&pCsr->aBuf[32]);
      sqlite3_result_int64(
        ctx,(((sqlite3_int64)v1) << 32) + (sqlite3_int64)v2
      );
      break;
    }
    default: {
      unsigned int val = get32bits(&pCsr->aBuf[4*(i+1)]);
      sqlite3_result_int(ctx, val);
      break;
    }