@@ -104,7 +104,7 @@ static BufFile *makeBufFile(File firstfile);
104
104
static void extendBufFile (BufFile * file );
105
105
static void BufFileLoadBuffer (BufFile * file );
106
106
static void BufFileDumpBuffer (BufFile * file );
107
- static int BufFileFlush (BufFile * file );
107
+ static void BufFileFlush (BufFile * file );
108
108
static File MakeNewSharedSegment (BufFile * file , int segment );
109
109
110
110
/*
@@ -430,7 +430,10 @@ BufFileLoadBuffer(BufFile *file)
430
430
if (file -> curOffset != file -> offsets [file -> curFile ])
431
431
{
432
432
if (FileSeek (thisfile , file -> curOffset , SEEK_SET ) != file -> curOffset )
433
- return ; /* seek failed, read nothing */
433
+ ereport (ERROR ,
434
+ (errcode_for_file_access (),
435
+ errmsg ("could not seek in file \"%s\": %m" ,
436
+ FilePathName (thisfile ))));
434
437
file -> offsets [file -> curFile ] = file -> curOffset ;
435
438
}
436
439
@@ -442,7 +445,14 @@ BufFileLoadBuffer(BufFile *file)
442
445
sizeof (file -> buffer ),
443
446
WAIT_EVENT_BUFFILE_READ );
444
447
if (file -> nbytes < 0 )
448
+ {
445
449
file -> nbytes = 0 ;
450
+ ereport (ERROR ,
451
+ (errcode_for_file_access (),
452
+ errmsg ("could not read file \"%s\": %m" ,
453
+ FilePathName (thisfile ))));
454
+ }
455
+
446
456
file -> offsets [file -> curFile ] += file -> nbytes ;
447
457
/* we choose not to advance curOffset here */
448
458
@@ -499,15 +509,22 @@ BufFileDumpBuffer(BufFile *file)
499
509
if (file -> curOffset != file -> offsets [file -> curFile ])
500
510
{
501
511
if (FileSeek (thisfile , file -> curOffset , SEEK_SET ) != file -> curOffset )
502
- return ; /* seek failed, give up */
512
+ ereport (ERROR ,
513
+ (errcode_for_file_access (),
514
+ errmsg ("could not seek in file \"%s\": %m" ,
515
+ FilePathName (thisfile ))));
503
516
file -> offsets [file -> curFile ] = file -> curOffset ;
504
517
}
505
518
bytestowrite = FileWrite (thisfile ,
506
519
file -> buffer .data + wpos ,
507
520
bytestowrite ,
508
521
WAIT_EVENT_BUFFILE_WRITE );
509
522
if (bytestowrite <= 0 )
510
- return ; /* failed to write */
523
+ ereport (ERROR ,
524
+ (errcode_for_file_access (),
525
+ errmsg ("could not write to file \"%s\" : %m" ,
526
+ FilePathName (thisfile ))));
527
+
511
528
file -> offsets [file -> curFile ] += bytestowrite ;
512
529
file -> curOffset += bytestowrite ;
513
530
wpos += bytestowrite ;
@@ -540,20 +557,16 @@ BufFileDumpBuffer(BufFile *file)
540
557
/*
541
558
* BufFileRead
542
559
*
543
- * Like fread() except we assume 1-byte element size.
560
+ * Like fread() except we assume 1-byte element size and report I/O errors via
561
+ * ereport().
544
562
*/
545
563
size_t
546
564
BufFileRead (BufFile * file , void * ptr , size_t size )
547
565
{
548
566
size_t nread = 0 ;
549
567
size_t nthistime ;
550
568
551
- if (file -> dirty )
552
- {
553
- if (BufFileFlush (file ) != 0 )
554
- return 0 ; /* could not flush... */
555
- Assert (!file -> dirty );
556
- }
569
+ BufFileFlush (file );
557
570
558
571
while (size > 0 )
559
572
{
@@ -587,7 +600,8 @@ BufFileRead(BufFile *file, void *ptr, size_t size)
587
600
/*
588
601
* BufFileWrite
589
602
*
590
- * Like fwrite() except we assume 1-byte element size.
603
+ * Like fwrite() except we assume 1-byte element size and report errors via
604
+ * ereport().
591
605
*/
592
606
size_t
593
607
BufFileWrite (BufFile * file , void * ptr , size_t size )
@@ -603,11 +617,7 @@ BufFileWrite(BufFile *file, void *ptr, size_t size)
603
617
{
604
618
/* Buffer full, dump it out */
605
619
if (file -> dirty )
606
- {
607
620
BufFileDumpBuffer (file );
608
- if (file -> dirty )
609
- break ; /* I/O error */
610
- }
611
621
else
612
622
{
613
623
/* Hmm, went directly from reading to writing? */
@@ -639,19 +649,15 @@ BufFileWrite(BufFile *file, void *ptr, size_t size)
639
649
/*
640
650
* BufFileFlush
641
651
*
642
- * Like fflush()
652
+ * Like fflush(), except that I/O errors are reported with ereport().
643
653
*/
644
- static int
654
+ static void
645
655
BufFileFlush (BufFile * file )
646
656
{
647
657
if (file -> dirty )
648
- {
649
658
BufFileDumpBuffer (file );
650
- if (file -> dirty )
651
- return EOF ;
652
- }
653
659
654
- return 0 ;
660
+ Assert (! file -> dirty ) ;
655
661
}
656
662
657
663
/*
@@ -660,6 +666,7 @@ BufFileFlush(BufFile *file)
660
666
* Like fseek(), except that target position needs two values in order to
661
667
* work when logical filesize exceeds maximum value representable by off_t.
662
668
* We do not support relative seeks across more than that, however.
669
+ * I/O errors are reported by ereport().
663
670
*
664
671
* Result is 0 if OK, EOF if not. Logical position is not moved if an
665
672
* impossible seek is attempted.
@@ -717,8 +724,7 @@ BufFileSeek(BufFile *file, int fileno, off_t offset, int whence)
717
724
return 0 ;
718
725
}
719
726
/* Otherwise, must reposition buffer, so flush any dirty data */
720
- if (BufFileFlush (file ) != 0 )
721
- return EOF ;
727
+ BufFileFlush (file );
722
728
723
729
/*
724
730
* At this point and no sooner, check for seek past last segment. The
0 commit comments