source: rtems/cpukit/libfs/src/rfs/rtems-rfs-rtems-dev.c @ df01da67

4.115
Last change on this file since df01da67 was df01da67, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/12 at 11:16:31

Filesystem: Use ioctl_command_t

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.com/license/LICENSE.
7 */
8/**
9 * @file
10 *
11 * @ingroup rtems-rfs
12 *
13 * RTEMS RFS Device Interface.
14 *
15 * This file contains the set of handlers used to map operations on RFS device
16 * nodes onto calls to the RTEMS Classic API IO Manager.
17 *
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <rtems/devfs.h>
25#include "rtems-rfs-rtems.h"
26
27static void
28rtems_rfs_rtems_device_get_major_and_minor ( const rtems_libio_t       *iop,
29                                             rtems_device_major_number *major,
30                                             rtems_device_minor_number *minor)
31{
32  *major = iop->data0;
33  *minor = (rtems_device_minor_number) iop->data1;
34}
35
36/**
37 * This handler maps an open() operation onto rtems_io_open().
38 *
39 * @param iop
40 * @param pathname
41 * @param flag
42 * @param mode
43 * @return int
44 */
45static int
46rtems_rfs_rtems_device_open ( rtems_libio_t *iop,
47                              const char    *pathname,
48                              int            oflag,
49                              mode_t         mode)
50{
51  rtems_libio_open_close_args_t args;
52  rtems_rfs_file_system*        fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
53  rtems_rfs_ino                 ino = rtems_rfs_rtems_get_iop_ino (iop);
54  rtems_rfs_inode_handle        inode;
55  rtems_device_major_number     major;
56  rtems_device_minor_number     minor;
57  rtems_status_code             status;
58  int                           rc;
59
60  rtems_rfs_rtems_lock (fs);
61
62  rc = rtems_rfs_inode_open (fs, ino, &inode, true);
63  if (rc > 0)
64  {
65    rtems_rfs_rtems_unlock (fs);
66    return rtems_rfs_rtems_error ("device_open: opening inode", rc);
67  }
68
69  major = rtems_rfs_inode_get_block (&inode, 0);
70  minor = rtems_rfs_inode_get_block (&inode, 1);
71
72  rc = rtems_rfs_inode_close (fs, &inode);
73  if (rc > 0)
74  {
75    rtems_rfs_rtems_unlock (fs);
76    return rtems_rfs_rtems_error ("device_open: closing inode", rc);
77  }
78
79  rtems_rfs_rtems_unlock (fs);
80
81  iop->data0 = major;
82  iop->data1 = (void *) minor;
83
84  args.iop   = iop;
85  args.flags = iop->flags;
86  args.mode  = mode;
87
88  status = rtems_io_open (major, minor, (void *) &args);
89
90  return rtems_deviceio_errno (status);
91}
92
93/**
94 * This handler maps a close() operation onto rtems_io_close().
95 *
96 * @param iop
97 * @return int
98 */
99
100static int
101rtems_rfs_rtems_device_close (rtems_libio_t* iop)
102{
103  rtems_libio_open_close_args_t args;
104  rtems_status_code             status;
105  rtems_device_major_number     major;
106  rtems_device_minor_number     minor;
107
108  rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
109
110  args.iop   = iop;
111  args.flags = 0;
112  args.mode  = 0;
113
114  status = rtems_io_close (major, minor, (void *) &args);
115
116  return rtems_deviceio_errno (status);
117}
118
119/**
120 * This handler maps a read() operation onto rtems_io_read().
121 *
122 * @param iop
123 * @param buffer
124 * @param count
125 * @return ssize_t
126 */
127
128static ssize_t
129rtems_rfs_rtems_device_read (rtems_libio_t* iop, void* buffer, size_t count)
130{
131  rtems_libio_rw_args_t     args;
132  rtems_status_code         status;
133  rtems_device_major_number major;
134  rtems_device_minor_number minor;
135
136  rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
137
138  args.iop         = iop;
139  args.offset      = iop->offset;
140  args.buffer      = buffer;
141  args.count       = count;
142  args.flags       = iop->flags;
143  args.bytes_moved = 0;
144
145  status = rtems_io_read (major, minor, (void *) &args);
146  if (status)
147    return rtems_deviceio_errno (status);
148
149  return (ssize_t) args.bytes_moved;
150}
151
152/*
153 * This handler maps a write() operation onto rtems_io_write().
154 *
155 * @param iop
156 * @param buffer
157 * @param count
158 * @return ssize_t
159 */
160
161static ssize_t
162rtems_rfs_rtems_device_write (rtems_libio_t* iop,
163                              const void*    buffer,
164                              size_t         count)
165{
166  rtems_libio_rw_args_t     args;
167  rtems_status_code         status;
168  rtems_device_major_number major;
169  rtems_device_minor_number minor;
170
171  rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
172
173  args.iop         = iop;
174  args.offset      = iop->offset;
175  args.buffer      = (void *) buffer;
176  args.count       = count;
177  args.flags       = iop->flags;
178  args.bytes_moved = 0;
179
180  status = rtems_io_write (major, minor, (void *) &args);
181  if (status)
182    return rtems_deviceio_errno (status);
183
184  return (ssize_t) args.bytes_moved;
185}
186
187/**
188 * This handler maps an ioctl() operation onto rtems_io_ioctl().
189 *
190 * @param iop
191 * @param command
192 * @param buffer
193 * @return int
194 */
195
196static int
197rtems_rfs_rtems_device_ioctl (rtems_libio_t*  iop,
198                              ioctl_command_t command,
199                              void*           buffer)
200{
201  rtems_libio_ioctl_args_t  args;
202  rtems_status_code         status;
203  rtems_device_major_number major;
204  rtems_device_minor_number minor;
205
206  rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
207
208  args.iop     = iop;
209  args.command = command;
210  args.buffer  = buffer;
211
212  status = rtems_io_control (major, minor, (void *) &args);
213  if (status)
214    return rtems_deviceio_errno (status);
215
216  return args.ioctl_return;
217}
218
219/**
220 * The consumes the truncate call. You cannot truncate device files.
221 *
222 * @param iop
223 * @param length
224 * @return int
225 */
226
227static int
228rtems_rfs_rtems_device_ftruncate (rtems_libio_t* iop, off_t length)
229{
230  return 0;
231}
232
233/*
234 *  Handler table for RFS device nodes
235 */
236
237const rtems_filesystem_file_handlers_r rtems_rfs_rtems_device_handlers = {
238  .open_h      = rtems_rfs_rtems_device_open,
239  .close_h     = rtems_rfs_rtems_device_close,
240  .read_h      = rtems_rfs_rtems_device_read,
241  .write_h     = rtems_rfs_rtems_device_write,
242  .ioctl_h     = rtems_rfs_rtems_device_ioctl,
243  .lseek_h     = rtems_filesystem_default_lseek_file,
244  .fstat_h     = rtems_rfs_rtems_fstat,
245  .ftruncate_h = rtems_rfs_rtems_device_ftruncate,
246  .fsync_h     = rtems_filesystem_default_fsync_or_fdatasync,
247  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
248  .fcntl_h     = rtems_filesystem_default_fcntl
249};
Note: See TracBrowser for help on using the repository browser.