xref: /dragonfly/sys/sys/pipe.h (revision 7ff0fc30)
1 /*
2  * Copyright (c) 1996 John S. Dyson
3  * All rights reserved.
4  * Copyright (c) 2003-2017 The DragonFly Project.  All rights reserved.
5  *
6  * This code is derived from software contributed to The DragonFly Project
7  * by Matthew Dillon <dillon@backplane.com>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice immediately at the beginning of the file, without modification,
14  *    this list of conditions, and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Absolutely no warranty of function or purpose is made by the author
19  *    John S. Dyson.
20  * 4. This work was done expressly for inclusion into FreeBSD.  Other use
21  *    is allowed if this notation is included.
22  * 5. Modifications may be freely made to this file if the above conditions
23  *    are met.
24  */
25 
26 #ifndef _SYS_PIPE_H_
27 #define _SYS_PIPE_H_
28 
29 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
30 
31 #ifndef _SYS_TYPES_H_
32 #include <sys/types.h>
33 #endif
34 #ifndef _SYS_TIME_H_
35 #include <sys/time.h>			/* for struct timespec */
36 #endif
37 #ifndef _SYS_EVENT_H_
38 #include <sys/event.h>			/* for struct kqinfo */
39 #endif
40 #ifndef _SYS_XIO_H_
41 #include <sys/xio.h>			/* for struct xio */
42 #endif
43 #ifndef _SYS_THREAD_H_
44 #include <sys/thread.h>			/* for struct lwkt_token */
45 #endif
46 #ifndef _MACHINE_PARAM_H_
47 #include <machine/param.h>		/* for PAGE_SIZE */
48 #endif
49 
50 /*
51  * Pipe buffer information.
52  */
53 struct pipebuf {
54 	struct {
55 		struct lwkt_token rlock;
56 		size_t		rindex;	/* current read index (FIFO)	*/
57 		int32_t		rip;	/* blocking read requested (FIFO) */
58 		int32_t		unu01;	/* blocking read requested (FIFO) */
59 		struct timespec	atime;	/* time of last access */
60 	} __cachealign;
61 	struct {
62 		struct lwkt_token wlock;
63 		size_t		windex;	/* current write index (FIFO)	*/
64 		int32_t		wip;
65 		int32_t		unu02;
66 		struct timespec	mtime;	/* time of last modify */
67 	} __cachealign;
68 	size_t		size;		/* size of buffer */
69 	caddr_t		buffer;		/* kva of buffer */
70 	struct vm_object *object;	/* VM object containing buffer */
71 	struct kqinfo	kq;		/* for compat with select/poll/kq */
72 	struct sigio	*sigio;		/* information for async I/O */
73 	uint32_t	state;		/* pipe status info */
74 	int		lticks;		/* vfs_timestamp optimization */
75 } __cachealign;
76 
77 /*
78  * Bits in pipebuf.state.
79  */
80 #define PIPE_ASYNC	0x0004	/* Async? I/O */
81 #define PIPE_WANTR	0x0008	/* Reader wants some characters */
82 #define PIPE_WANTW	0x0010	/* Writer wants space to put characters */
83 #define PIPE_REOF	0x0040	/* Pipe is in EOF condition (read EOF) */
84 #define PIPE_WEOF	0x0080	/* Pipe is in EOF condition (write shutdown) */
85 #define PIPE_CLOSED	0x1000	/* Pipe has been closed */
86 
87 /*
88  * The pipe() data structure encompasses two pipes.  Bit 0 in fp->f_data
89  * denotes which.
90  */
91 struct pipe {
92 	struct pipebuf	bufferA;	/* data storage */
93 	struct pipebuf	bufferB;	/* data storage */
94 	struct timespec	ctime;		/* time of status change */
95 	struct pipe	*next;
96 	uint32_t	open_count;
97 	uint32_t	unused01;
98 	uint64_t	inum;
99 } __cachealign;
100 
101 #endif	/* _KERNEL || _KERNEL_STRUCTURES */
102 #endif /* !_SYS_PIPE_H_ */
103