OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libfs/] [src/] [imfs/] [deviceio.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  IMFS Device Node Handlers
3
 *
4
 *  This file contains the set of handlers used to map operations on
5
 *  IMFS device nodes onto calls to the RTEMS Classic API IO Manager.
6
 *
7
 *  COPYRIGHT (c) 1989-1999.
8
 *  On-Line Applications Research Corporation (OAR).
9
 *
10
 *  The license and distribution terms for this file may be
11
 *  found in the file LICENSE in this distribution or at
12
 *  http://www.OARcorp.com/rtems/license.html.
13
 *
14
 *  deviceio.c,v 1.7 2001/07/06 21:48:16 joel Exp
15
 */
16
 
17
#if HAVE_CONFIG_H
18
#include "config.h"
19
#endif
20
 
21
#include <rtems.h>
22
#include <rtems/libio.h>
23
#include <rtems/assoc.h>                /* assoc.h not included by rtems.h */
24
#include <errno.h>
25
 
26
#include "imfs.h"
27
 
28
/*
29
 * Convert RTEMS status to a UNIX errno
30
 */
31
 
32
rtems_assoc_t errno_assoc[] = {
33
    { "OK",                 RTEMS_SUCCESSFUL,                0 },
34
    { "BUSY",               RTEMS_RESOURCE_IN_USE,           EBUSY },
35
    { "INVALID NAME",       RTEMS_INVALID_NAME,              EINVAL },
36
    { "NOT IMPLEMENTED",    RTEMS_NOT_IMPLEMENTED,           ENOSYS },
37
    { "TIMEOUT",            RTEMS_TIMEOUT,                   ETIMEDOUT },
38
    { "NO MEMORY",          RTEMS_NO_MEMORY,                 ENOMEM },
39
    { "NO DEVICE",          RTEMS_UNSATISFIED,               ENODEV },
40
    { "INVALID NUMBER",     RTEMS_INVALID_NUMBER,            EBADF},
41
    { "NOT RESOURCE OWNER", RTEMS_NOT_OWNER_OF_RESOURCE,     EPERM},
42
    { "IO ERROR",           RTEMS_IO_ERROR,                  EIO},
43
    { 0, 0, 0 },
44
};
45
 
46
static unsigned32
47
rtems_deviceio_errno(rtems_status_code code)
48
{
49
    int rc;
50
 
51
    if ((rc = rtems_assoc_remote_by_local(errno_assoc, (unsigned32) code)))
52
    {
53
        errno = rc;
54
        return -1;
55
    }
56
    return -1;
57
}
58
 
59
/*
60
 *  device_open
61
 *
62
 *  This handler maps an open() operation onto rtems_io_open().
63
 */
64
 
65
int device_open(
66
  rtems_libio_t *iop,
67
  const char    *pathname,
68
  unsigned32     flag,
69
  unsigned32     mode
70
)
71
{
72
  rtems_libio_open_close_args_t  args;
73
  rtems_status_code              status;
74
  IMFS_jnode_t                  *the_jnode;
75
 
76
  the_jnode  = iop->file_info;
77
 
78
  args.iop   = iop;
79
  args.flags = iop->flags;
80
  args.mode  = mode;
81
 
82
  status = rtems_io_open(
83
    the_jnode->info.device.major,
84
    the_jnode->info.device.minor,
85
    (void *) &args
86
  );
87
  if ( status ) {
88
    rtems_deviceio_errno(status);
89
    return RTEMS_UNSATISFIED;
90
  }
91
 
92
  return 0;
93
}
94
 
95
/*
96
 *  device_close
97
 *
98
 *  This handler maps a close() operation onto rtems_io_close().
99
 */
100
 
101
int device_close(
102
  rtems_libio_t *iop
103
)
104
{
105
  rtems_libio_open_close_args_t  args;
106
  rtems_status_code              status;
107
  IMFS_jnode_t                  *the_jnode;
108
 
109
  the_jnode = iop->file_info;
110
 
111
  args.iop   = iop;
112
  args.flags = 0;
113
  args.mode  = 0;
114
 
115
  status = rtems_io_close(
116
    the_jnode->info.device.major,
117
    the_jnode->info.device.minor,
118
    (void *) &args
119
  );
120
  if ( status ) {
121
    rtems_deviceio_errno(status);
122
    return RTEMS_UNSATISFIED;
123
  }
124
  return 0;
125
}
126
 
127
/*
128
 *  device_read
129
 *
130
 *  This handler maps a read() operation onto rtems_io_read().
131
 */
132
 
133
int device_read(
134
  rtems_libio_t *iop,
135
  void          *buffer,
136
  unsigned32     count
137
)
138
{
139
  rtems_libio_rw_args_t   args;
140
  rtems_status_code       status;
141
  IMFS_jnode_t           *the_jnode;
142
 
143
  the_jnode = iop->file_info;
144
 
145
  args.iop         = iop;
146
  args.offset      = iop->offset;
147
  args.buffer      = buffer;
148
  args.count       = count;
149
  args.flags       = iop->flags;
150
  args.bytes_moved = 0;
151
 
152
  status = rtems_io_read(
153
    the_jnode->info.device.major,
154
    the_jnode->info.device.minor,
155
    (void *) &args
156
  );
157
 
158
  if ( status )
159
    return rtems_deviceio_errno(status);
160
 
161
  return args.bytes_moved;
162
}
163
 
164
/*
165
 *  device_write
166
 *
167
 *  This handler maps a write() operation onto rtems_io_write().
168
 */
169
 
170
int device_write(
171
  rtems_libio_t *iop,
172
  const void    *buffer,
173
  unsigned32     count
174
)
175
{
176
  rtems_libio_rw_args_t   args;
177
  rtems_status_code       status;
178
  IMFS_jnode_t           *the_jnode;
179
 
180
  the_jnode = iop->file_info;
181
 
182
  args.iop         = iop;
183
  args.offset      = iop->offset;
184
  args.buffer      = (void *) buffer;
185
  args.count       = count;
186
  args.flags       = iop->flags;
187
  args.bytes_moved = 0;
188
 
189
  status = rtems_io_write(
190
    the_jnode->info.device.major,
191
    the_jnode->info.device.minor,
192
    (void *) &args
193
  );
194
 
195
  if ( status )
196
    return rtems_deviceio_errno(status);
197
 
198
  return args.bytes_moved;
199
}
200
 
201
/*
202
 *  device_ioctl
203
 *
204
 *  This handler maps an ioctl() operation onto rtems_io_ioctl().
205
 */
206
 
207
int device_ioctl(
208
  rtems_libio_t *iop,
209
  unsigned32     command,
210
  void          *buffer
211
)
212
{
213
  rtems_libio_ioctl_args_t  args;
214
  rtems_status_code         status;
215
  IMFS_jnode_t             *the_jnode;
216
 
217
  args.iop     = iop;
218
  args.command = command;
219
  args.buffer  = buffer;
220
 
221
  the_jnode = iop->file_info;
222
 
223
  status = rtems_io_control(
224
    the_jnode->info.device.major,
225
    the_jnode->info.device.minor,
226
    (void *) &args
227
  );
228
 
229
  if ( status )
230
    return rtems_deviceio_errno(status);
231
 
232
  return args.ioctl_return;
233
}
234
 
235
/*
236
 *  device_lseek
237
 *
238
 *  This handler eats all lseek() operations.
239
 */
240
 
241
int device_lseek(
242
  rtems_libio_t *iop,
243
  off_t          offset,
244
  int            whence
245
)
246
{
247
  return 0;
248
}
249
 
250
/*
251
 *  device_stat
252
 *
253
 *  The IMFS_stat() is used.
254
 */
255
 
256
/*
257
 *  device_rmnod
258
 *
259
 *  The IMFS_rmnod() is used.
260
 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.