Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / libcfs / linux / linux-curproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre curproc API implementation for Linux kernel
5  *
6  * Copyright (C) 2004 Cluster File Systems, Inc.
7  * Author: Nikita Danilov <nikita@clusterfs.com>
8  *
9  * This file is part of Lustre, http://www.lustre.org.
10  *
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.
19  */
20
21 #include <linux/sched.h>
22
23 #define DEBUG_SUBSYSTEM S_LNET
24
25 #include <libcfs/libcfs.h>
26 #include <libcfs/kp30.h>
27
28 /*
29  * Implementation of cfs_curproc API (see portals/include/libcfs/curproc.h)
30  * for Linux kernel.
31  */
32
33 uid_t  cfs_curproc_uid(void)
34 {
35         return current->uid;
36 }
37
38 gid_t  cfs_curproc_gid(void)
39 {
40         return current->gid;
41 }
42
43 uid_t  cfs_curproc_fsuid(void)
44 {
45         return current->fsuid;
46 }
47
48 gid_t  cfs_curproc_fsgid(void)
49 {
50         return current->fsgid;
51 }
52
53 pid_t  cfs_curproc_pid(void)
54 {
55         return current->pid;
56 }
57
58 int    cfs_curproc_groups_nr(void)
59 {
60         int nr;
61
62 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
63         task_lock(current);
64         nr = current->group_info->ngroups;
65         task_unlock(current);
66 #else
67         nr = current->ngroups;
68 #endif
69         return nr;
70 }
71
72 void   cfs_curproc_groups_dump(gid_t *array, int size)
73 {
74 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
75         task_lock(current);
76         size = min_t(int, size, current->group_info->ngroups);
77         memcpy(array, current->group_info->blocks[0], size * sizeof(__u32));
78         task_unlock(current);
79 #else
80         LASSERT(size <= NGROUPS);
81         size = min_t(int, size, current->ngroups);
82         memcpy(array, current->groups, size * sizeof(__u32));
83 #endif
84 }
85
86
87 int    cfs_curproc_is_in_groups(gid_t gid)
88 {
89         return in_group_p(gid);
90 }
91
92 mode_t cfs_curproc_umask(void)
93 {
94         return current->fs->umask;
95 }
96
97 char  *cfs_curproc_comm(void)
98 {
99         return current->comm;
100 }
101
102 cfs_kernel_cap_t cfs_curproc_cap_get(void)
103 {
104         return current->cap_effective;
105 }
106
107 void cfs_curproc_cap_set(cfs_kernel_cap_t cap)
108 {
109         current->cap_effective = cap;
110 }
111
112 EXPORT_SYMBOL(cfs_curproc_uid);
113 EXPORT_SYMBOL(cfs_curproc_pid);
114 EXPORT_SYMBOL(cfs_curproc_gid);
115 EXPORT_SYMBOL(cfs_curproc_fsuid);
116 EXPORT_SYMBOL(cfs_curproc_fsgid);
117 EXPORT_SYMBOL(cfs_curproc_umask);
118 EXPORT_SYMBOL(cfs_curproc_comm);
119 EXPORT_SYMBOL(cfs_curproc_groups_nr);
120 EXPORT_SYMBOL(cfs_curproc_groups_dump);
121 EXPORT_SYMBOL(cfs_curproc_is_in_groups);
122 EXPORT_SYMBOL(cfs_curproc_cap_get);
123 EXPORT_SYMBOL(cfs_curproc_cap_set);
124
125 /*
126  * Local variables:
127  * c-indentation-style: "K&R"
128  * c-basic-offset: 8
129  * tab-width: 8
130  * fill-column: 80
131  * scroll-step: 1
132  * End:
133  */