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
Line 
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
12  #include "config.h"
13#endif
14
15#include "imfs.h"
16
17#define JNODE2PIPE(_jnode)  ( (_jnode)->info.fifo.pipe )
18
19#define LIBIO2PIPE(_iop)  ( JNODE2PIPE((IMFS_jnode_t *)(_iop)->pathinfo.node_access) )
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
29static int IMFS_fifo_open(
30  rtems_libio_t *iop,
31  const char    *pathname,
32  int            oflag,
33  mode_t         mode
34)
35{
36  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
37
38  int err = fifo_open(&JNODE2PIPE(jnode), iop);
39  IMFS_FIFO_RETURN(err);
40}
41
42static int IMFS_fifo_close(
43  rtems_libio_t *iop
44)
45{
46  int err = 0;
47  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
48
49  pipe_release(&JNODE2PIPE(jnode), iop);
50
51  IMFS_FIFO_RETURN(err);
52}
53
54static ssize_t IMFS_fifo_read(
55  rtems_libio_t *iop,
56  void          *buffer,
57  size_t         count
58)
59{
60  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
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
69static ssize_t IMFS_fifo_write(
70  rtems_libio_t *iop,
71  const void    *buffer,
72  size_t         count
73)
74{
75  IMFS_jnode_t *jnode = iop->pathinfo.node_access;
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
85static int IMFS_fifo_ioctl(
86  rtems_libio_t   *iop,
87  ioctl_command_t  command,
88  void            *buffer
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
110static const rtems_filesystem_file_handlers_r IMFS_fifo_handlers = {
111  IMFS_fifo_open,
112  IMFS_fifo_close,
113  IMFS_fifo_read,
114  IMFS_fifo_write,
115  IMFS_fifo_ioctl,
116  rtems_filesystem_default_lseek,
117  IMFS_stat,
118  rtems_filesystem_default_ftruncate,
119  rtems_filesystem_default_fsync_or_fdatasync,
120  rtems_filesystem_default_fsync_or_fdatasync,
121  rtems_filesystem_default_fcntl
122};
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.