1 /* $NetBSD: ipc.h,v 1.24 2002/08/07 23:39:24 soren 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/types.h> 56 57 struct ipc_perm { 58 uid_t uid; /* user id */ 59 gid_t gid; /* group id */ 60 uid_t cuid; /* creator user id */ 61 gid_t cgid; /* creator group id */ 62 mode_t mode; /* r/w permission */ 63 64 /* 65 * These members are private and used only in the internal 66 * implementation of this interface. 67 */ 68 unsigned short _seq; /* sequence # (to generate unique 69 msg/sem/shm id) */ 70 key_t _key; /* user specified msg/sem/shm key */ 71 }; 72 73 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 74 /* Warning: 64-bit structure padding is needed here */ 75 struct ipc_perm_sysctl { 76 u_int64_t _key; 77 uid_t uid; 78 gid_t gid; 79 uid_t cuid; 80 gid_t cgid; 81 mode_t mode; 82 int16_t _seq; 83 int16_t pad; 84 }; 85 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */ 86 87 #ifdef _KERNEL 88 /* 89 * Old IPC permission structure used before NetBSD 1.5. 90 */ 91 struct ipc_perm14 { 92 unsigned short cuid; /* creator user id */ 93 unsigned short cgid; /* creator group id */ 94 unsigned short uid; /* user id */ 95 unsigned short gid; /* group id */ 96 unsigned short mode; /* r/w permission */ 97 unsigned short seq; /* sequence # (to generate unique 98 msg/sem/shm id) */ 99 key_t key; /* user specified msg/sem/shm key */ 100 }; 101 #endif /* _KERNEL */ 102 103 /* Common access type bits, used with ipcperm(). */ 104 #define IPC_R 000400 /* read permission */ 105 #define IPC_W 000200 /* write/alter permission */ 106 #define IPC_M 010000 /* permission to change control info */ 107 108 /* X/Open required constants (same values as system 5) */ 109 #define IPC_CREAT 001000 /* create entry if key does not exist */ 110 #define IPC_EXCL 002000 /* fail if key exists */ 111 #define IPC_NOWAIT 004000 /* error if request must wait */ 112 113 #define IPC_PRIVATE (key_t)0 /* private key */ 114 115 #define IPC_RMID 0 /* remove identifier */ 116 #define IPC_SET 1 /* set options */ 117 #define IPC_STAT 2 /* get options */ 118 119 /* 120 * Macros to convert between ipc ids and array indices or sequence ids. 121 * The first of these is used by ipcs(1), and so is defined outside the 122 * kernel as well. 123 */ 124 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) 125 #define IXSEQ_TO_IPCID(ix,perm) (((perm._seq) << 16) | (ix & 0xffff)) 126 #endif 127 128 #ifdef _KERNEL 129 #define IPCID_TO_IX(id) ((id) & 0xffff) 130 #define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff) 131 132 int ipcperm __P((struct ucred *, struct ipc_perm *, int)); 133 134 void ipc_perm14_to_native __P((struct ipc_perm14 *, struct ipc_perm *)); 135 void native_to_ipc_perm14 __P((struct ipc_perm *, struct ipc_perm14 *)); 136 #endif /* _KERNEL */ 137 138 #ifndef _KERNEL 139 #include <sys/cdefs.h> 140 141 __BEGIN_DECLS 142 key_t ftok __P((const char *, int)); 143 __END_DECLS 144 #endif 145 #endif /* !_SYS_IPC_H_ */ 146