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>
26 * Implementation of cfs_curproc API (see lnet/include/libcfs/curproc.h)
30 static inline struct ucred *curproc_ucred(void)
33 return proc_ucred(current_proc());
35 return current_proc()->p_cred->pc_ucred;
39 uid_t cfs_curproc_uid(void)
41 return curproc_ucred()->cr_uid;
44 gid_t cfs_curproc_gid(void)
46 LASSERT(curproc_ucred()->cr_ngroups > 0);
47 return curproc_ucred()->cr_groups[0];
50 uid_t cfs_curproc_fsuid(void)
53 return curproc_ucred()->cr_ruid;
55 return current_proc()->p_cred->p_ruid;
59 gid_t cfs_curproc_fsgid(void)
62 return curproc_ucred()->cr_rgid;
64 return current_proc()->p_cred->p_rgid;
68 pid_t cfs_curproc_pid(void)
71 /* no pid for each thread, return address of thread struct */
72 return (pid_t)current_thread();
74 return current_proc()->p_pid;
78 int cfs_curproc_groups_nr(void)
80 LASSERT(curproc_ucred()->cr_ngroups > 0);
81 return curproc_ucred()->cr_ngroups - 1;
84 int cfs_curproc_is_in_groups(gid_t gid)
92 for (i = 0; i < cr->cr_ngroups; ++ i) {
93 if (cr->cr_groups[i] == gid)
99 void cfs_curproc_groups_dump(gid_t *array, int size)
103 cr = curproc_ucred();
105 CLASSERT(sizeof array[0] == sizeof (__u32));
107 size = min_t(int, size, cr->cr_ngroups);
108 memcpy(array, &cr->cr_groups[1], size * sizeof(gid_t));
111 mode_t cfs_curproc_umask(void)
117 * fd_cmask is not available in kexts, so we just assume
118 * verything is permited.
122 return current_proc()->p_fd->fd_cmask;
126 char *cfs_curproc_comm(void)
130 * Writing to proc->p_comm is not permited in Darwin8,
131 * because proc_selfname() only return a copy of proc->p_comm,
132 * so this function is not really working while user try to
133 * change comm of current process.
135 static char pcomm[MAXCOMLEN+1];
137 proc_selfname(pcomm, MAXCOMLEN+1);
140 return current_proc()->p_comm;
144 cfs_kernel_cap_t cfs_curproc_cap_get(void)
149 void cfs_curproc_cap_set(cfs_kernel_cap_t cap)
157 * c-indentation-style: "K&R"