source: rtems/cpukit/libfs/src/imfs/deviceio.c @ 83c5fc1

4.104.114.84.95
Last change on this file since 83c5fc1 was f91bbe64, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/22/04 at 17:10:43

2004-03-22 Ralf Corsepius <ralf_corsepius@…>

  • libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h, libfs/src/dosfs/fat_fat_operations.c, libfs/src/dosfs/fat_fat_operations.h, libfs/src/dosfs/fat_file.c, libfs/src/dosfs/fat_file.h, libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_initsupp.c, libfs/src/dosfs/msdos_misc.c, libfs/src/imfs/deviceio.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/linearfile.c, libfs/src/imfs/memfile.c: Convert to using c99 fixed-size types.
  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
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.rtems.com/license/LICENSE.
13 *
14 *  $Id$
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
32rtems_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
46static int
47rtems_deviceio_errno(rtems_status_code code)
48{
49    int rc;
50   
51    if ((rc = rtems_assoc_remote_by_local(errno_assoc, (uint32_t  ) 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
65int device_open(
66  rtems_libio_t *iop,
67  const char    *pathname,
68  uint32_t       flag,
69  uint32_t       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    return rtems_deviceio_errno(status);
89
90  return 0;
91}
92
93/*
94 *  device_close
95 *
96 *  This handler maps a close() operation onto rtems_io_close().
97 */
98
99int device_close(
100  rtems_libio_t *iop
101)
102{
103  rtems_libio_open_close_args_t  args;
104  rtems_status_code              status;
105  IMFS_jnode_t                  *the_jnode;
106
107  the_jnode = iop->file_info;
108
109  args.iop   = iop;
110  args.flags = 0;
111  args.mode  = 0;
112
113  status = rtems_io_close(
114    the_jnode->info.device.major,
115    the_jnode->info.device.minor,
116    (void *) &args
117  );
118  if ( status ) {
119    return rtems_deviceio_errno(status);
120  }
121  return 0;
122}
123
124/*
125 *  device_read
126 *
127 *  This handler maps a read() operation onto rtems_io_read().
128 */
129
130ssize_t device_read(
131  rtems_libio_t *iop,
132  void          *buffer,
133  uint32_t       count
134)
135{
136  rtems_libio_rw_args_t   args;
137  rtems_status_code       status;
138  IMFS_jnode_t           *the_jnode;
139
140  the_jnode = iop->file_info;
141
142  args.iop         = iop;
143  args.offset      = iop->offset;
144  args.buffer      = buffer;
145  args.count       = count;
146  args.flags       = iop->flags;
147  args.bytes_moved = 0;
148
149  status = rtems_io_read(
150    the_jnode->info.device.major,
151    the_jnode->info.device.minor,
152    (void *) &args
153  );
154
155  if ( status )
156    return rtems_deviceio_errno(status);
157
158  return (ssize_t) args.bytes_moved;
159}
160
161/*
162 *  device_write
163 *
164 *  This handler maps a write() operation onto rtems_io_write().
165 */
166
167ssize_t device_write(
168  rtems_libio_t *iop,
169  const void    *buffer,
170  uint32_t       count
171)
172{
173  rtems_libio_rw_args_t   args;
174  rtems_status_code       status;
175  IMFS_jnode_t           *the_jnode;
176
177  the_jnode = iop->file_info;
178
179  args.iop         = iop;
180  args.offset      = iop->offset;
181  args.buffer      = (void *) buffer;
182  args.count       = count;
183  args.flags       = iop->flags;
184  args.bytes_moved = 0;
185
186  status = rtems_io_write(
187    the_jnode->info.device.major,
188    the_jnode->info.device.minor,
189    (void *) &args
190  );
191
192  if ( status )
193    return rtems_deviceio_errno(status);
194
195  return (ssize_t) args.bytes_moved;
196}
197
198/*
199 *  device_ioctl
200 *
201 *  This handler maps an ioctl() operation onto rtems_io_ioctl().
202 */
203
204int device_ioctl(
205  rtems_libio_t *iop,
206  uint32_t       command,
207  void          *buffer
208)
209{
210  rtems_libio_ioctl_args_t  args;
211  rtems_status_code         status;
212  IMFS_jnode_t             *the_jnode;
213
214  args.iop     = iop;
215  args.command = command;
216  args.buffer  = buffer;
217
218  the_jnode = iop->file_info;
219
220  status = rtems_io_control(
221    the_jnode->info.device.major,
222    the_jnode->info.device.minor,
223    (void *) &args
224  );
225
226  if ( status )
227    return rtems_deviceio_errno(status);
228
229  return args.ioctl_return;
230}
231
232/*
233 *  device_lseek
234 *
235 *  This handler eats all lseek() operations.
236 */
237
238int device_lseek(
239  rtems_libio_t *iop,
240  off_t          offset,
241  int            whence
242)
243{
244  return 0;
245}
246
247/*
248 *  device_stat
249 *
250 *  The IMFS_stat() is used.
251 */
252
253/*
254 *  device_rmnod
255 *
256 *  The IMFS_rmnod() is used.
257 */
Note: See TracBrowser for help on using the repository browser.