source: rtems/cpukit/libcsupport/src/sup_fs_deviceio.c @ fed66f99

4.11
Last change on this file since fed66f99 was fed66f99, checked in by Sebastian Huber <sebastian.huber@…>, on May 14, 2012 at 1:19:20 PM

Filesystem: Add shared device IO support

The device IO file system support in IMFS, devFS, and RFS uses now a
shared implementation.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 */
9
10#if HAVE_CONFIG_H
11  #include "config.h"
12#endif
13
14#include <rtems/deviceio.h>
15
16int rtems_deviceio_open(
17  rtems_libio_t *iop,
18  const char *path,
19  int oflag,
20  mode_t mode,
21  rtems_device_major_number major,
22  rtems_device_minor_number minor
23)
24{
25  rtems_status_code status;
26  rtems_libio_open_close_args_t args;
27
28  args.iop = iop;
29  args.flags = iop->flags;
30  args.mode = mode;
31
32  status = rtems_io_open( major, minor, &args );
33
34  return rtems_deviceio_errno( status );
35}
36
37int rtems_deviceio_close(
38  rtems_libio_t *iop,
39  rtems_device_major_number major,
40  rtems_device_minor_number minor
41)
42{
43  rtems_status_code status;
44  rtems_libio_open_close_args_t args;
45
46  args.iop = iop;
47  args.flags = 0;
48  args.mode = 0;
49
50  status = rtems_io_close( major, minor, &args );
51
52  return rtems_deviceio_errno( status );
53}
54
55ssize_t rtems_deviceio_read(
56  rtems_libio_t *iop,
57  void *buf,
58  size_t nbyte,
59  rtems_device_major_number major,
60  rtems_device_minor_number minor
61)
62{
63  rtems_status_code status;
64  rtems_libio_rw_args_t args;
65
66  args.iop = iop;
67  args.offset = iop->offset;
68  args.buffer = buf;
69  args.count = nbyte;
70  args.flags = iop->flags;
71  args.bytes_moved = 0;
72
73  status = rtems_io_read( major, minor, &args );
74  if ( status == RTEMS_SUCCESSFUL ) {
75    return (ssize_t) args.bytes_moved;
76  } else {
77    return rtems_deviceio_errno( status );
78  }
79}
80
81ssize_t rtems_deviceio_write(
82  rtems_libio_t *iop,
83  const void *buf,
84  size_t nbyte,
85  rtems_device_major_number major,
86  rtems_device_minor_number minor
87)
88{
89  rtems_status_code status;
90  rtems_libio_rw_args_t args;
91
92  args.iop = iop;
93  args.offset = iop->offset;
94  args.buffer = buf;
95  args.count = nbyte;
96  args.flags = iop->flags;
97  args.bytes_moved = 0;
98
99  status = rtems_io_write( major, minor, &args );
100  if ( status == RTEMS_SUCCESSFUL ) {
101    return (ssize_t) args.bytes_moved;
102  } else {
103    return rtems_deviceio_errno( status );
104  }
105}
106
107int rtems_deviceio_control(
108  rtems_libio_t *iop,
109  ioctl_command_t command,
110  void *buffer,
111  rtems_device_major_number major,
112  rtems_device_minor_number minor
113)
114{
115  rtems_status_code status;
116  rtems_libio_ioctl_args_t args;
117
118  args.iop = iop;
119  args.command = command;
120  args.buffer = buffer;
121
122  status = rtems_io_control( major, minor, &args );
123  if ( status == RTEMS_SUCCESSFUL ) {
124    return args.ioctl_return;
125  } else {
126    return rtems_deviceio_errno(status);
127  }
128}
Note: See TracBrowser for help on using the repository browser.