From: Chao Li <li.evan.chao@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Cc: Bryan Green <dbryan.green@gmail.com>
Subject: Re: Switch buffile.c/h to use pgoff_t
Date: Fri, 19 Dec 2025 11:00:54 +0800
Message-ID: <85F6E9BB-59E8-4BD5-9FC1-357C3ACD5F87@gmail.com> (raw)
In-Reply-To: <aUStrqoOCDRFAq1M@paquier.xyz>
References: <aUStrqoOCDRFAq1M@paquier.xyz>
> On Dec 19, 2025, at 09:43, Michael Paquier <michael@paquier.xyz> wrote:
>
> Hi all,
> (Added Bryan in CC as he has been looking at this stuff previously.)
>
> An mentioned on this thread and as a part of the quest to remove more
> of long in the tree, buffile.c and buffile.h still rely on an
> unportable off_t, which is signed 4 bytes on Windows:
> https://www.postgresql.org/message-id/0f238ff4-c442-42f5-adb8-01b762c94ca1@gmail.com
>
> Please find attached a patch to do the switch. I was surprised to see
> that the amount of code to adapt was limited, the routines of
> buffile.h changed in this commit being used in other places that keep
> track of offsets. Hence these other files just need to do a off_t =>
> pgoff_t flip in a couple of structures to be updated, as far as I can
> see.
>
> This removes a couple of extra long casts, as well as one comment in
> BufFileSeek() that relates to overflows for large offsets, that would
> not exist with this switch, which is nice.
>
> Thanks,
> --
> Michael
> <0001-Switch-buffile.c-h-to-use-portable-pgoff_t.patch>
```
while (wpos < file->nbytes)
{
- off_t availbytes;
+ pgoff_t availbytes;
instr_time io_start;
instr_time io_time;
@@ -524,7 +524,7 @@ BufFileDumpBuffer(BufFile *file)
bytestowrite = file->nbytes - wpos;
availbytes = MAX_PHYSICAL_FILESIZE - file->curOffset;
- if ((off_t) bytestowrite > availbytes)
+ if ((pgoff_t) bytestowrite > availbytes)
bytestowrite = (int) availbytes;
```
bytestowrite is of type int, loosing it to pgoff_t then compare with availbytes, if bytestowrite > availbytes, then availbytes must be within the range of int, so the next assignment “bytestowrite = (int) availbytes” is safe, but makes reading difficult.
Given MAX_PHYSICAL_FILESIZE is just 1G (2^30), why availbytes has to be pgoff_t instead of just int?
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: li.evan.chao@gmail.com, michael@paquier.xyz, dbryan.green@gmail.com
Subject: Re: Switch buffile.c/h to use pgoff_t
In-Reply-To: <85F6E9BB-59E8-4BD5-9FC1-357C3ACD5F87@gmail.com>
References: <aUStrqoOCDRFAq1M@paquier.xyz> <85F6E9BB-59E8-4BD5-9FC1-357C3ACD5F87@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox