Skip to content

Commit 612fa02

Browse files
committed
use lseek, wip
1 parent 101fd93 commit 612fa02

File tree

1 file changed

+13
-1
lines changed
  • src/backend/storage/file

1 file changed

+13
-1
lines changed

src/backend/storage/file/fd.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,20 @@ pg_flush_data(int fd, off_t offset, off_t nbytes)
451451
* We map the file (mmap()), tell the kernel to sync back the contents
452452
* (msync()), and then remove the mapping again (munmap()).
453453
*/
454+
455+
/* mmap() need exact length when we want to map whole file */
456+
if ((offset == 0) && (nbytes == 0))
457+
{
458+
int pagesize = getpagesize();
459+
nbytes = (lseek(fd, offset, SEEK_END)/pagesize + 1)*pagesize;
460+
if (nbytes < 0)
461+
ereport(WARNING,
462+
(errcode_for_file_access(),
463+
errmsg("could not determine dirty data size: %m")));
464+
}
465+
454466
p = mmap(NULL, nbytes,
455-
PROT_READ | PROT_WRITE, MAP_SHARED,
467+
PROT_READ, MAP_SHARED,
456468
fd, offset);
457469
if (p == MAP_FAILED)
458470
{

0 commit comments

Comments
 (0)