Merge branch 'vendor/OPENSSH'
[dragonfly.git] / sys / sys / pipe.h
1 /*
2  * Copyright (c) 1996 John S. Dyson
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice immediately at the beginning of the file, without modification,
10  *    this list of conditions, and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Absolutely no warranty of function or purpose is made by the author
15  *    John S. Dyson.
16  * 4. This work was done expressly for inclusion into FreeBSD.  Other use
17  *    is allowed if this notation is included.
18  * 5. Modifications may be freely made to this file if the above conditions
19  *    are met.
20  *
21  * $FreeBSD: src/sys/sys/pipe.h,v 1.16 1999/12/29 04:24:45 peter Exp $
22  * $DragonFly: src/sys/sys/pipe.h,v 1.10 2006/06/10 20:00:17 dillon Exp $
23  */
24
25 #ifndef _SYS_PIPE_H_
26 #define _SYS_PIPE_H_
27
28 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
29
30 #ifndef _SYS_TYPES_H_
31 #include <sys/types.h>
32 #endif
33 #ifndef _SYS_TIME_H_
34 #include <sys/time.h>                   /* for struct timespec */
35 #endif
36 #ifndef _SYS_SELINFO_H_
37 #include <sys/selinfo.h>                /* for struct selinfo */
38 #endif
39 #ifndef _SYS_XIO_H_
40 #include <sys/xio.h>                    /* for struct xio */
41 #endif
42 #ifndef _MACHINE_PARAM_H_
43 #include <machine/param.h>              /* for PAGE_SIZE */
44 #endif
45
46 /*
47  * Pipe buffer size, keep moderate in value, pipes take kva space.
48  */
49 #ifndef PIPE_SIZE
50 #define PIPE_SIZE       16384
51 #endif
52
53 #ifndef BIG_PIPE_SIZE
54 #define BIG_PIPE_SIZE   (64*1024)
55 #endif
56
57 /*
58  * PIPE_MINDIRECT MUST be smaller than PIPE_SIZE and MUST be bigger
59  * than PIPE_BUF.
60  */
61 #ifndef PIPE_MINDIRECT
62 #define PIPE_MINDIRECT  8192
63 #endif
64
65 /*
66  * Pipe buffer information.
67  * Separate in, out, cnt are used to simplify calculations.
68  * Buffered write is active when the buffer.cnt field is set.
69  */
70 struct pipebuf {
71         u_int   cnt;            /* number of chars currently in buffer */
72         u_int   in;             /* in pointer */
73         u_int   out;            /* out pointer */
74         u_int   size;           /* size of buffer */
75         caddr_t buffer;         /* kva of buffer */
76         struct  vm_object *object;      /* VM object containing buffer */
77 };
78
79 /*
80  * Bits in pipe_state.
81  */
82 #define PIPE_ASYNC      0x0004  /* Async? I/O. */
83 #define PIPE_WANTR      0x0008  /* Reader wants some characters. */
84 #define PIPE_WANTW      0x0010  /* Writer wants space to put characters. */
85 #define PIPE_WANT       0x0020  /* Pipe is wanted to be run-down. */
86 #define PIPE_SEL        0x0040  /* Pipe has a select active. */
87 #define PIPE_EOF        0x0080  /* Pipe is in EOF condition. */
88 #define PIPE_LOCK       0x0100  /* Process has exclusive access to pointers/data. */
89 #define PIPE_LWANT      0x0200  /* Process wants exclusive access to pointers/data. */
90 #define PIPE_DIRECTW    0x0400  /* Pipe direct write active. */
91 #define PIPE_DIRECTOK   0x0800  /* Direct mode ok. */
92 #define PIPE_DIRECTIP   0x1000  /* Direct write buffer build in progress */
93
94 enum pipe_feature { PIPE_COPY, PIPE_KMEM, PIPE_SFBUF1, PIPE_SFBUF2 };
95 /*
96  * Per-pipe data structure.
97  * Two of these are linked together to produce bi-directional pipes.
98  *
99  * NOTE: pipe_buffer.out has the dual purpose of tracking the copy offset
100  * for both the direct write case (with the rest of pipe_buffer) and the
101  * buffered write case (with pipe_map).
102  */
103 struct pipe {
104         struct  pipebuf pipe_buffer;    /* data storage */
105         struct  xio pipe_map;           /* mapping for direct I/O */
106         vm_offset_t pipe_kva;           /* kva mapping (testing only) */
107         cpumask_t pipe_kvamask;         /* kva cpu mask opt */
108         struct  selinfo pipe_sel;       /* for compat with select */
109         struct  timespec pipe_atime;    /* time of last access */
110         struct  timespec pipe_mtime;    /* time of last modify */
111         struct  timespec pipe_ctime;    /* time of status change */
112         struct  sigio *pipe_sigio;      /* information for async I/O */
113         struct  pipe *pipe_peer;        /* link with other direction */
114         u_int   pipe_state;             /* pipe status info */
115         enum pipe_feature pipe_feature; /* pipe transfer features */
116         int     pipe_busy;              /* busy flag, mostly to handle rundown sanely */
117 };
118
119 #endif  /* _KERNEL || _KERNEL_STRUCTURES */
120 #endif /* !_SYS_PIPE_H_ */