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

4.104.115
Last change on this file since 1d539c0 was 355b0544, checked in by Chris Johns <chrisj@…>, on 03/27/10 at 04:04:40

2010-03-27 Chris Johns <chrisj@…>

libfs/src/nfsclient/src/cexphelp.c,
libfs/src/nfsclient/src/dirutils.c,
libfs/src/nfsclient/src/nfs.modini.c,
libfs/src/nfsclient/src/nfsTest.c,
libfs/src/nfsclient/src/rpcio.c,
libfs/src/nfsclient/src/rpcio.modini.c,
libfs/src/nfsclient/src/sock_mbuf.c,
libfs/src/nfsclient/src/xdr_mbuf.c,
libfs/src/rfs/rtems-rfs-bitmaps-ut.c,
libfs/src/rfs/rtems-rfs-bitmaps.c,
libfs/src/rfs/rtems-rfs-block.c,
libfs/src/rfs/rtems-rfs-buffer-bdbuf.c,
libfs/src/rfs/rtems-rfs-buffer-devio.c,
libfs/src/rfs/rtems-rfs-buffer.c,
libfs/src/rfs/rtems-rfs-dir-hash.c, libfs/src/rfs/rtems-rfs-dir.c,
libfs/src/rfs/rtems-rfs-file-system.c,
libfs/src/rfs/rtems-rfs-file.c, libfs/src/rfs/rtems-rfs-format.c,
libfs/src/rfs/rtems-rfs-group.c, libfs/src/rfs/rtems-rfs-inode.c,
libfs/src/rfs/rtems-rfs-link.c, libfs/src/rfs/rtems-rfs-mutex.c,
libfs/src/rfs/rtems-rfs-rtems-dev.c,
libfs/src/rfs/rtems-rfs-rtems-dir.c,
libfs/src/rfs/rtems-rfs-rtems-file.c,
libfs/src/rfs/rtems-rfs-rtems-utils.c,
libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs-shell.c,
libfs/src/rfs/rtems-rfs-trace.c: Add HAVE_CONFIG_H support to let
files receive configure defines.

  • Property mode set to 100644
File size: 6.2 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 *  $Id$
9 */
10/**
11 * @file
12 *
13 * @ingroup rtems-rfs
14 *
15 * RTEMS RFS Device Interface.
16 *
17 * This file contains the set of handlers used to map operations on RFS device
18 * nodes onto calls to the RTEMS Classic API IO Manager.
19 *
20 */
21
22#if HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include "rtems-rfs-rtems.h"
27
28/*
29 * Convert RTEMS status to a UNIX errno
30 */
31extern int rtems_deviceio_errno (rtems_status_code code);
32
33/**
34 * This handler maps an open() operation onto rtems_io_open().
35 *
36 * @param iop
37 * @param pathname
38 * @param flag
39 * @param mode
40 * @return int
41 */
42static int
43rtems_rfs_rtems_device_open ( rtems_libio_t *iop,
44                              const char    *pathname,
45                              uint32_t       flag,
46                              uint32_t       mode)
47{
48  rtems_libio_open_close_args_t args;
49  rtems_rfs_file_system*        fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
50  rtems_rfs_ino                 ino = rtems_rfs_rtems_get_iop_ino (iop);
51  rtems_rfs_inode_handle        inode;
52  int                           major;
53  int                           minor;
54  rtems_status_code             status;
55  int                           rc;
56 
57  rtems_rfs_rtems_lock (fs);
58 
59  rc = rtems_rfs_inode_open (fs, ino, &inode, true);
60  if (rc > 0)
61  {
62    rtems_rfs_rtems_unlock (fs);
63    return rtems_rfs_rtems_error ("device_open: opening inode", rc);
64  }
65
66  major = rtems_rfs_inode_get_block (&inode, 0);
67  minor = rtems_rfs_inode_get_block (&inode, 1);
68
69  rc = rtems_rfs_inode_close (fs, &inode);
70  if (rc > 0)
71  {
72    rtems_rfs_rtems_unlock (fs);
73    return rtems_rfs_rtems_error ("device_open: closing inode", rc);
74  }
75
76  rtems_rfs_rtems_unlock (fs);
77 
78  iop->data0 = major;
79  iop->data1 = (void*)((intptr_t) minor);
80 
81  args.iop   = iop;
82  args.flags = iop->flags;
83  args.mode  = mode;
84
85  status = rtems_io_open (major, minor, (void *) &args);
86  if (status)
87    return rtems_deviceio_errno(status);
88
89  return 0;
90}
91
92/**
93 * This handler maps a close() operation onto rtems_io_close().
94 *
95 * @param iop
96 * @return int
97 */
98
99static int
100rtems_rfs_rtems_device_close (rtems_libio_t* iop)
101{
102  rtems_libio_open_close_args_t args;
103  rtems_status_code             status;
104  int                           major;
105  int                           minor;
106
107  major = (int) iop->data0;
108  minor = (intptr_t) iop->data1;
109
110  args.iop   = iop;
111  args.flags = 0;
112  args.mode  = 0;
113
114  status = rtems_io_close (major, minor, (void *) &args);
115  if (status)
116    return rtems_deviceio_errno (status);
117
118  return 0;
119}
120
121/**
122 * This handler maps a read() operation onto rtems_io_read().
123 *
124 * @param iop
125 * @param buffer
126 * @param count
127 * @return ssize_t
128 */
129
130static ssize_t
131rtems_rfs_rtems_device_read (rtems_libio_t* iop, void* buffer, size_t count)
132{
133  rtems_libio_rw_args_t args;
134  rtems_status_code     status;
135  int                   major;
136  int                   minor;
137
138  major = (int) iop->data0;
139  minor = (intptr_t) iop->data1;
140
141  args.iop         = iop;
142  args.offset      = iop->offset;
143  args.buffer      = buffer;
144  args.count       = count;
145  args.flags       = iop->flags;
146  args.bytes_moved = 0;
147
148  status = rtems_io_read (major, minor, (void *) &args);
149  if (status)
150    return rtems_deviceio_errno (status);
151
152  return (ssize_t) args.bytes_moved;
153}
154
155/*
156 * This handler maps a write() operation onto rtems_io_write().
157 *
158 * @param iop
159 * @param buffer
160 * @param count
161 * @return ssize_t
162 */
163
164static ssize_t
165rtems_rfs_rtems_device_write (rtems_libio_t* iop,
166                              const void*    buffer,
167                              size_t         count)
168{
169  rtems_libio_rw_args_t args;
170  rtems_status_code     status;
171  int                   major;
172  int                   minor;
173
174  major = (int) iop->data0;
175  minor = (intptr_t) iop->data1;
176
177  args.iop         = iop;
178  args.offset      = iop->offset;
179  args.buffer      = (void *) buffer;
180  args.count       = count;
181  args.flags       = iop->flags;
182  args.bytes_moved = 0;
183
184  status = rtems_io_write (major, minor, (void *) &args);
185  if (status)
186    return rtems_deviceio_errno (status);
187
188  return (ssize_t) args.bytes_moved;
189}
190
191/**
192 * This handler maps an ioctl() operation onto rtems_io_ioctl().
193 *
194 * @param iop
195 * @param command
196 * @param buffer
197 * @return int
198 */
199
200static int
201rtems_rfs_rtems_device_ioctl (rtems_libio_t* iop,
202                              uint32_t       command,
203                              void*          buffer)
204{
205  rtems_libio_ioctl_args_t args;
206  rtems_status_code        status;
207  int                      major;
208  int                      minor;
209
210  major = (int) iop->data0;
211  minor = (intptr_t) iop->data1;
212
213  args.iop     = iop;
214  args.command = command;
215  args.buffer  = buffer;
216
217  status = rtems_io_control (major, minor, (void *) &args);
218  if (status)
219    return rtems_deviceio_errno (status);
220
221  return args.ioctl_return;
222}
223
224/**
225 * This handler eats all lseek() operations and does not create an error. It
226 * assumes all devices can handle the seek. The writes fail.
227 *
228 * @param iop
229 * @param offset
230 * @param whence
231 * @return rtems_off64_t
232 */
233
234static rtems_off64_t
235rtems_rfs_rtems_device_lseek (rtems_libio_t* iop,
236                              rtems_off64_t  offset,
237                              int            whence)
238{
239  return offset;
240}
241
242/**
243 * The consumes the truncate call. You cannot truncate device files.
244 *
245 * @param iop
246 * @param length
247 * @return int
248 */
249
250static int
251rtems_rfs_rtems_device_ftruncate (rtems_libio_t* iop, rtems_off64_t length)
252{
253  return 0;
254}
255
256/*
257 *  Handler table for RFS device nodes
258 */
259
260const rtems_filesystem_file_handlers_r rtems_rfs_rtems_device_handlers = {
261  .open_h      = rtems_rfs_rtems_device_open,
262  .close_h     = rtems_rfs_rtems_device_close,
263  .read_h      = rtems_rfs_rtems_device_read,
264  .write_h     = rtems_rfs_rtems_device_write,
265  .ioctl_h     = rtems_rfs_rtems_device_ioctl,
266  .lseek_h     = rtems_rfs_rtems_device_lseek,
267  .fstat_h     = rtems_rfs_rtems_stat,
268  .fchmod_h    = rtems_rfs_rtems_fchmod,
269  .ftruncate_h = rtems_rfs_rtems_device_ftruncate,
270  .fpathconf_h = NULL,
271  .fsync_h     = NULL,
272  .fdatasync_h = NULL,
273  .fcntl_h     = NULL,
274  .rmnod_h     = rtems_rfs_rtems_rmnod
275};
Note: See TracBrowser for help on using the repository browser.