|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * 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 $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
@@ -671,9 +671,11 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
|
671 | 671 | }
|
672 | 672 |
|
673 | 673 | 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); |
675 | 677 |
|
676 |
| - ahprintf(AH, ";\n; Selected TOC Entries:\n;\n"); |
| 678 | + ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n"); |
677 | 679 |
|
678 | 680 | while (te != AH->toc)
|
679 | 681 | {
|
@@ -1368,6 +1370,87 @@ TocIDRequired(ArchiveHandle *AH, int id, RestoreOptions *ropt)
|
1368 | 1370 | return _tocEntryRequired(te, ropt);
|
1369 | 1371 | }
|
1370 | 1372 |
|
| 1373 | +size_t |
| 1374 | +WriteOffset(ArchiveHandle *AH, off_t o, int wasSet) |
| 1375 | +{ |
| 1376 | + int off; |
| 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 | + return sizeof(off_t) + 1; |
| 1388 | +} |
| 1389 | + |
| 1390 | +int |
| 1391 | +ReadOffset(ArchiveHandle *AH, off_t *o) |
| 1392 | +{ |
| 1393 | + int i; |
| 1394 | + int off; |
| 1395 | + int offsetFlg; |
| 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 | + return K_OFFSET_POS_NOT_SET; |
| 1408 | + else if (i == 0) |
| 1409 | + return K_OFFSET_NO_DATA; |
| 1410 | + |
| 1411 | + /* Cast to off_t because it was written as an int. */ |
| 1412 | + *o = (off_t)i; |
| 1413 | + return K_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 | + case K_OFFSET_POS_NOT_SET: |
| 1428 | + case K_OFFSET_NO_DATA: |
| 1429 | + case K_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 | + return offsetFlg; |
| 1452 | +} |
| 1453 | + |
1371 | 1454 | size_t
|
1372 | 1455 | WriteInt(ArchiveHandle *AH, int i)
|
1373 | 1456 | {
|
@@ -1528,14 +1611,22 @@ _discoverArchiveFormat(ArchiveHandle *AH)
|
1528 | 1611 | else
|
1529 | 1612 | AH->vrev = 0;
|
1530 | 1613 |
|
| 1614 | + /* Make a convenient integer <maj><min><rev>00 */ |
| 1615 | + AH->version = ((AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev) * 256 + 0; |
| 1616 | + |
1531 | 1617 | AH->intSize = fgetc(fh);
|
1532 | 1618 | AH->lookahead[AH->lookaheadLen++] = AH->intSize;
|
1533 | 1619 |
|
| 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 | + |
1534 | 1628 | AH->format = fgetc(fh);
|
1535 | 1629 | 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; |
1539 | 1630 | }
|
1540 | 1631 | else
|
1541 | 1632 | {
|
@@ -1599,13 +1690,16 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
|
1599 | 1690 | if (!AH)
|
1600 | 1691 | die_horribly(AH, modulename, "out of memory\n");
|
1601 | 1692 |
|
| 1693 | + /* AH->debugLevel = 100; */ |
| 1694 | + |
1602 | 1695 | AH->vmaj = K_VERS_MAJOR;
|
1603 | 1696 | AH->vmin = K_VERS_MINOR;
|
1604 | 1697 | AH->vrev = K_VERS_REV;
|
1605 | 1698 |
|
1606 | 1699 | AH->createDate = time(NULL);
|
1607 | 1700 |
|
1608 | 1701 | AH->intSize = sizeof(int);
|
| 1702 | + AH->offSize = sizeof(off_t); |
1609 | 1703 | AH->lastID = 0;
|
1610 | 1704 | if (FileSpec)
|
1611 | 1705 | {
|
@@ -1784,7 +1878,7 @@ ReadToc(ArchiveHandle *AH)
|
1784 | 1878 |
|
1785 | 1879 | /* Sanity check */
|
1786 | 1880 | 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 %d out of range - perhaps a corrupt TOC\n", te->id); |
1788 | 1882 |
|
1789 | 1883 | te->hadDumper = ReadInt(AH);
|
1790 | 1884 | te->oid = ReadStr(AH);
|
@@ -2133,6 +2227,7 @@ WriteHead(ArchiveHandle *AH)
|
2133 | 2227 | (*AH->WriteBytePtr) (AH, AH->vmin);
|
2134 | 2228 | (*AH->WriteBytePtr) (AH, AH->vrev);
|
2135 | 2229 | (*AH->WriteBytePtr) (AH, AH->intSize);
|
| 2230 | + (*AH->WriteBytePtr) (AH, AH->offSize); |
2136 | 2231 | (*AH->WriteBytePtr) (AH, AH->format);
|
2137 | 2232 |
|
2138 | 2233 | #ifndef HAVE_LIBZ
|
@@ -2195,6 +2290,11 @@ ReadHead(ArchiveHandle *AH)
|
2195 | 2290 | if (AH->intSize > sizeof(int))
|
2196 | 2291 | write_msg(modulename, "WARNING: archive was made on a machine with larger integers, some operations may fail\n");
|
2197 | 2292 |
|
| 2293 | + if (AH->version >= K_VERS_1_7) |
| 2294 | + AH->offSize = (*AH->ReadBytePtr) (AH); |
| 2295 | + else |
| 2296 | + AH->offSize = AH->intSize; |
| 2297 | + |
2198 | 2298 | fmt = (*AH->ReadBytePtr) (AH);
|
2199 | 2299 |
|
2200 | 2300 | if (AH->format != fmt)
|
|
0 commit comments