1*a820167aSvisa /* $OpenBSD: pipe.h,v 1.29 2022/07/09 12:48:21 visa Exp $ */ 2a2c3ae2eSniklas 38867e984Sshawn /* 48867e984Sshawn * Copyright (c) 1996 John S. Dyson 58867e984Sshawn * All rights reserved. 68867e984Sshawn * 78867e984Sshawn * Redistribution and use in source and binary forms, with or without 88867e984Sshawn * modification, are permitted provided that the following conditions 98867e984Sshawn * are met: 108867e984Sshawn * 1. Redistributions of source code must retain the above copyright 118867e984Sshawn * notice immediately at the beginning of the file, without modification, 128867e984Sshawn * this list of conditions, and the following disclaimer. 138867e984Sshawn * 2. Redistributions in binary form must reproduce the above copyright 148867e984Sshawn * notice, this list of conditions and the following disclaimer in the 158867e984Sshawn * documentation and/or other materials provided with the distribution. 168867e984Sshawn * 3. Absolutely no warranty of function or purpose is made by the author 178867e984Sshawn * John S. Dyson. 188867e984Sshawn * 4. This work was done expressly for inclusion into FreeBSD. Other use 198867e984Sshawn * is allowed if this notation is included. 208867e984Sshawn * 5. Modifications may be freely made to this file if the above conditions 218867e984Sshawn * are met. 228867e984Sshawn */ 238867e984Sshawn 248867e984Sshawn #ifndef _SYS_PIPE_H_ 258867e984Sshawn #define _SYS_PIPE_H_ 268867e984Sshawn 27a2c3ae2eSniklas #ifndef _KERNEL 28c74a1e1aSderaadt #include <sys/time.h> /* for struct timespec */ 29a2c3ae2eSniklas #endif /* _KERNEL */ 308867e984Sshawn 31*a820167aSvisa #include <sys/event.h> /* for struct klist */ 32a1a94567Svisa #include <sys/sigio.h> /* for struct sigio_ref */ 33a1a94567Svisa 348867e984Sshawn /* 358867e984Sshawn * Pipe buffer size, keep moderate in value, pipes take kva space. 368867e984Sshawn */ 378867e984Sshawn #ifndef PIPE_SIZE 388867e984Sshawn #define PIPE_SIZE 16384 398867e984Sshawn #endif 408867e984Sshawn 418867e984Sshawn #ifndef BIG_PIPE_SIZE 428867e984Sshawn #define BIG_PIPE_SIZE (64*1024) 438867e984Sshawn #endif 448867e984Sshawn 458867e984Sshawn /* 468867e984Sshawn * Pipe buffer information. 478867e984Sshawn * Separate in, out, cnt are used to simplify calculations. 488867e984Sshawn * Buffered write is active when the buffer.cnt field is set. 498867e984Sshawn */ 508867e984Sshawn struct pipebuf { 518867e984Sshawn u_int cnt; /* number of chars currently in buffer */ 528867e984Sshawn u_int in; /* in pointer */ 538867e984Sshawn u_int out; /* out pointer */ 548867e984Sshawn u_int size; /* size of buffer */ 558867e984Sshawn caddr_t buffer; /* kva of buffer */ 568867e984Sshawn }; 578867e984Sshawn 588867e984Sshawn /* 598867e984Sshawn * Bits in pipe_state. 608867e984Sshawn */ 618867e984Sshawn #define PIPE_ASYNC 0x004 /* Async? I/O. */ 628867e984Sshawn #define PIPE_WANTR 0x008 /* Reader wants some characters. */ 638867e984Sshawn #define PIPE_WANTW 0x010 /* Writer wants space to put characters. */ 64cb597556Ssemarie #define PIPE_WANTD 0x020 /* Pipe is wanted to be run-down. */ 658867e984Sshawn #define PIPE_EOF 0x080 /* Pipe is in EOF condition. */ 66853e8907Santon #define PIPE_LOCK 0x100 /* Thread has exclusive I/O access. */ 67853e8907Santon #define PIPE_LWANT 0x200 /* Thread wants exclusive I/O access. */ 688867e984Sshawn 6942294cbdSanton struct pipe_pair; 7042294cbdSanton 718867e984Sshawn /* 728867e984Sshawn * Per-pipe data structure. 738867e984Sshawn * Two of these are linked together to produce bi-directional pipes. 74bc80a0d6Santon * 75c5729a20Santon * Locking: 76bc80a0d6Santon * I immutable after creation 77bc80a0d6Santon * S sigio_lock 78eb6843b8Santon * p pipe_lock 798867e984Sshawn */ 808867e984Sshawn struct pipe { 81eb6843b8Santon struct rwlock *pipe_lock; 82eb6843b8Santon struct pipebuf pipe_buffer; /* [p] data storage */ 83*a820167aSvisa struct klist pipe_klist; /* [p] list of knotes */ 84eb6843b8Santon struct timespec pipe_atime; /* [p] time of last access */ 85eb6843b8Santon struct timespec pipe_mtime; /* [p] time of last modify */ 86bc80a0d6Santon struct timespec pipe_ctime; /* [I] time of status change */ 87bc80a0d6Santon struct sigio_ref pipe_sigio; /* [S] async I/O registration */ 88eb6843b8Santon struct pipe *pipe_peer; /* [p] link with other direction */ 8942294cbdSanton struct pipe_pair *pipe_pair; /* [I] pipe storage */ 90eb6843b8Santon u_int pipe_state; /* [p] pipe status info */ 91eb6843b8Santon int pipe_busy; /* [p] # readers/writers */ 928867e984Sshawn }; 938867e984Sshawn 94a2c3ae2eSniklas #ifdef _KERNEL 95c4071fd1Smillert void pipe_init(void); 96a2c3ae2eSniklas #endif /* _KERNEL */ 978867e984Sshawn 988867e984Sshawn #endif /* !_SYS_PIPE_H_ */ 99