db_pipes.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "pipe:" or "pipe.srv:".
  17. */
  18. #include "api.h"
  19. #include "pal.h"
  20. #include "pal_debug.h"
  21. #include "pal_defs.h"
  22. #include "pal_error.h"
  23. #include "pal_internal.h"
  24. static int pipe_listen(PAL_HANDLE* handle, PAL_NUM pipeid, int create) {
  25. return -PAL_ERROR_NOTIMPLEMENTED;
  26. }
  27. static int pipe_waitforclient(PAL_HANDLE handle, PAL_HANDLE* client) {
  28. return -PAL_ERROR_NOTIMPLEMENTED;
  29. }
  30. static int pipe_connect(PAL_HANDLE* handle, PAL_NUM pipeid, PAL_IDX connid, int create) {
  31. return -PAL_ERROR_NOTIMPLEMENTED;
  32. }
  33. static int pipe_private(PAL_HANDLE* handle) {
  34. return -PAL_ERROR_NOTIMPLEMENTED;
  35. }
  36. /* 'open' operation of pipe stream. For each pipe stream, it is identified by a decimal number in
  37. URI. There could be two types: pipe and pipe.srv. They behave pretty much the same, except they
  38. are two ends of the pipe. */
  39. static int pipe_open(PAL_HANDLE* handle, const char* type, const char* uri, int access, int share,
  40. int create, int options) {
  41. if (!strcmp_static(type, URI_TYPE_PIPE) && !*uri)
  42. return pipe_private(handle);
  43. char* endptr;
  44. PAL_NUM pipeid = strtol(uri, &endptr, 10);
  45. PAL_IDX connid = 0;
  46. if (*endptr == ':') {
  47. if (create & PAL_CREATE_TRY)
  48. return -PAL_ERROR_INVAL;
  49. connid = strtol(endptr + 1, &endptr, 10);
  50. }
  51. if (*endptr)
  52. return -PAL_ERROR_INVAL;
  53. if (!strcmp_static(type, URI_TYPE_PIPE_SRV))
  54. return pipe_listen(handle, pipeid, create);
  55. if (!strcmp_static(type, URI_TYPE_PIPE))
  56. return pipe_connect(handle, pipeid, connid, create);
  57. return -PAL_ERROR_INVAL;
  58. }
  59. /* 'read' operation of pipe stream. offset does not apply here. */
  60. static int64_t pipe_read(PAL_HANDLE handle, uint64_t offset, uint64_t len, void* buffer) {
  61. return -PAL_ERROR_NOTIMPLEMENTED;
  62. }
  63. /* 'write' operation of pipe stream. offset does not apply here. */
  64. static int64_t pipe_write(PAL_HANDLE handle, uint64_t offset, uint64_t len, const void* buffer) {
  65. return -PAL_ERROR_NOTIMPLEMENTED;
  66. }
  67. /* 'close' operation of pipe stream. */
  68. static int pipe_close(PAL_HANDLE handle) {
  69. return -PAL_ERROR_NOTIMPLEMENTED;
  70. }
  71. /* 'delete' operation of pipe stream. */
  72. static int pipe_delete(PAL_HANDLE handle, int access) {
  73. return -PAL_ERROR_NOTIMPLEMENTED;
  74. }
  75. static int pipe_getname(PAL_HANDLE handle, char* buffer, size_t count) {
  76. return -PAL_ERROR_NOTIMPLEMENTED;
  77. }
  78. struct handle_ops pipe_ops = {
  79. .getname = &pipe_getname,
  80. .open = &pipe_open,
  81. .waitforclient = &pipe_waitforclient,
  82. .read = &pipe_read,
  83. .write = &pipe_write,
  84. .close = &pipe_close,
  85. .delete = &pipe_delete,
  86. };
  87. struct handle_ops pipeprv_ops = {
  88. .open = &pipe_open,
  89. .read = &pipe_read,
  90. .write = &pipe_write,
  91. .close = &pipe_close,
  92. };