source: rtems/cpukit/libfs/src/imfs/deviceio.c @ 1bdff036

4.115
Last change on this file since 1bdff036 was 1bdff036, checked in by Sebastian Huber <sebastian.huber@…>, on 02/23/12 at 16:57:27

IMFS: Reference counting for nodes

The introduction of reference counting of nodes avoids the removal of
open nodes and potential usage of freed memory.

  • Property mode set to 100644
File size: 4.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-2008.
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 "imfs.h"
22
23#include <rtems/devfs.h>
24
25/*
26 *  device_open
27 *
28 *  This handler maps an open() operation onto rtems_io_open().
29 */
30
31int device_open(
32  rtems_libio_t *iop,
33  const char    *pathname,
34  int            oflag,
35  mode_t         mode
36)
37{
38  rtems_libio_open_close_args_t  args;
39  rtems_status_code              status;
40  IMFS_jnode_t                  *the_jnode;
41
42  the_jnode  = iop->pathinfo.node_access;
43
44  args.iop   = iop;
45  args.flags = iop->flags;
46  args.mode  = mode;
47
48  status = rtems_io_open(
49    the_jnode->info.device.major,
50    the_jnode->info.device.minor,
51    (void *) &args
52  );
53
54  return rtems_deviceio_errno( status );
55}
56
57/*
58 *  device_close
59 *
60 *  This handler maps a close() operation onto rtems_io_close().
61 */
62
63int device_close(
64  rtems_libio_t *iop
65)
66{
67  rtems_libio_open_close_args_t  args;
68  rtems_status_code              status;
69  IMFS_jnode_t                  *the_jnode;
70
71  the_jnode = iop->pathinfo.node_access;
72
73  args.iop   = iop;
74  args.flags = 0;
75  args.mode  = 0;
76
77  status = rtems_io_close(
78    the_jnode->info.device.major,
79    the_jnode->info.device.minor,
80    (void *) &args
81  );
82
83  return rtems_deviceio_errno( status );
84}
85
86/*
87 *  device_read
88 *
89 *  This handler maps a read() operation onto rtems_io_read().
90 */
91
92ssize_t device_read(
93  rtems_libio_t *iop,
94  void          *buffer,
95  size_t         count
96)
97{
98  rtems_libio_rw_args_t   args;
99  rtems_status_code       status;
100  IMFS_jnode_t           *the_jnode;
101
102  the_jnode = iop->pathinfo.node_access;
103
104  args.iop         = iop;
105  args.offset      = iop->offset;
106  args.buffer      = buffer;
107  args.count       = count;
108  args.flags       = iop->flags;
109  args.bytes_moved = 0;
110
111  status = rtems_io_read(
112    the_jnode->info.device.major,
113    the_jnode->info.device.minor,
114    (void *) &args
115  );
116
117  if ( status )
118    return rtems_deviceio_errno(status);
119
120  return (ssize_t) args.bytes_moved;
121}
122
123/*
124 *  device_write
125 *
126 *  This handler maps a write() operation onto rtems_io_write().
127 */
128
129ssize_t device_write(
130  rtems_libio_t *iop,
131  const void    *buffer,
132  size_t         count
133)
134{
135  rtems_libio_rw_args_t   args;
136  rtems_status_code       status;
137  IMFS_jnode_t           *the_jnode;
138
139  the_jnode = iop->pathinfo.node_access;
140
141  args.iop         = iop;
142  args.offset      = iop->offset;
143  args.buffer      = (void *) buffer;
144  args.count       = count;
145  args.flags       = iop->flags;
146  args.bytes_moved = 0;
147
148  status = rtems_io_write(
149    the_jnode->info.device.major,
150    the_jnode->info.device.minor,
151    (void *) &args
152  );
153
154  if ( status )
155    return rtems_deviceio_errno(status);
156
157  return (ssize_t) args.bytes_moved;
158}
159
160/*
161 *  device_ioctl
162 *
163 *  This handler maps an ioctl() operation onto rtems_io_ioctl().
164 */
165
166int device_ioctl(
167  rtems_libio_t *iop,
168  uint32_t       command,
169  void          *buffer
170)
171{
172  rtems_libio_ioctl_args_t  args;
173  rtems_status_code         status;
174  IMFS_jnode_t             *the_jnode;
175
176  args.iop     = iop;
177  args.command = command;
178  args.buffer  = buffer;
179
180  the_jnode = iop->pathinfo.node_access;
181
182  status = rtems_io_control(
183    the_jnode->info.device.major,
184    the_jnode->info.device.minor,
185    (void *) &args
186  );
187
188  if ( status )
189    return rtems_deviceio_errno(status);
190
191  return args.ioctl_return;
192}
193
194/*
195 *  device_lseek
196 *
197 *  This handler eats all lseek() operations and does not create
198 *  an error. It assumes all devices can handle the seek. The
199 *  writes fail.
200 */
201
202off_t device_lseek(
203  rtems_libio_t *iop,
204  off_t          offset,
205  int            whence
206)
207{
208  return offset;
209}
210
211/*
212 *  device_stat
213 *
214 *  The IMFS_stat() is used.
215 */
216
217/*
218 *  device_rmnod
219 *
220 *  The IMFS_rmnod() is used.
221 */
222
223int device_ftruncate(
224  rtems_libio_t *iop,
225  off_t          length
226)
227{
228  return 0;
229}
Note: See TracBrowser for help on using the repository browser.