From 4cec483efea42b72f7a44cc897567da346be854b Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Tue, 27 Feb 2024 21:40:42 +1300 Subject: [PATCH 1/2] Return ssize_t in fd.c I/O functions. Traditionally we used types based on traditional Unix read/write functions from before C and POSIX standardization, though not exactly (we had int for amount instead of unsigned). In commit 2d4f1ba6 we switched the argument types to the appropriate standard C types, making them like the POSIX functions they wrap, but again not exactly: the return type stayed as int. That wasn't really a live bug, because we don't expect PostgreSQL code to perform reads or writes of gigabytes and overflow an int, and OSes probably apply internal caps smaller than that anyway. This change is done on the principle that the return might as well follow the standard interfaces consistently. Reported-by: Tom Lane Discussion: https://postgr.es/m/1672202.1703441340%40sss.pgh.pa.us --- src/backend/storage/file/fd.c | 8 ++++---- src/include/storage/fd.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index d298e4842c..8c8e81f899 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -2132,11 +2132,11 @@ FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info) pgstat_report_wait_end(); } -int +ssize_t FileReadV(File file, const struct iovec *iov, int iovcnt, off_t offset, uint32 wait_event_info) { - int returnCode; + ssize_t returnCode; Vfd *vfdP; Assert(FileIsValid(file)); @@ -2188,11 +2188,11 @@ retry: return returnCode; } -int +ssize_t FileWriteV(File file, const struct iovec *iov, int iovcnt, off_t offset, uint32 wait_event_info) { - int returnCode; + ssize_t returnCode; Vfd *vfdP; Assert(FileIsValid(file)); diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h index 60bba5c970..a173174db9 100644 --- a/src/include/storage/fd.h +++ b/src/include/storage/fd.h @@ -107,8 +107,8 @@ extern File PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fil extern File OpenTemporaryFile(bool interXact); extern void FileClose(File file); extern int FilePrefetch(File file, off_t offset, off_t amount, uint32 wait_event_info); -extern int FileReadV(File file, const struct iovec *ioc, int iovcnt, off_t offset, uint32 wait_event_info); -extern int FileWriteV(File file, const struct iovec *ioc, int iovcnt, off_t offset, uint32 wait_event_info); +extern ssize_t FileReadV(File file, const struct iovec *ioc, int iovcnt, off_t offset, uint32 wait_event_info); +extern ssize_t FileWriteV(File file, const struct iovec *ioc, int iovcnt, off_t offset, uint32 wait_event_info); extern int FileSync(File file, uint32 wait_event_info); extern int FileZero(File file, off_t offset, off_t amount, uint32 wait_event_info); extern int FileFallocate(File file, off_t offset, off_t amount, uint32 wait_event_info); @@ -192,7 +192,7 @@ extern int durable_unlink(const char *fname, int elevel); extern void SyncDataDirectory(void); extern int data_sync_elevel(int elevel); -static inline int +static inline ssize_t FileRead(File file, void *buffer, size_t amount, off_t offset, uint32 wait_event_info) { @@ -204,7 +204,7 @@ FileRead(File file, void *buffer, size_t amount, off_t offset, return FileReadV(file, &iov, 1, offset, wait_event_info); } -static inline int +static inline ssize_t FileWrite(File file, const void *buffer, size_t amount, off_t offset, uint32 wait_event_info) { -- 2.39.3 (Apple Git-145)