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

4.115
Last change on this file since 3c96bee was ff1becb, checked in by Joel Sherrill <joel.sherrill@…>, on 01/10/13 at 19:22:57

rfs: Doxygen group cannot have a dash in it

Change rtems-rfs to rtems_rfs

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS RFS Device Interface
5 * @ingroup rtems_rfs
6 *
7 * This file contains the set of handlers used to map operations on RFS device
8 * nodes onto calls to the RTEMS Classic API IO Manager.
9 */
10
11/*
12 *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20  #include "config.h"
21#endif
22
23#include "rtems-rfs-rtems.h"
24
25#include <rtems/deviceio.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_rfs_file_system*        fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
52  rtems_rfs_ino                 ino = rtems_rfs_rtems_get_iop_ino (iop);
53  rtems_rfs_inode_handle        inode;
54  rtems_device_major_number     major;
55  rtems_device_minor_number     minor;
56  int                           rc;
57
58  rtems_rfs_rtems_lock (fs);
59
60  rc = rtems_rfs_inode_open (fs, ino, &inode, true);
61  if (rc > 0)
62  {
63    rtems_rfs_rtems_unlock (fs);
64    return rtems_rfs_rtems_error ("device_open: opening inode", rc);
65  }
66
67  major = rtems_rfs_inode_get_block (&inode, 0);
68  minor = rtems_rfs_inode_get_block (&inode, 1);
69
70  rc = rtems_rfs_inode_close (fs, &inode);
71  if (rc > 0)
72  {
73    rtems_rfs_rtems_unlock (fs);
74    return rtems_rfs_rtems_error ("device_open: closing inode", rc);
75  }
76
77  rtems_rfs_rtems_unlock (fs);
78
79  iop->data0 = major;
80  iop->data1 = (void *) minor;
81
82  return rtems_deviceio_open (iop, pathname, oflag, mode, minor, major);
83}
84
85/**
86 * This handler maps a close() operation onto rtems_io_close().
87 *
88 * @param iop
89 * @return int
90 */
91
92static int
93rtems_rfs_rtems_device_close (rtems_libio_t* iop)
94{
95  rtems_device_major_number     major;
96  rtems_device_minor_number     minor;
97
98  rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
99
100  return rtems_deviceio_close (iop, major, minor);
101}
102
103/**
104 * This handler maps a read() operation onto rtems_io_read().
105 *
106 * @param iop
107 * @param buffer
108 * @param count
109 * @return ssize_t
110 */
111
112static ssize_t
113rtems_rfs_rtems_device_read (rtems_libio_t* iop, void* buffer, size_t count)
114{
115  rtems_device_major_number major;
116  rtems_device_minor_number minor;
117
118  rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
119
120  return rtems_deviceio_read (iop, buffer, count, major, minor);
121}
122
123/*
124 * This handler maps a write() operation onto rtems_io_write().
125 *
126 * @param iop
127 * @param buffer
128 * @param count
129 * @return ssize_t
130 */
131
132static ssize_t
133rtems_rfs_rtems_device_write (rtems_libio_t* iop,
134                              const void*    buffer,
135                              size_t         count)
136{
137  rtems_device_major_number major;
138  rtems_device_minor_number minor;
139
140  rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
141
142  return rtems_deviceio_write (iop, buffer, count, major, minor);
143}
144
145/**
146 * This handler maps an ioctl() operation onto rtems_io_ioctl().
147 *
148 * @param iop
149 * @param command
150 * @param buffer
151 * @return int
152 */
153
154static int
155rtems_rfs_rtems_device_ioctl (rtems_libio_t*  iop,
156                              ioctl_command_t command,
157                              void*           buffer)
158{
159  rtems_device_major_number major;
160  rtems_device_minor_number minor;
161
162  rtems_rfs_rtems_device_get_major_and_minor (iop, &major, &minor);
163
164  return rtems_deviceio_control (iop, command, buffer, major, minor);
165}
166
167/**
168 * The consumes the truncate call. You cannot truncate device files.
169 *
170 * @param iop
171 * @param length
172 * @return int
173 */
174
175static int
176rtems_rfs_rtems_device_ftruncate (rtems_libio_t* iop, off_t length)
177{
178  return 0;
179}
180
181/*
182 *  Handler table for RFS device nodes
183 */
184
185const rtems_filesystem_file_handlers_r rtems_rfs_rtems_device_handlers = {
186  .open_h      = rtems_rfs_rtems_device_open,
187  .close_h     = rtems_rfs_rtems_device_close,
188  .read_h      = rtems_rfs_rtems_device_read,
189  .write_h     = rtems_rfs_rtems_device_write,
190  .ioctl_h     = rtems_rfs_rtems_device_ioctl,
191  .lseek_h     = rtems_filesystem_default_lseek_file,
192  .fstat_h     = rtems_rfs_rtems_fstat,
193  .ftruncate_h = rtems_rfs_rtems_device_ftruncate,
194  .fsync_h     = rtems_filesystem_default_fsync_or_fdatasync,
195  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
196  .fcntl_h     = rtems_filesystem_default_fcntl
197};
Note: See TracBrowser for help on using the repository browser.