1 /* $OpenBSD: pipe.h,v 1.29 2022/07/09 12:48:21 visa Exp $ */ 2 3 /* 4 * Copyright (c) 1996 John S. Dyson 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice immediately at the beginning of the file, without modification, 12 * this list of conditions, and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Absolutely no warranty of function or purpose is made by the author 17 * John S. Dyson. 18 * 4. This work was done expressly for inclusion into FreeBSD. Other use 19 * is allowed if this notation is included. 20 * 5. Modifications may be freely made to this file if the above conditions 21 * are met. 22 */ 23 24 #ifndef _SYS_PIPE_H_ 25 #define _SYS_PIPE_H_ 26 27 #ifndef _KERNEL 28 #include <sys/time.h> /* for struct timespec */ 29 #endif /* _KERNEL */ 30 31 #include <sys/event.h> /* for struct klist */ 32 #include <sys/sigio.h> /* for struct sigio_ref */ 33 34 /* 35 * Pipe buffer size, keep moderate in value, pipes take kva space. 36 */ 37 #ifndef PIPE_SIZE 38 #define PIPE_SIZE 16384 39 #endif 40 41 #ifndef BIG_PIPE_SIZE 42 #define BIG_PIPE_SIZE (64*1024) 43 #endif 44 45 /* 46 * Pipe buffer information. 47 * Separate in, out, cnt are used to simplify calculations. 48 * Buffered write is active when the buffer.cnt field is set. 49 */ 50 struct pipebuf { 51 u_int cnt; /* number of chars currently in buffer */ 52 u_int in; /* in pointer */ 53 u_int out; /* out pointer */ 54 u_int size; /* size of buffer */ 55 caddr_t buffer; /* kva of buffer */ 56 }; 57 58 /* 59 * Bits in pipe_state. 60 */ 61 #define PIPE_ASYNC 0x004 /* Async? I/O. */ 62 #define PIPE_WANTR 0x008 /* Reader wants some characters. */ 63 #define PIPE_WANTW 0x010 /* Writer wants space to put characters. */ 64 #define PIPE_WANTD 0x020 /* Pipe is wanted to be run-down. */ 65 #define PIPE_EOF 0x080 /* Pipe is in EOF condition. */ 66 #define PIPE_LOCK 0x100 /* Thread has exclusive I/O access. */ 67 #define PIPE_LWANT 0x200 /* Thread wants exclusive I/O access. */ 68 69 struct pipe_pair; 70 71 /* 72 * Per-pipe data structure. 73 * Two of these are linked together to produce bi-directional pipes. 74 * 75 * Locking: 76 * I immutable after creation 77 * S sigio_lock 78 * p pipe_lock 79 */ 80 struct pipe { 81 struct rwlock *pipe_lock; 82 struct pipebuf pipe_buffer; /* [p] data storage */ 83 struct klist pipe_klist; /* [p] list of knotes */ 84 struct timespec pipe_atime; /* [p] time of last access */ 85 struct timespec pipe_mtime; /* [p] time of last modify */ 86 struct timespec pipe_ctime; /* [I] time of status change */ 87 struct sigio_ref pipe_sigio; /* [S] async I/O registration */ 88 struct pipe *pipe_peer; /* [p] link with other direction */ 89 struct pipe_pair *pipe_pair; /* [I] pipe storage */ 90 u_int pipe_state; /* [p] pipe status info */ 91 int pipe_busy; /* [p] # readers/writers */ 92 }; 93 94 #ifdef _KERNEL 95 void pipe_init(void); 96 #endif /* _KERNEL */ 97 98 #endif /* !_SYS_PIPE_H_ */ 99