diff --git a/.travis.yml b/.travis.yml index fa7b713..4242ed6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ env: - PGBRANCH=REL_10_STABLE - PGBRANCH=REL9_6_STABLE - PGBRANCH=REL9_5_STABLE - - PGBRANCH=REL9_4_STABLE before_install: - CURDIR=$(pwd) diff --git a/README.md b/README.md index 656e904..fcfb1ab 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ index files (B-Tree, GiST, GIN, hash, BRIN, and SP-GiST indexes) when opened within the open source GUI hex editor [wxHexEditor](https://github.com/EUA/wxHexEditor). It makes viewing and editing PostgreSQL relation files *significantly* easier. PostgreSQL versions -9.4+ are supported. +9.5+ are supported. __CAUTION:__ Do not use pg_hexedit with a PostgreSQL data directory if you are not prepared to have it __corrupt data__! pg_hexedit is primarily made @@ -95,7 +95,7 @@ available within your $PATH: ```shell $ which pg_config - /code/postgresql/REL9_4_STABLE/install/bin/pg_config + /code/postgresql/REL_12_STABLE/install/bin/pg_config $ make $ # Installation -- not actually required for convenience scripts: $ make install diff --git a/pg_filenodemapdata.c b/pg_filenodemapdata.c index 981890c..1801ef1 100644 --- a/pg_filenodemapdata.c +++ b/pg_filenodemapdata.c @@ -37,9 +37,7 @@ #include "catalog/pg_db_role_setting.h" #include "catalog/pg_pltemplate.h" #include "catalog/pg_proc.h" -#if PG_VERSION_NUM >= 90500 #include "catalog/pg_replication_origin.h" -#endif #include "catalog/pg_shdepend.h" #include "catalog/pg_shdescription.h" #include "catalog/pg_shseclabel.h" @@ -49,36 +47,11 @@ #include "catalog/pg_tablespace.h" #include "catalog/pg_type.h" #include "catalog/toasting.h" +#include "port/pg_crc32c.h" #define HEXEDIT_VERSION "0.1" -/* Use macros to handle move from CRC-32 to CRC-32C in Postgres 9.5 */ -#if PG_VERSION_NUM >= 90500 -#include "port/pg_crc32c.h" -typedef pg_crc32c port_crc32; -#define PORT_INIT_CRC32(crc) INIT_CRC32C((crc)) -#define PORT_COMP_CRC32(crc,data,len) COMP_CRC32C((crc), (data), (len)) -#define PORT_FIN_CRC32(crc) FIN_CRC32C((crc)) -#define PORT_EQ_CRC32(c1,c2) EQ_CRC32C((c1), (c2)) -#define PORT_FAIL_HINT "PostgreSQL 9.4" -#else -#include "utils/pg_crc.h" -typedef pg_crc32 port_crc32; -#define PORT_INIT_CRC32(crc) INIT_CRC32((crc)) -#define PORT_COMP_CRC32(crc,data,len) COMP_CRC32((crc), (data), (len)) -#define PORT_FIN_CRC32(crc) FIN_CRC32((crc)) -#define PORT_EQ_CRC32(c1,c2) EQ_CRC32((c1), (c2)) -#define PORT_FAIL_HINT "PostgreSQL 9.5+" -#endif - /* Provide system catalog OIDs where unavailable */ -#if PG_VERSION_NUM < 90500 -#define ReplicationOriginRelationId 6000 -#define ReplicationOriginIdentIndex 6001 -#define ReplicationOriginNameIndex 6002 -#define PgShseclabelToastTable 4060 -#define PgShseclabelToastIndex 4061 -#endif #if PG_VERSION_NUM < 100000 #define SubscriptionRelationId 6100 #define SubscriptionObjectIndexId 6114 @@ -129,7 +102,7 @@ typedef struct RelMapFile int32 magic; /* always RELMAPPER_FILEMAGIC */ int32 num_mappings; /* number of valid RelMapping entries */ RelMapping mappings[MAX_MAPPINGS]; - port_crc32 crc; /* CRC of all above */ + pg_crc32c crc; /* CRC of all above */ int32 pad; /* to make the struct size be 512 exactly */ } RelMapFile; @@ -369,7 +342,7 @@ PrintRelMapContents(RelMapFile *map) static void VerifyRelMapContents(RelMapFile *map) { - port_crc32 crc; + pg_crc32c crc; if (map->magic != RELMAPPER_FILEMAGIC || map->num_mappings < 0 || @@ -380,17 +353,15 @@ VerifyRelMapContents(RelMapFile *map) } /* Print our own CRC-32/CRC-32C calculation */ - PORT_INIT_CRC32(crc); - PORT_COMP_CRC32(crc, (char *) map, offsetof(RelMapFile, crc)); - PORT_FIN_CRC32(crc); + INIT_CRC32C(crc); + COMP_CRC32C(crc, (char *) map, offsetof(RelMapFile, crc)); + FIN_CRC32C(crc); /* Raise error if they don't match */ - if (!PORT_EQ_CRC32(crc, map->crc)) + if (!EQ_CRC32C(crc, map->crc)) { fprintf(stderr, "calculated checksum 0x%.8X does not match file checksum\n", crc); - if (exitCode == 0) - fprintf(stderr, "if the pg_filenode.map file is from " PORT_FAIL_HINT ", this may be harmless.\n"); exitCode = 1; } } diff --git a/pg_hexedit.c b/pg_hexedit.c index 323ce22..74a5134 100644 --- a/pg_hexedit.c +++ b/pg_hexedit.c @@ -48,10 +48,8 @@ #include -#if PG_VERSION_NUM >= 90500 #include "access/brin_page.h" #include "access/brin_tuple.h" -#endif #include "access/gin_private.h" #include "access/gist.h" #include "access/hash.h" @@ -252,9 +250,7 @@ static char *GetIndexTupleFlags(IndexTuple itup); static const char *GetSpGistStateString(unsigned int code); static char *GetSpGistInnerTupleState(SpGistInnerTuple itup); static char *GetSpGistLeafTupleState(SpGistLeafTuple itup); -#if PG_VERSION_NUM >= 90500 static char *GetBrinTupleFlags(BrinTuple *itup); -#endif static bool IsBrinPage(Page page); static bool IsHashBitmapPage(Page page); static bool IsLeafPage(Page page); @@ -301,20 +297,16 @@ static void EmitXmlSpGistLeafTuple(Page page, BlockNumber blkno, OffsetNumber offset, SpGistLeafTuple tuple, uint32 relfileOff); -#if PG_VERSION_NUM >= 90500 static void EmitXmlBrinTuple(Page page, BlockNumber blkno, OffsetNumber offset, BrinTuple *tuple, uint32 relfileOff, int itemSize); -#endif static int EmitXmlPageHeader(Page page, BlockNumber blkno, uint32 level); static void EmitXmlPageMeta(BlockNumber blkno, uint32 level); static void EmitXmlPageItemIdArray(Page page, BlockNumber blkno); static void EmitXmlTuples(Page page, BlockNumber blkno); static void EmitXmlPostingTreeTids(Page page, BlockNumber blkno); static void EmitXmlHashBitmap(Page page, BlockNumber blkno); -#if PG_VERSION_NUM >= 90500 static void EmitXmlRevmap(Page page, BlockNumber blkno); -#endif static void EmitXmlSpecial(BlockNumber blkno, uint32 level); static void EmitXmlBody(void); @@ -1019,9 +1011,7 @@ GetSpecialSectionType(Page page) *ptype == SPGIST_PAGE_ID) rc = SPEC_SECT_INDEX_SPGIST; else if ( -#if PG_VERSION_NUM >= 90500 specialSize == MAXALIGN(sizeof(BrinSpecialSpace)) && -#endif IsBrinPage(page)) rc = SPEC_SECT_INDEX_BRIN; else if (specialSize == MAXALIGN(sizeof(GinPageOpaqueData))) @@ -1042,9 +1032,7 @@ GetSpecialSectionType(Page page) *ptype == SPGIST_PAGE_ID) rc = SPEC_SECT_INDEX_SPGIST; else if ( -#if PG_VERSION_NUM >= 90500 specialSize == MAXALIGN(sizeof(BrinSpecialSpace)) && -#endif IsBrinPage(page)) rc = SPEC_SECT_INDEX_BRIN; else if (specialSize == MAXALIGN(sizeof(GinPageOpaqueData))) @@ -1347,7 +1335,6 @@ GetSpGistLeafTupleState(SpGistLeafTuple itup) * * Note: Caller is responsible for pg_free()'ing returned buffer. */ -#if PG_VERSION_NUM >= 90500 static char * GetBrinTupleFlags(BrinTuple *itup) { @@ -1379,20 +1366,17 @@ GetBrinTupleFlags(BrinTuple *itup) return flagString; } -#endif /* Check whether page is a BRIN meta page */ static bool IsBrinPage(Page page) { -#if PG_VERSION_NUM >= 90500 if (bytesToFormat != blockSize) return false; if (BRIN_IS_META_PAGE(page) || BRIN_IS_REVMAP_PAGE(page) || BRIN_IS_REGULAR_PAGE(page)) return true; -#endif return false; } @@ -1563,13 +1547,11 @@ EmitXmlPage(BlockNumber blkno) /* GIN data/posting tree pages don't use IndexTuple or ItemId */ EmitXmlPostingTreeTids(page, blkno); } -#if PG_VERSION_NUM >= 90500 else if (specialType == SPEC_SECT_INDEX_BRIN && BRIN_IS_REVMAP_PAGE(page)) { /* BRIN revmap pages don't use IndexTuple/BrinTuple or ItemId */ EmitXmlRevmap(page, blkno); } -#endif else { /* Conventional heap/index page format */ @@ -2697,7 +2679,6 @@ EmitXmlSpGistLeafTuple(Page page, BlockNumber blkno, OffsetNumber offset, * This is similar to EmitXmlIndexTuple(), but BRIN never uses IndexTuple * representation, so requires this custom tuple formatting function. */ -#if PG_VERSION_NUM >= 90500 static void EmitXmlBrinTuple(Page page, BlockNumber blkno, OffsetNumber offset, BrinTuple *tuple, uint32 relfileOff, int itemSize) @@ -2770,7 +2751,6 @@ EmitXmlBrinTuple(Page page, BlockNumber blkno, OffsetNumber offset, EmitXmlTupleTag(blkno, offset, "contents", COLOR_WHITE, relfileOff, relfileOffNext - 1); } -#endif /* * Dump out a formatted block header for the requested block. @@ -3067,7 +3047,6 @@ EmitXmlPageMeta(BlockNumber blkno, uint32 level) cachedOffset += sizeof(int); } } -#if PG_VERSION_NUM >= 90500 else if (specialType == SPEC_SECT_INDEX_BRIN && blkno == BRIN_METAPAGE_BLKNO) { EmitXmlTag(InvalidBlockNumber, level, "brinMagic", COLOR_PINK, @@ -3083,7 +3062,6 @@ EmitXmlPageMeta(BlockNumber blkno, uint32 level) metaStartOffset + offsetof(BrinMetaPageData, lastRevmapPage), (metaStartOffset + sizeof(BrinMetaPageData)) - 1); } -#endif else { fprintf(stderr, "pg_hexedit error: unsupported metapage special section type \"%s\"\n", @@ -3293,14 +3271,12 @@ EmitXmlTuples(Page page, BlockNumber blkno) } else if (formatAs == ITEM_BRIN) { -#if PG_VERSION_NUM >= 90500 BrinTuple *tuple; tuple = (BrinTuple *) PageGetItem(page, itemId); EmitXmlBrinTuple(page, blkno, offset, tuple, pageOffset + itemOffset, itemSize); -#endif } } } @@ -3446,7 +3422,6 @@ EmitXmlHashBitmap(Page page, BlockNumber blkno) * We don't look at pd_upper, in keeping with pageinspect's brin_revmap_data(), * which also always emits REVMAP_PAGE_MAXITEMS entries. */ -#if PG_VERSION_NUM >= 90500 static void EmitXmlRevmap(Page page, BlockNumber blkno) { @@ -3481,7 +3456,6 @@ EmitXmlRevmap(Page page, BlockNumber blkno) relfileOff = relfileOffNext; } } -#endif /* * On blocks that have special sections, print the contents according to @@ -3717,7 +3691,6 @@ EmitXmlSpecial(BlockNumber blkno, uint32 level) } break; -#if PG_VERSION_NUM >= 90500 case SPEC_SECT_INDEX_BRIN: { /* @@ -3753,7 +3726,6 @@ EmitXmlSpecial(BlockNumber blkno, uint32 level) (pageOffset + specialOffset + sizeof(BrinSpecialSpace) - 1)); } break; -#endif default: /* Only complain the first time an error like this is seen */