PostgreSQL Source Code  git master
file_utils.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * Assorted utility functions to work on files.
4  *
5  *
6  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/common/file_utils.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef FILE_UTILS_H
14 #define FILE_UTILS_H
15 
16 #include <dirent.h>
17 
18 typedef enum PGFileType
19 {
26 
27 typedef enum DataDirSyncMethod
28 {
32 
33 struct iovec; /* avoid including port/pg_iovec.h here */
34 
35 #ifdef FRONTEND
36 extern int fsync_fname(const char *fname, bool isdir);
37 extern void sync_pgdata(const char *pg_data, int serverVersion,
39 extern void sync_dir_recurse(const char *dir, DataDirSyncMethod sync_method);
40 extern int durable_rename(const char *oldfile, const char *newfile);
41 extern int fsync_parent_path(const char *fname);
42 #endif
43 
44 extern PGFileType get_dirent_type(const char *path,
45  const struct dirent *de,
46  bool look_through_symlinks,
47  int elevel);
48 
49 extern int compute_remaining_iovec(struct iovec *destination,
50  const struct iovec *source,
51  int iovcnt,
52  size_t transferred);
53 
54 extern ssize_t pg_pwritev_with_retry(int fd,
55  const struct iovec *iov,
56  int iovcnt,
57  off_t offset);
58 
59 extern ssize_t pg_pwrite_zeros(int fd, size_t size, off_t offset);
60 
61 /* Filename components */
62 #define PG_TEMP_FILES_DIR "pgsql_tmp"
63 #define PG_TEMP_FILE_PREFIX "pgsql_tmp"
64 
65 #endif /* FILE_UTILS_H */
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:781
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:755
static int fsync_parent_path(const char *fname, int elevel)
Definition: fd.c:3896
int compute_remaining_iovec(struct iovec *destination, const struct iovec *source, int iovcnt, size_t transferred)
Definition: file_utils.c:593
PGFileType
Definition: file_utils.h:19
@ PGFILETYPE_LNK
Definition: file_utils.h:24
@ PGFILETYPE_UNKNOWN
Definition: file_utils.h:21
@ PGFILETYPE_DIR
Definition: file_utils.h:23
@ PGFILETYPE_REG
Definition: file_utils.h:22
@ PGFILETYPE_ERROR
Definition: file_utils.h:20
ssize_t pg_pwrite_zeros(int fd, size_t size, off_t offset)
Definition: file_utils.c:688
DataDirSyncMethod
Definition: file_utils.h:28
@ DATA_DIR_SYNC_METHOD_SYNCFS
Definition: file_utils.h:30
@ DATA_DIR_SYNC_METHOD_FSYNC
Definition: file_utils.h:29
ssize_t pg_pwritev_with_retry(int fd, const struct iovec *iov, int iovcnt, off_t offset)
Definition: file_utils.c:638
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
Definition: file_utils.c:526
static char * pg_data
Definition: initdb.c:138
static DataDirSyncMethod sync_method
Definition: initdb.c:170
static rewind_source * source
Definition: pg_rewind.c:89
static int fd(const char *x, int i)
Definition: preproc-init.c:105
static pg_noinline void Size size
Definition: slab.c:607
Definition: dirent.h:10