summaryrefslogtreecommitdiff
path: root/libs/fsys-wrapper.c
blob: f48db91a8ac2d1a110cc78f6b0f6affc98524928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

/* fsys.defs wrapper code.

   Copyright (C) 2008 Free Software Foundation, Inc.

   Written by FlĂvio Cruz <flaviocruz@gmail.com>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */

#include <mach/boolean.h>
#include <mach/kern_return.h>
#include <mach/message.h>
#include <mach/mig_errors.h>
#include <mach/mig_support.h>

#include <mach/std_types.h>
#include <mach/mach_types.h>
#include <device/device_types.h>
#include <device/net_status.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/resource.h>
#include <sys/utsname.h>
#include <hurd/hurd_types.h>

#include <stdio.h>
#include <assert.h>

#include "fsys-wrapper.h"

/* this is NULL initialized */
static void *routines[_NUMBER_OF_ROUTINES];

/* function wrappers follows... */

/* fsys startup */

typedef kern_return_t (*fsys_startup_type) (mach_port_t,
					    mach_port_t, mach_msg_type_name_t,
					    int, mach_port_t,
					    mach_port_t *,
					    mach_msg_type_name_t *);

kern_return_t
lisp_S_fsys_startup (mach_port_t bootstrap,
		   mach_port_t reply,
		   mach_msg_type_name_t replyPoly,
		   int openflags,
		   mach_port_t control_port,
		   mach_port_t * realnode,
		   mach_msg_type_name_t * realnodePoly)
{
  if (routines[FSYS_STARTUP] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_startup_type startup_routine = routines[FSYS_STARTUP];

  return startup_routine (bootstrap, reply, replyPoly, openflags,
			  control_port, realnode, realnodePoly);
}

/* fsys goaway */

typedef kern_return_t (*fsys_goaway_type) (fsys_t, mach_port_t,
					   mach_msg_type_name_t, int);

kern_return_t
lisp_S_fsys_goaway (fsys_t fsys, mach_port_t reply,
		  mach_msg_type_name_t replyPoly, int flags)
{
  if (routines[FSYS_GOAWAY] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_goaway_type goaway_routine = routines[FSYS_GOAWAY];

  return goaway_routine (fsys, reply, replyPoly, flags);
}

/* fsys getroot */

typedef kern_return_t (*fsys_getroot_type) (fsys_t,
					    mach_port_t,
					    mach_msg_type_name_t,
					    mach_port_t,
					    idarray_t,
					    mach_msg_type_number_t,
					    idarray_t,
					    mach_msg_type_number_t,
					    int, retry_type *,
					    string_t,
					    mach_port_t *,
					    mach_msg_type_name_t *);

kern_return_t
lisp_S_fsys_getroot (fsys_t fsys,
		   mach_port_t reply,
		   mach_msg_type_name_t replyPoly,
		   mach_port_t dotdot_node,
		   idarray_t gen_uids,
		   mach_msg_type_number_t gen_uidsCnt,
		   idarray_t gen_gids,
		   mach_msg_type_number_t gen_gidsCnt,
		   int flags,
		   retry_type * do_retry,
		   string_t retry_name,
		   mach_port_t * file, mach_msg_type_name_t * filePoly)
{
  if (routines[FSYS_GETROOT] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_getroot_type getroot_routine = routines[FSYS_GETROOT];

  return getroot_routine (fsys, reply, replyPoly,
			  dotdot_node,
			  gen_uids, gen_uidsCnt,
			  gen_gids, gen_gidsCnt,
			  flags, do_retry, retry_name, file, filePoly);
}

/* fsys getfile */

typedef kern_return_t (*fsys_getfile_type) (fsys_t,
					    mach_port_t,
					    mach_msg_type_name_t,
					    idarray_t,
					    mach_msg_type_number_t,
					    idarray_t,
					    mach_msg_type_number_t,
					    data_t,
					    mach_msg_type_number_t,
					    mach_port_t *,
					    mach_msg_type_name_t *);

kern_return_t
lisp_S_fsys_getfile (fsys_t fsys,
		   mach_port_t reply,
		   mach_msg_type_name_t replyPoly,
		   idarray_t gen_uids,
		   mach_msg_type_number_t gen_uidsCnt,
		   idarray_t gen_gids,
		   mach_msg_type_number_t gen_gidsCnt,
		   data_t filehandle,
		   mach_msg_type_number_t filehandleCnt,
		   mach_port_t * file, mach_msg_type_name_t * filePoly)
{
  if (routines[FSYS_GETFILE] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_getfile_type getfile_routine = routines[FSYS_GETFILE];

  return getfile_routine (fsys, reply, replyPoly,
			  gen_uids, gen_uidsCnt,
			  gen_gids, gen_gidsCnt,
			  filehandle, filehandleCnt, file, filePoly);
}

/* fsys syncfs */

typedef kern_return_t (*fsys_syncfs_type) (fsys_t,
					   mach_port_t, mach_msg_type_name_t,
					   int, int);

kern_return_t
lisp_S_fsys_syncfs (fsys_t fsys,
		  mach_port_t reply,
		  mach_msg_type_name_t replyPoly, int wait, int do_children)
{
  if (routines[FSYS_SYNCFS] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_syncfs_type syncfs_routine = routines[FSYS_SYNCFS];

  return syncfs_routine (fsys, reply, replyPoly, wait, do_children);
}

/* fsys set options */

typedef kern_return_t (*fsys_set_options_type) (fsys_t,
						mach_port_t,
						mach_msg_type_name_t, data_t,
						mach_msg_type_number_t, int);

kern_return_t
lisp_S_fsys_set_options (fsys_t fsys,
		       mach_port_t reply,
		       mach_msg_type_name_t replyPoly,
		       data_t options,
		       mach_msg_type_number_t optionsCnt, int do_children)
{
  if (routines[FSYS_SET_OPTIONS] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_set_options_type set_options_routine = routines[FSYS_SET_OPTIONS];

  return set_options_routine (fsys, reply, replyPoly,
			      options, optionsCnt, do_children);
}

/* fsys getpriv */

typedef kern_return_t (*fsys_getpriv_type) (fsys_t,
					    mach_port_t,
					    mach_msg_type_name_t,
					    mach_port_t *,
					    mach_msg_type_name_t *,
					    mach_port_t *,
					    mach_msg_type_name_t *,
					    mach_port_t *,
					    mach_msg_type_name_t *);

kern_return_t
lisp_S_fsys_getpriv (fsys_t fsys,
		   mach_port_t reply,
		   mach_msg_type_name_t replyPoly,
		   mach_port_t * host_priv,
		   mach_msg_type_name_t * host_privPoly,
		   mach_port_t * device_master,
		   mach_msg_type_name_t * device_masterPoly,
		   mach_port_t * fstask, mach_msg_type_name_t * fstaskPoly)
{
  if (routines[FSYS_GETPRIV] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_getpriv_type getpriv_routine = routines[FSYS_GETPRIV];

  return getpriv_routine (fsys, reply, replyPoly,
			  host_priv,
			  host_privPoly, device_master,
			  device_masterPoly, fstask, fstaskPoly);
}

/* fsys init */

typedef kern_return_t (*fsys_init_type) (fsys_t,
					 mach_port_t, mach_msg_type_name_t,
					 mach_port_t, auth_t);

kern_return_t
lisp_S_fsys_init (fsys_t fsys,
		mach_port_t reply_port,
		mach_msg_type_name_t reply_portPoly,
		mach_port_t proc_server, auth_t auth_handle)
{
  if (routines[FSYS_INIT] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_init_type init_routine = routines[FSYS_INIT];

  return init_routine (fsys, reply_port, reply_portPoly,
		       proc_server, auth_handle);
}

/* fsys forward */

typedef kern_return_t (*fsys_forward_type) (mach_port_t,
					    mach_port_t, mach_msg_type_name_t,
					    mach_port_t, data_t,
					    mach_msg_type_number_t);

kern_return_t
lisp_S_fsys_forward (mach_port_t server,
		   mach_port_t reply,
		   mach_msg_type_name_t replyPoly,
		   mach_port_t requestor,
		   data_t argv, mach_msg_type_number_t argvCnt)
{
  if (routines[FSYS_FORWARD] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_forward_type forward_routine = routines[FSYS_FORWARD];

  return forward_routine (server, reply, replyPoly, requestor, argv, argvCnt);
}

/* fsys get options */

typedef kern_return_t (*fsys_get_options_type) (fsys_t,
						mach_port_t,
						mach_msg_type_name_t,
						data_t *,
						mach_msg_type_number_t *);

kern_return_t
lisp_S_fsys_get_options (fsys_t server,
		       mach_port_t reply,
		       mach_msg_type_name_t replyPoly,
		       data_t * options, mach_msg_type_number_t * optionsCnt)
{
  if (routines[FSYS_GET_OPTIONS] == NULL)
    {
      return EOPNOTSUPP;
    }

  fsys_get_options_type get_options_routine = routines[FSYS_GET_OPTIONS];

  return get_options_routine (server, reply, replyPoly, options, optionsCnt);
}


static const char *
routine_to_str (const FsysRoutine rot)
{
#define RET(val) case val: return #val ;
  switch (rot)
    {
    RET (FSYS_STARTUP)
    RET (FSYS_GOAWAY)
    RET (FSYS_GETROOT)
    RET (FSYS_GETFILE)
    RET (FSYS_SYNCFS)
    RET (FSYS_SET_OPTIONS)
    RET (FSYS_GETPRIV)
    RET (FSYS_INIT)
    RET (FSYS_FORWARD)
    RET (FSYS_GET_OPTIONS)
    case _NUMBER_OF_ROUTINES:
    default:
      return "";
    }

#undef RET
}

#include "common.c"

COMMON_FUNCTIONS (fsys);