On Mon, 2013-06-24 at 20:34 -0400, Josh Kupershmidt wrote:
> This patch is in the current CommitFest, does it still need to be
> reviewed? If so, I notice that the version in pgfoundry's CVS is
> rather different than the version the patch seems to have been built
> against (presumably the pg_filedump-9.2.0.tar.gz release), and
> conflicts in several places with cvs tip.

Rebased against CVS tip; attached.

> Also, would anyone be willing to convert this repository to git and
> post it on github or similar? pgfoundry is becoming increasingly
> difficult to use, for instance the 'Browse CVS Repository' link for
> pg_filedump and other projects is broken[1] and apparently has been
> for months[2], not to mention the general crumminess of using CVS [3].

Eventually, it would be nice to have a more full-featured offline
checker utility. Do we want to try to turn this utility into that, or
make a new one?

Regards,
        Jeff Davis

Only in pg_filedump.checksums/: .deps
Only in pg_filedump.checksums/: pg_filedump
diff -rc pg_filedump/pg_filedump.c pg_filedump.checksums/pg_filedump.c
*** pg_filedump/pg_filedump.c	2013-06-06 11:33:17.000000000 -0700
--- pg_filedump.checksums/pg_filedump.c	2013-06-26 11:53:45.780117294 -0700
***************
*** 26,31 ****
--- 26,38 ----
  
  #include "utils/pg_crc_tables.h"
  
+ // checksum_impl.h uses Assert, which doesn't work outside the server
+ #undef Assert
+ #define Assert(X)
+ 
+ #include "storage/checksum.h"
+ #include "storage/checksum_impl.h"
+ 
  // Global variables for ease of use mostly
  static FILE *fp = NULL;		// File to dump or format
  static char *fileName = NULL;	// File name for display
***************
*** 40,51 ****
  static void DisplayOptions (unsigned int validOptions);
  static unsigned int ConsumeOptions (int numOptions, char **options);
  static int GetOptionValue (char *optionString);
! static void FormatBlock ();
  static unsigned int GetBlockSize ();
  static unsigned int GetSpecialSectionType (Page page);
  static bool IsBtreeMetaPage(Page page);
  static void CreateDumpFileHeader (int numOptions, char **options);
! static int FormatHeader (Page page);
  static void FormatItemBlock (Page page);
  static void FormatItem (unsigned int numBytes, unsigned int startIndex,
  			unsigned int formatAs);
--- 47,58 ----
  static void DisplayOptions (unsigned int validOptions);
  static unsigned int ConsumeOptions (int numOptions, char **options);
  static int GetOptionValue (char *optionString);
! static void FormatBlock (BlockNumber blkno);
  static unsigned int GetBlockSize ();
  static unsigned int GetSpecialSectionType (Page page);
  static bool IsBtreeMetaPage(Page page);
  static void CreateDumpFileHeader (int numOptions, char **options);
! static int FormatHeader (Page page, BlockNumber blkno);
  static void FormatItemBlock (Page page);
  static void FormatItem (unsigned int numBytes, unsigned int startIndex,
  			unsigned int formatAs);
***************
*** 288,293 ****
--- 295,305 ----
  		  SET_OPTION (itemOptions, ITEM_DETAIL, 'i');
  		  break;
  
+ 		  // Verify block checksums
+ 		case 'k':
+ 		  SET_OPTION (blockOptions, BLOCK_CHECKSUMS, 'k');
+ 		  break;
+ 
  		  // Interpret items as standard index values
  		case 'x':
  		  SET_OPTION (itemOptions, ITEM_INDEX, 'x');
***************
*** 555,561 ****
  
  // Dump out a formatted block header for the requested block
  static int
! FormatHeader (Page page)
  {
    int rc = 0;
    unsigned int headerBytes;
--- 567,573 ----
  
  // Dump out a formatted block header for the requested block
  static int
! FormatHeader (Page page, BlockNumber blkno)
  {
    int rc = 0;
    unsigned int headerBytes;
***************
*** 647,652 ****
--- 659,672 ----
  	  || (pageHeader->pd_upper < pageHeader->pd_lower)
  	  || (pageHeader->pd_special > blockSize))
  	printf (" Error: Invalid header information.\n\n");
+ 
+       if (blockOptions & BLOCK_CHECKSUMS)
+ 	{
+ 	  uint16 calc_checksum = pg_checksum_page(page, blkno);
+ 	  if (calc_checksum != pageHeader->pd_checksum)
+ 	    printf(" Error: checksum failure: calculated 0x%04x.\n\n",
+ 		   calc_checksum);
+ 	}
      }
  
    // If we have reached the end of file while interpreting the header, let
***************
*** 1208,1214 ****
  
  // For each block, dump out formatted header and content information
  static void
! FormatBlock ()
  {
    Page page = (Page) buffer;
    pageOffset = blockSize * currentBlock;
--- 1228,1234 ----
  
  // For each block, dump out formatted header and content information
  static void
! FormatBlock (BlockNumber blkno)
  {
    Page page = (Page) buffer;
    pageOffset = blockSize * currentBlock;
***************
*** 1228,1234 ****
        int rc;
        // Every block contains a header, items and possibly a special
        // section.  Beware of partial block reads though
!       rc = FormatHeader (page);
  
        // If we didn't encounter a partial read in the header, carry on...
        if (rc != EOF_ENCOUNTERED)
--- 1248,1254 ----
        int rc;
        // Every block contains a header, items and possibly a special
        // section.  Beware of partial block reads though
!       rc = FormatHeader (page, blkno);
  
        // If we didn't encounter a partial read in the header, carry on...
        if (rc != EOF_ENCOUNTERED)
***************
*** 1498,1504 ****
  		  contentsToDump = false;
  		}
  	      else
! 		FormatBlock ();
  	    }
  	}
  
--- 1518,1524 ----
  		  contentsToDump = false;
  		}
  	      else
! 		FormatBlock (currentBlock);
  	    }
  	}
  
Only in pg_filedump.checksums/: pg_filedump.c~
diff -rc pg_filedump/pg_filedump.h pg_filedump.checksums/pg_filedump.h
*** pg_filedump/pg_filedump.h	2013-06-06 11:33:17.000000000 -0700
--- pg_filedump.checksums/pg_filedump.h	2013-06-26 11:49:20.520122340 -0700
***************
*** 50,56 ****
    BLOCK_FORMAT = 0x00000004,	// -f: Formatted dump of blocks / control file
    BLOCK_FORCED = 0x00000008,	// -S: Block size forced
    BLOCK_NO_INTR = 0x00000010,	// -d: Dump straight blocks
!   BLOCK_RANGE = 0x00000020	// -R: Specific block range to dump
  }
  blockSwitches;
  
--- 50,57 ----
    BLOCK_FORMAT = 0x00000004,	// -f: Formatted dump of blocks / control file
    BLOCK_FORCED = 0x00000008,	// -S: Block size forced
    BLOCK_NO_INTR = 0x00000010,	// -d: Dump straight blocks
!   BLOCK_RANGE = 0x00000020,	// -R: Specific block range to dump
!   BLOCK_CHECKSUMS = 0x00000040	// -k: verify block checksums
  }
  blockSwitches;
  
Only in pg_filedump.checksums/: pg_filedump.o
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to