1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* smgrtype.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* storage manager type
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2003-11-29 20:52:15 +01:00
|
|
|
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgrtype.c,v 1.22 2003/11/29 19:51:57 pgsql Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "storage/smgr.h"
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct smgrid
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *smgr_name;
|
1997-09-08 23:56:23 +02:00
|
|
|
} smgrid;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* StorageManager[] -- List of defined storage managers.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* The weird comma placement is to keep compilers happy no matter
|
|
|
|
* which of these is (or is not) defined.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
static smgrid StorageManager[] = {
|
1996-07-09 08:22:35 +02:00
|
|
|
{"magnetic disk"},
|
1998-06-23 17:35:48 +02:00
|
|
|
#ifdef STABLE_MEMORY_STORAGE
|
1996-07-09 08:22:35 +02:00
|
|
|
{"main memory"}
|
1998-06-23 17:35:48 +02:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
};
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
static int NStorageManagers = lengthof(StorageManager);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
smgrin(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
char *s = PG_GETARG_CSTRING(0);
|
|
|
|
int16 i;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
for (i = 0; i < NStorageManagers; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(s, StorageManager[i].smgr_name) == 0)
|
2000-06-05 09:29:25 +02:00
|
|
|
PG_RETURN_INT16(i);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
2003-07-25 00:04:15 +02:00
|
|
|
elog(ERROR, "unrecognized storage manager name \"%s\"", s);
|
2000-06-05 09:29:25 +02:00
|
|
|
PG_RETURN_INT16(0);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
smgrout(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
int16 i = PG_GETARG_INT16(0);
|
1997-09-08 04:41:22 +02:00
|
|
|
char *s;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (i >= NStorageManagers || i < 0)
|
2003-07-25 00:04:15 +02:00
|
|
|
elog(ERROR, "invalid storage manager id: %d", i);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
s = pstrdup(StorageManager[i].smgr_name);
|
|
|
|
PG_RETURN_CSTRING(s);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
smgreq(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
int16 a = PG_GETARG_INT16(0);
|
|
|
|
int16 b = PG_GETARG_INT16(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(a == b);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
smgrne(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
int16 a = PG_GETARG_INT16(0);
|
|
|
|
int16 b = PG_GETARG_INT16(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(a != b);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|