fsys-wrapper.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /* fsys.defs wrapper code.
  2. Copyright (C) 2008 Free Software Foundation, Inc.
  3. Written by FlÃvio Cruz <flaviocruz@gmail.com>
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include <mach/boolean.h>
  16. #include <mach/kern_return.h>
  17. #include <mach/message.h>
  18. #include <mach/mig_errors.h>
  19. #include <mach/mig_support.h>
  20. #include <mach/std_types.h>
  21. #include <mach/mach_types.h>
  22. #include <device/device_types.h>
  23. #include <device/net_status.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/statfs.h>
  27. #include <sys/resource.h>
  28. #include <sys/utsname.h>
  29. #include <hurd/hurd_types.h>
  30. #include <stdio.h>
  31. #include <assert.h>
  32. #include "fsys-wrapper.h"
  33. /* this is NULL initialized */
  34. static void *routines[_NUMBER_OF_ROUTINES];
  35. /* function wrappers follows... */
  36. /* fsys startup */
  37. typedef kern_return_t (*fsys_startup_type) (mach_port_t,
  38. mach_port_t, mach_msg_type_name_t,
  39. int, mach_port_t,
  40. mach_port_t *,
  41. mach_msg_type_name_t *);
  42. kern_return_t
  43. lisp_S_fsys_startup (mach_port_t bootstrap,
  44. mach_port_t reply,
  45. mach_msg_type_name_t replyPoly,
  46. int openflags,
  47. mach_port_t control_port,
  48. mach_port_t * realnode,
  49. mach_msg_type_name_t * realnodePoly)
  50. {
  51. if (routines[FSYS_STARTUP] == NULL)
  52. {
  53. return EOPNOTSUPP;
  54. }
  55. fsys_startup_type startup_routine = routines[FSYS_STARTUP];
  56. return startup_routine (bootstrap, reply, replyPoly, openflags,
  57. control_port, realnode, realnodePoly);
  58. }
  59. /* fsys goaway */
  60. typedef kern_return_t (*fsys_goaway_type) (fsys_t, mach_port_t,
  61. mach_msg_type_name_t, int);
  62. kern_return_t
  63. lisp_S_fsys_goaway (fsys_t fsys, mach_port_t reply,
  64. mach_msg_type_name_t replyPoly, int flags)
  65. {
  66. if (routines[FSYS_GOAWAY] == NULL)
  67. {
  68. return EOPNOTSUPP;
  69. }
  70. fsys_goaway_type goaway_routine = routines[FSYS_GOAWAY];
  71. return goaway_routine (fsys, reply, replyPoly, flags);
  72. }
  73. /* fsys getroot */
  74. typedef kern_return_t (*fsys_getroot_type) (fsys_t,
  75. mach_port_t,
  76. mach_msg_type_name_t,
  77. mach_port_t,
  78. idarray_t,
  79. mach_msg_type_number_t,
  80. idarray_t,
  81. mach_msg_type_number_t,
  82. int, retry_type *,
  83. string_t,
  84. mach_port_t *,
  85. mach_msg_type_name_t *);
  86. kern_return_t
  87. lisp_S_fsys_getroot (fsys_t fsys,
  88. mach_port_t reply,
  89. mach_msg_type_name_t replyPoly,
  90. mach_port_t dotdot_node,
  91. idarray_t gen_uids,
  92. mach_msg_type_number_t gen_uidsCnt,
  93. idarray_t gen_gids,
  94. mach_msg_type_number_t gen_gidsCnt,
  95. int flags,
  96. retry_type * do_retry,
  97. string_t retry_name,
  98. mach_port_t * file, mach_msg_type_name_t * filePoly)
  99. {
  100. if (routines[FSYS_GETROOT] == NULL)
  101. {
  102. return EOPNOTSUPP;
  103. }
  104. fsys_getroot_type getroot_routine = routines[FSYS_GETROOT];
  105. return getroot_routine (fsys, reply, replyPoly,
  106. dotdot_node,
  107. gen_uids, gen_uidsCnt,
  108. gen_gids, gen_gidsCnt,
  109. flags, do_retry, retry_name, file, filePoly);
  110. }
  111. /* fsys getfile */
  112. typedef kern_return_t (*fsys_getfile_type) (fsys_t,
  113. mach_port_t,
  114. mach_msg_type_name_t,
  115. idarray_t,
  116. mach_msg_type_number_t,
  117. idarray_t,
  118. mach_msg_type_number_t,
  119. data_t,
  120. mach_msg_type_number_t,
  121. mach_port_t *,
  122. mach_msg_type_name_t *);
  123. kern_return_t
  124. lisp_S_fsys_getfile (fsys_t fsys,
  125. mach_port_t reply,
  126. mach_msg_type_name_t replyPoly,
  127. idarray_t gen_uids,
  128. mach_msg_type_number_t gen_uidsCnt,
  129. idarray_t gen_gids,
  130. mach_msg_type_number_t gen_gidsCnt,
  131. data_t filehandle,
  132. mach_msg_type_number_t filehandleCnt,
  133. mach_port_t * file, mach_msg_type_name_t * filePoly)
  134. {
  135. if (routines[FSYS_GETFILE] == NULL)
  136. {
  137. return EOPNOTSUPP;
  138. }
  139. fsys_getfile_type getfile_routine = routines[FSYS_GETFILE];
  140. return getfile_routine (fsys, reply, replyPoly,
  141. gen_uids, gen_uidsCnt,
  142. gen_gids, gen_gidsCnt,
  143. filehandle, filehandleCnt, file, filePoly);
  144. }
  145. /* fsys syncfs */
  146. typedef kern_return_t (*fsys_syncfs_type) (fsys_t,
  147. mach_port_t, mach_msg_type_name_t,
  148. int, int);
  149. kern_return_t
  150. lisp_S_fsys_syncfs (fsys_t fsys,
  151. mach_port_t reply,
  152. mach_msg_type_name_t replyPoly, int wait, int do_children)
  153. {
  154. if (routines[FSYS_SYNCFS] == NULL)
  155. {
  156. return EOPNOTSUPP;
  157. }
  158. fsys_syncfs_type syncfs_routine = routines[FSYS_SYNCFS];
  159. return syncfs_routine (fsys, reply, replyPoly, wait, do_children);
  160. }
  161. /* fsys set options */
  162. typedef kern_return_t (*fsys_set_options_type) (fsys_t,
  163. mach_port_t,
  164. mach_msg_type_name_t, data_t,
  165. mach_msg_type_number_t, int);
  166. kern_return_t
  167. lisp_S_fsys_set_options (fsys_t fsys,
  168. mach_port_t reply,
  169. mach_msg_type_name_t replyPoly,
  170. data_t options,
  171. mach_msg_type_number_t optionsCnt, int do_children)
  172. {
  173. if (routines[FSYS_SET_OPTIONS] == NULL)
  174. {
  175. return EOPNOTSUPP;
  176. }
  177. fsys_set_options_type set_options_routine = routines[FSYS_SET_OPTIONS];
  178. return set_options_routine (fsys, reply, replyPoly,
  179. options, optionsCnt, do_children);
  180. }
  181. /* fsys getpriv */
  182. typedef kern_return_t (*fsys_getpriv_type) (fsys_t,
  183. mach_port_t,
  184. mach_msg_type_name_t,
  185. mach_port_t *,
  186. mach_msg_type_name_t *,
  187. mach_port_t *,
  188. mach_msg_type_name_t *,
  189. mach_port_t *,
  190. mach_msg_type_name_t *);
  191. kern_return_t
  192. lisp_S_fsys_getpriv (fsys_t fsys,
  193. mach_port_t reply,
  194. mach_msg_type_name_t replyPoly,
  195. mach_port_t * host_priv,
  196. mach_msg_type_name_t * host_privPoly,
  197. mach_port_t * device_master,
  198. mach_msg_type_name_t * device_masterPoly,
  199. mach_port_t * fstask, mach_msg_type_name_t * fstaskPoly)
  200. {
  201. if (routines[FSYS_GETPRIV] == NULL)
  202. {
  203. return EOPNOTSUPP;
  204. }
  205. fsys_getpriv_type getpriv_routine = routines[FSYS_GETPRIV];
  206. return getpriv_routine (fsys, reply, replyPoly,
  207. host_priv,
  208. host_privPoly, device_master,
  209. device_masterPoly, fstask, fstaskPoly);
  210. }
  211. /* fsys init */
  212. typedef kern_return_t (*fsys_init_type) (fsys_t,
  213. mach_port_t, mach_msg_type_name_t,
  214. mach_port_t, auth_t);
  215. kern_return_t
  216. lisp_S_fsys_init (fsys_t fsys,
  217. mach_port_t reply_port,
  218. mach_msg_type_name_t reply_portPoly,
  219. mach_port_t proc_server, auth_t auth_handle)
  220. {
  221. if (routines[FSYS_INIT] == NULL)
  222. {
  223. return EOPNOTSUPP;
  224. }
  225. fsys_init_type init_routine = routines[FSYS_INIT];
  226. return init_routine (fsys, reply_port, reply_portPoly,
  227. proc_server, auth_handle);
  228. }
  229. /* fsys forward */
  230. typedef kern_return_t (*fsys_forward_type) (mach_port_t,
  231. mach_port_t, mach_msg_type_name_t,
  232. mach_port_t, data_t,
  233. mach_msg_type_number_t);
  234. kern_return_t
  235. lisp_S_fsys_forward (mach_port_t server,
  236. mach_port_t reply,
  237. mach_msg_type_name_t replyPoly,
  238. mach_port_t requestor,
  239. data_t argv, mach_msg_type_number_t argvCnt)
  240. {
  241. if (routines[FSYS_FORWARD] == NULL)
  242. {
  243. return EOPNOTSUPP;
  244. }
  245. fsys_forward_type forward_routine = routines[FSYS_FORWARD];
  246. return forward_routine (server, reply, replyPoly, requestor, argv, argvCnt);
  247. }
  248. /* fsys get options */
  249. typedef kern_return_t (*fsys_get_options_type) (fsys_t,
  250. mach_port_t,
  251. mach_msg_type_name_t,
  252. data_t *,
  253. mach_msg_type_number_t *);
  254. kern_return_t
  255. lisp_S_fsys_get_options (fsys_t server,
  256. mach_port_t reply,
  257. mach_msg_type_name_t replyPoly,
  258. data_t * options, mach_msg_type_number_t * optionsCnt)
  259. {
  260. if (routines[FSYS_GET_OPTIONS] == NULL)
  261. {
  262. return EOPNOTSUPP;
  263. }
  264. fsys_get_options_type get_options_routine = routines[FSYS_GET_OPTIONS];
  265. return get_options_routine (server, reply, replyPoly, options, optionsCnt);
  266. }
  267. static const char *
  268. routine_to_str (const FsysRoutine rot)
  269. {
  270. #define RET(val) case val: return #val ;
  271. switch (rot)
  272. {
  273. RET (FSYS_STARTUP)
  274. RET (FSYS_GOAWAY)
  275. RET (FSYS_GETROOT)
  276. RET (FSYS_GETFILE)
  277. RET (FSYS_SYNCFS)
  278. RET (FSYS_SET_OPTIONS)
  279. RET (FSYS_GETPRIV)
  280. RET (FSYS_INIT)
  281. RET (FSYS_FORWARD)
  282. RET (FSYS_GET_OPTIONS)
  283. case _NUMBER_OF_ROUTINES:
  284. default:
  285. return "";
  286. }
  287. #undef RET
  288. }
  289. #include "common.c"
  290. COMMON_FUNCTIONS (fsys);