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