Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vWQkL-000yfz-2b for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Dec 2025 03:01:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vWQkK-005YgJ-1M for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Dec 2025 03:01:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vWQkK-005Yg3-0R for pgsql-hackers@lists.postgresql.org; Fri, 19 Dec 2025 03:01:36 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vWQkG-001WbQ-1m for pgsql-hackers@lists.postgresql.org; Fri, 19 Dec 2025 03:01:36 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2a0d6f647e2so20431745ad.1 for ; Thu, 18 Dec 2025 19:01:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766113290; x=1766718090; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=b4FvzPODxFIT4hj2Mtpq2OIL2etlcgch2cqlXqFrJJw=; b=PlVSg7EnTDW0vAZ0zNXLPFySziSiR1jWTruJyX0rZmdOwhz1g0x18cnn468+RhYGT8 524BBRzZ8/Ohy5Lm4tv+dOzGctnQBhVu80KNWHC/xBA2TlTpFQSF1suC+1g6oHAE+Kgt AwNxwgc76AEDv9oFx57FGJrSf+fwip3Akray+qDbtlN7XdSR43tbPTlecr3er3A0VLZs sUx3aD6AwnZ7RkvV/cFE94GJHLri4mdbLc7D0SkGF23mJk2CN2voJEFOZiPQWaRhSeF5 ZKZUJLSdXG5bnNf+FMEkEuu6l5vkQErk00cgoh1iAXB0xRQI1ghaXr/Ffzcg3+M5yVnH 1Y2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766113290; x=1766718090; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=b4FvzPODxFIT4hj2Mtpq2OIL2etlcgch2cqlXqFrJJw=; b=YpPoVduXU7ecY9nNRopWQ/ez2UdogilMXEB8bvPHWZk0TNAdk55vbJ2rbCaIol5END yn2YywhtqFj6Kclrww7R9f29VI0/LV28OIzNk00SU9rlM9A1oVp4FmAScea6AMbMv6zR Fum/uQkQ9sgS4u1W1VNjIIH9153uZw4YFamOG3NFhDOsB1sOmKg8LVn02M6bB8/CpkAh DXiK/bNvg/LJdrdK7FcJhXYCOkSKLe5NFPOUkO3wrilx1rw+s/fodlDenX/wSapDo2Tn hd+9yfcvrxXZElX1TbRDW57XsVrd79VKopGLqIi4wGSIhflR4z9zAMY5qujglJYIIGgd IV7A== X-Gm-Message-State: AOJu0Yym4h488zUZB6yeBkQEVjy/9cc6HXzmlYpKYhZn/CW4Dba96eEb QM84FMnbfmtCBoke8jS/tbF/gmam0terR3xe5mhnnYjOt86gJcmcOC51 X-Gm-Gg: AY/fxX5+9FFIULY2cDY/FYyoAURs/Ja/zgv9X64hM2SRB620k6ER/iUIpHrzHc9wgaD s57G6GLdSUF7x6DBBOW04dZrU7comjsWc+jpg97lADZdm9n6zhUjmSpgI0hBHUKwjNKZft036jI VZS48SMayiMSp7L4mbN8p5k1pMNXYzwzMIRv7JCbJ1nkQ8Egam00Dvr5sUuIJUL20R1JFJCl+fU ndGuJETROMgyJ7nFuK9bUDZEpiaoCjZ3tivL9AI1B1HLZfJq5C0JhhR4KYB3UtfcjjJhX5XfZXK 80xVeHj9gCJpm/THCAfF7TAoZmVHQeAgeCbkvoZkzxYnmCkPlJij74Mp0aSkcNsAu5LLrRoSGb/ HSUiZ81MhWHQv+cRjK1LJExUV6rU7DxpbHHVw6GbrxnP5NXhcRNyN8XL5DgV3a7f8C+vC+c4LKD qdbHdjhAWftTR4+kNpv0JJ X-Google-Smtp-Source: AGHT+IEEQPrW1XEyJW87Bg/c0jTCBLasGudJukPJxCg3Td6V213HwJqAN/twf0CMD18nyYzjV5JWrw== X-Received: by 2002:a05:7022:3a83:b0:11c:b397:2657 with SMTP id a92af1059eb24-121722be81emr1645482c88.22.1766113290296; Thu, 18 Dec 2025 19:01:30 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1217254c734sm3588389c88.13.2025.12.18.19.01.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Dec 2025 19:01:29 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Switch buffile.c/h to use pgoff_t From: Chao Li In-Reply-To: Date: Fri, 19 Dec 2025 11:00:54 +0800 Cc: Postgres hackers , Bryan Green Content-Transfer-Encoding: quoted-printable Message-Id: <85F6E9BB-59E8-4BD5-9FC1-357C3ACD5F87@gmail.com> References: To: Michael Paquier X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Dec 19, 2025, at 09:43, Michael Paquier = wrote: >=20 > Hi all, > (Added Bryan in CC as he has been looking at this stuff previously.) >=20 > 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 >=20 > 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 =3D> > pgoff_t flip in a couple of structures to be updated, as far as I can > see. >=20 > 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. >=20 > 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; =20 @@ -524,7 +524,7 @@ BufFileDumpBuffer(BufFile *file) bytestowrite =3D file->nbytes - wpos; availbytes =3D MAX_PHYSICAL_FILESIZE - file->curOffset; =20 - if ((off_t) bytestowrite > availbytes) + if ((pgoff_t) bytestowrite > availbytes) bytestowrite =3D (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 =E2=80=9Cbytestowrite =3D (int) = availbytes=E2=80=9D 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/