PostgreSQL Source Code: src/common/controldata_utils.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef FRONTEND
19#else
21#endif
22
24#include <sys/stat.h>
25#include <fcntl.h>
27
31#ifdef FRONTEND
34#endif
36
37#ifndef FRONTEND
40#endif
41
42
43
44
45
46
47
48
49
50
53{
55
57
59}
60
61
62
63
64
65
66
69{
71 int fd;
73 int r;
74#ifdef FRONTEND
76 int retries = 0;
77#endif
78
80
82
83#ifdef FRONTEND
85
86retry:
87#endif
88
89#ifndef FRONTEND
93 errmsg("could not open file \"%s\" for reading: %m",
94 ControlFilePath)));
95#else
96 if ((fd = open(ControlFilePath, O_RDONLY | PG_BINARY, 0)) == -1)
97 pg_fatal("could not open file \"%s\" for reading: %m",
98 ControlFilePath);
99#endif
100
103 {
104 if (r < 0)
105#ifndef FRONTEND
108 errmsg("could not read file \"%s\": %m", ControlFilePath)));
109#else
110 pg_fatal("could not read file \"%s\": %m", ControlFilePath);
111#endif
112 else
113#ifndef FRONTEND
116 errmsg("could not read file \"%s\": read %d of %zu",
118#else
119 pg_fatal("could not read file \"%s\": read %d of %zu",
121#endif
122 }
123
124#ifndef FRONTEND
128 errmsg("could not close file \"%s\": %m",
129 ControlFilePath)));
130#else
132 pg_fatal("could not close file \"%s\": %m", ControlFilePath);
133#endif
134
135
141
143
144#ifdef FRONTEND
145
146
147
148
149
150
151
152
153 if (!*crc_ok_p &&
154 (retries == 0 || (crc, last_crc)) &&
155 retries < 10)
156 {
157 retries++;
158 last_crc = crc;
160 goto retry;
161 }
162#endif
163
164
167#ifndef FRONTEND
168 elog(ERROR, _("byte ordering mismatch"));
169#else
171 "The byte ordering used to store the pg_control file might not match the one\n"
172 "used by this program. In that case the results below would be incorrect, and\n"
173 "the PostgreSQL installation would be incompatible with this data directory.");
174#endif
175
177}
178
179
180
181
182
183
184
185
186
187
188void
191{
192 int fd;
195
196
198
199
205
206
207
208
209
210
213
215
216#ifndef FRONTEND
217
218
219
220
221
225 errmsg("could not open file \"%s\": %m",
226 ControlFilePath)));
227#else
228 if ((fd = open(ControlFilePath, O_WRONLY | PG_BINARY,
230 pg_fatal("could not open file \"%s\": %m", ControlFilePath);
231#endif
232
233 errno = 0;
234#ifndef FRONTEND
236#endif
238 {
239
240 if (errno == 0)
241 errno = ENOSPC;
242
243#ifndef FRONTEND
246 errmsg("could not write file \"%s\": %m",
247 ControlFilePath)));
248#else
249 pg_fatal("could not write file \"%s\": %m", ControlFilePath);
250#endif
251 }
252#ifndef FRONTEND
254#endif
255
257 {
258#ifndef FRONTEND
263 errmsg("could not fsync file \"%s\": %m",
264 ControlFilePath)));
266#else
268 pg_fatal("could not fsync file \"%s\": %m", ControlFilePath);
269#endif
270 }
271
273 {
274#ifndef FRONTEND
277 errmsg("could not close file \"%s\": %m",
278 ControlFilePath)));
279#else
280 pg_fatal("could not close file \"%s\": %m", ControlFilePath);
281#endif
282 }
283}
void update_controlfile(const char *DataDir, ControlFileData *ControlFile, bool do_sync)
ControlFileData * get_controlfile(const char *DataDir, bool *crc_ok_p)
ControlFileData * get_controlfile_by_exact_path(const char *ControlFilePath, bool *crc_ok_p)
int errcode_for_file_access(void)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
int CloseTransientFile(int fd)
int BasicOpenFile(const char *fileName, int fileFlags)
int OpenTransientFile(const char *fileName, int fileFlags)
#define palloc_object(type)
Assert(PointerIsAligned(start, uint64))
#define ERRCODE_DATA_CORRUPTED
#define PG_CONTROL_FILE_SIZE
#define COMP_CRC32C(crc, data, len)
#define EQ_CRC32C(c1, c2)
#define pg_log_warning(...)
static int fd(const char *x, int i)
void pg_usleep(long microsec)
uint32 pg_control_version
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
static ControlFileData * ControlFile
#define XLOG_CONTROL_FILE