db_pipes.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * db_pipes.c
  15. *
  16. * This file contains oeprands to handle streams with URIs that start with
  17. * "pipe:" or "pipe.srv:".
  18. */
  19. #include "pal_defs.h"
  20. #include "pal.h"
  21. #include "pal_internal.h"
  22. #include "pal_error.h"
  23. #include "pal_debug.h"
  24. #include "api.h"
  25. static int pipe_listen (PAL_HANDLE * handle, PAL_NUM pipeid, int create)
  26. {
  27. return -PAL_ERROR_NOTIMPLEMENTED;
  28. }
  29. static int pipe_waitforclient (PAL_HANDLE handle, PAL_HANDLE *client)
  30. {
  31. return -PAL_ERROR_NOTIMPLEMENTED;
  32. }
  33. static int pipe_connect (PAL_HANDLE * handle, PAL_NUM pipeid, PAL_IDX connid,
  34. int create)
  35. {
  36. return -PAL_ERROR_NOTIMPLEMENTED;
  37. }
  38. static int pipe_private (PAL_HANDLE * handle)
  39. {
  40. return -PAL_ERROR_NOTIMPLEMENTED;
  41. }
  42. /* 'open' operation of pipe stream. For each pipe stream, it is
  43. identified by a decimal number in URI. There could be two
  44. types: pipe and pipe.srv. They behave pretty much the same,
  45. except they are two ends of the pipe. */
  46. static int pipe_open (PAL_HANDLE *handle, const char * type,
  47. const char * uri, int access, int share,
  48. int create, int options)
  49. {
  50. if (strcmp_static(type, "pipe") && !*uri)
  51. return pipe_private(handle);
  52. char * endptr;
  53. PAL_NUM pipeid = strtol(uri, &endptr, 10);
  54. PAL_IDX connid = 0;
  55. if (*endptr == ':') {
  56. if (create & PAL_CREATE_TRY)
  57. return -PAL_ERROR_INVAL;
  58. connid = strtol(endptr + 1, &endptr, 10);
  59. }
  60. if (*endptr)
  61. return -PAL_ERROR_INVAL;
  62. if (strcmp_static(type, "pipe.srv"))
  63. return pipe_listen(handle, pipeid, create);
  64. if (strcmp_static(type, "pipe"))
  65. return pipe_connect(handle, pipeid, connid, create);
  66. return -PAL_ERROR_INVAL;
  67. }
  68. /* 'read' operation of pipe stream. offset does not apply here. */
  69. static int64_t pipe_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
  70. void * buffer)
  71. {
  72. return -PAL_ERROR_NOTIMPLEMENTED;
  73. }
  74. /* 'write' operation of pipe stream. offset does not apply here. */
  75. static int64_t pipe_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
  76. const void * buffer)
  77. {
  78. return -PAL_ERROR_NOTIMPLEMENTED;
  79. }
  80. /* 'close' operation of pipe stream. */
  81. static int pipe_close (PAL_HANDLE handle)
  82. {
  83. return -PAL_ERROR_NOTIMPLEMENTED;
  84. }
  85. /* 'delete' operation of pipe stream. */
  86. static int pipe_delete (PAL_HANDLE handle, int access)
  87. {
  88. return -PAL_ERROR_NOTIMPLEMENTED;
  89. }
  90. static int pipe_getname (PAL_HANDLE handle, char * buffer, size_t count)
  91. {
  92. return -PAL_ERROR_NOTIMPLEMENTED;
  93. }
  94. struct handle_ops pipe_ops = {
  95. .getname = &pipe_getname,
  96. .open = &pipe_open,
  97. .waitforclient = &pipe_waitforclient,
  98. .read = &pipe_read,
  99. .write = &pipe_write,
  100. .close = &pipe_close,
  101. .delete = &pipe_delete,
  102. };
  103. struct handle_ops pipeprv_ops = {
  104. .open = &pipe_open,
  105. .read = &pipe_read,
  106. .write = &pipe_write,
  107. .close = &pipe_close,
  108. };