source: rtems/cpukit/libfs/src/imfs/imfs_fifo.c @ 0ec9bbc

5
Last change on this file since 0ec9bbc was a397c7d8, checked in by Sebastian Huber <sebastian.huber@…>, on 12/13/17 at 07:00:02

IMFS: Include <rtems/imfs.h>

Prepare for header file move to common include directory.

Update #3254.

  • Property mode set to 100644
File size: 3.2 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.org/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17  #include "config.h"
18#endif
19
20#include <rtems/imfs.h>
21
22#include <sys/filio.h>
23
24#define JNODE2PIPE(_jnode)  ( ((IMFS_fifo_t *)(_jnode))->pipe )
25
26#define LIBIO2PIPE(_iop)  ( JNODE2PIPE((IMFS_jnode_t *)(_iop)->pathinfo.node_access) )
27
28/* Set errno and return -1 if error, else return _err */
29#define IMFS_FIFO_RETURN(_err) \
30do {  \
31  if (_err < 0) \
32    rtems_set_errno_and_return_minus_one(-_err); \
33  return _err; \
34} while (0)
35
36static int IMFS_fifo_open(
37  rtems_libio_t *iop,
38  const char    *pathname,
39  int            oflag,
40  mode_t         mode
41)
42{
43  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
44
45  int err = fifo_open(&JNODE2PIPE(jnode), iop);
46  IMFS_FIFO_RETURN(err);
47}
48
49static int IMFS_fifo_close(
50  rtems_libio_t *iop
51)
52{
53  int err = 0;
54  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
55
56  pipe_release(&JNODE2PIPE(jnode), iop);
57
58  IMFS_FIFO_RETURN(err);
59}
60
61static ssize_t IMFS_fifo_read(
62  rtems_libio_t *iop,
63  void          *buffer,
64  size_t         count
65)
66{
67  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
68
69  int err = pipe_read(JNODE2PIPE(jnode), buffer, count, iop);
70  if (err > 0)
71    IMFS_update_atime(jnode);
72
73  IMFS_FIFO_RETURN(err);
74}
75
76static ssize_t IMFS_fifo_write(
77  rtems_libio_t *iop,
78  const void    *buffer,
79  size_t         count
80)
81{
82  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
83
84  int err = pipe_write(JNODE2PIPE(jnode), buffer, count, iop);
85  if (err > 0) {
86    IMFS_mtime_ctime_update(jnode);
87  }
88
89  IMFS_FIFO_RETURN(err);
90}
91
92static int IMFS_fifo_ioctl(
93  rtems_libio_t   *iop,
94  ioctl_command_t  command,
95  void            *buffer
96)
97{
98  int err;
99
100  if (command == FIONBIO) {
101    if (buffer == NULL)
102      err = -EFAULT;
103    else {
104      if (*(int *)buffer)
105        rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_NO_DELAY );
106      else
107        rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_NO_DELAY );
108      return 0;
109    }
110  }
111  else
112    err = pipe_ioctl(LIBIO2PIPE(iop), command, buffer, iop);
113
114  IMFS_FIFO_RETURN(err);
115}
116
117static const rtems_filesystem_file_handlers_r IMFS_fifo_handlers = {
118  .open_h = IMFS_fifo_open,
119  .close_h = IMFS_fifo_close,
120  .read_h = IMFS_fifo_read,
121  .write_h = IMFS_fifo_write,
122  .ioctl_h = IMFS_fifo_ioctl,
123  .lseek_h = rtems_filesystem_default_lseek,
124  .fstat_h = IMFS_stat,
125  .ftruncate_h = rtems_filesystem_default_ftruncate,
126  .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
127  .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
128  .fcntl_h = rtems_filesystem_default_fcntl,
129  .kqfilter_h = rtems_filesystem_default_kqfilter,
130  .mmap_h = rtems_filesystem_default_mmap,
131  .poll_h = rtems_filesystem_default_poll,
132  .readv_h = rtems_filesystem_default_readv,
133  .writev_h = rtems_filesystem_default_writev
134};
135
136const IMFS_mknod_control IMFS_mknod_control_fifo = {
137  {
138    .handlers = &IMFS_fifo_handlers,
139    .node_initialize = IMFS_node_initialize_default,
140    .node_remove = IMFS_node_remove_default,
141    .node_destroy = IMFS_node_destroy_default
142  },
143  .node_size = sizeof( IMFS_fifo_t )
144};
Note: See TracBrowser for help on using the repository browser.