kernel - Refactor sys_pipe
[dragonfly.git] / sys / sys / pipe.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1996 John S. Dyson
3 * All rights reserved.
1dfdffca
MD
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>
984263bc
MD
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.
984263bc
MD
24 */
25
26#ifndef _SYS_PIPE_H_
27#define _SYS_PIPE_H_
28
03d6a592
MD
29#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
30
1bd40720
MD
31#ifndef _SYS_TYPES_H_
32#include <sys/types.h>
33#endif
34#ifndef _SYS_TIME_H_
984263bc 35#include <sys/time.h> /* for struct timespec */
1bd40720 36#endif
5b22f1a7
SG
37#ifndef _SYS_EVENT_H_
38#include <sys/event.h> /* for struct kqinfo */
984263bc 39#endif
1bd40720 40#ifndef _SYS_XIO_H_
24712b90
MD
41#include <sys/xio.h> /* for struct xio */
42#endif
1ae37239
MD
43#ifndef _SYS_THREAD_H_
44#include <sys/thread.h> /* for struct lwkt_token */
45#endif
1bd40720
MD
46#ifndef _MACHINE_PARAM_H_
47#include <machine/param.h> /* for PAGE_SIZE */
48#endif
24712b90 49
984263bc
MD
50/*
51 * Pipe buffer information.
984263bc
MD
52 */
53struct pipebuf {
1dfdffca
MD
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} __cachealign;
984263bc 75
984263bc 76/*
1dfdffca 77 * Bits in pipebuf.state.
984263bc 78 */
08593aa1
MD
79#define PIPE_ASYNC 0x0004 /* Async? I/O */
80#define PIPE_WANTR 0x0008 /* Reader wants some characters */
81#define PIPE_WANTW 0x0010 /* Writer wants space to put characters */
1ae37239
MD
82#define PIPE_REOF 0x0040 /* Pipe is in EOF condition (read EOF) */
83#define PIPE_WEOF 0x0080 /* Pipe is in EOF condition (write shutdown) */
84#define PIPE_CLOSED 0x1000 /* Pipe has been closed */
984263bc
MD
85
86/*
1dfdffca
MD
87 * The pipe() data structure encompasses two pipes. Bit 0 in fp->f_data
88 * denotes which.
984263bc
MD
89 */
90struct pipe {
1dfdffca
MD
91 struct pipebuf bufferA; /* data storage */
92 struct pipebuf bufferB; /* data storage */
93 struct timespec ctime; /* time of status change */
94 struct pipe *next;
95 uint32_t open_count;
96} __cachealign;
984263bc 97
03d6a592 98#endif /* _KERNEL || _KERNEL_STRUCTURES */
984263bc 99#endif /* !_SYS_PIPE_H_ */