/*********************************************************************** * fifodev.h * * Definitions for the fifo device, fifo_dev. * * This device should be created with the following commands run as * root: * * mknod fifo_dev c 100 0 * chmod 666 fifo_dev * * These commands should be run from the directory in which your * userland test program resides. Once these commands have been run, * the device can be accessed (read/write) by any user as the file * fifo_dev. ***********************************************************************/ #ifndef __FIFODEV_H #define __FIFODEV_H #include /* Major number for the fifo device. This particular number appears to * to be free now, but could be allocated to a "real" device later. */ #define MAJOR_NUM 100 /* File name for the fifo device. In reality, this could be anything. */ #define DEVICE_FILE_NAME "fifo_dev" /* FIFO_LEN is the length of the fifo, in characters. Ordinarily, this * length should be of no concern to userland programs. */ #define FIFO_LEN 32 /* buffer_descriptor is a type describing a fifo read/write buffer * descriptor, consisting of a pointer to the beginning of the * buffer and the buffer's length. It is used for IOCTL_WRITE_FIFO and * IOCTL_READ_FIFO (see below). len will be the number of characters to * transfer during the I/O operation. Obviously, len should be no larger * than the size of the buffer. Declaration example: * * char buffer[80]; * buffer_descriptor bd = { * .buffer = buffer, * .len = 12 * }; */ typedef struct { char *buffer; int len; } buffer_descriptor; /* IOCTL_SET_IMODE is used to set the fifo's input mode. STOP mode, the * default, will not overwrite fifo characters which have not yet been * read. OVERWRITE mode will overwrite unread characters. Usage example: * * ioctl(file, IOCTL_SET_IMODE, OVERWRITE); */ #define IOCTL_SET_IMODE _IOR(MAJOR_NUM, 0, int) #define STOP 0 #define OVERWRITE 1 /* IOCTL_SET_PMODE is used to set the fifo's processing mode. WHISPER * downcases all alphabetic characters, just as tolower() does. NORMAL * mode, the default, performs no processing. SHOUT mode upcases all * alphabetic characters, just as toupper() does. Usage example: * * ioctl(file, IOCTL_SET_PMODE, WHISPER); */ #define IOCTL_SET_PMODE _IOR(MAJOR_NUM, 1, int) #define WHISPER 0 #define NORMAL 1 #define SHOUT 2 /* IOCTL_WRITE_FIFO is used to write character data to the fifo in a * more controlled manner that that provided by normal file system * operations. The character data to be written should be described by * the buffer_descriptor. Note that copy_from_user must be used to copy * the buffer_descriptor from the user's address space to kernel address * space. This IOCTL returns the actual number of characters written. * Usage example: * * written_len = ioctl(file, IOCTL_WRITE_FIFO, bd); * * IOCTL_WRITE_FIFO should return -1 if an error occurs. */ #define IOCTL_WRITE_FIFO _IOWR(MAJOR_NUM, 2, buffer_descriptor *) /* IOCTL_READ_FIFO is similar to IOCTL_WRITE_FIFO. It returns the number * of characters read from the FIFO into the buffer described by the * buffer_descriptor. Characters stored in the fifo will only be read * once. * * IOCTL_READ_FIFO should return -1 if an error occurs. */ #define IOCTL_READ_FIFO _IOWR(MAJOR_NUM, 3, buffer_descriptor *) #endif