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