db_pipes.c 4.0 KB

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