PostgreSQL Source Code  git master
relpath.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * relpath.h
4  * Declarations for GetRelationPath() and friends
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/relpath.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef RELPATH_H
14 #define RELPATH_H
15 
16 /*
17  * 'pgrminclude ignore' needed here because CppAsString2() does not throw
18  * an error if the symbol is not defined.
19  */
20 #include "catalog/catversion.h" /* pgrminclude ignore */
21 
22 /*
23  * RelFileNumber data type identifies the specific relation file name.
24  */
26 #define InvalidRelFileNumber ((RelFileNumber) InvalidOid)
27 #define RelFileNumberIsValid(relnumber) \
28  ((bool) ((relnumber) != InvalidRelFileNumber))
29 
30 /*
31  * Name of major-version-specific tablespace subdirectories
32  */
33 #define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION "_" \
34  CppAsString2(CATALOG_VERSION_NO)
35 
36 /*
37  * Tablespace path (relative to installation's $PGDATA).
38  *
39  * These values should not be changed as many tools rely on it.
40  */
41 #define PG_TBLSPC_DIR "pg_tblspc"
42 #define PG_TBLSPC_DIR_SLASH "pg_tblspc/" /* required for strings
43  * comparisons */
44 
45 /* Characters to allow for an OID in a relation path */
46 #define OIDCHARS 10 /* max chars printed by %u */
47 
48 /*
49  * Stuff for fork names.
50  *
51  * The physical storage of a relation consists of one or more forks.
52  * The main fork is always created, but in addition to that there can be
53  * additional forks for storing various metadata. ForkNumber is used when
54  * we need to refer to a specific fork in a relation.
55  */
56 typedef enum ForkNumber
57 {
63 
64  /*
65  * NOTE: if you add a new fork, change MAX_FORKNUM and possibly
66  * FORKNAMECHARS below, and update the forkNames array in
67  * src/common/relpath.c
68  */
69 } ForkNumber;
70 
71 #define MAX_FORKNUM INIT_FORKNUM
72 
73 #define FORKNAMECHARS 4 /* max chars for a fork name */
74 
75 extern PGDLLIMPORT const char *const forkNames[];
76 
77 extern ForkNumber forkname_to_number(const char *forkName);
78 extern int forkname_chars(const char *str, ForkNumber *fork);
79 
80 /*
81  * Stuff for computing filesystem pathnames for relations.
82  */
83 extern char *GetDatabasePath(Oid dbOid, Oid spcOid);
84 
85 extern char *GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber,
86  int procNumber, ForkNumber forkNumber);
87 
88 /*
89  * Wrapper macros for GetRelationPath. Beware of multiple
90  * evaluation of the RelFileLocator or RelFileLocatorBackend argument!
91  */
92 
93 /* First argument is a RelFileLocator */
94 #define relpathbackend(rlocator, backend, forknum) \
95  GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
96  backend, forknum)
97 
98 /* First argument is a RelFileLocator */
99 #define relpathperm(rlocator, forknum) \
100  relpathbackend(rlocator, INVALID_PROC_NUMBER, forknum)
101 
102 /* First argument is a RelFileLocatorBackend */
103 #define relpath(rlocator, forknum) \
104  relpathbackend((rlocator).locator, (rlocator).backend, forknum)
105 
106 #endif /* RELPATH_H */
#define PGDLLIMPORT
Definition: c.h:1319
const char * str
unsigned int Oid
Definition: postgres_ext.h:31
Oid RelFileNumber
Definition: relpath.h:25
char * GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int procNumber, ForkNumber forkNumber)
Definition: relpath.c:142
PGDLLIMPORT const char *const forkNames[]
Definition: relpath.c:33
ForkNumber
Definition: relpath.h:56
@ FSM_FORKNUM
Definition: relpath.h:59
@ VISIBILITYMAP_FORKNUM
Definition: relpath.h:60
@ MAIN_FORKNUM
Definition: relpath.h:58
@ InvalidForkNumber
Definition: relpath.h:57
@ INIT_FORKNUM
Definition: relpath.h:61
char * GetDatabasePath(Oid dbOid, Oid spcOid)
Definition: relpath.c:110
int forkname_chars(const char *str, ForkNumber *fork)
Definition: relpath.c:81
ForkNumber forkname_to_number(const char *forkName)
Definition: relpath.c:50