@@ -1030,7 +1030,7 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
10301030 * go to the next page.
10311031 */
10321032if (!headers && fseek (in ,read_len ,SEEK_CUR )!= 0 )
1033- elog (ERROR ,"Cannot seek block %u of'%s' : %s" ,
1033+ elog (ERROR ,"Cannot seek block %u of\"%s\" : %s" ,
10341034blknum ,from_fullpath ,strerror (errno ));
10351035continue ;
10361036}
@@ -1039,7 +1039,7 @@ restore_data_file_internal(FILE *in, FILE *out, pgFile *file, uint32 backup_vers
10391039cur_pos_in != headers [n_hdr ].pos )
10401040{
10411041if (fseek (in ,headers [n_hdr ].pos ,SEEK_SET )!= 0 )
1042- elog (ERROR ,"Cannot seek to offset %u of'%s' : %s" ,
1042+ elog (ERROR ,"Cannot seek to offset %u of\"%s\" : %s" ,
10431043headers [n_hdr ].pos ,from_fullpath ,strerror (errno ));
10441044
10451045cur_pos_in = headers [n_hdr ].pos ;
@@ -1802,6 +1802,7 @@ get_checksum_map(const char *fullpath, uint32 checksum_version,
18021802BlockNumber blknum = 0 ;
18031803char read_buffer [BLCKSZ ];
18041804char in_buf [STDIO_BUFSIZE ];
1805+ off_t cur_pos = 0 ;
18051806
18061807/* open file */
18071808in = fopen (fullpath ,"r+" );
@@ -1819,16 +1820,32 @@ get_checksum_map(const char *fullpath, uint32 checksum_version,
18191820checksum_map = pgut_malloc (n_blocks * sizeof (PageState ));
18201821memset (checksum_map ,0 ,n_blocks * sizeof (PageState ));
18211822
1822- for (blknum = 0 ; blknum < n_blocks ; blknum ++ )
1823+ for (;; )
18231824{
1824- size_t read_len = fread (read_buffer ,1 ,BLCKSZ ,in );
18251825PageState page_st ;
1826+ size_t read_len = 0 ;
1827+
1828+ if (blknum >=n_blocks )
1829+ break ;
1830+
1831+ if (cur_pos != blknum * BLCKSZ &&
1832+ fseek (in ,blknum * BLCKSZ ,SEEK_SET ))
1833+ {
1834+ elog (ERROR ,"Cannot seek to offset %u in file \"%s\": %s" ,
1835+ blknum * BLCKSZ ,fullpath ,strerror (errno ));
1836+ }
1837+
1838+ read_len = fread (read_buffer ,1 ,BLCKSZ ,in );
1839+ cur_pos += read_len ;
18261840
18271841/* report error */
18281842if (ferror (in ))
18291843elog (ERROR ,"Cannot read block %u of \"%s\": %s" ,
18301844blknum ,fullpath ,strerror (errno ));
18311845
1846+ if (read_len == 0 && feof (in ))
1847+ break ;
1848+
18321849if (read_len == BLCKSZ )
18331850{
18341851int rc = validate_one_page (read_buffer ,segmentno + blknum ,
@@ -1844,12 +1861,11 @@ get_checksum_map(const char *fullpath, uint32 checksum_version,
18441861
18451862checksum_map [blknum ].lsn = page_st .lsn ;
18461863}
1864+
1865+ blknum ++ ;
18471866}
18481867else
1849- elog (ERROR ,"Failed to read blknum %u from file \"%s\"" ,blknum ,fullpath );
1850-
1851- if (feof (in ))
1852- break ;
1868+ elog (WARNING ,"Odd size read len %lu for blknum %u in file \"%s\"" ,read_len ,blknum ,fullpath );
18531869
18541870if (interrupted )
18551871elog (ERROR ,"Interrupted during page reading" );