@@ -548,7 +548,15 @@ int fio_pread(FILE* f, void* buf, off_t offs)
548548 return hdr .arg ;
549549 }
550550 else
551- return pread (fileno (f ), buf , BLCKSZ , offs );
551+ {
552+ int rc ;
553+ rc = fseek (f , offs , SEEK_SET );
554+
555+ if (rc < 0 )
556+ return rc ;
557+
558+ return fread (buf , 1 , BLCKSZ , f );
559+ }
552560}
553561
554562/* Set position in stdio file */
@@ -898,6 +906,28 @@ int fio_sync(char const* path, fio_location location)
898906 }
899907}
900908
909+ /* Get crc32 of file */
910+ pg_crc32 fio_get_crc32 (const char * file_path , fio_location location )
911+ {
912+ if (fio_is_remote (location ))
913+ {
914+ fio_header hdr ;
915+ size_t path_len = strlen (file_path ) + 1 ;
916+ pg_crc32 crc = 0 ;
917+ hdr .cop = FIO_GET_CRC32 ;
918+ hdr .handle = -1 ;
919+ hdr .size = path_len ;
920+
921+ IO_CHECK (fio_write_all (fio_stdout , & hdr , sizeof (hdr )), sizeof (hdr ));
922+ IO_CHECK (fio_write_all (fio_stdout , file_path , path_len ), path_len );
923+ IO_CHECK (fio_read_all (fio_stdin , & crc , sizeof (crc )), sizeof (crc ));
924+
925+ return crc ;
926+ }
927+ else
928+ return pgFileGetCRCnew (file_path , true, true);
929+ }
930+
901931/* Remove file */
902932int fio_unlink (char const * path , fio_location location )
903933{
@@ -1403,7 +1433,11 @@ static void fio_send_pages_impl(int fd, int out, fio_send_request* req)
14031433 return ;
14041434 }
14051435 }
1406- /* horizonLsn is not 0 for delta backup. As far as unsigned number are always greater or equal than zero, there is no sense to add more checks */
1436+ /*
1437+ * horizonLsn is not 0 for delta backup.
1438+ * As far as unsigned number are always greater or equal than zero,
1439+ * there is no sense to add more checks.
1440+ */
14071441 if (page_lsn >= req -> horizonLsn || page_lsn == InvalidXLogRecPtr )
14081442 {
14091443 char write_buffer [BLCKSZ * 2 ];
@@ -1450,6 +1484,7 @@ void fio_communicate(int in, int out)
14501484 struct stat st ;
14511485 int rc ;
14521486 int tmp_fd ;
1487+ pg_crc32 crc ;
14531488
14541489#ifdef WIN32
14551490 SYS_CHECK (setmode (in , _O_BINARY ));
@@ -1591,6 +1626,11 @@ void fio_communicate(int in, int out)
15911626
15921627 IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
15931628 break ;
1629+ case FIO_GET_CRC32 :
1630+ /* calculate crc32 for a file */
1631+ crc = pgFileGetCRCnew (buf , true, true);
1632+ IO_CHECK (fio_write_all (out , & crc , sizeof (crc )), sizeof (crc ));
1633+ break ;
15941634 default :
15951635 Assert (false);
15961636 }
0 commit comments