[07a3253d] | 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 | * |
---|
[08311cc3] | 7 | * COPYRIGHT (c) 1989-1999. |
---|
[07a3253d] | 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 |
---|
[cf0539b1] | 12 | * http://www.rtems.com/license/LICENSE. |
---|
[07a3253d] | 13 | * |
---|
| 14 | * $Id$ |
---|
| 15 | */ |
---|
| 16 | |
---|
[d6b1d73] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[07a3253d] | 21 | #include <rtems.h> |
---|
| 22 | #include <rtems/libio.h> |
---|
[b8c8cab] | 23 | #include <rtems/assoc.h> /* assoc.h not included by rtems.h */ |
---|
| 24 | #include <errno.h> |
---|
[07a3253d] | 25 | |
---|
| 26 | #include "imfs.h" |
---|
| 27 | |
---|
[b8c8cab] | 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 | |
---|
[8d49b7c] | 46 | static int |
---|
[b8c8cab] | 47 | rtems_deviceio_errno(rtems_status_code code) |
---|
| 48 | { |
---|
| 49 | int rc; |
---|
[a5305f6b] | 50 | |
---|
[f91bbe64] | 51 | if ((rc = rtems_assoc_remote_by_local(errno_assoc, (uint32_t ) code))) |
---|
[b8c8cab] | 52 | { |
---|
| 53 | errno = rc; |
---|
| 54 | return -1; |
---|
| 55 | } |
---|
| 56 | return -1; |
---|
| 57 | } |
---|
| 58 | |
---|
[07a3253d] | 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, |
---|
[f91bbe64] | 68 | uint32_t flag, |
---|
| 69 | uint32_t mode |
---|
[07a3253d] | 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 | ); |
---|
[8d49b7c] | 87 | if ( status ) |
---|
| 88 | return rtems_deviceio_errno(status); |
---|
[07a3253d] | 89 | |
---|
| 90 | return 0; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | /* |
---|
| 94 | * device_close |
---|
| 95 | * |
---|
| 96 | * This handler maps a close() operation onto rtems_io_close(). |
---|
| 97 | */ |
---|
| 98 | |
---|
| 99 | int 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 | ); |
---|
[b8c8cab] | 118 | if ( status ) { |
---|
[8d49b7c] | 119 | return rtems_deviceio_errno(status); |
---|
[b8c8cab] | 120 | } |
---|
[07a3253d] | 121 | return 0; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /* |
---|
| 125 | * device_read |
---|
| 126 | * |
---|
| 127 | * This handler maps a read() operation onto rtems_io_read(). |
---|
| 128 | */ |
---|
| 129 | |
---|
[d32359a7] | 130 | ssize_t device_read( |
---|
[07a3253d] | 131 | rtems_libio_t *iop, |
---|
| 132 | void *buffer, |
---|
[f91bbe64] | 133 | uint32_t count |
---|
[07a3253d] | 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 ) |
---|
[b8c8cab] | 156 | return rtems_deviceio_errno(status); |
---|
[07a3253d] | 157 | |
---|
[d32359a7] | 158 | return (ssize_t) args.bytes_moved; |
---|
[07a3253d] | 159 | } |
---|
| 160 | |
---|
| 161 | /* |
---|
| 162 | * device_write |
---|
| 163 | * |
---|
| 164 | * This handler maps a write() operation onto rtems_io_write(). |
---|
| 165 | */ |
---|
| 166 | |
---|
[d32359a7] | 167 | ssize_t device_write( |
---|
[07a3253d] | 168 | rtems_libio_t *iop, |
---|
| 169 | const void *buffer, |
---|
[f91bbe64] | 170 | uint32_t count |
---|
[07a3253d] | 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 ) |
---|
[b8c8cab] | 193 | return rtems_deviceio_errno(status); |
---|
[07a3253d] | 194 | |
---|
[d32359a7] | 195 | return (ssize_t) args.bytes_moved; |
---|
[07a3253d] | 196 | } |
---|
| 197 | |
---|
| 198 | /* |
---|
| 199 | * device_ioctl |
---|
| 200 | * |
---|
| 201 | * This handler maps an ioctl() operation onto rtems_io_ioctl(). |
---|
| 202 | */ |
---|
| 203 | |
---|
| 204 | int device_ioctl( |
---|
| 205 | rtems_libio_t *iop, |
---|
[f91bbe64] | 206 | uint32_t command, |
---|
[07a3253d] | 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 ) |
---|
[b8c8cab] | 227 | return rtems_deviceio_errno(status); |
---|
[07a3253d] | 228 | |
---|
| 229 | return args.ioctl_return; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | /* |
---|
| 233 | * device_lseek |
---|
| 234 | * |
---|
| 235 | * This handler eats all lseek() operations. |
---|
| 236 | */ |
---|
| 237 | |
---|
| 238 | int 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 | * |
---|
[94b357c2] | 250 | * The IMFS_stat() is used. |
---|
[07a3253d] | 251 | */ |
---|
[b568ccb] | 252 | |
---|
| 253 | /* |
---|
| 254 | * device_rmnod |
---|
[94b357c2] | 255 | * |
---|
| 256 | * The IMFS_rmnod() is used. |
---|
[b568ccb] | 257 | */ |
---|