1139825Simp/*- 21541Srgrimes * Copyright (c) 1981, 1984, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)msgbuf.h 8.1 (Berkeley) 6/2/93 3050477Speter * $FreeBSD: stable/11/sys/sys/msgbuf.h 338109 2018-08-20 17:27:30Z kevans $ 311541Srgrimes */ 321541Srgrimes 332165Spaul#ifndef _SYS_MSGBUF_H_ 34125954Sbde#define _SYS_MSGBUF_H_ 352165Spaul 36222537Sken#include <sys/lock.h> 37222537Sken#include <sys/mutex.h> 38222537Sken 3983045Sobrienstruct msgbuf { 40222537Sken char *msg_ptr; /* pointer to buffer */ 4136179Sphk#define MSG_MAGIC 0x063062 42222537Sken u_int msg_magic; 43222537Sken u_int msg_size; /* size of buffer area */ 44222537Sken u_int msg_wseq; /* write sequence number */ 45222537Sken u_int msg_rseq; /* read sequence number */ 46222537Sken u_int msg_cksum; /* checksum of contents */ 47222537Sken u_int msg_seqmod; /* range for sequence numbers */ 48222537Sken int msg_lastpri; /* saved priority value */ 49233135Seadler u_int msg_flags; 50233135Seadler#define MSGBUF_NEEDNL 0x01 /* set when newline needed */ 51222537Sken struct mtx msg_lock; /* mutex to protect the buffer */ 521541Srgrimes}; 5336441Sphk 54125954Sbde/* Normalise a sequence number or a difference between sequence numbers. */ 55125954Sbde#define MSGBUF_SEQNORM(mbp, seq) (((seq) + (mbp)->msg_seqmod) % \ 56116660Siedowse (mbp)->msg_seqmod) 57125954Sbde#define MSGBUF_SEQ_TO_POS(mbp, seq) ((seq) % (mbp)->msg_size) 58125954Sbde/* Subtract sequence numbers. Note that only positive values result. */ 59125954Sbde#define MSGBUF_SEQSUB(mbp, seq1, seq2) (MSGBUF_SEQNORM((mbp), (seq1) - (seq2))) 60116660Siedowse 6155205Speter#ifdef _KERNEL 62217688Spluknetextern int msgbufsize; 6370239Sphkextern int msgbuftrigger; 642112Swollmanextern struct msgbuf *msgbufp; 65198860Sedextern struct mtx msgbuf_lock; 66125954Sbde 67106917Stmmvoid msgbufinit(void *ptr, int size); 68116660Siedowsevoid msgbuf_addchar(struct msgbuf *mbp, int c); 69338109Skevansvoid msgbuf_addstr(struct msgbuf *mbp, int pri, const char *str, int filter_cr); 70116660Siedowsevoid msgbuf_clear(struct msgbuf *mbp); 71116660Siedowsevoid msgbuf_copy(struct msgbuf *src, struct msgbuf *dst); 72116660Siedowseint msgbuf_getbytes(struct msgbuf *mbp, char *buf, int buflen); 73116660Siedowseint msgbuf_getchar(struct msgbuf *mbp); 74116660Siedowseint msgbuf_getcount(struct msgbuf *mbp); 75116660Siedowsevoid msgbuf_init(struct msgbuf *mbp, void *ptr, int size); 76116660Siedowseint msgbuf_peekbytes(struct msgbuf *mbp, char *buf, int buflen, 77116660Siedowse u_int *seqp); 78125954Sbdevoid msgbuf_reinit(struct msgbuf *mbp, void *ptr, int size); 7936441Sphk 80125954Sbde#ifndef MSGBUF_SIZE 81226090Sobrien#define MSGBUF_SIZE (32768 * 3) 821541Srgrimes#endif 83125954Sbde#endif /* KERNEL */ 842165Spaul 85125954Sbde#endif /* !_SYS_MSGBUF_H_ */ 86