source: rtems/cpukit/libfs/src/imfs/imfs_fifo.c @ 2f68778

4.115
Last change on this file since 2f68778 was 2f68778, checked in by Sebastian Huber <sebastian.huber@…>, on 12/16/13 at 12:44:13

Filesystem: Add readv/writev handlers

The readv() and writev() support was implemented in terms of multiple
calls to the read and write handlers. This imposes a problem on device
files which use an IO vector as single request entity. For example a
low-level network device (e.g. BPF(4)) may use an IO vector to create
one frame from multiple protocol layers each with its own IO vector
entry.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief FIFO Support
5 * @ingroup IMFS
6 */
7
8/*
9 * Author: Wei Shen <cquark@gmail.com>
10 *
11 * The license and distribution terms for this file may be
12 * found in the file LICENSE in this distribution or at
13 * http://www.rtems.com/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17  #include "config.h"
18#endif
19
20#include "imfs.h"
21
22#define JNODE2PIPE(_jnode)  ( (_jnode)->info.fifo.pipe )
23
24#define LIBIO2PIPE(_iop)  ( JNODE2PIPE((IMFS_jnode_t *)(_iop)->pathinfo.node_access) )
25
26/* Set errno and return -1 if error, else return _err */
27#define IMFS_FIFO_RETURN(_err) \
28do {  \
29  if (_err < 0) \
30    rtems_set_errno_and_return_minus_one(-_err); \
31  return _err; \
32} while (0)
33
34static int IMFS_fifo_open(
35  rtems_libio_t *iop,
36  const char    *pathname,
37  int            oflag,
38  mode_t         mode
39)
40{
41  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
42
43  int err = fifo_open(&JNODE2PIPE(jnode), iop);
44  IMFS_FIFO_RETURN(err);
45}
46
47static int IMFS_fifo_close(
48  rtems_libio_t *iop
49)
50{
51  int err = 0;
52  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
53
54  pipe_release(&JNODE2PIPE(jnode), iop);
55
56  IMFS_FIFO_RETURN(err);
57}
58
59static ssize_t IMFS_fifo_read(
60  rtems_libio_t *iop,
61  void          *buffer,
62  size_t         count
63)
64{
65  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
66
67  int err = pipe_read(JNODE2PIPE(jnode), buffer, count, iop);
68  if (err > 0)
69    IMFS_update_atime(jnode);
70
71  IMFS_FIFO_RETURN(err);
72}
73
74static ssize_t IMFS_fifo_write(
75  rtems_libio_t *iop,
76  const void    *buffer,
77  size_t         count
78)
79{
80  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
81
82  int err = pipe_write(JNODE2PIPE(jnode), buffer, count, iop);
83  if (err > 0) {
84    IMFS_mtime_ctime_update(jnode);
85  }
86
87  IMFS_FIFO_RETURN(err);
88}
89
90static int IMFS_fifo_ioctl(
91  rtems_libio_t   *iop,
92  ioctl_command_t  command,
93  void            *buffer
94)
95{
96  int err;
97
98  if (command == FIONBIO) {
99    if (buffer == NULL)
100      err = -EFAULT;
101    else {
102      if (*(int *)buffer)
103        iop->flags |= LIBIO_FLAGS_NO_DELAY;
104      else
105        iop->flags &= ~LIBIO_FLAGS_NO_DELAY;
106      return 0;
107    }
108  }
109  else
110    err = pipe_ioctl(LIBIO2PIPE(iop), command, buffer, iop);
111
112  IMFS_FIFO_RETURN(err);
113}
114
115static const rtems_filesystem_file_handlers_r IMFS_fifo_handlers = {
116  .open_h = IMFS_fifo_open,
117  .close_h = IMFS_fifo_close,
118  .read_h = IMFS_fifo_read,
119  .write_h = IMFS_fifo_write,
120  .ioctl_h = IMFS_fifo_ioctl,
121  .lseek_h = rtems_filesystem_default_lseek,
122  .fstat_h = IMFS_stat,
123  .ftruncate_h = rtems_filesystem_default_ftruncate,
124  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
125  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
126  .fcntl_h = rtems_filesystem_default_fcntl,
127  .readv_h = rtems_filesystem_default_readv,
128  .writev_h = rtems_filesystem_default_writev
129};
130
131const IMFS_node_control IMFS_node_control_fifo = {
132  .imfs_type = IMFS_FIFO,
133  .handlers = &IMFS_fifo_handlers,
134  .node_initialize = IMFS_node_initialize_default,
135  .node_remove = IMFS_node_remove_default,
136  .node_destroy = IMFS_node_destroy_default
137};
Note: See TracBrowser for help on using the repository browser.