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-2022, 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 /* Characters to allow for an OID in a relation path */
37 #define OIDCHARS 10 /* max chars printed by %u */
38 
39 /*
40  * Stuff for fork names.
41  *
42  * The physical storage of a relation consists of one or more forks.
43  * The main fork is always created, but in addition to that there can be
44  * additional forks for storing various metadata. ForkNumber is used when
45  * we need to refer to a specific fork in a relation.
46  */
47 typedef enum ForkNumber
48 {
54 
55  /*
56  * NOTE: if you add a new fork, change MAX_FORKNUM and possibly
57  * FORKNAMECHARS below, and update the forkNames array in
58  * src/common/relpath.c
59  */
61 
62 #define MAX_FORKNUM INIT_FORKNUM
63 
64 #define FORKNAMECHARS 4 /* max chars for a fork name */
65 
66 extern PGDLLIMPORT const char *const forkNames[];
67 
68 extern ForkNumber forkname_to_number(const char *forkName);
69 extern int forkname_chars(const char *str, ForkNumber *fork);
70 
71 /*
72  * Stuff for computing filesystem pathnames for relations.
73  */
74 extern char *GetDatabasePath(Oid dbOid, Oid spcOid);
75 
76 extern char *GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber,
77  int backendId, ForkNumber forkNumber);
78 
79 /*
80  * Wrapper macros for GetRelationPath. Beware of multiple
81  * evaluation of the RelFileLocator or RelFileLocatorBackend argument!
82  */
83 
84 /* First argument is a RelFileLocator */
85 #define relpathbackend(rlocator, backend, forknum) \
86  GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
87  backend, forknum)
88 
89 /* First argument is a RelFileLocator */
90 #define relpathperm(rlocator, forknum) \
91  relpathbackend(rlocator, InvalidBackendId, forknum)
92 
93 /* First argument is a RelFileLocatorBackend */
94 #define relpath(rlocator, forknum) \
95  relpathbackend((rlocator).locator, (rlocator).backend, forknum)
96 
97 #endif /* RELPATH_H */
#define PGDLLIMPORT
Definition: c.h:1252
unsigned int Oid
Definition: postgres_ext.h:31
Oid RelFileNumber
Definition: relpath.h:25
PGDLLIMPORT const char *const forkNames[]
Definition: relpath.c:33
ForkNumber
Definition: relpath.h:48
@ FSM_FORKNUM
Definition: relpath.h:51
@ VISIBILITYMAP_FORKNUM
Definition: relpath.h:52
@ MAIN_FORKNUM
Definition: relpath.h:50
@ InvalidForkNumber
Definition: relpath.h:49
@ INIT_FORKNUM
Definition: relpath.h:53
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
char * GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int backendId, ForkNumber forkNumber)
Definition: relpath.c:141