PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
relpath.h File Reference
Include dependency graph for relpath.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define InvalidRelFileNumber   ((RelFileNumber) InvalidOid)
 
#define RelFileNumberIsValid(relnumber)    ((bool) ((relnumber) != InvalidRelFileNumber))
 
#define TABLESPACE_VERSION_DIRECTORY
 
#define PG_TBLSPC_DIR   "pg_tblspc"
 
#define PG_TBLSPC_DIR_SLASH
 
#define OIDCHARS   10 /* max chars printed by %u */
 
#define MAX_FORKNUM   INIT_FORKNUM
 
#define FORKNAMECHARS   4 /* max chars for a fork name */
 
#define relpathbackend(rlocator, backend, forknum)
 
#define relpathperm(rlocator, forknum)    relpathbackend(rlocator, INVALID_PROC_NUMBER, forknum)
 
#define relpath(rlocator, forknum)    relpathbackend((rlocator).locator, (rlocator).backend, forknum)
 

Typedefs

typedef Oid RelFileNumber
 
typedef enum ForkNumber ForkNumber
 

Enumerations

enum  ForkNumber {
  InvalidForkNumber = -1 , MAIN_FORKNUM = 0 , FSM_FORKNUM , VISIBILITYMAP_FORKNUM ,
  INIT_FORKNUM
}
 

Functions

ForkNumber forkname_to_number (const char *forkName)
 
int forkname_chars (const char *str, ForkNumber *fork)
 
char * GetDatabasePath (Oid dbOid, Oid spcOid)
 
char * GetRelationPath (Oid dbOid, Oid spcOid, RelFileNumber relNumber, int procNumber, ForkNumber forkNumber)
 

Variables

PGDLLIMPORT const char *const forkNames []
 

Macro Definition Documentation

◆ FORKNAMECHARS

#define FORKNAMECHARS   4 /* max chars for a fork name */

Definition at line 72 of file relpath.h.

◆ InvalidRelFileNumber

#define InvalidRelFileNumber   ((RelFileNumber) InvalidOid)

Definition at line 26 of file relpath.h.

◆ MAX_FORKNUM

#define MAX_FORKNUM   INIT_FORKNUM

Definition at line 70 of file relpath.h.

◆ OIDCHARS

#define OIDCHARS   10 /* max chars printed by %u */

Definition at line 45 of file relpath.h.

◆ PG_TBLSPC_DIR

#define PG_TBLSPC_DIR   "pg_tblspc"

Definition at line 41 of file relpath.h.

◆ PG_TBLSPC_DIR_SLASH

#define PG_TBLSPC_DIR_SLASH
Value:
"pg_tblspc/" /* required for strings
* comparisons */

Definition at line 42 of file relpath.h.

◆ RelFileNumberIsValid

#define RelFileNumberIsValid (   relnumber)     ((bool) ((relnumber) != InvalidRelFileNumber))

Definition at line 27 of file relpath.h.

◆ relpath

#define relpath (   rlocator,
  forknum 
)     relpathbackend((rlocator).locator, (rlocator).backend, forknum)

Definition at line 102 of file relpath.h.

◆ relpathbackend

#define relpathbackend (   rlocator,
  backend,
  forknum 
)
Value:
GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
backend, forknum)
char * GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int procNumber, ForkNumber forkNumber)
Definition: relpath.c:142

Definition at line 93 of file relpath.h.

◆ relpathperm

#define relpathperm (   rlocator,
  forknum 
)     relpathbackend(rlocator, INVALID_PROC_NUMBER, forknum)

Definition at line 98 of file relpath.h.

◆ TABLESPACE_VERSION_DIRECTORY

#define TABLESPACE_VERSION_DIRECTORY
Value:
"PG_" PG_MAJORVERSION "_" \
CppAsString2(CATALOG_VERSION_NO)
#define CATALOG_VERSION_NO
Definition: catversion.h:60

Definition at line 33 of file relpath.h.

Typedef Documentation

◆ ForkNumber

typedef enum ForkNumber ForkNumber

◆ RelFileNumber

typedef Oid RelFileNumber

Definition at line 25 of file relpath.h.

Enumeration Type Documentation

◆ ForkNumber

enum ForkNumber
Enumerator
InvalidForkNumber 
MAIN_FORKNUM 
FSM_FORKNUM 
VISIBILITYMAP_FORKNUM 
INIT_FORKNUM 

Definition at line 55 of file relpath.h.

57 {
58  InvalidForkNumber = -1,
59  MAIN_FORKNUM = 0,
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  */
@ 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

Function Documentation

◆ forkname_chars()

int forkname_chars ( const char *  str,
ForkNumber fork 
)

Definition at line 81 of file relpath.c.

82 {
83  ForkNumber forkNum;
84 
85  for (forkNum = 1; forkNum <= MAX_FORKNUM; forkNum++)
86  {
87  int len = strlen(forkNames[forkNum]);
88 
89  if (strncmp(forkNames[forkNum], str, len) == 0)
90  {
91  if (fork)
92  *fork = forkNum;
93  return len;
94  }
95  }
96  if (fork)
97  *fork = InvalidForkNumber;
98  return 0;
99 }
const char * str
const void size_t len
const char *const forkNames[]
Definition: relpath.c:33
ForkNumber
Definition: relpath.h:56
#define MAX_FORKNUM
Definition: relpath.h:70

References forkNames, InvalidForkNumber, len, MAX_FORKNUM, and str.

Referenced by looks_like_temp_rel_name(), and parse_filename_for_nontemp_relation().

◆ forkname_to_number()

ForkNumber forkname_to_number ( const char *  forkName)

Definition at line 50 of file relpath.c.

51 {
52  ForkNumber forkNum;
53 
54  for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
55  if (strcmp(forkNames[forkNum], forkName) == 0)
56  return forkNum;
57 
58 #ifndef FRONTEND
59  ereport(ERROR,
60  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
61  errmsg("invalid fork name"),
62  errhint("Valid fork names are \"main\", \"fsm\", "
63  "\"vm\", and \"init\".")));
64 #endif
65 
66  return InvalidForkNumber;
67 }
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149

References ereport, errcode(), errhint(), errmsg(), ERROR, forkNames, InvalidForkNumber, and MAX_FORKNUM.

Referenced by get_raw_page_fork(), get_raw_page_fork_1_9(), main(), pg_prewarm(), and pg_relation_size().

◆ GetDatabasePath()

char* GetDatabasePath ( Oid  dbOid,
Oid  spcOid 
)

Definition at line 110 of file relpath.c.

111 {
112  if (spcOid == GLOBALTABLESPACE_OID)
113  {
114  /* Shared system relations live in {datadir}/global */
115  Assert(dbOid == 0);
116  return pstrdup("global");
117  }
118  else if (spcOid == DEFAULTTABLESPACE_OID)
119  {
120  /* The default tablespace is {datadir}/base */
121  return psprintf("base/%u", dbOid);
122  }
123  else
124  {
125  /* All other tablespaces are accessed via symlinks */
126  return psprintf("%s/%u/%s/%u",
127  PG_TBLSPC_DIR, spcOid,
129  }
130 }
#define Assert(condition)
Definition: c.h:863
char * pstrdup(const char *in)
Definition: mcxt.c:1696
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
#define PG_TBLSPC_DIR
Definition: relpath.h:41
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:33

References Assert, PG_TBLSPC_DIR, psprintf(), pstrdup(), and TABLESPACE_VERSION_DIRECTORY.

Referenced by check_db_file_conflict(), CreateDatabaseUsingFileCopy(), CreateDatabaseUsingWalLog(), createdb(), dbase_redo(), InitPostgres(), movedb(), movedb_failure_callback(), ProcessCommittedInvalidationMessages(), relmap_redo(), remove_dbtablespaces(), and TablespaceCreateDbspace().

◆ GetRelationPath()

char* GetRelationPath ( Oid  dbOid,
Oid  spcOid,
RelFileNumber  relNumber,
int  procNumber,
ForkNumber  forkNumber 
)

Definition at line 142 of file relpath.c.

144 {
145  char *path;
146 
147  if (spcOid == GLOBALTABLESPACE_OID)
148  {
149  /* Shared system relations live in {datadir}/global */
150  Assert(dbOid == 0);
151  Assert(procNumber == INVALID_PROC_NUMBER);
152  if (forkNumber != MAIN_FORKNUM)
153  path = psprintf("global/%u_%s",
154  relNumber, forkNames[forkNumber]);
155  else
156  path = psprintf("global/%u", relNumber);
157  }
158  else if (spcOid == DEFAULTTABLESPACE_OID)
159  {
160  /* The default tablespace is {datadir}/base */
161  if (procNumber == INVALID_PROC_NUMBER)
162  {
163  if (forkNumber != MAIN_FORKNUM)
164  path = psprintf("base/%u/%u_%s",
165  dbOid, relNumber,
166  forkNames[forkNumber]);
167  else
168  path = psprintf("base/%u/%u",
169  dbOid, relNumber);
170  }
171  else
172  {
173  if (forkNumber != MAIN_FORKNUM)
174  path = psprintf("base/%u/t%d_%u_%s",
175  dbOid, procNumber, relNumber,
176  forkNames[forkNumber]);
177  else
178  path = psprintf("base/%u/t%d_%u",
179  dbOid, procNumber, relNumber);
180  }
181  }
182  else
183  {
184  /* All other tablespaces are accessed via symlinks */
185  if (procNumber == INVALID_PROC_NUMBER)
186  {
187  if (forkNumber != MAIN_FORKNUM)
188  path = psprintf("%s/%u/%s/%u/%u_%s",
189  PG_TBLSPC_DIR, spcOid,
191  dbOid, relNumber,
192  forkNames[forkNumber]);
193  else
194  path = psprintf("%s/%u/%s/%u/%u",
195  PG_TBLSPC_DIR, spcOid,
197  dbOid, relNumber);
198  }
199  else
200  {
201  if (forkNumber != MAIN_FORKNUM)
202  path = psprintf("%s/%u/%s/%u/t%d_%u_%s",
203  PG_TBLSPC_DIR, spcOid,
205  dbOid, procNumber, relNumber,
206  forkNames[forkNumber]);
207  else
208  path = psprintf("%s/%u/%s/%u/t%d_%u",
209  PG_TBLSPC_DIR, spcOid,
211  dbOid, procNumber, relNumber);
212  }
213  }
214  return path;
215 }
#define INVALID_PROC_NUMBER
Definition: procnumber.h:26

References Assert, forkNames, INVALID_PROC_NUMBER, MAIN_FORKNUM, PG_TBLSPC_DIR, psprintf(), and TABLESPACE_VERSION_DIRECTORY.

Referenced by GetIncrementalFilePath().

Variable Documentation

◆ forkNames

PGDLLIMPORT const char* const forkNames[]
extern