Subversion Repositories shark

Rev

Rev 3 | 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
/*
1031 tullio 41
 * CVS :        $Id: wrappers.c,v 1.2 2006-03-09 16:30:05 tullio Exp $
2 pj 42
 *
43
 * File:        $File$
1031 tullio 44
 * Revision:    $Revision: 1.2 $
45
 * Last update: $Date: 2006-03-09 16:30:05 $
2 pj 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
int __xstat(int version, char *path, struct stat *buf)
165
{
166
  int res;
167
 
168
  res=SYS_CALL2(k_stat,path,buf);
169
 
170
 
171
  if (ISERROR(res)) {
172
    __set_errno(-res);    
173
    return -1;
174
  }
175
 
176
  return 0;
177
}
178
 
179
/* for inlines */
180
 
181
int stat (char *__path,struct stat *__statbuf)
182
{
183
  return __xstat (_STAT_VER, __path, __statbuf);
184
}
185
 
186
int fstat (int __fd, struct stat *__statbuf)
187
{
188
  return __fxstat (_STAT_VER, __fd, __statbuf);
189
}
190
 
191
/* --- */
192
/* --- */
193
/* --- */
194
/* --- */
195
 
196
int k_ioctl(int fs, unsigned long int request, void *arg)
197
{
198
  return -ENOSYS;
199
}
200
 
201
int ioctl(int fd, unsigned long int request, ...)
202
{
203
  int res;
204
  void *arg=NULL;
205
 
206
  res=SYS_CALL3(k_ioctl,fd,request,arg);
207
 
208
  if (ISERROR(res)) {
209
    __set_errno(-res);
210
    return -1;
211
  }
212
 
213
  return 0;    
214
}
215
 
216
/* --- */
217
 
218
extern int k_fdevice(char *device_name);
219
 
220
__dev_t fdevice(char *device_name)
221
{
222
  int res;
223
 
224
  res=SYS_CALL1(k_fdevice,device_name);
225
 
226
  if (ISERROR(res)) {
227
    __set_errno(-res);
228
    return -1;
229
  }
230
 
231
  return res;      
232
}
233
 
234
/* --- */
235
 
236
extern int k_mount(__dev_t device, __uint8_t fsind,
237
                   char *where, struct mount_opts *);
238
 
239
int mount(__dev_t device, __uint8_t fsind,
240
          char *where, struct mount_opts *options)
241
{
242
  int res;
243
 
244
  res=SYS_CALL4(k_mount,device,fsind,where,options);
245
 
246
  if (ISERROR(res)) {
247
    __set_errno(-res);
248
    return -1;
249
  }
250
 
251
  return 0;    
252
}
253
 
254
extern int k_umount(__dev_t device);
255
 
256
int umount(__dev_t device)
257
{
258
  int res;
259
 
260
  res=SYS_CALL1(k_umount,device);
261
 
262
  if (ISERROR(res)) {
263
    __set_errno(-res);
264
    return -1;
265
  }
266
 
267
  return 0;    
268
}
269
 
270
/* --- */
271
 
272
int isatty(int fd)
273
{
274
  return 0;
275
}
276
 
277
/* --- */
278
 
279
extern int k_chdir(char *path);
280
 
281
int chdir(char *path)
282
{
283
  int res;
284
 
285
  res=SYS_CALL1(k_chdir,path);
286
 
287
  if (ISERROR(res)) {
288
    __set_errno(-res);
289
    return -1;
290
  }
291
 
292
  return 0;    
293
}
294
 
295
extern int k_access(char *path,int amode);
296
 
297
int access(char *path,int amode)
298
{
299
  int res;
300
 
301
  res=SYS_CALL2(k_access,path,amode);
302
 
303
  if (ISERROR(res)) {
304
    __set_errno(-res);
305
    return -1;
306
  }
307
 
308
  return 0;    
309
}
310
 
311
extern int k_utime(char *path,void *);
312
 
313
int utime(char *path,void *ptr)
314
{
315
  int res;
316
 
317
  res=SYS_CALL2(k_utime,path,ptr);
318
 
319
  if (ISERROR(res)) {
320
    __set_errno(-res);
321
    return -1;
322
  }
323
 
324
  return 0;    
325
}
326
 
327
/* --- */
328
 
329
extern int k_fcntl(int fildes, int cmd, void *ptr);
330
 
331
int fcntl(int fildes, int cmd, ...)    
332
{
333
  void *ptr;
334
  int mode;
335
  int res;
336
 
337
  ptr=NULL;
338
  if (cmd==F_SETFL||cmd==F_SETFD||cmd==F_DUPFD){
339
    va_list arg;
340
    mode=0;
341
    va_start(arg, cmd);
342
    mode=va_arg(arg,int);
343
    va_end(arg);
344
    ptr=(void *)mode;
345
  } else if (cmd==F_GETLK||cmd==F_SETLK||cmd==F_SETLKW) {
346
    va_list arg;
347
    va_start(arg, cmd);
348
    ptr=va_arg(arg,void *);
349
    va_end(arg);
350
  }
351
 
352
  res=SYS_CALL3(k_fcntl,fildes,cmd,ptr);
353
 
354
  if (ISERROR(res)) {
355
    __set_errno(-res);
356
    return -1;
357
  }
358
  return res;
359
}
360
 
361
 
362
 
363
/* --- */
364