1 /*-------------------------------------------------------------------------
2  *
3  * smgrtype.c
4  *	  storage manager type
5  *
6  * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *	  src/backend/storage/smgr/smgrtype.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include "storage/smgr.h"
18 
19 
20 typedef struct smgrid
21 {
22 	const char *smgr_name;
23 } smgrid;
24 
25 /*
26  *	StorageManager[] -- List of defined storage managers.
27  */
28 static const smgrid StorageManager[] = {
29 	{"magnetic disk"}
30 };
31 
32 static const int NStorageManagers = lengthof(StorageManager);
33 
34 
35 Datum
smgrin(PG_FUNCTION_ARGS)36 smgrin(PG_FUNCTION_ARGS)
37 {
38 	char	   *s = PG_GETARG_CSTRING(0);
39 	int16		i;
40 
41 	for (i = 0; i < NStorageManagers; i++)
42 	{
43 		if (strcmp(s, StorageManager[i].smgr_name) == 0)
44 			PG_RETURN_INT16(i);
45 	}
46 	elog(ERROR, "unrecognized storage manager name \"%s\"", s);
47 	PG_RETURN_INT16(0);
48 }
49 
50 Datum
smgrout(PG_FUNCTION_ARGS)51 smgrout(PG_FUNCTION_ARGS)
52 {
53 	int16		i = PG_GETARG_INT16(0);
54 	char	   *s;
55 
56 	if (i >= NStorageManagers || i < 0)
57 		elog(ERROR, "invalid storage manager ID: %d", i);
58 
59 	s = pstrdup(StorageManager[i].smgr_name);
60 	PG_RETURN_CSTRING(s);
61 }
62 
63 Datum
smgreq(PG_FUNCTION_ARGS)64 smgreq(PG_FUNCTION_ARGS)
65 {
66 	int16		a = PG_GETARG_INT16(0);
67 	int16		b = PG_GETARG_INT16(1);
68 
69 	PG_RETURN_BOOL(a == b);
70 }
71 
72 Datum
smgrne(PG_FUNCTION_ARGS)73 smgrne(PG_FUNCTION_ARGS)
74 {
75 	int16		a = PG_GETARG_INT16(0);
76 	int16		b = PG_GETARG_INT16(1);
77 
78 	PG_RETURN_BOOL(a != b);
79 }
80