xref: /netbsd-src/sys/sys/ipc.h (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1 /*	$NetBSD: ipc.h,v 1.25 2003/04/28 23:16:28 bjh21 Exp $	*/
2 
3 /*
4  * Copyright (c) 1988 University of Utah.
5  * Copyright (c) 1990, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  * (c) UNIX System Laboratories, Inc.
8  * All or some portions of this file are derived from material licensed
9  * to the University of California by American Telephone and Telegraph
10  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11  * the permission of UNIX System Laboratories, Inc.
12  *
13  * This code is derived from software contributed to Berkeley by
14  * the Systems Programming Group of the University of Utah Computer
15  * Science Department.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  *    notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the
24  *    documentation and/or other materials provided with the distribution.
25  * 3. All advertising materials mentioning features or use of this software
26  *    must display the following acknowledgement:
27  *	This product includes software developed by the University of
28  *	California, Berkeley and its contributors.
29  * 4. Neither the name of the University nor the names of its contributors
30  *    may be used to endorse or promote products derived from this software
31  *    without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
34  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
37  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43  * SUCH DAMAGE.
44  *
45  *	@(#)ipc.h	8.4 (Berkeley) 2/19/95
46  */
47 
48 /*
49  * SVID compatible ipc.h file
50  */
51 
52 #ifndef _SYS_IPC_H_
53 #define _SYS_IPC_H_
54 
55 #include <sys/featuretest.h>
56 #include <sys/types.h>
57 
58 struct ipc_perm {
59 	uid_t		uid;	/* user id */
60 	gid_t		gid;	/* group id */
61 	uid_t		cuid;	/* creator user id */
62 	gid_t		cgid;	/* creator group id */
63 	mode_t		mode;	/* r/w permission */
64 
65 	/*
66 	 * These members are private and used only in the internal
67 	 * implementation of this interface.
68 	 */
69 	unsigned short	_seq;	/* sequence # (to generate unique
70 				   msg/sem/shm id) */
71 	key_t		_key;	/* user specified msg/sem/shm key */
72 };
73 
74 #if defined(_NETBSD_SOURCE)
75 /* Warning: 64-bit structure padding is needed here */
76 struct ipc_perm_sysctl {
77 	u_int64_t	_key;
78 	uid_t		uid;
79 	gid_t		gid;
80 	uid_t		cuid;
81 	gid_t		cgid;
82 	mode_t		mode;
83 	int16_t		_seq;
84 	int16_t		pad;
85 };
86 #endif /* _NETBSD_SOURCE */
87 
88 #ifdef _KERNEL
89 /*
90  * Old IPC permission structure used before NetBSD 1.5.
91  */
92 struct ipc_perm14 {
93 	unsigned short	cuid;	/* creator user id */
94 	unsigned short	cgid;	/* creator group id */
95 	unsigned short	uid;	/* user id */
96 	unsigned short	gid;	/* group id */
97 	unsigned short	mode;	/* r/w permission */
98 	unsigned short	seq;	/* sequence # (to generate unique
99 				   msg/sem/shm id) */
100 	key_t	key;		/* user specified msg/sem/shm key */
101 };
102 #endif /* _KERNEL */
103 
104 /* Common access type bits, used with ipcperm(). */
105 #define	IPC_R		000400	/* read permission */
106 #define	IPC_W		000200	/* write/alter permission */
107 #define	IPC_M		010000	/* permission to change control info */
108 
109 /* X/Open required constants (same values as system 5) */
110 #define	IPC_CREAT	001000	/* create entry if key does not exist */
111 #define	IPC_EXCL	002000	/* fail if key exists */
112 #define	IPC_NOWAIT	004000	/* error if request must wait */
113 
114 #define	IPC_PRIVATE	(key_t)0 /* private key */
115 
116 #define	IPC_RMID	0	/* remove identifier */
117 #define	IPC_SET		1	/* set options */
118 #define	IPC_STAT	2	/* get options */
119 
120 /*
121  * Macros to convert between ipc ids and array indices or sequence ids.
122  * The first of these is used by ipcs(1), and so is defined outside the
123  * kernel as well.
124  */
125 #if defined(_NETBSD_SOURCE)
126 #define	IXSEQ_TO_IPCID(ix,perm)	(((perm._seq) << 16) | (ix & 0xffff))
127 #endif
128 
129 #ifdef _KERNEL
130 #define	IPCID_TO_IX(id)		((id) & 0xffff)
131 #define	IPCID_TO_SEQ(id)	(((id) >> 16) & 0xffff)
132 
133 int	ipcperm __P((struct ucred *, struct ipc_perm *, int));
134 
135 void	ipc_perm14_to_native __P((struct ipc_perm14 *, struct ipc_perm *));
136 void	native_to_ipc_perm14 __P((struct ipc_perm *, struct ipc_perm14 *));
137 #endif /* _KERNEL */
138 
139 #ifndef _KERNEL
140 #include <sys/cdefs.h>
141 
142 __BEGIN_DECLS
143 key_t	ftok __P((const char *, int));
144 __END_DECLS
145 #endif
146 #endif /* !_SYS_IPC_H_ */
147