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