@@ -62,7 +62,7 @@ typedef struct WriteTarState
62
62
int tablespacenum ;
63
63
char filename [MAXPGPATH ];
64
64
FILE * tarfile ;
65
- char tarhdr [512 ];
65
+ char tarhdr [TAR_BLOCK_SIZE ];
66
66
bool basetablespace ;
67
67
bool in_tarhdr ;
68
68
bool skip_file ;
@@ -1024,7 +1024,7 @@ writeTarData(WriteTarState *state, char *buf, int r)
1024
1024
static void
1025
1025
ReceiveTarFile (PGconn * conn , PGresult * res , int rownum )
1026
1026
{
1027
- char zerobuf [1024 ];
1027
+ char zerobuf [TAR_BLOCK_SIZE * 2 ];
1028
1028
WriteTarState state ;
1029
1029
1030
1030
memset (& state , 0 , sizeof (state ));
@@ -1169,7 +1169,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
1169
1169
1170
1170
if (state .basetablespace && writerecoveryconf )
1171
1171
{
1172
- char header [512 ];
1172
+ char header [TAR_BLOCK_SIZE ];
1173
1173
1174
1174
/*
1175
1175
* If postgresql.auto.conf has not been found in the streamed data,
@@ -1188,7 +1188,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
1188
1188
pg_file_create_mode , 04000 , 02000 ,
1189
1189
time (NULL ));
1190
1190
1191
- padding = (( recoveryconfcontents -> len + 511 ) & ~ 511 ) - recoveryconfcontents -> len ;
1191
+ padding = tarPaddingBytesRequired ( recoveryconfcontents -> len ) ;
1192
1192
1193
1193
writeTarData (& state , header , sizeof (header ));
1194
1194
writeTarData (& state , recoveryconfcontents -> data ,
@@ -1224,7 +1224,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
1224
1224
*/
1225
1225
if (strcmp (basedir , "-" ) == 0 && manifest )
1226
1226
{
1227
- char header [512 ];
1227
+ char header [TAR_BLOCK_SIZE ];
1228
1228
PQExpBufferData buf ;
1229
1229
1230
1230
initPQExpBuffer (& buf );
@@ -1242,7 +1242,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
1242
1242
termPQExpBuffer (& buf );
1243
1243
}
1244
1244
1245
- /* 2 * 512 bytes empty data at end of file */
1245
+ /* 2 * TAR_BLOCK_SIZE bytes empty data at end of file */
1246
1246
writeTarData (& state , zerobuf , sizeof (zerobuf ));
1247
1247
1248
1248
#ifdef HAVE_LIBZ
@@ -1303,9 +1303,9 @@ ReceiveTarCopyChunk(size_t r, char *copybuf, void *callback_data)
1303
1303
*
1304
1304
* To do this, we have to process the individual files inside the TAR
1305
1305
* stream. The stream consists of a header and zero or more chunks,
1306
- * all 512 bytes long . The stream from the server is broken up into
1307
- * smaller pieces, so we have to track the size of the files to find
1308
- * the next header structure.
1306
+ * each with a length equal to TAR_BLOCK_SIZE . The stream from the
1307
+ * server is broken up into smaller pieces, so we have to track the
1308
+ * size of the files to find the next header structure.
1309
1309
*/
1310
1310
int rr = r ;
1311
1311
int pos = 0 ;
@@ -1318,17 +1318,17 @@ ReceiveTarCopyChunk(size_t r, char *copybuf, void *callback_data)
1318
1318
* We're currently reading a header structure inside the TAR
1319
1319
* stream, i.e. the file metadata.
1320
1320
*/
1321
- if (state -> tarhdrsz < 512 )
1321
+ if (state -> tarhdrsz < TAR_BLOCK_SIZE )
1322
1322
{
1323
1323
/*
1324
1324
* Copy the header structure into tarhdr in case the
1325
- * header is not aligned to 512 bytes or it's not returned
1326
- * in whole by the last PQgetCopyData call.
1325
+ * header is not aligned properly or it's not returned in
1326
+ * whole by the last PQgetCopyData call.
1327
1327
*/
1328
1328
int hdrleft ;
1329
1329
int bytes2copy ;
1330
1330
1331
- hdrleft = 512 - state -> tarhdrsz ;
1331
+ hdrleft = TAR_BLOCK_SIZE - state -> tarhdrsz ;
1332
1332
bytes2copy = (rr > hdrleft ? hdrleft : rr );
1333
1333
1334
1334
memcpy (& state -> tarhdr [state -> tarhdrsz ], copybuf + pos ,
@@ -1361,14 +1361,14 @@ ReceiveTarCopyChunk(size_t r, char *copybuf, void *callback_data)
1361
1361
1362
1362
state -> filesz = read_tar_number (& state -> tarhdr [124 ], 12 );
1363
1363
state -> file_padding_len =
1364
- (( state -> filesz + 511 ) & ~ 511 ) - state -> filesz ;
1364
+ tarPaddingBytesRequired ( state -> filesz ) ;
1365
1365
1366
1366
if (state -> is_recovery_guc_supported &&
1367
1367
state -> is_postgresql_auto_conf &&
1368
1368
writerecoveryconf )
1369
1369
{
1370
1370
/* replace tar header */
1371
- char header [512 ];
1371
+ char header [TAR_BLOCK_SIZE ];
1372
1372
1373
1373
tarCreateHeader (header , "postgresql.auto.conf" , NULL ,
1374
1374
state -> filesz + recoveryconfcontents -> len ,
@@ -1388,7 +1388,7 @@ ReceiveTarCopyChunk(size_t r, char *copybuf, void *callback_data)
1388
1388
* If we're not skipping the file, write the tar
1389
1389
* header unmodified.
1390
1390
*/
1391
- writeTarData (state , state -> tarhdr , 512 );
1391
+ writeTarData (state , state -> tarhdr , TAR_BLOCK_SIZE );
1392
1392
}
1393
1393
}
1394
1394
@@ -1425,15 +1425,15 @@ ReceiveTarCopyChunk(size_t r, char *copybuf, void *callback_data)
1425
1425
int padding ;
1426
1426
int tailsize ;
1427
1427
1428
- tailsize = (512 - state -> file_padding_len ) + recoveryconfcontents -> len ;
1429
- padding = (( tailsize + 511 ) & ~ 511 ) - tailsize ;
1428
+ tailsize = (TAR_BLOCK_SIZE - state -> file_padding_len ) + recoveryconfcontents -> len ;
1429
+ padding = tarPaddingBytesRequired ( tailsize ) ;
1430
1430
1431
1431
writeTarData (state , recoveryconfcontents -> data ,
1432
1432
recoveryconfcontents -> len );
1433
1433
1434
1434
if (padding )
1435
1435
{
1436
- char zerobuf [512 ];
1436
+ char zerobuf [TAR_BLOCK_SIZE ];
1437
1437
1438
1438
MemSet (zerobuf , 0 , sizeof (zerobuf ));
1439
1439
writeTarData (state , zerobuf , padding );
@@ -1551,12 +1551,12 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf, void *callback_data)
1551
1551
/*
1552
1552
* No current file, so this must be the header for a new file
1553
1553
*/
1554
- if (r != 512 )
1554
+ if (r != TAR_BLOCK_SIZE )
1555
1555
{
1556
1556
pg_log_error ("invalid tar block header size: %zu" , r );
1557
1557
exit (1 );
1558
1558
}
1559
- totaldone += 512 ;
1559
+ totaldone += TAR_BLOCK_SIZE ;
1560
1560
1561
1561
state -> current_len_left = read_tar_number (& copybuf [124 ], 12 );
1562
1562
@@ -1566,10 +1566,10 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf, void *callback_data)
1566
1566
#endif
1567
1567
1568
1568
/*
1569
- * All files are padded up to 512 bytes
1569
+ * All files are padded up to a multiple of TAR_BLOCK_SIZE
1570
1570
*/
1571
1571
state -> current_padding =
1572
- (( state -> current_len_left + 511 ) & ~ 511 ) - state -> current_len_left ;
1572
+ tarPaddingBytesRequired ( state -> current_len_left ) ;
1573
1573
1574
1574
/*
1575
1575
* First part of header is zero terminated filename
0 commit comments