* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.232 2006/04/03 23:35:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.233 2006/04/04 22:39:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
WriteControlFile(void)
{
int fd;
- char buffer[BLCKSZ]; /* need not be aligned */
+ char buffer[PG_CONTROL_SIZE]; /* need not be aligned */
char *localeptr;
/*
FIN_CRC32(ControlFile->crc);
/*
- * We write out BLCKSZ bytes into pg_control, zero-padding the excess over
- * sizeof(ControlFileData). This reduces the odds of premature-EOF errors
- * when reading pg_control. We'll still fail when we check the contents
- * of the file, but hopefully with a more specific error than "couldn't
- * read pg_control".
+ * We write out PG_CONTROL_SIZE bytes into pg_control, zero-padding the
+ * excess over sizeof(ControlFileData). This reduces the odds of
+ * premature-EOF errors when reading pg_control. We'll still fail when we
+ * check the contents of the file, but hopefully with a more specific
+ * error than "couldn't read pg_control".
*/
- if (sizeof(ControlFileData) > BLCKSZ)
- ereport(PANIC,
- (errmsg("sizeof(ControlFileData) is larger than BLCKSZ; fix either one")));
+ if (sizeof(ControlFileData) > PG_CONTROL_SIZE)
+ elog(PANIC, "sizeof(ControlFileData) is larger than PG_CONTROL_SIZE; fix either one");
- memset(buffer, 0, BLCKSZ);
+ memset(buffer, 0, PG_CONTROL_SIZE);
memcpy(buffer, ControlFile, sizeof(ControlFileData));
fd = BasicOpenFile(XLOG_CONTROL_FILE,
XLOG_CONTROL_FILE)));
errno = 0;
- if (write(fd, buffer, BLCKSZ) != BLCKSZ)
+ if (write(fd, buffer, PG_CONTROL_SIZE) != PG_CONTROL_SIZE)
{
/* if write didn't set errno, assume problem is no disk space */
if (errno == 0)
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.41 2006/04/03 23:35:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.42 2006/04/04 22:39:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
/* Use malloc to ensure we have a maxaligned buffer */
- buffer = (char *) malloc(BLCKSZ);
+ buffer = (char *) malloc(PG_CONTROL_SIZE);
- len = read(fd, buffer, BLCKSZ);
+ len = read(fd, buffer, PG_CONTROL_SIZE);
if (len < 0)
{
fprintf(stderr, _("%s: could not read file \"%s\": %s\n"),
RewriteControlFile(void)
{
int fd;
- char buffer[BLCKSZ]; /* need not be aligned */
+ char buffer[PG_CONTROL_SIZE]; /* need not be aligned */
/*
* Adjust fields as needed to force an empty XLOG starting at the next
FIN_CRC32(ControlFile.crc);
/*
- * We write out BLCKSZ bytes into pg_control, zero-padding the excess over
- * sizeof(ControlFileData). This reduces the odds of premature-EOF errors
- * when reading pg_control. We'll still fail when we check the contents
- * of the file, but hopefully with a more specific error than "couldn't
- * read pg_control".
+ * We write out PG_CONTROL_SIZE bytes into pg_control, zero-padding the
+ * excess over sizeof(ControlFileData). This reduces the odds of
+ * premature-EOF errors when reading pg_control. We'll still fail when we
+ * check the contents of the file, but hopefully with a more specific
+ * error than "couldn't read pg_control".
*/
- if (sizeof(ControlFileData) > BLCKSZ)
+ if (sizeof(ControlFileData) > PG_CONTROL_SIZE)
{
fprintf(stderr,
- _("%s: internal error -- sizeof(ControlFileData) is too large ... fix xlog.c\n"),
+ _("%s: internal error -- sizeof(ControlFileData) is too large ... fix PG_CONTROL_SIZE\n"),
progname);
exit(1);
}
- memset(buffer, 0, BLCKSZ);
+ memset(buffer, 0, PG_CONTROL_SIZE);
memcpy(buffer, &ControlFile, sizeof(ControlFileData));
unlink(XLOG_CONTROL_FILE);
}
errno = 0;
- if (write(fd, buffer, BLCKSZ) != BLCKSZ)
+ if (write(fd, buffer, PG_CONTROL_SIZE) != PG_CONTROL_SIZE)
{
/* if write didn't set errno, assume problem is no disk space */
if (errno == 0)
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.28 2006/04/03 23:35:05 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.29 2006/04/04 22:39:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
pg_crc32 crc;
} ControlFileData;
+/*
+ * Physical size of the pg_control file. Note that this is considerably
+ * bigger than the actually used size (ie, sizeof(ControlFileData)).
+ * The idea is to keep the physical size constant independent of format
+ * changes, so that ReadControlFile will deliver a suitable wrong-version
+ * message instead of a read error if it's looking at an incompatible file.
+ */
+#define PG_CONTROL_SIZE 8192
+
#endif /* PG_CONTROL_H */