char *waldata_start;
xl_heap_rewrite_mapping xlrec;
Oid dboid;
- uint32 len;
- int written;
+ size_t len;
+ ssize_t written;
uint32 num_mappings = dclist_count(&src->mappings);
/* this file hasn't got any new mappings */
*/
written = FileWrite(src->vfd, waldata_start, len, src->off,
WAIT_EVENT_LOGICAL_REWRITE_WRITE);
- if (written != len)
+ if (written < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write to file \"%s\", wrote %d of %d: %m", src->path,
+ errmsg("could not write to file \"%s\": %m", src->path)));
+ else if (written != len)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\": wrote %zd of %zu", src->path,
written, len)));
src->off += len;
char path[MAXPGPATH];
int fd;
xl_heap_rewrite_mapping *xlrec;
- uint32 len;
+ size_t len;
char *data;
xlrec = (xl_heap_rewrite_mapping *) XLogRecGetData(r);
* to avoid emplacing a bogus file.
*/
void
-writeTimeLineHistoryFile(TimeLineID tli, const char *content, int size)
+writeTimeLineHistoryFile(TimeLineID tli, const char *content, size_t size)
{
char path[MAXPGPATH];
char tmppath[MAXPGPATH];
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_FILE_WRITE);
- if ((int) write(fd, content, size) != size)
+ if (write(fd, content, size) != size)
{
int save_errno = errno;
const TwoPhaseCallback callbacks[]);
static void RemoveGXact(GlobalTransaction gxact);
-static void XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, int *len);
+static void XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, size_t *len);
static char *ProcessTwoPhaseBuffer(FullTransactionId fxid,
XLogRecPtr prepare_start_lsn,
bool fromdisk, bool setParent, bool setNextXid);
const char *gid, TimestampTz prepared_at, Oid owner,
Oid databaseid);
static void RemoveTwoPhaseFile(FullTransactionId fxid, bool giveWarning);
-static void RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, int len);
+static void RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, size_t len);
/*
* Register shared memory for two-phase state.
* similarly to the way WALSender or Logical Decoding would do.
*/
static void
-XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, int *len)
+XlogReadTwoPhaseData(XLogRecPtr lsn, char **buf, size_t *len)
{
XLogRecord *record;
XLogReaderState *xlogreader;
* Note: content and len don't include CRC.
*/
static void
-RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, int len)
+RecreateTwoPhaseFile(FullTransactionId fxid, const void *content, size_t len)
{
char path[MAXPGPATH];
pg_crc32c statefile_crc;
gxact->prepare_end_lsn <= redo_horizon)
{
char *buf;
- int len;
+ size_t len;
XlogReadTwoPhaseData(gxact->prepare_start_lsn, &buf, &len);
RecreateTwoPhaseFile(gxact->fxid, buf, len);
}
errno = 0;
pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_WRITE);
- if ((int) write(fd, buffer.data, sizeof(buffer)) != (int) sizeof(buffer))
+ if (write(fd, buffer.data, sizeof(buffer)) != sizeof(buffer))
{
int save_errno = errno;
bbsink_server_archive_contents(bbsink *sink, size_t len)
{
bbsink_server *mysink = (bbsink_server *) sink;
- int nbytes;
+ ssize_t nbytes;
nbytes = FileWrite(mysink->file, mysink->base.bbs_buffer, len,
mysink->filepos, WAIT_EVENT_BASEBACKUP_WRITE);
/* short write: complain appropriately */
ereport(ERROR,
(errcode(ERRCODE_DISK_FULL),
- errmsg("could not write file \"%s\": wrote only %d of %zu bytes at offset %lld",
+ errmsg("could not write file \"%s\": wrote only %zd of %zu bytes at offset %lld",
FilePathName(mysink->file),
nbytes, len, (long long) mysink->filepos),
errhint("Check free disk space.")));
bbsink_server_manifest_contents(bbsink *sink, size_t len)
{
bbsink_server *mysink = (bbsink_server *) sink;
- int nbytes;
+ ssize_t nbytes;
nbytes = FileWrite(mysink->file, mysink->base.bbs_buffer, len,
mysink->filepos, WAIT_EVENT_BASEBACKUP_WRITE);
/* short write: complain appropriately */
ereport(ERROR,
(errcode(ERRCODE_DISK_FULL),
- errmsg("could not write file \"%s\": wrote only %d of %zu bytes at offset %lld",
+ errmsg("could not write file \"%s\": wrote only %zd of %zu bytes at offset %lld",
FilePathName(mysink->file),
nbytes, len, (long long) mysink->filepos),
errhint("Check free disk space.")));
CreateDirAndVersionFile(char *dbpath, Oid dbid, Oid tsid, bool isRedo)
{
int fd;
- int nbytes;
+ size_t nbytes;
char versionfile[MAXPGPATH];
char buf[16];
/* Write PG_MAJORVERSION in the PG_VERSION file. */
pgstat_report_wait_start(WAIT_EVENT_VERSION_FILE_WRITE);
errno = 0;
- if ((int) write(fd, buf, nbytes) != nbytes)
+ if (write(fd, buf, nbytes) != nbytes)
{
/* If write didn't set errno, assume problem is no disk space. */
if (errno == 0)
Oid lobjId = PG_GETARG_OID(0);
text *filename = PG_GETARG_TEXT_PP(1);
int fd;
- int nbytes,
- tmp;
+ int nbytes;
char buf[BUFSIZE];
char fnamebuf[MAXPGPATH];
LargeObjectDesc *lobj;
*/
while ((nbytes = inv_read(lobj, buf, BUFSIZE)) > 0)
{
+ ssize_t tmp;
+
tmp = write(fd, buf, nbytes);
if (tmp != nbytes)
ereport(ERROR,
if (fd >= 0)
{
const char *oomvalue = getenv("PG_OOM_ADJUST_VALUE");
- int rc;
+ ssize_t rc;
if (oomvalue == NULL) /* supply a useful default */
oomvalue = "0";
static int libpqrcv_server_version(WalReceiverConn *conn);
static void libpqrcv_readtimelinehistoryfile(WalReceiverConn *conn,
TimeLineID tli, char **filename,
- char **content, int *len);
+ char **content, size_t *len);
static bool libpqrcv_startstreaming(WalReceiverConn *conn,
const WalRcvStreamOptions *options);
static void libpqrcv_endstreaming(WalReceiverConn *conn,
static void
libpqrcv_readtimelinehistoryfile(WalReceiverConn *conn,
TimeLineID tli, char **filename,
- char **content, int *len)
+ char **content, size_t *len)
{
PGresult *res;
char cmd[64];
{
char *fname;
char *content;
- int len;
+ size_t len;
char expectedfname[MAXFNAMELEN];
ereport(LOG,
XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr, TimeLineID tli)
{
int startoff;
- int byteswritten;
+ ssize_t byteswritten;
instr_time start;
Assert(tli != 0);
BufFileDumpBuffer(BufFile *file)
{
int64 wpos = 0;
- int64 bytestowrite;
File thisfile;
/*
int64 availbytes;
instr_time io_start;
instr_time io_time;
+ size_t bytestowrite;
+ ssize_t rc;
/*
* Advance to next component file if necessary and possible.
else
INSTR_TIME_SET_ZERO(io_start);
- bytestowrite = FileWrite(thisfile,
- file->buffer.data + wpos,
- bytestowrite,
- file->curOffset,
- WAIT_EVENT_BUFFILE_WRITE);
- if (bytestowrite <= 0)
+ rc = FileWrite(thisfile,
+ file->buffer.data + wpos,
+ bytestowrite,
+ file->curOffset,
+ WAIT_EVENT_BUFFILE_WRITE);
+ if (rc <= 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write to file \"%s\": %m",
INSTR_TIME_ACCUM_DIFF(pgBufferUsage.temp_blk_write_time, io_time, io_start);
}
- file->curOffset += bytestowrite;
- wpos += bytestowrite;
+ file->curOffset += rc;
+ wpos += rc;
pgBufferUsage.temp_blks_written++;
}
static void
sendSelfPipeByte(void)
{
- int rc;
+ ssize_t rc;
char dummy = 0;
retry:
const void *buffer, bool skipFsync)
{
pgoff_t seekpos;
- int nbytes;
+ ssize_t nbytes;
MdfdVec *v;
/* If this build supports direct I/O, the buffer must be I/O aligned. */
/* short write: complain appropriately */
ereport(ERROR,
(errcode(ERRCODE_DISK_FULL),
- errmsg("could not extend file \"%s\": wrote only %d of %d bytes at block %u",
+ errmsg("could not extend file \"%s\": wrote only %zd of %zu bytes at block %u",
FilePathName(v->mdfd_vfd),
- nbytes, BLCKSZ, blocknum),
+ nbytes, (size_t) BLCKSZ, blocknum),
errhint("Check free disk space.")));
}
struct iovec iov[PG_IOV_MAX];
int iovcnt;
pgoff_t seekpos;
- int nbytes;
+ ssize_t nbytes;
MdfdVec *v;
BlockNumber nblocks_this_segment;
size_t transferred_this_segment;
static void
write_console(const char *line, int len)
{
- int rc;
+ ssize_t rc;
#ifdef WIN32
{
PipeProtoChunk p;
int fd = fileno(stderr);
- int rc;
+ ssize_t rc;
Assert(len > 0);
AddToDataDirLockFile(int target_line, const char *str)
{
int fd;
- ssize_t len;
+ ssize_t nread;
+ size_t len;
int lineno;
char *srcptr;
char *destptr;
return;
}
pgstat_report_wait_start(WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ);
- len = read(fd, srcbuffer, sizeof(srcbuffer) - 1);
+ nread = read(fd, srcbuffer, sizeof(srcbuffer) - 1);
pgstat_report_wait_end();
- if (len < 0)
+ if (nread < 0)
{
ereport(LOG,
(errcode_for_file_access(),
close(fd);
return;
}
- srcbuffer[len] = '\0';
+ srcbuffer[nread] = '\0';
/*
* Advance over lines we are not supposed to rewrite, then copy them to
probe smgr__md__read__start(ForkNumber, BlockNumber, Oid, Oid, Oid, int);
probe smgr__md__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, long long int, long long int);
probe smgr__md__write__start(ForkNumber, BlockNumber, Oid, Oid, Oid, int);
- probe smgr__md__write__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int, int);
+ probe smgr__md__write__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, long long int, long long int);
probe wal__insert(unsigned char, unsigned char);
probe wal__switch();
while (!time_to_abort)
{
int r;
- int bytes_left;
- int bytes_written;
+ size_t bytes_left;
+ size_t bytes_written;
TimestampTz now;
- int hdr_len;
+ size_t hdr_len;
cur_record_lsn = InvalidXLogRecPtr;
while (bytes_left)
{
- int ret;
+ ssize_t ret;
ret = write(outfd,
copybuf + hdr_len + bytes_written,
if (ret < 0)
{
- pg_log_error("could not write %d bytes to log file \"%s\": %m",
+ pg_log_error("could not write %zu bytes to log file \"%s\": %m",
bytes_left, outfile);
goto error;
}
if (write(outfd, "\n", 1) != 1)
{
- pg_log_error("could not write %d bytes to log file \"%s\": %m",
- 1, outfile);
+ pg_log_error("could not write %zu bytes to log file \"%s\": %m",
+ (size_t) 1, outfile);
goto error;
}
static bool
writeTimeLineHistoryFile(StreamCtl *stream, const char *filename, const char *content)
{
- int size = strlen(content);
+ size_t size = strlen(content);
char histfname[MAXFNAMELEN];
Walfile *f;
return false;
}
- if ((int) stream->walmethod->ops->write(f, content, size) != size)
+ if (stream->walmethod->ops->write(f, content, size) != size)
{
pg_log_error("could not write timeline history file \"%s\": %s",
histfname, GetLastWalMethodError(stream->walmethod));
}
else if (mode == PG_MODE_ENABLE)
{
- int w;
+ ssize_t w;
/*
* Do not rewrite if the checksum is already set to the expected
pg_fatal("could not write block %u in file \"%s\": %m",
blockno, fn);
else
- pg_fatal("could not write block %u in file \"%s\": wrote %d of %d",
- blockno, fn, w, BLCKSZ);
+ pg_fatal("could not write block %u in file \"%s\": wrote %zd of %zu",
+ blockno, fn, w, (size_t) BLCKSZ);
}
}
if (!line_starts_with(s, e, "INCREMENTAL FROM LSN: ", NULL) &&
!line_starts_with(s, e, "INCREMENTAL FROM TLI: ", NULL))
{
+ const size_t bytes_left = e - s;
ssize_t wb;
- wb = write(output_fd, s, e - s);
- if (wb != e - s)
+ wb = write(output_fd, s, bytes_left);
+ if (wb != bytes_left)
{
if (wb < 0)
pg_fatal("could not write file \"%s\": %m", output_filename);
else
- pg_fatal("could not write file \"%s\": wrote %d of %d",
- output_filename, (int) wb, (int) (e - s));
+ pg_fatal("could not write file \"%s\": wrote %zd of %zu",
+ output_filename, wb, bytes_left);
}
- if (pg_checksum_update(&checksum_ctx, (uint8 *) s, e - s) < 0)
+ if (pg_checksum_update(&checksum_ctx, (uint8 *) s, bytes_left) < 0)
pg_fatal("could not update checksum of file \"%s\"",
output_filename);
}
uint8 *buffer;
const int buffer_size = 50 * BLCKSZ;
ssize_t rb;
- unsigned offset = 0;
+ size_t offset = 0;
if ((src_fd = open(src, O_RDONLY | PG_BINARY, 0)) < 0)
pg_fatal("could not open file \"%s\": %m", src);
if (wb < 0)
pg_fatal("could not write to file \"%s\": %m", dst);
else
- pg_fatal("could not write to file \"%s\", offset %u: wrote %d of %d",
- dst, offset, (int) wb, (int) rb);
+ pg_fatal("could not write to file \"%s\", offset %zu: wrote %zd of %zu",
+ dst, offset, wb, (size_t) rb);
}
if (pg_checksum_update(checksum_ctx, buffer, rb) < 0)
write_block(int fd, const char *output_filename,
const uint8 *buffer, pg_checksum_context *checksum_ctx)
{
- int wb;
+ ssize_t wb;
if ((wb = write(fd, buffer, BLCKSZ)) != BLCKSZ)
{
if (wb < 0)
pg_fatal("could not write file \"%s\": %m", output_filename);
else
- pg_fatal("could not write file \"%s\": wrote %d of %d",
- output_filename, wb, BLCKSZ);
+ pg_fatal("could not write file \"%s\": wrote %zd of %zu",
+ output_filename, wb, (size_t) BLCKSZ);
}
/* Update the checksum computation. */
if (wb < 0)
pg_fatal("could not write file \"%s\": %m", mwriter->pathname);
else
- pg_fatal("could not write file \"%s\": wrote %zd of %d",
- mwriter->pathname, wb, mwriter->buf.len);
+ pg_fatal("could not write file \"%s\": wrote %zd of %zu",
+ mwriter->pathname, wb, (size_t) mwriter->buf.len);
}
if (mwriter->still_checksumming &&
#define write_stderr(str) \
do { \
const char *str_ = (str); \
- int rc_; \
+ ssize_t rc_; \
rc_ = write(fileno(stderr), str_, strlen(str_)); \
(void) rc_; \
} while (0)
static void
sendMessageToLeader(int pipefd[2], const char *str)
{
- int len = strlen(str) + 1;
+ size_t len = strlen(str) + 1;
if (pipewrite(pipefd[PIPE_WRITE], str, len) != len)
pg_fatal("could not write to the communication channel: %m");
static void
sendMessageToWorker(ParallelState *pstate, int worker, const char *str)
{
- int len = strlen(str) + 1;
+ size_t len = strlen(str) + 1;
if (pipewrite(pstate->parallelSlot[worker].pipeWrite, str, len) != len)
{
static void
signal_cleanup(SIGNAL_ARGS)
{
- int rc;
+ ssize_t rc;
/* Delete the file if it exists. Ignore errors */
if (needs_unlink)
#define write_stderr(str) \
do { \
const char *str_ = (str); \
- int rc_; \
+ ssize_t rc_; \
rc_ = write(fileno(stderr), str_, strlen(str_)); \
(void) rc_; \
} while (0)
extern TimeLineID findNewestTimeLine(TimeLineID startTLI);
extern void writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
XLogRecPtr switchpoint, const char *reason);
-extern void writeTimeLineHistoryFile(TimeLineID tli, const char *content, int size);
+extern void writeTimeLineHistoryFile(TimeLineID tli, const char *content, size_t size);
extern void restoreTimeLineHistoryFiles(TimeLineID begin, TimeLineID end);
extern bool tliInHistory(TimeLineID tli, List *expectedTLEs);
extern TimeLineID tliOfPointInHistory(XLogRecPtr ptr, List *history);
TimeLineID tli,
char **filename,
char **content,
- int *size);
+ size_t *size);
/*
* walrcv_startstreaming_fn
{
int result = 1;
int fd;
- int nbytes,
- tmp;
+ int nbytes;
char buf[LO_BUFSIZE];
int lobj;
char sebuf[PG_STRERROR_R_BUFLEN];
*/
while ((nbytes = lo_read(conn, lobj, buf, LO_BUFSIZE)) > 0)
{
+ ssize_t tmp;
+
tmp = write(fd, buf, nbytes);
if (tmp != nbytes)
{
{
int lobj_fd;
char buf[BUFSIZE];
- int nbytes,
- tmp;
+ int nbytes;
int fd;
/*
*/
while ((nbytes = lo_read(conn, lobj_fd, buf, BUFSIZE)) > 0)
{
+ ssize_t tmp;
+
tmp = write(fd, buf, nbytes);
if (tmp < nbytes)
{
{
int lobj_fd;
char buf[BUFSIZE];
- int nbytes,
- tmp;
+ int nbytes;
int fd;
/*
*/
while ((nbytes = lo_read(conn, lobj_fd, buf, BUFSIZE)) > 0)
{
+ ssize_t tmp;
+
tmp = write(fd, buf, nbytes);
if (tmp < nbytes)
{