/ Check-in [ab580029]
Login

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

Overview
Comment:Enhancements to OSTRACE usage in the Win32 VFS.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ab5800291e1908b5b51d912feeacf748dc9be14b
User & Date: mistachkin 2015-03-27 18:20:25
Context
2015-03-30
23:43
Prevent a possible infinite loop when trying to DROP a table from a corrupt database. check-in: 395bb3e6 user: drh tags: trunk
2015-03-27
18:22
Merge updates from trunk. Closed-Leaf check-in: 45acf6a8 user: mistachkin tags: winViewFlush
18:20
Enhancements to OSTRACE usage in the Win32 VFS. check-in: ab580029 user: mistachkin tags: trunk
02:27
Fix the ".testctrl imposter" command in the command-line shell to be consistent in error reporting and results with the other .testctrl commands. check-in: 0ec08ba8 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

  2446   2446     winFile *pFile = (winFile*)id;
  2447   2447   
  2448   2448     assert( id!=0 );
  2449   2449   #ifndef SQLITE_OMIT_WAL
  2450   2450     assert( pFile->pShm==0 );
  2451   2451   #endif
  2452   2452     assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE );
  2453         -  OSTRACE(("CLOSE file=%p\n", pFile->h));
         2453  +  OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p\n",
         2454  +           osGetCurrentProcessId(), pFile, pFile->h));
  2454   2455   
  2455   2456   #if SQLITE_MAX_MMAP_SIZE>0
  2456   2457     winUnmapfile(pFile);
  2457   2458   #endif
  2458   2459   
  2459   2460     do{
  2460   2461       rc = osCloseHandle(pFile->h);
................................................................................
  2475   2476       sqlite3_free(pFile->zDeleteOnClose);
  2476   2477     }
  2477   2478   #endif
  2478   2479     if( rc ){
  2479   2480       pFile->h = NULL;
  2480   2481     }
  2481   2482     OpenCounter(-1);
  2482         -  OSTRACE(("CLOSE file=%p, rc=%s\n", pFile->h, rc ? "ok" : "failed"));
         2483  +  OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
         2484  +           osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed"));
  2483   2485     return rc ? SQLITE_OK
  2484   2486               : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(),
  2485   2487                             "winClose", pFile->zPath);
  2486   2488   }
  2487   2489   
  2488   2490   /*
  2489   2491   ** Read data from a file into a buffer.  Return SQLITE_OK if all
................................................................................
  2503   2505     DWORD nRead;                    /* Number of bytes actually read from file */
  2504   2506     int nRetry = 0;                 /* Number of retrys */
  2505   2507   
  2506   2508     assert( id!=0 );
  2507   2509     assert( amt>0 );
  2508   2510     assert( offset>=0 );
  2509   2511     SimulateIOError(return SQLITE_IOERR_READ);
  2510         -  OSTRACE(("READ file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n",
         2512  +  OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
         2513  +           "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
  2511   2514              pFile->h, pBuf, amt, offset, pFile->locktype));
  2512   2515   
  2513   2516   #if SQLITE_MAX_MMAP_SIZE>0
  2514   2517     /* Deal with as much of this read request as possible by transfering
  2515   2518     ** data from the memory mapping using memcpy().  */
  2516   2519     if( offset<pFile->mmapSize ){
  2517   2520       if( offset+amt <= pFile->mmapSize ){
  2518   2521         memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
  2519         -      OSTRACE(("READ-MMAP file=%p, rc=SQLITE_OK\n", pFile->h));
         2522  +      OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
         2523  +               osGetCurrentProcessId(), pFile, pFile->h));
  2520   2524         return SQLITE_OK;
  2521   2525       }else{
  2522   2526         int nCopy = (int)(pFile->mmapSize - offset);
  2523   2527         memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
  2524   2528         pBuf = &((u8 *)pBuf)[nCopy];
  2525   2529         amt -= nCopy;
  2526   2530         offset += nCopy;
  2527   2531       }
  2528   2532     }
  2529   2533   #endif
  2530   2534   
  2531   2535   #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
  2532   2536     if( winSeekFile(pFile, offset) ){
  2533         -    OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
         2537  +    OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
         2538  +             osGetCurrentProcessId(), pFile, pFile->h));
  2534   2539       return SQLITE_FULL;
  2535   2540     }
  2536   2541     while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
  2537   2542   #else
  2538   2543     memset(&overlapped, 0, sizeof(OVERLAPPED));
  2539   2544     overlapped.Offset = (LONG)(offset & 0xffffffff);
  2540   2545     overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
  2541   2546     while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) &&
  2542   2547            osGetLastError()!=ERROR_HANDLE_EOF ){
  2543   2548   #endif
  2544   2549       DWORD lastErrno;
  2545   2550       if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
  2546   2551       pFile->lastErrno = lastErrno;
  2547         -    OSTRACE(("READ file=%p, rc=SQLITE_IOERR_READ\n", pFile->h));
         2552  +    OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_READ\n",
         2553  +             osGetCurrentProcessId(), pFile, pFile->h));
  2548   2554       return winLogError(SQLITE_IOERR_READ, pFile->lastErrno,
  2549   2555                          "winRead", pFile->zPath);
  2550   2556     }
  2551   2557     winLogIoerr(nRetry, __LINE__);
  2552   2558     if( nRead<(DWORD)amt ){
  2553   2559       /* Unread parts of the buffer must be zero-filled */
  2554   2560       memset(&((char*)pBuf)[nRead], 0, amt-nRead);
  2555         -    OSTRACE(("READ file=%p, rc=SQLITE_IOERR_SHORT_READ\n", pFile->h));
         2561  +    OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_SHORT_READ\n",
         2562  +             osGetCurrentProcessId(), pFile, pFile->h));
  2556   2563       return SQLITE_IOERR_SHORT_READ;
  2557   2564     }
  2558   2565   
  2559         -  OSTRACE(("READ file=%p, rc=SQLITE_OK\n", pFile->h));
         2566  +  OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
         2567  +           osGetCurrentProcessId(), pFile, pFile->h));
  2560   2568     return SQLITE_OK;
  2561   2569   }
  2562   2570   
  2563   2571   /*
  2564   2572   ** Write data from a buffer into a file.  Return SQLITE_OK on success
  2565   2573   ** or some other error code on failure.
  2566   2574   */
................................................................................
  2575   2583     int nRetry = 0;                 /* Number of retries */
  2576   2584   
  2577   2585     assert( amt>0 );
  2578   2586     assert( pFile );
  2579   2587     SimulateIOError(return SQLITE_IOERR_WRITE);
  2580   2588     SimulateDiskfullError(return SQLITE_FULL);
  2581   2589   
  2582         -  OSTRACE(("WRITE file=%p, buffer=%p, amount=%d, offset=%lld, lock=%d\n",
         2590  +  OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
         2591  +           "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
  2583   2592              pFile->h, pBuf, amt, offset, pFile->locktype));
  2584   2593   
  2585   2594   #if SQLITE_MAX_MMAP_SIZE>0
  2586   2595     /* Deal with as much of this write request as possible by transfering
  2587   2596     ** data from the memory mapping using memcpy().  */
  2588   2597     if( offset<pFile->mmapSize ){
  2589   2598       if( offset+amt <= pFile->mmapSize ){
  2590   2599         memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
  2591         -      OSTRACE(("WRITE-MMAP file=%p, rc=SQLITE_OK\n", pFile->h));
         2600  +      OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
         2601  +               osGetCurrentProcessId(), pFile, pFile->h));
  2592   2602         return SQLITE_OK;
  2593   2603       }else{
  2594   2604         int nCopy = (int)(pFile->mmapSize - offset);
  2595   2605         memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
  2596   2606         pBuf = &((u8 *)pBuf)[nCopy];
  2597   2607         amt -= nCopy;
  2598   2608         offset += nCopy;
................................................................................
  2647   2657         rc = 1;
  2648   2658       }
  2649   2659     }
  2650   2660   
  2651   2661     if( rc ){
  2652   2662       if(   ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
  2653   2663          || ( pFile->lastErrno==ERROR_DISK_FULL )){
  2654         -      OSTRACE(("WRITE file=%p, rc=SQLITE_FULL\n", pFile->h));
         2664  +      OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
         2665  +               osGetCurrentProcessId(), pFile, pFile->h));
  2655   2666         return winLogError(SQLITE_FULL, pFile->lastErrno,
  2656   2667                            "winWrite1", pFile->zPath);
  2657   2668       }
  2658         -    OSTRACE(("WRITE file=%p, rc=SQLITE_IOERR_WRITE\n", pFile->h));
         2669  +    OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_WRITE\n",
         2670  +             osGetCurrentProcessId(), pFile, pFile->h));
  2659   2671       return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno,
  2660   2672                          "winWrite2", pFile->zPath);
  2661   2673     }else{
  2662   2674       winLogIoerr(nRetry, __LINE__);
  2663   2675     }
  2664         -  OSTRACE(("WRITE file=%p, rc=SQLITE_OK\n", pFile->h));
         2676  +  OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
         2677  +           osGetCurrentProcessId(), pFile, pFile->h));
  2665   2678     return SQLITE_OK;
  2666   2679   }
  2667   2680   
  2668   2681   /*
  2669   2682   ** Truncate an open file to a specified size
  2670   2683   */
  2671   2684   static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
  2672   2685     winFile *pFile = (winFile*)id;  /* File handle object */
  2673   2686     int rc = SQLITE_OK;             /* Return code for this function */
  2674   2687     DWORD lastErrno;
  2675   2688   
  2676   2689     assert( pFile );
  2677   2690     SimulateIOError(return SQLITE_IOERR_TRUNCATE);
  2678         -  OSTRACE(("TRUNCATE file=%p, size=%lld, lock=%d\n",
  2679         -           pFile->h, nByte, pFile->locktype));
         2691  +  OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, size=%lld, lock=%d\n",
         2692  +           osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype));
  2680   2693   
  2681   2694     /* If the user has configured a chunk-size for this file, truncate the
  2682   2695     ** file so that it consists of an integer number of chunks (i.e. the
  2683   2696     ** actual file size after the operation may be larger than the requested
  2684   2697     ** size).
  2685   2698     */
  2686   2699     if( pFile->szChunk>0 ){
................................................................................
  2704   2717     ** use read() and write() to access data beyond this point from now on.
  2705   2718     */
  2706   2719     if( pFile->pMapRegion && nByte<pFile->mmapSize ){
  2707   2720       pFile->mmapSize = nByte;
  2708   2721     }
  2709   2722   #endif
  2710   2723   
  2711         -  OSTRACE(("TRUNCATE file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
         2724  +  OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, rc=%s\n",
         2725  +           osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc)));
  2712   2726     return rc;
  2713   2727   }
  2714   2728   
  2715   2729   #ifdef SQLITE_TEST
  2716   2730   /*
  2717   2731   ** Count the number of fullsyncs and normal syncs.  This is used to test
  2718   2732   ** that syncs and fullsyncs are occuring at the right times.
................................................................................
  2749   2763     );
  2750   2764   
  2751   2765     /* Unix cannot, but some systems may return SQLITE_FULL from here. This
  2752   2766     ** line is to test that doing so does not cause any problems.
  2753   2767     */
  2754   2768     SimulateDiskfullError( return SQLITE_FULL );
  2755   2769   
  2756         -  OSTRACE(("SYNC file=%p, flags=%x, lock=%d\n",
  2757         -           pFile->h, flags, pFile->locktype));
         2770  +  OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, flags=%x, lock=%d\n",
         2771  +           osGetCurrentProcessId(), pFile, pFile->h, flags,
         2772  +           pFile->locktype));
  2758   2773   
  2759   2774   #ifndef SQLITE_TEST
  2760   2775     UNUSED_PARAMETER(flags);
  2761   2776   #else
  2762   2777     if( (flags&0x0F)==SQLITE_SYNC_FULL ){
  2763   2778       sqlite3_fullsync_count++;
  2764   2779     }
................................................................................
  2765   2780     sqlite3_sync_count++;
  2766   2781   #endif
  2767   2782   
  2768   2783     /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
  2769   2784     ** no-op
  2770   2785     */
  2771   2786   #ifdef SQLITE_NO_SYNC
  2772         -  OSTRACE(("SYNC-NOP file=%p, rc=SQLITE_OK\n", pFile->h));
         2787  +  OSTRACE(("SYNC-NOP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
         2788  +           osGetCurrentProcessId(), pFile, pFile->h));
  2773   2789     return SQLITE_OK;
  2774   2790   #else
  2775   2791     rc = osFlushFileBuffers(pFile->h);
  2776   2792     SimulateIOError( rc=FALSE );
  2777   2793     if( rc ){
  2778         -    OSTRACE(("SYNC file=%p, rc=SQLITE_OK\n", pFile->h));
         2794  +    OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
         2795  +             osGetCurrentProcessId(), pFile, pFile->h));
  2779   2796       return SQLITE_OK;
  2780   2797     }else{
  2781   2798       pFile->lastErrno = osGetLastError();
  2782         -    OSTRACE(("SYNC file=%p, rc=SQLITE_IOERR_FSYNC\n", pFile->h));
         2799  +    OSTRACE(("SYNC pid=%lu, pFile=%p, file=%p, rc=SQLITE_IOERR_FSYNC\n",
         2800  +             osGetCurrentProcessId(), pFile, pFile->h));
  2783   2801       return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
  2784   2802                          "winSync", pFile->zPath);
  2785   2803     }
  2786   2804   #endif
  2787   2805   }
  2788   2806   
  2789   2807   /*