Subversion Repositories shark

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/*
22
 * Copyright (C) 1999 Massimiliano Giorgi
23
 *
24
 * This program is free software; you can redistribute it and/or modify
25
 * it under the terms of the GNU General Public License as published by
26
 * the Free Software Foundation; either version 2 of the License, or
27
 * (at your option) any later version.
28
 *
29
 * This program is distributed in the hope that it will be useful,
30
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
 * GNU General Public License for more details.
33
 *
34
 * You should have received a copy of the GNU General Public License
35
 * along with this program; if not, write to the Free Software
36
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
37
 *
38
 */
39
 
40
/*
41
 * CVS :        $Id: wrappers.c,v 1.1.1.1 2002-03-29 14:12:53 pj Exp $
42
 *
43
 * File:        $File$
44
 * Revision:    $Revision: 1.1.1.1 $
45
 * Last update: $Date: 2002-03-29 14:12:53 $
46
 */
47
 
48
#include <kernel/model.h>
49
 
50
#include <fs/types.h>
51
#include <fs/const.h>
52
#include <fs/stdarg.h>
53
#include <fs/syscall.h>
54
#include <fs/errno.h>
55
#include <fs/limits.h>
56
#include <fs/fcntl.h>
57
#include <fs/stat.h>
58
#include <fs/dirent.h>
59
#include <fs/mount.h>
60
 
61
#include "errno.h"
62
#include "mutex.h"
63
 
64
static NOP_mutexattr_t libio_mutexattr=NOP_MUTEXATTR_INITIALIZER;
65
mutexattr_t *libio_mutexattrptr=&libio_mutexattr;
66
 
67
int libio_initialize(void)
68
{
69
  extern int dir_initialize(void);  
70
  return dir_initialize();
71
}
72
 
73
/*
74
 *
75
 * SYSTEM CALLS
76
 *
77
 */
78
 
79
 
80
 
81
 
82
extern int k_open(const char *pathname, int oflag, int mode);
83
 
84
int open(const char *pathname, int oflag, ...)    
85
{
86
  int mode=0;
87
  int res;
88
 
89
  if (oflag & O_CREAT){
90
    va_list arg;
91
    va_start(arg, oflag);
92
    mode=va_arg(arg,int);
93
    va_end(arg);
94
  }
95
 
96
  res=SYS_CALL3(k_open,pathname,oflag,mode);
97
 
98
  if (ISERROR(res)) {
99
    __set_errno(-res);
100
    return -1;
101
  }
102
  return res;
103
}
104
 
105
/* --- */
106
 
107
 
108
/* --- */
109
 
110
/*
111
extern __ssize_t k_read(int fd, __ptr_t buf, __ssize_t nbytes);
112
 
113
__ssize_t read(int fd, __ptr_t buf, __ssize_t nbytes)
114
{
115
  int res;
116
 
117
  res=SYS_CALL3(k_read,fd,buf,nbytes);
118
 
119
  if (ISERROR(res)) {
120
    __set_errno(-res);
121
    return -1;
122
  }
123
  return res;
124
}
125
 
126
extern __ssize_t k_write(int fd, __ptr_t buf, __ssize_t nbytes);
127
 
128
__ssize_t write(int fd, __ptr_t buf, __ssize_t nbytes)
129
{
130
  int res;
131
 
132
  res=SYS_CALL3(k_write,fd,buf,nbytes);
133
 
134
  if (ISERROR(res)) {
135
    __set_errno(-res);
136
    return -1;
137
  }
138
  return res;
139
}
140
*/
141
 
142
/* --- */
143
 
144
 
145
/* --- */
146
 
147
extern int k_fstat(int fd, struct stat *buf);
148
 
149
int __fxstat(int version, int fd, struct stat *buf)
150
{
151
  int res;
152
 
153
  res=SYS_CALL2(k_fstat,fd,buf);
154
 
155
  if (ISERROR(res)) {
156
    __set_errno(-res);
157
    return -1;
158
  }
159
  return 0;
160
}
161
 
162
extern int k_stat(char *path, struct stat *buf);
163
 
164
//#include <h/sys/kern.h>
165
 
166
int __xstat(int version, char *path, struct stat *buf)
167
{
168
  int res;
169
 
170
  res=SYS_CALL2(k_stat,path,buf);
171
 
172
 
173
  if (ISERROR(res)) {
174
    __set_errno(-res);    
175
    return -1;
176
  }
177
 
178
  return 0;
179
}
180
 
181
/* for inlines */
182
 
183
int stat (char *__path,struct stat *__statbuf)
184
{
185
  return __xstat (_STAT_VER, __path, __statbuf);
186
}
187
 
188
int fstat (int __fd, struct stat *__statbuf)
189
{
190
  return __fxstat (_STAT_VER, __fd, __statbuf);
191
}
192
 
193
/* --- */
194
/* --- */
195
/* --- */
196
/* --- */
197
 
198
int k_ioctl(int fs, unsigned long int request, void *arg)
199
{
200
  return -ENOSYS;
201
}
202
 
203
int ioctl(int fd, unsigned long int request, ...)
204
{
205
  int res;
206
  void *arg=NULL;
207
 
208
  res=SYS_CALL3(k_ioctl,fd,request,arg);
209
 
210
  if (ISERROR(res)) {
211
    __set_errno(-res);
212
    return -1;
213
  }
214
 
215
  return 0;    
216
}
217
 
218
/* --- */
219
 
220
extern int k_fdevice(char *device_name);
221
 
222
__dev_t fdevice(char *device_name)
223
{
224
  int res;
225
 
226
  res=SYS_CALL1(k_fdevice,device_name);
227
 
228
  if (ISERROR(res)) {
229
    __set_errno(-res);
230
    return -1;
231
  }
232
 
233
  return res;      
234
}
235
 
236
/* --- */
237
 
238
extern int k_mount(__dev_t device, __uint8_t fsind,
239
                   char *where, struct mount_opts *);
240
 
241
int mount(__dev_t device, __uint8_t fsind,
242
          char *where, struct mount_opts *options)
243
{
244
  int res;
245
 
246
  res=SYS_CALL4(k_mount,device,fsind,where,options);
247
 
248
  if (ISERROR(res)) {
249
    __set_errno(-res);
250
    return -1;
251
  }
252
 
253
  return 0;    
254
}
255
 
256
extern int k_umount(__dev_t device);
257
 
258
int umount(__dev_t device)
259
{
260
  int res;
261
 
262
  res=SYS_CALL1(k_umount,device);
263
 
264
  if (ISERROR(res)) {
265
    __set_errno(-res);
266
    return -1;
267
  }
268
 
269
  return 0;    
270
}
271
 
272
/* --- */
273
 
274
int isatty(int fd)
275
{
276
  return 0;
277
}
278
 
279
/* --- */
280
 
281
extern int k_chdir(char *path);
282
 
283
int chdir(char *path)
284
{
285
  int res;
286
 
287
  res=SYS_CALL1(k_chdir,path);
288
 
289
  if (ISERROR(res)) {
290
    __set_errno(-res);
291
    return -1;
292
  }
293
 
294
  return 0;    
295
}
296
 
297
extern int k_access(char *path,int amode);
298
 
299
int access(char *path,int amode)
300
{
301
  int res;
302
 
303
  res=SYS_CALL2(k_access,path,amode);
304
 
305
  if (ISERROR(res)) {
306
    __set_errno(-res);
307
    return -1;
308
  }
309
 
310
  return 0;    
311
}
312
 
313
extern int k_utime(char *path,void *);
314
 
315
int utime(char *path,void *ptr)
316
{
317
  int res;
318
 
319
  res=SYS_CALL2(k_utime,path,ptr);
320
 
321
  if (ISERROR(res)) {
322
    __set_errno(-res);
323
    return -1;
324
  }
325
 
326
  return 0;    
327
}
328
 
329
/* --- */
330
 
331
extern int k_fcntl(int fildes, int cmd, void *ptr);
332
 
333
int fcntl(int fildes, int cmd, ...)    
334
{
335
  void *ptr;
336
  int mode;
337
  int res;
338
 
339
  ptr=NULL;
340
  if (cmd==F_SETFL||cmd==F_SETFD||cmd==F_DUPFD){
341
    va_list arg;
342
    mode=0;
343
    va_start(arg, cmd);
344
    mode=va_arg(arg,int);
345
    va_end(arg);
346
    ptr=(void *)mode;
347
  } else if (cmd==F_GETLK||cmd==F_SETLK||cmd==F_SETLKW) {
348
    va_list arg;
349
    va_start(arg, cmd);
350
    ptr=va_arg(arg,void *);
351
    va_end(arg);
352
  }
353
 
354
  res=SYS_CALL3(k_fcntl,fildes,cmd,ptr);
355
 
356
  if (ISERROR(res)) {
357
    __set_errno(-res);
358
    return -1;
359
  }
360
  return res;
361
}
362
 
363
 
364
 
365
/* --- */
366