Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 74096ed

Browse files
committed
Fix pg_dump on win32 to properly dump files larger than 2Gb when using
binary dump formats.
1 parent bc959b7 commit 74096ed

File tree

6 files changed

+59
-41
lines changed

6 files changed

+59
-41
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.141 2007/02/01 19:10:28 momjian Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.142 2007/02/19 15:05:06 mha Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1311,24 +1311,24 @@ TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt)
13111311
}
13121312

13131313
size_t
1314-
WriteOffset(ArchiveHandle *AH, off_t o, int wasSet)
1314+
WriteOffset(ArchiveHandle *AH, pgoff_t o, int wasSet)
13151315
{
13161316
int off;
13171317

13181318
/* Save the flag */
13191319
(*AH->WriteBytePtr) (AH, wasSet);
13201320

1321-
/* Write out off_t smallest byte first, prevents endian mismatch */
1322-
for (off = 0; off < sizeof(off_t); off++)
1321+
/* Write out pgoff_t smallest byte first, prevents endian mismatch */
1322+
for (off = 0; off < sizeof(pgoff_t); off++)
13231323
{
13241324
(*AH->WriteBytePtr) (AH, o & 0xFF);
13251325
o >>= 8;
13261326
}
1327-
return sizeof(off_t) + 1;
1327+
return sizeof(pgoff_t) + 1;
13281328
}
13291329

13301330
int
1331-
ReadOffset(ArchiveHandle *AH, off_t *o)
1331+
ReadOffset(ArchiveHandle *AH, pgoff_t *o)
13321332
{
13331333
int i;
13341334
int off;
@@ -1348,8 +1348,8 @@ ReadOffset(ArchiveHandle *AH, off_t *o)
13481348
else if (i == 0)
13491349
return K_OFFSET_NO_DATA;
13501350

1351-
/* Cast to off_t because it was written as an int. */
1352-
*o = (off_t) i;
1351+
/* Cast to pgoff_t because it was written as an int. */
1352+
*o = (pgoff_t) i;
13531353
return K_OFFSET_POS_SET;
13541354
}
13551355

@@ -1379,8 +1379,8 @@ ReadOffset(ArchiveHandle *AH, off_t *o)
13791379
*/
13801380
for (off = 0; off < AH->offSize; off++)
13811381
{
1382-
if (off < sizeof(off_t))
1383-
*o |= ((off_t) ((*AH->ReadBytePtr) (AH))) << (off * 8);
1382+
if (off < sizeof(pgoff_t))
1383+
*o |= ((pgoff_t) ((*AH->ReadBytePtr) (AH))) << (off * 8);
13841384
else
13851385
{
13861386
if ((*AH->ReadBytePtr) (AH) != 0)
@@ -1647,7 +1647,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
16471647
AH->createDate = time(NULL);
16481648

16491649
AH->intSize = sizeof(int);
1650-
AH->offSize = sizeof(off_t);
1650+
AH->offSize = sizeof(pgoff_t);
16511651
if (FileSpec)
16521652
{
16531653
AH->fSpec = strdup(FileSpec);
@@ -2768,11 +2768,11 @@ checkSeek(FILE *fp)
27682768

27692769
if (fseeko(fp, 0, SEEK_CUR) != 0)
27702770
return false;
2771-
else if (sizeof(off_t) > sizeof(long))
2771+
else if (sizeof(pgoff_t) > sizeof(long))
27722772

27732773
/*
2774-
* At this point, off_t is too large for long, so we return based on
2775-
* whether an off_t version of fseek is available.
2774+
* At this point, pgoff_t is too large for long, so we return based on
2775+
* whether an pgoff_t version of fseek is available.
27762776
*/
27772777
#ifdef HAVE_FSEEKO
27782778
return true;

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*
1919
* IDENTIFICATION
20-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.74 2007/01/25 03:30:43 momjian Exp $
20+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.75 2007/02/19 15:05:06 mha Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -199,7 +199,7 @@ typedef struct _archiveHandle
199199
* format */
200200
size_t lookaheadSize; /* Size of allocated buffer */
201201
size_t lookaheadLen; /* Length of data in lookahead */
202-
off_t lookaheadPos; /* Current read position in lookahead buffer */
202+
pgoff_t lookaheadPos; /* Current read position in lookahead buffer */
203203

204204
ArchiveEntryPtr ArchiveEntryPtr; /* Called for each metadata object */
205205
StartDataPtr StartDataPtr; /* Called when table data is about to be
@@ -332,8 +332,8 @@ extern int ReadInt(ArchiveHandle *AH);
332332
extern char *ReadStr(ArchiveHandle *AH);
333333
extern size_t WriteStr(ArchiveHandle *AH, const char *s);
334334

335-
int ReadOffset(ArchiveHandle *, off_t *);
336-
size_t WriteOffset(ArchiveHandle *, off_t, int);
335+
int ReadOffset(ArchiveHandle *, pgoff_t *);
336+
size_t WriteOffset(ArchiveHandle *, pgoff_t, int);
337337

338338
extern void StartRestoreBlobs(ArchiveHandle *AH);
339339
extern void StartRestoreBlob(ArchiveHandle *AH, Oid oid);

src/bin/pg_dump/pg_backup_custom.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*
2121
* IDENTIFICATION
22-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.36 2006/10/04 00:30:05 momjian Exp $
22+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.37 2007/02/19 15:05:06 mha Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -70,14 +70,14 @@ typedef struct
7070
char *zlibIn;
7171
size_t inSize;
7272
int hasSeek;
73-
off_t filePos;
74-
off_t dataStart;
73+
pgoff_t filePos;
74+
pgoff_t dataStart;
7575
} lclContext;
7676

7777
typedef struct
7878
{
7979
int dataState;
80-
off_t dataPos;
80+
pgoff_t dataPos;
8181
} lclTocEntry;
8282

8383

@@ -88,7 +88,7 @@ typedef struct
8888
static void _readBlockHeader(ArchiveHandle *AH, int *type, int *id);
8989
static void _StartDataCompressor(ArchiveHandle *AH, TocEntry *te);
9090
static void _EndDataCompressor(ArchiveHandle *AH, TocEntry *te);
91-
static off_t _getFilePos(ArchiveHandle *AH, lclContext *ctx);
91+
static pgoff_t _getFilePos(ArchiveHandle *AH, lclContext *ctx);
9292
static int _DoDeflate(ArchiveHandle *AH, lclContext *ctx, int flush);
9393

9494
static char *modulename = gettext_noop("custom archiver");
@@ -791,7 +791,7 @@ static void
791791
_CloseArchive(ArchiveHandle *AH)
792792
{
793793
lclContext *ctx = (lclContext *) AH->formatData;
794-
off_t tpos;
794+
pgoff_t tpos;
795795

796796
if (AH->mode == archModeWrite)
797797
{
@@ -827,10 +827,10 @@ _CloseArchive(ArchiveHandle *AH)
827827
/*
828828
* Get the current position in the archive file.
829829
*/
830-
static off_t
830+
static pgoff_t
831831
_getFilePos(ArchiveHandle *AH, lclContext *ctx)
832832
{
833-
off_t pos;
833+
pgoff_t pos;
834834

835835
if (ctx->hasSeek)
836836
{
@@ -841,7 +841,7 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
841841

842842
/*
843843
* Prior to 1.7 (pg7.3) we relied on the internally maintained
844-
* pointer. Now we rely on off_t always. pos = ctx->filePos;
844+
* pointer. Now we rely on pgoff_t always. pos = ctx->filePos;
845845
*/
846846
}
847847
}

src/bin/pg_dump/pg_backup_files.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*
2222
* IDENTIFICATION
23-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.30 2007/02/08 11:10:27 petere Exp $
23+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.31 2007/02/19 15:05:06 mha Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -51,7 +51,7 @@ static void _EndBlobs(ArchiveHandle *AH, TocEntry *te);
5151
typedef struct
5252
{
5353
int hasSeek;
54-
off_t filePos;
54+
pgoff_t filePos;
5555
FILE *blobToc;
5656
} lclContext;
5757

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.56 2006/11/01 15:59:26 tgl Exp $
19+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.57 2007/02/19 15:05:06 mha Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -67,30 +67,30 @@ typedef struct
6767
FILE *tmpFH;
6868
char *targetFile;
6969
char mode;
70-
off_t pos;
71-
off_t fileLen;
70+
pgoff_t pos;
71+
pgoff_t fileLen;
7272
ArchiveHandle *AH;
7373
} TAR_MEMBER;
7474

7575
/*
7676
* Maximum file size for a tar member: The limit inherent in the
7777
* format is 2^33-1 bytes (nearly 8 GB). But we don't want to exceed
78-
* what we can represent by an off_t.
78+
* what we can represent by an pgoff_t.
7979
*/
8080
#ifdef INT64_IS_BUSTED
8181
#define MAX_TAR_MEMBER_FILELEN INT_MAX
8282
#else
83-
#define MAX_TAR_MEMBER_FILELEN (((int64) 1 << Min(33, sizeof(off_t)*8 - 1)) - 1)
83+
#define MAX_TAR_MEMBER_FILELEN (((int64) 1 << Min(33, sizeof(pgoff_t)*8 - 1)) - 1)
8484
#endif
8585

8686
typedef struct
8787
{
8888
int hasSeek;
89-
off_t filePos;
89+
pgoff_t filePos;
9090
TAR_MEMBER *blobToc;
9191
FILE *tarFH;
92-
off_t tarFHpos;
93-
off_t tarNextMember;
92+
pgoff_t tarFHpos;
93+
pgoff_t tarNextMember;
9494
TAR_MEMBER *FH;
9595
int isSpecialScript;
9696
TAR_MEMBER *scriptTH;
@@ -1048,7 +1048,7 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
10481048
FILE *tmp = th->tmpFH; /* Grab it for convenience */
10491049
char buf[32768];
10501050
size_t cnt;
1051-
off_t len = 0;
1051+
pgoff_t len = 0;
10521052
size_t res;
10531053
size_t i,
10541054
pad;
@@ -1061,7 +1061,7 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
10611061

10621062
/*
10631063
* Some compilers with throw a warning knowing this test can never be true
1064-
* because off_t can't exceed the compared maximum.
1064+
* because pgoff_t can't exceed the compared maximum.
10651065
*/
10661066
if (th->fileLen > MAX_TAR_MEMBER_FILELEN)
10671067
die_horribly(AH, modulename, "archive member too large for tar format\n");
@@ -1197,7 +1197,7 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
11971197
chk;
11981198
size_t len;
11991199
unsigned long ullen;
1200-
off_t hPos;
1200+
pgoff_t hPos;
12011201
bool gotBlock = false;
12021202

12031203
while (!gotBlock)

src/bin/pg_dump/pg_dump.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.132 2007/01/23 17:54:50 tgl Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.133 2007/02/19 15:05:06 mha Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -16,6 +16,24 @@
1616

1717
#include "postgres_fe.h"
1818

19+
/*
20+
* WIN32 does not provide 64-bit off_t, but does provide the functions operating
21+
* with 64-bit offsets.
22+
*/
23+
#ifdef WIN32
24+
#define pgoff_t __int64
25+
#undef fseeko
26+
#undef ftello
27+
#ifdef WIN32_ONLY_COMPILER
28+
#define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin)
29+
#define ftello(stream) _ftelli64(stream)
30+
#else
31+
#define fseeko(stream, offset, origin) fseeko64(stream, offset, origin)
32+
#define ftello(stream) ftello64(stream)
33+
#endif
34+
#else
35+
#define pgoff_t off_t
36+
#endif
1937

2038
/*
2139
* pg_dump uses two different mechanisms for identifying database objects:

0 commit comments

Comments
 (0)