134{
135 char *buffer;
136 int srcfd;
138 int nbytes;
139 off_t offset;
140 off_t flush_offset;
141
142
143#define COPY_BUF_SIZE (8 * BLCKSZ)
144
145
146
147
148
149
150
151#if defined(__darwin__)
152#define FLUSH_DISTANCE (32 * 1024 * 1024)
153#else
154#define FLUSH_DISTANCE (1024 * 1024)
155#endif
156
157
159
160
161
162
164 if (srcfd < 0)
167 errmsg(
"could not open file \"%s\": %m", fromfile)));
168
173 errmsg(
"could not create file \"%s\": %m", tofile)));
174
175
176
177
178 flush_offset = 0;
179 for (offset = 0;; offset += nbytes)
180 {
181
183
184
185
186
187
188
190 {
192 flush_offset = offset;
193 }
194
198 if (nbytes < 0)
201 errmsg(
"could not read file \"%s\": %m", fromfile)));
202 if (nbytes == 0)
203 break;
204 errno = 0;
206 if ((
int)
write(
dstfd, buffer, nbytes) != nbytes)
207 {
208
209 if (errno == 0)
210 errno = ENOSPC;
213 errmsg(
"could not write to file \"%s\": %m", tofile)));
214 }
216 }
217
218 if (offset > flush_offset)
220
224 errmsg(
"could not close file \"%s\": %m", tofile)));
225
229 errmsg(
"could not close file \"%s\": %m", fromfile)));
230
232}
int errcode_for_file_access(void)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void pg_flush_data(int fd, off_t offset, off_t nbytes)
int CloseTransientFile(int fd)
int OpenTransientFile(const char *fileName, int fileFlags)
void pfree(void *pointer)
#define CHECK_FOR_INTERRUPTS()
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)