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-1998. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * Copyright assigned to U.S. Government, 1994. |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.OARcorp.com/rtems/license.html. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #include <rtems.h> |
---|
19 | #include <rtems/libio.h> |
---|
20 | #include "libio_.h" |
---|
21 | |
---|
22 | #include "imfs.h" |
---|
23 | |
---|
24 | /* |
---|
25 | * device_open |
---|
26 | * |
---|
27 | * This handler maps an open() operation onto rtems_io_open(). |
---|
28 | */ |
---|
29 | |
---|
30 | int device_open( |
---|
31 | rtems_libio_t *iop, |
---|
32 | const char *pathname, |
---|
33 | unsigned32 flag, |
---|
34 | unsigned32 mode |
---|
35 | ) |
---|
36 | { |
---|
37 | rtems_libio_open_close_args_t args; |
---|
38 | rtems_status_code status; |
---|
39 | IMFS_jnode_t *the_jnode; |
---|
40 | |
---|
41 | the_jnode = iop->file_info; |
---|
42 | |
---|
43 | args.iop = iop; |
---|
44 | args.flags = iop->flags; |
---|
45 | args.mode = mode; |
---|
46 | |
---|
47 | status = rtems_io_open( |
---|
48 | the_jnode->info.device.major, |
---|
49 | the_jnode->info.device.minor, |
---|
50 | (void *) &args |
---|
51 | ); |
---|
52 | if ( status ) |
---|
53 | return RTEMS_UNSATISFIED; |
---|
54 | |
---|
55 | return 0; |
---|
56 | } |
---|
57 | |
---|
58 | /* |
---|
59 | * device_close |
---|
60 | * |
---|
61 | * This handler maps a close() operation onto rtems_io_close(). |
---|
62 | */ |
---|
63 | |
---|
64 | int device_close( |
---|
65 | rtems_libio_t *iop |
---|
66 | ) |
---|
67 | { |
---|
68 | rtems_libio_open_close_args_t args; |
---|
69 | rtems_status_code status; |
---|
70 | IMFS_jnode_t *the_jnode; |
---|
71 | |
---|
72 | the_jnode = iop->file_info; |
---|
73 | |
---|
74 | args.iop = iop; |
---|
75 | args.flags = 0; |
---|
76 | args.mode = 0; |
---|
77 | |
---|
78 | status = rtems_io_close( |
---|
79 | the_jnode->info.device.major, |
---|
80 | the_jnode->info.device.minor, |
---|
81 | (void *) &args |
---|
82 | ); |
---|
83 | if ( status ) |
---|
84 | return RTEMS_UNSATISFIED; |
---|
85 | |
---|
86 | return 0; |
---|
87 | } |
---|
88 | |
---|
89 | /* |
---|
90 | * device_read |
---|
91 | * |
---|
92 | * This handler maps a read() operation onto rtems_io_read(). |
---|
93 | */ |
---|
94 | |
---|
95 | int device_read( |
---|
96 | rtems_libio_t *iop, |
---|
97 | void *buffer, |
---|
98 | unsigned32 count |
---|
99 | ) |
---|
100 | { |
---|
101 | rtems_libio_rw_args_t args; |
---|
102 | rtems_status_code status; |
---|
103 | IMFS_jnode_t *the_jnode; |
---|
104 | |
---|
105 | the_jnode = iop->file_info; |
---|
106 | |
---|
107 | args.iop = iop; |
---|
108 | args.offset = iop->offset; |
---|
109 | args.buffer = buffer; |
---|
110 | args.count = count; |
---|
111 | args.flags = iop->flags; |
---|
112 | args.bytes_moved = 0; |
---|
113 | |
---|
114 | status = rtems_io_read( |
---|
115 | the_jnode->info.device.major, |
---|
116 | the_jnode->info.device.minor, |
---|
117 | (void *) &args |
---|
118 | ); |
---|
119 | |
---|
120 | if ( status ) |
---|
121 | return -1; |
---|
122 | |
---|
123 | return args.bytes_moved; |
---|
124 | } |
---|
125 | |
---|
126 | /* |
---|
127 | * device_write |
---|
128 | * |
---|
129 | * This handler maps a write() operation onto rtems_io_write(). |
---|
130 | */ |
---|
131 | |
---|
132 | int device_write( |
---|
133 | rtems_libio_t *iop, |
---|
134 | const void *buffer, |
---|
135 | unsigned32 count |
---|
136 | ) |
---|
137 | { |
---|
138 | rtems_libio_rw_args_t args; |
---|
139 | rtems_status_code status; |
---|
140 | IMFS_jnode_t *the_jnode; |
---|
141 | |
---|
142 | the_jnode = iop->file_info; |
---|
143 | |
---|
144 | args.iop = iop; |
---|
145 | args.offset = iop->offset; |
---|
146 | args.buffer = (void *) buffer; |
---|
147 | args.count = count; |
---|
148 | args.flags = iop->flags; |
---|
149 | args.bytes_moved = 0; |
---|
150 | |
---|
151 | status = rtems_io_write( |
---|
152 | the_jnode->info.device.major, |
---|
153 | the_jnode->info.device.minor, |
---|
154 | (void *) &args |
---|
155 | ); |
---|
156 | |
---|
157 | if ( status ) |
---|
158 | return -1; |
---|
159 | |
---|
160 | return args.bytes_moved; |
---|
161 | } |
---|
162 | |
---|
163 | /* |
---|
164 | * device_ioctl |
---|
165 | * |
---|
166 | * This handler maps an ioctl() operation onto rtems_io_ioctl(). |
---|
167 | */ |
---|
168 | |
---|
169 | int device_ioctl( |
---|
170 | rtems_libio_t *iop, |
---|
171 | unsigned32 command, |
---|
172 | void *buffer |
---|
173 | ) |
---|
174 | { |
---|
175 | rtems_libio_ioctl_args_t args; |
---|
176 | rtems_status_code status; |
---|
177 | IMFS_jnode_t *the_jnode; |
---|
178 | |
---|
179 | args.iop = iop; |
---|
180 | args.command = command; |
---|
181 | args.buffer = buffer; |
---|
182 | |
---|
183 | the_jnode = iop->file_info; |
---|
184 | |
---|
185 | status = rtems_io_control( |
---|
186 | the_jnode->info.device.major, |
---|
187 | the_jnode->info.device.minor, |
---|
188 | (void *) &args |
---|
189 | ); |
---|
190 | |
---|
191 | if ( status ) |
---|
192 | return -1; |
---|
193 | |
---|
194 | return args.ioctl_return; |
---|
195 | } |
---|
196 | |
---|
197 | /* |
---|
198 | * device_lseek |
---|
199 | * |
---|
200 | * This handler eats all lseek() operations. |
---|
201 | */ |
---|
202 | |
---|
203 | int device_lseek( |
---|
204 | rtems_libio_t *iop, |
---|
205 | off_t offset, |
---|
206 | int whence |
---|
207 | ) |
---|
208 | { |
---|
209 | return 0; |
---|
210 | } |
---|
211 | |
---|
212 | /* |
---|
213 | * device_stat |
---|
214 | * |
---|
215 | * This IMFS_stat() is used. |
---|
216 | */ |
---|
217 | |
---|
218 | /* |
---|
219 | * device_rmnod |
---|
220 | */ |
---|
221 | |
---|
222 | int device_rmnod( |
---|
223 | rtems_filesystem_location_info_t *pathloc /* IN */ |
---|
224 | ) |
---|
225 | { |
---|
226 | IMFS_jnode_t *the_jnode; |
---|
227 | |
---|
228 | the_jnode = (IMFS_jnode_t *) pathloc->node_access; |
---|
229 | |
---|
230 | /* |
---|
231 | * Take the node out of the parent's chain that contains this node |
---|
232 | */ |
---|
233 | |
---|
234 | if ( the_jnode->Parent != NULL ) { |
---|
235 | Chain_Extract( (Chain_Node *) the_jnode ); |
---|
236 | the_jnode->Parent = NULL; |
---|
237 | } |
---|
238 | |
---|
239 | /* |
---|
240 | * Decrement the link counter and see if we can free the space. |
---|
241 | */ |
---|
242 | |
---|
243 | the_jnode->st_nlink--; |
---|
244 | IMFS_update_ctime( the_jnode ); |
---|
245 | |
---|
246 | /* |
---|
247 | * The file cannot be open and the link must be less than 1 to free. |
---|
248 | */ |
---|
249 | |
---|
250 | if ( !rtems_libio_is_file_open( the_jnode ) && (the_jnode->st_nlink < 1) ) { |
---|
251 | |
---|
252 | /* |
---|
253 | * Is the rtems_filesystem_current is this node? |
---|
254 | */ |
---|
255 | |
---|
256 | if ( rtems_filesystem_current.node_access == pathloc->node_access ) |
---|
257 | rtems_filesystem_current.node_access = NULL; |
---|
258 | |
---|
259 | /* |
---|
260 | * Free memory associated with a memory file. |
---|
261 | */ |
---|
262 | |
---|
263 | free( the_jnode ); |
---|
264 | } |
---|
265 | |
---|
266 | return 0; |
---|
267 | |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | |
---|