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:141

Definition at line 78 of file relpath.h.

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

◆ relpathperm

◆ TABLESPACE_VERSION_DIRECTORY

Typedef Documentation

◆ ForkNumber

typedef enum ForkNumber 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 81 of file relpath.c.

References forkNames, InvalidForkNumber, and MAX_FORKNUM.

Referenced by looks_like_temp_rel_name(), and parse_filename_for_nontemp_relation().

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 }
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 50 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().

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:1071
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
ForkNumber
Definition: relpath.h:40
#define ereport(elevel,...)
Definition: elog.h:144
#define MAX_FORKNUM
Definition: relpath.h:55
int errmsg(const char *fmt,...)
Definition: elog.c:824
const char *const forkNames[]
Definition: relpath.c:33

◆ GetDatabasePath()

char* GetDatabasePath ( Oid  dbNode,
Oid  spcNode 
)

Definition at line 110 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().

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

◆ GetRelationPath()

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

Definition at line 141 of file relpath.c.

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

143 {
144  char *path;
145 
146  if (spcNode == GLOBALTABLESPACE_OID)
147  {
148  /* Shared system relations live in {datadir}/global */
149  Assert(dbNode == 0);
150  Assert(backendId == InvalidBackendId);
151  if (forkNumber != MAIN_FORKNUM)
152  path = psprintf("global/%u_%s",
153  relNode, forkNames[forkNumber]);
154  else
155  path = psprintf("global/%u", relNode);
156  }
157  else if (spcNode == 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  dbNode, relNode,
165  forkNames[forkNumber]);
166  else
167  path = psprintf("base/%u/%u",
168  dbNode, relNode);
169  }
170  else
171  {
172  if (forkNumber != MAIN_FORKNUM)
173  path = psprintf("base/%u/t%d_%u_%s",
174  dbNode, backendId, relNode,
175  forkNames[forkNumber]);
176  else
177  path = psprintf("base/%u/t%d_%u",
178  dbNode, backendId, relNode);
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  dbNode, relNode,
190  forkNames[forkNumber]);
191  else
192  path = psprintf("pg_tblspc/%u/%s/%u/%u",
194  dbNode, relNode);
195  }
196  else
197  {
198  if (forkNumber != MAIN_FORKNUM)
199  path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u_%s",
201  dbNode, backendId, relNode,
202  forkNames[forkNumber]);
203  else
204  path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u",
206  dbNode, backendId, relNode);
207  }
208  }
209  return path;
210 }
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:738
const char *const forkNames[]
Definition: relpath.c:33

Variable Documentation

◆ forkNames

const char* const forkNames[]