1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre curproc API implementation for XNU kernel
6 * Copyright (C) 2004 Cluster File Systems, Inc.
7 * Author: Nikita Danilov <nikita@clusterfs.com>
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or modify it under the
12 * terms of version 2 of the GNU General Public License as published by the
13 * Free Software Foundation. Lustre is distributed in the hope that it will be
14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 * Public License for more details. You should have received a copy of the GNU
17 * General Public License along with Lustre; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #define DEBUG_SUBSYSTEM S_LNET
23 #include <libcfs/libcfs.h>
24 #include <libcfs/kp30.h>
27 * Implementation of cfs_curproc API (see lnet/include/libcfs/curproc.h)
31 static inline struct ucred *curproc_ucred(void)
34 return proc_ucred(current_proc());
36 return current_proc()->p_cred->pc_ucred;
40 uid_t cfs_curproc_uid(void)
42 return curproc_ucred()->cr_uid;
45 gid_t cfs_curproc_gid(void)
47 LASSERT(curproc_ucred()->cr_ngroups > 0);
48 return curproc_ucred()->cr_groups[0];
51 uid_t cfs_curproc_fsuid(void)
54 return curproc_ucred()->cr_ruid;
56 return current_proc()->p_cred->p_ruid;
60 gid_t cfs_curproc_fsgid(void)
63 return curproc_ucred()->cr_rgid;
65 return current_proc()->p_cred->p_rgid;
69 pid_t cfs_curproc_pid(void)
72 /* no pid for each thread, return address of thread struct */
73 return (pid_t)current_thread();
75 return current_proc()->p_pid;
79 int cfs_curproc_groups_nr(void)
81 LASSERT(curproc_ucred()->cr_ngroups > 0);
82 return curproc_ucred()->cr_ngroups - 1;
85 int cfs_curproc_is_in_groups(gid_t gid)
93 for (i = 0; i < cr->cr_ngroups; ++ i) {
94 if (cr->cr_groups[i] == gid)
100 void cfs_curproc_groups_dump(gid_t *array, int size)
104 cr = curproc_ucred();
106 CLASSERT(sizeof array[0] == sizeof (__u32));
108 size = min_t(int, size, cr->cr_ngroups);
109 memcpy(array, &cr->cr_groups[1], size * sizeof(gid_t));
112 mode_t cfs_curproc_umask(void)
118 * fd_cmask is not available in kexts, so we just assume
119 * verything is permited.
123 return current_proc()->p_fd->fd_cmask;
127 char *cfs_curproc_comm(void)
131 * Writing to proc->p_comm is not permited in Darwin8,
132 * because proc_selfname() only return a copy of proc->p_comm,
133 * so this function is not really working while user try to
134 * change comm of current process.
136 static char pcomm[MAXCOMLEN+1];
138 proc_selfname(pcomm, MAXCOMLEN+1);
141 return current_proc()->p_comm;
145 cfs_kernel_cap_t cfs_curproc_cap_get(void)
150 void cfs_curproc_cap_set(cfs_kernel_cap_t cap)
158 * c-indentation-style: "K&R"