@@ -501,15 +501,19 @@ tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
501501state -> writepos_file ,
502502state -> writepos_offset ,
503503SEEK_SET )!= 0 )
504- elog (ERROR ,"tuplestore seek failed" );
504+ ereport (ERROR ,
505+ (errcode_for_file_access (),
506+ errmsg ("could not seek in tuplestore temporary file: %m" )));
505507}
506508else
507509{
508510if (BufFileSeek (state -> myfile ,
509511readptr -> file ,
510512readptr -> offset ,
511513SEEK_SET )!= 0 )
512- elog (ERROR ,"tuplestore seek failed" );
514+ ereport (ERROR ,
515+ (errcode_for_file_access (),
516+ errmsg ("could not seek in tuplestore temporary file: %m" )));
513517}
514518break ;
515519default :
@@ -834,7 +838,9 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
834838if (BufFileSeek (state -> myfile ,
835839state -> writepos_file ,state -> writepos_offset ,
836840SEEK_SET )!= 0 )
837- elog (ERROR ,"tuplestore seek to EOF failed" );
841+ ereport (ERROR ,
842+ (errcode_for_file_access (),
843+ errmsg ("could not seek in tuplestore temporary file: %m" )));
838844state -> status = TSS_WRITEFILE ;
839845
840846/*
@@ -936,7 +942,9 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
936942if (BufFileSeek (state -> myfile ,
937943readptr -> file ,readptr -> offset ,
938944SEEK_SET )!= 0 )
939- elog (ERROR ,"tuplestore seek failed" );
945+ ereport (ERROR ,
946+ (errcode_for_file_access (),
947+ errmsg ("could not seek in tuplestore temporary file: %m" )));
940948state -> status = TSS_READFILE ;
941949/* FALL THRU into READFILE case */
942950
@@ -998,7 +1006,9 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
9981006if (BufFileSeek (state -> myfile ,0 ,
9991007- (long ) (tuplen + sizeof (unsignedint )),
10001008SEEK_CUR )!= 0 )
1001- elog (ERROR ,"bogus tuple length in backward scan" );
1009+ ereport (ERROR ,
1010+ (errcode_for_file_access (),
1011+ errmsg ("could not seek in tuplestore temporary file: %m" )));
10021012Assert (!state -> truncated );
10031013return NULL ;
10041014}
@@ -1013,7 +1023,9 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
10131023if (BufFileSeek (state -> myfile ,0 ,
10141024- (long )tuplen ,
10151025SEEK_CUR )!= 0 )
1016- elog (ERROR ,"bogus tuple length in backward scan" );
1026+ ereport (ERROR ,
1027+ (errcode_for_file_access (),
1028+ errmsg ("could not seek in tuplestore temporary file: %m" )));
10171029tup = READTUP (state ,tuplen );
10181030return tup ;
10191031
@@ -1213,7 +1225,9 @@ tuplestore_rescan(Tuplestorestate *state)
12131225case TSS_READFILE :
12141226readptr -> eof_reached = false;
12151227if (BufFileSeek (state -> myfile ,0 ,0L ,SEEK_SET )!= 0 )
1216- elog (ERROR ,"tuplestore seek to start failed" );
1228+ ereport (ERROR ,
1229+ (errcode_for_file_access (),
1230+ errmsg ("could not seek in tuplestore temporary file: %m" )));
12171231break ;
12181232default :
12191233elog (ERROR ,"invalid tuplestore state" );
@@ -1276,14 +1290,18 @@ tuplestore_copy_read_pointer(Tuplestorestate *state,
12761290state -> writepos_file ,
12771291state -> writepos_offset ,
12781292SEEK_SET )!= 0 )
1279- elog (ERROR ,"tuplestore seek failed" );
1293+ ereport (ERROR ,
1294+ (errcode_for_file_access (),
1295+ errmsg ("could not seek in tuplestore temporary file: %m" )));
12801296}
12811297else
12821298{
12831299if (BufFileSeek (state -> myfile ,
12841300dptr -> file ,dptr -> offset ,
12851301SEEK_SET )!= 0 )
1286- elog (ERROR ,"tuplestore seek failed" );
1302+ ereport (ERROR ,
1303+ (errcode_for_file_access (),
1304+ errmsg ("could not seek in tuplestore temporary file: %m" )));
12871305}
12881306}
12891307else if (srcptr == state -> activeptr )
@@ -1427,10 +1445,10 @@ getlen(Tuplestorestate *state, bool eofOK)
14271445nbytes = BufFileRead (state -> myfile , (void * )& len ,sizeof (len ));
14281446if (nbytes == sizeof (len ))
14291447return len ;
1430- if (nbytes != 0 )
1431- elog (ERROR ,"unexpected end of tape" );
1432- if (! eofOK )
1433- elog ( ERROR , "unexpected end of data" );
1448+ if (nbytes != 0 || ! eofOK )
1449+ ereport (ERROR ,
1450+ ( errcode_for_file_access (),
1451+ errmsg ( "could not read from tuplestore temporary file: %m" )) );
14341452return 0 ;
14351453}
14361454
@@ -1469,14 +1487,20 @@ writetup_heap(Tuplestorestate *state, void *tup)
14691487
14701488if (BufFileWrite (state -> myfile , (void * )& tuplen ,
14711489sizeof (tuplen ))!= sizeof (tuplen ))
1472- elog (ERROR ,"write failed" );
1490+ ereport (ERROR ,
1491+ (errcode_for_file_access (),
1492+ errmsg ("could not write to tuplestore temporary file: %m" )));
14731493if (BufFileWrite (state -> myfile , (void * )tupbody ,
14741494tupbodylen )!= (size_t )tupbodylen )
1475- elog (ERROR ,"write failed" );
1495+ ereport (ERROR ,
1496+ (errcode_for_file_access (),
1497+ errmsg ("could not write to tuplestore temporary file: %m" )));
14761498if (state -> backward )/* need trailing length word? */
14771499if (BufFileWrite (state -> myfile , (void * )& tuplen ,
14781500sizeof (tuplen ))!= sizeof (tuplen ))
1479- elog (ERROR ,"write failed" );
1501+ ereport (ERROR ,
1502+ (errcode_for_file_access (),
1503+ errmsg ("could not write to tuplestore temporary file: %m" )));
14801504
14811505FREEMEM (state ,GetMemoryChunkSpace (tuple ));
14821506heap_free_minimal_tuple (tuple );
@@ -1495,10 +1519,14 @@ readtup_heap(Tuplestorestate *state, unsigned int len)
14951519tuple -> t_len = tuplen ;
14961520if (BufFileRead (state -> myfile , (void * )tupbody ,
14971521tupbodylen )!= (size_t )tupbodylen )
1498- elog (ERROR ,"unexpected end of data" );
1522+ ereport (ERROR ,
1523+ (errcode_for_file_access (),
1524+ errmsg ("could not read from tuplestore temporary file: %m" )));
14991525if (state -> backward )/* need trailing length word? */
15001526if (BufFileRead (state -> myfile , (void * )& tuplen ,
15011527sizeof (tuplen ))!= sizeof (tuplen ))
1502- elog (ERROR ,"unexpected end of data" );
1528+ ereport (ERROR ,
1529+ (errcode_for_file_access (),
1530+ errmsg ("could not read from tuplestore temporary file: %m" )));
15031531return (void * )tuple ;
15041532}