Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / OBSD / osi_misc.c
CommitLineData
805e021f
CE
1/*
2 * osi_misc.c
3 *
4 * $Id$
5 */
6
7/*
8copyright 2002
9the regents of the university of michigan
10all rights reserved
11
12permission is granted to use, copy, create derivative works
13and redistribute this software and such derivative works
14for any purpose, so long as the name of the university of
15michigan is not used in any advertising or publicity
16pertaining to the use or distribution of this software
17without specific, written prior authorization. if the
18above copyright notice or any other identification of the
19university of michigan is included in any copy of any
20portion of this software, then the disclaimer below must
21also be included.
22
23this software is provided as is, without representation
24from the university of michigan as to its fitness for any
25purpose, and without warranty by the university of
26michigan of any kind, either express or implied, including
27without limitation the implied warranties of
28merchantability and fitness for a particular purpose. the
29regents of the university of michigan shall not be liable
30for any damages, including special, indirect, incidental, or
31consequential damages, with respect to any claim arising
32out of or in connection with the use of the software, even
33if it has been or is hereafter advised of the possibility of
34such damages.
35*/
36
37/*
38 * Copyright 2000, International Business Machines Corporation and others.
39 * All Rights Reserved.
40 *
41 * This software has been released under the terms of the IBM Public
42 * License. For details, see the LICENSE file in the top-level source
43 * directory or online at http://www.openafs.org/dl/license10.html
44 */
45
46#include <afsconfig.h>
47#include "afs/param.h"
48
49
50#include "afs/sysincludes.h" /* Standard vendor system headers */
51#include "afs/afsincludes.h" /* Afs-based standard headers */
52#include <sys/types.h>
53#include <sys/malloc.h>
54
55/*
56 * afs_suser() returns true if the caller is superuser, false otherwise.
57 *
58 * Note that it must NOT set errno.
59 */
60
61/*
62 * OpenBSD version of afs_osi_suser() by Jim Rees.
63 * See osi_machdep.h for afs_suser macro. It simply calls afs_osi_suser()
64 * with the creds of the current process.
65 */
66
67int
68afs_osi_suser(void *credp)
69{
70#ifdef AFS_OBSD35_ENV
71 return (suser_ucred((struct ucred *)credp) ? 0 : 1);
72#else
73 return (suser((struct ucred *)credp, &curproc->p_acflag) ? 0 : 1);
74#endif
75}
76
77/*
78 * reworked for netbsd and openbsd at 4.0/4.4
79 */
80
81#if defined(AFS_OBSD42_ENV)
82/* ripped out MALLOC/FREE */
83
84void *
85osi_obsd_Alloc(size_t asize, int cansleep)
86{
87 void *p;
88 int glocked;
89
90 if (cansleep) {
91 glocked = ISAFS_GLOCK();
92 if (glocked)
93 AFS_GUNLOCK();
94 p = malloc(asize, M_AFSGENERIC, M_WAITOK);
95 if (glocked)
96 AFS_GLOCK();
97 } else {
98 p = malloc(asize, M_AFSGENERIC, M_NOWAIT);
99 }
100
101 return (p);
102}
103
104void
105osi_obsd_Free(void *p, size_t asize)
106{
107 free(p, M_AFSGENERIC);
108}
109
110#else
111void *
112osi_obsd_Alloc(size_t asize, int cansleep)
113{
114 void *p;
115 int glocked;
116
117 if (cansleep) {
118 glocked = ISAFS_GLOCK();
119 if (glocked)
120 AFS_GUNLOCK();
121 MALLOC(p, void *, asize, M_AFSGENERIC, M_WAITOK);
122 if (glocked)
123 AFS_GLOCK();
124 } else {
125 MALLOC(p, void *, asize, M_AFSGENERIC, M_NOWAIT);
126 }
127
128 return (p);
129}
130
131void
132osi_obsd_Free(void *p, size_t asize)
133{
134 FREE(p, M_AFSGENERIC);
135}
136#endif
137
138#if 0 /* XXX */
139/* I speculate this usage may be more correct than definitions
140 * in afs_osi_alloc.c, which I discarded successfully for FreeBSD 7+,
141 * and am trying to discard for NetBSD 4.x, but until tested, I'm
142 * not rocking the boat. Matt.
143 */
144
145void
146osi_FreeLargeSpace(void *p)
147{
148 osi_obsd_Free(p, 0);
149}
150
151void
152osi_FreeSmallSpace(void *p)
153{
154 osi_obsd_Free(p, 0);
155}
156
157void *
158osi_AllocLargeSpace(size_t size)
159{
160 AFS_ASSERT_GLOCK();
161 AFS_STATCNT(osi_AllocLargeSpace);
162 return (osi_obsd_Alloc(size, 1));
163}
164#endif
165
166int
167afs_syscall_icreate(dev, near_inode, param1, param2, param3, param4, retval)
168 long *retval;
169 long dev, near_inode, param1, param2, param3, param4;
170{
171 return EINVAL;
172}
173
174int
175afs_syscall_iopen(dev, inode, usrmod, retval)
176 long *retval;
177 int dev, inode, usrmod;
178{
179 return EINVAL;
180}
181
182int
183afs_syscall_iincdec(dev, inode, inode_p1, amount)
184 int dev, inode, inode_p1, amount;
185{
186 return EINVAL;
187}