1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/libcfs/darwin/darwin-curproc.c
38 * Lustre curproc API implementation for XNU kernel
40 * Author: Nikita Danilov <nikita@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_LNET
45 #include <libcfs/libcfs.h>
48 * Implementation of cfs_curproc API (see lnet/include/libcfs/curproc.h)
52 static inline struct ucred *curproc_ucred(void)
55 return proc_ucred(current_proc());
57 return current_proc()->p_cred->pc_ucred;
61 uid_t cfs_curproc_uid(void)
63 return curproc_ucred()->cr_uid;
66 gid_t cfs_curproc_gid(void)
68 LASSERT(curproc_ucred()->cr_ngroups > 0);
69 return curproc_ucred()->cr_groups[0];
72 uid_t cfs_curproc_fsuid(void)
75 return curproc_ucred()->cr_ruid;
77 return current_proc()->p_cred->p_ruid;
81 gid_t cfs_curproc_fsgid(void)
84 return curproc_ucred()->cr_rgid;
86 return current_proc()->p_cred->p_rgid;
90 pid_t cfs_curproc_pid(void)
93 /* no pid for each thread, return address of thread struct */
94 return (pid_t)current_thread();
96 return current_proc()->p_pid;
100 int cfs_curproc_groups_nr(void)
102 LASSERT(curproc_ucred()->cr_ngroups > 0);
103 return curproc_ucred()->cr_ngroups - 1;
106 int cfs_curproc_is_in_groups(gid_t gid)
111 cr = curproc_ucred();
114 for (i = 0; i < cr->cr_ngroups; ++ i) {
115 if (cr->cr_groups[i] == gid)
121 void cfs_curproc_groups_dump(gid_t *array, int size)
125 cr = curproc_ucred();
127 CLASSERT(sizeof array[0] == sizeof (__u32));
129 size = min_t(int, size, cr->cr_ngroups);
130 memcpy(array, &cr->cr_groups[1], size * sizeof(gid_t));
133 mode_t cfs_curproc_umask(void)
139 * fd_cmask is not available in kexts, so we just assume
140 * verything is permited.
144 return current_proc()->p_fd->fd_cmask;
148 char *cfs_curproc_comm(void)
152 * Writing to proc->p_comm is not permited in Darwin8,
153 * because proc_selfname() only return a copy of proc->p_comm,
154 * so this function is not really working while user try to
155 * change comm of current process.
157 static char pcomm[MAXCOMLEN+1];
159 proc_selfname(pcomm, MAXCOMLEN+1);
162 return current_proc()->p_comm;
166 cfs_kernel_cap_t cfs_curproc_cap_get(void)
171 void cfs_curproc_cap_set(cfs_kernel_cap_t cap)
179 * c-indentation-style: "K&R"