File indexing completed on 2025-05-11 08:24:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039
0040 #include <rtems/imfsimpl.h>
0041
0042 #include <sys/filio.h>
0043
0044 #define JNODE2PIPE(_jnode) ( ((IMFS_fifo_t *)(_jnode))->pipe )
0045
0046 #define LIBIO2PIPE(_iop) ( JNODE2PIPE((IMFS_jnode_t *)(_iop)->pathinfo.node_access) )
0047
0048
0049 #define IMFS_FIFO_RETURN(_err) \
0050 do { \
0051 if (_err < 0) \
0052 rtems_set_errno_and_return_minus_one(-_err); \
0053 return _err; \
0054 } while (0)
0055
0056 static int IMFS_fifo_open(
0057 rtems_libio_t *iop,
0058 const char *pathname,
0059 int oflag,
0060 mode_t mode
0061 )
0062 {
0063 IMFS_jnode_t *jnode = iop->pathinfo.node_access;
0064
0065 int err = fifo_open(&JNODE2PIPE(jnode), iop);
0066 IMFS_FIFO_RETURN(err);
0067 }
0068
0069 static int IMFS_fifo_close(
0070 rtems_libio_t *iop
0071 )
0072 {
0073 int err = 0;
0074 IMFS_jnode_t *jnode = iop->pathinfo.node_access;
0075
0076 pipe_release(&JNODE2PIPE(jnode), iop);
0077
0078 IMFS_FIFO_RETURN(err);
0079 }
0080
0081 static ssize_t IMFS_fifo_read(
0082 rtems_libio_t *iop,
0083 void *buffer,
0084 size_t count
0085 )
0086 {
0087 IMFS_jnode_t *jnode = iop->pathinfo.node_access;
0088
0089 int err = pipe_read(JNODE2PIPE(jnode), buffer, count, iop);
0090 if (err > 0)
0091 IMFS_update_atime(jnode);
0092
0093 IMFS_FIFO_RETURN(err);
0094 }
0095
0096 static ssize_t IMFS_fifo_write(
0097 rtems_libio_t *iop,
0098 const void *buffer,
0099 size_t count
0100 )
0101 {
0102 IMFS_jnode_t *jnode = iop->pathinfo.node_access;
0103
0104 int err = pipe_write(JNODE2PIPE(jnode), buffer, count, iop);
0105 if (err > 0) {
0106 IMFS_mtime_ctime_update(jnode);
0107 }
0108
0109 IMFS_FIFO_RETURN(err);
0110 }
0111
0112 static int IMFS_fifo_ioctl(
0113 rtems_libio_t *iop,
0114 ioctl_command_t command,
0115 void *buffer
0116 )
0117 {
0118 int err;
0119
0120 if (command == FIONBIO) {
0121 if (buffer == NULL)
0122 err = -EFAULT;
0123 else {
0124 if (*(int *)buffer)
0125 rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_NO_DELAY );
0126 else
0127 rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_NO_DELAY );
0128 return 0;
0129 }
0130 }
0131 else
0132 err = pipe_ioctl(LIBIO2PIPE(iop), command, buffer, iop);
0133
0134 IMFS_FIFO_RETURN(err);
0135 }
0136
0137 static const rtems_filesystem_file_handlers_r IMFS_fifo_handlers = {
0138 .open_h = IMFS_fifo_open,
0139 .close_h = IMFS_fifo_close,
0140 .read_h = IMFS_fifo_read,
0141 .write_h = IMFS_fifo_write,
0142 .ioctl_h = IMFS_fifo_ioctl,
0143 .lseek_h = rtems_filesystem_default_lseek,
0144 .fstat_h = IMFS_stat,
0145 .ftruncate_h = rtems_filesystem_default_ftruncate,
0146 .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
0147 .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
0148 .fcntl_h = rtems_filesystem_default_fcntl,
0149 .kqfilter_h = rtems_filesystem_default_kqfilter,
0150 .mmap_h = rtems_filesystem_default_mmap,
0151 .poll_h = rtems_filesystem_default_poll,
0152 .readv_h = rtems_filesystem_default_readv,
0153 .writev_h = rtems_filesystem_default_writev
0154 };
0155
0156 const IMFS_mknod_control IMFS_mknod_control_fifo = {
0157 {
0158 .handlers = &IMFS_fifo_handlers,
0159 .node_initialize = IMFS_node_initialize_default,
0160 .node_remove = IMFS_node_remove_default,
0161 .node_destroy = IMFS_node_destroy_default
0162 },
0163 .node_size = sizeof( IMFS_fifo_t )
0164 };