geom_gate userland utility improvements
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

145 lines
4.1 KiB

  1. /*-
  2. * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. *
  26. * $FreeBSD$
  27. */
  28. #ifndef _GGATE_H_
  29. #define _GGATE_H_
  30. #include <sys/endian.h>
  31. #include <stdarg.h>
  32. #define G_GATE_BUFSIZE_START 65536
  33. #define G_GATE_PORT 3080
  34. #define G_GATE_RCVBUF 131072
  35. #define G_GATE_SNDBUF 131072
  36. #define G_GATE_QUEUE_SIZE 1024
  37. #define G_GATE_TIMEOUT 30
  38. extern int g_gate_devfd;
  39. extern int g_gate_verbose;
  40. /* Client's initial packet. */
  41. struct g_gate_cinit {
  42. char gc_path[PATH_MAX + 1];
  43. uint8_t gc_flags;
  44. };
  45. /* Server's initial packet. */
  46. struct g_gate_sinit {
  47. uint8_t gs_flags;
  48. uint64_t gs_mediasize;
  49. uint32_t gs_sectorsize;
  50. uint16_t gs_error;
  51. };
  52. /* Control struct. */
  53. struct g_gate_hdr {
  54. uint8_t gh_cmd; /* command */
  55. uint64_t gh_offset; /* device offset */
  56. uint32_t gh_length; /* size of block */
  57. int16_t gh_error; /* error value (0 if ok) */
  58. };
  59. void g_gate_vlog(int priority, const char *message, va_list ap);
  60. void g_gate_log(int priority, const char *message, ...);
  61. void g_gate_xvlog(const char *message, va_list ap);
  62. void g_gate_xlog(const char *message, ...);
  63. off_t g_gate_mediasize(int fd);
  64. size_t g_gate_sectorsize(int fd);
  65. void g_gate_open_device(void);
  66. void g_gate_close_device(void);
  67. void g_gate_ioctl(unsigned long req, void *data);
  68. void g_gate_destroy(int unit, int force);
  69. int g_gate_openflags(unsigned ggflags);
  70. void g_gate_load_module(void);
  71. #ifdef LIBGEOM
  72. void g_gate_list(int unit, int verbose);
  73. #endif
  74. in_addr_t g_gate_str2ip(const char *str);
  75. /*
  76. * g_gate_swap2h_* - functions swap bytes to host byte order (from big endian).
  77. * g_gate_swap2n_* - functions swap bytes to network byte order (actually
  78. * to big endian byte order).
  79. */
  80. static __inline void
  81. g_gate_swap2h_cinit(struct g_gate_cinit *cinit __unused)
  82. {
  83. /* Nothing here for now. */
  84. }
  85. static __inline void
  86. g_gate_swap2n_cinit(struct g_gate_cinit *cinit __unused)
  87. {
  88. /* Nothing here for now. */
  89. }
  90. static __inline void
  91. g_gate_swap2h_sinit(struct g_gate_sinit *sinit)
  92. {
  93. /* Swap only used fields. */
  94. sinit->gs_mediasize = be64toh(sinit->gs_mediasize);
  95. sinit->gs_sectorsize = be32toh(sinit->gs_sectorsize);
  96. sinit->gs_error = be16toh(sinit->gs_error);
  97. }
  98. static __inline void
  99. g_gate_swap2n_sinit(struct g_gate_sinit *sinit)
  100. {
  101. /* Swap only used fields. */
  102. sinit->gs_mediasize = htobe64(sinit->gs_mediasize);
  103. sinit->gs_sectorsize = htobe32(sinit->gs_sectorsize);
  104. sinit->gs_error = htobe16(sinit->gs_error);
  105. }
  106. static __inline void
  107. g_gate_swap2h_hdr(struct g_gate_hdr *hdr)
  108. {
  109. /* Swap only used fields. */
  110. hdr->gh_offset = be64toh(hdr->gh_offset);
  111. hdr->gh_length = be32toh(hdr->gh_length);
  112. hdr->gh_error = be16toh(hdr->gh_error);
  113. }
  114. static __inline void
  115. g_gate_swap2n_hdr(struct g_gate_hdr *hdr)
  116. {
  117. /* Swap only used fields. */
  118. hdr->gh_offset = htobe64(hdr->gh_offset);
  119. hdr->gh_length = htobe32(hdr->gh_length);
  120. hdr->gh_error = htobe16(hdr->gh_error);
  121. }
  122. #endif /* _GGATE_H_ */