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 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(rnode, backend, forknum)
 
#define relpathperm(rnode, forknum)   relpathbackend(rnode, InvalidBackendId, forknum)
 
#define relpath(rnode, forknum)   relpathbackend((rnode).node, (rnode).backend, forknum)
 

Typedefs

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 dbNode, Oid spcNode)
 
char * GetRelationPath (Oid dbNode, Oid spcNode, Oid relNode, int backendId, ForkNumber forkNumber)
 

Variables

const char *const forkNames []
 

Macro Definition Documentation

◆ FORKNAMECHARS

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

Definition at line 57 of file relpath.h.

Referenced by CreateTableSpace().

◆ MAX_FORKNUM

◆ OIDCHARS

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

◆ relpath

#define relpath (   rnode,
  forknum 
)    relpathbackend((rnode).node, (rnode).backend, forknum)

◆ relpathbackend

#define relpathbackend (   rnode,
  backend,
  forknum 
)
Value:
GetRelationPath((rnode).dbNode, (rnode).spcNode, (rnode).relNode, \
backend, forknum)
char * GetRelationPath(Oid dbNode, Oid spcNode, Oid relNode, int backendId, ForkNumber forkNumber)
Definition: relpath.c:138

Definition at line 78 of file relpath.h.

Referenced by calculate_relation_size(), copy_relation_data(), DropDatabaseBuffers(), DropRelFileNodeAllLocalBuffers(), DropRelFileNodeLocalBuffers(), local_buffer_write_error_callback(), pg_relation_filepath(), and PrintBufferLeakWarning().

◆ relpathperm

◆ TABLESPACE_VERSION_DIRECTORY

Typedef Documentation

◆ ForkNumber

Enumeration Type Documentation

◆ ForkNumber

enum ForkNumber
Enumerator
InvalidForkNumber 
MAIN_FORKNUM 
FSM_FORKNUM 
VISIBILITYMAP_FORKNUM 
INIT_FORKNUM 

Definition at line 40 of file relpath.h.

41 {
42  InvalidForkNumber = -1,
43  MAIN_FORKNUM = 0,
47 
48  /*
49  * NOTE: if you add a new fork, change MAX_FORKNUM and possibly
50  * FORKNAMECHARS below, and update the forkNames array in
51  * src/common/relpath.c
52  */
53 } ForkNumber;
ForkNumber
Definition: relpath.h:40

Function Documentation

◆ forkname_chars()

int forkname_chars ( const char *  str,
ForkNumber fork 
)

Definition at line 78 of file relpath.c.

References forkNames, InvalidForkNumber, and MAX_FORKNUM.

Referenced by looks_like_temp_rel_name(), and parse_filename_for_nontemp_relation().

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

◆ forkname_to_number()

ForkNumber forkname_to_number ( const char *  forkName)

Definition at line 47 of file relpath.c.

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

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

48 {
49  ForkNumber forkNum;
50 
51  for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
52  if (strcmp(forkNames[forkNum], forkName) == 0)
53  return forkNum;
54 
55 #ifndef FRONTEND
56  ereport(ERROR,
57  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
58  errmsg("invalid fork name"),
59  errhint("Valid fork names are \"main\", \"fsm\", "
60  "\"vm\", and \"init\".")));
61 #endif
62 
63  return InvalidForkNumber;
64 }
int errhint(const char *fmt,...)
Definition: elog.c:987
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
ForkNumber
Definition: relpath.h:40
#define MAX_FORKNUM
Definition: relpath.h:55
int errmsg(const char *fmt,...)
Definition: elog.c:797
const char *const forkNames[]
Definition: relpath.c:33

◆ GetDatabasePath()

char* GetDatabasePath ( Oid  dbNode,
Oid  spcNode 
)

Definition at line 107 of file relpath.c.

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

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

108 {
109  if (spcNode == GLOBALTABLESPACE_OID)
110  {
111  /* Shared system relations live in {datadir}/global */
112  Assert(dbNode == 0);
113  return pstrdup("global");
114  }
115  else if (spcNode == DEFAULTTABLESPACE_OID)
116  {
117  /* The default tablespace is {datadir}/base */
118  return psprintf("base/%u", dbNode);
119  }
120  else
121  {
122  /* All other tablespaces are accessed via symlinks */
123  return psprintf("pg_tblspc/%u/%s/%u",
124  spcNode, TABLESPACE_VERSION_DIRECTORY, dbNode);
125  }
126 }
char * pstrdup(const char *in)
Definition: mcxt.c:1161
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:26
#define Assert(condition)
Definition: c.h:699

◆ GetRelationPath()

char* GetRelationPath ( Oid  dbNode,
Oid  spcNode,
Oid  relNode,
int  backendId,
ForkNumber  forkNumber 
)

Definition at line 138 of file relpath.c.

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

140 {
141  char *path;
142 
143  if (spcNode == GLOBALTABLESPACE_OID)
144  {
145  /* Shared system relations live in {datadir}/global */
146  Assert(dbNode == 0);
147  Assert(backendId == InvalidBackendId);
148  if (forkNumber != MAIN_FORKNUM)
149  path = psprintf("global/%u_%s",
150  relNode, forkNames[forkNumber]);
151  else
152  path = psprintf("global/%u", relNode);
153  }
154  else if (spcNode == DEFAULTTABLESPACE_OID)
155  {
156  /* The default tablespace is {datadir}/base */
157  if (backendId == InvalidBackendId)
158  {
159  if (forkNumber != MAIN_FORKNUM)
160  path = psprintf("base/%u/%u_%s",
161  dbNode, relNode,
162  forkNames[forkNumber]);
163  else
164  path = psprintf("base/%u/%u",
165  dbNode, relNode);
166  }
167  else
168  {
169  if (forkNumber != MAIN_FORKNUM)
170  path = psprintf("base/%u/t%d_%u_%s",
171  dbNode, backendId, relNode,
172  forkNames[forkNumber]);
173  else
174  path = psprintf("base/%u/t%d_%u",
175  dbNode, backendId, relNode);
176  }
177  }
178  else
179  {
180  /* All other tablespaces are accessed via symlinks */
181  if (backendId == InvalidBackendId)
182  {
183  if (forkNumber != MAIN_FORKNUM)
184  path = psprintf("pg_tblspc/%u/%s/%u/%u_%s",
186  dbNode, relNode,
187  forkNames[forkNumber]);
188  else
189  path = psprintf("pg_tblspc/%u/%s/%u/%u",
191  dbNode, relNode);
192  }
193  else
194  {
195  if (forkNumber != MAIN_FORKNUM)
196  path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u_%s",
198  dbNode, backendId, relNode,
199  forkNames[forkNumber]);
200  else
201  path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u",
203  dbNode, backendId, relNode);
204  }
205  }
206  return path;
207 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define TABLESPACE_VERSION_DIRECTORY
Definition: relpath.h:26
#define InvalidBackendId
Definition: backendid.h:23
#define Assert(condition)
Definition: c.h:699
const char *const forkNames[]
Definition: relpath.c:33

Variable Documentation

◆ forkNames

const char* const forkNames[]