PostgreSQL Source Code  git master
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 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, InvalidBackendId, 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 backendId, ForkNumber forkNumber)
 

Variables

PGDLLIMPORT const char *const forkNames []
 

Macro Definition Documentation

◆ FORKNAMECHARS

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

Definition at line 64 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 62 of file relpath.h.

◆ OIDCHARS

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

Definition at line 37 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 94 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 backendId, ForkNumber forkNumber)
Definition: relpath.c:141

Definition at line 85 of file relpath.h.

◆ relpathperm

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

Definition at line 90 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 47 of file relpath.h.

48 {
49  InvalidForkNumber = -1,
50  MAIN_FORKNUM = 0,
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  */
60 } ForkNumber;
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

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 void size_t len
const char *const forkNames[]
Definition: relpath.c:33
#define MAX_FORKNUM
Definition: relpath.h:62

References forkNames, InvalidForkNumber, len, MAX_FORKNUM, and generate_unaccent_rules::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:1153
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145

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("pg_tblspc/%u/%s/%u",
127  spcOid, TABLESPACE_VERSION_DIRECTORY, dbOid);
128  }
129 }
Assert(fmt[strlen(fmt) - 1] !='\n')
char * pstrdup(const char *in)
Definition: mcxt.c:1483
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:33

References Assert(), 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  backendId,
ForkNumber  forkNumber 
)

Definition at line 141 of file relpath.c.

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

References Assert(), forkNames, InvalidBackendId, MAIN_FORKNUM, psprintf(), and TABLESPACE_VERSION_DIRECTORY.

Variable Documentation

◆ forkNames

PGDLLIMPORT const char* const forkNames[]
extern