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