aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-10-19 02:34:45 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-10-19 02:34:45 +0000
commit42b991fd1f951374fb37bd1b9844faf16c74a38e (patch)
tree6bef7e7123660b8d5cf96ca83deb3f2262910658 /src
parentd357c96789f1df4b885a555ae88d192deb15cd95 (diff)
downloadpostgresql-42b991fd1f951374fb37bd1b9844faf16c74a38e.tar.gz
postgresql-42b991fd1f951374fb37bd1b9844faf16c74a38e.zip
BufFileSeek's behavior at segment boundaries wasn't what
logfile.c wanted ... seems easier to fix BufFileSeek.
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/file/buffile.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index 452e3a187df..2dafe08c5d9 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -6,7 +6,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/file/buffile.c,v 1.2 1999/10/16 19:49:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/file/buffile.c,v 1.3 1999/10/19 02:34:45 tgl Exp $
*
* NOTES:
*
@@ -434,8 +434,7 @@ BufFileSeek(BufFile *file, int fileno, long offset, int whence)
switch (whence)
{
case SEEK_SET:
- if (fileno < 0 || fileno >= file->numFiles ||
- offset < 0)
+ if (fileno < 0)
return EOF;
newFile = fileno;
newOffset = offset;
@@ -443,7 +442,7 @@ BufFileSeek(BufFile *file, int fileno, long offset, int whence)
case SEEK_CUR:
/*
* Relative seek considers only the signed offset, ignoring fileno.
- * Note that large offsets (> 1 gig) risk overflow.
+ * Note that large offsets (> 1 gig) risk overflow in this add...
*/
newFile = file->curFile;
newOffset = (file->curOffset + file->pos) + offset;
@@ -463,15 +462,6 @@ BufFileSeek(BufFile *file, int fileno, long offset, int whence)
return EOF;
newOffset += MAX_PHYSICAL_FILESIZE;
}
- if (file->isTemp)
- {
- while (newOffset > MAX_PHYSICAL_FILESIZE)
- {
- if (++newFile >= file->numFiles)
- return EOF;
- newOffset -= MAX_PHYSICAL_FILESIZE;
- }
- }
if (newFile == file->curFile &&
newOffset >= file->curOffset &&
newOffset <= file->curOffset + file->nbytes)
@@ -488,6 +478,29 @@ BufFileSeek(BufFile *file, int fileno, long offset, int whence)
/* Otherwise, must reposition buffer, so flush any dirty data */
if (BufFileFlush(file) != 0)
return EOF;
+ /*
+ * At this point and no sooner, check for seek past last segment.
+ * The above flush could have created a new segment, so
+ * checking sooner would not work (at least not with this code).
+ */
+ if (file->isTemp)
+ {
+ /* convert seek to "start of next seg" to "end of last seg" */
+ if (newFile == file->numFiles && newOffset == 0)
+ {
+ newFile--;
+ newOffset = MAX_PHYSICAL_FILESIZE;
+ }
+ while (newOffset > MAX_PHYSICAL_FILESIZE)
+ {
+ if (++newFile >= file->numFiles)
+ return EOF;
+ newOffset -= MAX_PHYSICAL_FILESIZE;
+ }
+ }
+ if (newFile >= file->numFiles)
+ return EOF;
+ /* Seek is OK! */
file->curFile = newFile;
file->curOffset = newOffset;
file->pos = 0;