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 #include <linux/version.h>
19 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
20 # define AFS_LINUX26_ONEGROUP_ENV 1
23 /* Only needed for xdr.h in glibc 2.1.x */
25 # define quad_t __quad_t
26 # define u_quad_t __u_quad_t
31 #ifdef STRUCT_TASK_STRUCT_HAS_TGID
32 # define getpid() current->tgid
33 # ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
34 # define getppid() current->real_parent->tgid
35 # elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
36 # define getppid() current->parent->tgid
38 # define getppid() current->p_opptr->tgid
40 #else /* !STRUCT_TASK_STRUCT_HAS_TGID */
41 # define getpid() current->pid
42 # ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
43 # define getppid() current->real_parent->pid
44 # elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
45 # define getppid() current->parent->pid
47 # define getppid() current->p_opptr->pid
49 #endif /* STRUCT_TASK_STRUCT_HAS_TGID */
51 #ifdef RECALC_SIGPENDING_TAKES_VOID
52 # define RECALC_SIGPENDING(X) recalc_sigpending()
54 # define RECALC_SIGPENDING(X) recalc_sigpending(X)
57 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK)
58 # define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
59 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
60 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND)
61 # define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
62 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
64 # define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
65 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
68 #if defined (STRUCT_TASK_STRUCT_HAS_RLIM)
69 # define TASK_STRUCT_RLIM rlim
70 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM)
71 # define TASK_STRUCT_RLIM signal->rlim
73 # error Not sure what to do about rlim (should be in the Linux task struct somewhere....)
79 #if defined(HAVE_LINUX_CURRENT_KERNEL_TIME)
80 static inline time_t osi_Time(void) {
81 struct timespec xtime;
82 xtime = current_kernel_time();
86 # define osi_Time() (xtime.tv_sec)
91 #ifdef AFS_LINUX_64BIT_KERNEL
92 # define osi_GetTime(V) \
94 struct timeval __afs_tv; \
95 do_gettimeofday(&__afs_tv); \
96 (V)->tv_sec = (afs_int32)__afs_tv.tv_sec; \
97 (V)->tv_usec = (afs_int32)__afs_tv.tv_usec; \
100 # define osi_GetTime(V) do_gettimeofday((V))
103 #undef gop_lookupname
104 #define gop_lookupname osi_lookupname
106 #undef gop_lookupname_user
107 #define gop_lookupname_user osi_lookupname
109 #define osi_vnhold(V, N) do { VN_HOLD(AFSTOV(V)); } while (0)
110 #define VN_HOLD(V) osi_Assert(igrab((V)) == (V))
111 #define VN_RELE(V) iput((V))
113 #define afs_suser(x) capable(CAP_SYS_ADMIN)
114 extern int afs_osi_Wakeup(void *event);
118 afs_osi_Wakeup(event);
121 #define vType(V) ((AFSTOV((V)))->i_mode & S_IFMT)
122 #define vSetType(V, type) AFSTOV((V))->i_mode = ((type) | (AFSTOV((V))->i_mode & ~S_IFMT)) /* preserve mode */
123 #define vSetVfsp(V, vfsp) /* unused */
124 #define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS) /* test superblock instead */
125 #define SetAfsVnode(V) /* unnecessary */
127 #include <asm/uaccess.h>
129 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
130 static inline long copyinstr(char *from, char *to, int count, int *length) {
132 tmp = strncpy_from_user(to, from, count);
138 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
140 /* kernel print statements */
141 #define printf(args...) printk(args)
142 #define uprintf(args...) printk(args)
146 #define NGROUPS NGROUPS_SMALL
149 typedef struct task_struct afs_proc_t;
151 /* Credentials. For newer kernels we use the kernel structure directly. */
152 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
154 typedef struct cred afs_ucred_t;
155 typedef struct cred cred_t;
157 # define afs_cr_uid(cred) ((cred)->fsuid)
158 # define afs_cr_gid(cred) ((cred)->fsgid)
159 # define afs_cr_ruid(cred) ((cred)->uid)
160 # define afs_cr_rgid(cred) ((cred)->gid)
161 # define afs_cr_group_info(cred) ((cred)->group_info)
162 # define crhold(c) (get_cred(c))
164 afs_set_cr_uid(cred_t *cred, uid_t uid) {
168 afs_set_cr_gid(cred_t *cred, gid_t gid) {
172 afs_set_cr_ruid(cred_t *cred, uid_t uid) {
176 afs_set_cr_rgid(cred_t *cred, gid_t gid) {
180 afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) {
181 cred->group_info = group_info;
184 # define current_group_info() (current->cred->group_info)
185 # define task_gid(task) (task->cred->gid)
186 # define task_user(task) (task->cred->user)
187 # define task_session_keyring(task) (task->cred->tgcred->session_keyring)
188 # define current_session_keyring() (current->cred->tgcred->session_keyring)
192 typedef struct afs_cred {
198 struct group_info *cr_group_info;
201 typedef struct afs_cred afs_ucred_t;
202 # define afs_cr_group_info(cred) ((cred)->cr_group_info)
204 afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) {
205 cred->cr_group_info = group_info;
208 # define current_group_info() (current->group_info)
209 # if !defined(task_gid)
210 # define task_gid(task) (task->gid)
212 # if !defined(task_uid)
213 # define task_uid(task) (task->uid)
215 # define task_user(task) (task->user)
216 # define task_session_keyring(task) (task->signal->session_keyring)
217 # define current_session_keyring() (current->signal->session_keyring)
218 # define crhold(c) atomic_inc(&(c)->cr_ref)
220 #endif /* defined(STRUCT_TASK_STRUCT_HAS_CRED) */
222 #if !defined(current_cred)
223 # define current_gid() (current->gid)
224 # define current_uid() (current->uid)
225 # define current_fsgid() (current->fsgid)
226 # define current_fsuid() (current->fsuid)
229 /* UIO manipulation */
230 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
231 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
233 struct iovec *uio_iov;
235 afs_offs_t uio_offset;
240 #define afsio_iov uio_iov
241 #define afsio_iovcnt uio_iovcnt
242 #define afsio_offset uio_offset
243 #define afsio_seg uio_segflg
244 #define afsio_fmode uio_fmode
245 #define afsio_resid uio_resid
247 /* Get/set the inode in the osifile struct. */
248 #define FILE_INODE(F) (F)->f_dentry->d_inode
250 #define OSIFILE_INODE(a) FILE_INODE((a)->filp)
252 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
253 # define NEED_IOCTL32
256 #include <linux/version.h>
257 #include <linux/sched.h>
258 #include <linux/wait.h>
260 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
261 extern struct mutex afs_global_lock;
263 extern struct semaphore afs_global_lock;
264 # define mutex_lock(lock) down(lock)
265 # define mutex_unlock(lock) up(lock)
267 extern int afs_global_owner;
269 #define AFS_GLOCK() \
271 mutex_lock(&afs_global_lock); \
272 if (afs_global_owner) \
273 osi_Panic("afs_global_lock already held by pid %d", \
275 afs_global_owner = current->pid; \
278 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
280 #define AFS_GUNLOCK() \
282 if (!ISAFS_GLOCK()) \
283 osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
284 afs_global_owner = 0; \
285 mutex_unlock(&afs_global_lock); \
288 #define osi_InitGlock()
290 #ifdef AFS_AMD64_LINUX20_ENV
291 /* RHEL5 beta's kernel doesn't define these. They aren't gonna change, so... */
293 # ifndef __NR_ia32_afs_syscall
294 # define __NR_ia32_afs_syscall 137
296 # ifndef __NR_ia32_setgroups
297 # define __NR_ia32_setgroups 81
299 # ifndef __NR_ia32_setgroups32
300 # define __NR_ia32_setgroups32 206
302 # ifndef __NR_ia32_close
303 # define __NR_ia32_close 6
305 # ifndef __NR_ia32_chdir
306 # define __NR_ia32_chdir 12
308 # ifndef __NR_ia32_break
309 # define __NR_ia32_break 17
311 # ifndef __NR_ia32_stty
312 # define __NR_ia32_stty 31
314 # ifndef __NR_ia32_gtty
315 # define __NR_ia32_gtty 32
317 # ifndef __NR_ia32_ftime
318 # define __NR_ia32_ftime 35
320 # ifndef __NR_ia32_prof
321 # define __NR_ia32_prof 44
323 # ifndef __NR_ia32_lock
324 # define __NR_ia32_lock 53
326 # ifndef __NR_ia32_mpx
327 # define __NR_ia32_mpx 56
329 # ifndef __NR_ia32_exit
330 # define __NR_ia32_exit 1
332 # ifndef __NR_ia32_mount
333 # define __NR_ia32_mount 21
335 # ifndef __NR_ia32_read
336 # define __NR_ia32_read 3
338 # ifndef __NR_ia32_write
339 # define __NR_ia32_write 4
341 # ifndef __NR_ia32_open
342 # define __NR_ia32_open 5
344 # ifndef __NR_ia32_close
345 # define __NR_ia32_close 6
347 # ifndef __NR_ia32_unlink
348 # define __NR_ia32_unlink 10
352 #define osi_procname(procname, size) strncpy(procname, current->comm, size)
354 #endif /* OSI_MACHDEP_H_ */