Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2b28702

Browse files
committed
Allow 8-byte off_t to properly pg_dump, from Philip Warner with mods by Bruce.
1 parent19cc7bc commit2b28702

File tree

7 files changed

+154
-87
lines changed

7 files changed

+154
-87
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 107 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.58 2002/10/16 05:46:54 momjian Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.59 2002/10/22 19:15:23 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -671,9 +671,11 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
671671
}
672672

673673
ahprintf(AH,"; Dump Version: %d.%d-%d\n",AH->vmaj,AH->vmin,AH->vrev);
674-
ahprintf(AH,"; Format: %s\n;\n",fmtName);
674+
ahprintf(AH,"; Format: %s\n",fmtName);
675+
ahprintf(AH,"; Integer: %d bytes\n",AH->intSize);
676+
ahprintf(AH,"; Offset: %d bytes\n",AH->offSize);
675677

676-
ahprintf(AH,";\n; Selected TOC Entries:\n;\n");
678+
ahprintf(AH,";\n;\n; Selected TOC Entries:\n;\n");
677679

678680
while (te!=AH->toc)
679681
{
@@ -1368,6 +1370,87 @@ TocIDRequired(ArchiveHandle *AH, int id, RestoreOptions *ropt)
13681370
return_tocEntryRequired(te,ropt);
13691371
}
13701372

1373+
size_t
1374+
WriteOffset(ArchiveHandle*AH,off_to,intwasSet)
1375+
{
1376+
intoff;
1377+
1378+
/* Save the flag */
1379+
(*AH->WriteBytePtr) (AH,wasSet);
1380+
1381+
/* Write out off_t smallest byte first, prevents endian mismatch */
1382+
for (off=0;off<sizeof(off_t);off++)
1383+
{
1384+
(*AH->WriteBytePtr) (AH,o&0xFF);
1385+
o >>=8;
1386+
}
1387+
returnsizeof(off_t)+1;
1388+
}
1389+
1390+
int
1391+
ReadOffset(ArchiveHandle*AH,off_t*o)
1392+
{
1393+
inti;
1394+
intoff;
1395+
intoffsetFlg;
1396+
1397+
/* Initialize to zero */
1398+
*o=0;
1399+
1400+
/* Check for old version */
1401+
if (AH->version<K_VERS_1_7)
1402+
{
1403+
/* Prior versions wrote offsets using WriteInt */
1404+
i=ReadInt(AH);
1405+
/* -1 means not set */
1406+
if (i<0)
1407+
returnK_OFFSET_POS_NOT_SET;
1408+
elseif (i==0)
1409+
returnK_OFFSET_NO_DATA;
1410+
1411+
/* Cast to off_t because it was written as an int. */
1412+
*o= (off_t)i;
1413+
returnK_OFFSET_POS_SET;
1414+
}
1415+
1416+
/*
1417+
* Read the flag indicating the state of the data pointer.
1418+
* Check if valid and die if not.
1419+
*
1420+
* This used to be handled by a negative or zero pointer,
1421+
* now we use an extra byte specifically for the state.
1422+
*/
1423+
offsetFlg= (*AH->ReadBytePtr) (AH)&0xFF;
1424+
1425+
switch (offsetFlg)
1426+
{
1427+
caseK_OFFSET_POS_NOT_SET:
1428+
caseK_OFFSET_NO_DATA:
1429+
caseK_OFFSET_POS_SET:
1430+
1431+
break;
1432+
1433+
default:
1434+
die_horribly(AH,modulename,"Unexpected data offset flag %d\n",offsetFlg);
1435+
}
1436+
1437+
/*
1438+
* Read the bytes
1439+
*/
1440+
for (off=0;off<AH->offSize;off++)
1441+
{
1442+
if (off<sizeof(off_t))
1443+
*o |= ((*AH->ReadBytePtr) (AH)) << (off*8);
1444+
else
1445+
{
1446+
if ((*AH->ReadBytePtr) (AH)!=0)
1447+
die_horribly(AH,modulename,"file offset in dump file is too large\n");
1448+
}
1449+
}
1450+
1451+
returnoffsetFlg;
1452+
}
1453+
13711454
size_t
13721455
WriteInt(ArchiveHandle*AH,inti)
13731456
{
@@ -1528,14 +1611,22 @@ _discoverArchiveFormat(ArchiveHandle *AH)
15281611
else
15291612
AH->vrev=0;
15301613

1614+
/* Make a convenient integer <maj><min><rev>00 */
1615+
AH->version= ((AH->vmaj*256+AH->vmin)*256+AH->vrev)*256+0;
1616+
15311617
AH->intSize=fgetc(fh);
15321618
AH->lookahead[AH->lookaheadLen++]=AH->intSize;
15331619

1620+
if (AH->version >=K_VERS_1_7)
1621+
{
1622+
AH->offSize=fgetc(fh);
1623+
AH->lookahead[AH->lookaheadLen++]=AH->offSize;
1624+
}
1625+
else
1626+
AH->offSize=AH->intSize;
1627+
15341628
AH->format=fgetc(fh);
15351629
AH->lookahead[AH->lookaheadLen++]=AH->format;
1536-
1537-
/* Make a convenient integer <maj><min><rev>00 */
1538-
AH->version= ((AH->vmaj*256+AH->vmin)*256+AH->vrev)*256+0;
15391630
}
15401631
else
15411632
{
@@ -1599,13 +1690,16 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
15991690
if (!AH)
16001691
die_horribly(AH,modulename,"out of memory\n");
16011692

1693+
/* AH->debugLevel = 100; */
1694+
16021695
AH->vmaj=K_VERS_MAJOR;
16031696
AH->vmin=K_VERS_MINOR;
16041697
AH->vrev=K_VERS_REV;
16051698

16061699
AH->createDate=time(NULL);
16071700

16081701
AH->intSize=sizeof(int);
1702+
AH->offSize=sizeof(off_t);
16091703
AH->lastID=0;
16101704
if (FileSpec)
16111705
{
@@ -1784,7 +1878,7 @@ ReadToc(ArchiveHandle *AH)
17841878

17851879
/* Sanity check */
17861880
if (te->id <=0||te->id>AH->tocCount)
1787-
die_horribly(AH,modulename,"entry id out of range - perhaps a corrupt TOC\n");
1881+
die_horribly(AH,modulename,"entry id%dout of range - perhaps a corrupt TOC\n",te->id);
17881882

17891883
te->hadDumper=ReadInt(AH);
17901884
te->oid=ReadStr(AH);
@@ -2133,6 +2227,7 @@ WriteHead(ArchiveHandle *AH)
21332227
(*AH->WriteBytePtr) (AH,AH->vmin);
21342228
(*AH->WriteBytePtr) (AH,AH->vrev);
21352229
(*AH->WriteBytePtr) (AH,AH->intSize);
2230+
(*AH->WriteBytePtr) (AH,AH->offSize);
21362231
(*AH->WriteBytePtr) (AH,AH->format);
21372232

21382233
#ifndefHAVE_LIBZ
@@ -2195,6 +2290,11 @@ ReadHead(ArchiveHandle *AH)
21952290
if (AH->intSize>sizeof(int))
21962291
write_msg(modulename,"WARNING: archive was made on a machine with larger integers, some operations may fail\n");
21972292

2293+
if (AH->version >=K_VERS_1_7)
2294+
AH->offSize= (*AH->ReadBytePtr) (AH);
2295+
else
2296+
AH->offSize=AH->intSize;
2297+
21982298
fmt= (*AH->ReadBytePtr) (AH);
21992299

22002300
if (AH->format!=fmt)

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*
1919
* IDENTIFICATION
20-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.47 2002/09/04 20:31:34 momjian Exp $
20+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.48 2002/10/22 19:15:23 momjian Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -58,7 +58,7 @@ typedef z_stream *z_streamp;
5858
#include"libpq-fe.h"
5959

6060
#defineK_VERS_MAJOR 1
61-
#defineK_VERS_MINOR6
61+
#defineK_VERS_MINOR7
6262
#defineK_VERS_REV 0
6363

6464
/* Data block types */
@@ -73,11 +73,17 @@ typedef z_stream *z_streamp;
7373
#defineK_VERS_1_4 (( (1 * 256 + 4) * 256 + 0) * 256 + 0)/* Date & name in header */
7474
#defineK_VERS_1_5 (( (1 * 256 + 5) * 256 + 0) * 256 + 0)/* Handle dependencies */
7575
#defineK_VERS_1_6 (( (1 * 256 + 6) * 256 + 0) * 256 + 0)/* Schema field in TOCs */
76-
#defineK_VERS_MAX (( (1 * 256 + 6) * 256 + 255) * 256 + 0)
76+
#defineK_VERS_1_7 (( (1 * 256 + 7) * 256 + 0) * 256 + 0)/* File Offset size in header */
77+
#defineK_VERS_MAX (( (1 * 256 + 7) * 256 + 255) * 256 + 0)
7778

7879
/* No of BLOBs to restore in 1 TX */
7980
#defineBLOB_BATCH_SIZE 100
8081

82+
/* Flags to indicate disposition of offsets stored in files */
83+
#defineK_OFFSET_POS_NOT_SET 1
84+
#defineK_OFFSET_POS_SET 2
85+
#defineK_OFFSET_NO_DATA 3
86+
8187
struct_archiveHandle;
8288
struct_tocEntry;
8389
struct_restoreList;
@@ -148,6 +154,7 @@ typedef struct _archiveHandle
148154
intdebugLevel;/* Used for logging (currently only by
149155
* --verbose) */
150156
size_tintSize;/* Size of an integer in the archive */
157+
size_toffSize;/* Size of a file offset in the archive - Added V1.7 */
151158
ArchiveFormatformat;/* Archive format */
152159

153160
sqlparseInfosqlparse;
@@ -287,6 +294,9 @@ extern intReadInt(ArchiveHandle *AH);
287294
externchar*ReadStr(ArchiveHandle*AH);
288295
externsize_tWriteStr(ArchiveHandle*AH,constchar*s);
289296

297+
intReadOffset(ArchiveHandle*,off_t*);
298+
size_tWriteOffset(ArchiveHandle*,off_t,int);
299+
290300
externvoidStartRestoreBlobs(ArchiveHandle*AH);
291301
externvoidStartRestoreBlob(ArchiveHandle*AH,Oidoid);
292302
externvoidEndRestoreBlob(ArchiveHandle*AH,Oidoid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp