2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * Linux implementation.
15 #ifndef OSI_MACHDEP_H_
16 #define OSI_MACHDEP_H_
18 /* Only needed for xdr.h in glibc 2.1.x */
20 # define quad_t __quad_t
21 # define u_quad_t __u_quad_t
26 #ifdef STRUCT_TASK_STRUCT_HAS_TGID
27 # define getpid() current->tgid
28 # ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
29 # define getppid() current->real_parent->tgid
30 # elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
31 # define getppid() current->parent->tgid
33 # define getppid() current->p_opptr->tgid
35 #else /* !STRUCT_TASK_STRUCT_HAS_TGID */
36 # define getpid() current->pid
37 # ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
38 # define getppid() current->real_parent->pid
39 # elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
40 # define getppid() current->parent->pid
42 # define getppid() current->p_opptr->pid
44 #endif /* STRUCT_TASK_STRUCT_HAS_TGID */
46 #ifdef RECALC_SIGPENDING_TAKES_VOID
47 # define RECALC_SIGPENDING(X) recalc_sigpending()
49 # define RECALC_SIGPENDING(X) recalc_sigpending(X)
52 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK)
53 # define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
54 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
55 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND)
56 # define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
57 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
59 # define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
60 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
63 #if defined (STRUCT_TASK_STRUCT_HAS_RLIM)
64 # define TASK_STRUCT_RLIM rlim
65 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM)
66 # define TASK_STRUCT_RLIM signal->rlim
68 # error Not sure what to do about rlim (should be in the Linux task struct somewhere....)
74 #if defined(HAVE_LINUX_CURRENT_KERNEL_TIME)
75 static inline time_t osi_Time(void) {
76 struct timespec xtime;
77 xtime = current_kernel_time();
81 # define osi_Time() (xtime.tv_sec)
86 #ifdef AFS_LINUX_64BIT_KERNEL
87 # define osi_GetTime(V) \
89 struct timeval __afs_tv; \
90 do_gettimeofday(&__afs_tv); \
91 (V)->tv_sec = (afs_int32)__afs_tv.tv_sec; \
92 (V)->tv_usec = (afs_int32)__afs_tv.tv_usec; \
95 # define osi_GetTime(V) do_gettimeofday((V))
99 #define gop_lookupname osi_lookupname
101 #undef gop_lookupname_user
102 #define gop_lookupname_user osi_lookupname
104 #define osi_vnhold(V, N) do { VN_HOLD(AFSTOV(V)); } while (0)
105 #define VN_HOLD(V) osi_Assert(igrab((V)) == (V))
106 #define VN_RELE(V) iput((V))
108 #define afs_suser(x) capable(CAP_SYS_ADMIN)
109 extern int afs_osi_Wakeup(void *event);
113 afs_osi_Wakeup(event);
116 #define vType(V) ((AFSTOV((V)))->i_mode & S_IFMT)
117 #define vSetType(V, type) AFSTOV((V))->i_mode = ((type) | (AFSTOV((V))->i_mode & ~S_IFMT)) /* preserve mode */
118 #define vSetVfsp(V, vfsp) /* unused */
119 #define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS) /* test superblock instead */
120 #define SetAfsVnode(V) /* unnecessary */
122 #include <asm/uaccess.h>
124 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
125 static inline long copyinstr(char *from, char *to, int count, int *length) {
127 tmp = strncpy_from_user(to, from, count);
133 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
135 /* kernel print statements */
136 #define printf(args...) printk(args)
137 #define uprintf(args...) printk(args)
141 #define NGROUPS NGROUPS_SMALL
144 typedef struct task_struct afs_proc_t;
146 #ifdef HAVE_LINUX_KUID_T
148 #include <linux/uidgid.h>
149 typedef kuid_t afs_kuid_t;
150 typedef kgid_t afs_kgid_t;
151 extern struct user_namespace *afs_ns;
152 # ifdef CONFIG_USER_NS
153 # define afs_current_user_ns() current_user_ns()
155 /* Here current_user_ns() expands to GPL-only init_user_ns symbol! */
156 # define afs_current_user_ns() ((struct user_namespace *)NULL)
159 static inline kuid_t afs_make_kuid(uid_t uid) {
160 return make_kuid(afs_ns, uid);
162 static inline kgid_t afs_make_kgid(gid_t gid) {
163 return make_kgid(afs_ns, gid);
165 static inline uid_t afs_from_kuid(kuid_t kuid) {
166 return from_kuid(afs_ns, kuid);
168 static inline uid_t afs_from_kgid(kgid_t kgid) {
169 return from_kgid(afs_ns, kgid);
174 typedef uid_t afs_kuid_t;
175 typedef gid_t afs_kgid_t;
177 static inline afs_kuid_t afs_make_kuid(uid_t uid) {return uid;}
178 static inline afs_kgid_t afs_make_kgid(gid_t gid) {return gid;}
179 static inline uid_t afs_from_kuid(afs_kuid_t kuid) {return kuid;}
180 static inline gid_t afs_from_kgid(afs_kgid_t kgid) {return kgid;}
181 static inline unsigned char uid_eq(uid_t a, uid_t b) {return a == b;}
182 static inline unsigned char gid_eq(gid_t a, gid_t b) {return a == b;}
183 static inline unsigned char uid_lt(uid_t a, uid_t b) {return a < b;}
184 static inline unsigned char gid_lt(gid_t a, gid_t b) {return a < b;}
185 #define GLOBAL_ROOT_UID ((afs_kuid_t) 0)
186 #define GLOBAL_ROOT_GID ((afs_kgid_t) 0)
190 /* Credentials. For newer kernels we use the kernel structure directly. */
191 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
193 typedef struct cred afs_ucred_t;
194 typedef struct cred cred_t;
196 # define afs_cr_uid(cred) (afs_from_kuid((cred)->fsuid))
197 # define afs_cr_gid(cred) (afs_from_kgid((cred)->fsgid))
198 # define afs_cr_ruid(cred) (afs_from_kuid((cred)->uid))
199 # define afs_cr_rgid(cred) (afs_from_kgid((cred)->gid))
200 # define afs_cr_group_info(cred) ((cred)->group_info)
201 # define crhold(c) (get_cred(c))
203 afs_set_cr_uid(cred_t *cred, uid_t uid) {
204 cred->fsuid = afs_make_kuid(uid);
207 afs_set_cr_gid(cred_t *cred, gid_t gid) {
208 cred->fsgid = afs_make_kgid(gid);
211 afs_set_cr_ruid(cred_t *cred, uid_t uid) {
212 cred->uid = afs_make_kuid(uid);
215 afs_set_cr_rgid(cred_t *cred, gid_t gid) {
216 cred->gid = afs_make_kgid(gid);
219 afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) {
220 cred->group_info = group_info;
223 # define current_group_info() (current->cred->group_info)
224 # define task_gid(task) (task->cred->gid)
225 # define task_user(task) (task->cred->user)
226 # if defined(STRUCT_CRED_HAS_SESSION_KEYRING)
227 # define task_session_keyring(task) (task->cred->session_keyring)
228 # define current_session_keyring() (current->cred->session_keyring)
230 # define task_session_keyring(task) (task->cred->tgcred->session_keyring)
231 # define current_session_keyring() (current->cred->tgcred->session_keyring)
236 typedef struct afs_cred {
242 struct group_info *cr_group_info;
245 typedef struct afs_cred afs_ucred_t;
246 # define afs_cr_group_info(cred) ((cred)->cr_group_info)
248 afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) {
249 cred->cr_group_info = group_info;
252 # define current_group_info() (current->group_info)
253 # if !defined(task_gid)
254 # define task_gid(task) (task->gid)
256 # if !defined(task_uid)
257 # define task_uid(task) (task->uid)
259 # define task_user(task) (task->user)
260 # define task_session_keyring(task) (task->signal->session_keyring)
261 # define current_session_keyring() (current->signal->session_keyring)
262 # define crhold(c) atomic_inc(&(c)->cr_ref)
264 #endif /* defined(STRUCT_TASK_STRUCT_HAS_CRED) */
266 #if !defined(current_cred)
267 # define current_gid() (current->gid)
268 # define current_uid() (current->uid)
269 # define current_fsgid() (current->fsgid)
270 # define current_fsuid() (current->fsuid)
273 /* UIO manipulation */
274 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
275 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
277 struct iovec *uio_iov;
279 afs_offs_t uio_offset;
284 #define afsio_iov uio_iov
285 #define afsio_iovcnt uio_iovcnt
286 #define afsio_offset uio_offset
287 #define afsio_seg uio_segflg
288 #define afsio_fmode uio_fmode
289 #define afsio_resid uio_resid
291 /* Get/set the inode in the osifile struct. */
292 #define FILE_INODE(F) (F)->f_dentry->d_inode
294 #define OSIFILE_INODE(a) FILE_INODE((a)->filp)
296 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
297 # define NEED_IOCTL32
300 #include <linux/version.h>
301 #include <linux/sched.h>
302 #include <linux/wait.h>
304 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
305 extern struct mutex afs_global_lock;
307 extern struct semaphore afs_global_lock;
308 # define mutex_lock(lock) down(lock)
309 # define mutex_unlock(lock) up(lock)
311 extern int afs_global_owner;
313 #define AFS_GLOCK() \
315 mutex_lock(&afs_global_lock); \
316 if (afs_global_owner) \
317 osi_Panic("afs_global_lock already held by pid %d", \
319 afs_global_owner = current->pid; \
322 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
324 #define AFS_GUNLOCK() \
326 if (!ISAFS_GLOCK()) \
327 osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
328 afs_global_owner = 0; \
329 mutex_unlock(&afs_global_lock); \
332 #define osi_InitGlock()
334 #ifdef AFS_AMD64_LINUX20_ENV
335 /* RHEL5 beta's kernel doesn't define these. They aren't gonna change, so... */
337 # ifndef __NR_ia32_afs_syscall
338 # define __NR_ia32_afs_syscall 137
340 # ifndef __NR_ia32_setgroups
341 # define __NR_ia32_setgroups 81
343 # ifndef __NR_ia32_setgroups32
344 # define __NR_ia32_setgroups32 206
346 # ifndef __NR_ia32_close
347 # define __NR_ia32_close 6
349 # ifndef __NR_ia32_chdir
350 # define __NR_ia32_chdir 12
352 # ifndef __NR_ia32_break
353 # define __NR_ia32_break 17
355 # ifndef __NR_ia32_stty
356 # define __NR_ia32_stty 31
358 # ifndef __NR_ia32_gtty
359 # define __NR_ia32_gtty 32
361 # ifndef __NR_ia32_ftime
362 # define __NR_ia32_ftime 35
364 # ifndef __NR_ia32_prof
365 # define __NR_ia32_prof 44
367 # ifndef __NR_ia32_lock
368 # define __NR_ia32_lock 53
370 # ifndef __NR_ia32_mpx
371 # define __NR_ia32_mpx 56
373 # ifndef __NR_ia32_exit
374 # define __NR_ia32_exit 1
376 # ifndef __NR_ia32_mount
377 # define __NR_ia32_mount 21
379 # ifndef __NR_ia32_read
380 # define __NR_ia32_read 3
382 # ifndef __NR_ia32_write
383 # define __NR_ia32_write 4
385 # ifndef __NR_ia32_open
386 # define __NR_ia32_open 5
388 # ifndef __NR_ia32_close
389 # define __NR_ia32_close 6
391 # ifndef __NR_ia32_unlink
392 # define __NR_ia32_unlink 10
396 #define osi_procname(procname, size) strncpy(procname, current->comm, size)
398 #endif /* OSI_MACHDEP_H_ */