0003-Support-large-files-on-Windows-in-our-VFD-API.patch
text/x-patch
Filename: 0003-Support-large-files-on-Windows-in-our-VFD-API.patch
Type: text/x-patch
Part: 2
Message:
Large files for relations
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0003
Subject: Support large files on Windows in our VFD API.
| File | + | − |
|---|---|---|
| src/backend/storage/file/fd.c | 15 | 15 |
| src/include/storage/fd.h | 10 | 10 |
From 2782d8c1b5c6ff266488536c49cb3a4d4a7b4da6 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Sun, 5 Mar 2023 11:27:16 +1300
Subject: [PATCH 03/11] Support large files on Windows in our VFD API.
All fd.c interfaces that take off_t now need to use pgoff_t instead,
because we can't use Windows' 32 bit off_t.
---
src/backend/storage/file/fd.c | 30 +++++++++++++++---------------
src/include/storage/fd.h | 20 ++++++++++----------
2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 053588a302..f5e194a797 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -204,7 +204,7 @@ typedef struct vfd
File nextFree; /* link to next free VFD, if in freelist */
File lruMoreRecently; /* doubly linked recency-of-use list */
File lruLessRecently;
- off_t fileSize; /* current size of file (0 if not temporary) */
+ pgoff_t fileSize; /* current size of file (0 if not temporary) */
char *fileName; /* name of file, or NULL for unused VFD */
/* NB: fileName is malloc'd, and must be free'd when closing the VFD */
int fileFlags; /* open(2) flags for (re)opening the file */
@@ -463,7 +463,7 @@ pg_fdatasync(int fd)
* offset of 0 with nbytes 0 means that the entire file should be flushed
*/
void
-pg_flush_data(int fd, off_t offset, off_t nbytes)
+pg_flush_data(int fd, pgoff_t offset, pgoff_t nbytes)
{
/*
* Right now file flushing is primarily used to avoid making later
@@ -636,7 +636,7 @@ pg_flush_data(int fd, off_t offset, off_t nbytes)
* Truncate a file to a given length by name.
*/
int
-pg_truncate(const char *path, off_t length)
+pg_truncate(const char *path, pgoff_t length)
{
#ifdef WIN32
int save_errno;
@@ -1439,7 +1439,7 @@ FileAccess(File file)
* Called whenever a temporary file is deleted to report its size.
*/
static void
-ReportTemporaryFileUsage(const char *path, off_t size)
+ReportTemporaryFileUsage(const char *path, pgoff_t size)
{
pgstat_report_tempfile(size);
@@ -1989,7 +1989,7 @@ FileClose(File file)
* to read into.
*/
int
-FilePrefetch(File file, off_t offset, off_t amount, uint32 wait_event_info)
+FilePrefetch(File file, pgoff_t offset, pgoff_t amount, uint32 wait_event_info)
{
#if defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
int returnCode;
@@ -2017,7 +2017,7 @@ FilePrefetch(File file, off_t offset, off_t amount, uint32 wait_event_info)
}
void
-FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info)
+FileWriteback(File file, pgoff_t offset, pgoff_t nbytes, uint32 wait_event_info)
{
int returnCode;
@@ -2043,7 +2043,7 @@ FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info)
}
int
-FileRead(File file, void *buffer, size_t amount, off_t offset,
+FileRead(File file, void *buffer, size_t amount, pgoff_t offset,
uint32 wait_event_info)
{
int returnCode;
@@ -2099,7 +2099,7 @@ retry:
}
int
-FileWrite(File file, const void *buffer, size_t amount, off_t offset,
+FileWrite(File file, const void *buffer, size_t amount, pgoff_t offset,
uint32 wait_event_info)
{
int returnCode;
@@ -2128,7 +2128,7 @@ FileWrite(File file, const void *buffer, size_t amount, off_t offset,
*/
if (temp_file_limit >= 0 && (vfdP->fdstate & FD_TEMP_FILE_LIMIT))
{
- off_t past_write = offset + amount;
+ pgoff_t past_write = offset + amount;
if (past_write > vfdP->fileSize)
{
@@ -2160,7 +2160,7 @@ retry:
*/
if (vfdP->fdstate & FD_TEMP_FILE_LIMIT)
{
- off_t past_write = offset + amount;
+ pgoff_t past_write = offset + amount;
if (past_write > vfdP->fileSize)
{
@@ -2224,7 +2224,7 @@ FileSync(File file, uint32 wait_event_info)
* appropriate error.
*/
int
-FileZero(File file, off_t offset, off_t amount, uint32 wait_event_info)
+FileZero(File file, pgoff_t offset, pgoff_t amount, uint32 wait_event_info)
{
int returnCode;
ssize_t written;
@@ -2269,7 +2269,7 @@ FileZero(File file, off_t offset, off_t amount, uint32 wait_event_info)
* appropriate error.
*/
int
-FileFallocate(File file, off_t offset, off_t amount, uint32 wait_event_info)
+FileFallocate(File file, pgoff_t offset, pgoff_t amount, uint32 wait_event_info)
{
#ifdef HAVE_POSIX_FALLOCATE
int returnCode;
@@ -2305,7 +2305,7 @@ FileFallocate(File file, off_t offset, off_t amount, uint32 wait_event_info)
return FileZero(file, offset, amount, wait_event_info);
}
-off_t
+pgoff_t
FileSize(File file)
{
Assert(FileIsValid(file));
@@ -2316,14 +2316,14 @@ FileSize(File file)
if (FileIsNotOpen(file))
{
if (FileAccess(file) < 0)
- return (off_t) -1;
+ return (pgoff_t) -1;
}
return lseek(VfdCache[file].fd, 0, SEEK_END);
}
int
-FileTruncate(File file, off_t offset, uint32 wait_event_info)
+FileTruncate(File file, pgoff_t offset, uint32 wait_event_info)
{
int returnCode;
diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h
index 6791a406fc..a4528428ff 100644
--- a/src/include/storage/fd.h
+++ b/src/include/storage/fd.h
@@ -110,16 +110,16 @@ extern File PathNameOpenFile(const char *fileName, int fileFlags);
extern File PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
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 FileRead(File file, void *buffer, size_t amount, off_t offset, uint32 wait_event_info);
-extern int FileWrite(File file, const void *buffer, size_t amount, off_t offset, uint32 wait_event_info);
+extern int FilePrefetch(File file, pgoff_t offset, pgoff_t amount, uint32 wait_event_info);
+extern int FileRead(File file, void *buffer, size_t amount, pgoff_t offset, uint32 wait_event_info);
+extern int FileWrite(File file, const void *buffer, size_t amount, pgoff_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);
+extern int FileZero(File file, pgoff_t offset, pgoff_t amount, uint32 wait_event_info);
+extern int FileFallocate(File file, pgoff_t offset, pgoff_t amount, uint32 wait_event_info);
-extern off_t FileSize(File file);
-extern int FileTruncate(File file, off_t offset, uint32 wait_event_info);
-extern void FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info);
+extern pgoff_t FileSize(File file);
+extern int FileTruncate(File file, pgoff_t offset, uint32 wait_event_info);
+extern void FileWriteback(File file, pgoff_t offset, pgoff_t nbytes, uint32 wait_event_info);
extern char *FilePathName(File file);
extern int FileGetRawDesc(File file);
extern int FileGetRawFlags(File file);
@@ -186,8 +186,8 @@ extern int pg_fsync(int fd);
extern int pg_fsync_no_writethrough(int fd);
extern int pg_fsync_writethrough(int fd);
extern int pg_fdatasync(int fd);
-extern void pg_flush_data(int fd, off_t offset, off_t nbytes);
-extern int pg_truncate(const char *path, off_t length);
+extern void pg_flush_data(int fd, pgoff_t offset, pgoff_t nbytes);
+extern int pg_truncate(const char *path, pgoff_t length);
extern void fsync_fname(const char *fname, bool isdir);
extern int fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel);
extern int durable_rename(const char *oldfile, const char *newfile, int elevel);
--
2.40.1