Commit 80a9d51c authored by Christoph Berg's avatar Christoph Berg

Refresh patches

parent faf2dcd7
commit 81982fa168744a92a435ecbb2d0a360cb650af7a
Author: Christoph Berg <myon@debian.org>
Date: Sat Aug 30 22:15:22 2014 +0200
Add support for verifying block checksums
Patch by Jeff Davis, rebased by Fabrízio de Royes Mello.
diff --git a/README.pg_filedump b/README.pg_filedump
index c9104e4..3a04d59 100644
--- a/README.pg_filedump
+++ b/README.pg_filedump
@@ -59,7 +59,7 @@ not require any manual adjustments of the Makefile.
------------------------------------------------------------------------
Invocation:
-pg_filedump [-abcdfhixy] [-R startblock [endblock]] [-S blocksize] file
+pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-S blocksize] file
Defaults are: relative addressing, range of the entire file, block size
as listed on block 0 in the file
@@ -74,6 +74,7 @@ The following options are valid for heap and index files:
-f Display formatted block content dump along with interpretation
-h Display this information
-i Display interpreted item details
+ -k Verify block checksums
-R Display specific block ranges within the file (Blocks are
indexed from 0)
[startblock]: block to start at
diff --git a/pg_filedump.c b/pg_filedump.c
index abcdb1e..34ce9d6 100644
--- a/pg_filedump.c
+++ b/pg_filedump.c
@@ -26,6 +26,13 @@
#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,12 +47,12 @@ static unsigned int blockVersion = 0; // Block version number
static void DisplayOptions (unsigned int validOptions);
static unsigned int ConsumeOptions (int numOptions, char **options);
static int GetOptionValue (char *optionString);
-static void FormatBlock ();
+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);
+static int FormatHeader (Page page, BlockNumber blkno);
static void FormatItemBlock (Page page);
static void FormatItem (unsigned int numBytes, unsigned int startIndex,
unsigned int formatAs);
@@ -68,7 +75,7 @@ DisplayOptions (unsigned int validOptions)
FD_VERSION, FD_PG_VERSION);
printf
- ("\nUsage: pg_filedump [-abcdfhixy] [-R startblock [endblock]] [-S blocksize] file\n\n"
+ ("\nUsage: pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-S blocksize] file\n\n"
"Display formatted contents of a PostgreSQL heap/index/control file\n"
"Defaults are: relative addressing, range of the entire file, block\n"
" size as listed on block 0 in the file\n\n"
@@ -82,6 +89,7 @@ DisplayOptions (unsigned int validOptions)
" -f Display formatted block content dump along with interpretation\n"
" -h Display this information\n"
" -i Display interpreted item details\n"
+ " -k Verify block checksums\n"
" -R Display specific block ranges within the file (Blocks are\n"
" indexed from 0)\n" " [startblock]: block to start at\n"
" [endblock]: block to end at\n"
@@ -288,6 +296,11 @@ ConsumeOptions (int numOptions, char **options)
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,7 +568,7 @@ CreateDumpFileHeader (int numOptions, char **options)
// Dump out a formatted block header for the requested block
static int
-FormatHeader (Page page)
+FormatHeader (Page page, BlockNumber blkno)
{
int rc = 0;
unsigned int headerBytes;
@@ -647,6 +660,14 @@ FormatHeader (Page page)
|| (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,7 +1229,7 @@ FormatSpecial ()
// For each block, dump out formatted header and content information
static void
-FormatBlock ()
+FormatBlock (BlockNumber blkno)
{
Page page = (Page) buffer;
pageOffset = blockSize * currentBlock;
@@ -1228,7 +1249,7 @@ FormatBlock ()
int rc;
// Every block contains a header, items and possibly a special
// section. Beware of partial block reads though
- rc = FormatHeader (page);
+ rc = FormatHeader (page, blkno);
// If we didn't encounter a partial read in the header, carry on...
if (rc != EOF_ENCOUNTERED)
@@ -1498,7 +1519,7 @@ DumpFileContents ()
contentsToDump = false;
}
else
- FormatBlock ();
+ FormatBlock (currentBlock);
}
}
diff --git a/pg_filedump.h b/pg_filedump.h
index 9769c03..1a6284c 100644
--- a/pg_filedump.h
+++ b/pg_filedump.h
@@ -22,8 +22,8 @@
* Original Author: Patrick Macdonald <patrickm@redhat.com>
*/
-#define FD_VERSION "9.3.0" /* version ID of pg_filedump */
-#define FD_PG_VERSION "PostgreSQL 9.3.x" /* PG version it works with */
+#define FD_VERSION "9.4.0" /* version ID of pg_filedump */
+#define FD_PG_VERSION "PostgreSQL 9.4.x" /* PG version it works with */
#include "postgres.h"
@@ -50,7 +50,8 @@ typedef enum
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_RANGE = 0x00000020, // -R: Specific block range to dump
+ BLOCK_CHECKSUMS = 0x00000040 // -k: verify block checksums
}
blockSwitches;
Description: USe LDFLAGS to build
--- postgresql-filedump-9.3.0.orig/Makefile
+++ postgresql-filedump-9.3.0/Makefile
@@ -18,7 +18,7 @@ DISTFILES= README.pg_filedump Makefile M
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ DISTFILES= README.pg_filedump Makefile M
all: pg_filedump
pg_filedump: pg_filedump.o
- ${CC} ${CFLAGS} -o pg_filedump pg_filedump.o
+ ${CC} ${LDFLAGS} -o pg_filedump pg_filedump.o
- ${CC} ${CFLAGS} -o pg_filedump pg_filedump.o -lpgport
+ ${CC} ${LDFLAGS} -o pg_filedump pg_filedump.o -lpgport
pg_filedump.o: pg_filedump.c
${CC} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} pg_filedump.c -c
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
# View README.pg_filedump first
# note this must match version macros in pg_filedump.h
-FD_VERSION=9.3.0
+FD_VERSION=9.5.0
CC=gcc
CFLAGS=-g -O -Wall -Wmissing-prototypes -Wmissing-declarations
@@ -18,7 +18,7 @@ DISTFILES= README.pg_filedump Makefile M
all: pg_filedump
pg_filedump: pg_filedump.o
- ${CC} ${LDFLAGS} -o pg_filedump pg_filedump.o
+ ${CC} ${LDFLAGS} -o pg_filedump pg_filedump.o -lpgport
pg_filedump.o: pg_filedump.c
${CC} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} pg_filedump.c -c
--- a/README.pg_filedump
+++ b/README.pg_filedump
@@ -2,7 +2,7 @@ pg_filedump - Display formatted contents
or control file.
Copyright (c) 2002-2010 Red Hat, Inc.
-Copyright (c) 2011-2014, PostgreSQL Global Development Group
+Copyright (c) 2011-2015, PostgreSQL Global Development Group
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
--- a/pg_filedump.c
+++ b/pg_filedump.c
@@ -3,7 +3,7 @@
* formatting heap (data), index and control files.
*
* Copyright (c) 2002-2010 Red Hat, Inc.
- * Copyright (c) 2011-2014, PostgreSQL Global Development Group
+ * Copyright (c) 2011-2015, PostgreSQL Global Development Group
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
#include "pg_filedump.h"
-#include "utils/pg_crc_tables.h"
+#include "utils/pg_crc.h"
// checksum_impl.h uses Assert, which doesn't work outside the server
#undef Assert
@@ -1094,6 +1094,8 @@ FormatSpecial ()
strcat (flagString, "SPLITEND|");
if (btreeSection->btpo_flags & BTP_HAS_GARBAGE)
strcat (flagString, "HASGARBAGE|");
+ if (btreeSection->btpo_flags & BTP_INCOMPLETE_SPLIT)
+ strcat (flagString, "INCOMPLETESPLIT|");
if (strlen (flagString))
flagString[strlen (flagString) - 1] = '\0';
@@ -1175,6 +1177,10 @@ FormatSpecial ()
strcat (flagString, "LIST|");
if (ginSection->flags & GIN_LIST_FULLROW)
strcat (flagString, "FULLROW|");
+ if (ginSection->flags & GIN_INCOMPLETE_SPLIT)
+ strcat(flagString, "INCOMPLETESPLIT|");
+ if (ginSection->flags & GIN_COMPRESSED)
+ strcat(flagString, "COMPRESSED|");
if (strlen (flagString))
flagString[strlen (flagString) - 1] = '\0';
printf (" GIN Index Section:\n"
@@ -1296,9 +1302,9 @@ FormatControl ()
char *dbState;
// Compute a local copy of the CRC to verify the one on disk
- INIT_CRC32 (crcLocal);
- COMP_CRC32 (crcLocal, buffer, offsetof(ControlFileData, crc));
- FIN_CRC32 (crcLocal);
+ INIT_CRC32C(crcLocal);
+ COMP_CRC32C(crcLocal, buffer, offsetof(ControlFileData, crc));
+ FIN_CRC32C(crcLocal);
// Grab a readable version of the database state
switch (controlData->state)
@@ -1309,6 +1315,9 @@ FormatControl ()
case DB_SHUTDOWNED:
dbState = "SHUTDOWNED";
break;
+ case DB_SHUTDOWNED_IN_RECOVERY:
+ dbState = "SHUTDOWNED_IN_RECOVERY";
+ break;
case DB_SHUTDOWNING:
dbState = "SHUTDOWNING";
break;
@@ -1356,7 +1365,7 @@ FormatControl ()
" Maximum Index Keys: %u\n"
" TOAST Chunk Size: %u\n"
" Date and Time Type Storage: %s\n\n",
- EQ_CRC32 (crcLocal,
+ EQ_CRC32C(crcLocal,
controlData->crc) ? "Correct" : "Not Correct",
controlData->pg_control_version,
(controlData->pg_control_version == PG_CONTROL_VERSION ?
--- a/pg_filedump.h
+++ b/pg_filedump.h
@@ -3,7 +3,7 @@
* formatting heap (data), index and control files.
*
* Copyright (c) 2002-2010 Red Hat, Inc.
- * Copyright (c) 2011-2014, PostgreSQL Global Development Group
+ * Copyright (c) 2011-2015, PostgreSQL Global Development Group
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,8 +22,8 @@
* Original Author: Patrick Macdonald <patrickm@redhat.com>
*/
-#define FD_VERSION "9.4.0" /* version ID of pg_filedump */
-#define FD_PG_VERSION "PostgreSQL 9.4.x" /* PG version it works with */
+#define FD_VERSION "9.5.0" /* version ID of pg_filedump */
+#define FD_PG_VERSION "PostgreSQL 9.5.x" /* PG version it works with */
#include "postgres.h"
81982fa168744a92a435ecbb2d0a360cb650af7a
hardening
pg_filedump-9.5.diff
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment