@@ -727,7 +727,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
727727if (file -> write_size != BYTES_INVALID )
728728{
729729/* open backup mode file for read */
730- in = fopen (file -> path ,PG_BINARY_R );
730+ in = fio_fopen (file -> path ,PG_BINARY_R , FIO_LOCAL_HOST , file -> is_datafile && instance_config . encryption );
731731if (in == NULL )
732732{
733733elog (ERROR ,"Cannot open backup file \"%s\": %s" ,file -> path ,
@@ -744,15 +744,15 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
744744if (out == NULL )
745745{
746746int errno_tmp = errno ;
747- fclose (in );
747+ fio_fclose (in );
748748elog (ERROR ,"Cannot open restore target file \"%s\": %s" ,
749749to_path ,strerror (errno_tmp ));
750750}
751751
752752while (true)
753753{
754754off_t write_pos ;
755- size_t read_len ;
755+ ssize_t read_len ;
756756DataPage compressed_page ;/* used as read buffer */
757757DataPage page ;
758758int32 uncompressed_size = 0 ;
@@ -777,13 +777,13 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
777777}
778778
779779/* read BackupPageHeader */
780- read_len = fread ( & header ,1 , sizeof (header ), in );
780+ read_len = fio_fread ( in , & header ,sizeof (header ));
781781if (read_len != sizeof (header ))
782782{
783783int errno_tmp = errno ;
784- if (read_len == 0 && feof ( in ) )
784+ if (read_len == 0 )
785785break ;/* EOF found */
786- else if (read_len != 0 && feof ( in ) )
786+ else if (read_len > 0 )
787787elog (ERROR ,
788788"Odd size page found at block %u of \"%s\"" ,
789789blknum ,file -> path );
@@ -818,8 +818,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
818818Assert (header .compressed_size <=BLCKSZ );
819819
820820/* read a page from file */
821- read_len = fread (compressed_page .data ,1 ,
822- MAXALIGN (header .compressed_size ),in );
821+ read_len = fio_fread (in ,compressed_page .data ,MAXALIGN (header .compressed_size ));
823822if (read_len != MAXALIGN (header .compressed_size ))
824823elog (ERROR ,"Cannot read block %u of \"%s\" read %zu of %d" ,
825824blknum ,file -> path ,read_len ,header .compressed_size );
@@ -926,7 +925,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
926925int errno_tmp = errno ;
927926
928927if (in )
929- fclose (in );
928+ fio_fclose (in );
930929fio_fclose (out );
931930elog (ERROR ,"Cannot change mode of \"%s\": %s" ,to_path ,
932931strerror (errno_tmp ));
@@ -937,7 +936,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
937936elog (ERROR ,"Cannot write \"%s\": %s" ,to_path ,strerror (errno ));
938937
939938if (in )
940- fclose (in );
939+ fio_fclose (in );
941940}
942941
943942/*
@@ -964,7 +963,7 @@ copy_file(fio_location from_location, const char *to_root,
964963file -> write_size = 0 ;
965964
966965/* open backup mode file for read */
967- in = fio_fopen (file -> path ,PG_BINARY_R ,from_location ,instance_config .encryption && from_location == FIO_BACKUP_HOST );
966+ in = fio_fopen (file -> path ,PG_BINARY_R ,from_location ,file -> is_datafile && instance_config .encryption && from_location == FIO_BACKUP_HOST );
968967if (in == NULL )
969968{
970969FIN_FILE_CRC32 (true,crc );
@@ -989,7 +988,7 @@ copy_file(fio_location from_location, const char *to_root,
989988
990989/* open backup file for write */
991990join_path_components (to_path ,to_root ,file -> rel_path );
992- out = fio_fopen (to_path ,PG_BINARY_W ,to_location ,instance_config .encryption && to_location == FIO_BACKUP_HOST );
991+ out = fio_fopen (to_path ,PG_BINARY_W ,to_location ,file -> is_datafile && instance_config .encryption && to_location == FIO_BACKUP_HOST );
993992if (out == NULL )
994993{
995994int errno_tmp = errno ;
@@ -1265,15 +1264,15 @@ bool
12651264check_file_pages (pgFile * file ,XLogRecPtr stop_lsn ,uint32 checksum_version ,
12661265uint32 backup_version )
12671266{
1268- size_t read_len = 0 ;
1267+ ssize_t read_len = 0 ;
12691268bool is_valid = true;
12701269FILE * in ;
12711270pg_crc32 crc ;
12721271bool use_crc32c = backup_version <=20021 || backup_version >=20025 ;
12731272
12741273elog (VERBOSE ,"Validate relation blocks for file %s" ,file -> path );
12751274
1276- in = fopen (file -> path ,PG_BINARY_R );
1275+ in = fio_fopen (file -> path ,PG_BINARY_R , FIO_BACKUP_HOST , instance_config . encryption );
12771276if (in == NULL )
12781277{
12791278if (errno == ENOENT )
@@ -1301,13 +1300,13 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
13011300elog (ERROR ,"Interrupted during data file validation" );
13021301
13031302/* read BackupPageHeader */
1304- read_len = fread ( & header ,1 , sizeof (header ), in );
1303+ read_len = fio_fread ( in , & header ,sizeof (header ));
13051304if (read_len != sizeof (header ))
13061305{
13071306int errno_tmp = errno ;
1308- if (read_len == 0 && feof ( in ) )
1307+ if (read_len == 0 )
13091308break ;/* EOF found */
1310- else if (read_len != 0 && feof ( in ) )
1309+ else if (read_len > 0 )
13111310elog (WARNING ,
13121311"Odd size page found at block %u of \"%s\"" ,
13131312blknum ,file -> path );
@@ -1343,8 +1342,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
13431342
13441343Assert (header .compressed_size <=BLCKSZ );
13451344
1346- read_len = fread (compressed_page .data ,1 ,
1347- MAXALIGN (header .compressed_size ),in );
1345+ read_len = fio_fread (in ,compressed_page .data ,MAXALIGN (header .compressed_size ));
13481346if (read_len != MAXALIGN (header .compressed_size ))
13491347{
13501348elog (WARNING ,"Cannot read block %u of \"%s\" read %zu of %d" ,
@@ -1395,7 +1393,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
13951393}
13961394
13971395FIN_FILE_CRC32 (use_crc32c ,crc );
1398- fclose (in );
1396+ fio_fclose (in );
13991397
14001398if (crc != file -> crc )
14011399{