aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2013-02-21 22:46:17 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2013-02-21 22:46:17 -0300
commita73018392636ce832b09b5c31f6ad1f18a4643ea (patch)
tree45ff73dc25699e9156147948e7f4ba2a85961a33 /src/backend
parent6e3fd964632e95c7359457b7d67aa20c72a71679 (diff)
downloadpostgresql-a73018392636ce832b09b5c31f6ad1f18a4643ea.tar.gz
postgresql-a73018392636ce832b09b5c31f6ad1f18a4643ea.zip
Move relpath() to libpgcommon
This enables non-backend code, such as pg_xlogdump, to use it easily. The previous location, in src/backend/catalog/catalog.c, made that essentially impossible because that file depends on many backend-only facilities; so this needs to live separately.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/Makefile8
-rw-r--r--src/backend/access/rmgrdesc/smgrdesc.c1
-rw-r--r--src/backend/access/rmgrdesc/xactdesc.c1
-rw-r--r--src/backend/access/transam/xlogutils.c1
-rw-r--r--src/backend/catalog/catalog.c140
-rw-r--r--src/backend/commands/tablespace.c1
-rw-r--r--src/backend/storage/buffer/bufmgr.c1
-rw-r--r--src/backend/storage/buffer/localbuf.c1
-rw-r--r--src/backend/storage/file/fd.c1
-rw-r--r--src/backend/storage/file/reinit.c1
-rw-r--r--src/backend/storage/smgr/md.c1
-rw-r--r--src/backend/utils/adt/dbsize.c1
-rw-r--r--src/backend/utils/adt/misc.c1
-rw-r--r--src/backend/utils/cache/relcache.c1
14 files changed, 18 insertions, 142 deletions
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 323b417ed74..318cdbcf767 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -35,10 +35,12 @@ LOCALOBJS += utils/probes.o
endif
endif
-OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
+OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a \
+ $(top_builddir)/src/common/libpgcommon_srv.a
-# We put libpgport into OBJS, so remove it from LIBS; also add libldap
-LIBS := $(filter-out -lpgport, $(LIBS)) $(LDAP_LIBS_BE)
+# We put libpgport and libpgcommon into OBJS, so remove it from LIBS; also add
+# libldap
+LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) $(LDAP_LIBS_BE)
# The backend doesn't need everything that's in LIBS, however
LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
diff --git a/src/backend/access/rmgrdesc/smgrdesc.c b/src/backend/access/rmgrdesc/smgrdesc.c
index bcabf8993af..176d8142a60 100644
--- a/src/backend/access/rmgrdesc/smgrdesc.c
+++ b/src/backend/access/rmgrdesc/smgrdesc.c
@@ -16,6 +16,7 @@
#include "catalog/catalog.h"
#include "catalog/storage_xlog.h"
+#include "common/relpath.h"
void
diff --git a/src/backend/access/rmgrdesc/xactdesc.c b/src/backend/access/rmgrdesc/xactdesc.c
index 247127999e3..11c6912753a 100644
--- a/src/backend/access/rmgrdesc/xactdesc.c
+++ b/src/backend/access/rmgrdesc/xactdesc.c
@@ -16,6 +16,7 @@
#include "access/xact.h"
#include "catalog/catalog.h"
+#include "common/relpath.h"
#include "storage/sinval.h"
#include "utils/timestamp.h"
diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index f9a6e628b7f..5429d5ed5e9 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -20,6 +20,7 @@
#include "access/xlog.h"
#include "access/xlogutils.h"
#include "catalog/catalog.h"
+#include "common/relpath.h"
#include "storage/smgr.h"
#include "utils/guc.h"
#include "utils/hsearch.h"
diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c
index 968648627c0..967182b541b 100644
--- a/src/backend/catalog/catalog.c
+++ b/src/backend/catalog/catalog.c
@@ -37,6 +37,7 @@
#include "catalog/pg_shseclabel.h"
#include "catalog/pg_tablespace.h"
#include "catalog/toasting.h"
+#include "common/relpath.h"
#include "miscadmin.h"
#include "storage/fd.h"
#include "utils/fmgroids.h"
@@ -44,21 +45,6 @@
#include "utils/tqual.h"
-#define FORKNAMECHARS 4 /* max chars for a fork name */
-
-/*
- * Lookup table of fork name by fork number.
- *
- * If you add a new entry, remember to update the errhint below, and the
- * documentation for pg_relation_size(). Also keep FORKNAMECHARS above
- * up-to-date.
- */
-const char *forkNames[] = {
- "main", /* MAIN_FORKNUM */
- "fsm", /* FSM_FORKNUM */
- "vm", /* VISIBILITYMAP_FORKNUM */
- "init" /* INIT_FORKNUM */
-};
/*
* forkname_to_number - look up fork number by name
@@ -80,130 +66,6 @@ forkname_to_number(char *forkName)
}
/*
- * forkname_chars
- * We use this to figure out whether a filename could be a relation
- * fork (as opposed to an oddly named stray file that somehow ended
- * up in the database directory). If the passed string begins with
- * a fork name (other than the main fork name), we return its length,
- * and set *fork (if not NULL) to the fork number. If not, we return 0.
- *
- * Note that the present coding assumes that there are no fork names which
- * are prefixes of other fork names.
- */
-int
-forkname_chars(const char *str, ForkNumber *fork)
-{
- ForkNumber forkNum;
-
- for (forkNum = 1; forkNum <= MAX_FORKNUM; forkNum++)
- {
- int len = strlen(forkNames[forkNum]);
-
- if (strncmp(forkNames[forkNum], str, len) == 0)
- {
- if (fork)
- *fork = forkNum;
- return len;
- }
- }
- return 0;
-}
-
-/*
- * relpathbackend - construct path to a relation's file
- *
- * Result is a palloc'd string.
- */
-char *
-relpathbackend(RelFileNode rnode, BackendId backend, ForkNumber forknum)
-{
- int pathlen;
- char *path;
-
- if (rnode.spcNode == GLOBALTABLESPACE_OID)
- {
- /* Shared system relations live in {datadir}/global */
- Assert(rnode.dbNode == 0);
- Assert(backend == InvalidBackendId);
- pathlen = 7 + OIDCHARS + 1 + FORKNAMECHARS + 1;
- path = (char *) palloc(pathlen);
- if (forknum != MAIN_FORKNUM)
- snprintf(path, pathlen, "global/%u_%s",
- rnode.relNode, forkNames[forknum]);
- else
- snprintf(path, pathlen, "global/%u", rnode.relNode);
- }
- else if (rnode.spcNode == DEFAULTTABLESPACE_OID)
- {
- /* The default tablespace is {datadir}/base */
- if (backend == InvalidBackendId)
- {
- pathlen = 5 + OIDCHARS + 1 + OIDCHARS + 1 + FORKNAMECHARS + 1;
- path = (char *) palloc(pathlen);
- if (forknum != MAIN_FORKNUM)
- snprintf(path, pathlen, "base/%u/%u_%s",
- rnode.dbNode, rnode.relNode,
- forkNames[forknum]);
- else
- snprintf(path, pathlen, "base/%u/%u",
- rnode.dbNode, rnode.relNode);
- }
- else
- {
- /* OIDCHARS will suffice for an integer, too */
- pathlen = 5 + OIDCHARS + 2 + OIDCHARS + 1 + OIDCHARS + 1
- + FORKNAMECHARS + 1;
- path = (char *) palloc(pathlen);
- if (forknum != MAIN_FORKNUM)
- snprintf(path, pathlen, "base/%u/t%d_%u_%s",
- rnode.dbNode, backend, rnode.relNode,
- forkNames[forknum]);
- else
- snprintf(path, pathlen, "base/%u/t%d_%u",
- rnode.dbNode, backend, rnode.relNode);
- }
- }
- else
- {
- /* All other tablespaces are accessed via symlinks */
- if (backend == InvalidBackendId)
- {
- pathlen = 9 + 1 + OIDCHARS + 1
- + strlen(TABLESPACE_VERSION_DIRECTORY) + 1 + OIDCHARS + 1
- + OIDCHARS + 1 + FORKNAMECHARS + 1;
- path = (char *) palloc(pathlen);
- if (forknum != MAIN_FORKNUM)
- snprintf(path, pathlen, "pg_tblspc/%u/%s/%u/%u_%s",
- rnode.spcNode, TABLESPACE_VERSION_DIRECTORY,
- rnode.dbNode, rnode.relNode,
- forkNames[forknum]);
- else
- snprintf(path, pathlen, "pg_tblspc/%u/%s/%u/%u",
- rnode.spcNode, TABLESPACE_VERSION_DIRECTORY,
- rnode.dbNode, rnode.relNode);
- }
- else
- {
- /* OIDCHARS will suffice for an integer, too */
- pathlen = 9 + 1 + OIDCHARS + 1
- + strlen(TABLESPACE_VERSION_DIRECTORY) + 1 + OIDCHARS + 2
- + OIDCHARS + 1 + OIDCHARS + 1 + FORKNAMECHARS + 1;
- path = (char *) palloc(pathlen);
- if (forknum != MAIN_FORKNUM)
- snprintf(path, pathlen, "pg_tblspc/%u/%s/%u/t%d_%u_%s",
- rnode.spcNode, TABLESPACE_VERSION_DIRECTORY,
- rnode.dbNode, backend, rnode.relNode,
- forkNames[forknum]);
- else
- snprintf(path, pathlen, "pg_tblspc/%u/%s/%u/t%d_%u",
- rnode.spcNode, TABLESPACE_VERSION_DIRECTORY,
- rnode.dbNode, backend, rnode.relNode);
- }
- }
- return path;
-}
-
-/*
* GetDatabasePath - construct path to a database dir
*
* Result is a palloc'd string.
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 9bba75be1a2..7cad0cc969d 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -64,6 +64,7 @@
#include "commands/comment.h"
#include "commands/seclabel.h"
#include "commands/tablespace.h"
+#include "common/relpath.h"
#include "miscadmin.h"
#include "postmaster/bgwriter.h"
#include "storage/fd.h"
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 405ff61130e..ea7d469f2f4 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -34,6 +34,7 @@
#include <unistd.h>
#include "catalog/catalog.h"
+#include "common/relpath.h"
#include "executor/instrument.h"
#include "miscadmin.h"
#include "pg_trace.h"
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c
index df15789e6a6..30dc8098ed2 100644
--- a/src/backend/storage/buffer/localbuf.c
+++ b/src/backend/storage/buffer/localbuf.c
@@ -16,6 +16,7 @@
#include "postgres.h"
#include "catalog/catalog.h"
+#include "common/relpath.h"
#include "executor/instrument.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index ff7e221cde9..ba1b84eadef 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -71,6 +71,7 @@
#include "access/xact.h"
#include "catalog/catalog.h"
#include "catalog/pg_tablespace.h"
+#include "common/relpath.h"
#include "pgstat.h"
#include "storage/fd.h"
#include "storage/ipc.h"
diff --git a/src/backend/storage/file/reinit.c b/src/backend/storage/file/reinit.c
index 2623be8aeff..d62d5848a7a 100644
--- a/src/backend/storage/file/reinit.c
+++ b/src/backend/storage/file/reinit.c
@@ -17,6 +17,7 @@
#include <unistd.h>
#include "catalog/catalog.h"
+#include "common/relpath.h"
#include "storage/copydir.h"
#include "storage/fd.h"
#include "storage/reinit.h"
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 20eb36a85f9..7d567ae1103 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -21,6 +21,7 @@
#include "miscadmin.h"
#include "access/xlog.h"
#include "catalog/catalog.h"
+#include "common/relpath.h"
#include "portability/instr_time.h"
#include "postmaster/bgwriter.h"
#include "storage/fd.h"
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 89ad3868bac..11b004072f6 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -21,6 +21,7 @@
#include "catalog/pg_tablespace.h"
#include "commands/dbcommands.h"
#include "commands/tablespace.h"
+#include "common/relpath.h"
#include "miscadmin.h"
#include "storage/fd.h"
#include "utils/acl.h"
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index a36d065abf2..4e38d7c06c2 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -24,6 +24,7 @@
#include "catalog/pg_tablespace.h"
#include "catalog/pg_type.h"
#include "commands/dbcommands.h"
+#include "common/relpath.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "parser/keywords.h"
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index b9c03c31156..e85c7a98725 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -56,6 +56,7 @@
#include "catalog/schemapg.h"
#include "catalog/storage.h"
#include "commands/trigger.h"
+#include "common/relpath.h"
#include "miscadmin.h"
#include "optimizer/clauses.h"
#include "optimizer/planmain.h"