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 smgrin(PG_FUNCTION_ARGS)37smgrin(PG_FUNCTION_ARGS) 38 { 39 char *s = PG_GETARG_CSTRING(0); 40 int16 i; 41 42 for (i = 0; i < NStorageManagers; i++) 43 { 44 if (strcmp(s, StorageManager[i].smgr_name) == 0) 45 PG_RETURN_INT16(i); 46 } 47 elog(ERROR, "unrecognized storage manager name \"%s\"", s); 48 PG_RETURN_INT16(0); 49 } 50 51 Datum smgrout(PG_FUNCTION_ARGS)52smgrout(PG_FUNCTION_ARGS) 53 { 54 int16 i = PG_GETARG_INT16(0); 55 char *s; 56 57 if (i >= NStorageManagers || i < 0) 58 elog(ERROR, "invalid storage manager ID: %d", i); 59 60 s = pstrdup(StorageManager[i].smgr_name); 61 PG_RETURN_CSTRING(s); 62 } 63 64 Datum smgreq(PG_FUNCTION_ARGS)65smgreq(PG_FUNCTION_ARGS) 66 { 67 int16 a = PG_GETARG_INT16(0); 68 int16 b = PG_GETARG_INT16(1); 69 70 PG_RETURN_BOOL(a == b); 71 } 72 73 Datum smgrne(PG_FUNCTION_ARGS)74smgrne(PG_FUNCTION_ARGS) 75 { 76 int16 a = PG_GETARG_INT16(0); 77 int16 b = PG_GETARG_INT16(1); 78 79 PG_RETURN_BOOL(a != b); 80 } 81